From 79038a43916465318f254245fe5a761ae67749dd Mon Sep 17 00:00:00 2001 From: upstream svn Date: Sat, 15 Jan 2011 18:06:52 +0000 Subject: [PATCH] Improve speed of category tab title updates - Instead of looping through all downloads for each category, loop only once - Titles are updated every 5s anyway, so remove updates triggered from each (!) partfile - Update on application start and whenever files are moved to a different category --- .svn-revision | 2 +- src/DownloadListCtrl.cpp | 1 + src/DownloadQueue.cpp | 1 + src/PartFile.cpp | 3 --- src/TransferWnd.cpp | 60 ++++++++++++++++++++++++++---------------------- src/TransferWnd.h | 14 +++-------- 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/.svn-revision b/.svn-revision index 06ee293a..dff92322 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10433 +10434 diff --git a/src/DownloadListCtrl.cpp b/src/DownloadListCtrl.cpp index 463677b4..81457765 100644 --- a/src/DownloadListCtrl.cpp +++ b/src/DownloadListCtrl.cpp @@ -487,6 +487,7 @@ void CDownloadListCtrl::OnSetCategory( wxCommandEvent& event ) OnItemSelectionChanged(ev); // clear clients that may have been shown ChangeCategory( m_category ); // This only updates the visibility of the clear completed button + theApp->amuledlg->m_transferwnd->UpdateCatTabTitles(); } diff --git a/src/DownloadQueue.cpp b/src/DownloadQueue.cpp index 9c053d01..1f11226d 100644 --- a/src/DownloadQueue.cpp +++ b/src/DownloadQueue.cpp @@ -169,6 +169,7 @@ void CDownloadQueue::LoadMetFiles(const CPath& path) DoSortByPriority(); CheckDiskspace( path ); + Notify_ShowUpdateCatTabTitles(); } } diff --git a/src/PartFile.cpp b/src/PartFile.cpp index 9f44d3a6..92991fa5 100644 --- a/src/PartFile.cpp +++ b/src/PartFile.cpp @@ -1570,9 +1570,6 @@ uint32 CPartFile::Process(uint32 reducedownload/*in percent*/,uint8 m_icounter) UpdateCompletedInfos(); } m_bPercentUpdated = false; - if (thePrefs::ShowCatTabInfos()) { - Notify_ShowUpdateCatTabTitles(); - } } // release file handle if unused for some time diff --git a/src/TransferWnd.cpp b/src/TransferWnd.cpp index f540fa85..453bfdae 100644 --- a/src/TransferWnd.cpp +++ b/src/TransferWnd.cpp @@ -146,13 +146,14 @@ void CTransferWnd::AddCategory( Category_Struct* category ) theApp->amuledlg->m_searchwnd->UpdateCatChoice(); } -void CTransferWnd::UpdateCategory( int index, bool titleChanged ) +void CTransferWnd::UpdateCategory(int index) { - wxString label = theApp->glob_prefs->GetCategory( index )->title; - - if ( thePrefs::ShowCatTabInfos() ) { - uint16 files = 0; - uint16 download = 0; + uint32 nrCats = theApp->glob_prefs->GetCatCount(); + std::vector files, downloads; + bool showCatTabInfos = thePrefs::ShowCatTabInfos(); + if (showCatTabInfos) { + files.insert(files.begin(), nrCats, 0); + downloads.insert(downloads.begin(), nrCats, 0); #ifdef CLIENT_GUI for (CDownQueueRem::const_iterator it = theApp->downloadqueue->begin(); it != theApp->downloadqueue->end(); ++it) { @@ -164,25 +165,38 @@ void CTransferWnd::UpdateCategory( int index, bool titleChanged ) for (int i = 0; i < size; ++i ) { CPartFile *cur_file = fileList[i]; #endif - if ( cur_file && cur_file->CheckShowItemInGivenCat(index) ) { - files++; - - if ( cur_file->GetTransferingSrcCount() ) { - download++; + bool downloading = cur_file->GetTransferingSrcCount() > 0; + int fileCat = cur_file->GetCategory(); + if ((index == -1 || fileCat == index) && cur_file->CheckShowItemInGivenCat(fileCat)) { + files[fileCat]++; + if (downloading) { + downloads[fileCat]++; + } + } + if (index == -1 && fileCat > 0 && cur_file->CheckShowItemInGivenCat(0)) { + files[0]++; + if (downloading) { + downloads[0]++; } } } - label += CFormat(wxT(" (%u/%u)")) % download % files; } - - m_dlTab->SetPageText( index, label ); - - - if ( titleChanged ) { - theApp->amuledlg->m_searchwnd->UpdateCatChoice(); + int start, end; + if (index == -1) { + start = 0; + end = nrCats - 1; + } else { + start = index; + end = index; + } + for (int i = start; i <= end; i++) { + wxString label = theApp->glob_prefs->GetCategory(i)->title; + if (showCatTabInfos) { + label += CFormat(wxT(" (%u/%u)")) % downloads[i] % files[i]; + } + m_dlTab->SetPageText(i, label); } - } @@ -398,14 +412,6 @@ void CTransferWnd::OnBtnClearDownloads( wxCommandEvent& WXUNUSED(evt) ) } -void CTransferWnd::UpdateCatTabTitles() -{ - for ( uint8 i = 0; i < m_dlTab->GetPageCount(); i++ ) { - UpdateCategory( i, false ); - } -} - - void CTransferWnd::Prepare() { wxSplitterWindow* splitter = CastChild( wxT("splitterWnd"), wxSplitterWindow ); diff --git a/src/TransferWnd.h b/src/TransferWnd.h index 04a29758..5f4b609a 100644 --- a/src/TransferWnd.h +++ b/src/TransferWnd.h @@ -75,17 +75,9 @@ public: /** * Updates the title of the specified category. * - * @param index The index of the category on the notebook. - * @param titleChanged Set to true if the actual title has changed. - * - * The second paramerter will make the UpdateCategory function signal - * to the searchdlg page that the lists of categories has been changed, - * and force it to refresh its list of categories. - * - * This however should only be done when the title has actually changed, - * since it will cause the user-selection to be reset. + * @param index The index of the category on the notebook. -1 will update all categories. */ - void UpdateCategory( int index, bool titleChanged = false ); + void UpdateCategory(int index); /** * Remove category @@ -106,7 +98,7 @@ public: /** * Helper-function which updates the displayed titles of all existing categories. */ - void UpdateCatTabTitles(); + void UpdateCatTabTitles() { UpdateCategory(-1); } /** -- 2.11.4.GIT