From d9cb73634d4f8eff35847d550f135f59ad3c2ab7 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 15 Nov 2009 13:10:31 +0000 Subject: [PATCH] - Performance improvement, property tabs are updated only when displayed --- src/propertieswidget.cpp | 77 ++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index b06d3cdd5..2845fe6fa 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -86,6 +86,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, TransferListWidget *transfer connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle&)), this, SLOT(loadTorrentInfos(QTorrentHandle &))); connect(incrementalDownload, SIGNAL(stateChanged(int)), this, SLOT(setIncrementalDownload(int))); connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged())); + connect(stackedProperties, SIGNAL(currentChanged(int)), this, SLOT(loadDynamicData())); // Downloaded pieces progress bar progressBar = new RealProgressBar(this); @@ -274,42 +275,50 @@ void PropertiesWidget::loadDynamicData() { if(!h.is_valid()) return; try { // Transfer infos - wasted->setText(misc::friendlyUnit(h.total_failed_bytes()+h.total_redundant_bytes())); - upTotal->setText(misc::friendlyUnit(h.all_time_upload()) + " ("+misc::friendlyUnit(h.total_payload_upload())+" "+tr("this session")+")"); - dlTotal->setText(misc::friendlyUnit(h.all_time_download()) + " ("+misc::friendlyUnit(h.total_payload_download())+" "+tr("this session")+")"); - lbl_uplimit->setText(misc::friendlyUnit(h.upload_limit())); - lbl_dllimit->setText(misc::friendlyUnit(h.download_limit())); - QString elapsed_txt = misc::userFriendlyDuration(h.active_time()); - if(h.is_seed()) { - elapsed_txt += " ("+tr("Seeding for %1", "e.g. Seeding for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")"; - } - lbl_elapsed->setText(elapsed_txt); - lbl_connections->setText(QString::number(h.num_connections())+" ("+tr("%1 max", "e.g. 10 max").arg(QString::number(h.connections_limit()))+")"); - // Load peers - peersList->loadPeers(h); - // Update ratio info - float ratio; - if(h.total_payload_download() == 0){ - if(h.total_payload_upload() == 0) - ratio = 1.; - else - ratio = 10.; // Max ratio - }else{ - ratio = (double)h.total_payload_upload()/(double)h.total_payload_download(); - if(ratio > 10.){ - ratio = 10.; + if(stackedProperties->currentIndex() == MAIN_TAB) { + wasted->setText(misc::friendlyUnit(h.total_failed_bytes()+h.total_redundant_bytes())); + upTotal->setText(misc::friendlyUnit(h.all_time_upload()) + " ("+misc::friendlyUnit(h.total_payload_upload())+" "+tr("this session")+")"); + dlTotal->setText(misc::friendlyUnit(h.all_time_download()) + " ("+misc::friendlyUnit(h.total_payload_download())+" "+tr("this session")+")"); + lbl_uplimit->setText(misc::friendlyUnit(h.upload_limit())); + lbl_dllimit->setText(misc::friendlyUnit(h.download_limit())); + QString elapsed_txt = misc::userFriendlyDuration(h.active_time()); + if(h.is_seed()) { + elapsed_txt += " ("+tr("Seeding for %1", "e.g. Seeding for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")"; + } + lbl_elapsed->setText(elapsed_txt); + lbl_connections->setText(QString::number(h.num_connections())+" ("+tr("%1 max", "e.g. 10 max").arg(QString::number(h.connections_limit()))+")"); + // Update ratio info + float ratio; + if(h.total_payload_download() == 0){ + if(h.total_payload_upload() == 0) + ratio = 1.; + else + ratio = 10.; // Max ratio + }else{ + ratio = (double)h.total_payload_upload()/(double)h.total_payload_download(); + if(ratio > 10.){ + ratio = 10.; + } } + shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1))); + // Downloaded pieces + if(progressBarUpdater) + progressBarUpdater->refresh(); + // Progress + progress_lbl->setText(QString::number(h.progress()*100., 'f', 1)+"%"); + return; + } + if(stackedProperties->currentIndex() == PEERS_TAB) { + // Load peers + peersList->loadPeers(h); + return; + } + if(stackedProperties->currentIndex() == FILES_TAB) { + // Files progress + std::vector fp; + h.file_progress(fp); + PropListModel->updateFilesProgress(fp); } - shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1))); - // Downloaded pieces - if(progressBarUpdater) - progressBarUpdater->refresh(); - // Progress - progress_lbl->setText(QString::number(h.progress()*100., 'f', 1)+"%"); - // Files progress - std::vector fp; - h.file_progress(fp); - PropListModel->updateFilesProgress(fp); } catch(invalid_handle e) {} }