Merge #15149: gui: Show current wallet name in window title

fe7048b39 gui: Show current wallet name in window title (João Barbosa)
8a7926112 gui: Keep network style in BitcoinGUI (João Barbosa)
f411c8b35 gui: Remove unused return type in some BitcoinGUI methods (João Barbosa)

Pull request description:

  <img width="876" alt="screenshot 2019-01-11 at 23 58 26" src="https://user-images.githubusercontent.com/3534524/51065458-d7ebaf80-15fc-11e9-9162-e37e9a10d448.png">

Tree-SHA512: 5c43f615834983bc1c5045e07c6e119044dd78ca947fd2679d302b519d5ce1d08d29ca00b1c11e88c4bbc4d56f2e6f4a8adc42084f3503e751e642e8a13112dc
This commit is contained in:
Jonas Schnelli 2019-01-15 09:01:43 -10:00
commit c7c84209bb
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D
4 changed files with 53 additions and 36 deletions

View File

@ -77,7 +77,8 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
QMainWindow(parent), QMainWindow(parent),
m_node(node), m_node(node),
trayIconMenu{new QMenu()}, trayIconMenu{new QMenu()},
platformStyle(_platformStyle) platformStyle(_platformStyle),
m_network_style(networkStyle)
{ {
QSettings settings; QSettings settings;
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) { if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
@ -85,20 +86,12 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center()); move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
} }
QString windowTitle = tr(PACKAGE_NAME) + " - ";
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
enableWallet = WalletModel::isWalletEnabled(); enableWallet = WalletModel::isWalletEnabled();
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
if(enableWallet) QApplication::setWindowIcon(m_network_style->getTrayAndWindowIcon());
{ setWindowIcon(m_network_style->getTrayAndWindowIcon());
windowTitle += tr("Wallet"); updateWindowTitle();
} else {
windowTitle += tr("Node");
}
windowTitle += " " + networkStyle->getTitleAddText();
QApplication::setWindowIcon(networkStyle->getTrayAndWindowIcon());
setWindowIcon(networkStyle->getTrayAndWindowIcon());
setWindowTitle(windowTitle);
rpcConsole = new RPCConsole(node, _platformStyle, nullptr); rpcConsole = new RPCConsole(node, _platformStyle, nullptr);
helpMessageDialog = new HelpMessageDialog(node, this, false); helpMessageDialog = new HelpMessageDialog(node, this, false);
@ -133,7 +126,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
// Create system tray icon and notification // Create system tray icon and notification
if (QSystemTrayIcon::isSystemTrayAvailable()) { if (QSystemTrayIcon::isSystemTrayAvailable()) {
createTrayIcon(networkStyle); createTrayIcon();
} }
notificator = new Notificator(QApplication::applicationName(), trayIcon, this); notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
@ -572,10 +565,9 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
} }
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
bool BitcoinGUI::addWallet(WalletModel *walletModel) void BitcoinGUI::addWallet(WalletModel* walletModel)
{ {
if(!walletFrame) if (!walletFrame) return;
return false;
const QString display_name = walletModel->getDisplayName(); const QString display_name = walletModel->getDisplayName();
setWalletActionsEnabled(true); setWalletActionsEnabled(true);
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel)); m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
@ -584,12 +576,12 @@ bool BitcoinGUI::addWallet(WalletModel *walletModel)
m_wallet_selector_action->setVisible(true); m_wallet_selector_action->setVisible(true);
} }
rpcConsole->addWallet(walletModel); rpcConsole->addWallet(walletModel);
return walletFrame->addWallet(walletModel); walletFrame->addWallet(walletModel);
} }
bool BitcoinGUI::removeWallet(WalletModel* walletModel) void BitcoinGUI::removeWallet(WalletModel* walletModel)
{ {
if (!walletFrame) return false; if (!walletFrame) return;
int index = m_wallet_selector->findData(QVariant::fromValue(walletModel)); int index = m_wallet_selector->findData(QVariant::fromValue(walletModel));
m_wallet_selector->removeItem(index); m_wallet_selector->removeItem(index);
if (m_wallet_selector->count() == 0) { if (m_wallet_selector->count() == 0) {
@ -599,20 +591,21 @@ bool BitcoinGUI::removeWallet(WalletModel* walletModel)
m_wallet_selector_action->setVisible(false); m_wallet_selector_action->setVisible(false);
} }
rpcConsole->removeWallet(walletModel); 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) if (!walletFrame) return;
return false; walletFrame->setCurrentWallet(wallet_model);
return walletFrame->setCurrentWallet(wallet_model); updateWindowTitle();
} }
bool BitcoinGUI::setCurrentWalletBySelectorIndex(int index) void BitcoinGUI::setCurrentWalletBySelectorIndex(int index)
{ {
WalletModel* wallet_model = m_wallet_selector->itemData(index).value<WalletModel*>(); WalletModel* wallet_model = m_wallet_selector->itemData(index).value<WalletModel*>();
return setCurrentWallet(wallet_model); setCurrentWallet(wallet_model);
} }
void BitcoinGUI::removeAllWallets() void BitcoinGUI::removeAllWallets()
@ -642,14 +635,14 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
openAction->setEnabled(enabled); openAction->setEnabled(enabled);
} }
void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle) void BitcoinGUI::createTrayIcon()
{ {
assert(QSystemTrayIcon::isSystemTrayAvailable()); assert(QSystemTrayIcon::isSystemTrayAvailable());
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
if (QSystemTrayIcon::isSystemTrayAvailable()) { if (QSystemTrayIcon::isSystemTrayAvailable()) {
trayIcon = new QSystemTrayIcon(networkStyle->getTrayAndWindowIcon(), this); trayIcon = new QSystemTrayIcon(m_network_style->getTrayAndWindowIcon(), this);
QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + networkStyle->getTitleAddText(); QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + m_network_style->getTitleAddText();
trayIcon->setToolTip(toolTip); trayIcon->setToolTip(toolTip);
} }
#endif #endif
@ -1208,6 +1201,21 @@ void BitcoinGUI::updateProxyIcon()
} }
} }
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) void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
{ {
if(!clientModel) if(!clientModel)

View File

@ -80,8 +80,8 @@ public:
The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending
functionality. functionality.
*/ */
bool addWallet(WalletModel *walletModel); void addWallet(WalletModel* walletModel);
bool removeWallet(WalletModel* walletModel); void removeWallet(WalletModel* walletModel);
void removeAllWallets(); void removeAllWallets();
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
bool enableWallet = false; bool enableWallet = false;
@ -161,6 +161,7 @@ private:
int spinnerFrame = 0; int spinnerFrame = 0;
const PlatformStyle *platformStyle; const PlatformStyle *platformStyle;
const NetworkStyle* const m_network_style;
/** Create the main UI actions. */ /** Create the main UI actions. */
void createActions(); void createActions();
@ -169,7 +170,7 @@ private:
/** Create the toolbars */ /** Create the toolbars */
void createToolBars(); void createToolBars();
/** Create system tray icon and notification */ /** Create system tray icon and notification */
void createTrayIcon(const NetworkStyle *networkStyle); void createTrayIcon();
/** Create system tray menu (or setup the dock menu) */ /** Create system tray menu (or setup the dock menu) */
void createTrayIconMenu(); void createTrayIconMenu();
@ -213,8 +214,8 @@ public Q_SLOTS:
void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr); void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
bool setCurrentWallet(WalletModel* wallet_model); void setCurrentWallet(WalletModel* wallet_model);
bool setCurrentWalletBySelectorIndex(int index); void setCurrentWalletBySelectorIndex(int index);
/** Set the UI status indicators based on the currently selected wallet. /** Set the UI status indicators based on the currently selected wallet.
*/ */
void updateWalletStatus(); void updateWalletStatus();
@ -242,6 +243,7 @@ public Q_SLOTS:
private: private:
/** Set the proxy-enabled icon as shown in the UI. */ /** Set the proxy-enabled icon as shown in the UI. */
void updateProxyIcon(); void updateProxyIcon();
void updateWindowTitle();
public Q_SLOTS: public Q_SLOTS:
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET

View File

@ -208,11 +208,17 @@ void WalletFrame::usedReceivingAddresses()
walletView->usedReceivingAddresses(); walletView->usedReceivingAddresses();
} }
WalletView *WalletFrame::currentWalletView() WalletView* WalletFrame::currentWalletView() const
{ {
return qobject_cast<WalletView*>(walletStack->currentWidget()); return qobject_cast<WalletView*>(walletStack->currentWidget());
} }
WalletModel* WalletFrame::currentWalletModel() const
{
WalletView* wallet_view = currentWalletView();
return wallet_view ? wallet_view->getWalletModel() : nullptr;
}
void WalletFrame::outOfSyncWarningClicked() void WalletFrame::outOfSyncWarningClicked()
{ {
Q_EMIT requestedSyncWarningInfo(); Q_EMIT requestedSyncWarningInfo();

View File

@ -60,7 +60,8 @@ private:
const PlatformStyle *platformStyle; const PlatformStyle *platformStyle;
public: public:
WalletView *currentWalletView(); WalletView* currentWalletView() const;
WalletModel* currentWalletModel() const;
public Q_SLOTS: public Q_SLOTS:
/** Switch to overview (home) page */ /** Switch to overview (home) page */