Browse Source

Add "Notification timeout" option

adaptive-webui-19844
kevtechxx 4 years ago
parent
commit
7722916fad
  1. 15
      src/gui/advancedsettings.cpp
  2. 4
      src/gui/advancedsettings.h
  3. 17
      src/gui/mainwindow.cpp
  4. 4
      src/gui/mainwindow.h

15
src/gui/advancedsettings.cpp

@ -78,6 +78,9 @@ namespace @@ -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() @@ -273,6 +276,9 @@ void AdvancedSettings::saveAdvancedSettings()
MainWindow *const mainWindow = static_cast<Application*>(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() @@ -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<int>::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);

4
src/gui/advancedsettings.h

@ -88,4 +88,8 @@ private: @@ -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
};

17
src/gui/mainwindow.cpp

@ -120,6 +120,9 @@ namespace @@ -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) @@ -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 @@ -1666,7 +1681,7 @@ void MainWindow::showNotificationBaloon(const QString &title, const QString &msg
QVariantMap hints;
hints["desktop-entry"] = "qBittorrent";
QDBusPendingReply<uint> reply = notifications.Notify("qBittorrent", 0, "qbittorrent", title,
msg, QStringList(), hints, -1);
msg, QStringList(), hints, getNotificationTimeout());
reply.waitForFinished();
if (!reply.isError())
return;

4
src/gui/mainwindow.h

@ -96,6 +96,10 @@ public: @@ -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;

Loading…
Cancel
Save