2005-01-20 23:22:22 +00:00
// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2005 University of California
2004-05-17 22:15:10 +00:00
//
2005-01-20 23:22:22 +00:00
// 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.
2004-04-10 09:11:03 +00:00
//
2005-01-20 23:22:22 +00:00
// 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.
2004-05-17 22:15:10 +00:00
//
2005-01-20 23:22:22 +00:00
// To view the GNU Lesser General Public License visit
// http://www.gnu.org/copyleft/lesser.html
// or write to the Free Software Foundation, Inc.,
2007-10-09 11:35:47 +00:00
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2004-04-10 09:11:03 +00:00
2004-04-11 04:37:10 +00:00
# if defined(__GNUG__) && !defined(__APPLE__)
2004-09-21 01:30:29 +00:00
# pragma implementation "ViewTransfers.h"
2004-04-11 04:37:10 +00:00
# endif
2004-04-10 09:11:03 +00:00
# include "stdwx.h"
2004-08-11 23:52:22 +00:00
# include "BOINCGUIApp.h"
2006-10-20 15:00:14 +00:00
# include "BOINCBaseFrame.h"
2004-08-11 23:52:22 +00:00
# include "MainDocument.h"
2006-06-24 05:00:57 +00:00
# include "AdvancedFrame.h"
2004-09-24 22:19:02 +00:00
# include "BOINCTaskCtrl.h"
# include "BOINCListCtrl.h"
2004-09-21 01:30:29 +00:00
# include "ViewTransfers.h"
2004-07-13 05:56:03 +00:00
# include "Events.h"
2004-10-22 18:39:21 +00:00
# include "error_numbers.h"
2004-04-10 09:11:03 +00:00
2004-12-02 07:43:47 +00:00
2004-04-13 00:33:40 +00:00
# include "res/xfer.xpm"
2004-09-24 22:19:02 +00:00
2004-08-11 23:52:22 +00:00
# define COLUMN_PROJECT 0
# define COLUMN_FILE 1
# define COLUMN_PROGRESS 2
# define COLUMN_SIZE 3
# define COLUMN_TIME 4
# define COLUMN_SPEED 5
# define COLUMN_STATUS 6
2005-04-22 06:06:22 +00:00
// buttons in the "tasks" area
# define BTN_RETRY 0
# define BTN_ABORT 1
2004-08-11 23:52:22 +00:00
2005-04-07 07:04:50 +00:00
CTransfer : : CTransfer ( ) {
2004-12-02 07:43:47 +00:00
}
2005-04-07 07:04:50 +00:00
CTransfer : : ~ CTransfer ( ) {
2004-12-02 07:43:47 +00:00
m_strProjectName . Clear ( ) ;
m_strFileName . Clear ( ) ;
2008-06-27 10:05:47 +00:00
m_fProgress = 0.0 ;
m_fBytesXferred = 0.0 ;
m_fTotalBytes = 0.0 ;
m_dTime = 0.0 ;
m_dSpeed = 0.0 ;
2004-12-02 07:43:47 +00:00
m_strStatus . Clear ( ) ;
}
2004-09-21 01:30:29 +00:00
IMPLEMENT_DYNAMIC_CLASS ( CViewTransfers , CBOINCBaseView )
2004-04-10 09:11:03 +00:00
2005-04-21 06:04:26 +00:00
BEGIN_EVENT_TABLE ( CViewTransfers , CBOINCBaseView )
EVT_BUTTON ( ID_TASK_TRANSFERS_RETRYNOW , CViewTransfers : : OnTransfersRetryNow )
EVT_BUTTON ( ID_TASK_TRANSFERS_ABORT , CViewTransfers : : OnTransfersAbort )
2005-04-21 23:14:10 +00:00
EVT_LIST_ITEM_SELECTED ( ID_LIST_TRANSFERSVIEW , CViewTransfers : : OnListSelected )
EVT_LIST_ITEM_DESELECTED ( ID_LIST_TRANSFERSVIEW , CViewTransfers : : OnListDeselected )
2008-06-27 10:05:47 +00:00
EVT_LIST_COL_CLICK ( ID_LIST_TRANSFERSVIEW , CViewTransfers : : OnColClick )
EVT_LIST_CACHE_HINT ( ID_LIST_TRANSFERSVIEW , CViewTransfers : : OnCacheHint )
2005-04-21 06:04:26 +00:00
END_EVENT_TABLE ( )
2004-04-10 09:11:03 +00:00
2008-06-27 10:05:47 +00:00
static CViewTransfers * MyCViewTransfers ;
2008-07-08 15:13:34 +00:00
static bool CompareViewTransferItems ( int iRowIndex1 , int iRowIndex2 ) {
CTransfer * transfer1 = MyCViewTransfers - > m_TransferCache . at ( iRowIndex1 ) ;
CTransfer * transfer2 = MyCViewTransfers - > m_TransferCache . at ( iRowIndex2 ) ;
2008-06-27 10:05:47 +00:00
int result = 0 ;
switch ( MyCViewTransfers - > m_iSortColumn ) {
case COLUMN_PROJECT :
result = transfer1 - > m_strProjectName . CmpNoCase ( transfer2 - > m_strProjectName ) ;
break ;
case COLUMN_FILE :
result = transfer1 - > m_strFileName . CmpNoCase ( transfer2 - > m_strFileName ) ;
break ;
case COLUMN_PROGRESS :
if ( transfer1 - > m_fProgress < transfer2 - > m_fProgress ) {
result = - 1 ;
} else if ( transfer1 - > m_fProgress > transfer2 - > m_fProgress ) {
result = 1 ;
}
break ;
case COLUMN_SIZE :
if ( transfer1 - > m_fBytesXferred < transfer2 - > m_fBytesXferred ) {
result = - 1 ;
} else if ( transfer1 - > m_fBytesXferred > transfer2 - > m_fBytesXferred ) {
result = 1 ;
}
break ;
case COLUMN_TIME :
if ( transfer1 - > m_dTime < transfer2 - > m_dTime ) {
result = - 1 ;
} else if ( transfer1 - > m_dTime > transfer2 - > m_dTime ) {
result = 1 ;
}
break ;
case COLUMN_SPEED :
if ( transfer1 - > m_dSpeed < transfer2 - > m_dSpeed ) {
result = - 1 ;
} else if ( transfer1 - > m_dSpeed > transfer2 - > m_dSpeed ) {
result = 1 ;
}
break ;
case COLUMN_STATUS :
result = transfer1 - > m_strStatus . CmpNoCase ( transfer2 - > m_strStatus ) ;
break ;
}
2008-07-08 15:13:34 +00:00
// Always return FALSE for equality (result == 0)
return ( MyCViewTransfers - > m_bReverseSort ? ( result > 0 ) : ( result < = 0 ) ) ;
2008-06-27 10:05:47 +00:00
}
2005-09-02 18:40:06 +00:00
CViewTransfers : : CViewTransfers ( )
{ }
2004-04-10 09:11:03 +00:00
2004-09-21 01:30:29 +00:00
CViewTransfers : : CViewTransfers ( wxNotebook * pNotebook ) :
2008-06-27 10:05:47 +00:00
CBOINCBaseView ( pNotebook , ID_TASK_TRANSFERSVIEW , DEFAULT_TASK_FLAGS , ID_LIST_TRANSFERSVIEW , DEFAULT_LIST_MULTI_SEL_FLAGS )
2005-04-21 06:04:26 +00:00
{
CTaskItemGroup * pGroup = NULL ;
CTaskItem * pItem = NULL ;
2005-04-27 06:55:28 +00:00
wxASSERT ( m_pTaskPane ) ;
wxASSERT ( m_pListPane ) ;
2004-09-21 01:30:29 +00:00
2004-12-23 01:06:41 +00:00
//
// Setup View
//
2006-02-08 06:56:34 +00:00
pGroup = new CTaskItemGroup ( _ ( " Commands " ) ) ;
2005-04-21 06:04:26 +00:00
m_TaskGroups . push_back ( pGroup ) ;
pItem = new CTaskItem (
_ ( " Retry Now " ) ,
_ ( " Click 'Retry now' to transfer the file now " ) ,
ID_TASK_TRANSFERS_RETRYNOW
) ;
pGroup - > m_Tasks . push_back ( pItem ) ;
2004-09-24 22:19:02 +00:00
2005-04-21 06:04:26 +00:00
pItem = new CTaskItem (
_ ( " Abort Transfer " ) ,
2008-07-08 20:05:07 +00:00
_ ( " Click 'Abort transfer' to delete the file from the transfer queue. This will prevent you from being granted credit for this result. " ) ,
2005-04-21 06:04:26 +00:00
ID_TASK_TRANSFERS_ABORT
) ;
pGroup - > m_Tasks . push_back ( pItem ) ;
2004-09-24 22:19:02 +00:00
2005-04-21 06:04:26 +00:00
// Create Task Pane Items
2005-04-21 23:14:10 +00:00
m_pTaskPane - > UpdateControls ( ) ;
2004-09-24 22:19:02 +00:00
2005-04-21 06:04:26 +00:00
// Create List Pane Items
2004-10-22 18:39:21 +00:00
m_pListPane - > InsertColumn ( COLUMN_PROJECT , _ ( " Project " ) , wxLIST_FORMAT_LEFT , 125 ) ;
m_pListPane - > InsertColumn ( COLUMN_FILE , _ ( " File " ) , wxLIST_FORMAT_LEFT , 205 ) ;
m_pListPane - > InsertColumn ( COLUMN_PROGRESS , _ ( " Progress " ) , wxLIST_FORMAT_CENTRE , 60 ) ;
m_pListPane - > InsertColumn ( COLUMN_SIZE , _ ( " Size " ) , wxLIST_FORMAT_LEFT , 80 ) ;
2005-06-17 04:53:35 +00:00
m_pListPane - > InsertColumn ( COLUMN_TIME , _ ( " Elapsed Time " ) , wxLIST_FORMAT_LEFT , 80 ) ;
2004-10-22 18:39:21 +00:00
m_pListPane - > InsertColumn ( COLUMN_SPEED , _ ( " Speed " ) , wxLIST_FORMAT_LEFT , 80 ) ;
m_pListPane - > InsertColumn ( COLUMN_STATUS , _ ( " Status " ) , wxLIST_FORMAT_LEFT , 150 ) ;
2005-04-22 01:46:32 +00:00
2008-06-24 10:52:12 +00:00
m_iProgressColumn = COLUMN_PROGRESS ;
2008-06-27 10:05:47 +00:00
// Needed by static sort routine;
MyCViewTransfers = this ;
m_funcSortCompare = CompareViewTransferItems ;
2005-04-22 01:46:32 +00:00
UpdateSelection ( ) ;
2004-04-10 09:11:03 +00:00
}
2005-04-07 07:04:50 +00:00
CViewTransfers : : ~ CViewTransfers ( ) {
2005-02-01 00:54:06 +00:00
EmptyCache ( ) ;
2005-04-21 06:04:26 +00:00
EmptyTasks ( ) ;
2004-04-10 09:11:03 +00:00
}
2005-09-02 21:03:36 +00:00
wxString & CViewTransfers : : GetViewName ( ) {
2005-09-02 20:56:08 +00:00
static wxString strViewName ( _ ( " Transfers " ) ) ;
return strViewName ;
2004-04-10 09:11:03 +00:00
}
2004-04-11 05:09:18 +00:00
2004-04-13 00:33:40 +00:00
- fixes #207 - HTML entities in BOINC Manager have to be decoded
BOINC Manager can now properly decode HTML entites for the
following elements:
Projects Tab:
Project Name
User Name
Team Name
Work Tab:
Project Name
Application Name
Transfers Tab:
Project Name
Messages Tab:
Project Name
Disk Tab:
Project Name
- fixes #212 - Info in columns misaligned on switching views
- Properly restore which tab view the user left from when going
to the advanced view from the simple view
- Fix the problem that caused the manager to wait for 7 seconds
to display anything on initial startup.
- Store the various Grid/List persisted data seperately so that
the different header sizes don't cause problems.
clientgui/
AdvancedFrame.cpp
BOINCBaseView.cpp, .h
BOINCGridCtrl.cpp
ViewMessages.cpp, .h
ViewMessagesGrid.cpp, .h
ViewProjects.cpp, .h
ViewProjectsGrid.cpp, .h
ViewResources.cpp, .h
ViewStatistics.cpp, .h
ViewTransfers.cpp, .h
ViewTransfersGrid.cpp, .h
ViewWork.cpp, .h
ViewWorkGrid.cpp, .h
lib/
gui_rpc_client_ops.C
svn path=/trunk/boinc/; revision=12761
2007-05-29 05:07:35 +00:00
wxString & CViewTransfers : : GetViewDisplayName ( ) {
static wxString strViewName ( _ ( " Transfers " ) ) ;
return strViewName ;
}
2005-04-07 07:04:50 +00:00
const char * * CViewTransfers : : GetViewIcon ( ) {
2004-04-13 00:33:40 +00:00
return xfer_xpm ;
}
2004-05-21 06:27:15 +00:00
2005-07-07 22:26:49 +00:00
void CViewTransfers : : OnTransfersRetryNow ( wxCommandEvent & WXUNUSED ( event ) ) {
2005-04-21 06:04:26 +00:00
wxLogTrace ( wxT ( " Function Start/End " ) , wxT ( " CViewTransfers::OnTransfersRetryNow - Function Begin " ) ) ;
- fixes #207 - HTML entities in BOINC Manager have to be decoded
BOINC Manager can now properly decode HTML entites for the
following elements:
Projects Tab:
Project Name
User Name
Team Name
Work Tab:
Project Name
Application Name
Transfers Tab:
Project Name
Messages Tab:
Project Name
Disk Tab:
Project Name
- fixes #212 - Info in columns misaligned on switching views
- Properly restore which tab view the user left from when going
to the advanced view from the simple view
- Fix the problem that caused the manager to wait for 7 seconds
to display anything on initial startup.
- Store the various Grid/List persisted data seperately so that
the different header sizes don't cause problems.
clientgui/
AdvancedFrame.cpp
BOINCBaseView.cpp, .h
BOINCGridCtrl.cpp
ViewMessages.cpp, .h
ViewMessagesGrid.cpp, .h
ViewProjects.cpp, .h
ViewProjectsGrid.cpp, .h
ViewResources.cpp, .h
ViewStatistics.cpp, .h
ViewTransfers.cpp, .h
ViewTransfersGrid.cpp, .h
ViewWork.cpp, .h
ViewWorkGrid.cpp, .h
lib/
gui_rpc_client_ops.C
svn path=/trunk/boinc/; revision=12761
2007-05-29 05:07:35 +00:00
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
CAdvancedFrame * pFrame = wxDynamicCast ( GetParent ( ) - > GetParent ( ) - > GetParent ( ) , CAdvancedFrame ) ;
2008-06-27 10:05:47 +00:00
int row ;
2005-04-21 06:04:26 +00:00
2005-04-27 06:55:28 +00:00
wxASSERT ( pDoc ) ;
2005-04-21 06:04:26 +00:00
wxASSERT ( wxDynamicCast ( pDoc , CMainDocument ) ) ;
2005-04-27 06:55:28 +00:00
wxASSERT ( pFrame ) ;
2006-06-24 05:00:57 +00:00
wxASSERT ( wxDynamicCast ( pFrame , CAdvancedFrame ) ) ;
2005-04-21 06:04:26 +00:00
pFrame - > UpdateStatusText ( _ ( " Retrying transfer now... " ) ) ;
2008-06-27 10:05:47 +00:00
row = - 1 ;
while ( 1 ) {
// Step through all selected items
row = m_pListPane - > GetNextItem ( row , wxLIST_NEXT_ALL , wxLIST_STATE_SELECTED ) ;
if ( row < 0 ) break ;
pDoc - > TransferRetryNow ( m_iSortedIndexes [ row ] ) ;
}
2005-04-21 06:04:26 +00:00
pFrame - > UpdateStatusText ( wxT ( " " ) ) ;
2005-04-21 23:14:10 +00:00
UpdateSelection ( ) ;
2006-02-17 20:59:15 +00:00
pFrame - > ResetReminderTimers ( ) ;
2005-05-05 06:07:14 +00:00
pFrame - > FireRefreshView ( ) ;
2005-04-21 23:14:10 +00:00
2005-04-21 06:04:26 +00:00
wxLogTrace ( wxT ( " Function Start/End " ) , wxT ( " CViewTransfers::OnTransfersRetryNow - Function End " ) ) ;
}
2005-07-07 22:26:49 +00:00
void CViewTransfers : : OnTransfersAbort ( wxCommandEvent & WXUNUSED ( event ) ) {
2005-04-21 06:04:26 +00:00
wxLogTrace ( wxT ( " Function Start/End " ) , wxT ( " CViewTransfers::OnTransfersAbort - Function Begin " ) ) ;
- fixes #207 - HTML entities in BOINC Manager have to be decoded
BOINC Manager can now properly decode HTML entites for the
following elements:
Projects Tab:
Project Name
User Name
Team Name
Work Tab:
Project Name
Application Name
Transfers Tab:
Project Name
Messages Tab:
Project Name
Disk Tab:
Project Name
- fixes #212 - Info in columns misaligned on switching views
- Properly restore which tab view the user left from when going
to the advanced view from the simple view
- Fix the problem that caused the manager to wait for 7 seconds
to display anything on initial startup.
- Store the various Grid/List persisted data seperately so that
the different header sizes don't cause problems.
clientgui/
AdvancedFrame.cpp
BOINCBaseView.cpp, .h
BOINCGridCtrl.cpp
ViewMessages.cpp, .h
ViewMessagesGrid.cpp, .h
ViewProjects.cpp, .h
ViewProjectsGrid.cpp, .h
ViewResources.cpp, .h
ViewStatistics.cpp, .h
ViewTransfers.cpp, .h
ViewTransfersGrid.cpp, .h
ViewWork.cpp, .h
ViewWorkGrid.cpp, .h
lib/
gui_rpc_client_ops.C
svn path=/trunk/boinc/; revision=12761
2007-05-29 05:07:35 +00:00
wxInt32 iAnswer = 0 ;
wxString strMessage = wxEmptyString ;
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
CAdvancedFrame * pFrame = wxDynamicCast ( GetParent ( ) - > GetParent ( ) - > GetParent ( ) , CAdvancedFrame ) ;
CTransfer * pTransfer = NULL ;
2008-06-27 10:05:47 +00:00
int row ;
2005-04-21 06:04:26 +00:00
2005-04-27 06:55:28 +00:00
wxASSERT ( pDoc ) ;
2005-04-21 06:04:26 +00:00
wxASSERT ( wxDynamicCast ( pDoc , CMainDocument ) ) ;
2005-04-27 06:55:28 +00:00
wxASSERT ( pFrame ) ;
2006-06-24 05:00:57 +00:00
wxASSERT ( wxDynamicCast ( pFrame , CAdvancedFrame ) ) ;
2005-04-21 06:04:26 +00:00
2006-06-22 10:10:51 +00:00
if ( ! pDoc - > IsUserAuthorized ( ) )
return ;
2005-04-21 06:04:26 +00:00
pFrame - > UpdateStatusText ( _ ( " Aborting transfer... " ) ) ;
2008-06-27 10:05:47 +00:00
row = - 1 ;
while ( 1 ) {
// Step through all selected items
row = m_pListPane - > GetNextItem ( row , wxLIST_NEXT_ALL , wxLIST_STATE_SELECTED ) ;
if ( row < 0 ) break ;
pTransfer = m_TransferCache . at ( m_iSortedIndexes [ row ] ) ;
strMessage . Printf (
2008-07-08 20:05:07 +00:00
_ ( " Are you sure you want to abort this file transfer '%s'? \n NOTE: Aborting a transfer will invalidate a task and you \n will not receive credit for it. " ) ,
2008-06-27 10:05:47 +00:00
pTransfer - > m_strFileName . c_str ( )
) ;
iAnswer = : : wxMessageBox (
strMessage ,
_ ( " Abort File Transfer " ) ,
wxYES_NO | wxICON_QUESTION ,
this
) ;
if ( wxYES = = iAnswer ) {
pDoc - > TransferAbort ( m_iSortedIndexes [ row ] ) ;
}
2005-04-21 06:04:26 +00:00
}
2008-06-27 10:05:47 +00:00
2005-04-21 06:04:26 +00:00
pFrame - > UpdateStatusText ( wxT ( " " ) ) ;
2005-04-21 23:14:10 +00:00
UpdateSelection ( ) ;
2005-05-05 06:07:14 +00:00
pFrame - > FireRefreshView ( ) ;
2005-04-21 23:14:10 +00:00
2005-04-21 06:04:26 +00:00
wxLogTrace ( wxT ( " Function Start/End " ) , wxT ( " CViewTransfers::OnTransfersAbort - Function End " ) ) ;
}
2005-04-07 07:04:50 +00:00
wxInt32 CViewTransfers : : GetDocCount ( ) {
2006-04-17 20:26:59 +00:00
return wxGetApp ( ) . GetDocument ( ) - > GetTransferCount ( ) ;
2004-10-26 08:41:02 +00:00
}
2005-04-07 07:04:50 +00:00
wxString CViewTransfers : : OnListGetItemText ( long item , long column ) const {
2004-12-02 07:43:47 +00:00
wxString strBuffer = wxEmptyString ;
2004-10-22 00:41:18 +00:00
2005-04-07 07:04:50 +00:00
switch ( column ) {
2004-08-11 23:52:22 +00:00
case COLUMN_PROJECT :
2005-04-07 07:04:50 +00:00
FormatProjectName ( item , strBuffer ) ;
2004-08-11 23:52:22 +00:00
break ;
case COLUMN_FILE :
2005-04-07 07:04:50 +00:00
FormatFileName ( item , strBuffer ) ;
2004-08-11 23:52:22 +00:00
break ;
case COLUMN_PROGRESS :
2005-04-07 07:04:50 +00:00
FormatProgress ( item , strBuffer ) ;
2004-08-11 23:52:22 +00:00
break ;
case COLUMN_SIZE :
2005-04-07 07:04:50 +00:00
FormatSize ( item , strBuffer ) ;
2004-08-11 23:52:22 +00:00
break ;
case COLUMN_TIME :
2005-04-07 07:04:50 +00:00
FormatTime ( item , strBuffer ) ;
2004-08-11 23:52:22 +00:00
break ;
case COLUMN_SPEED :
2005-04-07 07:04:50 +00:00
FormatSpeed ( item , strBuffer ) ;
2004-08-11 23:52:22 +00:00
break ;
case COLUMN_STATUS :
2005-04-07 07:04:50 +00:00
FormatStatus ( item , strBuffer ) ;
2004-08-11 23:52:22 +00:00
break ;
}
2004-12-02 07:43:47 +00:00
2004-08-11 23:52:22 +00:00
return strBuffer ;
}
2004-09-24 22:19:02 +00:00
2005-04-07 07:04:50 +00:00
wxInt32 CViewTransfers : : AddCacheElement ( ) {
2004-12-02 07:43:47 +00:00
CTransfer * pItem = new CTransfer ( ) ;
2005-04-27 06:55:28 +00:00
wxASSERT ( pItem ) ;
if ( pItem ) {
2005-04-07 07:04:50 +00:00
m_TransferCache . push_back ( pItem ) ;
2008-06-27 10:05:47 +00:00
m_iSortedIndexes . Add ( ( int ) m_TransferCache . size ( ) - 1 ) ;
2004-12-02 07:43:47 +00:00
return 0 ;
}
return - 1 ;
}
2005-04-07 07:04:50 +00:00
wxInt32 CViewTransfers : : EmptyCache ( ) {
2005-01-29 19:59:39 +00:00
unsigned int i ;
for ( i = 0 ; i < m_TransferCache . size ( ) ; i + + ) {
delete m_TransferCache [ i ] ;
}
2005-01-29 00:58:43 +00:00
m_TransferCache . clear ( ) ;
2008-06-27 10:05:47 +00:00
m_iSortedIndexes . Clear ( ) ;
2004-12-02 07:43:47 +00:00
return 0 ;
}
2005-04-07 07:04:50 +00:00
wxInt32 CViewTransfers : : GetCacheCount ( ) {
2006-07-21 08:23:26 +00:00
return ( wxInt32 ) m_TransferCache . size ( ) ;
2004-12-02 07:43:47 +00:00
}
2005-04-07 07:04:50 +00:00
wxInt32 CViewTransfers : : RemoveCacheElement ( ) {
2008-06-27 10:05:47 +00:00
unsigned int i ;
2005-01-29 21:30:45 +00:00
delete m_TransferCache . back ( ) ;
2005-04-07 07:04:50 +00:00
m_TransferCache . erase ( m_TransferCache . end ( ) - 1 ) ;
2008-06-27 10:05:47 +00:00
m_iSortedIndexes . Clear ( ) ;
for ( i = 0 ; i < m_TransferCache . size ( ) ; i + + ) {
m_iSortedIndexes . Add ( i ) ;
}
2004-12-02 07:43:47 +00:00
return 0 ;
}
2008-06-27 10:05:47 +00:00
void CViewTransfers : : UpdateSelection ( ) {
CTaskItemGroup * pGroup = m_TaskGroups [ 0 ] ;
2004-12-02 07:43:47 +00:00
2008-06-27 10:05:47 +00:00
CBOINCBaseView : : PreUpdateSelection ( ) ;
if ( m_pListPane - > GetSelectedItemCount ( ) ) {
m_pTaskPane - > EnableTaskGroupTasks ( pGroup ) ;
} else {
m_pTaskPane - > DisableTaskGroupTasks ( pGroup ) ;
}
CBOINCBaseView : : PostUpdateSelection ( ) ;
}
bool CViewTransfers : : SynchronizeCacheItem ( wxInt32 iRowIndex , wxInt32 iColumnIndex ) {
wxString strDocumentText = wxEmptyString ;
float fDocumentFloat = 0.0 ;
double fDocumentDouble = 0.0 ;
CTransfer * transfer = m_TransferCache . at ( m_iSortedIndexes [ iRowIndex ] ) ;
bool bNeedRefresh = false ;
strDocumentText . Empty ( ) ;
switch ( iColumnIndex ) {
2004-12-02 07:43:47 +00:00
case COLUMN_PROJECT :
2008-06-27 10:05:47 +00:00
GetDocProjectName ( m_iSortedIndexes [ iRowIndex ] , strDocumentText ) ;
if ( ! strDocumentText . IsSameAs ( transfer - > m_strProjectName ) ) {
transfer - > m_strProjectName = strDocumentText ;
bNeedRefresh = true ;
}
2004-12-02 07:43:47 +00:00
break ;
case COLUMN_FILE :
2008-06-27 10:05:47 +00:00
GetDocFileName ( m_iSortedIndexes [ iRowIndex ] , strDocumentText ) ;
if ( ! strDocumentText . IsSameAs ( transfer - > m_strFileName ) ) {
transfer - > m_strFileName = strDocumentText ;
bNeedRefresh = true ;
}
2004-12-02 07:43:47 +00:00
break ;
case COLUMN_PROGRESS :
2008-06-27 10:05:47 +00:00
GetDocProgress ( m_iSortedIndexes [ iRowIndex ] , fDocumentFloat ) ;
if ( fDocumentFloat ! = transfer - > m_fProgress ) {
transfer - > m_fProgress = fDocumentFloat ;
bNeedRefresh = true ;
}
2004-12-02 07:43:47 +00:00
break ;
case COLUMN_SIZE :
2008-06-27 10:05:47 +00:00
GetDocBytesXferred ( m_iSortedIndexes [ iRowIndex ] , fDocumentDouble ) ;
if ( fDocumentDouble ! = transfer - > m_fBytesXferred ) {
transfer - > m_fBytesXferred = fDocumentDouble ;
bNeedRefresh = true ;
}
GetDocTotalBytes ( m_iSortedIndexes [ iRowIndex ] , fDocumentDouble ) ;
if ( fDocumentDouble ! = transfer - > m_fTotalBytes ) {
transfer - > m_fTotalBytes = fDocumentDouble ;
bNeedRefresh = true ;
}
2004-12-02 07:43:47 +00:00
break ;
case COLUMN_TIME :
2008-06-27 10:05:47 +00:00
GetDocTime ( m_iSortedIndexes [ iRowIndex ] , fDocumentDouble ) ;
if ( fDocumentDouble ! = transfer - > m_dTime ) {
transfer - > m_dTime = fDocumentDouble ;
bNeedRefresh = true ;
}
2004-12-02 07:43:47 +00:00
break ;
case COLUMN_SPEED :
2008-06-27 10:05:47 +00:00
GetDocSpeed ( m_iSortedIndexes [ iRowIndex ] , fDocumentDouble ) ;
if ( fDocumentDouble ! = transfer - > m_dSpeed ) {
transfer - > m_dSpeed = fDocumentDouble ;
bNeedRefresh = true ;
}
2004-12-02 07:43:47 +00:00
break ;
case COLUMN_STATUS :
2008-06-27 10:05:47 +00:00
GetDocStatus ( m_iSortedIndexes [ iRowIndex ] , strDocumentText ) ;
if ( ! strDocumentText . IsSameAs ( transfer - > m_strStatus ) ) {
transfer - > m_strStatus = strDocumentText ;
return true ;
}
2004-12-02 07:43:47 +00:00
break ;
}
2008-06-27 10:05:47 +00:00
return bNeedRefresh ;
2004-12-02 07:43:47 +00:00
}
2008-06-27 10:05:47 +00:00
void CViewTransfers : : GetDocProjectName ( wxInt32 item , wxString & strBuffer ) const {
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
2006-01-09 14:03:13 +00:00
2008-06-27 10:05:47 +00:00
if ( transfer ) {
strBuffer = wxString ( transfer - > project_name . c_str ( ) , wxConvUTF8 ) ;
2005-04-22 06:06:22 +00:00
} else {
2008-06-27 10:05:47 +00:00
strBuffer = wxEmptyString ;
2005-04-22 06:06:22 +00:00
}
2004-09-24 22:19:02 +00:00
}
2005-04-07 07:04:50 +00:00
wxInt32 CViewTransfers : : FormatProjectName ( wxInt32 item , wxString & strBuffer ) const {
2008-06-27 10:05:47 +00:00
CTransfer * transfer = m_TransferCache . at ( m_iSortedIndexes [ item ] ) ;
strBuffer = HtmlEntityDecode ( transfer - > m_strProjectName ) ;
2004-10-22 00:41:18 +00:00
return 0 ;
}
2008-06-27 10:05:47 +00:00
void CViewTransfers : : GetDocFileName ( wxInt32 item , wxString & strBuffer ) const {
2005-06-13 08:47:51 +00:00
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
2004-10-22 00:41:18 +00:00
2005-06-13 08:47:51 +00:00
if ( transfer ) {
2006-03-23 01:17:07 +00:00
strBuffer = wxString ( transfer - > name . c_str ( ) , wxConvUTF8 ) ;
2008-06-27 10:05:47 +00:00
} else {
strBuffer = wxEmptyString ;
2005-06-13 08:47:51 +00:00
}
2008-06-27 10:05:47 +00:00
}
wxInt32 CViewTransfers : : FormatFileName ( wxInt32 item , wxString & strBuffer ) const {
CTransfer * transfer = m_TransferCache . at ( m_iSortedIndexes [ item ] ) ;
strBuffer = transfer - > m_strFileName ;
2004-10-22 00:41:18 +00:00
return 0 ;
}
2008-06-27 10:05:47 +00:00
void CViewTransfers : : GetDocProgress ( wxInt32 item , float & fBuffer ) const {
2004-10-22 08:51:50 +00:00
float fBytesSent = 0 ;
float fFileSize = 0 ;
2005-06-13 08:47:51 +00:00
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
2004-10-22 08:51:50 +00:00
2008-06-27 10:05:47 +00:00
fBuffer = 0 ;
2005-06-13 08:47:51 +00:00
if ( transfer ) {
2006-02-15 02:25:14 +00:00
fBytesSent = transfer - > bytes_xferred ;
2005-06-13 08:47:51 +00:00
fFileSize = transfer - > nbytes ;
}
2004-10-22 08:51:50 +00:00
2005-11-03 01:36:37 +00:00
// Curl apparently counts the HTTP header in byte count.
// Prevent this from causing > 100% display
//
if ( fBytesSent > fFileSize ) {
fBytesSent = fFileSize ;
}
2008-06-27 10:05:47 +00:00
if ( fFileSize ) {
fBuffer = floor ( ( fBytesSent / fFileSize ) * 10000 ) / 100 ;
2006-02-15 02:25:14 +00:00
}
2008-06-27 10:05:47 +00:00
}
2004-10-22 08:51:50 +00:00
2008-06-27 10:05:47 +00:00
wxInt32 CViewTransfers : : FormatProgress ( wxInt32 item , wxString & strBuffer ) const {
CTransfer * transfer = m_TransferCache . at ( m_iSortedIndexes [ item ] ) ;
strBuffer . Printf ( wxT ( " %.2f%% " ) , transfer - > m_fProgress ) ;
2004-10-22 00:41:18 +00:00
return 0 ;
}
2008-06-27 10:05:47 +00:00
void CViewTransfers : : GetDocBytesXferred ( wxInt32 item , double & fBuffer ) const {
2005-06-13 08:47:51 +00:00
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
2004-10-22 08:51:50 +00:00
2005-06-13 08:47:51 +00:00
if ( transfer ) {
2008-06-27 10:05:47 +00:00
fBuffer = transfer - > bytes_xferred ;
} else {
fBuffer = 0.0 ;
2005-06-13 08:47:51 +00:00
}
2008-06-27 10:05:47 +00:00
}
void CViewTransfers : : GetDocTotalBytes ( wxInt32 item , double & fBuffer ) const {
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
if ( transfer ) {
fBuffer = transfer - > nbytes ;
} else {
fBuffer = 0.0 ;
}
}
wxInt32 CViewTransfers : : FormatSize ( wxInt32 item , wxString & strBuffer ) const {
double xTera = 1099511627776.0 ;
double xGiga = 1073741824.0 ;
double xMega = 1048576.0 ;
double xKilo = 1024.0 ;
CTransfer * transfer = m_TransferCache . at ( m_iSortedIndexes [ item ] ) ;
double fBytesSent = transfer - > m_fBytesXferred ;
double fFileSize = transfer - > m_fTotalBytes ;
2005-04-07 07:04:50 +00:00
if ( fFileSize ! = 0 ) {
if ( fFileSize > = xTera ) {
strBuffer . Printf ( wxT ( " %0.2f/%0.2f TB " ) , fBytesSent / xTera , fFileSize / xTera ) ;
} else if ( fFileSize > = xGiga ) {
strBuffer . Printf ( wxT ( " %0.2f/%0.2f GB " ) , fBytesSent / xGiga , fFileSize / xGiga ) ;
} else if ( fFileSize > = xMega ) {
strBuffer . Printf ( wxT ( " %0.2f/%0.2f MB " ) , fBytesSent / xMega , fFileSize / xMega ) ;
} else if ( fFileSize > = xKilo ) {
strBuffer . Printf ( wxT ( " %0.2f/%0.2f KB " ) , fBytesSent / xKilo , fFileSize / xKilo ) ;
} else {
strBuffer . Printf ( wxT ( " %0.0f/%0.0f bytes " ) , fBytesSent , fFileSize ) ;
2004-10-22 08:51:50 +00:00
}
2005-04-07 07:04:50 +00:00
} else {
if ( fBytesSent > = xTera ) {
strBuffer . Printf ( wxT ( " %0.2f TB " ) , fBytesSent / xTera ) ;
} else if ( fBytesSent > = xGiga ) {
strBuffer . Printf ( wxT ( " %0.2f GB " ) , fBytesSent / xGiga ) ;
} else if ( fBytesSent > = xMega ) {
strBuffer . Printf ( wxT ( " %0.2f MB " ) , fBytesSent / xMega ) ;
} else if ( fBytesSent > = xKilo ) {
strBuffer . Printf ( wxT ( " %0.2f KB " ) , fBytesSent / xKilo ) ;
} else {
strBuffer . Printf ( wxT ( " %0.0f bytes " ) , fBytesSent ) ;
2004-10-22 08:51:50 +00:00
}
}
2005-06-13 08:47:51 +00:00
2004-10-22 00:41:18 +00:00
return 0 ;
}
2008-06-27 10:05:47 +00:00
void CViewTransfers : : GetDocTime ( wxInt32 item , double & fBuffer ) const {
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
if ( transfer ) {
fBuffer = transfer - > time_so_far ;
} else {
fBuffer = 0.0 ;
}
}
2005-04-07 07:04:50 +00:00
wxInt32 CViewTransfers : : FormatTime ( wxInt32 item , wxString & strBuffer ) const {
2004-10-22 19:23:09 +00:00
wxInt32 iHour = 0 ;
wxInt32 iMin = 0 ;
wxInt32 iSec = 0 ;
wxTimeSpan ts ;
2008-06-27 10:05:47 +00:00
CTransfer * transfer = m_TransferCache . at ( m_iSortedIndexes [ item ] ) ;
2004-10-22 18:39:21 +00:00
2008-06-27 10:05:47 +00:00
float fBuffer = transfer - > m_dTime ;
2004-10-22 18:39:21 +00:00
2004-10-22 19:23:09 +00:00
iHour = ( wxInt32 ) ( fBuffer / ( 60 * 60 ) ) ;
iMin = ( wxInt32 ) ( fBuffer / 60 ) % 60 ;
iSec = ( wxInt32 ) ( fBuffer ) % 60 ;
2005-04-07 07:04:50 +00:00
ts = wxTimeSpan ( iHour , iMin , iSec ) ;
2004-10-22 18:39:21 +00:00
2004-10-22 19:23:09 +00:00
strBuffer = ts . Format ( ) ;
2004-10-22 18:39:21 +00:00
2004-10-22 00:41:18 +00:00
return 0 ;
}
2008-06-27 10:05:47 +00:00
void CViewTransfers : : GetDocSpeed ( wxInt32 item , double & fBuffer ) const {
2005-06-13 08:47:51 +00:00
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
2004-10-22 08:51:50 +00:00
2005-06-13 08:47:51 +00:00
if ( transfer ) {
if ( transfer - > xfer_active )
2008-06-27 10:05:47 +00:00
fBuffer = transfer - > xfer_speed / 1024 ;
2005-06-13 08:47:51 +00:00
else
2008-06-27 10:05:47 +00:00
fBuffer = 0.0 ;
2005-04-07 07:04:50 +00:00
}
2008-06-27 10:05:47 +00:00
}
2004-10-22 08:51:50 +00:00
2008-06-27 10:05:47 +00:00
wxInt32 CViewTransfers : : FormatSpeed ( wxInt32 item , wxString & strBuffer ) const {
CTransfer * transfer = m_TransferCache . at ( m_iSortedIndexes [ item ] ) ;
strBuffer . Printf ( wxT ( " %.2f KBps " ) , transfer - > m_dSpeed ) ;
2005-06-13 08:47:51 +00:00
2004-10-22 00:41:18 +00:00
return 0 ;
}
2008-06-27 10:05:47 +00:00
void CViewTransfers : : GetDocStatus ( wxInt32 item , wxString & strBuffer ) const {
2005-06-13 08:47:51 +00:00
CMainDocument * doc = wxGetApp ( ) . GetDocument ( ) ;
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
2006-08-31 19:24:38 +00:00
CC_STATUS status ;
2004-10-22 18:39:21 +00:00
2005-06-13 08:47:51 +00:00
wxASSERT ( doc ) ;
wxASSERT ( wxDynamicCast ( doc , CMainDocument ) ) ;
2004-10-22 18:39:21 +00:00
2006-08-31 19:24:38 +00:00
doc - > GetCoreClientStatus ( status ) ;
2005-02-22 07:10:44 +00:00
2005-06-13 08:47:51 +00:00
wxDateTime dtNextRequest ( ( time_t ) transfer - > next_request_time ) ;
2004-10-22 18:39:21 +00:00
wxDateTime dtNow ( wxDateTime : : Now ( ) ) ;
2005-08-26 18:13:36 +00:00
if ( transfer ) {
if ( dtNextRequest > dtNow ) {
wxTimeSpan tsNextRequest ( dtNextRequest - dtNow ) ;
strBuffer = _ ( " Retry in " ) + tsNextRequest . Format ( ) ;
} else if ( ERR_GIVEUP_DOWNLOAD = = transfer - > status ) {
strBuffer = _ ( " Download failed " ) ;
} else if ( ERR_GIVEUP_UPLOAD = = transfer - > status ) {
strBuffer = _ ( " Upload failed " ) ;
2005-04-07 07:04:50 +00:00
} else {
2006-08-31 19:24:38 +00:00
if ( status . network_suspend_reason ) {
2005-08-26 18:13:36 +00:00
strBuffer = _ ( " Suspended " ) ;
} else {
2006-03-04 00:53:20 +00:00
if ( transfer - > xfer_active ) {
strBuffer = transfer - > generated_locally ? _ ( " Uploading " ) : _ ( " Downloading " ) ;
} else {
strBuffer = transfer - > generated_locally ? _ ( " Upload pending " ) : _ ( " Download pending " ) ;
}
2005-08-26 18:13:36 +00:00
}
2005-02-22 07:10:44 +00:00
}
2004-10-22 18:39:21 +00:00
}
2008-06-27 10:05:47 +00:00
}
wxInt32 CViewTransfers : : FormatStatus ( wxInt32 item , wxString & strBuffer ) const {
CTransfer * transfer = m_TransferCache . at ( m_iSortedIndexes [ item ] ) ;
strBuffer = transfer - > m_strStatus ;
2004-10-22 18:39:21 +00:00
2004-10-22 00:41:18 +00:00
return 0 ;
}
2004-12-08 00:40:19 +00:00
2008-06-24 10:52:12 +00:00
double CViewTransfers : : GetProgressValue ( long item ) {
2008-06-27 10:05:47 +00:00
double fBytesSent = 0 ;
double fFileSize = 0 ;
FILE_TRANSFER * transfer = wxGetApp ( ) . GetDocument ( ) - > file_transfer ( item ) ;
2008-06-24 10:52:12 +00:00
if ( transfer ) {
fBytesSent = transfer - > bytes_xferred ;
fFileSize = transfer - > nbytes ;
}
// Curl apparently counts the HTTP header in byte count.
// Prevent this from causing > 100% display
//
if ( fBytesSent > fFileSize ) {
fBytesSent = fFileSize ;
}
if ( 0.0 = = fFileSize ) return 0.0 ;
return ( fBytesSent / fFileSize ) ;
}
2005-01-02 18:29:53 +00:00
const char * BOINC_RCSID_7aadb93332 = " $Id$ " ;