From fd5d1583de810f6fec780552b29f4e244d943b27 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 13 Nov 2016 22:46:17 +0200 Subject: [PATCH] Option to disable tracker's favicon download. --- src/gui/advancedsettings.cpp | 6 ++++++ src/gui/advancedsettings.h | 4 ++-- src/gui/mainwindow.cpp | 15 +++++++++++++++ src/gui/mainwindow.h | 4 ++++ src/gui/transferlistfilterswidget.cpp | 20 ++++++++++++++++++++ src/gui/transferlistfilterswidget.h | 3 +++ 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index e6a66257f..c6d850991 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -66,6 +66,7 @@ enum AdvSettingsRows RESOLVE_COUNTRIES, PROGRAM_NOTIFICATIONS, TORRENT_ADDED_NOTIFICATIONS, + DOWNLOAD_TRACKER_FAVICON, #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) USE_ICON_THEME, #endif @@ -171,6 +172,8 @@ void AdvancedSettings::saveAdvancedSettings() MainWindow * const mainWindow = static_cast(QCoreApplication::instance())->mainWindow(); mainWindow->setNotificationsEnabled(cb_program_notifications.isChecked()); mainWindow->setTorrentAddedNotificationsEnabled(cb_torrent_added_notifications.isChecked()); + // Misc GUI properties + mainWindow->setDownloadTrackerFavicon(cb_tracker_favicon.isChecked()); // Tracker session->setTrackerEnabled(cb_tracker_status.isChecked()); @@ -354,6 +357,9 @@ void AdvancedSettings::loadAdvancedSettings() // Torrent added notifications cb_torrent_added_notifications.setChecked(mainWindow->isTorrentAddedNotificationsEnabled()); addRow(TORRENT_ADDED_NOTIFICATIONS, tr("Display notifications for added torrents"), &cb_torrent_added_notifications); + // Download tracker's favicon + cb_tracker_favicon.setChecked(mainWindow->isDownloadTrackerFavicon()); + addRow(DOWNLOAD_TRACKER_FAVICON, tr("Download tracker's favicon"), &cb_tracker_favicon); // Tracker State cb_tracker_status.setChecked(session->isTrackerEnabled()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 68ac3c17c..74fc45fab 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -60,8 +60,8 @@ private: QLabel labelQbtLink, labelLibtorrentLink; QSpinBox spin_cache, spin_save_resume_data_interval, outgoing_ports_min, outgoing_ports_max, spin_list_refresh, spin_maxhalfopen, spin_tracker_port, spin_cache_ttl; - QCheckBox cb_os_cache, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, - cb_super_seeding, cb_program_notifications, cb_torrent_added_notifications, cb_tracker_status, + QCheckBox cb_os_cache, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, cb_super_seeding, + cb_program_notifications, cb_torrent_added_notifications, cb_tracker_favicon, cb_tracker_status, cb_confirm_torrent_recheck, cb_enable_tracker_ext, cb_listen_ipv6, cb_announce_all_trackers; QComboBox combo_iface, combo_iface_address; QLineEdit txtAnnounceIP; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 044261e9e..72623358a 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -114,6 +114,9 @@ namespace const QString KEY_NOTIFICATIONS_ENABLED = NOTIFICATIONS_SETTINGS_KEY("Enabled"); const QString KEY_NOTIFICATIONS_TORRENTADDED = NOTIFICATIONS_SETTINGS_KEY("TorrentAdded"); + // Misc + const QString KEY_DOWNLOAD_TRACKER_FAVICON = NOTIFICATIONS_SETTINGS_KEY("DownloadTrackerFavicon"); + //just a shortcut inline SettingsStorage *settings() { return SettingsStorage::instance(); } } @@ -220,6 +223,7 @@ MainWindow::MainWindow(QWidget *parent) //transferList->setStyleSheet("QTreeView {border: none;}"); // borderless m_propertiesWidget = new PropertiesWidget(hSplitter, this, m_transferListWidget); m_transferListFiltersWidget = new TransferListFiltersWidget(m_splitter, m_transferListWidget); + m_transferListFiltersWidget->setDownloadTrackerFavicon(isDownloadTrackerFavicon()); hSplitter->addWidget(m_transferListWidget); hSplitter->addWidget(m_propertiesWidget); m_splitter->addWidget(m_transferListFiltersWidget); @@ -444,6 +448,17 @@ void MainWindow::setTorrentAddedNotificationsEnabled(bool value) settings()->storeValue(KEY_NOTIFICATIONS_TORRENTADDED, value); } +bool MainWindow::isDownloadTrackerFavicon() const +{ + return settings()->loadValue(KEY_DOWNLOAD_TRACKER_FAVICON, true).toBool(); +} + +void MainWindow::setDownloadTrackerFavicon(bool value) +{ + m_transferListFiltersWidget->setDownloadTrackerFavicon(value); + settings()->storeValue(KEY_DOWNLOAD_TRACKER_FAVICON, value); +} + void MainWindow::addToolbarContextMenu() { const Preferences* const pref = Preferences::instance(); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 1a680e31e..1c529fd43 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -94,6 +94,10 @@ public: bool isTorrentAddedNotificationsEnabled() const; void setTorrentAddedNotificationsEnabled(bool value); + // Misc properties + bool isDownloadTrackerFavicon() const; + void setDownloadTrackerFavicon(bool value); + void activate(); void cleanup(); diff --git a/src/gui/transferlistfilterswidget.cpp b/src/gui/transferlistfilterswidget.cpp index 833a27c04..181c7080c 100644 --- a/src/gui/transferlistfilterswidget.cpp +++ b/src/gui/transferlistfilterswidget.cpp @@ -440,6 +440,7 @@ int CategoryFiltersList::rowFromCategory(const QString &category) const TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *transferList) : FiltersBase(parent, transferList) , m_totalTorrents(0) + , m_downloadTrackerFavicon(true) { QListWidgetItem *allTrackers = new QListWidgetItem(this); allTrackers->setData(Qt::DisplayRole, QVariant(tr("All (0)", "this is for the tracker filter"))); @@ -566,6 +567,19 @@ void TrackerFiltersList::changeTrackerless(bool trackerless, const QString &hash removeItem("", hash); } +void TrackerFiltersList::setDownloadTrackerFavicon(bool value) +{ + if (value == m_downloadTrackerFavicon) return; + m_downloadTrackerFavicon = value; + + if (m_downloadTrackerFavicon) { + foreach (const QString &tracker, m_trackers.keys()) { + if (!tracker.isEmpty()) + downloadFavicon(QString("http://%1/favicon.ico").arg(tracker)); + } + } +} + void TrackerFiltersList::trackerSuccess(const QString &hash, const QString &tracker) { QStringList errored = m_errors.value(hash); @@ -630,6 +644,7 @@ void TrackerFiltersList::trackerWarning(const QString &hash, const QString &trac void TrackerFiltersList::downloadFavicon(const QString& url) { + if (!m_downloadTrackerFavicon) return; Net::DownloadHandler *h = Net::DownloadManager::instance()->downloadUrl(url, true); connect(h, SIGNAL(downloadFinished(QString, QString)), this, SLOT(handleFavicoDownload(QString, QString))); connect(h, SIGNAL(downloadFailed(QString, QString)), this, SLOT(handleFavicoFailure(QString, QString))); @@ -835,6 +850,11 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi connect(this, SIGNAL(trackerWarning(const QString &, const QString &)), trackerFilters, SLOT(trackerWarning(const QString &, const QString &))); } +void TransferListFiltersWidget::setDownloadTrackerFavicon(bool value) +{ + trackerFilters->setDownloadTrackerFavicon(value); +} + void TransferListFiltersWidget::addTrackers(BitTorrent::TorrentHandle *const torrent, const QList &trackers) { foreach (const BitTorrent::TrackerEntry &tracker, trackers) diff --git a/src/gui/transferlistfilterswidget.h b/src/gui/transferlistfilterswidget.h index 3a78c9ff7..3ea54260a 100644 --- a/src/gui/transferlistfilterswidget.h +++ b/src/gui/transferlistfilterswidget.h @@ -136,6 +136,7 @@ public: void addItem(const QString &tracker, const QString &hash); void removeItem(const QString &tracker, const QString &hash); void changeTrackerless(bool trackerless, const QString &hash); + void setDownloadTrackerFavicon(bool value); public slots: void trackerSuccess(const QString &hash, const QString &tracker); @@ -165,6 +166,7 @@ private: QHash m_warnings; QStringList m_iconPaths; int m_totalTorrents; + bool m_downloadTrackerFavicon; }; class TransferListFiltersWidget: public QFrame @@ -173,6 +175,7 @@ class TransferListFiltersWidget: public QFrame public: TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList); + void setDownloadTrackerFavicon(bool value); public slots: void addTrackers(BitTorrent::TorrentHandle *const torrent, const QList &trackers);