mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-13 00:33:09 -07:00
parent
31d04cffd9
commit
ef6e848756
10 changed files with 70 additions and 23 deletions
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue