Browse Source

- Refresh torrent properties and transfer list only when they are visible in order to save CPU :)

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
70c62f6294
  1. 22
      src/GUI.cpp
  2. 3
      src/GUI.h
  3. 9
      src/propertieswidget.cpp
  4. 6
      src/propertieswidget.h
  5. 10
      src/transferlistwidget.cpp
  6. 4
      src/transferlistwidget.h

22
src/GUI.cpp

@ -60,7 +60,6 @@ @@ -60,7 +60,6 @@
#include "statusbar.h"
using namespace libtorrent;
enum TabIndex{TAB_TRANSFER, TAB_SEARCH, TAB_RSS};
/*****************************************************
* *
@ -110,14 +109,15 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis @@ -110,14 +109,15 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
qDebug("create tabWidget");
tabs = new QTabWidget();
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int)));
vSplitter = new QSplitter(Qt::Horizontal);
vSplitter->setChildrenCollapsible(false);
hSplitter = new QSplitter(Qt::Vertical);
hSplitter->setChildrenCollapsible(false);
// Transfer List tab
transferList = new TransferListWidget(hSplitter, BTSession);
properties = new PropertiesWidget(hSplitter, transferList, BTSession);
transferList = new TransferListWidget(hSplitter, this, BTSession);
properties = new PropertiesWidget(hSplitter, this, transferList, BTSession);
transferListFilters = new TransferListFiltersWidget(vSplitter, transferList);
hSplitter->addWidget(transferList);
hSplitter->addWidget(properties);
@ -246,6 +246,14 @@ void GUI::on_actionBugReport_triggered() const { @@ -246,6 +246,14 @@ void GUI::on_actionBugReport_triggered() const {
QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://bugs.qbittorrent.org")));
}
void GUI::tab_changed(int new_tab) {
if(new_tab == TAB_TRANSFER) {
qDebug("Changed tab to transfer list, refreshing the list");
transferList->refreshList();
properties->loadDynamicData();
}
}
void GUI::writeSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.beginGroup(QString::fromUtf8("MainWindow"));
@ -410,7 +418,7 @@ void GUI::previewFile(QString filePath) { @@ -410,7 +418,7 @@ void GUI::previewFile(QString filePath) {
}
int GUI::getCurrentTabIndex() const{
if(isMinimized() || isHidden())
if(isMinimized() || !isVisible())
return -1;
return tabs->currentIndex();
}
@ -463,7 +471,11 @@ void GUI::on_actionAbout_triggered() { @@ -463,7 +471,11 @@ void GUI::on_actionAbout_triggered() {
void GUI::showEvent(QShowEvent *e) {
qDebug("** Show Event **");
//updateLists(true);
if(getCurrentTabIndex() == TAB_TRANSFER) {
qDebug("-> Refreshing transfer list");
transferList->refreshList();
properties->loadDynamicData();
}
e->accept();
}

3
src/GUI.h

@ -37,6 +37,8 @@ @@ -37,6 +37,8 @@
#include "ui_mainwindow.h"
#include "qtorrenthandle.h"
enum TabIndex{TAB_TRANSFER, TAB_SEARCH, TAB_RSS};
class Bittorrent;
class QTimer;
class downloadFromURL;
@ -112,6 +114,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -112,6 +114,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void fullDiskError(QTorrentHandle& h, QString msg) const;
void handleDownloadFromUrlFailure(QString, QString) const;
void createSystrayDelayed();
void tab_changed(int);
// Keyboard shortcuts
void createKeyboardShortcuts();
void displayTransferTab() const;

9
src/propertieswidget.cpp

@ -48,6 +48,7 @@ @@ -48,6 +48,7 @@
#include "torrentfilesmodel.h"
#include "peerlistwidget.h"
#include "trackerlist.h"
#include "GUI.h"
#ifdef Q_WS_MAC
#define DEFAULT_BUTTON_CSS ""
@ -57,7 +58,8 @@ @@ -57,7 +58,8 @@
#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 3px; margin-right: 3px;}"
#endif
PropertiesWidget::PropertiesWidget(QWidget *parent, TransferListWidget *transferList, Bittorrent* BTSession): QWidget(parent), transferList(transferList), BTSession(BTSession) {
PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, Bittorrent* BTSession):
QWidget(parent), transferList(transferList), main_window(main_window), BTSession(BTSession) {
setupUi(this);
state = VISIBLE;
@ -283,8 +285,9 @@ void PropertiesWidget::reloadPreferences() { @@ -283,8 +285,9 @@ void PropertiesWidget::reloadPreferences() {
}
void PropertiesWidget::loadDynamicData() {
if(!h.is_valid()) return;
if(state != VISIBLE) return;
// Refresh only if the torrent handle is valid and if visible
if(!h.is_valid() || main_window->getCurrentTabIndex() != TAB_TRANSFER || state != VISIBLE) return;
qDebug("Refreshing torrent properties");
try {
// Transfer infos
if(stackedProperties->currentIndex() == MAIN_TAB) {

6
src/propertieswidget.h

@ -47,6 +47,7 @@ class QAction; @@ -47,6 +47,7 @@ class QAction;
class torrent_file;
class PeerListWidget;
class TrackerList;
class GUI;
enum Tab {MAIN_TAB, TRACKERS_TAB, PEERS_TAB, URLSEEDS_TAB, FILES_TAB};
enum SlideState {REDUCED, VISIBLE};
@ -56,6 +57,7 @@ class PropertiesWidget : public QWidget, private Ui::PropertiesWidget { @@ -56,6 +57,7 @@ class PropertiesWidget : public QWidget, private Ui::PropertiesWidget {
private:
TransferListWidget *transferList;
GUI *main_window;
QTorrentHandle h;
QTimer *refreshTimer;
RealProgressBar *progressBar;
@ -78,7 +80,6 @@ protected: @@ -78,7 +80,6 @@ protected:
protected slots:
void loadTorrentInfos(QTorrentHandle &h);
void loadDynamicData();
void loadUrlSeeds();
void on_main_infos_button_clicked();
void on_trackers_button_clicked();
@ -96,6 +97,7 @@ protected slots: @@ -96,6 +97,7 @@ protected slots:
void filteredFilesChanged();
public slots:
void loadDynamicData();
void reduce();
void slide();
void clear();
@ -104,7 +106,7 @@ public slots: @@ -104,7 +106,7 @@ public slots:
void reloadPreferences();
public:
PropertiesWidget(QWidget *parent, TransferListWidget *transferList, Bittorrent* BTSession);
PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, Bittorrent* BTSession);
~PropertiesWidget();
const QTorrentHandle& getCurrentTorrent() const;
Bittorrent* getBTSession() const;

10
src/transferlistwidget.cpp

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
#include "previewselect.h"
#include "speedlimitdlg.h"
#include "options_imp.h"
#include "GUI.h"
#include "deletionconfirmationdlg.h"
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
@ -48,10 +49,10 @@ @@ -48,10 +49,10 @@
#include <QRegExp>
#include <vector>
TransferListWidget::TransferListWidget(QWidget *parent, Bittorrent *_BTSession): QTreeView(parent) {
QSettings settings("qBittorrent", "qBittorrent");
BTSession = _BTSession;
TransferListWidget::TransferListWidget(QWidget *parent, GUI *main_window, Bittorrent *_BTSession):
QTreeView(parent), BTSession(_BTSession), main_window(main_window) {
QSettings settings("qBittorrent", "qBittorrent");
// Create and apply delegate
listDelegate = new TransferListDelegate(this);
setItemDelegate(listDelegate);
@ -386,6 +387,9 @@ void TransferListWidget::setRefreshInterval(int t) { @@ -386,6 +387,9 @@ void TransferListWidget::setRefreshInterval(int t) {
}
void TransferListWidget::refreshList() {
// Refresh only if displayed
if(main_window->getCurrentTabIndex() != TAB_TRANSFER) return;
qDebug("Refreshing transfer list");
unsigned int nb_downloading = 0, nb_seeding=0, nb_active=0, nb_inactive = 0;
for(int i=0; i<listModel->rowCount(); ++i) {
int s = updateTorrent(i);

4
src/transferlistwidget.h

@ -39,6 +39,7 @@ class QSortFilterProxyModel; @@ -39,6 +39,7 @@ class QSortFilterProxyModel;
class Bittorrent;
class QTimer;
class TransferListDelegate;
class GUI;
enum TorrentFilter {FILTER_ALL, FILTER_DOWNLOADING, FILTER_COMPLETED, FILTER_ACTIVE, FILTER_INACTIVE};
@ -51,9 +52,10 @@ private: @@ -51,9 +52,10 @@ private:
QSortFilterProxyModel *proxyModel;
Bittorrent* BTSession;
QTimer *refreshTimer;
GUI *main_window;
public:
TransferListWidget(QWidget *parent, Bittorrent* BTSession);
TransferListWidget(QWidget *parent, GUI *main_window, Bittorrent* BTSession);
~TransferListWidget();
protected:

Loading…
Cancel
Save