Add ability to pause/resume entire BitTorrent session

PR #20757.
Closes #18993.
This commit is contained in:
Vladimir Golovnev 2024-05-03 09:02:50 +03:00 committed by GitHub
parent 05416458db
commit 8ef7d3ec9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 189 additions and 114 deletions

View file

@ -430,9 +430,15 @@ namespace BitTorrent
virtual void setResumeDataStorageType(ResumeDataStorageType type) = 0; virtual void setResumeDataStorageType(ResumeDataStorageType type) = 0;
virtual bool isMergeTrackersEnabled() const = 0; virtual bool isMergeTrackersEnabled() const = 0;
virtual void setMergeTrackersEnabled(bool enabled) = 0; virtual void setMergeTrackersEnabled(bool enabled) = 0;
virtual bool isStartPaused() const = 0;
virtual void setStartPaused(bool value) = 0;
virtual bool isRestored() const = 0; virtual bool isRestored() const = 0;
virtual bool isPaused() const = 0;
virtual void pause() = 0;
virtual void resume() = 0;
virtual Torrent *getTorrent(const TorrentID &id) const = 0; virtual Torrent *getTorrent(const TorrentID &id) const = 0;
virtual Torrent *findTorrent(const InfoHash &infoHash) const = 0; virtual Torrent *findTorrent(const InfoHash &infoHash) const = 0;
virtual QVector<Torrent *> torrents() const = 0; virtual QVector<Torrent *> torrents() const = 0;
@ -466,6 +472,8 @@ namespace BitTorrent
void loadTorrentFailed(const QString &error); void loadTorrentFailed(const QString &error);
void metadataDownloaded(const TorrentInfo &info); void metadataDownloaded(const TorrentInfo &info);
void restored(); void restored();
void paused();
void resumed();
void speedLimitModeChanged(bool alternative); void speedLimitModeChanged(bool alternative);
void statsUpdated(); void statsUpdated();
void subcategoriesSupportChanged(); void subcategoriesSupportChanged();

View file

@ -523,6 +523,7 @@ SessionImpl::SessionImpl(QObject *parent)
, m_I2POutboundQuantity {BITTORRENT_SESSION_KEY(u"I2P/OutboundQuantity"_s), 3} , m_I2POutboundQuantity {BITTORRENT_SESSION_KEY(u"I2P/OutboundQuantity"_s), 3}
, m_I2PInboundLength {BITTORRENT_SESSION_KEY(u"I2P/InboundLength"_s), 3} , m_I2PInboundLength {BITTORRENT_SESSION_KEY(u"I2P/InboundLength"_s), 3}
, m_I2POutboundLength {BITTORRENT_SESSION_KEY(u"I2P/OutboundLength"_s), 3} , m_I2POutboundLength {BITTORRENT_SESSION_KEY(u"I2P/OutboundLength"_s), 3}
, m_startPaused {BITTORRENT_SESSION_KEY(u"StartPaused"_s)}
, m_seedingLimitTimer {new QTimer(this)} , m_seedingLimitTimer {new QTimer(this)}
, m_resumeDataTimer {new QTimer(this)} , m_resumeDataTimer {new QTimer(this)}
, m_ioThread {new QThread} , m_ioThread {new QThread}
@ -1541,7 +1542,9 @@ void SessionImpl::endStartup(ResumeSessionContext *context)
context->deleteLater(); context->deleteLater();
connect(context, &QObject::destroyed, this, [this] connect(context, &QObject::destroyed, this, [this]
{ {
if (!m_isPaused)
m_nativeSession->resume(); m_nativeSession->resume();
if (m_refreshEnqueued) if (m_refreshEnqueued)
m_refreshEnqueued = false; m_refreshEnqueued = false;
else else
@ -3913,6 +3916,16 @@ void SessionImpl::setMergeTrackersEnabled(const bool enabled)
m_isMergeTrackersEnabled = enabled; m_isMergeTrackersEnabled = enabled;
} }
bool SessionImpl::isStartPaused() const
{
return m_startPaused.get(false);
}
void SessionImpl::setStartPaused(const bool value)
{
m_startPaused = value;
}
QStringList SessionImpl::bannedIPs() const QStringList SessionImpl::bannedIPs() const
{ {
return m_bannedIPs; return m_bannedIPs;
@ -3923,6 +3936,35 @@ bool SessionImpl::isRestored() const
return m_isRestored; return m_isRestored;
} }
bool SessionImpl::isPaused() const
{
return m_isPaused;
}
void SessionImpl::pause()
{
if (!m_isPaused)
{
if (isRestored())
m_nativeSession->pause();
m_isPaused = true;
emit paused();
}
}
void SessionImpl::resume()
{
if (m_isPaused)
{
if (isRestored())
m_nativeSession->resume();
m_isPaused = false;
emit resumed();
}
}
int SessionImpl::maxConnectionsPerTorrent() const int SessionImpl::maxConnectionsPerTorrent() const
{ {
return m_maxConnectionsPerTorrent; return m_maxConnectionsPerTorrent;
@ -4370,6 +4412,9 @@ void SessionImpl::setQueueingSystemEnabled(const bool enabled)
m_torrentsQueueChanged = true; m_torrentsQueueChanged = true;
else else
removeTorrentsQueue(); removeTorrentsQueue();
for (TorrentImpl *torrent : asConst(m_torrents))
torrent->handleQueueingModeChanged();
} }
} }

