From 7722916fada4ae984d1c134edcd74edd5262ea4f Mon Sep 17 00:00:00 2001 From: kevtechxx Date: Tue, 13 Apr 2021 16:22:48 +0200 Subject: [PATCH] Add "Notification timeout" option --- src/gui/advancedsettings.cpp | 15 +++++++++++++++ src/gui/advancedsettings.h | 4 ++++ src/gui/mainwindow.cpp | 17 ++++++++++++++++- src/gui/mainwindow.h | 4 ++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index c975a1b02..0d8f32a7e 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -78,6 +78,9 @@ namespace RESOLVE_COUNTRIES, PROGRAM_NOTIFICATIONS, TORRENT_ADDED_NOTIFICATIONS, +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) + NOTIFICATION_TIMEOUT, +#endif CONFIRM_REMOVE_ALL_TAGS, DOWNLOAD_TRACKER_FAVICON, SAVE_PATH_HISTORY_LENGTH, @@ -273,6 +276,9 @@ void AdvancedSettings::saveAdvancedSettings() MainWindow *const mainWindow = static_cast(QCoreApplication::instance())->mainWindow(); mainWindow->setNotificationsEnabled(m_checkBoxProgramNotifications.isChecked()); mainWindow->setTorrentAddedNotificationsEnabled(m_checkBoxTorrentAddedNotifications.isChecked()); +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) + mainWindow->setNotificationTimeout(m_spinBoxNotificationTimeout.value()); +#endif // Misc GUI properties mainWindow->setDownloadTrackerFavicon(m_checkBoxTrackerFavicon.isChecked()); AddNewTorrentDialog::setSavePathHistoryLength(m_spinBoxSavePathHistoryLength.value()); @@ -640,6 +646,15 @@ void AdvancedSettings::loadAdvancedSettings() // Torrent added notifications m_checkBoxTorrentAddedNotifications.setChecked(mainWindow->isTorrentAddedNotificationsEnabled()); addRow(TORRENT_ADDED_NOTIFICATIONS, tr("Display notifications for added torrents"), &m_checkBoxTorrentAddedNotifications); +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) + // Notification timeout + m_spinBoxNotificationTimeout.setMinimum(-1); + m_spinBoxNotificationTimeout.setMaximum(std::numeric_limits::max()); + m_spinBoxNotificationTimeout.setValue(mainWindow->getNotificationTimeout()); + m_spinBoxNotificationTimeout.setSpecialValueText(tr("System default")); + m_spinBoxNotificationTimeout.setSuffix(tr(" ms", " milliseconds")); + addRow(NOTIFICATION_TIMEOUT, tr("Notification timeout [0: infinite]"), &m_spinBoxNotificationTimeout); +#endif // Download tracker's favicon m_checkBoxTrackerFavicon.setChecked(mainWindow->isDownloadTrackerFavicon()); addRow(DOWNLOAD_TRACKER_FAVICON, tr("Download tracker's favicon"), &m_checkBoxTrackerFavicon); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 428b264df..8bf07c43e 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -88,4 +88,8 @@ private: #ifndef Q_OS_MACOS QCheckBox m_checkBoxIconsInMenusEnabled; #endif + +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) + QSpinBox m_spinBoxNotificationTimeout; +#endif }; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index b663dd34b..b0dc2d842 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -120,6 +120,9 @@ namespace #define NOTIFICATIONS_SETTINGS_KEY(name) QStringLiteral(SETTINGS_KEY("Notifications/") name) const QString KEY_NOTIFICATIONS_ENABLED = NOTIFICATIONS_SETTINGS_KEY("Enabled"); const QString KEY_NOTIFICATIONS_TORRENTADDED = NOTIFICATIONS_SETTINGS_KEY("TorrentAdded"); +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) + const QString KEY_NOTIFICATION_TIMEOUT = NOTIFICATIONS_SETTINGS_KEY("Timeout"); +#endif // Misc const QString KEY_DOWNLOAD_TRACKER_FAVICON = QStringLiteral(SETTINGS_KEY("DownloadTrackerFavicon")); @@ -528,6 +531,18 @@ void MainWindow::setTorrentAddedNotificationsEnabled(bool value) settings()->storeValue(KEY_NOTIFICATIONS_TORRENTADDED, value); } +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) +int MainWindow::getNotificationTimeout() const +{ + return settings()->loadValue(KEY_NOTIFICATION_TIMEOUT, -1); +} + +void MainWindow::setNotificationTimeout(const int value) +{ + settings()->storeValue(KEY_NOTIFICATION_TIMEOUT, value); +} +#endif + bool MainWindow::isDownloadTrackerFavicon() const { return settings()->loadValue(KEY_DOWNLOAD_TRACKER_FAVICON, false); @@ -1666,7 +1681,7 @@ void MainWindow::showNotificationBaloon(const QString &title, const QString &msg QVariantMap hints; hints["desktop-entry"] = "qBittorrent"; QDBusPendingReply reply = notifications.Notify("qBittorrent", 0, "qbittorrent", title, - msg, QStringList(), hints, -1); + msg, QStringList(), hints, getNotificationTimeout()); reply.waitForFinished(); if (!reply.isError()) return; diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 63a8096ba..8fa089adb 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -96,6 +96,10 @@ public: void setNotificationsEnabled(bool value); bool isTorrentAddedNotificationsEnabled() const; void setTorrentAddedNotificationsEnabled(bool value); +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) + int getNotificationTimeout() const; + void setNotificationTimeout(int value); +#endif // Misc properties bool isDownloadTrackerFavicon() const;