From c8cbeaf5f703b17c1fabb40afc6e96ffc6d9d171 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Mon, 8 Sep 2008 09:11:56 +0000 Subject: [PATCH] MGR: Make formatting of List Views more efficient; fix progress bars in transfers tab svn path=/trunk/boinc/; revision=15976 --- checkin_notes | 11 ++++ clientgui/BOINCBaseView.cpp | 2 - clientgui/ViewProjects.cpp | 96 ++++++++++++++++++--------------- clientgui/ViewProjects.h | 9 ++-- clientgui/ViewTransfers.cpp | 98 ++++++++++++++-------------------- clientgui/ViewTransfers.h | 15 +++--- clientgui/ViewWork.cpp | 102 +++++++++++++++--------------------- clientgui/ViewWork.h | 15 +++--- 8 files changed, 168 insertions(+), 180 deletions(-) diff --git a/checkin_notes b/checkin_notes index 03b009a239..c832589635 100644 --- a/checkin_notes +++ b/checkin_notes @@ -7277,3 +7277,14 @@ David 7 Sept 2008 hosts_user.php login_form.php top_users.php + +Charlie 8 Sep 2008 + MGR: Make formatting of List Views more efficient; fix bug which showed + progress bars in wrong rows in transfers tab. + + clientgui/ + BOINCBaseView.cpp + ViewProjects.cpp,.h + ViewTransfers.cpp,.h + ViewWork.cpp,.h + diff --git a/clientgui/BOINCBaseView.cpp b/clientgui/BOINCBaseView.cpp index fd95189ffa..22f98732d8 100644 --- a/clientgui/BOINCBaseView.cpp +++ b/clientgui/BOINCBaseView.cpp @@ -445,7 +445,6 @@ int CBOINCBaseView::SynchronizeCache() { iRowTotal = GetDocCount(); iColumnTotal = m_pListPane->GetColumnCount(); -// Freeze(); // To reduce flicker for (iRowIndex = 0; iRowIndex < iRowTotal; iRowIndex++) { bNeedRefreshData = false; @@ -468,7 +467,6 @@ int CBOINCBaseView::SynchronizeCache() { sortData(); // Will mark moved items as needing refresh } -// Thaw(); return 0; } diff --git a/clientgui/ViewProjects.cpp b/clientgui/ViewProjects.cpp index 142ce96334..a89bea16dd 100644 --- a/clientgui/ViewProjects.cpp +++ b/clientgui/ViewProjects.cpp @@ -57,6 +57,9 @@ CProject::CProject() { + m_fTotalCredit = -1.0; + m_fAVGCredit = -1.0; + m_fResourceShare = -1.0; } @@ -64,9 +67,6 @@ CProject::~CProject() { m_strProjectName.Clear(); m_strAccountName.Clear(); m_strTeamName.Clear(); - m_fTotalCredit = 0.0; - m_fAVGCredit = 0.0; - m_fResourceShare = 0.0; m_strStatus.Clear(); } @@ -528,33 +528,43 @@ wxInt32 CViewProjects::GetDocCount() { wxString CViewProjects::OnListGetItemText(long item, long column) const { + CProject* project = NULL; 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; + try { + project = m_ProjectCache.at(m_iSortedIndexes[item]); + } catch ( std::out_of_range ) { + project = NULL; } - return strBuffer; + + 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; } @@ -742,6 +752,7 @@ bool CViewProjects::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex GetDocTotalCredit(m_iSortedIndexes[iRowIndex], fDocumentFloat); if (fDocumentFloat != project->m_fTotalCredit) { project->m_fTotalCredit = fDocumentFloat; + FormatTotalCredit(fDocumentFloat, project->m_strTotalCredit); return true; } break; @@ -749,6 +760,7 @@ bool CViewProjects::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex GetDocAVGCredit(m_iSortedIndexes[iRowIndex], fDocumentFloat); if (fDocumentFloat != project->m_fAVGCredit) { project->m_fAVGCredit = fDocumentFloat; + FormatAVGCredit(fDocumentFloat, project->m_strAVGCredit); return true; } break; @@ -756,6 +768,7 @@ bool CViewProjects::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex GetDocResourceShare(m_iSortedIndexes[iRowIndex], fDocumentFloat); if (fDocumentFloat != project->m_fResourceShare) { project->m_fResourceShare = fDocumentFloat; + FormatResourceShare(fDocumentFloat, project->m_strResourceShare); return true; } break; @@ -778,7 +791,7 @@ void CViewProjects::GetDocProjectName(wxInt32 item, wxString& strBuffer) const { if (project) { project->get_name(project_name); - strBuffer = wxString(project_name.c_str(), wxConvUTF8); + strBuffer = strBuffer = HtmlEntityDecode(wxString(project_name.c_str(), wxConvUTF8)); } else { strBuffer = wxEmptyString; } @@ -787,7 +800,7 @@ void CViewProjects::GetDocProjectName(wxInt32 item, wxString& strBuffer) const { wxInt32 CViewProjects::FormatProjectName(wxInt32 item, wxString& strBuffer) const { CProject* project = m_ProjectCache.at(m_iSortedIndexes[item]); - strBuffer = HtmlEntityDecode(project->m_strProjectName); + strBuffer = project->m_strProjectName; return 0; } @@ -797,7 +810,7 @@ void CViewProjects::GetDocAccountName(wxInt32 item, wxString& strBuffer) const { PROJECT* project = wxGetApp().GetDocument()->project(item); if (project) { - strBuffer = wxString(project->user_name.c_str(), wxConvUTF8); + strBuffer = HtmlEntityDecode(wxString(project->user_name.c_str(), wxConvUTF8)); } else { strBuffer = wxEmptyString; } @@ -806,7 +819,7 @@ void CViewProjects::GetDocAccountName(wxInt32 item, wxString& strBuffer) const { wxInt32 CViewProjects::FormatAccountName(wxInt32 item, wxString& strBuffer) const { CProject* project = m_ProjectCache.at(m_iSortedIndexes[item]); - strBuffer = HtmlEntityDecode(project->m_strAccountName); + strBuffer = project->m_strAccountName; return 0; } @@ -816,7 +829,7 @@ void CViewProjects::GetDocTeamName(wxInt32 item, wxString& strBuffer) const { PROJECT* project = wxGetApp().GetDocument()->project(item); if (project) { - strBuffer = wxString(project->team_name.c_str(), wxConvUTF8); + strBuffer = HtmlEntityDecode(wxString(project->team_name.c_str(), wxConvUTF8)); } else { strBuffer = wxEmptyString; } @@ -825,7 +838,7 @@ void CViewProjects::GetDocTeamName(wxInt32 item, wxString& strBuffer) const { wxInt32 CViewProjects::FormatTeamName(wxInt32 item, wxString& strBuffer) const { CProject* project = m_ProjectCache.at(m_iSortedIndexes[item]); - strBuffer = HtmlEntityDecode(project->m_strTeamName); + strBuffer = project->m_strTeamName; return 0; } @@ -842,9 +855,8 @@ void CViewProjects::GetDocTotalCredit(wxInt32 item, float& fBuffer) const { } -wxInt32 CViewProjects::FormatTotalCredit(wxInt32 item, wxString& strBuffer) const { - CProject* project = m_ProjectCache.at(m_iSortedIndexes[item]); - strBuffer.Printf(wxT("%0.2f"), project->m_fTotalCredit); +wxInt32 CViewProjects::FormatTotalCredit(float fBuffer, wxString& strBuffer) const { + strBuffer.Printf(wxT("%0.2f"), fBuffer); return 0; } @@ -861,9 +873,8 @@ void CViewProjects::GetDocAVGCredit(wxInt32 item, float& fBuffer) const { } -wxInt32 CViewProjects::FormatAVGCredit(wxInt32 item, wxString& strBuffer) const { - CProject* project = m_ProjectCache.at(m_iSortedIndexes[item]); - strBuffer.Printf(wxT("%0.2f"), project->m_fAVGCredit); +wxInt32 CViewProjects::FormatAVGCredit(float fBuffer, wxString& strBuffer) const { + strBuffer.Printf(wxT("%0.2f"), fBuffer); return 0; } @@ -880,17 +891,16 @@ void CViewProjects::GetDocResourceShare(wxInt32 item, float& fBuffer) const { } -wxInt32 CViewProjects::FormatResourceShare(wxInt32 item, wxString& strBuffer) const { +wxInt32 CViewProjects::FormatResourceShare(float fBuffer, wxString& strBuffer) const { CMainDocument* pDoc = wxGetApp().GetDocument(); - CProject* project = m_ProjectCache.at(m_iSortedIndexes[item]); wxASSERT(pDoc); wxASSERT(wxDynamicCast(pDoc, CMainDocument)); - if (project && pDoc) { + if (pDoc) { strBuffer.Printf(wxT("%0.0f (%0.2f%%)"), - project->m_fResourceShare, - ((project->m_fResourceShare / pDoc->m_fProjectTotalResourceShare) * 100) + fBuffer, + ((fBuffer / pDoc->m_fProjectTotalResourceShare) * 100) ); } diff --git a/clientgui/ViewProjects.h b/clientgui/ViewProjects.h index 8d571269cc..bdbf3fe2e9 100644 --- a/clientgui/ViewProjects.h +++ b/clientgui/ViewProjects.h @@ -40,6 +40,9 @@ public: float m_fResourceShare; wxString m_strStatus; wxString m_strProjectURL; // Used internally, not displayed + wxString m_strTotalCredit; + wxString m_strAVGCredit; + wxString m_strResourceShare; }; @@ -89,11 +92,11 @@ protected: void GetDocTeamName(wxInt32 item, wxString& strBuffer) const; wxInt32 FormatTeamName( wxInt32 item, wxString& strBuffer ) const; void GetDocTotalCredit(wxInt32 item, float& fBuffer) const; - wxInt32 FormatTotalCredit( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatTotalCredit( float fBuffer, wxString& strBuffer ) const; void GetDocAVGCredit(wxInt32 item, float& fBuffer) const; - wxInt32 FormatAVGCredit( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatAVGCredit( float fBuffer, wxString& strBuffer ) const; void GetDocResourceShare(wxInt32 item, float& fBuffer) const; - wxInt32 FormatResourceShare( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatResourceShare( float fBuffer, wxString& strBuffer ) const; void GetDocStatus(wxInt32 item, wxString& strBuffer) const; wxInt32 FormatStatus( wxInt32 item, wxString& strBuffer ) const; void GetDocProjectURL(wxInt32 item, wxString& strBuffer) const; diff --git a/clientgui/ViewTransfers.cpp b/clientgui/ViewTransfers.cpp index cb2c8a2fe4..60ba82108e 100644 --- a/clientgui/ViewTransfers.cpp +++ b/clientgui/ViewTransfers.cpp @@ -48,17 +48,17 @@ CTransfer::CTransfer() { + m_fProgress = -1.0; + m_fBytesXferred = -1.0; + m_fTotalBytes = -1.0; + m_dTime = -1.0; + m_dSpeed = -1.0; } CTransfer::~CTransfer() { m_strProjectName.Clear(); m_strFileName.Clear(); - m_fProgress = 0.0; - m_fBytesXferred = 0.0; - m_fTotalBytes = 0.0; - m_dTime = 0.0; - m_dSpeed = 0.0; m_strStatus.Clear(); } @@ -322,30 +322,39 @@ wxInt32 CViewTransfers::GetDocCount() { wxString CViewTransfers::OnListGetItemText(long item, long column) const { + CTransfer* transfer; wxString strBuffer = wxEmptyString; - switch(column) { + try { + transfer = m_TransferCache.at(m_iSortedIndexes[item]); + } catch ( std::out_of_range ) { + transfer = NULL; + } + + if (transfer) { + switch(column) { case COLUMN_PROJECT: - FormatProjectName(item, strBuffer); + strBuffer = transfer->m_strProjectName; break; case COLUMN_FILE: - FormatFileName(item, strBuffer); + strBuffer = transfer->m_strFileName; break; case COLUMN_PROGRESS: - FormatProgress(item, strBuffer); + strBuffer = transfer->m_strProgress; break; case COLUMN_SIZE: - FormatSize(item, strBuffer); + strBuffer = transfer->m_strSize; break; case COLUMN_TIME: - FormatTime(item, strBuffer); + strBuffer = transfer->m_strTime; break; case COLUMN_SPEED: - FormatSpeed(item, strBuffer); + strBuffer = transfer->m_strSpeed; break; case COLUMN_STATUS: - FormatStatus(item, strBuffer); + strBuffer = transfer->m_strStatus; break; + } } return strBuffer; @@ -411,7 +420,7 @@ bool CViewTransfers::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnInde wxString strDocumentText = wxEmptyString; wxString strDocumentText2 = wxEmptyString; float fDocumentFloat = 0.0; - double fDocumentDouble = 0.0; + double fDocumentDouble = 0.0, fDocumentDouble2 = 0.0; CTransfer* transfer = m_TransferCache.at(m_iSortedIndexes[iRowIndex]); bool bNeedRefresh = false; @@ -438,18 +447,19 @@ bool CViewTransfers::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnInde GetDocProgress(m_iSortedIndexes[iRowIndex], fDocumentFloat); if (fDocumentFloat != transfer->m_fProgress) { transfer->m_fProgress = fDocumentFloat; + FormatProgress(fDocumentFloat, transfer->m_strProgress); bNeedRefresh = true; } break; case COLUMN_SIZE: GetDocBytesXferred(m_iSortedIndexes[iRowIndex], fDocumentDouble); - if (fDocumentDouble != transfer->m_fBytesXferred) { + GetDocTotalBytes(m_iSortedIndexes[iRowIndex], fDocumentDouble2); + if (( fDocumentDouble != transfer->m_fBytesXferred) || + (fDocumentDouble2 != transfer->m_fTotalBytes) + ) { transfer->m_fBytesXferred = fDocumentDouble; - bNeedRefresh = true; - } - GetDocTotalBytes(m_iSortedIndexes[iRowIndex], fDocumentDouble); - if (fDocumentDouble != transfer->m_fTotalBytes) { - transfer->m_fTotalBytes = fDocumentDouble; + transfer->m_fTotalBytes = fDocumentDouble2; + FormatSize(fDocumentDouble, fDocumentDouble2, transfer->m_strSize); bNeedRefresh = true; } break; @@ -457,6 +467,7 @@ bool CViewTransfers::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnInde GetDocTime(m_iSortedIndexes[iRowIndex], fDocumentDouble); if (fDocumentDouble != transfer->m_dTime) { transfer->m_dTime = fDocumentDouble; + FormatTime(fDocumentDouble, transfer->m_strTime); bNeedRefresh = true; } break; @@ -464,6 +475,7 @@ bool CViewTransfers::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnInde GetDocSpeed(m_iSortedIndexes[iRowIndex], fDocumentDouble); if (fDocumentDouble != transfer->m_dSpeed) { transfer->m_dSpeed = fDocumentDouble; + FormatSpeed(fDocumentDouble, transfer->m_strSpeed); bNeedRefresh = true; } break; @@ -484,20 +496,13 @@ void CViewTransfers::GetDocProjectName(wxInt32 item, wxString& strBuffer) const FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item); if (transfer) { - strBuffer = wxString(transfer->project_name.c_str(), wxConvUTF8); + strBuffer = HtmlEntityDecode(wxString(transfer->project_name.c_str(), wxConvUTF8)); } else { strBuffer = wxEmptyString; } } -wxInt32 CViewTransfers::FormatProjectName(wxInt32 item, wxString& strBuffer) const { - CTransfer* transfer = m_TransferCache.at(m_iSortedIndexes[item]); - strBuffer = HtmlEntityDecode(transfer->m_strProjectName); - return 0; -} - - void CViewTransfers::GetDocFileName(wxInt32 item, wxString& strBuffer) const { FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item); @@ -509,13 +514,6 @@ void CViewTransfers::GetDocFileName(wxInt32 item, wxString& strBuffer) const { } -wxInt32 CViewTransfers::FormatFileName(wxInt32 item, wxString& strBuffer) const { - CTransfer* transfer = m_TransferCache.at(m_iSortedIndexes[item]); - strBuffer = transfer->m_strFileName; - return 0; -} - - void CViewTransfers::GetDocProgress(wxInt32 item, float& fBuffer) const { float fBytesSent = 0; float fFileSize = 0; @@ -540,9 +538,8 @@ void CViewTransfers::GetDocProgress(wxInt32 item, float& fBuffer) const { } -wxInt32 CViewTransfers::FormatProgress(wxInt32 item, wxString& strBuffer) const { - CTransfer* transfer = m_TransferCache.at(m_iSortedIndexes[item]); - strBuffer.Printf(wxT("%.2f%%"), transfer->m_fProgress); +wxInt32 CViewTransfers::FormatProgress(float fBuffer, wxString& strBuffer) const { + strBuffer.Printf(wxT("%.2f%%"), fBuffer); return 0; } @@ -569,14 +566,11 @@ void CViewTransfers::GetDocTotalBytes(wxInt32 item, double& fBuffer) const { } -wxInt32 CViewTransfers::FormatSize(wxInt32 item, wxString& strBuffer) const { +wxInt32 CViewTransfers::FormatSize(double fBytesSent, double fFileSize, 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; if (fFileSize != 0) { if (fFileSize >= xTera) { @@ -619,14 +613,11 @@ void CViewTransfers::GetDocTime(wxInt32 item, double& fBuffer) const { } -wxInt32 CViewTransfers::FormatTime(wxInt32 item, wxString& strBuffer) const { +wxInt32 CViewTransfers::FormatTime(double fBuffer, wxString& strBuffer) const { wxInt32 iHour = 0; wxInt32 iMin = 0; wxInt32 iSec = 0; wxTimeSpan ts; - CTransfer* transfer = m_TransferCache.at(m_iSortedIndexes[item]); - - float fBuffer = transfer->m_dTime; iHour = (wxInt32)(fBuffer / (60 * 60)); iMin = (wxInt32)(fBuffer / 60) % 60; @@ -652,9 +643,8 @@ void CViewTransfers::GetDocSpeed(wxInt32 item, double& fBuffer) const { } -wxInt32 CViewTransfers::FormatSpeed(wxInt32 item, wxString& strBuffer) const { - CTransfer* transfer = m_TransferCache.at(m_iSortedIndexes[item]); - strBuffer.Printf(wxT("%.2f KBps"), transfer->m_dSpeed); +wxInt32 CViewTransfers::FormatSpeed(double fBuffer, wxString& strBuffer) const { + strBuffer.Printf(wxT("%.2f KBps"), fBuffer); return 0; } @@ -696,14 +686,6 @@ void CViewTransfers::GetDocStatus(wxInt32 item, wxString& strBuffer) const { } -wxInt32 CViewTransfers::FormatStatus(wxInt32 item, wxString& strBuffer) const { - CTransfer* transfer = m_TransferCache.at(m_iSortedIndexes[item]); - strBuffer = transfer->m_strStatus; - - return 0; -} - - void CViewTransfers::GetDocProjectURL(wxInt32 item, wxString& strBuffer) const { FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item); @@ -718,7 +700,7 @@ void CViewTransfers::GetDocProjectURL(wxInt32 item, wxString& strBuffer) const { double CViewTransfers::GetProgressValue(long item) { double fBytesSent = 0; double fFileSize = 0; - FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(item); + FILE_TRANSFER* transfer = wxGetApp().GetDocument()->file_transfer(m_iSortedIndexes[item]); if (transfer) { fBytesSent = transfer->bytes_xferred; diff --git a/clientgui/ViewTransfers.h b/clientgui/ViewTransfers.h index 74a72ceb4f..32acd174c0 100644 --- a/clientgui/ViewTransfers.h +++ b/clientgui/ViewTransfers.h @@ -40,6 +40,10 @@ public: double m_dSpeed; wxString m_strStatus; wxString m_strProjectURL; // Used internally, not displayed + wxString m_strProgress; + wxString m_strSize; + wxString m_strTime; + wxString m_strSpeed; }; @@ -78,20 +82,17 @@ protected: virtual void UpdateSelection(); void GetDocProjectName(wxInt32 item, wxString& strBuffer) const; - wxInt32 FormatProjectName( wxInt32 item, wxString& strBuffer ) const; void GetDocFileName(wxInt32 item, wxString& strBuffer) const; - wxInt32 FormatFileName( wxInt32 item, wxString& strBuffer ) const; void GetDocProgress(wxInt32 item, float& fBuffer) const; - wxInt32 FormatProgress( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatProgress( float fBuffer, wxString& strBuffer ) const; void GetDocBytesXferred(wxInt32 item, double& fBuffer) const; void GetDocTotalBytes(wxInt32 item, double& fBuffer) const; - wxInt32 FormatSize( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatSize( double fBytesSent, double fFileSize, wxString& strBuffer ) const; void GetDocTime(wxInt32 item, double& fBuffer) const; - wxInt32 FormatTime( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatTime( double fBuffer, wxString& strBuffer ) const; void GetDocSpeed(wxInt32 item, double& fBuffer) const; - wxInt32 FormatSpeed( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatSpeed( double fBuffer, wxString& strBuffer ) const; void GetDocStatus(wxInt32 item, wxString& strBuffer) const; - wxInt32 FormatStatus( wxInt32 item, wxString& strBuffer ) const; void GetDocProjectURL(wxInt32 item, wxString& strBuffer) const; virtual double GetProgressValue(long item); diff --git a/clientgui/ViewWork.cpp b/clientgui/ViewWork.cpp index aec7678c77..6ae98ebc8d 100644 --- a/clientgui/ViewWork.cpp +++ b/clientgui/ViewWork.cpp @@ -57,6 +57,10 @@ CWork::CWork() { + m_fCPUTime = -1.0; + m_fProgress = -1.0; + m_fTimeToCompletion = -1.0; + m_tReportDeadline = (time_t)0; } @@ -64,11 +68,12 @@ CWork::~CWork() { m_strProjectName.Clear(); m_strApplicationName.Clear(); m_strName.Clear(); - m_fCPUTime = 0.0; - m_fProgress = 0.0; - m_fTimeToCompletion = 0.0; - m_tReportDeadline = (time_t)0; m_strStatus.Clear(); + m_strProjectURL.Clear(); + m_strCPUTime.Clear(); + m_strProgress.Clear(); + m_strTimeToCompletion.Clear(); + m_strReportDeadline.Clear(); } @@ -362,11 +367,9 @@ void CViewWork::OnWorkAbort( wxCommandEvent& WXUNUSED(event) ) { wxInt32 iAnswer = 0; wxInt32 iResult = 0; wxString strMessage = wxEmptyString; - wxString strName = wxEmptyString; - wxString strProgress = wxEmptyString; - wxString strStatus = wxEmptyString; CMainDocument* pDoc = wxGetApp().GetDocument(); CAdvancedFrame* pFrame = wxDynamicCast(GetParent()->GetParent()->GetParent(), CAdvancedFrame); + CWork* work; int row; wxASSERT(pDoc); @@ -388,15 +391,13 @@ void CViewWork::OnWorkAbort( wxCommandEvent& WXUNUSED(event) ) { if (row < 0) break; iResult = m_iSortedIndexes[row]; - FormatName(iResult, strName); - FormatProgress(iResult, strProgress); - FormatStatus(iResult, strStatus); + work = m_WorkCache.at(m_iSortedIndexes[row]); strMessage.Printf( _("Are you sure you want to abort this task '%s'?\n(Progress: %s, Status: %s)"), - strName.c_str(), - strProgress.c_str(), - strStatus.c_str() + (work->m_strName).c_str(), + (work->m_strProgress).c_str(), + (work->m_strStatus).c_str() ); iAnswer = wxGetApp().SafeMessageBox( @@ -467,32 +468,39 @@ wxInt32 CViewWork::GetDocCount() { wxString CViewWork::OnListGetItemText(long item, long column) const { - wxString strBuffer = wxEmptyString; + CWork* work = NULL; + wxString strBuffer = wxEmptyString; + + try { + work = m_WorkCache.at(m_iSortedIndexes[item]); + } catch ( std::out_of_range ) { + work = NULL; + } switch(column) { case COLUMN_PROJECT: - FormatProjectName(item, strBuffer); + strBuffer = work->m_strProjectName; break; case COLUMN_APPLICATION: - FormatApplicationName(item, strBuffer); + strBuffer = work->m_strApplicationName; break; case COLUMN_NAME: - FormatName(item, strBuffer); + strBuffer = work->m_strName; break; case COLUMN_CPUTIME: - FormatCPUTime(item, strBuffer); + strBuffer = work->m_strCPUTime; break; case COLUMN_PROGRESS: - FormatProgress(item, strBuffer); + strBuffer = work->m_strProgress; break; case COLUMN_TOCOMPLETION: - FormatTimeToCompletion(item, strBuffer); + strBuffer = work->m_strTimeToCompletion; break; case COLUMN_REPORTDEADLINE: - FormatReportDeadline(item, strBuffer); + strBuffer = work->m_strReportDeadline; break; case COLUMN_STATUS: - FormatStatus(item, strBuffer); + strBuffer = work->m_strStatus; break; } @@ -690,6 +698,7 @@ bool CViewWork::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex) { GetDocCPUTime(m_iSortedIndexes[iRowIndex], fDocumentFloat); if (fDocumentFloat != work->m_fCPUTime) { work->m_fCPUTime = fDocumentFloat; + FormatCPUTime(fDocumentFloat, work->m_strCPUTime); return true; } break; @@ -697,6 +706,7 @@ bool CViewWork::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex) { GetDocProgress(m_iSortedIndexes[iRowIndex], fDocumentFloat); if (fDocumentFloat != work->m_fProgress) { work->m_fProgress = fDocumentFloat; + FormatProgress(fDocumentFloat, work->m_strProgress); return true; } break; @@ -704,6 +714,7 @@ bool CViewWork::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex) { GetDocTimeToCompletion(m_iSortedIndexes[iRowIndex], fDocumentFloat); if (fDocumentFloat != work->m_fTimeToCompletion) { work->m_fTimeToCompletion = fDocumentFloat; + FormatTimeToCompletion(fDocumentFloat, work->m_strTimeToCompletion); return true; } break; @@ -711,6 +722,7 @@ bool CViewWork::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex) { GetDocReportDeadline(m_iSortedIndexes[iRowIndex], tDocumentTime); if (tDocumentTime != work->m_tReportDeadline) { work->m_tReportDeadline = tDocumentTime; + FormatReportDeadline(tDocumentTime, work->m_strReportDeadline); return true; } break; @@ -741,7 +753,7 @@ void CViewWork::GetDocProjectName(wxInt32 item, wxString& strBuffer) const { state_project = doc->state.lookup_project(result->project_url); if (state_project) { state_project->get_name(project_name); - strBuffer = wxString(project_name.c_str(), wxConvUTF8); + strBuffer = HtmlEntityDecode(wxString(project_name.c_str(), wxConvUTF8)); } else { doc->ForceCacheUpdate(); } @@ -749,14 +761,6 @@ void CViewWork::GetDocProjectName(wxInt32 item, wxString& strBuffer) const { } -wxInt32 CViewWork::FormatProjectName(wxInt32 item, wxString& strBuffer) const { - CWork* work = m_WorkCache.at(m_iSortedIndexes[item]); - strBuffer = HtmlEntityDecode(work->m_strProjectName); - - return 0; -} - - void CViewWork::GetDocApplicationName(wxInt32 item, wxString& strBuffer) const { CMainDocument* pDoc = wxGetApp().GetDocument(); RESULT* result = wxGetApp().GetDocument()->result(item); @@ -803,14 +807,6 @@ void CViewWork::GetDocApplicationName(wxInt32 item, wxString& strBuffer) const { } -wxInt32 CViewWork::FormatApplicationName(wxInt32 item, wxString& strBuffer) const { - CWork* work = m_WorkCache.at(m_iSortedIndexes[item]); - strBuffer = work->m_strApplicationName; - - return 0; -} - - void CViewWork::GetDocName(wxInt32 item, wxString& strBuffer) const { RESULT* result = wxGetApp().GetDocument()->result(item); @@ -822,14 +818,6 @@ void CViewWork::GetDocName(wxInt32 item, wxString& strBuffer) const { } -wxInt32 CViewWork::FormatName(wxInt32 item, wxString& strBuffer) const { - CWork* work = m_WorkCache.at(m_iSortedIndexes[item]); - strBuffer = wxString(work->m_strName.c_str(), wxConvUTF8); - - return 0; -} - - void CViewWork::GetDocCPUTime(wxInt32 item, float& fBuffer) const { RESULT* result = wxGetApp().GetDocument()->result(item); @@ -848,14 +836,11 @@ void CViewWork::GetDocCPUTime(wxInt32 item, float& fBuffer) const { } -wxInt32 CViewWork::FormatCPUTime(wxInt32 item, wxString& strBuffer) const { - CWork* work = m_WorkCache.at(m_iSortedIndexes[item]); - +wxInt32 CViewWork::FormatCPUTime(float fBuffer, wxString& strBuffer) const { wxInt32 iHour = 0; wxInt32 iMin = 0; wxInt32 iSec = 0; wxTimeSpan ts; - float fBuffer = work->m_fCPUTime; if (0 == fBuffer) { strBuffer = wxT("---"); @@ -891,9 +876,8 @@ void CViewWork::GetDocProgress(wxInt32 item, float& fBuffer) const { } -wxInt32 CViewWork::FormatProgress(wxInt32 item, wxString& strBuffer) const { - CWork* work = m_WorkCache.at(m_iSortedIndexes[item]); - strBuffer.Printf(wxT("%.3f%%"), work->m_fProgress); +wxInt32 CViewWork::FormatProgress(float fBuffer, wxString& strBuffer) const { + strBuffer.Printf(wxT("%.3f%%"), fBuffer); return 0; } @@ -909,9 +893,8 @@ void CViewWork::GetDocTimeToCompletion(wxInt32 item, float& fBuffer) const { } -wxInt32 CViewWork::FormatTimeToCompletion(wxInt32 item, wxString& strBuffer) const { - CWork* work = m_WorkCache.at(m_iSortedIndexes[item]); - double est = work->m_fTimeToCompletion; +wxInt32 CViewWork::FormatTimeToCompletion(float fBuffer, wxString& strBuffer) const { + double est = fBuffer; wxInt32 iHour = 0; wxInt32 iMin = 0; wxInt32 iSec = 0; @@ -947,11 +930,10 @@ void CViewWork::GetDocReportDeadline(wxInt32 item, time_t& time) const { } -wxInt32 CViewWork::FormatReportDeadline(wxInt32 item, wxString& strBuffer) const { - CWork* work = m_WorkCache.at(m_iSortedIndexes[item]); +wxInt32 CViewWork::FormatReportDeadline(time_t deadline, wxString& strBuffer) const { wxDateTime dtTemp; - dtTemp.Set(work->m_tReportDeadline); + dtTemp.Set(deadline); strBuffer = dtTemp.Format(); return 0; diff --git a/clientgui/ViewWork.h b/clientgui/ViewWork.h index 1249f5469e..c7f06be645 100644 --- a/clientgui/ViewWork.h +++ b/clientgui/ViewWork.h @@ -41,6 +41,10 @@ public: time_t m_tReportDeadline; wxString m_strStatus; wxString m_strProjectURL; // Used internally, not displayed + wxString m_strCPUTime; + wxString m_strProgress; + wxString m_strTimeToCompletion; + wxString m_strReportDeadline; }; @@ -84,19 +88,16 @@ protected: virtual void UpdateSelection(); void GetDocProjectName(wxInt32 item, wxString& strBuffer) const; - wxInt32 FormatProjectName( wxInt32 item, wxString& strBuffer ) const; void GetDocApplicationName(wxInt32 item, wxString& strBuffer) const; - wxInt32 FormatApplicationName( wxInt32 item, wxString& strBuffer ) const; void GetDocName(wxInt32 item, wxString& strBuffer) const; - wxInt32 FormatName( wxInt32 item, wxString& strBuffer ) const; void GetDocCPUTime(wxInt32 item, float& fBuffer) const; - wxInt32 FormatCPUTime( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatCPUTime( float fBuffer, wxString& strBuffer ) const; void GetDocProgress(wxInt32 item, float& fBuffer) const; - wxInt32 FormatProgress( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatProgress( float fBuffer, wxString& strBuffer ) const; void GetDocTimeToCompletion(wxInt32 item, float& fBuffer) const; - wxInt32 FormatTimeToCompletion( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatTimeToCompletion( float fBuffer, wxString& strBuffer ) const; void GetDocReportDeadline(wxInt32 item, time_t& time) const; - wxInt32 FormatReportDeadline( wxInt32 item, wxString& strBuffer ) const; + wxInt32 FormatReportDeadline( time_t deadline, wxString& strBuffer ) const; void GetDocStatus(wxInt32 item, wxString& strBuffer) const; wxInt32 FormatStatus( wxInt32 item, wxString& strBuffer ) const; void GetDocProjectURL(wxInt32 item, wxString& strBuffer) const;