View file

@ -407,9 +407,15 @@ namespace BitTorrent
void setResumeDataStorageType(ResumeDataStorageType type) override; void setResumeDataStorageType(ResumeDataStorageType type) override;
bool isMergeTrackersEnabled() const override; bool isMergeTrackersEnabled() const override;
void setMergeTrackersEnabled(bool enabled) override; void setMergeTrackersEnabled(bool enabled) override;
bool isStartPaused() const override;
void setStartPaused(bool value) override;
bool isRestored() const override; bool isRestored() const override;
bool isPaused() const override;
void pause() override;
void resume() override;
Torrent *getTorrent(const TorrentID &id) const override; Torrent *getTorrent(const TorrentID &id) const override;
Torrent *findTorrent(const InfoHash &infoHash) const override; Torrent *findTorrent(const InfoHash &infoHash) const override;
QVector<Torrent *> torrents() const override; QVector<Torrent *> torrents() const override;
@ -722,8 +728,10 @@ namespace BitTorrent
CachedSettingValue<int> m_I2POutboundQuantity; CachedSettingValue<int> m_I2POutboundQuantity;
CachedSettingValue<int> m_I2PInboundLength; CachedSettingValue<int> m_I2PInboundLength;
CachedSettingValue<int> m_I2POutboundLength; CachedSettingValue<int> m_I2POutboundLength;
SettingValue<bool> m_startPaused;
bool m_isRestored = false; bool m_isRestored = false;
bool m_isPaused = isStartPaused();
// Order is important. This needs to be declared after its CachedSettingsValue // Order is important. This needs to be declared after its CachedSettingsValue
// counterpart, because it uses it for initialization in the constructor // counterpart, because it uses it for initialization in the constructor

View file

