mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
- Refresh torrent properties and transfer list only when they are visible in order to save CPU :)
This commit is contained in:
parent
d6e1dc9020
commit
70c62f6294
22
src/GUI.cpp
22
src/GUI.cpp
@ -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
|
||||
|
||||
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 {
|
||||
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) {
|
||||
}
|
||||
|
||||
int GUI::getCurrentTabIndex() const{
|
||||
if(isMinimized() || isHidden())
|
||||
if(isMinimized() || !isVisible())
|
||||
return -1;
|
||||
return tabs->currentIndex();
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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{
|
||||
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;
|
||||
|
@ -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 @@
|
||||
#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() {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -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 {
|
||||
|
||||
private:
|
||||
TransferListWidget *transferList;
|
||||
GUI *main_window;
|
||||
QTorrentHandle h;
|
||||
QTimer *refreshTimer;
|
||||
RealProgressBar *progressBar;
|
||||
@ -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:
|
||||
void filteredFilesChanged();
|
||||
|
||||
public slots:
|
||||
void loadDynamicData();
|
||||
void reduce();
|
||||
void slide();
|
||||
void clear();
|
||||
@ -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;
|
||||
|
@ -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 @@
|
||||
#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) {
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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:
|
||||
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…
Reference in New Issue
Block a user