diff --git a/src/app/application.cpp b/src/app/application.cpp index b8a1a1975..aeee2c7cd 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -130,6 +130,13 @@ Application::Application(const QString &id, int &argc, char **argv) Logger::instance()->addMessage(tr("qBittorrent %1 started", "qBittorrent v3.2.0alpha started").arg(VERSION)); } +#ifndef DISABLE_GUI +QPointer Application::mainWindow() +{ + return m_window; +} +#endif + bool Application::isFileLoggerEnabled() const { return settings()->loadValue(KEY_FILELOGGER_ENABLED, true).toBool(); diff --git a/src/app/application.h b/src/app/application.h index 8c9c098ec..bfc630272 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -76,6 +76,10 @@ public: int exec(const QStringList ¶ms); bool sendParams(const QStringList ¶ms); +#ifndef DISABLE_GUI + QPointer mainWindow(); +#endif + // FileLogger properties bool isFileLoggerEnabled() const; void setFileLoggerEnabled(bool value); diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 2fbda9c15..654d6043c 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -105,16 +105,6 @@ void Preferences::setLocale(const QString &locale) setValue("Preferences/General/Locale", locale); } -bool Preferences::useProgramNotification() const -{ - return value("Preferences/General/ProgramNotification", true).toBool(); -} - -void Preferences::useProgramNotification(bool use) -{ - setValue("Preferences/General/ProgramNotification", use); -} - bool Preferences::deleteTorrentFilesAsDefault() const { return value("Preferences/General/DeleteTorrentsFilesAsDefault", false).toBool(); diff --git a/src/base/preferences.h b/src/base/preferences.h index f9eaec5ff..584765432 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -115,8 +115,6 @@ public: // General options QString getLocale() const; void setLocale(const QString &locale); - bool useProgramNotification() const; - void useProgramNotification(bool use); bool deleteTorrentFilesAsDefault() const; void setDeleteTorrentFilesAsDefault(bool del); bool confirmOnExit() const; diff --git a/src/base/settingsstorage.cpp b/src/base/settingsstorage.cpp index cbd34452f..eadf9e3b2 100644 --- a/src/base/settingsstorage.cpp +++ b/src/base/settingsstorage.cpp @@ -81,8 +81,7 @@ namespace { "AddNewTorrentDialog/Expanded", "AddNewTorrentDialog/expanded" }, { "AddNewTorrentDialog/SavePathHistory", "TorrentAdditionDlg/save_path_history" }, { "AddNewTorrentDialog/Enabled", "Preferences/Downloads/NewAdditionDialog" }, - { "AddNewTorrentDialog/TopLevel", "Preferences/Downloads/NewAdditionDialogFront" }, - { "ExecutionLog/Enabled", "Preferences/ExecutionLog/enabled" } + { "AddNewTorrentDialog/TopLevel", "Preferences/Downloads/NewAdditionDialogFront" } }; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 14075b892..0f62e3e34 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -31,7 +31,9 @@ #include #include #include +#include "app/application.h" #include "base/preferences.h" +#include "gui/mainwindow.h" enum AdvSettingsCols { @@ -58,6 +60,7 @@ enum AdvSettingsRows RESOLVE_HOSTS, RESOLVE_COUNTRIES, PROGRAM_NOTIFICATIONS, + TORRENT_ADDED_NOTIFICATIONS, #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) USE_ICON_THEME, #endif @@ -150,7 +153,9 @@ void AdvancedSettings::saveAdvancedSettings() else pref->setNetworkAddress(addr.toString()); // Program notification - pref->useProgramNotification(cb_program_notifications.isChecked()); + MainWindow * const mainWindow = static_cast(QCoreApplication::instance())->mainWindow(); + mainWindow->setNotificationsEnabled(cb_program_notifications.isChecked()); + mainWindow->setTorrentAddedNotificationsEnabled(cb_torrent_added_notifications.isChecked()); // Tracker pref->setTrackerEnabled(cb_tracker_status.isChecked()); pref->setTrackerPort(spin_tracker_port.value()); @@ -284,8 +289,12 @@ void AdvancedSettings::loadAdvancedSettings() txt_network_address.setText(pref->getNetworkAddress()); addRow(NETWORK_ADDRESS, tr("IP Address to report to trackers (requires restart)"), &txt_network_address); // Program notifications - cb_program_notifications.setChecked(pref->useProgramNotification()); - addRow(PROGRAM_NOTIFICATIONS, tr("Display program on-screen notifications"), &cb_program_notifications); + const MainWindow * const mainWindow = static_cast(QCoreApplication::instance())->mainWindow(); + cb_program_notifications.setChecked(mainWindow->isNotificationsEnabled()); + addRow(PROGRAM_NOTIFICATIONS, tr("Display notifications"), &cb_program_notifications); + // Torrent added notifications + cb_torrent_added_notifications.setChecked(mainWindow->isTorrentAddedNotificationsEnabled()); + addRow(TORRENT_ADDED_NOTIFICATIONS, tr("Display notifications for added torrents"), &cb_torrent_added_notifications); // Tracker State cb_tracker_status.setChecked(pref->isTrackerEnabled()); addRow(TRACKER_STATUS, tr("Enable embedded tracker"), &cb_tracker_status); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index b0d13f8c7..30fecd1d4 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -60,7 +60,7 @@ 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_tracker_status, + cb_super_seeding, cb_program_notifications, cb_torrent_added_notifications, cb_tracker_status, cb_confirm_torrent_recheck, cb_enable_tracker_ext, cb_listen_ipv6, cb_announce_all_trackers; QComboBox combo_iface; QLineEdit txt_network_address; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 563ac1732..306ed7402 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -101,13 +101,18 @@ void qt_mac_set_dock_menu(QMenu *menu); namespace { -#define SETTINGS_KEY(name) "MainWindow/" name +#define SETTINGS_KEY(name) "GUI/" name // ExecutionLog properties keys -#define EXECUTIONLOG_SETTINGS_KEY(name) SETTINGS_KEY("ExecutionLog/") name +#define EXECUTIONLOG_SETTINGS_KEY(name) SETTINGS_KEY("Log/") name const QString KEY_EXECUTIONLOG_ENABLED = EXECUTIONLOG_SETTINGS_KEY("Enabled"); const QString KEY_EXECUTIONLOG_TYPES = EXECUTIONLOG_SETTINGS_KEY("Types"); + // Notifications properties keys +#define NOTIFICATIONS_SETTINGS_KEY(name) SETTINGS_KEY("Notifications/") name + const QString KEY_NOTIFICATIONS_ENABLED = NOTIFICATIONS_SETTINGS_KEY("Enabled"); + const QString KEY_NOTIFICATIONS_TORRENTADDED = NOTIFICATIONS_SETTINGS_KEY("TorrentAdded"); + //just a shortcut inline SettingsStorage *settings() { return SettingsStorage::instance(); } } @@ -181,6 +186,7 @@ MainWindow::MainWindow(QWidget *parent) // Creating Bittorrent session connect(BitTorrent::Session::instance(), SIGNAL(fullDiskError(BitTorrent::TorrentHandle *const, QString)), this, SLOT(fullDiskError(BitTorrent::TorrentHandle *const, QString))); connect(BitTorrent::Session::instance(), SIGNAL(addTorrentFailed(const QString &)), this, SLOT(addTorrentFailed(const QString &))); + connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle *const)), this, SLOT(torrentAdded(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), this, SLOT(finishedTorrent(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(trackerAuthenticationRequired(BitTorrent::TorrentHandle *const)), this, SLOT(trackerAuthenticationRequired(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(downloadFromUrlFailed(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString))); @@ -421,6 +427,26 @@ void MainWindow::setExecutionLogMsgTypes(const int value) settings()->storeValue(KEY_EXECUTIONLOG_TYPES, value); } +bool MainWindow::isNotificationsEnabled() const +{ + return settings()->loadValue(KEY_NOTIFICATIONS_ENABLED, true).toBool(); +} + +void MainWindow::setNotificationsEnabled(bool value) +{ + settings()->storeValue(KEY_NOTIFICATIONS_ENABLED, value); +} + +bool MainWindow::isTorrentAddedNotificationsEnabled() const +{ + return settings()->loadValue(KEY_NOTIFICATIONS_TORRENTADDED, false).toBool(); +} + +void MainWindow::setTorrentAddedNotificationsEnabled(bool value) +{ + settings()->storeValue(KEY_NOTIFICATIONS_TORRENTADDED, value); +} + void MainWindow::addToolbarContextMenu() { const Preferences* const pref = Preferences::instance(); @@ -696,6 +722,13 @@ void MainWindow::addTorrentFailed(const QString &error) const showNotificationBaloon(tr("Error"), tr("Failed to add torrent: %1").arg(error)); } +// called when a torrent was added +void MainWindow::torrentAdded(BitTorrent::TorrentHandle *const torrent) const +{ + if (isTorrentAddedNotificationsEnabled()) + showNotificationBaloon(tr("Torrent added"), tr("'%1' was added.", "e.g: xxx.avi was added.").arg(torrent->name())); +} + // called when a torrent has finished void MainWindow::finishedTorrent(BitTorrent::TorrentHandle *const torrent) const { @@ -1279,7 +1312,7 @@ void MainWindow::updateGUI() void MainWindow::showNotificationBaloon(QString title, QString msg) const { - if (!Preferences::instance()->useProgramNotification()) return; + if (!isNotificationsEnabled()) return; #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) org::freedesktop::Notifications notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 0d81b821f..8d67b235a 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -88,6 +88,12 @@ public: int executionLogMsgTypes() const; void setExecutionLogMsgTypes(const int value); + // Notifications properties + bool isNotificationsEnabled() const; + void setNotificationsEnabled(bool value); + bool isTorrentAddedNotificationsEnabled() const; + void setTorrentAddedNotificationsEnabled(bool value); + void activate(); void cleanup(); @@ -120,6 +126,7 @@ private slots: void loadPreferences(bool configureSession = true); void addUnauthenticatedTracker(const QPair &tracker); void addTorrentFailed(const QString &error) const; + void torrentAdded(BitTorrent::TorrentHandle *const torrent) const; void finishedTorrent(BitTorrent::TorrentHandle *const torrent) const; void askRecursiveTorrentDownloadConfirmation(BitTorrent::TorrentHandle *const torrent); void optionsSaved(); diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 5e3130bc6..a8aa3c47e 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -320,7 +320,7 @@ void SearchWidget::searchStarted() // Error | Stopped by user | Finished normally void SearchWidget::searchFinished(bool cancelled) { - if (Preferences::instance()->useProgramNotification() && (m_mainWindow->currentTabWidget() != this)) + if (m_mainWindow->isNotificationsEnabled() && (m_mainWindow->currentTabWidget() != this)) m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished")); if (m_activeSearchTab.isNull()) return; // The active tab was closed @@ -338,7 +338,7 @@ void SearchWidget::searchFinished(bool cancelled) void SearchWidget::searchFailed() { - if (Preferences::instance()->useProgramNotification() && (m_mainWindow->currentTabWidget() != this)) + if (m_mainWindow->isNotificationsEnabled() && (m_mainWindow->currentTabWidget() != this)) m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has failed")); if (m_activeSearchTab.isNull()) return; // The active tab was closed