@ -999,6 +999,9 @@ bool TorrentImpl::isStopped() const
bool TorrentImpl::isQueued() const bool TorrentImpl::isQueued() const
{ {
if (!m_session->isQueueingSystemEnabled())
return false;
// Torrent is Queued if it isn't in Stopped state but paused internally // Torrent is Queued if it isn't in Stopped state but paused internally
return (!isStopped() return (!isStopped()
&& (m_nativeStatus.flags & lt::torrent_flags::auto_managed) && (m_nativeStatus.flags & lt::torrent_flags::auto_managed)
@ -1153,7 +1156,7 @@ void TorrentImpl::updateState()
{ {
if (isStopped()) if (isStopped())
m_state = TorrentState::StoppedDownloading; m_state = TorrentState::StoppedDownloading;
else if (m_session->isQueueingSystemEnabled() && isQueued()) else if (isQueued())
m_state = TorrentState::QueuedDownloading; m_state = TorrentState::QueuedDownloading;
else else
m_state = isForced() ? TorrentState::ForcedDownloadingMetadata : TorrentState::DownloadingMetadata; m_state = isForced() ? TorrentState::ForcedDownloadingMetadata : TorrentState::DownloadingMetadata;
@ -1167,7 +1170,7 @@ void TorrentImpl::updateState()
{ {
if (isStopped()) if (isStopped())
m_state = TorrentState::StoppedUploading; m_state = TorrentState::StoppedUploading;
else if (m_session->isQueueingSystemEnabled() && isQueued()) else if (isQueued())
m_state = TorrentState::QueuedUploading; m_state = TorrentState::QueuedUploading;
else if (isForced()) else if (isForced())
m_state = TorrentState::ForcedUploading; m_state = TorrentState::ForcedUploading;
@ -1180,7 +1183,7 @@ void TorrentImpl::updateState()
{ {
if (isStopped()) if (isStopped())
m_state = TorrentState::StoppedDownloading; m_state = TorrentState::StoppedDownloading;
else if (m_session->isQueueingSystemEnabled() && isQueued()) else if (isQueued())
m_state = TorrentState::QueuedDownloading; m_state = TorrentState::QueuedDownloading;
else if (isForced()) else if (isForced())
m_state = TorrentState::ForcedDownloading; m_state = TorrentState::ForcedDownloading;
@ -1963,6 +1966,11 @@ void TorrentImpl::handleStateUpdate(const lt::torrent_status &nativeStatus)
updateStatus(nativeStatus); updateStatus(nativeStatus);
} }
void TorrentImpl::handleQueueingModeChanged()
{
updateState();
}
void TorrentImpl::handleMoveStorageJobFinished(const Path &path, const MoveStorageContext context, const bool hasOutstandingJob) void TorrentImpl::handleMoveStorageJobFinished(const Path &path, const MoveStorageContext context, const bool hasOutstandingJob)
{ {
if (context == MoveStorageContext::ChangeSavePath) if (context == MoveStorageContext::ChangeSavePath)

View file

@ -269,6 +269,7 @@ namespace BitTorrent
void handleAlert(const lt::alert *a); void handleAlert(const lt::alert *a);
void handleStateUpdate(const lt::torrent_status &nativeStatus); void handleStateUpdate(const lt::torrent_status &nativeStatus);
void handleQueueingModeChanged();
void handleCategoryOptionsChanged(); void handleCategoryOptionsChanged();
void handleAppendExtensionToggled(); void handleAppendExtensionToggled();
void handleUnwantedFolderToggled(); void handleUnwantedFolderToggled();

View file

@ -1397,19 +1397,6 @@ void Preferences::setConfirmRemoveAllTags(const bool enabled)
setValue(u"Preferences/Advanced/confirmRemoveAllTags"_s, enabled); setValue(u"Preferences/Advanced/confirmRemoveAllTags"_s, enabled);
} }
bool Preferences::confirmPauseAndResumeAll() const
{
return value(u"GUI/ConfirmActions/PauseAndResumeAllTorrents"_s, true);
}
void Preferences::setConfirmPauseAndResumeAll(const bool enabled)
{
if (enabled == confirmPauseAndResumeAll())
return;
setValue(u"GUI/ConfirmActions/PauseAndResumeAllTorrents"_s, enabled);
}
bool Preferences::confirmMergeTrackers() const bool Preferences::confirmMergeTrackers() const
{ {
return value(u"GUI/ConfirmActions/MergeTrackers"_s, true); return value(u"GUI/ConfirmActions/MergeTrackers"_s, true);

View file

@ -305,8 +305,6 @@ public:
void setConfirmTorrentRecheck(bool enabled); void setConfirmTorrentRecheck(bool enabled);
bool confirmRemoveAllTags() const; bool confirmRemoveAllTags() const;
void setConfirmRemoveAllTags(bool enabled); void setConfirmRemoveAllTags(bool enabled);
bool confirmPauseAndResumeAll() const;
void setConfirmPauseAndResumeAll(bool enabled);
bool confirmMergeTrackers() const; bool confirmMergeTrackers() const;
void setConfirmMergeTrackers(bool enabled); void setConfirmMergeTrackers(bool enabled);
bool confirmRemoveTrackerFromAllTorrents() const; bool confirmRemoveTrackerFromAllTorrents() const;

View file

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 qBittorrent project * Copyright (C) 2016-2024 qBittorrent project
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -105,6 +105,7 @@ namespace
ENABLE_MARK_OF_THE_WEB, ENABLE_MARK_OF_THE_WEB,
#endif // Q_OS_MACOS || Q_OS_WIN #endif // Q_OS_MACOS || Q_OS_WIN
PYTHON_EXECUTABLE_PATH, PYTHON_EXECUTABLE_PATH,
START_SESSION_PAUSED,
// libtorrent section // libtorrent section
LIBTORRENT_HEADER, LIBTORRENT_HEADER,
@ -331,6 +332,8 @@ void AdvancedSettings::saveAdvancedSettings() const
#endif // Q_OS_MACOS || Q_OS_WIN #endif // Q_OS_MACOS || Q_OS_WIN
// Python executable path // Python executable path
pref->setPythonExecutablePath(Path(m_pythonExecutablePath.text().trimmed())); pref->setPythonExecutablePath(Path(m_pythonExecutablePath.text().trimmed()));
// Start session paused
session->setStartPaused(m_checkBoxStartSessionPaused.isChecked());
// Choking algorithm // Choking algorithm
session->setChokingAlgorithm(m_comboBoxChokingAlgorithm.currentData().value<BitTorrent::ChokingAlgorithm>()); session->setChokingAlgorithm(m_comboBoxChokingAlgorithm.currentData().value<BitTorrent::ChokingAlgorithm>());
// Seed choking algorithm // Seed choking algorithm
@ -843,6 +846,9 @@ void AdvancedSettings::loadAdvancedSettings()
m_pythonExecutablePath.setPlaceholderText(tr("(Auto detect if empty)")); m_pythonExecutablePath.setPlaceholderText(tr("(Auto detect if empty)"));
m_pythonExecutablePath.setText(pref->getPythonExecutablePath().toString()); m_pythonExecutablePath.setText(pref->getPythonExecutablePath().toString());
addRow(PYTHON_EXECUTABLE_PATH, tr("Python executable path (may require restart)"), &m_pythonExecutablePath); addRow(PYTHON_EXECUTABLE_PATH, tr("Python executable path (may require restart)"), &m_pythonExecutablePath);
// Start session paused
m_checkBoxStartSessionPaused.setChecked(session->isStartPaused());
addRow(START_SESSION_PAUSED, tr("Start session in paused state"), &m_checkBoxStartSessionPaused);
// Choking algorithm // Choking algorithm
m_comboBoxChokingAlgorithm.addItem(tr("Fixed slots"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::FixedSlots)); m_comboBoxChokingAlgorithm.addItem(tr("Fixed slots"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::FixedSlots));
m_comboBoxChokingAlgorithm.addItem(tr("Upload rate based"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::RateBased)); m_comboBoxChokingAlgorithm.addItem(tr("Upload rate based"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::RateBased));

View file

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 qBittorrent project * Copyright (C) 2015-2024 qBittorrent project
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -79,7 +79,7 @@ private:
m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus, m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus,
m_checkBoxTrackerPortForwarding, m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers, m_checkBoxTrackerPortForwarding, m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers,
m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxSSRFMitigation, m_checkBoxBlockPeersOnPrivilegedPorts, m_checkBoxPieceExtentAffinity, m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxSSRFMitigation, m_checkBoxBlockPeersOnPrivilegedPorts, m_checkBoxPieceExtentAffinity,
m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport, m_checkBoxConfirmRemoveTrackerFromAllTorrents; m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport, m_checkBoxConfirmRemoveTrackerFromAllTorrents, m_checkBoxStartSessionPaused;
QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxDiskIOReadMode, m_comboBoxDiskIOWriteMode, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm, QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxDiskIOReadMode, m_comboBoxDiskIOWriteMode, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm,
m_comboBoxSeedChokingAlgorithm, m_comboBoxResumeDataStorage; m_comboBoxSeedChokingAlgorithm, m_comboBoxResumeDataStorage;
QLineEdit m_lineEditAppInstanceName, m_pythonExecutablePath, m_lineEditAnnounceIP, m_lineEditDHTBootstrapNodes; QLineEdit m_lineEditAppInstanceName, m_pythonExecutablePath, m_lineEditAnnounceIP, m_lineEditDHTBootstrapNodes;

View file

@ -125,18 +125,18 @@ namespace
MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, const QString &titleSuffix) MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, const QString &titleSuffix)
: GUIApplicationComponent(app) : GUIApplicationComponent(app)
, m_ui(new Ui::MainWindow) , m_ui {new Ui::MainWindow}
, m_storeExecutionLogEnabled(EXECUTIONLOG_SETTINGS_KEY(u"Enabled"_s)) , m_downloadRate {Utils::Misc::friendlyUnit(0, true)}
, m_storeDownloadTrackerFavicon(SETTINGS_KEY(u"DownloadTrackerFavicon"_s)) , m_uploadRate {Utils::Misc::friendlyUnit(0, true)}
, m_storeExecutionLogTypes(EXECUTIONLOG_SETTINGS_KEY(u"Types"_s), Log::MsgType::ALL) , m_storeExecutionLogEnabled {EXECUTIONLOG_SETTINGS_KEY(u"Enabled"_s)}
, m_storeDownloadTrackerFavicon {SETTINGS_KEY(u"DownloadTrackerFavicon"_s)}
, m_storeExecutionLogTypes {EXECUTIONLOG_SETTINGS_KEY(u"Types"_s), Log::MsgType::ALL}
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
, m_badger(std::make_unique<MacUtils::Badger>()) , m_badger {std::make_unique<MacUtils::Badger>()}
#endif // Q_OS_MACOS #endif // Q_OS_MACOS
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
setTitleSuffix(titleSuffix);
Preferences *const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
m_uiLocked = pref->isUILocked(); m_uiLocked = pref->isUILocked();
m_displaySpeedInTitle = pref->speedInTitleBar(); m_displaySpeedInTitle = pref->speedInTitleBar();
@ -145,6 +145,8 @@ MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, con
setWindowIcon(UIThemeManager::instance()->getIcon(u"qbittorrent"_s)); setWindowIcon(UIThemeManager::instance()->getIcon(u"qbittorrent"_s));
#endif // Q_OS_MACOS #endif // Q_OS_MACOS
setTitleSuffix(titleSuffix);
#if (defined(Q_OS_UNIX)) #if (defined(Q_OS_UNIX))
m_ui->actionOptions->setText(tr("Preferences")); m_ui->actionOptions->setText(tr("Preferences"));
#endif #endif
@ -167,21 +169,37 @@ MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, con
m_ui->actionExit->setIcon(UIThemeManager::instance()->getIcon(u"application-exit"_s)); m_ui->actionExit->setIcon(UIThemeManager::instance()->getIcon(u"application-exit"_s));
m_ui->actionLock->setIcon(UIThemeManager::instance()->getIcon(u"object-locked"_s)); m_ui->actionLock->setIcon(UIThemeManager::instance()->getIcon(u"object-locked"_s));
m_ui->actionOptions->setIcon(UIThemeManager::instance()->getIcon(u"configure"_s, u"preferences-system"_s)); m_ui->actionOptions->setIcon(UIThemeManager::instance()->getIcon(u"configure"_s, u"preferences-system"_s));
m_ui->actionStop->setIcon(UIThemeManager::instance()->getIcon(u"torrent-stop"_s, u"media-playback-pause"_s));
m_ui->actionStopAll->setIcon(UIThemeManager::instance()->getIcon(u"torrent-stop"_s, u"media-playback-pause"_s));
m_ui->actionStart->setIcon(UIThemeManager::instance()->getIcon(u"torrent-start"_s, u"media-playback-start"_s)); m_ui->actionStart->setIcon(UIThemeManager::instance()->getIcon(u"torrent-start"_s, u"media-playback-start"_s));
m_ui->actionStartAll->setIcon(UIThemeManager::instance()->getIcon(u"torrent-start"_s, u"media-playback-start"_s)); m_ui->actionStop->setIcon(UIThemeManager::instance()->getIcon(u"torrent-stop"_s, u"media-playback-pause"_s));
m_ui->actionPauseSession->setIcon(UIThemeManager::instance()->getIcon(u"pause-session"_s, u"media-playback-pause"_s));
m_ui->actionResumeSession->setIcon(UIThemeManager::instance()->getIcon(u"torrent-start"_s, u"media-playback-start"_s));
m_ui->menuAutoShutdownOnDownloadsCompletion->setIcon(UIThemeManager::instance()->getIcon(u"task-complete"_s, u"application-exit"_s)); m_ui->menuAutoShutdownOnDownloadsCompletion->setIcon(UIThemeManager::instance()->getIcon(u"task-complete"_s, u"application-exit"_s));
m_ui->actionManageCookies->setIcon(UIThemeManager::instance()->getIcon(u"browser-cookies"_s, u"preferences-web-browser-cookies"_s)); m_ui->actionManageCookies->setIcon(UIThemeManager::instance()->getIcon(u"browser-cookies"_s, u"preferences-web-browser-cookies"_s));
m_ui->menuLog->setIcon(UIThemeManager::instance()->getIcon(u"help-contents"_s)); m_ui->menuLog->setIcon(UIThemeManager::instance()->getIcon(u"help-contents"_s));
m_ui->actionCheckForUpdates->setIcon(UIThemeManager::instance()->getIcon(u"view-refresh"_s)); m_ui->actionCheckForUpdates->setIcon(UIThemeManager::instance()->getIcon(u"view-refresh"_s));
m_ui->actionPauseSession->setVisible(!BitTorrent::Session::instance()->isPaused());
m_ui->actionResumeSession->setVisible(BitTorrent::Session::instance()->isPaused());
connect(BitTorrent::Session::instance(), &BitTorrent::Session::paused, this, [this]
{
m_ui->actionPauseSession->setVisible(false);
m_ui->actionResumeSession->setVisible(true);
refreshWindowTitle();
refreshTrayIconTooltip();
});
connect(BitTorrent::Session::instance(), &BitTorrent::Session::resumed, this, [this]
{
m_ui->actionPauseSession->setVisible(true);
m_ui->actionResumeSession->setVisible(false);
refreshWindowTitle();
refreshTrayIconTooltip();
});
auto *lockMenu = new QMenu(m_ui->menuView); auto *lockMenu = new QMenu(m_ui->menuView);
lockMenu->addAction(tr("&Set Password"), this, &MainWindow::defineUILockPassword); lockMenu->addAction(tr("&Set Password"), this, &MainWindow::defineUILockPassword);
lockMenu->addAction(tr("&Clear Password"), this, &MainWindow::clearUILockPassword); lockMenu->addAction(tr("&Clear Password"), this, &MainWindow::clearUILockPassword);
m_ui->actionLock->setMenu(lockMenu); m_ui->actionLock->setMenu(lockMenu);
// Creating Bittorrent session
updateAltSpeedsBtn(BitTorrent::Session::instance()->isAltGlobalSpeedLimitEnabled()); updateAltSpeedsBtn(BitTorrent::Session::instance()->isAltGlobalSpeedLimitEnabled());
connect(BitTorrent::Session::instance(), &BitTorrent::Session::speedLimitModeChanged, this, &MainWindow::updateAltSpeedsBtn); connect(BitTorrent::Session::instance(), &BitTorrent::Session::speedLimitModeChanged, this, &MainWindow::updateAltSpeedsBtn);
@ -285,9 +303,9 @@ MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, con
// Transfer list slots // Transfer list slots
connect(m_ui->actionStart, &QAction::triggered, m_transferListWidget, &TransferListWidget::startSelectedTorrents); connect(m_ui->actionStart, &QAction::triggered, m_transferListWidget, &TransferListWidget::startSelectedTorrents);
connect(m_ui->actionStartAll, &QAction::triggered, m_transferListWidget, &TransferListWidget::startAllTorrents);
connect(m_ui->actionStop, &QAction::triggered, m_transferListWidget, &TransferListWidget::stopSelectedTorrents); connect(m_ui->actionStop, &QAction::triggered, m_transferListWidget, &TransferListWidget::stopSelectedTorrents);
connect(m_ui->actionStopAll, &QAction::triggered, m_transferListWidget, &TransferListWidget::stopAllTorrents); connect(m_ui->actionPauseSession, &QAction::triggered, m_transferListWidget, &TransferListWidget::pauseSession);
connect(m_ui->actionResumeSession, &QAction::triggered, m_transferListWidget, &TransferListWidget::resumeSession);
connect(m_ui->actionDelete, &QAction::triggered, m_transferListWidget, &TransferListWidget::softDeleteSelectedTorrents); connect(m_ui->actionDelete, &QAction::triggered, m_transferListWidget, &TransferListWidget::softDeleteSelectedTorrents);
connect(m_ui->actionTopQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::topQueuePosSelectedTorrents); connect(m_ui->actionTopQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::topQueuePosSelectedTorrents);
connect(m_ui->actionIncreaseQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::increaseQueuePosSelectedTorrents); connect(m_ui->actionIncreaseQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::increaseQueuePosSelectedTorrents);
@ -326,7 +344,7 @@ MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, con
// Configure BT session according to options // Configure BT session according to options
loadPreferences(); loadPreferences();
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated, this, &MainWindow::reloadSessionStats); connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated, this, &MainWindow::loadSessionStats);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated, this, &MainWindow::reloadTorrentStats); connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated, this, &MainWindow::reloadTorrentStats);
// Accept drag 'n drops // Accept drag 'n drops
@ -530,7 +548,7 @@ void MainWindow::setTitleSuffix(const QString &suffix)
m_windowTitle = QStringLiteral("qBittorrent " QBT_VERSION) m_windowTitle = QStringLiteral("qBittorrent " QBT_VERSION)
+ (!suffix.isEmpty() ? (separator + suffix) : QString()); + (!suffix.isEmpty() ? (separator + suffix) : QString());
setWindowTitle(m_windowTitle); refreshWindowTitle();
} }
void MainWindow::addToolbarContextMenu() void MainWindow::addToolbarContextMenu()
@ -881,9 +899,9 @@ void MainWindow::createKeyboardShortcuts()
m_ui->actionOptions->setShortcut(Qt::ALT | Qt::Key_O); m_ui->actionOptions->setShortcut(Qt::ALT | Qt::Key_O);
m_ui->actionStatistics->setShortcut(Qt::CTRL | Qt::Key_I); m_ui->actionStatistics->setShortcut(Qt::CTRL | Qt::Key_I);
m_ui->actionStart->setShortcut(Qt::CTRL | Qt::Key_S); m_ui->actionStart->setShortcut(Qt::CTRL | Qt::Key_S);
m_ui->actionStartAll->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_S);
m_ui->actionStop->setShortcut(Qt::CTRL | Qt::Key_P); m_ui->actionStop->setShortcut(Qt::CTRL | Qt::Key_P);
m_ui->actionStopAll->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_P); m_ui->actionPauseSession->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_P);
m_ui->actionResumeSession->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_S);
m_ui->actionBottomQueuePos->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Minus); m_ui->actionBottomQueuePos->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Minus);
m_ui->actionDecreaseQueuePos->setShortcut(Qt::CTRL | Qt::Key_Minus); m_ui->actionDecreaseQueuePos->setShortcut(Qt::CTRL | Qt::Key_Minus);
m_ui->actionIncreaseQueuePos->setShortcut(Qt::CTRL | Qt::Key_Plus); m_ui->actionIncreaseQueuePos->setShortcut(Qt::CTRL | Qt::Key_Plus);
@ -1488,28 +1506,21 @@ void MainWindow::loadPreferences()
qDebug("GUI settings loaded"); qDebug("GUI settings loaded");
} }
void MainWindow::reloadSessionStats() void MainWindow::loadSessionStats()
{ {
const BitTorrent::SessionStatus &status = BitTorrent::Session::instance()->status(); const auto *btSession = BitTorrent::Session::instance();
const QString downloadRate = Utils::Misc::friendlyUnit(status.payloadDownloadRate, true); const BitTorrent::SessionStatus &status = btSession->status();
const QString uploadRate = Utils::Misc::friendlyUnit(status.payloadUploadRate, true); const QString m_downloadRate = Utils::Misc::friendlyUnit(status.payloadDownloadRate, true);
const QString m_uploadRate = Utils::Misc::friendlyUnit(status.payloadUploadRate, true);
// update global information // update global information
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
m_badger->updateSpeed(status.payloadDownloadRate, status.payloadUploadRate); m_badger->updateSpeed(status.payloadDownloadRate, status.payloadUploadRate);
#else #else
const auto toolTip = u"%1\n%2"_s.arg( refreshTrayIconTooltip();
tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(downloadRate)
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(uploadRate));
app()->desktopIntegration()->setToolTip(toolTip); // tray icon
#endif // Q_OS_MACOS #endif // Q_OS_MACOS
if (m_displaySpeedInTitle) refreshWindowTitle();
{
const QString title = tr("[D: %1, U: %2] %3", "D = Download; U = Upload; %3 is the rest of the window title")
.arg(downloadRate, uploadRate, m_windowTitle);
setWindowTitle(title);
}
} }
void MainWindow::reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents) void MainWindow::reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents)
@ -1551,8 +1562,8 @@ void MainWindow::populateDesktopIntegrationMenu()
menu->addAction(m_ui->actionSetGlobalSpeedLimits); menu->addAction(m_ui->actionSetGlobalSpeedLimits);
menu->addSeparator(); menu->addSeparator();
menu->addAction(m_ui->actionStartAll); menu->addAction(m_ui->actionResumeSession);
menu->addAction(m_ui->actionStopAll); menu->addAction(m_ui->actionPauseSession);
#ifndef Q_OS_MACOS #ifndef Q_OS_MACOS
menu->addSeparator(); menu->addSeparator();
@ -1613,10 +1624,7 @@ void MainWindow::on_actionSpeedInTitleBar_triggered()
{ {
m_displaySpeedInTitle = static_cast<QAction *>(sender())->isChecked(); m_displaySpeedInTitle = static_cast<QAction *>(sender())->isChecked();
Preferences::instance()->showSpeedInTitleBar(m_displaySpeedInTitle); Preferences::instance()->showSpeedInTitleBar(m_displaySpeedInTitle);
if (m_displaySpeedInTitle) refreshWindowTitle();
reloadSessionStats();
else
setWindowTitle(m_windowTitle);
} }
void MainWindow::on_actionRSSReader_triggered() void MainWindow::on_actionRSSReader_triggered()
@ -1881,6 +1889,45 @@ void MainWindow::applyTransferListFilter()
m_transferListWidget->applyFilter(m_columnFilterEdit->text(), m_columnFilterComboBox->currentData().value<TransferListModel::Column>()); m_transferListWidget->applyFilter(m_columnFilterEdit->text(), m_columnFilterComboBox->currentData().value<TransferListModel::Column>());
} }
void MainWindow::refreshWindowTitle()
{
const auto *btSession = BitTorrent::Session::instance();
if (btSession->isPaused())
{
const QString title = tr("[PAUSED] %1", "%1 is the rest of the window title").arg(m_windowTitle);
setWindowTitle(title);
}
else
{
if (m_displaySpeedInTitle)
{
const QString title = tr("[D: %1, U: %2] %3", "D = Download; U = Upload; %3 is the rest of the window title")
.arg(m_downloadRate, m_uploadRate, m_windowTitle);
setWindowTitle(title);
}
else
{
setWindowTitle(m_windowTitle);
}
}
}
void MainWindow::refreshTrayIconTooltip()
{
const auto *btSession = BitTorrent::Session::instance();
if (!btSession->isPaused())
{
const auto toolTip = u"%1\n%2"_s.arg(
tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(m_downloadRate)
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(m_uploadRate));
app()->desktopIntegration()->setToolTip(toolTip);
}
else
{
app()->desktopIntegration()->setToolTip(tr("Paused"));
}
}
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
void MainWindow::checkProgramUpdate(const bool invokedByUser) void MainWindow::checkProgramUpdate(const bool invokedByUser)
{ {

View file

@ -127,7 +127,7 @@ private slots:
void displayRSSTab(); void displayRSSTab();
void displayExecutionLogTab(); void displayExecutionLogTab();
void toggleFocusBetweenLineEdits(); void toggleFocusBetweenLineEdits();
void reloadSessionStats(); void loadSessionStats();
void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents); void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents);
void loadPreferences(); void loadPreferences();
void optionsSaved(); void optionsSaved();
@ -203,14 +203,19 @@ private:
void showStatusBar(bool show); void showStatusBar(bool show);
void showFiltersSidebar(bool show); void showFiltersSidebar(bool show);
void applyTransferListFilter(); void applyTransferListFilter();
void refreshWindowTitle();
void refreshTrayIconTooltip();
Ui::MainWindow *m_ui = nullptr; Ui::MainWindow *m_ui = nullptr;
QFileSystemWatcher *m_executableWatcher = nullptr;
// GUI related
QString m_windowTitle; QString m_windowTitle;
QString m_downloadRate;
QString m_uploadRate;
bool m_posInitialized = false; bool m_posInitialized = false;
bool m_neverShown = true; bool m_neverShown = true;
QFileSystemWatcher *m_executableWatcher = nullptr;
// GUI related
QPointer<QTabWidget> m_tabs; QPointer<QTabWidget> m_tabs;
QPointer<StatusBar> m_statusBar; QPointer<StatusBar> m_statusBar;
QPointer<OptionsDialog> m_options; QPointer<OptionsDialog> m_options;

