diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -83,8 +83,8 @@ * The wallet model represents a bitcoin wallet, and offers access to the * list of transactions, address book and sending functionality. */ - bool addWallet(WalletModel *walletModel); - bool removeWallet(WalletModel *walletModel); + void addWallet(WalletModel *walletModel); + void removeWallet(WalletModel *walletModel); void removeAllWallets(); #endif // ENABLE_WALLET bool enableWallet = false; @@ -154,8 +154,9 @@ int prevBlocks = 0; int spinnerFrame = 0; - const PlatformStyle *platformStyle; const Config *config; + const PlatformStyle *platformStyle; + const NetworkStyle *const m_network_style; /** Create the main UI actions. */ void createActions(); @@ -164,7 +165,7 @@ /** Create the toolbars */ void createToolBars(); /** Create system tray icon and notification */ - void createTrayIcon(const NetworkStyle *networkStyle); + void createTrayIcon(); /** Create system tray menu (or setup the dock menu) */ void createTrayIconMenu(); @@ -213,8 +214,8 @@ unsigned int style, bool *ret = nullptr); #ifdef ENABLE_WALLET - bool setCurrentWallet(WalletModel *wallet_model); - bool setCurrentWalletBySelectorIndex(int index); + void setCurrentWallet(WalletModel *wallet_model); + void setCurrentWalletBySelectorIndex(int index); /** Set the UI status indicators based on the currently selected wallet. */ void updateWalletStatus(); @@ -244,6 +245,7 @@ private: /** Set the proxy-enabled icon as shown in the UI. */ void updateProxyIcon(); + void updateWindowTitle(); public Q_SLOTS: #ifdef ENABLE_WALLET diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -71,8 +71,8 @@ BitcoinGUI::BitcoinGUI(interfaces::Node &node, const Config *configIn, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) - : QMainWindow(parent), enableWallet(false), m_node(node), - platformStyle(_platformStyle), config(configIn) { + : QMainWindow(parent), m_node(node), config(configIn), + platformStyle(_platformStyle), m_network_style(networkStyle) { QSettings settings; if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) { // Restore failed (perhaps missing setting), center the window @@ -80,19 +80,12 @@ frameGeometry().center()); } - QString windowTitle = tr(PACKAGE_NAME) + " - "; #ifdef ENABLE_WALLET enableWallet = WalletModel::isWalletEnabled(); #endif // ENABLE_WALLET - if (enableWallet) { - windowTitle += tr("Wallet"); - } else { - windowTitle += tr("Node"); - } - windowTitle += " " + networkStyle->getTitleAddText(); - QApplication::setWindowIcon(networkStyle->getTrayAndWindowIcon()); - setWindowIcon(networkStyle->getTrayAndWindowIcon()); - setWindowTitle(windowTitle); + QApplication::setWindowIcon(m_network_style->getTrayAndWindowIcon()); + setWindowIcon(m_network_style->getTrayAndWindowIcon()); + updateWindowTitle(); rpcConsole = new RPCConsole(node, _platformStyle, 0); helpMessageDialog = new HelpMessageDialog(node, this, false); @@ -127,7 +120,7 @@ // Create system tray icon and notification if (QSystemTrayIcon::isSystemTrayAvailable()) { - createTrayIcon(networkStyle); + createTrayIcon(); } notificator = new Notificator(QApplication::applicationName(), trayIcon, this); @@ -611,9 +604,9 @@ } #ifdef ENABLE_WALLET -bool BitcoinGUI::addWallet(WalletModel *walletModel) { +void BitcoinGUI::addWallet(WalletModel *walletModel) { if (!walletFrame) { - return false; + return; } const QString display_name = walletModel->getDisplayName(); setWalletActionsEnabled(true); @@ -623,12 +616,12 @@ m_wallet_selector_action->setVisible(true); } rpcConsole->addWallet(walletModel); - return walletFrame->addWallet(walletModel); + walletFrame->addWallet(walletModel); } -bool BitcoinGUI::removeWallet(WalletModel *walletModel) { +void BitcoinGUI::removeWallet(WalletModel *walletModel) { if (!walletFrame) { - return false; + return; } int index = m_wallet_selector->findData(QVariant::fromValue(walletModel)); m_wallet_selector->removeItem(index); @@ -639,20 +632,22 @@ m_wallet_selector_action->setVisible(false); } rpcConsole->removeWallet(walletModel); - return walletFrame->removeWallet(walletModel); + walletFrame->removeWallet(walletModel); + updateWindowTitle(); } -bool BitcoinGUI::setCurrentWallet(WalletModel *wallet_model) { +void BitcoinGUI::setCurrentWallet(WalletModel *wallet_model) { if (!walletFrame) { - return false; + return; } - return walletFrame->setCurrentWallet(wallet_model); + walletFrame->setCurrentWallet(wallet_model); + updateWindowTitle(); } -bool BitcoinGUI::setCurrentWalletBySelectorIndex(int index) { +void BitcoinGUI::setCurrentWalletBySelectorIndex(int index) { WalletModel *wallet_model = m_wallet_selector->itemData(index).value(); - return setCurrentWallet(wallet_model); + setCurrentWallet(wallet_model); } void BitcoinGUI::removeAllWallets() { @@ -679,15 +674,15 @@ openAction->setEnabled(enabled); } -void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle) { +void BitcoinGUI::createTrayIcon() { assert(QSystemTrayIcon::isSystemTrayAvailable()); #ifndef Q_OS_MAC if (QSystemTrayIcon::isSystemTrayAvailable()) { trayIcon = - new QSystemTrayIcon(networkStyle->getTrayAndWindowIcon(), this); + new QSystemTrayIcon(m_network_style->getTrayAndWindowIcon(), this); QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + - networkStyle->getTitleAddText(); + m_network_style->getTitleAddText(); trayIcon->setToolTip(toolTip); } #endif @@ -1260,6 +1255,20 @@ } } +void BitcoinGUI::updateWindowTitle() { + QString window_title = tr(PACKAGE_NAME) + " - "; +#ifdef ENABLE_WALLET + if (walletFrame) { + WalletModel *const wallet_model = walletFrame->currentWalletModel(); + if (wallet_model && !wallet_model->getWalletName().isEmpty()) { + window_title += wallet_model->getDisplayName() + " - "; + } + } +#endif + window_title += m_network_style->getTitleAddText(); + setWindowTitle(window_title); +} + void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden) { if (!clientModel) { return; diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -61,7 +61,8 @@ const PlatformStyle *platformStyle; public: - WalletView *currentWalletView(); + WalletView *currentWalletView() const; + WalletModel *currentWalletModel() const; public Q_SLOTS: /** Switch to overview (home) page */ diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -200,10 +200,15 @@ } } -WalletView *WalletFrame::currentWalletView() { +WalletView *WalletFrame::currentWalletView() const { return qobject_cast(walletStack->currentWidget()); } +WalletModel *WalletFrame::currentWalletModel() const { + WalletView *wallet_view = currentWalletView(); + return wallet_view ? wallet_view->getWalletModel() : nullptr; +} + void WalletFrame::outOfSyncWarningClicked() { Q_EMIT requestedSyncWarningInfo(); }