2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2006-08-18 21:45:17 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2006-08-18 21:45:17 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2006-08-18 21:45:17 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-08-18 21:45:17 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2006-08-18 21:45:17 +00:00
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "sg_ClientStateIndicator.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
2006-10-20 15:00:14 +00:00
|
|
|
#include "diagnostics.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "mfile.h"
|
|
|
|
#include "miofile.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "error_numbers.h"
|
2006-08-18 21:45:17 +00:00
|
|
|
#include "BOINCGUIApp.h"
|
2006-10-20 15:00:14 +00:00
|
|
|
#include "SkinManager.h"
|
|
|
|
#include "MainDocument.h"
|
|
|
|
#include "BOINCBaseFrame.h"
|
2006-08-18 21:45:17 +00:00
|
|
|
#include "sg_BoincSimpleGUI.h"
|
|
|
|
#include "sg_ImageLoader.h"
|
|
|
|
#include "sg_ClientStateIndicator.h"
|
2006-08-23 21:22:41 +00:00
|
|
|
#include "time.h"
|
2006-08-18 21:45:17 +00:00
|
|
|
|
|
|
|
#define ID_ANIMATIONRENDERTIMER 12000
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(ClientStateIndicator, wxPanel)
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(ClientStateIndicator, wxPanel)
|
|
|
|
EVT_PAINT(ClientStateIndicator::OnPaint)
|
|
|
|
EVT_ERASE_BACKGROUND(ClientStateIndicator::OnEraseBackground)
|
|
|
|
EVT_TIMER(ID_ANIMATIONRENDERTIMER, ClientStateIndicator::RunConnectionAnimation)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
ClientStateIndicator::ClientStateIndicator() {}
|
|
|
|
|
2006-11-06 13:45:50 +00:00
|
|
|
ClientStateIndicator::ClientStateIndicator(CSimplePanel* parent,wxPoint coord) :
|
2006-10-20 15:00:14 +00:00
|
|
|
wxPanel(parent, wxID_ANY, coord, wxSize(343,314), wxNO_BORDER)
|
2006-08-18 21:45:17 +00:00
|
|
|
{
|
2006-10-25 22:18:16 +00:00
|
|
|
m_connRenderTimer = NULL;
|
2006-08-18 21:45:17 +00:00
|
|
|
connIndicatorWidth = 14;
|
|
|
|
connIndicatorHeight = 15;
|
2006-08-24 17:54:54 +00:00
|
|
|
numOfIndic = 5;
|
2006-08-18 21:45:17 +00:00
|
|
|
indexIndVis = 1;//first will be visible on start
|
2006-08-24 17:54:54 +00:00
|
|
|
rightPosition = 118;
|
2006-08-18 21:45:17 +00:00
|
|
|
topPosition = 5;
|
2006-10-25 21:51:37 +00:00
|
|
|
stateMessage = wxEmptyString;
|
2006-08-24 17:54:54 +00:00
|
|
|
clientState = CLIENT_STATE_NONE;
|
2006-08-18 21:45:17 +00:00
|
|
|
CreateComponent();
|
2006-08-23 21:22:41 +00:00
|
|
|
error_time = 0;
|
2006-08-18 21:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ClientStateIndicator::~ClientStateIndicator()
|
|
|
|
{
|
2006-10-25 22:18:16 +00:00
|
|
|
if (m_connRenderTimer) {
|
2006-10-25 21:51:37 +00:00
|
|
|
m_connRenderTimer->Stop();
|
|
|
|
delete m_connRenderTimer;
|
|
|
|
}
|
2006-08-18 21:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientStateIndicator::CreateComponent(){
|
2006-10-23 06:48:48 +00:00
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
|
|
|
|
wxASSERT(pSkinSimple);
|
|
|
|
wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));
|
|
|
|
|
2006-08-18 21:45:17 +00:00
|
|
|
//Set Background color
|
2006-10-23 06:48:48 +00:00
|
|
|
SetBackgroundColour(*pSkinSimple->GetBackgroundImage()->GetBackgroundColor());
|
2006-08-18 21:45:17 +00:00
|
|
|
}
|
2006-10-23 06:48:48 +00:00
|
|
|
|
|
|
|
|
2006-12-20 00:05:12 +00:00
|
|
|
void ClientStateIndicator::SetActionState(wxString message)
|
2006-08-18 21:45:17 +00:00
|
|
|
{
|
2006-10-23 06:48:48 +00:00
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
|
|
|
|
wxASSERT(pSkinSimple);
|
|
|
|
wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));
|
|
|
|
|
2006-08-18 21:45:17 +00:00
|
|
|
Freeze();
|
2006-12-20 00:05:12 +00:00
|
|
|
stateMessage = message;
|
2006-08-24 17:54:54 +00:00
|
|
|
if ( clientState != CLIENT_STATE_ACTION ) {
|
|
|
|
//Delete Previous state
|
|
|
|
DeletePreviousState();
|
2006-08-18 21:45:17 +00:00
|
|
|
|
2006-08-24 17:54:54 +00:00
|
|
|
clientState = CLIENT_STATE_ACTION;
|
|
|
|
i_indBg = new ImageLoader(this);
|
|
|
|
i_indBg->Move(wxPoint(42,74));
|
2006-10-23 06:48:48 +00:00
|
|
|
i_indBg->LoadImage(*(pSkinSimple->GetStateIndicatorBackgroundImage()->GetBitmap()));
|
2006-08-18 21:45:17 +00:00
|
|
|
|
2006-08-24 17:54:54 +00:00
|
|
|
for(int x = 0; x < numOfIndic; x++){
|
|
|
|
ImageLoader *i_connInd = new ImageLoader(this);
|
|
|
|
i_connInd->Move(wxPoint(rightPosition +(connIndicatorWidth+10) * x,84));
|
2006-10-23 06:48:48 +00:00
|
|
|
i_connInd->LoadImage(*(pSkinSimple->GetConnectingIndicatorImage()->GetBitmap()));
|
2006-08-24 17:54:54 +00:00
|
|
|
if(x !=0){
|
|
|
|
i_connInd->Show(false);
|
|
|
|
}
|
|
|
|
m_connIndV.push_back(i_connInd);
|
|
|
|
}
|
|
|
|
//set animation timer for interface
|
2006-10-25 22:18:16 +00:00
|
|
|
if ( !m_connRenderTimer ) {
|
|
|
|
m_connRenderTimer = new wxTimer(this, ID_ANIMATIONRENDERTIMER);
|
|
|
|
}
|
2006-08-24 17:54:54 +00:00
|
|
|
m_connRenderTimer->Start(500);
|
|
|
|
}
|
|
|
|
Thaw();
|
|
|
|
}
|
|
|
|
|
2006-12-20 00:05:12 +00:00
|
|
|
void ClientStateIndicator::SetPausedState(wxString message)
|
2006-08-24 17:54:54 +00:00
|
|
|
{
|
2006-10-23 06:48:48 +00:00
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
|
|
|
|
wxASSERT(pSkinSimple);
|
|
|
|
wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));
|
|
|
|
|
2006-08-24 17:54:54 +00:00
|
|
|
Freeze();
|
2006-12-20 00:05:12 +00:00
|
|
|
stateMessage = message;
|
2006-08-24 17:54:54 +00:00
|
|
|
if ( clientState != CLIENT_STATE_PAUSED ) {
|
|
|
|
//Delete Previous state
|
|
|
|
DeletePreviousState();
|
|
|
|
|
|
|
|
clientState = CLIENT_STATE_PAUSED;
|
|
|
|
i_indBg = new ImageLoader(this);
|
|
|
|
i_indBg->Move(wxPoint(42,74));
|
2006-10-23 06:48:48 +00:00
|
|
|
i_indBg->LoadImage(*(pSkinSimple->GetStateIndicatorBackgroundImage()->GetBitmap()));
|
2006-08-24 17:54:54 +00:00
|
|
|
|
2006-08-18 21:45:17 +00:00
|
|
|
|
2006-08-24 17:54:54 +00:00
|
|
|
for(int x = 0; x < numOfIndic; x++){
|
|
|
|
ImageLoader *i_connInd = new ImageLoader(this);
|
|
|
|
i_connInd->Move(wxPoint(rightPosition +(connIndicatorWidth+10) * x,84));
|
2006-10-23 06:48:48 +00:00
|
|
|
i_connInd->LoadImage(*(pSkinSimple->GetConnectingIndicatorImage()->GetBitmap()));
|
2006-08-24 17:54:54 +00:00
|
|
|
m_connIndV.push_back(i_connInd);
|
2006-08-18 21:45:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Thaw();
|
|
|
|
}
|
2006-12-20 00:05:12 +00:00
|
|
|
void ClientStateIndicator::SetNoActionState(wxString message)
|
2006-08-18 21:45:17 +00:00
|
|
|
{
|
2006-10-23 06:48:48 +00:00
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
|
|
|
|
wxASSERT(pSkinSimple);
|
|
|
|
wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));
|
|
|
|
|
2006-08-18 21:45:17 +00:00
|
|
|
Freeze();
|
2006-12-20 00:05:12 +00:00
|
|
|
stateMessage = message;
|
2006-08-18 21:45:17 +00:00
|
|
|
|
2006-08-24 17:54:54 +00:00
|
|
|
if ( clientState != CLIENT_STATE_ERROR ) {
|
|
|
|
//Delete Previous state
|
|
|
|
DeletePreviousState();
|
|
|
|
|
|
|
|
clientState = CLIENT_STATE_ERROR;
|
|
|
|
i_indBg = new ImageLoader(this);
|
|
|
|
i_indBg->Move(wxPoint(42,74));
|
2006-10-23 06:48:48 +00:00
|
|
|
i_indBg->LoadImage(*(pSkinSimple->GetStateIndicatorBackgroundImage()->GetBitmap()));
|
2006-08-24 17:54:54 +00:00
|
|
|
|
|
|
|
i_errorInd = new ImageLoader(this);
|
|
|
|
i_errorInd->Move(wxPoint(rightPosition+24,84));
|
2006-10-23 06:48:48 +00:00
|
|
|
i_errorInd->LoadImage(*(pSkinSimple->GetErrorIndicatorImage()->GetBitmap()));
|
2006-08-24 17:54:54 +00:00
|
|
|
i_errorInd->Refresh();
|
|
|
|
}
|
2006-08-18 21:45:17 +00:00
|
|
|
Thaw();
|
|
|
|
}
|
|
|
|
void ClientStateIndicator::DeletePreviousState()
|
|
|
|
{
|
2006-08-24 17:54:54 +00:00
|
|
|
if(clientState == CLIENT_STATE_ACTION || clientState == CLIENT_STATE_PAUSED){
|
|
|
|
if (m_connRenderTimer && clientState == CLIENT_STATE_ACTION) {
|
2006-08-18 21:45:17 +00:00
|
|
|
m_connRenderTimer->Stop();
|
|
|
|
delete m_connRenderTimer;
|
2006-10-25 22:18:16 +00:00
|
|
|
m_connRenderTimer = NULL;
|
2006-08-18 21:45:17 +00:00
|
|
|
}
|
|
|
|
for(int indIndex = 0; indIndex < numOfIndic; indIndex++){
|
|
|
|
delete m_connIndV.at(indIndex);
|
|
|
|
}
|
|
|
|
//clear vector
|
|
|
|
if(m_connIndV.size() > 0){
|
|
|
|
m_connIndV.clear();
|
|
|
|
}
|
|
|
|
//delete ind bg
|
|
|
|
delete i_indBg;
|
2006-08-24 17:54:54 +00:00
|
|
|
}else if(clientState == CLIENT_STATE_ERROR){
|
2006-08-18 21:45:17 +00:00
|
|
|
delete i_errorInd;
|
|
|
|
//delete ind bg
|
|
|
|
delete i_indBg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void ClientStateIndicator::RunConnectionAnimation(wxTimerEvent& WXUNUSED(event)){
|
|
|
|
|
|
|
|
if(indexIndVis < numOfIndic){
|
|
|
|
indexIndVis++;
|
|
|
|
for(int j = 0; j < indexIndVis; j++){
|
|
|
|
ImageLoader *currInd = m_connIndV[j];
|
|
|
|
currInd->Show(true);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
indexIndVis = 0;
|
|
|
|
for(int i = 0; i < numOfIndic; i++){
|
|
|
|
ImageLoader *currInd = m_connIndV[i];
|
|
|
|
currInd->Show(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void ClientStateIndicator::ReskinInterface()
|
|
|
|
{
|
2006-08-23 21:22:41 +00:00
|
|
|
DisplayState();
|
2006-08-18 21:45:17 +00:00
|
|
|
}
|
|
|
|
void ClientStateIndicator::OnPaint(wxPaintEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
2006-08-24 17:54:54 +00:00
|
|
|
//set font
|
2006-08-18 21:45:17 +00:00
|
|
|
dc.SetFont(wxFont(9,74,90,90,0,wxT("Arial")));
|
2006-08-24 17:54:54 +00:00
|
|
|
// center the text
|
|
|
|
wxCoord height, width;
|
|
|
|
dc.GetTextExtent(stateMessage, &width, &height);
|
|
|
|
dc.DrawText(stateMessage, wxPoint(176-width/2,120));
|
2006-08-18 21:45:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
void ClientStateIndicator::OnEraseBackground(wxEraseEvent& event){
|
2006-10-23 06:48:48 +00:00
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
|
|
|
|
wxASSERT(pSkinSimple);
|
|
|
|
wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));
|
2006-08-18 21:45:17 +00:00
|
|
|
|
|
|
|
event.Skip(false);
|
|
|
|
wxDC *dc;
|
|
|
|
dc=event.GetDC();
|
|
|
|
dc->SetBackground(wxBrush(this->GetBackgroundColour(),wxSOLID));
|
|
|
|
dc->Clear();
|
2006-10-23 06:48:48 +00:00
|
|
|
dc->DrawBitmap(*(pSkinSimple->GetWorkunitAreaBackgroundImage()->GetBitmap()), 0, 0);
|
2006-09-15 20:15:44 +00:00
|
|
|
|
2006-08-18 21:45:17 +00:00
|
|
|
}
|
2006-08-23 21:22:41 +00:00
|
|
|
|
2006-08-24 17:54:54 +00:00
|
|
|
bool ClientStateIndicator::DownloadingResults() {
|
|
|
|
bool return_value = false;
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
if ( pDoc->results.results.size() > 0 ) {
|
|
|
|
RESULT* result;
|
|
|
|
for(unsigned int i=0; !return_value && i < pDoc->results.results.size(); i++ ) {
|
|
|
|
result = pDoc->result(i);
|
|
|
|
if ( result != NULL && result->state == RESULT_FILES_DOWNLOADING ) {
|
|
|
|
return_value = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2006-09-08 21:48:06 +00:00
|
|
|
bool ClientStateIndicator::Suspended() {
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
CC_STATUS status;
|
|
|
|
bool result = false;
|
|
|
|
pDoc->GetCoreClientStatus(status);
|
2010-03-11 01:39:14 +00:00
|
|
|
if ( pDoc->IsConnected() && status.task_suspend_reason > 0 && status.task_suspend_reason != SUSPEND_REASON_DISK_SIZE && status.task_suspend_reason != SUSPEND_REASON_THROTTLE ) {
|
2006-09-08 21:48:06 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-10-18 16:06:29 +00:00
|
|
|
// Check to see if a project update is scheduled or in progress
|
|
|
|
bool ClientStateIndicator::ProjectUpdateScheduled() {
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
PROJECT* project;
|
2008-09-30 09:36:07 +00:00
|
|
|
int prjCount = pDoc->GetSimpleProjectCount();
|
|
|
|
for(int i=0; i<prjCount; i++) {
|
2006-10-18 16:06:29 +00:00
|
|
|
project = pDoc->state.projects[i];
|
|
|
|
if ( project->sched_rpc_pending || project->master_url_fetch_pending || project->scheduler_rpc_in_progress ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-08-23 21:22:41 +00:00
|
|
|
void ClientStateIndicator::DisplayState() {
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
if ( pDoc->IsReconnecting() ) {
|
2006-08-24 17:54:54 +00:00
|
|
|
error_time = 0;
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Retrieving current status."));
|
2006-08-24 17:54:54 +00:00
|
|
|
} else if ( pDoc->IsConnected() && pDoc->state.projects.size() == 0) {
|
|
|
|
error_time = 0;
|
2006-10-23 06:48:48 +00:00
|
|
|
SetPausedState(_("You don't have any projects. Please Add a Project."));
|
2006-08-24 17:54:54 +00:00
|
|
|
} else if ( DownloadingResults() ) {
|
|
|
|
error_time = 0;
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Downloading work from the server."));
|
2006-09-08 21:48:06 +00:00
|
|
|
} else if ( Suspended() ) {
|
|
|
|
CC_STATUS status;
|
|
|
|
pDoc->GetCoreClientStatus(status);
|
|
|
|
if ( status.task_suspend_reason & SUSPEND_REASON_BATTERIES ) {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Processing Suspended: Running On Batteries."));
|
2006-09-08 21:48:06 +00:00
|
|
|
} else if ( status.task_suspend_reason & SUSPEND_REASON_USER_ACTIVE ) {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Processing Suspended: User Active."));
|
2006-09-08 21:48:06 +00:00
|
|
|
} else if ( status.task_suspend_reason & SUSPEND_REASON_USER_REQ ) {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Processing Suspended: User paused processing."));
|
2006-09-08 21:48:06 +00:00
|
|
|
} else if ( status.task_suspend_reason & SUSPEND_REASON_TIME_OF_DAY ) {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Processing Suspended: Time of Day."));
|
2006-09-08 21:48:06 +00:00
|
|
|
} else if ( status.task_suspend_reason & SUSPEND_REASON_BENCHMARKS ) {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Processing Suspended: Benchmarks Running."));
|
2006-09-08 21:48:06 +00:00
|
|
|
} else {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Processing Suspended."));
|
2006-09-08 21:48:06 +00:00
|
|
|
}
|
2006-10-18 16:06:29 +00:00
|
|
|
} else if ( ProjectUpdateScheduled() ) {
|
|
|
|
error_time = 0;
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Waiting to contact project servers."));
|
2006-08-23 21:22:41 +00:00
|
|
|
} else {
|
|
|
|
if ( error_time == 0 ) {
|
2006-10-10 02:53:25 +00:00
|
|
|
error_time = time(NULL) + 10;
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Retrieving current status"));
|
2006-08-23 21:22:41 +00:00
|
|
|
} else if ( error_time < time(NULL) ) {
|
2006-10-10 02:53:25 +00:00
|
|
|
if ( pDoc->IsConnected() ) {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetNoActionState(_("No work available to process"));
|
2006-10-10 02:53:25 +00:00
|
|
|
} else {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetNoActionState(_("Unable to connect to the core client"));
|
2006-10-10 02:53:25 +00:00
|
|
|
}
|
2006-08-23 21:22:41 +00:00
|
|
|
} else {
|
2006-10-23 06:48:48 +00:00
|
|
|
SetActionState(_("Retrieving current status"));
|
2006-08-23 21:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|