View file

@ -44,14 +44,15 @@
</property> </property>
<addaction name="actionStart"/> <addaction name="actionStart"/>
<addaction name="actionStop"/> <addaction name="actionStop"/>
<addaction name="actionStartAll"/>
<addaction name="actionStopAll"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionDelete"/> <addaction name="actionDelete"/>
<addaction name="actionTopQueuePos"/> <addaction name="actionTopQueuePos"/>
<addaction name="actionIncreaseQueuePos"/> <addaction name="actionIncreaseQueuePos"/>
<addaction name="actionDecreaseQueuePos"/> <addaction name="actionDecreaseQueuePos"/>
<addaction name="actionBottomQueuePos"/> <addaction name="actionBottomQueuePos"/>
<addaction name="separator"/>
<addaction name="actionPauseSession"/>
<addaction name="actionResumeSession"/>
</widget> </widget>
<widget class="QMenu" name="menuHelp"> <widget class="QMenu" name="menuHelp">
<property name="title"> <property name="title">
@ -196,14 +197,14 @@
<string>Sto&amp;p</string> <string>Sto&amp;p</string>
</property> </property>
</action> </action>
<action name="actionStartAll"> <action name="actionResumeSession">
<property name="text"> <property name="text">
<string>Star&amp;t All</string> <string>&amp;Resume Session</string>
</property> </property>
</action> </action>
<action name="actionStopAll"> <action name="actionPauseSession">
<property name="text"> <property name="text">
<string>&amp;Stop All</string> <string>Pau&amp;se Session</string>
</property> </property>
</action> </action>
<action name="actionDelete"> <action name="actionDelete">

