diff --git a/CHANGELOG.md b/CHANGELOG.md index c20bd5a9..45a38814 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added - Support of xdg-activation protocol on Wayland with Qt < 6.3 - Option to open torrent's file or download directory on double click +- Right click on status bar opens menu to quickly connect to different server ### Changed - "Open" and "Show in file manager" actions now show error dialog if file/directory does not exist, diff --git a/src/ui/screens/mainwindow/mainwindow.cpp b/src/ui/screens/mainwindow/mainwindow.cpp index 3539f61f..acca0930 100644 --- a/src/ui/screens/mainwindow/mainwindow.cpp +++ b/src/ui/screens/mainwindow/mainwindow.cpp @@ -218,10 +218,16 @@ namespace tremotesf { mWindow->setCentralWidget(&mSplitter); - mWindow->setStatusBar(new MainWindowStatusBar(mViewModel.rpc())); + auto* const statusBar = new MainWindowStatusBar(mViewModel.rpc()); + mWindow->setStatusBar(statusBar); if (!Settings::instance()->isStatusBarVisible()) { - mWindow->statusBar()->hide(); + statusBar->hide(); } + QObject::connect(statusBar, &MainWindowStatusBar::showConnectionSettingsDialog, this, [this] { + showSingleInstanceDialog([this] { + return new ConnectionSettingsDialog(mWindow); + }); + }); setupActions(); @@ -341,7 +347,8 @@ namespace tremotesf { QAction mAddTorrentFileAction{ QIcon::fromTheme("list-add"_l1), //: Menu item - qApp->translate("tremotesf", "&Add Torrent File...")}; + qApp->translate("tremotesf", "&Add Torrent File...") + }; QAction mAddTorrentLinkAction{ QIcon::fromTheme("insert-link"_l1), //: Menu item diff --git a/src/ui/screens/mainwindow/mainwindowstatusbar.cpp b/src/ui/screens/mainwindow/mainwindowstatusbar.cpp index f3226320..49e5e958 100644 --- a/src/ui/screens/mainwindow/mainwindowstatusbar.cpp +++ b/src/ui/screens/mainwindow/mainwindowstatusbar.cpp @@ -8,9 +8,11 @@ #include #include #include +#include #include +#include "log/log.h" #include "rpc/serverstats.h" #include "rpc/servers.h" #include "rpc/rpc.h" @@ -20,6 +22,9 @@ namespace tremotesf { MainWindowStatusBar::MainWindowStatusBar(const Rpc* rpc, QWidget* parent) : QStatusBar(parent), mRpc(rpc) { setSizeGripEnabled(false); + setContextMenuPolicy(Qt::CustomContextMenu); + QObject::connect(this, &QWidget::customContextMenuRequested, this, &MainWindowStatusBar::showContextMenu); + auto container = new QWidget(this); addPermanentWidget(container, 1); @@ -138,9 +143,48 @@ namespace tremotesf { void MainWindowStatusBar::updateStatusLabels() { mStatusLabel->setText(mRpc->status().toString()); if (mRpc->error() != RpcError::NoError) { - setToolTip(mRpc->errorMessage()); + mStatusLabel->setToolTip(mRpc->errorMessage()); } else { - setToolTip({}); + mStatusLabel->setToolTip({}); + } + } + + void MainWindowStatusBar::showContextMenu() { + auto* const menu = new QMenu(this); + auto* const group = new QActionGroup(menu); + group->setExclusive(true); + menu->setAttribute(Qt::WA_DeleteOnClose, true); + const auto servers = Servers::instance()->servers(); + const auto currentServerName = Servers::instance()->currentServerName(); + for (const auto& server : servers) { + auto* const action = menu->addAction(server.name); + action->setCheckable(true); + group->addAction(action); + if (server.name == currentServerName) { + action->setChecked(true); + } } + menu->addSeparator(); + auto* const connectionSettingsAction = menu->addAction( + QIcon::fromTheme("network-server"_l1), + qApp->translate("tremotesf", "&Connection Settings") + ); + QObject::connect(menu, &QMenu::triggered, this, [this, connectionSettingsAction](QAction* action) { + if (action == connectionSettingsAction) { + emit showConnectionSettingsDialog(); + } else { + const auto selectedName = action->text(); + const auto servers = Servers::instance()->servers(); + const auto found = std::find_if(servers.begin(), servers.end(), [&](const auto& server) { + return server.name == selectedName; + }); + if (found != servers.end()) { + Servers::instance()->setCurrentServer(selectedName); + } else { + logWarning("Selected server {} which no longer exists", selectedName); + } + } + }); + menu->popup(QCursor::pos()); } } diff --git a/src/ui/screens/mainwindow/mainwindowstatusbar.h b/src/ui/screens/mainwindow/mainwindowstatusbar.h index 2c945099..5d649102 100644 --- a/src/ui/screens/mainwindow/mainwindowstatusbar.h +++ b/src/ui/screens/mainwindow/mainwindowstatusbar.h @@ -23,6 +23,7 @@ namespace tremotesf { void updateLayout(); void updateServerLabel(); void updateStatusLabels(); + void showContextMenu(); const Rpc* mRpc{}; QLabel* mNoServersErrorImage{}; @@ -35,6 +36,9 @@ namespace tremotesf { KSeparator* mThirdSeparator{}; QLabel* mUploadSpeedImage{}; QLabel* mUploadSpeedLabel{}; + + signals: + void showConnectionSettingsDialog(); }; }