2004-10-23 07:13:18 +00:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
// Revision History:
|
|
|
|
//
|
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "TaskBarIcon.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
|
|
|
#include "BOINCGUIApp.h"
|
|
|
|
#include "TaskBarIcon.h"
|
2004-10-24 05:40:12 +00:00
|
|
|
#include "DlgAbout.h"
|
|
|
|
#include "Events.h"
|
2004-10-23 07:13:18 +00:00
|
|
|
|
|
|
|
#include "res/boinc.xpm"
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CTaskBarIcon, wxTaskBarIcon)
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE (CTaskBarIcon, wxTaskBarIcon)
|
2004-10-24 05:40:12 +00:00
|
|
|
EVT_MENU(wxID_OPEN, CTaskBarIcon::OnOpen)
|
2004-10-24 07:38:38 +00:00
|
|
|
EVT_MENU_RANGE(ID_TB_ACTIVITYRUNALWAYS, ID_TB_ACTIVITYSUSPEND, CTaskBarIcon::OnActivitySelection)
|
|
|
|
EVT_MENU_RANGE(ID_TB_NETWORKRUNALWAYS, ID_TB_NETWORKSUSPEND, CTaskBarIcon::OnNetworkSelection)
|
2004-10-24 05:40:12 +00:00
|
|
|
EVT_MENU(wxID_ABOUT, CTaskBarIcon::OnAbout)
|
2004-10-23 23:40:11 +00:00
|
|
|
EVT_MENU(wxID_EXIT, CTaskBarIcon::OnExit)
|
2004-10-24 07:38:38 +00:00
|
|
|
EVT_CLOSE(CTaskBarIcon::OnClose)
|
2004-10-23 07:13:18 +00:00
|
|
|
END_EVENT_TABLE ()
|
|
|
|
|
|
|
|
|
|
|
|
CTaskBarIcon::CTaskBarIcon() :
|
|
|
|
wxTaskBarIcon()
|
|
|
|
{
|
2004-10-23 23:40:11 +00:00
|
|
|
iconTaskBarIcon = wxIcon( boinc_xpm );
|
2004-10-24 05:40:12 +00:00
|
|
|
dtLastMouseCaptureTime = wxDateTime( (time_t)0 );
|
2004-10-23 23:40:11 +00:00
|
|
|
|
|
|
|
SetIcon( iconTaskBarIcon, wxEmptyString );
|
2004-10-23 07:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CTaskBarIcon::~CTaskBarIcon()
|
|
|
|
{
|
|
|
|
RemoveIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
void CTaskBarIcon::OnOpen( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2004-10-25 00:56:16 +00:00
|
|
|
ResetTaskBar();
|
2004-10-24 21:30:29 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
CMainFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
wxASSERT(NULL != pFrame);
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CMainFrame));
|
|
|
|
|
|
|
|
if ( NULL != pFrame )
|
|
|
|
pFrame->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CTaskBarIcon::OnActivitySelection( wxCommandEvent& event )
|
|
|
|
{
|
2004-10-25 00:56:16 +00:00
|
|
|
ResetTaskBar();
|
2004-10-24 21:30:29 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(NULL != pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
switch( event.GetId() )
|
|
|
|
{
|
2004-10-24 07:38:38 +00:00
|
|
|
case ID_TB_ACTIVITYRUNALWAYS:
|
2004-10-24 05:40:12 +00:00
|
|
|
pDoc->SetActivityRunMode( CMainDocument::MODE_ALWAYS );
|
|
|
|
break;
|
2004-10-24 07:38:38 +00:00
|
|
|
case ID_TB_ACTIVITYSUSPEND:
|
2004-10-24 05:40:12 +00:00
|
|
|
pDoc->SetActivityRunMode( CMainDocument::MODE_NEVER );
|
|
|
|
break;
|
2004-10-24 07:38:38 +00:00
|
|
|
case ID_TB_ACTIVITYRUNBASEDONPREPERENCES:
|
2004-10-24 05:40:12 +00:00
|
|
|
pDoc->SetActivityRunMode( CMainDocument::MODE_AUTO );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CTaskBarIcon::OnNetworkSelection( wxCommandEvent& event )
|
|
|
|
{
|
2004-10-25 00:56:16 +00:00
|
|
|
ResetTaskBar();
|
2004-10-24 21:30:29 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(NULL != pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
switch( event.GetId() )
|
|
|
|
{
|
2004-10-24 07:38:38 +00:00
|
|
|
case ID_TB_NETWORKSUSPEND:
|
2004-10-24 05:40:12 +00:00
|
|
|
if ( event.IsChecked() )
|
|
|
|
{
|
|
|
|
pDoc->SetNetworkRunMode( CMainDocument::MODE_ALWAYS );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pDoc->SetNetworkRunMode( CMainDocument::MODE_NEVER );
|
|
|
|
}
|
|
|
|
break;
|
2004-10-24 07:38:38 +00:00
|
|
|
case ID_TB_NETWORKRUNALWAYS:
|
|
|
|
case ID_TB_NETWORKRUNBASEDONPREPERENCES:
|
2004-10-24 05:40:12 +00:00
|
|
|
default:
|
|
|
|
pDoc->SetNetworkRunMode( CMainDocument::MODE_ALWAYS );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CTaskBarIcon::OnAbout( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2004-10-25 00:56:16 +00:00
|
|
|
ResetTaskBar();
|
2004-10-24 21:30:29 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
CDlgAbout* pDlg = new CDlgAbout(NULL);
|
|
|
|
wxASSERT(NULL != pDlg);
|
|
|
|
|
|
|
|
pDlg->ShowModal();
|
|
|
|
|
|
|
|
if (pDlg)
|
|
|
|
pDlg->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
void CTaskBarIcon::OnExit( wxCommandEvent& WXUNUSED(event) )
|
2004-10-23 07:13:18 +00:00
|
|
|
{
|
2004-10-25 00:56:16 +00:00
|
|
|
ResetTaskBar();
|
2004-10-24 21:30:29 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
CMainFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
wxASSERT(NULL != pFrame);
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CMainFrame));
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
if ( NULL != pFrame )
|
|
|
|
pFrame->Close(true);
|
2004-10-23 07:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
void CTaskBarIcon::OnClose( wxCloseEvent& event )
|
2004-10-23 07:13:18 +00:00
|
|
|
{
|
2004-10-25 00:56:16 +00:00
|
|
|
ResetTaskBar();
|
2004-10-24 21:30:29 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
CMainFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
wxASSERT(NULL != pFrame);
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CMainFrame));
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
if ( NULL != pFrame )
|
|
|
|
pFrame->Close(true);
|
2004-10-23 07:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
void CTaskBarIcon::OnMouseMove( wxEvent& event )
|
2004-10-23 07:13:18 +00:00
|
|
|
{
|
2004-10-24 05:40:12 +00:00
|
|
|
wxTimeSpan ts(wxDateTime::Now() - dtLastMouseCaptureTime);
|
2004-10-23 23:40:11 +00:00
|
|
|
|
2004-10-25 00:56:16 +00:00
|
|
|
if ( ts.GetSeconds() >= 5 )
|
2004-10-23 23:40:11 +00:00
|
|
|
{
|
|
|
|
dtLastMouseCaptureTime = wxDateTime::Now();
|
|
|
|
|
|
|
|
wxString strTitle = wxGetApp().GetAppName();
|
|
|
|
wxString strMessage = wxEmptyString;
|
|
|
|
wxString strBuffer = wxEmptyString;
|
|
|
|
wxString strProjectName = wxEmptyString;
|
|
|
|
wxString strResultName = wxEmptyString;
|
|
|
|
float fProgress = 0;
|
|
|
|
bool bIsActive = false;
|
|
|
|
bool bIsExecuting = false;
|
|
|
|
bool bIsDownloaded = false;
|
|
|
|
wxInt32 iResultCount = 0;
|
|
|
|
wxInt32 iIndex = 0;
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(NULL != pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
iResultCount = pDoc->GetWorkCount();
|
|
|
|
|
|
|
|
for ( iIndex = 0; iIndex < iResultCount; iIndex++ )
|
|
|
|
{
|
|
|
|
bIsDownloaded = ( CMainDocument::RESULT_FILES_DOWNLOADED == pDoc->GetWorkState( iIndex ) );
|
|
|
|
bIsActive = ( pDoc->IsWorkActive( iIndex ) );
|
|
|
|
bIsExecuting = ( CMainDocument::CPU_SCHED_SCHEDULED == pDoc->GetWorkSchedulerState( iIndex ) );
|
|
|
|
if ( !( bIsActive ) || !( bIsDownloaded ) || !( bIsExecuting ) ) continue;
|
|
|
|
|
|
|
|
pDoc->GetWorkProjectName( iIndex, strProjectName );
|
|
|
|
pDoc->GetWorkName( iIndex, strResultName );
|
|
|
|
pDoc->GetWorkFractionDone( iIndex, fProgress );
|
|
|
|
|
|
|
|
strBuffer.Printf(wxT( "%s: %s: %.2f%%\n"), strProjectName.c_str(), strResultName.c_str(), fProgress * 100 );
|
|
|
|
strMessage += strBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowBalloon( strTitle, strMessage );
|
|
|
|
}
|
2004-10-23 07:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CTaskBarIcon::OnRButtonDown( wxEvent& event )
|
|
|
|
{
|
2004-10-25 00:56:16 +00:00
|
|
|
ResetTaskBar();
|
2004-10-24 07:43:33 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
wxMenu* menu = new wxMenu;
|
|
|
|
wxInt32 iActivityMode = -1;
|
|
|
|
wxInt32 iNetworkMode = -1;
|
|
|
|
|
|
|
|
wxASSERT(NULL != pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
wxASSERT(NULL != menu);
|
|
|
|
|
|
|
|
menu->Append( wxID_OPEN, _("&Open"), wxEmptyString );
|
|
|
|
menu->AppendSeparator();
|
2004-10-24 07:38:38 +00:00
|
|
|
menu->AppendRadioItem( ID_TB_ACTIVITYRUNALWAYS, _("&Run always"), wxEmptyString );
|
|
|
|
menu->AppendRadioItem( ID_TB_ACTIVITYRUNBASEDONPREPERENCES, _("Run based on &preferences"), wxEmptyString );
|
|
|
|
menu->AppendRadioItem( ID_TB_ACTIVITYSUSPEND, _("&Suspend"), wxEmptyString );
|
2004-10-24 05:40:12 +00:00
|
|
|
menu->AppendSeparator();
|
2004-10-24 07:38:38 +00:00
|
|
|
menu->AppendCheckItem( ID_TB_NETWORKSUSPEND, _("&Disable BOINC Network Access"), wxEmptyString );
|
2004-10-24 05:40:12 +00:00
|
|
|
menu->AppendSeparator();
|
|
|
|
menu->Append( wxID_ABOUT, _("&About BOINC Manager..."), wxEmptyString );
|
|
|
|
menu->AppendSeparator();
|
|
|
|
menu->Append( wxID_EXIT, _("E&xit"), wxEmptyString );
|
|
|
|
|
|
|
|
pDoc->GetActivityRunMode( iActivityMode );
|
|
|
|
switch( iActivityMode )
|
|
|
|
{
|
|
|
|
case CMainDocument::MODE_ALWAYS:
|
2004-10-24 07:38:38 +00:00
|
|
|
menu->Check( ID_TB_ACTIVITYRUNALWAYS, true );
|
2004-10-24 05:40:12 +00:00
|
|
|
break;
|
|
|
|
case CMainDocument::MODE_NEVER:
|
2004-10-24 07:38:38 +00:00
|
|
|
menu->Check( ID_TB_ACTIVITYSUSPEND, true );
|
2004-10-24 05:40:12 +00:00
|
|
|
break;
|
|
|
|
case CMainDocument::MODE_AUTO:
|
2004-10-24 07:38:38 +00:00
|
|
|
menu->Check( ID_TB_ACTIVITYRUNBASEDONPREPERENCES, true );
|
2004-10-24 05:40:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
pDoc->GetNetworkRunMode( iNetworkMode );
|
|
|
|
switch( iNetworkMode )
|
|
|
|
{
|
|
|
|
case CMainDocument::MODE_NEVER:
|
2004-10-24 07:38:38 +00:00
|
|
|
menu->Check( ID_TB_NETWORKSUSPEND, true );
|
2004-10-24 05:40:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-10-24 07:38:38 +00:00
|
|
|
menu->Check( ID_TB_NETWORKSUSPEND, false );
|
2004-10-24 05:40:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
PopupMenu( menu );
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
delete menu;
|
2004-10-23 07:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
void CTaskBarIcon::OnLButtonDClick( wxEvent& event )
|
2004-10-23 07:13:18 +00:00
|
|
|
{
|
2004-10-25 00:56:16 +00:00
|
|
|
ResetTaskBar();
|
2004-10-24 21:30:29 +00:00
|
|
|
|
2004-10-24 05:40:12 +00:00
|
|
|
CMainFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
wxASSERT(NULL != pFrame);
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CMainFrame));
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
if ( NULL != pFrame )
|
|
|
|
pFrame->Show();
|
2004-10-23 07:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
bool CTaskBarIcon::ShowBalloon( wxString title, wxString message, unsigned int timeout, ICONTYPES icon )
|
2004-10-23 07:13:18 +00:00
|
|
|
{
|
|
|
|
if (!IsOK())
|
|
|
|
return false;
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
wxInt32 iPlatform = 0;
|
|
|
|
wxInt32 iMajorVersion = 0;
|
|
|
|
wxInt32 iMinorVersion = 0;
|
|
|
|
bool bRetVal = false;
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
iPlatform = wxGetOsVersion( &iMajorVersion, &iMinorVersion );
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
#ifdef __WXMSW__
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
if ( ( wxWINDOWS_NT == iPlatform ) && ( 5 >= iMajorVersion ) )
|
|
|
|
{
|
|
|
|
NOTIFYICONDATA notifyData;
|
|
|
|
|
|
|
|
memset(¬ifyData, 0, sizeof(notifyData));
|
|
|
|
|
|
|
|
notifyData.cbSize = sizeof(notifyData);
|
|
|
|
notifyData.hWnd = (HWND) m_hWnd;
|
|
|
|
notifyData.uID = 99;
|
|
|
|
notifyData.uCallbackMessage = sm_taskbarMsg;
|
|
|
|
notifyData.uFlags = NIF_MESSAGE | NIF_INFO;
|
|
|
|
notifyData.dwInfoFlags = icon | NIIF_NOSOUND;
|
|
|
|
notifyData.uTimeout = timeout;
|
|
|
|
lstrcpyn(notifyData.szInfo, WXSTRINGCAST message, sizeof(notifyData.szInfo));
|
|
|
|
lstrcpyn(notifyData.szInfoTitle, WXSTRINGCAST title, sizeof(notifyData.szInfoTitle));
|
|
|
|
|
|
|
|
if (m_iconAdded)
|
|
|
|
bRetVal = (Shell_NotifyIcon(NIM_MODIFY, ¬ifyData) != 0);
|
|
|
|
}
|
2004-10-23 07:13:18 +00:00
|
|
|
else
|
2004-10-23 23:40:11 +00:00
|
|
|
{
|
|
|
|
wxString strMessage;
|
|
|
|
strMessage = title + wxT("\n") + message;
|
|
|
|
SetIcon( iconTaskBarIcon, strMessage );
|
|
|
|
}
|
2004-10-23 07:13:18 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
return bRetVal;
|
2004-10-23 07:13:18 +00:00
|
|
|
}
|
2004-10-25 00:56:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
void CTaskBarIcon::ResetTaskBar()
|
|
|
|
{
|
|
|
|
ShowBalloon( wxT(""), wxT("") );
|
|
|
|
dtLastMouseCaptureTime = wxDateTime::Now();
|
|
|
|
}
|
|
|
|
|