forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewProjects.cpp
737 lines (566 loc) · 21.5 KB
/
ViewProjects.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2005 University of California
//
// This 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 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// 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.
//
// To view the GNU Lesser General Public License visit
// http://www.gnu.org/copyleft/lesser.html
// or write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma implementation "ViewProjects.h"
#endif
#include "stdwx.h"
#include "util.h"
#include "BOINCGUIApp.h"
#include "BOINCBaseFrame.h"
#include "MainDocument.h"
#include "AdvancedFrame.h"
#include "BOINCTaskCtrl.h"
#include "BOINCListCtrl.h"
#include "ViewProjects.h"
#include "Events.h"
#include "res/proj.xpm"
#define COLUMN_PROJECT 0
#define COLUMN_ACCOUNTNAME 1
#define COLUMN_TEAMNAME 2
#define COLUMN_TOTALCREDIT 3
#define COLUMN_AVGCREDIT 4
#define COLUMN_RESOURCESHARE 5
#define COLUMN_STATUS 6
// groups that contain buttons
#define GRP_TASKS 0
#define GRP_WEBSITES 1
// buttons in the "tasks" area
#define BTN_UPDATE 0
#define BTN_SUSPEND 1
#define BTN_NOWORK 2
#define BTN_RESET 3
#define BTN_DETACH 4
CProject::CProject() {
}
CProject::~CProject() {
m_strProjectName.Clear();
m_strAccountName.Clear();
m_strTeamName.Clear();
m_strTotalCredit.Clear();
m_strAVGCredit.Clear();
m_strResourceShare.Clear();
m_strStatus.Clear();
}
IMPLEMENT_DYNAMIC_CLASS(CViewProjects, CBOINCBaseView)
BEGIN_EVENT_TABLE (CViewProjects, CBOINCBaseView)
EVT_BUTTON(ID_TASK_PROJECT_UPDATE, CViewProjects::OnProjectUpdate)
EVT_BUTTON(ID_TASK_PROJECT_SUSPEND, CViewProjects::OnProjectSuspend)
EVT_BUTTON(ID_TASK_PROJECT_NONEWWORK, CViewProjects::OnProjectNoNewWork)
EVT_BUTTON(ID_TASK_PROJECT_RESET, CViewProjects::OnProjectReset)
EVT_BUTTON(ID_TASK_PROJECT_DETACH, CViewProjects::OnProjectDetach)
EVT_CUSTOM_RANGE(wxEVT_COMMAND_BUTTON_CLICKED, ID_TASK_PROJECT_WEB_PROJDEF_MIN, ID_TASK_PROJECT_WEB_PROJDEF_MAX, CViewProjects::OnProjectWebsiteClicked)
EVT_LIST_ITEM_SELECTED(ID_LIST_PROJECTSVIEW, CViewProjects::OnListSelected)
EVT_LIST_ITEM_DESELECTED(ID_LIST_PROJECTSVIEW, CViewProjects::OnListDeselected)
END_EVENT_TABLE ()
CViewProjects::CViewProjects()
{}
CViewProjects::CViewProjects(wxNotebook* pNotebook) :
CBOINCBaseView(pNotebook, ID_TASK_PROJECTSVIEW, DEFAULT_TASK_FLAGS, ID_LIST_PROJECTSVIEW, DEFAULT_LIST_SINGLE_SEL_FLAGS)
{
CTaskItemGroup* pGroup = NULL;
CTaskItem* pItem = NULL;
wxASSERT(m_pTaskPane);
wxASSERT(m_pListPane);
//
// Setup View
//
pGroup = new CTaskItemGroup( _("Commands") );
m_TaskGroups.push_back( pGroup );
pItem = new CTaskItem(
_("Update"),
_("Report all completed tasks, get latest credit, "
"get latest preferences, and possibly get more tasks."),
ID_TASK_PROJECT_UPDATE
);
pGroup->m_Tasks.push_back( pItem );
pItem = new CTaskItem(
_("Suspend"),
_("Suspend tasks for this project."),
ID_TASK_PROJECT_SUSPEND
);
pGroup->m_Tasks.push_back( pItem );
pItem = new CTaskItem(
_("No new tasks"),
_("Don't get new tasks for this project."),
ID_TASK_PROJECT_NONEWWORK
);
pGroup->m_Tasks.push_back( pItem );
pItem = new CTaskItem(
_("Reset project"),
_("Delete all files and tasks associated with this project, "
"and get new tasks. "
"You can update the project "
"first to report any completed tasks."),
ID_TASK_PROJECT_RESET
);
pGroup->m_Tasks.push_back( pItem );
pItem = new CTaskItem(
_("Detach"),
_("Detach computer from this project. "
"Tasks in progress will be lost "
"(use 'Update' first to report any completed tasks)."),
ID_TASK_PROJECT_DETACH
);
pGroup->m_Tasks.push_back( pItem );
// Create Task Pane Items
m_pTaskPane->UpdateControls();
// Create List Pane Items
m_pListPane->InsertColumn(COLUMN_PROJECT, _("Project"), wxLIST_FORMAT_LEFT, 150);
m_pListPane->InsertColumn(COLUMN_ACCOUNTNAME, _("Account"), wxLIST_FORMAT_LEFT, 80);
m_pListPane->InsertColumn(COLUMN_TEAMNAME, _("Team"), wxLIST_FORMAT_LEFT, 80);
m_pListPane->InsertColumn(COLUMN_TOTALCREDIT, _("Work done"), wxLIST_FORMAT_RIGHT, 80);
m_pListPane->InsertColumn(COLUMN_AVGCREDIT, _("Avg. work done"), wxLIST_FORMAT_RIGHT, 80);
m_pListPane->InsertColumn(COLUMN_RESOURCESHARE, _("Resource share"), wxLIST_FORMAT_CENTRE, 85);
m_pListPane->InsertColumn(COLUMN_STATUS, _("Status"), wxLIST_FORMAT_LEFT, 150);
UpdateSelection();
}
CViewProjects::~CViewProjects() {
EmptyCache();
EmptyTasks();
}
wxString& CViewProjects::GetViewName() {
static wxString strViewName(_("Projects"));
return strViewName;
}
const char** CViewProjects::GetViewIcon() {
return proj_xpm;
}
void CViewProjects::OnProjectUpdate( wxCommandEvent& WXUNUSED(event) ) {
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectUpdate - Function Begin"));
CMainDocument* pDoc = wxGetApp().GetDocument();
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
wxASSERT(pDoc);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
wxASSERT(pFrame);
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
wxASSERT(m_pTaskPane);
wxASSERT(m_pListPane);
pFrame->UpdateStatusText(_("Updating project..."));
pDoc->ProjectUpdate(m_pListPane->GetFirstSelected());
pFrame->UpdateStatusText(wxT(""));
m_bForceUpdateSelection = true;
UpdateSelection();
pFrame->ResetReminderTimers();
pFrame->FireRefreshView();
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectUpdate - Function End"));
}
void CViewProjects::OnProjectSuspend( wxCommandEvent& WXUNUSED(event) ) {
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectSuspend - Function Begin"));
CMainDocument* pDoc = wxGetApp().GetDocument();
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
wxASSERT(pDoc);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
wxASSERT(pFrame);
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
wxASSERT(m_pTaskPane);
wxASSERT(m_pListPane);
PROJECT* project = pDoc->project(m_pListPane->GetFirstSelected());
if (project->suspended_via_gui) {
pFrame->UpdateStatusText(_("Resuming project..."));
pDoc->ProjectResume(m_pListPane->GetFirstSelected());
pFrame->UpdateStatusText(wxT(""));
} else {
pFrame->UpdateStatusText(_("Suspending project..."));
pDoc->ProjectSuspend(m_pListPane->GetFirstSelected());
pFrame->UpdateStatusText(wxT(""));
}
m_bForceUpdateSelection = true;
UpdateSelection();
pFrame->FireRefreshView();
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectSuspend - Function End"));
}
void CViewProjects::OnProjectNoNewWork( wxCommandEvent& WXUNUSED(event) ) {
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectNoNewWork - Function Begin"));
CMainDocument* pDoc = wxGetApp().GetDocument();
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
wxASSERT(pDoc);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
wxASSERT(pFrame);
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
wxASSERT(m_pTaskPane);
wxASSERT(m_pListPane);
PROJECT* project = pDoc->project(m_pListPane->GetFirstSelected());
if (project->dont_request_more_work) {
pFrame->UpdateStatusText(_("Telling project to allow additional task downloads..."));
pDoc->ProjectAllowMoreWork(m_pListPane->GetFirstSelected());
pFrame->UpdateStatusText(wxT(""));
} else {
pFrame->UpdateStatusText(_("Telling project to not fetch any additional tasks..."));
pDoc->ProjectNoMoreWork(m_pListPane->GetFirstSelected());
pFrame->UpdateStatusText(wxT(""));
}
m_bForceUpdateSelection = true;
UpdateSelection();
pFrame->FireRefreshView();
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectNoNewWork - Function End"));
}
void CViewProjects::OnProjectReset( wxCommandEvent& WXUNUSED(event) ) {
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectReset - Function Begin"));
wxInt32 iAnswer = 0;
std::string strProjectName;
wxString strMessage = wxEmptyString;
CMainDocument* pDoc = wxGetApp().GetDocument();
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
wxASSERT(pDoc);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
wxASSERT(pFrame);
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
wxASSERT(m_pTaskPane);
wxASSERT(m_pListPane);
if (!pDoc->IsUserAuthorized())
return;
pFrame->UpdateStatusText(_("Resetting project..."));
PROJECT* project = pDoc->project(m_pListPane->GetFirstSelected());
project->get_name(strProjectName);
strMessage.Printf(
_("Are you sure you want to reset project '%s'?"),
wxString(strProjectName.c_str(), wxConvUTF8).c_str()
);
iAnswer = ::wxMessageBox(
strMessage,
_("Reset Project"),
wxYES_NO | wxICON_QUESTION,
this
);
if (wxYES == iAnswer) {
pDoc->ProjectReset(m_pListPane->GetFirstSelected());
}
pFrame->UpdateStatusText(wxT(""));
m_bForceUpdateSelection = true;
UpdateSelection();
pFrame->FireRefreshView();
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectReset - Function End"));
}
void CViewProjects::OnProjectDetach( wxCommandEvent& WXUNUSED(event) ) {
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectDetach - Function Begin"));
wxInt32 iAnswer = 0;
std::string strProjectName;
wxString strMessage = wxEmptyString;
CMainDocument* pDoc = wxGetApp().GetDocument();
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
wxASSERT(pDoc);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
wxASSERT(pFrame);
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
wxASSERT(m_pTaskPane);
wxASSERT(m_pListPane);
if (!pDoc->IsUserAuthorized())
return;
pFrame->UpdateStatusText(_("Detaching from project..."));
PROJECT* project = pDoc->project(m_pListPane->GetFirstSelected());
project->get_name(strProjectName);
strMessage.Printf(
_("Are you sure you want to detach from project '%s'?"),
wxString(strProjectName.c_str(), wxConvUTF8).c_str()
);
iAnswer = ::wxMessageBox(
strMessage,
_("Detach from Project"),
wxYES_NO | wxICON_QUESTION,
this
);
if (wxYES == iAnswer) {
pDoc->ProjectDetach(m_pListPane->GetFirstSelected());
}
pFrame->UpdateStatusText(wxT(""));
m_bForceUpdateSelection = true;
UpdateSelection();
pFrame->FireRefreshView();
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectDetach - Function End"));
}
void CViewProjects::OnProjectWebsiteClicked( wxEvent& event ) {
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectWebsiteClicked - Function Begin"));
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
wxASSERT(pFrame);
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
wxASSERT(m_pTaskPane);
wxASSERT(m_pListPane);
pFrame->UpdateStatusText(_("Launching browser..."));
int website_task_index = event.GetId() - ID_TASK_PROJECT_WEB_PROJDEF_MIN;
pFrame->ExecuteBrowserLink(
m_TaskGroups[1]->m_Tasks[website_task_index]->m_strWebSiteLink
);
pFrame->UpdateStatusText(wxT(""));
UpdateSelection();
pFrame->FireRefreshView();
wxLogTrace(wxT("Function Start/End"), wxT("CViewProjects::OnProjectWebsiteClicked - Function End"));
}
wxInt32 CViewProjects::GetDocCount() {
return wxGetApp().GetDocument()->GetProjectCount();
}
wxString CViewProjects::OnListGetItemText(long item, long column) const {
CProject* project = NULL;
wxString strBuffer = wxEmptyString;
try {
project = m_ProjectCache.at(item);
} catch ( std::out_of_range ) {
project = NULL;
}
if (project) {
switch(column) {
case COLUMN_PROJECT:
strBuffer = project->m_strProjectName;
break;
case COLUMN_ACCOUNTNAME:
strBuffer = project->m_strAccountName;
break;
case COLUMN_TEAMNAME:
strBuffer = project->m_strTeamName;
break;
case COLUMN_TOTALCREDIT:
strBuffer = project->m_strTotalCredit;
break;
case COLUMN_AVGCREDIT:
strBuffer = project->m_strAVGCredit;
break;
case COLUMN_RESOURCESHARE:
strBuffer = project->m_strResourceShare;
break;
case COLUMN_STATUS:
strBuffer = project->m_strStatus;
break;
}
}
return strBuffer;
}
wxString CViewProjects::OnDocGetItemText(long item, long column) const {
wxString strBuffer = wxEmptyString;
switch(column) {
case COLUMN_PROJECT:
FormatProjectName(item, strBuffer);
break;
case COLUMN_ACCOUNTNAME:
FormatAccountName(item, strBuffer);
break;
case COLUMN_TEAMNAME:
FormatTeamName(item, strBuffer);
break;
case COLUMN_TOTALCREDIT:
FormatTotalCredit(item, strBuffer);
break;
case COLUMN_AVGCREDIT:
FormatAVGCredit(item, strBuffer);
break;
case COLUMN_RESOURCESHARE:
FormatResourceShare(item, strBuffer);
break;
case COLUMN_STATUS:
FormatStatus(item, strBuffer);
break;
}
return strBuffer;
}
wxInt32 CViewProjects::AddCacheElement() {
CProject* pItem = new CProject();
wxASSERT(pItem);
if (pItem) {
m_ProjectCache.push_back(pItem);
return 0;
}
return -1;
}
wxInt32 CViewProjects::EmptyCache() {
unsigned int i;
for (i=0; i<m_ProjectCache.size(); i++) {
delete m_ProjectCache[i];
}
m_ProjectCache.clear();
return 0;
}
wxInt32 CViewProjects::GetCacheCount() {
return (wxInt32)m_ProjectCache.size();
}
wxInt32 CViewProjects::RemoveCacheElement() {
delete m_ProjectCache.back();
m_ProjectCache.erase(m_ProjectCache.end() - 1);
return 0;
}
wxInt32 CViewProjects::UpdateCache(long item, long column, wxString& strNewData) {
CProject* project = m_ProjectCache.at(item);
switch(column) {
case COLUMN_PROJECT:
project->m_strProjectName = strNewData;
break;
case COLUMN_ACCOUNTNAME:
project->m_strAccountName = strNewData;
break;
case COLUMN_TEAMNAME:
project->m_strTeamName = strNewData;
break;
case COLUMN_TOTALCREDIT:
project->m_strTotalCredit = strNewData;
break;
case COLUMN_AVGCREDIT:
project->m_strAVGCredit = strNewData;
break;
case COLUMN_RESOURCESHARE:
project->m_strResourceShare = strNewData;
break;
case COLUMN_STATUS:
project->m_strStatus = strNewData;
break;
}
return 0;
}
void CViewProjects::UpdateSelection() {
CTaskItemGroup* pGroup = NULL;
PROJECT* project = NULL;
CMainDocument* pDoc = wxGetApp().GetDocument();
wxASSERT(pDoc);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
wxASSERT(m_pTaskPane);
wxASSERT(m_pListPane);
CBOINCBaseView::PreUpdateSelection();
// Update the tasks static box buttons
//
pGroup = m_TaskGroups[0];
if (m_pListPane->GetSelectedItemCount()) {
project = pDoc->project(m_pListPane->GetFirstSelected());
m_pTaskPane->EnableTask(pGroup->m_Tasks[BTN_UPDATE]);
m_pTaskPane->EnableTask(pGroup->m_Tasks[BTN_SUSPEND]);
if (project) {
if (project->suspended_via_gui) {
m_pTaskPane->UpdateTask(
pGroup->m_Tasks[BTN_SUSPEND], _("Resume"), _("Resume tasks for this project.")
);
} else {
m_pTaskPane->UpdateTask(
pGroup->m_Tasks[BTN_SUSPEND], _("Suspend"), _("Suspend tasks for this project.")
);
}
}
m_pTaskPane->EnableTask(pGroup->m_Tasks[BTN_NOWORK]);
if (project) {
if (project->dont_request_more_work) {
m_pTaskPane->UpdateTask(
pGroup->m_Tasks[BTN_NOWORK], _("Allow new tasks"), _("Allow fetching new tasks for this project.")
);
} else {
m_pTaskPane->UpdateTask(
pGroup->m_Tasks[BTN_NOWORK], _("No new tasks"), _("Don't fetch new tasks for this project.")
);
}
}
m_pTaskPane->EnableTask(pGroup->m_Tasks[BTN_RESET]);
if (project->attached_via_acct_mgr) {
m_pTaskPane->DisableTask(pGroup->m_Tasks[BTN_DETACH]);
} else {
m_pTaskPane->EnableTask(pGroup->m_Tasks[BTN_DETACH]);
}
CBOINCBaseView::UpdateWebsiteSelection(GRP_WEBSITES, project);
} else {
m_pTaskPane->DisableTaskGroupTasks(pGroup);
}
CBOINCBaseView::PostUpdateSelection();
}
wxInt32 CViewProjects::FormatProjectName(wxInt32 item, wxString& strBuffer) const {
PROJECT* project = wxGetApp().GetDocument()->project(item);
std::string project_name;
if (project) {
project->get_name(project_name);
strBuffer = wxString(project_name.c_str(), wxConvUTF8);
}
return 0;
}
wxInt32 CViewProjects::FormatAccountName(wxInt32 item, wxString& strBuffer) const {
PROJECT* project = wxGetApp().GetDocument()->project(item);
if (project) {
strBuffer = wxString(project->user_name.c_str(), wxConvUTF8);
}
return 0;
}
wxInt32 CViewProjects::FormatTeamName(wxInt32 item, wxString& strBuffer) const {
PROJECT* project = wxGetApp().GetDocument()->project(item);
if (project) {
strBuffer = wxString(project->team_name.c_str(), wxConvUTF8);
}
return 0;
}
wxInt32 CViewProjects::FormatTotalCredit(wxInt32 item, wxString& strBuffer) const {
PROJECT* project = wxGetApp().GetDocument()->project(item);
if (project) {
strBuffer.Printf(wxT("%0.2f"), project->user_total_credit);
}
return 0;
}
wxInt32 CViewProjects::FormatAVGCredit(wxInt32 item, wxString& strBuffer) const {
PROJECT* project = wxGetApp().GetDocument()->project(item);
if (project) {
strBuffer.Printf(wxT("%0.2f"), project->user_expavg_credit);
}
return 0;
}
wxInt32 CViewProjects::FormatResourceShare(wxInt32 item, wxString& strBuffer) const {
CMainDocument* pDoc = wxGetApp().GetDocument();
PROJECT* project = wxGetApp().GetDocument()->project(item);
wxASSERT(pDoc);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
if (project && pDoc) {
strBuffer.Printf(wxT("%0.0f (%0.2f%%)"),
project->resource_share,
((project->resource_share / pDoc->m_fProjectTotalResourceShare) * 100)
);
}
return 0;
}
wxInt32 CViewProjects::FormatStatus(wxInt32 item, wxString& status) const {
PROJECT* project = wxGetApp().GetDocument()->project(item);
if (project) {
if (project->suspended_via_gui) {
append_to_status(status, _("Suspended by user"));
}
if (project->dont_request_more_work) {
append_to_status(status, _("Won't get new tasks"));
}
if (project->sched_rpc_pending) {
append_to_status(status, _("Scheduler request pending"));
append_to_status(status, wxString(rpc_reason_string(project->sched_rpc_pending), wxConvUTF8));
}
wxDateTime dtNextRPC((time_t)project->min_rpc_time);
wxDateTime dtNow(wxDateTime::Now());
if (dtNextRPC > dtNow) {
wxTimeSpan tsNextRPC(dtNextRPC - dtNow);
append_to_status(status, _("Communication deferred ") + tsNextRPC.Format());
}
}
return 0;
}
bool CViewProjects::IsWebsiteLink(const wxString& strLink) {
bool bReturnValue = false;
if (strLink.StartsWith(wxT("web:")))
bReturnValue = true;
return bReturnValue;
}
wxInt32 CViewProjects::ConvertWebsiteIndexToLink(wxInt32 iProjectIndex, wxInt32 iWebsiteIndex, wxString& strLink) {
strLink.Printf(wxT("web:%d:%d"), iProjectIndex, iWebsiteIndex);
return 0;
}
wxInt32 CViewProjects::ConvertLinkToWebsiteIndex(const wxString& strLink, wxInt32& iProjectIndex, wxInt32& iWebsiteIndex) {
wxString strTemplate = strLink;
wxString strBuffer = wxEmptyString;
strTemplate.Replace(wxT("web:"), wxEmptyString);
strBuffer = strTemplate;
strBuffer.Remove(strBuffer.Find(wxT(":")));
strBuffer.ToLong((long*) &iProjectIndex);
strBuffer = strTemplate;
strBuffer = strBuffer.Mid(strBuffer.Find(wxT(":")) + 1);
strBuffer.ToLong((long*) &iWebsiteIndex);
return 0;
}
const char *BOINC_RCSID_b4edf777fc = "$Id$";