Browse Source

Display notifications when a torrent is added. Closes #334 and #915.

adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
ef6e848756
  1. 7
      src/app/application.cpp
  2. 4
      src/app/application.h
  3. 10
      src/base/preferences.cpp
  4. 2
      src/base/preferences.h
  5. 3
      src/base/settingsstorage.cpp
  6. 15
      src/gui/advancedsettings.cpp
  7. 2
      src/gui/advancedsettings.h
  8. 39
      src/gui/mainwindow.cpp
  9. 7
      src/gui/mainwindow.h
  10. 4
      src/gui/search/searchwidget.cpp

7
src/app/application.cpp

@ -130,6 +130,13 @@ Application::Application(const QString &id, int &argc, char **argv) @@ -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<MainWindow> Application::mainWindow()
{
return m_window;
}
#endif
bool Application::isFileLoggerEnabled() const
{
return settings()->loadValue(KEY_FILELOGGER_ENABLED, true).toBool();

4
src/app/application.h

@ -76,6 +76,10 @@ public: @@ -76,6 +76,10 @@ public:
int exec(const QStringList &params);
bool sendParams(const QStringList &params);
#ifndef DISABLE_GUI
QPointer<MainWindow> mainWindow();
#endif
// FileLogger properties
bool isFileLoggerEnabled() const;
void setFileLoggerEnabled(bool value);

10
src/base/preferences.cpp

@ -105,16 +105,6 @@ void Preferences::setLocale(const QString &locale) @@ -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();

2
src/base/preferences.h

@ -115,8 +115,6 @@ public: @@ -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;

3
src/base/settingsstorage.cpp

@ -81,8 +81,7 @@ namespace @@ -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" }
};

15
src/gui/advancedsettings.cpp

@ -31,7 +31,9 @@ @@ -31,7 +31,9 @@
#include <QHeaderView>
#include <QHostAddress>
#include <QNetworkInterface>
#include "app/application.h"
#include "base/preferences.h"
#include "gui/mainwindow.h"
enum AdvSettingsCols
{
@ -58,6 +60,7 @@ enum AdvSettingsRows @@ -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() @@ -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<Application*>(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() @@ -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<Application*>(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);

2
src/gui/advancedsettings.h

@ -60,7 +60,7 @@ private: @@ -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;

39
src/gui/mainwindow.cpp

@ -101,13 +101,18 @@ void qt_mac_set_dock_menu(QMenu *menu); @@ -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) @@ -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) @@ -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 @@ -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() @@ -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",

7
src/gui/mainwindow.h

@ -88,6 +88,12 @@ public: @@ -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: @@ -120,6 +126,7 @@ private slots:
void loadPreferences(bool configureSession = true);
void addUnauthenticatedTracker(const QPair<BitTorrent::TorrentHandle*, QString> &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();

4
src/gui/search/searchwidget.cpp

@ -320,7 +320,7 @@ void SearchWidget::searchStarted() @@ -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) @@ -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

Loading…
Cancel
Save