Ticket #9: taskbar.patch

File taskbar.patch, 11.4 kB (added by Didactylos, 2 years ago)

Updated to patch current revision

  • clientgui/BOINCTaskBar.cpp

    old new  
    8888    m_bTaskbarInitiatedShutdown = false; 
    8989 
    9090    m_dtLastHoverDetected = wxDateTime((time_t)0); 
    91     m_dtLastBalloonDisplayed = wxDateTime((time_t)0); 
    9291 
    9392    m_bMouseButtonPressed = false; 
    9493 
     
    303302 
    304303 
    305304void CTaskBarIcon::OnMouseMove(wxTaskBarIconEvent& WXUNUSED(event)) { 
    306     wxTimeSpan ts(wxDateTime::Now() - m_dtLastHoverDetected); 
    307     if (ts.GetSeconds() >= 10) { 
    308         m_dtLastHoverDetected = wxDateTime::Now(); 
    309     } 
    310305 
    311306    wxTimeSpan tsLastHover(wxDateTime::Now() - m_dtLastHoverDetected); 
    312     wxTimeSpan tsLastBalloon(wxDateTime::Now() - m_dtLastBalloonDisplayed); 
    313     if ((tsLastHover.GetSeconds() >= 2) && (tsLastBalloon.GetSeconds() >= 10)) { 
    314         m_dtLastBalloonDisplayed = wxDateTime::Now(); 
    315307 
     308    if (tsLastHover.GetSeconds() >= 2) { 
     309        m_dtLastHoverDetected = wxDateTime::Now(); 
     310 
    316311        CMainDocument* pDoc                 = wxGetApp().GetDocument(); 
    317312        CSkinAdvanced* pSkinAdvanced        = wxGetApp().GetSkinManager()->GetAdvanced(); 
    318313        wxString       strTitle             = wxEmptyString; 
     
    321316        wxString       strBuffer            = wxEmptyString; 
    322317        wxString       strProjectName       = wxEmptyString; 
    323318        float          fProgress            = 0; 
    324         bool           bIsActive            = false; 
    325         bool           bIsExecuting         = false; 
    326         bool           bIsDownloaded        = false; 
    327         wxInt32        iResultCount         = 0; 
    328         wxInt32        iIndex               = 0; 
    329319        wxIcon         iconIcon             = wxNullIcon; 
    330320        CC_STATUS      status; 
    331321 
     
    335325        wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced)); 
    336326 
    337327 
    338         // What should the title of the balloon be? 
     328        // What should the title of the tooltip be? 
    339329        strTitle = pSkinAdvanced->GetApplicationName(); 
    340330 
    341331        if (pDoc->IsConnected()) { 
     332            pDoc->GetConnectedComputerName(strMachineName); 
     333            if (!pDoc->IsComputerNameLocal(strMachineName)) { 
     334                strTitle = strTitle + wxT(" - (") + strMachineName + wxT(")"); 
     335            } 
    342336 
     337                        strMessage += strTitle; 
     338 
    343339            pDoc->GetCoreClientStatus(status); 
    344340            if (status.task_suspend_reason && !(status.task_suspend_reason & SUSPEND_REASON_CPU_USAGE_LIMIT)) { 
    345341                // 1st %s is the previous instance of the message 
    346342                // 2nd %s is the project name 
    347343                //    i.e. 'BOINC', 'GridRepublic' 
    348344                strBuffer.Printf( 
    349                     _("Computation is suspended.\n") 
     345                    _("\nComputation is suspended.") 
    350346                ); 
    351347                iconIcon = m_iconTaskBarSnooze; 
    352348                strMessage += strBuffer; 
     
    357353                // 2nd %s is the project name 
    358354                //    i.e. 'BOINC', 'GridRepublic' 
    359355                strBuffer.Printf( 
    360                     _("Network activity is suspended.\n") 
     356                    _("\nNetwork activity is suspended.") 
    361357                ); 
    362358                strMessage += strBuffer; 
    363359            } 
    364360 
    365             if (strMessage.Length() > 0) { 
    366                 strMessage += wxT("\n"); 
    367             } 
     361            std::vector<RESULT*> tasks = GetRunningTasks(pDoc); 
    368362 
    369             iResultCount = pDoc->GetWorkCount(); 
    370             for (iIndex = 0; iIndex < iResultCount; iIndex++) { 
    371                 RESULT* result = pDoc->result(iIndex); 
    372                 RESULT* state_result = NULL; 
    373                 std::string project_name; 
     363            if (tasks.size() == 0) { 
     364                strMessage += _("\nNo running tasks."); 
     365            } else if (tasks.size() < 3) { 
    374366 
    375                 bIsDownloaded = (result->state == RESULT_FILES_DOWNLOADED); 
    376                 bIsActive     = result->active_task; 
    377                 bIsExecuting  = (result->scheduler_state == CPU_SCHED_SCHEDULED)
    378                 if (!(bIsActive) || !(bIsDownloaded) || !(bIsExecuting)) continue; 
     367                std::vector<RESULT*>::iterator i = tasks.begin(); 
     368                while (i != tasks.end()) { 
     369                    RESULT* task = *i
     370                    std::string project_name; 
    379371 
    380                 if (result) { 
    381                     state_result = pDoc->state.lookup_result(result->project_url, result->name); 
    382                     if (state_result) { 
    383                         state_result->project->get_name(project_name); 
    384                         strProjectName = wxString(project_name.c_str()); 
     372                    if (task) { 
     373                        RESULT* state_result = pDoc->state.lookup_result(task->project_url, task->name); 
     374                        if (state_result) { 
     375                            state_result->project->get_name(project_name); 
     376                        } 
    385377                    } 
    386                     fProgress = floor(result->fraction_done*10000)/100; 
     378                    fProgress = floor(task->fraction_done*10000)/100; 
     379                 
     380                    strBuffer.Printf(wxT("\n%s: %.2f%%"), project_name.c_str(), fProgress ); 
     381                    strMessage += strBuffer; 
     382                    i++; 
    387383                } 
    388  
    389                 strBuffer.Printf(wxT("%s: %.2f%%\n"), strProjectName.c_str(), fProgress ); 
     384            } else { 
     385                strBuffer.Printf(_("\n%d running tasks."), tasks.size()); 
    390386                strMessage += strBuffer; 
    391387            } 
     388 
    392389        } else if (pDoc->IsReconnecting()) { 
    393390            // 1st %s is the previous instance of the message 
    394391            // 2nd %s is the application name 
     
    396393            // 3rd %s is the project name 
    397394            //    i.e. 'BOINC', 'GridRepublic' 
    398395            strBuffer.Printf( 
    399                 _("Reconnecting to client.\n") 
     396                _("\nReconnecting to client.") 
    400397            ); 
    401398            strMessage += strBuffer; 
    402399        } else { 
     
    406403            // 3rd %s is the project name 
    407404            //    i.e. 'BOINC', 'GridRepublic' 
    408405            strBuffer.Printf( 
    409                 _("Not connected to a client.\n") 
     406                _("\nNot connected to a client.") 
    410407            ); 
    411408            iconIcon = m_iconTaskBarDisconnected; 
    412409            strMessage += strBuffer; 
    413410        } 
    414411 
    415         SetBalloon(iconIcon, strTitle, strMessage); 
     412        SetTooltip(strMessage); 
    416413    } 
    417414} 
    418415 
    419416 
     417std::vector<RESULT*> CTaskBarIcon::GetRunningTasks(CMainDocument* pDoc) { 
     418 
     419    std::vector<RESULT*> results; 
     420    bool bIsActive, bIsExecuting, bIsDownloaded; 
     421     
     422    int iResultCount = pDoc->GetWorkCount(); 
     423 
     424    for (int iIndex = 0; iIndex < iResultCount; iIndex++) { 
     425        RESULT* result = pDoc->result(iIndex); 
     426 
     427        if (result) { 
     428            bIsDownloaded = (result->state == RESULT_FILES_DOWNLOADED); 
     429            bIsActive     = result->active_task; 
     430            bIsExecuting  = (result->scheduler_state == CPU_SCHED_SCHEDULED); 
     431            if (bIsActive && bIsDownloaded && bIsExecuting) { 
     432                results.push_back(result); 
     433            } 
     434        } 
     435    } 
     436    return results; 
     437} 
     438 
     439 
    420440void CTaskBarIcon::OnContextMenu(wxTaskBarIconExEvent& WXUNUSED(event)) { 
    421441    DisplayContextMenu(); 
    422442} 
     
    469489    SetIcon(m_iconTaskBarNormal, wxT("")); 
    470490#endif 
    471491 
    472     m_dtLastBalloonDisplayed = wxDateTime::Now(); 
    473492} 
    474493 
    475494 
  • clientgui/BOINCTaskBar.h

    old new  
    2424#pragma interface "BOINCTaskBar.cpp" 
    2525#endif 
    2626 
     27#include "MainDocument.h" 
    2728 
    2829#ifdef __WXMSW__ 
    2930#include "msw/taskbarex.h" 
     
    8182 
    8283private: 
    8384    wxDateTime m_dtLastHoverDetected; 
    84     wxDateTime m_dtLastBalloonDisplayed; 
    8585 
    8686    wxTimer*   m_pRefreshTimer; 
    8787 
    8888    bool       m_bMouseButtonPressed; 
    8989 
    9090    void       ResetTaskBar(); 
    91  
    9291    void       DisplayContextMenu(); 
     92    std::vector<RESULT*> GetRunningTasks(CMainDocument* pDoc); 
    9393     
    9494    DECLARE_EVENT_TABLE() 
    9595 
     
    126126 
    127127#endif 
    128128 
     129 
     130 
  • clientgui/msw/taskbarex.cpp

    old new  
    9494 
    9595void wxTaskBarIconEx::OnTaskBarCreated(wxTaskBarIconExEvent& WXUNUSED(event)) 
    9696{ 
    97     m_iconAdded = (Shell_NotifyIcon(NIM_ADD, &notifyData) != 0)
    98     Shell_NotifyIcon(NIM_SETVERSION, &notifyData); 
     97    m_iconAdded = false
     98    RecreateIcon(); 
    9999} 
    100100 
    101101// Operations 
     
    124124        lstrcpyn(notifyData.szTip, WXSTRINGCAST tooltip, sizeof(notifyData.szTip)); 
    125125    } 
    126126 
    127  
    128     if (m_iconAdded) 
    129         return (Shell_NotifyIcon(NIM_MODIFY, &notifyData) != 0); 
    130     else 
    131     { 
    132         m_iconAdded = (Shell_NotifyIcon(NIM_ADD, &notifyData) != 0); 
    133         if (IsBalloonsSupported()) 
    134             Shell_NotifyIcon(NIM_SETVERSION, &notifyData); 
    135         return m_iconAdded; 
    136     } 
     127    return RecreateIcon(); 
    137128} 
    138129 
    139130bool wxTaskBarIconEx::SetBalloon(const wxIcon& icon, const wxString title, const wxString message, unsigned int timeout, unsigned int iconballoon) 
     
    175166        lstrcpyn(notifyData.szTip, WXSTRINGCAST strTip, sizeof(notifyData.szTip)); 
    176167    } 
    177168 
    178     if (m_iconAdded) 
    179         return (Shell_NotifyIcon(NIM_MODIFY, & notifyData) != 0); 
    180     else 
    181     { 
    182         m_iconAdded = (Shell_NotifyIcon(NIM_ADD, & notifyData) != 0); 
    183         if (IsBalloonsSupported()) 
    184             Shell_NotifyIcon(NIM_SETVERSION, &notifyData); 
    185         return m_iconAdded; 
    186     } 
     169    return RecreateIcon(); 
    187170} 
    188171 
     172bool wxTaskBarIconEx::SetTooltip(const wxString tip) 
     173{ 
     174        if (!IsOK()) 
     175            return false; 
     176 
     177    memset(&notifyData, 0, sizeof(notifyData)); 
     178    notifyData.cbSize           = sizeof(notifyData); 
     179    notifyData.hWnd             = (HWND) m_hWnd; 
     180    notifyData.uID              = 99; 
     181    notifyData.uCallbackMessage = sm_taskbarMsg; 
     182    notifyData.uFlags           = NIF_TIP; 
     183    notifyData.uVersion         = NOTIFYICON_VERSION; 
     184 
     185    lstrcpyn(notifyData.szTip, WXSTRINGCAST tip, sizeof(notifyData.szTip)); 
     186 
     187    return RecreateIcon(); 
     188} 
     189 
     190 
    189191bool wxTaskBarIconEx::RemoveIcon(void) 
    190192{ 
    191193    if (!m_iconAdded) 
     
    419421    return lReturnValue; 
    420422} 
    421423 
     424 
     425bool wxTaskBarIconEx::RecreateIcon() { 
     426    
     427    if (m_iconAdded) 
     428        return (Shell_NotifyIcon(NIM_MODIFY, &notifyData) != 0); 
     429    else { 
     430        m_iconAdded = (Shell_NotifyIcon(NIM_ADD, &notifyData) != 0); 
     431        if (IsBalloonsSupported()) 
     432            Shell_NotifyIcon(NIM_SETVERSION, &notifyData); 
     433        return m_iconAdded; 
     434    } 
     435} 
     436 
    422437LRESULT APIENTRY wxTaskBarIconExWindowProc( HWND hWnd, unsigned msg, UINT wParam, LONG lParam ) 
    423438{ 
    424439    return wxGetApp().GetTaskBarIcon()->WindowProc((WXHWND) hWnd, msg, wParam, lParam); 
  • clientgui/msw/taskbarex.h

    old new  
    2626 
    2727class wxTaskBarIconEx: public wxEvtHandler { 
    2828    DECLARE_DYNAMIC_CLASS(wxTaskBarIconEx) 
     29    DECLARE_EVENT_TABLE() 
    2930public: 
    3031 
    3132    wxTaskBarIconEx(void); 
     
    5758        unsigned int iconballoon = NIIF_INFO 
    5859    ); 
    5960 
     61        bool SetTooltip(const wxString tip); 
     62 
    6063    bool RemoveIcon(); 
    6164 
    6265    bool PopupMenu(wxMenu *menu); //, int x, int y); 
     
    7679    static unsigned int sm_taskbarMsg; 
    7780 
    7881private: 
    79     DECLARE_EVENT_TABLE() 
     82    bool RecreateIcon(); 
    8083 
    8184}; 
    8285 
     
    135138 
    136139 
    137140 
     141 
     142 

If this page is incomplete or incorrect, please edit it or add it to the wiki to-do list. To do this, you must be logged in; click Login or Register above.