1
// This file is part of BOINC.
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2008 University of California
5
// BOINC is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Lesser General Public License
7
// as published by the Free Software Foundation,
8
// either version 3 of the License, or (at your option) any later version.
10
// BOINC is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
21
#include "BOINCGUIApp.h"
22
#include "MainDocument.h"
23
#include "DlgItemProperties.h"
24
#include "sg_TaskPanel.h"
25
#include "sg_TaskCommandPopup.h"
27
IMPLEMENT_DYNAMIC_CLASS(CSimpleTaskPopupButton, wxButton)
29
BEGIN_EVENT_TABLE(CSimpleTaskPopupButton, wxButton)
30
EVT_LEFT_DOWN(CSimpleTaskPopupButton::OnTasksCommandButton)
31
EVT_MENU(ID_TASK_WORK_SHOWGRAPHICS, CSimpleTaskPopupButton::OnTaskShowGraphics)
32
EVT_MENU(ID_TASK_WORK_SUSPEND, CSimpleTaskPopupButton::OnTaskSuspendResume)
33
EVT_MENU(ID_TASK_WORK_ABORT, CSimpleTaskPopupButton::OnTaskAbort)
34
EVT_MENU(ID_TASK_SHOW_PROPERTIES, CSimpleTaskPopupButton::OnTaskShowProperties)
37
CSimpleTaskPopupButton::CSimpleTaskPopupButton() {
40
CSimpleTaskPopupButton::CSimpleTaskPopupButton(wxWindow* parent, wxWindowID id,
41
const wxString& label, const wxPoint& pos, const wxSize& size,
42
long style, const wxValidator& validator, const wxString& name) :
43
wxButton(parent, id, label, pos, size, style, validator, name)
46
m_TaskSuspendedViaGUI = false;
47
m_TaskCommandPopUpMenu = new wxMenu();
52
CSimpleTaskPopupButton::~CSimpleTaskPopupButton() {
53
delete m_TaskCommandPopUpMenu;
57
void CSimpleTaskPopupButton::AddMenuItems() {
58
m_ShowGraphicsMenuItem = m_TaskCommandPopUpMenu->Append(
59
ID_TASK_WORK_SHOWGRAPHICS,
61
_("Show application graphics in a window.")
64
m_SuspendResumeMenuItem = m_TaskCommandPopUpMenu->Append(
67
_("Suspend work for this result.")
70
m_AbortMenuItem = m_TaskCommandPopUpMenu->Append(
73
_("Abandon work on the result. You will get no credit for it.")
76
m_ShowPropertiesMenuItem = m_TaskCommandPopUpMenu->Append(
77
ID_TASK_SHOW_PROPERTIES,
79
_("Show task details.")
84
void CSimpleTaskPopupButton::OnTasksCommandButton(wxMouseEvent& /*event*/) {
85
CMainDocument* pDoc = wxGetApp().GetDocument();
86
bool enableShowGraphics = true;
87
bool enableAbort = true;
89
wxString strMachineName;
93
TaskSelectionData* selData = ((CSimpleTaskPanel*)GetParent())->GetTaskSelectionData();
94
if (selData == NULL) return;
96
RESULT* result = lookup_result(selData->project_url, selData->result_name);
100
if (result->suspended_via_gui) {
101
m_TaskSuspendedViaGUI = true;
102
m_SuspendResumeMenuItem->SetItemLabel(_("Resume"));
103
m_SuspendResumeMenuItem->SetHelp(_("Resume work for this task."));
105
m_TaskSuspendedViaGUI = false;
106
m_SuspendResumeMenuItem->SetItemLabel(_("Suspend"));
107
m_SuspendResumeMenuItem->SetHelp(_("Suspend work for this task."));
110
pDoc->GetCoreClientStatus(status);
111
if (status.task_suspend_reason & ~(SUSPEND_REASON_CPU_THROTTLE)) {
112
enableShowGraphics = false;
115
pDoc->GetConnectedComputerName(strMachineName);
116
if (!pDoc->IsComputerNameLocal(strMachineName)) {
117
enableShowGraphics = false;
120
// Disable Show Graphics button if selected task can't display graphics
121
if (((!result->supports_graphics) || pDoc->GetState()->executing_as_daemon)
122
&& !strlen(result->graphics_exec_path)
124
enableShowGraphics = false;
127
if (result->suspended_via_gui ||
128
result->project_suspended_via_gui ||
129
(result->scheduler_state != CPU_SCHED_SCHEDULED)
131
enableShowGraphics = false;
134
m_ShowGraphicsMenuItem->Enable(enableShowGraphics);
136
// Disable Abort button if any selected task already aborted
138
result->active_task_state == PROCESS_ABORT_PENDING ||
139
result->active_task_state == PROCESS_ABORTED ||
140
result->state == RESULT_ABORTED
145
m_AbortMenuItem->Enable(enableAbort);
148
// Disable tooltips on Mac while menus are popped up because they cover menus
149
wxToolTip::Enable(false);
152
PopupMenu(m_TaskCommandPopUpMenu);
156
/*** CAF *** FOR TESTING ONLY ***/
162
s = (wxT("This is a very very very and extremely long label."));
170
UpdateStaticText(&m_TaskProjectName, s);
174
UpdateStaticText(&m_TaskApplicationName, s);
178
UpdateStaticText(&m_ElapsedTimeValue, s);
182
UpdateStaticText(&m_TimeRemainingValue, s);
186
UpdateStaticText(&m_StatusValueText, s);
190
m_ProgressBar->SetValue( i * 10 );
192
// m_TaskSelectionCtrl->SetStringSelection(tempArray[sel]);
193
m_TaskSelectionCtrl->SetSelection(sel);
198
void CSimpleTaskPopupButton::OnTaskShowGraphics(wxCommandEvent& WXUNUSED(event)) {
199
CMainDocument* pDoc = wxGetApp().GetDocument();
202
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
204
TaskSelectionData* selData = ((CSimpleTaskPanel*)GetParent())->GetTaskSelectionData();
205
if (selData == NULL) return;
207
RESULT* result = lookup_result(selData->project_url, selData->result_name);
209
pDoc->WorkShowGraphics(result);
214
void CSimpleTaskPopupButton::OnTaskSuspendResume(wxCommandEvent& WXUNUSED(event)) {
215
CMainDocument* pDoc = wxGetApp().GetDocument();
218
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
220
TaskSelectionData* selData = ((CSimpleTaskPanel*)GetParent())->GetTaskSelectionData();
221
if (selData == NULL) return;
223
if (m_TaskSuspendedViaGUI) {
224
pDoc->WorkResume(selData->project_url, selData->result_name);
226
pDoc->WorkSuspend(selData->project_url, selData->result_name);
231
void CSimpleTaskPopupButton::OnTaskAbort(wxCommandEvent& WXUNUSED(event)) {
233
wxString strMessage = wxEmptyString;
234
CMainDocument* pDoc = wxGetApp().GetDocument();
237
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
239
if (!pDoc->IsUserAuthorized()) // Probably no longer relevant
242
TaskSelectionData* selData = ((CSimpleTaskPanel*)GetParent())->GetTaskSelectionData();
243
if (selData == NULL) return;
245
RESULT* result = lookup_result(selData->project_url, selData->result_name);
247
#if SELECTBYRESULTNAME
248
wxString name = wxString(selData->result_name, wxConvUTF8, strlen(selData->result_name));
250
wxString name = ((CSimpleTaskPanel*)GetParent())->GetSelectedTaskString();
253
_("Are you sure you want to abort this task '%s'?\n(Progress: %.1lf%%, Status: %s)"),
254
name.c_str(), result->fraction_done * 100.0, result_description(result, false).c_str());
256
iAnswer = wxGetApp().SafeMessageBox(
259
wxYES_NO | wxICON_QUESTION,
263
if (wxYES != iAnswer) {
267
pDoc->WorkAbort(result->project_url, result->name);
272
void CSimpleTaskPopupButton::OnTaskShowProperties(wxCommandEvent& WXUNUSED(event)) {
273
TaskSelectionData* selData = ((CSimpleTaskPanel*)GetParent())->GetTaskSelectionData();
274
if (selData == NULL) return;
276
RESULT* result = lookup_result(selData->project_url, selData->result_name);
278
CDlgItemProperties dlg(this);
279
dlg.renderInfos(result);
285
// CMainDocument::state.lookup_result() does not yield current scheduler_state;
286
// we must use CMainDocument::result() for that.
287
RESULT* CSimpleTaskPopupButton::lookup_result(char* url, char* name) {
288
CMainDocument* pDoc = wxGetApp().GetDocument();
291
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
293
return pDoc->result(wxString(name, wxConvUTF8), wxString(url, wxConvUTF8));