1
// Berkeley Open Infrastructure for Network Computing
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2005 University of California
5
// This is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation;
8
// either version 2.1 of the License, or (at your option) any later version.
10
// This software 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
// To view the GNU Lesser General Public License visit
16
// http://www.gnu.org/copyleft/lesser.html
17
// or write to the Free Software Foundation, Inc.,
18
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
#if defined(__GNUG__) && !defined(__APPLE__)
21
#pragma implementation "ViewTransfers.h"
25
#include "BOINCGUIApp.h"
26
#include "BOINCBaseFrame.h"
27
#include "MainDocument.h"
28
#include "AdvancedFrame.h"
29
#include "BOINCTaskCtrl.h"
30
#include "BOINCListCtrl.h"
31
#include "ViewTransfers.h"
33
#include "error_numbers.h"
36
#include "res/xfer.xpm"
39
#define COLUMN_PROJECT 0
41
#define COLUMN_PROGRESS 2
44
#define COLUMN_SPEED 5
45
#define COLUMN_STATUS 6
47
// buttons in the "tasks" area
52
CTransfer::CTransfer() {
56
CTransfer::~CTransfer() {
57
m_strProjectName.Clear();
58
m_strFileName.Clear();
59
m_strProgress.Clear();
67
IMPLEMENT_DYNAMIC_CLASS(CViewTransfers, CBOINCBaseView)
69
BEGIN_EVENT_TABLE (CViewTransfers, CBOINCBaseView)
70
EVT_BUTTON(ID_TASK_TRANSFERS_RETRYNOW, CViewTransfers::OnTransfersRetryNow)
71
EVT_BUTTON(ID_TASK_TRANSFERS_ABORT, CViewTransfers::OnTransfersAbort)
72
EVT_LIST_ITEM_SELECTED(ID_LIST_TRANSFERSVIEW, CViewTransfers::OnListSelected)
73
EVT_LIST_ITEM_DESELECTED(ID_LIST_TRANSFERSVIEW, CViewTransfers::OnListDeselected)
77
CViewTransfers::CViewTransfers()
81
CViewTransfers::CViewTransfers(wxNotebook* pNotebook) :
82
CBOINCBaseView(pNotebook, ID_TASK_TRANSFERSVIEW, DEFAULT_TASK_FLAGS, ID_LIST_TRANSFERSVIEW, DEFAULT_LIST_SINGLE_SEL_FLAGS)
84
CTaskItemGroup* pGroup = NULL;
85
CTaskItem* pItem = NULL;
87
wxASSERT(m_pTaskPane);
88
wxASSERT(m_pListPane);
94
pGroup = new CTaskItemGroup( _("Commands") );
95
m_TaskGroups.push_back( pGroup );
97
pItem = new CTaskItem(
99
_("Click 'Retry now' to transfer the file now"),
100
ID_TASK_TRANSFERS_RETRYNOW
102
pGroup->m_Tasks.push_back( pItem );
104
pItem = new CTaskItem(
106
_("Click 'Abort transfer' to delete the file from the transfer queue. "
107
"This will prevent you from being granted credit for this result."),
108
ID_TASK_TRANSFERS_ABORT
110
pGroup->m_Tasks.push_back( pItem );
113
// Create Task Pane Items
114
m_pTaskPane->UpdateControls();
116
// Create List Pane Items
117
m_pListPane->InsertColumn(COLUMN_PROJECT, _("Project"), wxLIST_FORMAT_LEFT, 125);
118
m_pListPane->InsertColumn(COLUMN_FILE, _("File"), wxLIST_FORMAT_LEFT, 205);
119
m_pListPane->InsertColumn(COLUMN_PROGRESS, _("Progress"), wxLIST_FORMAT_CENTRE, 60);
120
m_pListPane->InsertColumn(COLUMN_SIZE, _("Size"), wxLIST_FORMAT_LEFT, 80);
121
m_pListPane->InsertColumn(COLUMN_TIME, _("Elapsed Time"), wxLIST_FORMAT_LEFT, 80);
122
m_pListPane->InsertColumn(COLUMN_SPEED, _("Speed"), wxLIST_FORMAT_LEFT, 80);
123
m_pListPane->InsertColumn(COLUMN_STATUS, _("Status"), wxLIST_FORMAT_LEFT, 150);
129
CViewTransfers::~CViewTransfers() {
135
wxString& CViewTransfers::GetViewName() {
136
static wxString strViewName(_("Transfers"));
141
wxString& CViewTransfers::GetViewDisplayName() {
142
static wxString strViewName(_("Transfers"));
147
const char** CViewTransfers::GetViewIcon() {
152
void CViewTransfers::OnTransfersRetryNow( wxCommandEvent& WXUNUSED(event) ) {
153
wxLogTrace(wxT("Function Start/End"), wxT("CViewTransfers::OnTransfersRetryNow - Function Begin"));
155
CMainDocument* pDoc = wxGetApp().GetDocument();
156
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
159
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
161
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
163
pFrame->UpdateStatusText(_("Retrying transfer now..."));
164
pDoc->TransferRetryNow(m_pListPane->GetFirstSelected());
165
pFrame->UpdateStatusText(wxT(""));
168
pFrame->ResetReminderTimers();
169
pFrame->FireRefreshView();
171
wxLogTrace(wxT("Function Start/End"), wxT("CViewTransfers::OnTransfersRetryNow - Function End"));
175
void CViewTransfers::OnTransfersAbort( wxCommandEvent& WXUNUSED(event) ) {
176
wxLogTrace(wxT("Function Start/End"), wxT("CViewTransfers::OnTransfersAbort - Function Begin"));
179
wxString strMessage = wxEmptyString;
180
CMainDocument* pDoc = wxGetApp().GetDocument();
181
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
182
CTransfer* pTransfer = NULL;
185
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
187
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
189
if (!pDoc->IsUserAuthorized())
192
pFrame->UpdateStatusText(_("Aborting transfer..."));
194
pTransfer = m_TransferCache.at(m_pListPane->GetFirstSelected());
197
_("Are you sure you want to abort this file transfer '%s'?\n"
198
"NOTE: Aborting a transfer will invalidate a task and you\n"
199
"will not receive credit for it."),
200
pTransfer->m_strFileName.c_str()
203
iAnswer = ::wxMessageBox(
205
_("Abort File Transfer"),
206
wxYES_NO | wxICON_QUESTION,
210
if (wxYES == iAnswer) {
211
pDoc->TransferAbort(m_pListPane->GetFirstSelected());
214
pFrame->UpdateStatusText(wxT(""));
217
pFrame->FireRefreshView();
219
wxLogTrace(wxT("Function Start/End"), wxT("CViewTransfers::OnTransfersAbort - Function End"));
223
wxInt32 CViewTransfers::GetDocCount() {
224
return wxGetApp().GetDocument()->GetTransferCount();
228
wxString CViewTransfers::OnListGetItemText(long item, long column) const {
229
CTransfer* transfer = m_TransferCache.at(item);
230
wxString strBuffer = wxEmptyString;
233
transfer = m_TransferCache.at(item);
234
} catch ( std::out_of_range ) {
241
strBuffer = transfer->m_strProjectName;
244
strBuffer = transfer->m_strFileName;
246
case COLUMN_PROGRESS:
247
strBuffer = transfer->m_strProgress;
250
strBuffer = transfer->m_strSize;
253
strBuffer = transfer->m_strTime;
256
strBuffer = transfer->m_strSpeed;
259
strBuffer = transfer->m_strStatus;
268
wxString CViewTransfers::OnDocGetItemText(long item, long column) const {
269
wxString strBuffer = wxEmptyString;
273
FormatProjectName(item, strBuffer);
276
FormatFileName(item, strBuffer);
278
case COLUMN_PROGRESS:
279
FormatProgress(item, strBuffer);
282
FormatSize(item, strBuffer);
285
FormatTime(item, strBuffer);
288
FormatSpeed(item, strBuffer);
291
FormatStatus(item, strBuffer);
299
wxInt32 CViewTransfers::AddCacheElement() {
300
CTransfer* pItem = new CTransfer();
303
m_TransferCache.push_back(pItem);
310
wxInt32 CViewTransfers::EmptyCache() {
312
for (i=0; i<m_TransferCache.size(); i++) {
313
delete m_TransferCache[i];
315
m_TransferCache.clear();
320
wxInt32 CViewTransfers::GetCacheCount() {
321
return (wxInt32)m_TransferCache.size();
325
wxInt32 CViewTransfers::RemoveCacheElement() {
326
delete m_TransferCache.back();
327
m_TransferCache.erase(m_TransferCache.end() - 1);
332
wxInt32 CViewTransfers::UpdateCache(long item, long column, wxString& strNewData) {
333
CTransfer* transfer = m_TransferCache.at(item);
337
transfer->m_strProjectName = strNewData;
340
transfer->m_strFileName = strNewData;
342
case COLUMN_PROGRESS:
343
transfer->m_strProgress = strNewData;
346
transfer->m_strSize = strNewData;
349
transfer->m_strTime = strNewData;
352
transfer->m_strSpeed = strNewData;
355
transfer->m_strStatus = strNewData;
363
void CViewTransfers::UpdateSelection() {
364
CTaskItemGroup* pGroup = m_TaskGroups[0];
366
CBOINCBaseView::PreUpdateSelection();
368
if (m_pListPane->GetSelectedItemCount()) {
369
m_pTaskPane->EnableTaskGroupTasks(pGroup);
371
m_pTaskPane->DisableTaskGroupTasks(pGroup);
374
CBOINCBaseView::PostUpdateSelection();
378
wxInt32 CViewTransfers::FormatProjectName(wxInt32 item, wxString& strBuffer) const {
379
FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item);
382
strBuffer = HtmlEntityDecode(wxString(transfer->project_name.c_str(), wxConvUTF8));
388
wxInt32 CViewTransfers::FormatFileName(wxInt32 item, wxString& strBuffer) const {
389
FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item);
392
strBuffer = wxString(transfer->name.c_str(), wxConvUTF8);
398
wxInt32 CViewTransfers::FormatProgress(wxInt32 item, wxString& strBuffer) const {
399
float fBytesSent = 0;
401
FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item);
404
fBytesSent = transfer->bytes_xferred;
405
fFileSize = transfer->nbytes;
408
// Curl apparently counts the HTTP header in byte count.
409
// Prevent this from causing > 100% display
411
if (fBytesSent > fFileSize) {
412
fBytesSent = fFileSize;
415
if ( 0.0 == fFileSize ) {
416
strBuffer = wxT("0%");
418
strBuffer.Printf(wxT("%.2f%%"), floor((fBytesSent / fFileSize) * 10000)/100);
425
wxInt32 CViewTransfers::FormatSize(wxInt32 item, wxString& strBuffer) const {
426
float fBytesSent = 0;
428
double xTera = 1099511627776.0;
429
double xGiga = 1073741824.0;
430
double xMega = 1048576.0;
431
double xKilo = 1024.0;
432
FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item);
435
fBytesSent = transfer->bytes_xferred;
436
fFileSize = transfer->nbytes;
439
if (fFileSize != 0) {
440
if (fFileSize >= xTera) {
441
strBuffer.Printf(wxT("%0.2f/%0.2f TB"), fBytesSent/xTera, fFileSize/xTera);
442
} else if (fFileSize >= xGiga) {
443
strBuffer.Printf(wxT("%0.2f/%0.2f GB"), fBytesSent/xGiga, fFileSize/xGiga);
444
} else if (fFileSize >= xMega) {
445
strBuffer.Printf(wxT("%0.2f/%0.2f MB"), fBytesSent/xMega, fFileSize/xMega);
446
} else if (fFileSize >= xKilo) {
447
strBuffer.Printf(wxT("%0.2f/%0.2f KB"), fBytesSent/xKilo, fFileSize/xKilo);
449
strBuffer.Printf(wxT("%0.0f/%0.0f bytes"), fBytesSent, fFileSize);
452
if (fBytesSent >= xTera) {
453
strBuffer.Printf(wxT("%0.2f TB"), fBytesSent/xTera);
454
} else if (fBytesSent >= xGiga) {
455
strBuffer.Printf(wxT("%0.2f GB"), fBytesSent/xGiga);
456
} else if (fBytesSent >= xMega) {
457
strBuffer.Printf(wxT("%0.2f MB"), fBytesSent/xMega);
458
} else if (fBytesSent >= xKilo) {
459
strBuffer.Printf(wxT("%0.2f KB"), fBytesSent/xKilo);
461
strBuffer.Printf(wxT("%0.0f bytes"), fBytesSent);
469
wxInt32 CViewTransfers::FormatTime(wxInt32 item, wxString& strBuffer) const {
475
FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item);
478
fBuffer = transfer->time_so_far;
481
iHour = (wxInt32)(fBuffer / (60 * 60));
482
iMin = (wxInt32)(fBuffer / 60) % 60;
483
iSec = (wxInt32)(fBuffer) % 60;
485
ts = wxTimeSpan(iHour, iMin, iSec);
487
strBuffer = ts.Format();
493
wxInt32 CViewTransfers::FormatSpeed(wxInt32 item, wxString& strBuffer) const {
494
float fTransferSpeed = 0;
495
FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item);
498
if (transfer->xfer_active)
499
fTransferSpeed = transfer->xfer_speed / 1024;
501
fTransferSpeed = 0.0;
504
strBuffer.Printf(wxT("%.2f KBps"), fTransferSpeed);
510
wxInt32 CViewTransfers::FormatStatus(wxInt32 item, wxString& strBuffer) const {
511
CMainDocument* doc = wxGetApp().GetDocument();
512
FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item);
516
wxASSERT(wxDynamicCast(doc, CMainDocument));
518
doc->GetCoreClientStatus(status);
520
wxDateTime dtNextRequest((time_t)transfer->next_request_time);
521
wxDateTime dtNow(wxDateTime::Now());
524
if (dtNextRequest > dtNow) {
525
wxTimeSpan tsNextRequest(dtNextRequest - dtNow);
526
strBuffer = _("Retry in ") + tsNextRequest.Format();
527
} else if (ERR_GIVEUP_DOWNLOAD == transfer->status) {
528
strBuffer = _("Download failed");
529
} else if (ERR_GIVEUP_UPLOAD == transfer->status) {
530
strBuffer = _("Upload failed");
532
if (status.network_suspend_reason) {
533
strBuffer = _("Suspended");
535
if (transfer->xfer_active) {
536
strBuffer = transfer->generated_locally? _("Uploading") : _("Downloading");
538
strBuffer = transfer->generated_locally? _("Upload pending") : _("Download pending");
548
const char *BOINC_RCSID_7aadb93332 = "$Id: ViewTransfers.cpp 13804 2007-10-09 11:35:47Z fthomas $";
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/>.
18
#if defined(__GNUG__) && !defined(__APPLE__)
19
#pragma implementation "ViewTransfers.h"
23
#include "BOINCGUIApp.h"
24
#include "BOINCBaseFrame.h"
25
#include "MainDocument.h"
26
#include "AdvancedFrame.h"
27
#include "BOINCTaskCtrl.h"
28
#include "BOINCListCtrl.h"
29
#include "ViewTransfers.h"
31
#include "error_numbers.h"
34
#include "res/xfer.xpm"
37
#define COLUMN_PROJECT 0
39
#define COLUMN_PROGRESS 2
42
#define COLUMN_SPEED 5
43
#define COLUMN_STATUS 6
45
// buttons in the "tasks" area
50
CTransfer::CTransfer() {
52
m_fBytesXferred = -1.0;
59
CTransfer::~CTransfer() {
60
m_strProjectName.Clear();
61
m_strFileName.Clear();
66
IMPLEMENT_DYNAMIC_CLASS(CViewTransfers, CBOINCBaseView)
68
BEGIN_EVENT_TABLE (CViewTransfers, CBOINCBaseView)
69
EVT_BUTTON(ID_TASK_TRANSFERS_RETRYNOW, CViewTransfers::OnTransfersRetryNow)
70
EVT_BUTTON(ID_TASK_TRANSFERS_ABORT, CViewTransfers::OnTransfersAbort)
71
EVT_LIST_ITEM_SELECTED(ID_LIST_TRANSFERSVIEW, CViewTransfers::OnListSelected)
72
EVT_LIST_ITEM_DESELECTED(ID_LIST_TRANSFERSVIEW, CViewTransfers::OnListDeselected)
73
EVT_LIST_COL_CLICK(ID_LIST_TRANSFERSVIEW, CViewTransfers::OnColClick)
74
EVT_LIST_CACHE_HINT(ID_LIST_TRANSFERSVIEW, CViewTransfers::OnCacheHint)
78
static CViewTransfers* MyCViewTransfers;
80
static bool CompareViewTransferItems(int iRowIndex1, int iRowIndex2) {
86
transfer1 = MyCViewTransfers->m_TransferCache.at(iRowIndex1);
87
} catch ( std::out_of_range ) {
92
transfer2 = MyCViewTransfers->m_TransferCache.at(iRowIndex2);
93
} catch ( std::out_of_range ) {
97
switch (MyCViewTransfers->m_iSortColumn) {
99
result = transfer1->m_strProjectName.CmpNoCase(transfer2->m_strProjectName);
102
result = transfer1->m_strFileName.CmpNoCase(transfer2->m_strFileName);
104
case COLUMN_PROGRESS:
105
if (transfer1->m_fProgress < transfer2->m_fProgress) {
107
} else if (transfer1->m_fProgress > transfer2->m_fProgress) {
112
if (transfer1->m_fBytesXferred < transfer2->m_fBytesXferred) {
114
} else if (transfer1->m_fBytesXferred > transfer2->m_fBytesXferred) {
119
if (transfer1->m_dTime < transfer2->m_dTime) {
121
} else if (transfer1->m_dTime > transfer2->m_dTime) {
126
if (transfer1->m_dSpeed < transfer2->m_dSpeed) {
128
} else if (transfer1->m_dSpeed > transfer2->m_dSpeed) {
133
result = transfer1->m_strStatus.CmpNoCase(transfer2->m_strStatus);
137
// Always return FALSE for equality (result == 0)
138
return (MyCViewTransfers->m_bReverseSort ? (result > 0) : (result < 0));
142
CViewTransfers::CViewTransfers()
146
CViewTransfers::CViewTransfers(wxNotebook* pNotebook) :
147
CBOINCBaseView(pNotebook, ID_TASK_TRANSFERSVIEW, DEFAULT_TASK_FLAGS, ID_LIST_TRANSFERSVIEW, DEFAULT_LIST_MULTI_SEL_FLAGS)
149
CTaskItemGroup* pGroup = NULL;
150
CTaskItem* pItem = NULL;
152
wxASSERT(m_pTaskPane);
153
wxASSERT(m_pListPane);
159
pGroup = new CTaskItemGroup( _("Commands") );
160
m_TaskGroups.push_back( pGroup );
162
pItem = new CTaskItem(
164
_("Click 'Retry now' to transfer the file now"),
165
ID_TASK_TRANSFERS_RETRYNOW
167
pGroup->m_Tasks.push_back( pItem );
169
pItem = new CTaskItem(
171
_("Click 'Abort transfer' to delete the file from the transfer queue. This will prevent you from being granted credit for this result."),
172
ID_TASK_TRANSFERS_ABORT
174
pGroup->m_Tasks.push_back( pItem );
177
// Create Task Pane Items
178
m_pTaskPane->UpdateControls();
180
// Create List Pane Items
181
m_pListPane->InsertColumn(COLUMN_PROJECT, _("Project"), wxLIST_FORMAT_LEFT, 125);
182
m_pListPane->InsertColumn(COLUMN_FILE, _("File"), wxLIST_FORMAT_LEFT, 205);
183
m_pListPane->InsertColumn(COLUMN_PROGRESS, _("Progress"), wxLIST_FORMAT_CENTRE, 60);
184
m_pListPane->InsertColumn(COLUMN_SIZE, _("Size"), wxLIST_FORMAT_LEFT, 80);
185
m_pListPane->InsertColumn(COLUMN_TIME, _("Elapsed Time"), wxLIST_FORMAT_LEFT, 80);
186
m_pListPane->InsertColumn(COLUMN_SPEED, _("Speed"), wxLIST_FORMAT_LEFT, 80);
187
m_pListPane->InsertColumn(COLUMN_STATUS, _("Status"), wxLIST_FORMAT_LEFT, 150);
189
m_iProgressColumn = COLUMN_PROGRESS;
191
// Needed by static sort routine;
192
MyCViewTransfers = this;
193
m_funcSortCompare = CompareViewTransferItems;
199
CViewTransfers::~CViewTransfers() {
205
wxString& CViewTransfers::GetViewName() {
206
static wxString strViewName(wxT("Transfers"));
211
wxString& CViewTransfers::GetViewDisplayName() {
212
static wxString strViewName(_("Transfers"));
217
const char** CViewTransfers::GetViewIcon() {
222
const int CViewTransfers::GetViewCurrentViewPage() {
227
wxString CViewTransfers::GetKeyValue1(int iRowIndex) {
230
if (GetTransferCacheAtIndex(transfer, m_iSortedIndexes[iRowIndex])) {
231
return wxEmptyString;
234
return transfer->m_strFileName;
238
wxString CViewTransfers::GetKeyValue2(int iRowIndex) {
241
if (GetTransferCacheAtIndex(transfer, m_iSortedIndexes[iRowIndex])) {
242
return wxEmptyString;
245
return transfer->m_strProjectURL;
249
int CViewTransfers::FindRowIndexByKeyValues(wxString& key1, wxString& key2) {
251
unsigned int iRowIndex, n = GetCacheCount();
252
for(iRowIndex=0; iRowIndex < n; iRowIndex++) {
253
if (GetTransferCacheAtIndex(transfer, m_iSortedIndexes[iRowIndex])) {
256
if(! (transfer->m_strFileName).IsSameAs(key1)) continue;
257
if((transfer->m_strProjectURL).IsSameAs(key2)) return iRowIndex;
263
void CViewTransfers::OnTransfersRetryNow( wxCommandEvent& WXUNUSED(event) ) {
264
wxLogTrace(wxT("Function Start/End"), wxT("CViewTransfers::OnTransfersRetryNow - Function Begin"));
266
CMainDocument* pDoc = wxGetApp().GetDocument();
267
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
271
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
273
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
274
wxASSERT(m_pListPane);
277
pDoc->GetCoreClientStatus(status);
278
if (status.network_suspend_reason) {
279
wxString msg = _("Network activity is suspended - ");
280
msg += suspend_reason_wxstring(status.network_suspend_reason);
281
msg += _(".\nYou can enable it using the Activity menu.");
282
wxGetApp().SafeMessageBox(
285
wxOK | wxICON_INFORMATION,
291
pFrame->UpdateStatusText(_("Retrying transfer now..."));
294
// Step through all selected items
295
row = m_pListPane->GetNextItem(row, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
298
pDoc->TransferRetryNow(m_iSortedIndexes[row]);
300
pFrame->UpdateStatusText(wxT(""));
303
pFrame->ResetReminderTimers();
304
pFrame->FireRefreshView();
306
wxLogTrace(wxT("Function Start/End"), wxT("CViewTransfers::OnTransfersRetryNow - Function End"));
310
void CViewTransfers::OnTransfersAbort( wxCommandEvent& WXUNUSED(event) ) {
311
wxLogTrace(wxT("Function Start/End"), wxT("CViewTransfers::OnTransfersAbort - Function Begin"));
314
wxString strMessage = wxEmptyString;
315
CMainDocument* pDoc = wxGetApp().GetDocument();
316
CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame);
317
CTransfer* pTransfer = NULL;
321
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
323
wxASSERT(wxDynamicCast(pFrame, CAdvancedFrame));
324
wxASSERT(m_pListPane);
326
if (!pDoc->IsUserAuthorized())
329
pFrame->UpdateStatusText(_("Aborting transfer..."));
333
// Step through all selected items
334
row = m_pListPane->GetNextItem(row, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
337
if (GetTransferCacheAtIndex(pTransfer, m_iSortedIndexes[row])) {
342
_("Are you sure you want to abort this file transfer '%s'?\nNOTE: Aborting a transfer will invalidate a task and you\nwill not receive credit for it."),
343
pTransfer->m_strFileName.c_str()
346
iAnswer = wxGetApp().SafeMessageBox(
348
_("Abort File Transfer"),
349
wxYES_NO | wxICON_QUESTION,
353
if (wxYES == iAnswer) {
354
pDoc->TransferAbort(m_iSortedIndexes[row]);
358
pFrame->UpdateStatusText(wxT(""));
361
pFrame->FireRefreshView();
363
wxLogTrace(wxT("Function Start/End"), wxT("CViewTransfers::OnTransfersAbort - Function End"));
367
wxInt32 CViewTransfers::GetDocCount() {
368
return wxGetApp().GetDocument()->GetTransferCount();
372
wxString CViewTransfers::OnListGetItemText(long item, long column) const {
374
wxString strBuffer = wxEmptyString;
376
m_pListPane->AddPendingProgressBar(item);
379
transfer = m_TransferCache.at(m_iSortedIndexes[item]);
380
} catch ( std::out_of_range ) {
387
strBuffer = transfer->m_strProjectName;
390
strBuffer = transfer->m_strFileName;
392
case COLUMN_PROGRESS:
393
// CBOINCListCtrl::DrawProgressBars() will draw this using
394
// data provided by GetProgressText() and GetProgressValue(),
395
// but we need it here for accessibility programs.
396
strBuffer = transfer->m_strProgress;
399
strBuffer = transfer->m_strSize;
402
strBuffer = transfer->m_strTime;
405
strBuffer = transfer->m_strSpeed;
408
strBuffer = transfer->m_strStatus;
417
wxInt32 CViewTransfers::AddCacheElement() {
418
CTransfer* pItem = new CTransfer();
421
m_TransferCache.push_back(pItem);
422
m_iSortedIndexes.Add((int)m_TransferCache.size()-1);
429
wxInt32 CViewTransfers::EmptyCache() {
431
for (i=0; i<m_TransferCache.size(); i++) {
432
delete m_TransferCache[i];
434
m_TransferCache.clear();
435
m_iSortedIndexes.Clear();
440
wxInt32 CViewTransfers::GetCacheCount() {
441
return (wxInt32)m_TransferCache.size();
445
wxInt32 CViewTransfers::RemoveCacheElement() {
447
delete m_TransferCache.back();
448
m_TransferCache.erase(m_TransferCache.end() - 1);
449
m_iSortedIndexes.Clear();
450
for (i=0; i<m_TransferCache.size(); i++) {
451
m_iSortedIndexes.Add(i);
457
bool CViewTransfers::IsSelectionManagementNeeded() {
462
void CViewTransfers::UpdateSelection() {
463
CTaskItemGroup* pGroup = m_TaskGroups[0];
465
CBOINCBaseView::PreUpdateSelection();
467
if (m_pListPane->GetSelectedItemCount()) {
468
m_pTaskPane->EnableTaskGroupTasks(pGroup);
470
m_pTaskPane->DisableTaskGroupTasks(pGroup);
473
CBOINCBaseView::PostUpdateSelection();
477
bool CViewTransfers::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex) {
478
wxString strDocumentText = wxEmptyString;
479
wxString strDocumentText2 = wxEmptyString;
480
float fDocumentFloat = 0.0;
481
double fDocumentDouble = 0.0, fDocumentDouble2 = 0.0;
483
bool bNeedRefresh = false;
485
strDocumentText.Empty();
487
if (GetTransferCacheAtIndex(transfer, m_iSortedIndexes[iRowIndex])) {
491
switch(iColumnIndex) {
493
GetDocProjectName(m_iSortedIndexes[iRowIndex], strDocumentText);
494
GetDocProjectURL(m_iSortedIndexes[iRowIndex], strDocumentText2);
495
if (!strDocumentText.IsSameAs(transfer->m_strProjectName) || !strDocumentText2.IsSameAs(transfer->m_strProjectURL)) {
496
transfer->m_strProjectName = strDocumentText;
497
transfer->m_strProjectURL = strDocumentText2;
502
GetDocFileName(m_iSortedIndexes[iRowIndex], strDocumentText);
503
if (!strDocumentText.IsSameAs(transfer->m_strFileName)) {
504
transfer->m_strFileName = strDocumentText;
508
case COLUMN_PROGRESS:
509
GetDocProgress(m_iSortedIndexes[iRowIndex], fDocumentFloat);
510
if (fDocumentFloat != transfer->m_fProgress) {
511
transfer->m_fProgress = fDocumentFloat;
512
FormatProgress(fDocumentFloat, transfer->m_strProgress);
517
GetDocBytesXferred(m_iSortedIndexes[iRowIndex], fDocumentDouble);
518
GetDocTotalBytes(m_iSortedIndexes[iRowIndex], fDocumentDouble2);
519
if (( fDocumentDouble != transfer->m_fBytesXferred) ||
520
(fDocumentDouble2 != transfer->m_fTotalBytes)
522
transfer->m_fBytesXferred = fDocumentDouble;
523
transfer->m_fTotalBytes = fDocumentDouble2;
524
FormatSize(fDocumentDouble, fDocumentDouble2, transfer->m_strSize);
529
GetDocTime(m_iSortedIndexes[iRowIndex], fDocumentDouble);
530
if (fDocumentDouble != transfer->m_dTime) {
531
transfer->m_dTime = fDocumentDouble;
532
FormatTime(fDocumentDouble, transfer->m_strTime);
537
GetDocSpeed(m_iSortedIndexes[iRowIndex], fDocumentDouble);
538
if (fDocumentDouble != transfer->m_dSpeed) {
539
transfer->m_dSpeed = fDocumentDouble;
540
FormatSpeed(fDocumentDouble, transfer->m_strSpeed);
545
GetDocStatus(m_iSortedIndexes[iRowIndex], strDocumentText);
546
if (!strDocumentText.IsSameAs(transfer->m_strStatus)) {
547
transfer->m_strStatus = strDocumentText;
557
void CViewTransfers::GetDocProjectName(wxInt32 item, wxString& strBuffer) const {
558
FILE_TRANSFER* transfer = NULL;
559
CMainDocument* pDoc = wxGetApp().GetDocument();
562
transfer = pDoc->file_transfer(item);
566
strBuffer = HtmlEntityDecode(wxString(transfer->project_name.c_str(), wxConvUTF8));
568
strBuffer = wxEmptyString;
573
void CViewTransfers::GetDocFileName(wxInt32 item, wxString& strBuffer) const {
574
FILE_TRANSFER* transfer = NULL;
575
CMainDocument* pDoc = wxGetApp().GetDocument();
578
transfer = pDoc->file_transfer(item);
582
strBuffer = wxString(transfer->name.c_str(), wxConvUTF8);
584
strBuffer = wxEmptyString;
589
void CViewTransfers::GetDocProgress(wxInt32 item, float& fBuffer) const {
590
float fBytesSent = 0;
592
FILE_TRANSFER* transfer = NULL;
593
CMainDocument* pDoc = wxGetApp().GetDocument();
596
transfer = pDoc->file_transfer(item);
601
fBytesSent = transfer->bytes_xferred;
602
fFileSize = transfer->nbytes;
605
// Curl apparently counts the HTTP header in byte count.
606
// Prevent this from causing > 100% display
608
if (fBytesSent > fFileSize) {
609
fBytesSent = fFileSize;
613
fBuffer = floor((fBytesSent / fFileSize) * 10000)/100;
618
wxInt32 CViewTransfers::FormatProgress(float fBuffer, wxString& strBuffer) const {
619
strBuffer.Printf(wxT("%.2f%%"), fBuffer);
624
void CViewTransfers::GetDocBytesXferred(wxInt32 item, double& fBuffer) const {
625
FILE_TRANSFER* transfer = NULL;
626
CMainDocument* pDoc = wxGetApp().GetDocument();
629
transfer = pDoc->file_transfer(item);
633
fBuffer = transfer->bytes_xferred;
640
void CViewTransfers::GetDocTotalBytes(wxInt32 item, double& fBuffer) const {
641
FILE_TRANSFER* transfer = NULL;
642
CMainDocument* pDoc = wxGetApp().GetDocument();
645
transfer = pDoc->file_transfer(item);
649
fBuffer = transfer->nbytes;
656
wxInt32 CViewTransfers::FormatSize(double fBytesSent, double fFileSize, wxString& strBuffer) const {
657
double xTera = 1099511627776.0;
658
double xGiga = 1073741824.0;
659
double xMega = 1048576.0;
660
double xKilo = 1024.0;
662
if (fFileSize != 0) {
663
if (fFileSize >= xTera) {
664
strBuffer.Printf(wxT("%0.2f/%0.2f TB"), fBytesSent/xTera, fFileSize/xTera);
665
} else if (fFileSize >= xGiga) {
666
strBuffer.Printf(wxT("%0.2f/%0.2f GB"), fBytesSent/xGiga, fFileSize/xGiga);
667
} else if (fFileSize >= xMega) {
668
strBuffer.Printf(wxT("%0.2f/%0.2f MB"), fBytesSent/xMega, fFileSize/xMega);
669
} else if (fFileSize >= xKilo) {
670
strBuffer.Printf(wxT("%0.2f/%0.2f KB"), fBytesSent/xKilo, fFileSize/xKilo);
672
strBuffer.Printf(wxT("%0.0f/%0.0f bytes"), fBytesSent, fFileSize);
675
if (fBytesSent >= xTera) {
676
strBuffer.Printf(wxT("%0.2f TB"), fBytesSent/xTera);
677
} else if (fBytesSent >= xGiga) {
678
strBuffer.Printf(wxT("%0.2f GB"), fBytesSent/xGiga);
679
} else if (fBytesSent >= xMega) {
680
strBuffer.Printf(wxT("%0.2f MB"), fBytesSent/xMega);
681
} else if (fBytesSent >= xKilo) {
682
strBuffer.Printf(wxT("%0.2f KB"), fBytesSent/xKilo);
684
strBuffer.Printf(wxT("%0.0f bytes"), fBytesSent);
692
void CViewTransfers::GetDocTime(wxInt32 item, double& fBuffer) const {
693
FILE_TRANSFER* transfer = NULL;
694
CMainDocument* pDoc = wxGetApp().GetDocument();
697
transfer = pDoc->file_transfer(item);
701
fBuffer = transfer->time_so_far;
708
wxInt32 CViewTransfers::FormatTime(double fBuffer, wxString& strBuffer) const {
714
iHour = (wxInt32)(fBuffer / (60 * 60));
715
iMin = (wxInt32)(fBuffer / 60) % 60;
716
iSec = (wxInt32)(fBuffer) % 60;
718
ts = wxTimeSpan(iHour, iMin, iSec);
720
strBuffer = ts.Format();
726
void CViewTransfers::GetDocSpeed(wxInt32 item, double& fBuffer) const {
727
FILE_TRANSFER* transfer = NULL;
728
CMainDocument* pDoc = wxGetApp().GetDocument();
731
transfer = pDoc->file_transfer(item);
735
if (transfer->xfer_active)
736
fBuffer = transfer->xfer_speed / 1024;
743
wxInt32 CViewTransfers::FormatSpeed(double fBuffer, wxString& strBuffer) const {
744
strBuffer.Printf(wxT("%.2f KBps"), fBuffer);
750
void CViewTransfers::GetDocStatus(wxInt32 item, wxString& strBuffer) const {
751
FILE_TRANSFER* transfer = NULL;
752
CMainDocument* pDoc = wxGetApp().GetDocument();
756
transfer = pDoc->file_transfer(item);
761
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
763
retval = pDoc->GetCoreClientStatus(status);
765
wxDateTime dtNextRequest((time_t)transfer->next_request_time);
766
wxDateTime dtNow(wxDateTime::Now());
768
if (transfer && !retval) {
769
if (dtNextRequest > dtNow) {
770
wxTimeSpan tsNextRequest(dtNextRequest - dtNow);
771
strBuffer = _("Retry in ") + tsNextRequest.Format();
772
} else if (ERR_GIVEUP_DOWNLOAD == transfer->status) {
773
strBuffer = _("Download failed");
774
} else if (ERR_GIVEUP_UPLOAD == transfer->status) {
775
strBuffer = _("Upload failed");
777
if (status.network_suspend_reason) {
778
strBuffer = transfer->generated_locally
779
?_("Upload suspended - ")
780
:_("Download suspended - ")
782
strBuffer += suspend_reason_wxstring(status.network_suspend_reason);
784
if (transfer->xfer_active) {
785
strBuffer = transfer->generated_locally? _("Uploading") : _("Downloading");
787
strBuffer = transfer->generated_locally? _("Upload pending") : _("Download pending");
791
if (transfer->project_backoff) {
793
FormatTime(transfer->project_backoff, x);
794
strBuffer += _(" (project backoff: ") + x + _(")");
800
void CViewTransfers::GetDocProjectURL(wxInt32 item, wxString& strBuffer) const {
801
FILE_TRANSFER* transfer = NULL;
802
CMainDocument* pDoc = wxGetApp().GetDocument();
805
transfer = pDoc->file_transfer(item);
811
strBuffer = wxString(transfer->project_url.c_str(), wxConvUTF8);
816
double CViewTransfers::GetProgressValue(long item) {
817
double fBytesSent = 0;
818
double fFileSize = 0;
819
FILE_TRANSFER* transfer = NULL;
820
CMainDocument* pDoc = wxGetApp().GetDocument();
823
transfer = pDoc->file_transfer(m_iSortedIndexes[item]);
827
fBytesSent = transfer->bytes_xferred;
828
fFileSize = transfer->nbytes;
831
// Curl apparently counts the HTTP header in byte count.
832
// Prevent this from causing > 100% display
834
if (fBytesSent > fFileSize) {
835
fBytesSent = fFileSize;
838
if ( 0.0 == fFileSize ) return 0.0;
840
return (fBytesSent / fFileSize);
844
wxString CViewTransfers::GetProgressText( long item) {
846
wxString strBuffer = wxEmptyString;
848
GetTransferCacheAtIndex(transfer, m_iSortedIndexes[item]);
850
strBuffer = transfer->m_strProgress;
856
int CViewTransfers::GetTransferCacheAtIndex(CTransfer*& transferPtr, int index) {
858
transferPtr = m_TransferCache.at(index);
859
} catch ( std::out_of_range ) {