View file

@ -281,7 +281,6 @@ void OptionsDialog::loadBehaviorTabOptions()
m_ui->checkShowSplash->setChecked(!pref->isSplashScreenDisabled()); m_ui->checkShowSplash->setChecked(!pref->isSplashScreenDisabled());
m_ui->checkProgramExitConfirm->setChecked(pref->confirmOnExit()); m_ui->checkProgramExitConfirm->setChecked(pref->confirmOnExit());
m_ui->checkProgramAutoExitConfirm->setChecked(!pref->dontConfirmAutoExit()); m_ui->checkProgramAutoExitConfirm->setChecked(!pref->dontConfirmAutoExit());
m_ui->checkConfirmStopAndStartAll->setChecked(pref->confirmPauseAndResumeAll());
m_ui->windowStateComboBox->addItem(tr("Normal"), QVariant::fromValue(WindowState::Normal)); m_ui->windowStateComboBox->addItem(tr("Normal"), QVariant::fromValue(WindowState::Normal));
m_ui->windowStateComboBox->addItem(tr("Minimized"), QVariant::fromValue(WindowState::Minimized)); m_ui->windowStateComboBox->addItem(tr("Minimized"), QVariant::fromValue(WindowState::Minimized));
@ -381,7 +380,6 @@ void OptionsDialog::loadBehaviorTabOptions()
connect(m_ui->checkShowSplash, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkShowSplash, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkProgramExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkProgramExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkProgramAutoExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkProgramAutoExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkConfirmStopAndStartAll, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkShowSystray, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkShowSystray, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkMinimizeToSysTray, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkMinimizeToSysTray, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkCloseToSystray, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkCloseToSystray, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
@ -464,7 +462,6 @@ void OptionsDialog::saveBehaviorTabOptions() const
pref->setSplashScreenDisabled(isSplashScreenDisabled()); pref->setSplashScreenDisabled(isSplashScreenDisabled());
pref->setConfirmOnExit(m_ui->checkProgramExitConfirm->isChecked()); pref->setConfirmOnExit(m_ui->checkProgramExitConfirm->isChecked());
pref->setDontConfirmAutoExit(!m_ui->checkProgramAutoExitConfirm->isChecked()); pref->setDontConfirmAutoExit(!m_ui->checkProgramAutoExitConfirm->isChecked());
pref->setConfirmPauseAndResumeAll(m_ui->checkConfirmStopAndStartAll->isChecked());
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
pref->setWinStartup(WinStartup()); pref->setWinStartup(WinStartup());

View file

@ -226,19 +226,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkConfirmStopAndStartAll">
<property name="toolTip">
<string>Shows a confirmation dialog upon pausing/starting all the torrents</string>
</property>
<property name="text">
<string>Confirm &quot;Stop/Start all&quot; actions</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="checkAltRowColors"> <widget class="QCheckBox" name="checkAltRowColors">
<property name="text"> <property name="text">

View file

@ -377,36 +377,14 @@ void TransferListWidget::setSelectedTorrentsLocation()
fileDialog->open(); fileDialog->open();
} }
void TransferListWidget::stopAllTorrents() void TransferListWidget::pauseSession()
{ {
if (Preferences::instance()->confirmPauseAndResumeAll()) BitTorrent::Session::instance()->pause();
{
// Show confirmation if user would really like to Stop All
const QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Confirm stop all torrents")
, tr("Would you like to stop all torrents?"), (QMessageBox::Yes | QMessageBox::No));
if (ret != QMessageBox::Yes)
return;
}
for (BitTorrent::Torrent *const torrent : asConst(BitTorrent::Session::instance()->torrents()))
torrent->stop();
} }
void TransferListWidget::startAllTorrents() void TransferListWidget::resumeSession()
{ {
if (Preferences::instance()->confirmPauseAndResumeAll()) BitTorrent::Session::instance()->resume();
{
// Show confirmation if user would really like to Start All
const QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Confirm start all torrents")
, tr("Would you like to start all torrents?"), (QMessageBox::Yes | QMessageBox::No));
if (ret != QMessageBox::Yes)
return;
}
for (BitTorrent::Torrent *const torrent : asConst(BitTorrent::Session::instance()->torrents()))
torrent->start();
} }
void TransferListWidget::startSelectedTorrents() void TransferListWidget::startSelectedTorrents()
@ -1142,8 +1120,7 @@ void TransferListWidget::displayListMenu()
needsStop = true; needsStop = true;
} }
const bool queued = (BitTorrent::Session::instance()->isQueueingSystemEnabled() && torrent->isQueued()); const bool queued = torrent->isQueued();
if (!isStopped && !rechecking && !queued) if (!isStopped && !rechecking && !queued)
oneCanForceReannounce = true; oneCanForceReannounce = true;

View file

@ -68,8 +68,8 @@ public slots:
void removeSelectionTag(const Tag &tag); void removeSelectionTag(const Tag &tag);
void clearSelectionTags(); void clearSelectionTags();
void setSelectedTorrentsLocation(); void setSelectedTorrentsLocation();
void stopAllTorrents(); void pauseSession();
void startAllTorrents(); void resumeSession();
void startSelectedTorrents(); void startSelectedTorrents();
void forceStartSelectedTorrents(); void forceStartSelectedTorrents();
void startVisibleTorrents(); void startVisibleTorrents();