Allow to set custom suffix to window title

This is to allow users to differentiate qbt instances when there are multiple running.
PR #20429.
Closes #17905.
This commit is contained in:
Chocobo1
2024-02-27 12:41:12 +08:00
committed by GitHub
parent 364bcf73ee
commit 46e8ee50c8
13 changed files with 98 additions and 27 deletions

View File

@@ -79,6 +79,7 @@ namespace
CONFIRM_RECHECK_TORRENT,
RECHECK_COMPLETED,
// UI related
APP_INSTANCE_NAME,
LIST_REFRESH,
RESOLVE_HOSTS,
RESOLVE_COUNTRIES,
@@ -280,6 +281,8 @@ void AdvancedSettings::saveAdvancedSettings() const
session->setBlockPeersOnPrivilegedPorts(m_checkBoxBlockPeersOnPrivilegedPorts.isChecked());
// Recheck torrents on completion
pref->recheckTorrentsOnCompletion(m_checkBoxRecheckCompleted.isChecked());
// Customize application instance name
app()->setInstanceName(m_lineEditAppInstanceName.text());
// Transfer list refresh interval
session->setRefreshInterval(m_spinBoxListRefresh.value());
// Peer resolution
@@ -723,6 +726,10 @@ void AdvancedSettings::loadAdvancedSettings()
// Recheck completed torrents
m_checkBoxRecheckCompleted.setChecked(pref->recheckTorrentsOnCompletion());
addRow(RECHECK_COMPLETED, tr("Recheck torrents on completion"), &m_checkBoxRecheckCompleted);
// Customize application instance name
m_lineEditAppInstanceName.setText(app()->instanceName());
m_lineEditAppInstanceName.setToolTip(tr("It appends the text to the window title to help distinguish qBittorent instances"));
addRow(APP_INSTANCE_NAME, tr("Customize application instance name"), &m_lineEditAppInstanceName);
// Refresh interval
m_spinBoxListRefresh.setMinimum(30);
m_spinBoxListRefresh.setMaximum(99999);

View File

@@ -82,7 +82,7 @@ private:
m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport, m_checkBoxConfirmRemoveTrackerFromAllTorrents;
QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxDiskIOReadMode, m_comboBoxDiskIOWriteMode, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm,
m_comboBoxSeedChokingAlgorithm, m_comboBoxResumeDataStorage;
QLineEdit m_pythonExecutablePath, m_lineEditAnnounceIP, m_lineEditDHTBootstrapNodes;
QLineEdit m_lineEditAppInstanceName, m_pythonExecutablePath, m_lineEditAnnounceIP, m_lineEditDHTBootstrapNodes;
#ifndef QBT_USES_LIBTORRENT2
QSpinBox m_spinBoxCache, m_spinBoxCacheTTL;

View File

@@ -122,7 +122,7 @@ namespace
}
}
MainWindow::MainWindow(IGUIApplication *app, WindowState initialState)
MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, const QString &titleSuffix)
: GUIApplicationComponent(app)
, m_ui(new Ui::MainWindow)
, m_storeExecutionLogEnabled(EXECUTIONLOG_SETTINGS_KEY(u"Enabled"_s))
@@ -134,9 +134,10 @@ MainWindow::MainWindow(IGUIApplication *app, WindowState initialState)
{
m_ui->setupUi(this);
setTitleSuffix(titleSuffix);
Preferences *const pref = Preferences::instance();
m_uiLocked = pref->isUILocked();
setWindowTitle(QStringLiteral("qBittorrent " QBT_VERSION));
m_displaySpeedInTitle = pref->speedInTitleBar();
// Setting icons
#ifndef Q_OS_MACOS
@@ -524,6 +525,16 @@ void MainWindow::setDownloadTrackerFavicon(const bool value)
m_storeDownloadTrackerFavicon = value;
}
void MainWindow::setTitleSuffix(const QString &suffix)
{
const auto emDash = QChar(0x2014);
const QString separator = u' ' + emDash + u' ';
m_windowTitle = QStringLiteral("qBittorrent " QBT_VERSION)
+ (!suffix.isEmpty() ? (separator + suffix) : QString());
setWindowTitle(m_windowTitle);
}
void MainWindow::addToolbarContextMenu()
{
const Preferences *const pref = Preferences::instance();
@@ -1485,23 +1496,24 @@ void MainWindow::loadPreferences()
void MainWindow::reloadSessionStats()
{
const BitTorrent::SessionStatus &status = BitTorrent::Session::instance()->status();
const QString downloadRate = Utils::Misc::friendlyUnit(status.payloadDownloadRate, true);
const QString uploadRate = Utils::Misc::friendlyUnit(status.payloadUploadRate, true);
// update global information
#ifdef Q_OS_MACOS
m_badger->updateSpeed(status.payloadDownloadRate, status.payloadUploadRate);
#else
const auto toolTip = u"%1\n%2"_s.arg(
tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
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
if (m_displaySpeedInTitle)
{
setWindowTitle(tr("[D: %1, U: %2] qBittorrent %3", "D = Download; U = Upload; %3 is qBittorrent version")
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)
, Utils::Misc::friendlyUnit(status.payloadUploadRate, true)
, QStringLiteral(QBT_VERSION)));
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);
}
}
@@ -1621,7 +1633,7 @@ void MainWindow::on_actionSpeedInTitleBar_triggered()
if (m_displaySpeedInTitle)
reloadSessionStats();
else
setWindowTitle(QStringLiteral("qBittorrent " QBT_VERSION));
setWindowTitle(m_windowTitle);
}
void MainWindow::on_actionRSSReader_triggered()

View File

@@ -84,7 +84,7 @@ class MainWindow final : public GUIApplicationComponent<QMainWindow>
Q_DISABLE_COPY_MOVE(MainWindow)
public:
explicit MainWindow(IGUIApplication *app, WindowState initialState = WindowState::Normal);
explicit MainWindow(IGUIApplication *app, WindowState initialState = WindowState::Normal, const QString &titleSuffix = {});
~MainWindow() override;
QWidget *currentTabWidget() const;
@@ -97,12 +97,12 @@ public:
Log::MsgTypes executionLogMsgTypes() const;
void setExecutionLogMsgTypes(Log::MsgTypes value);
// Notifications properties
// Misc properties
bool isDownloadTrackerFavicon() const;
void setDownloadTrackerFavicon(bool value);
void setTitleSuffix(const QString &suffix);
void activate();
void cleanup();
@@ -207,6 +207,7 @@ private:
QFileSystemWatcher *m_executableWatcher = nullptr;
// GUI related
QString m_windowTitle;
bool m_posInitialized = false;
bool m_neverShown = true;
QPointer<QTabWidget> m_tabs;