Ticket #9: taskbar.patch
File taskbar.patch, 11.4 KB (added by , 17 years ago) |
---|
-
clientgui/BOINCTaskBar.cpp
88 88 m_bTaskbarInitiatedShutdown = false; 89 89 90 90 m_dtLastHoverDetected = wxDateTime((time_t)0); 91 m_dtLastBalloonDisplayed = wxDateTime((time_t)0);92 91 93 92 m_bMouseButtonPressed = false; 94 93 … … 303 302 304 303 305 304 void CTaskBarIcon::OnMouseMove(wxTaskBarIconEvent& WXUNUSED(event)) { 306 wxTimeSpan ts(wxDateTime::Now() - m_dtLastHoverDetected);307 if (ts.GetSeconds() >= 10) {308 m_dtLastHoverDetected = wxDateTime::Now();309 }310 305 311 306 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();315 307 308 if (tsLastHover.GetSeconds() >= 2) { 309 m_dtLastHoverDetected = wxDateTime::Now(); 310 316 311 CMainDocument* pDoc = wxGetApp().GetDocument(); 317 312 CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced(); 318 313 wxString strTitle = wxEmptyString; … … 321 316 wxString strBuffer = wxEmptyString; 322 317 wxString strProjectName = wxEmptyString; 323 318 float fProgress = 0; 324 bool bIsActive = false;325 bool bIsExecuting = false;326 bool bIsDownloaded = false;327 wxInt32 iResultCount = 0;328 wxInt32 iIndex = 0;329 319 wxIcon iconIcon = wxNullIcon; 330 320 CC_STATUS status; 331 321 … … 335 325 wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced)); 336 326 337 327 338 // What should the title of the balloonbe?328 // What should the title of the tooltip be? 339 329 strTitle = pSkinAdvanced->GetApplicationName(); 340 330 341 331 if (pDoc->IsConnected()) { 332 pDoc->GetConnectedComputerName(strMachineName); 333 if (!pDoc->IsComputerNameLocal(strMachineName)) { 334 strTitle = strTitle + wxT(" - (") + strMachineName + wxT(")"); 335 } 342 336 337 strMessage += strTitle; 338 343 339 pDoc->GetCoreClientStatus(status); 344 340 if (status.task_suspend_reason && !(status.task_suspend_reason & SUSPEND_REASON_CPU_USAGE_LIMIT)) { 345 341 // 1st %s is the previous instance of the message 346 342 // 2nd %s is the project name 347 343 // i.e. 'BOINC', 'GridRepublic' 348 344 strBuffer.Printf( 349 _(" Computation is suspended.\n")345 _("\nComputation is suspended.") 350 346 ); 351 347 iconIcon = m_iconTaskBarSnooze; 352 348 strMessage += strBuffer; … … 357 353 // 2nd %s is the project name 358 354 // i.e. 'BOINC', 'GridRepublic' 359 355 strBuffer.Printf( 360 _(" Network activity is suspended.\n")356 _("\nNetwork activity is suspended.") 361 357 ); 362 358 strMessage += strBuffer; 363 359 } 364 360 365 if (strMessage.Length() > 0) { 366 strMessage += wxT("\n"); 367 } 361 std::vector<RESULT*> tasks = GetRunningTasks(pDoc); 368 362 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) { 374 366 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; 379 371 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 } 385 377 } 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++; 387 383 } 388 389 strBuffer.Printf( wxT("%s: %.2f%%\n"), strProjectName.c_str(), fProgress);384 } else { 385 strBuffer.Printf(_("\n%d running tasks."), tasks.size()); 390 386 strMessage += strBuffer; 391 387 } 388 392 389 } else if (pDoc->IsReconnecting()) { 393 390 // 1st %s is the previous instance of the message 394 391 // 2nd %s is the application name … … 396 393 // 3rd %s is the project name 397 394 // i.e. 'BOINC', 'GridRepublic' 398 395 strBuffer.Printf( 399 _(" Reconnecting to client.\n")396 _("\nReconnecting to client.") 400 397 ); 401 398 strMessage += strBuffer; 402 399 } else { … … 406 403 // 3rd %s is the project name 407 404 // i.e. 'BOINC', 'GridRepublic' 408 405 strBuffer.Printf( 409 _(" Not connected to a client.\n")406 _("\nNot connected to a client.") 410 407 ); 411 408 iconIcon = m_iconTaskBarDisconnected; 412 409 strMessage += strBuffer; 413 410 } 414 411 415 Set Balloon(iconIcon, strTitle,strMessage);412 SetTooltip(strMessage); 416 413 } 417 414 } 418 415 419 416 417 std::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 420 440 void CTaskBarIcon::OnContextMenu(wxTaskBarIconExEvent& WXUNUSED(event)) { 421 441 DisplayContextMenu(); 422 442 } … … 469 489 SetIcon(m_iconTaskBarNormal, wxT("")); 470 490 #endif 471 491 472 m_dtLastBalloonDisplayed = wxDateTime::Now();473 492 } 474 493 475 494 -
clientgui/BOINCTaskBar.h
24 24 #pragma interface "BOINCTaskBar.cpp" 25 25 #endif 26 26 27 #include "MainDocument.h" 27 28 28 29 #ifdef __WXMSW__ 29 30 #include "msw/taskbarex.h" … … 81 82 82 83 private: 83 84 wxDateTime m_dtLastHoverDetected; 84 wxDateTime m_dtLastBalloonDisplayed;85 85 86 86 wxTimer* m_pRefreshTimer; 87 87 88 88 bool m_bMouseButtonPressed; 89 89 90 90 void ResetTaskBar(); 91 92 91 void DisplayContextMenu(); 92 std::vector<RESULT*> GetRunningTasks(CMainDocument* pDoc); 93 93 94 94 DECLARE_EVENT_TABLE() 95 95 … … 126 126 127 127 #endif 128 128 129 130 -
clientgui/msw/taskbarex.cpp
94 94 95 95 void wxTaskBarIconEx::OnTaskBarCreated(wxTaskBarIconExEvent& WXUNUSED(event)) 96 96 { 97 m_iconAdded = (Shell_NotifyIcon(NIM_ADD, ¬ifyData) != 0);98 Shell_NotifyIcon(NIM_SETVERSION, ¬ifyData);97 m_iconAdded = false; 98 RecreateIcon(); 99 99 } 100 100 101 101 // Operations … … 124 124 lstrcpyn(notifyData.szTip, WXSTRINGCAST tooltip, sizeof(notifyData.szTip)); 125 125 } 126 126 127 128 if (m_iconAdded) 129 return (Shell_NotifyIcon(NIM_MODIFY, ¬ifyData) != 0); 130 else 131 { 132 m_iconAdded = (Shell_NotifyIcon(NIM_ADD, ¬ifyData) != 0); 133 if (IsBalloonsSupported()) 134 Shell_NotifyIcon(NIM_SETVERSION, ¬ifyData); 135 return m_iconAdded; 136 } 127 return RecreateIcon(); 137 128 } 138 129 139 130 bool wxTaskBarIconEx::SetBalloon(const wxIcon& icon, const wxString title, const wxString message, unsigned int timeout, unsigned int iconballoon) … … 175 166 lstrcpyn(notifyData.szTip, WXSTRINGCAST strTip, sizeof(notifyData.szTip)); 176 167 } 177 168 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, ¬ifyData); 185 return m_iconAdded; 186 } 169 return RecreateIcon(); 187 170 } 188 171 172 bool wxTaskBarIconEx::SetTooltip(const wxString tip) 173 { 174 if (!IsOK()) 175 return false; 176 177 memset(¬ifyData, 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 189 191 bool wxTaskBarIconEx::RemoveIcon(void) 190 192 { 191 193 if (!m_iconAdded) … … 419 421 return lReturnValue; 420 422 } 421 423 424 425 bool wxTaskBarIconEx::RecreateIcon() { 426 427 if (m_iconAdded) 428 return (Shell_NotifyIcon(NIM_MODIFY, ¬ifyData) != 0); 429 else { 430 m_iconAdded = (Shell_NotifyIcon(NIM_ADD, ¬ifyData) != 0); 431 if (IsBalloonsSupported()) 432 Shell_NotifyIcon(NIM_SETVERSION, ¬ifyData); 433 return m_iconAdded; 434 } 435 } 436 422 437 LRESULT APIENTRY wxTaskBarIconExWindowProc( HWND hWnd, unsigned msg, UINT wParam, LONG lParam ) 423 438 { 424 439 return wxGetApp().GetTaskBarIcon()->WindowProc((WXHWND) hWnd, msg, wParam, lParam); -
clientgui/msw/taskbarex.h
26 26 27 27 class wxTaskBarIconEx: public wxEvtHandler { 28 28 DECLARE_DYNAMIC_CLASS(wxTaskBarIconEx) 29 DECLARE_EVENT_TABLE() 29 30 public: 30 31 31 32 wxTaskBarIconEx(void); … … 57 58 unsigned int iconballoon = NIIF_INFO 58 59 ); 59 60 61 bool SetTooltip(const wxString tip); 62 60 63 bool RemoveIcon(); 61 64 62 65 bool PopupMenu(wxMenu *menu); //, int x, int y); … … 76 79 static unsigned int sm_taskbarMsg; 77 80 78 81 private: 79 DECLARE_EVENT_TABLE()82 bool RecreateIcon(); 80 83 81 84 }; 82 85 … … 135 138 136 139 137 140 141 142