From 544d220819bea7d47822b877fd7228dcbf19d418 Mon Sep 17 00:00:00 2001 From: crowning- Date: Tue, 15 Nov 2016 23:38:04 +0100 Subject: [PATCH 1/3] [UI] TrayIcon + TrayIconMenu for OSX --- src/qt/bitcoingui.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 325e81e42..2721a2fdf 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -653,20 +653,16 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle) { -#ifndef Q_OS_MAC trayIcon = new QSystemTrayIcon(this); QString toolTip = tr("Dash Core client") + " " + networkStyle->getTitleAddText(); trayIcon->setToolTip(toolTip); trayIcon->setIcon(networkStyle->getTrayAndWindowIcon()); trayIcon->show(); -#endif - notificator = new Notificator(QApplication::applicationName(), trayIcon, this); } void BitcoinGUI::createTrayIconMenu() { -#ifndef Q_OS_MAC // return if trayIcon is unset (only on non-Mac OSes) if (!trayIcon) return; @@ -676,12 +672,6 @@ void BitcoinGUI::createTrayIconMenu() connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason))); -#else - // Note: On Mac, the dock icon is used to provide the tray's functionality. - MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance(); - dockIconHandler->setMainWindow((QMainWindow *)this); - trayIconMenu = dockIconHandler->dockMenu(); -#endif // Configuration of the tray icon (or dock icon) icon menu trayIconMenu->addAction(toggleHideAction); @@ -702,10 +692,8 @@ void BitcoinGUI::createTrayIconMenu() trayIconMenu->addAction(openConfEditorAction); trayIconMenu->addAction(openMNConfEditorAction); trayIconMenu->addAction(showBackupsAction); -#ifndef Q_OS_MAC // This is built-in on Mac trayIconMenu->addSeparator(); trayIconMenu->addAction(quitAction); -#endif } #ifndef Q_OS_MAC From 12691e15d453094a6623806f8bdcc912bead8c89 Mon Sep 17 00:00:00 2001 From: crowning- Date: Wed, 16 Nov 2016 22:04:26 +0100 Subject: [PATCH 2/3] [UI] TrayIcon + TrayIconMenu for OSX (review changes) --- src/qt/bitcoingui.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index c22a1d60b..2aebb9d34 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -126,6 +126,7 @@ private: QSystemTrayIcon *trayIcon; QMenu *trayIconMenu; + QMenu *dockIconMenu; Notificator *notificator; RPCConsole *rpcConsole; HelpMessageDialog *helpMessageDialog; @@ -145,7 +146,7 @@ private: /** Create system tray icon and notification */ void createTrayIcon(const NetworkStyle *networkStyle); /** Create system tray menu (or setup the dock menu) */ - void createTrayIconMenu(); + void createIconMenu(QMenu *pmenu); /** Enable or disable all wallet-related actions */ void setWalletActionsEnabled(bool enabled); From 9071136c9b8890439f30874a68985e5ded38701e Mon Sep 17 00:00:00 2001 From: crowning- Date: Wed, 16 Nov 2016 22:04:33 +0100 Subject: [PATCH 3/3] [UI] TrayIcon + TrayIconMenu for OSX (review changes) --- src/qt/bitcoingui.cpp | 82 ++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 2721a2fdf..ca91f6893 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -110,6 +110,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n showHelpMessageAction(0), trayIcon(0), trayIconMenu(0), + dockIconMenu(0), notificator(0), rpcConsole(0), helpMessageDialog(0), @@ -568,7 +569,25 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel) { // Create system tray menu (or setup the dock menu) that late to prevent users from calling actions, // while the client has not yet fully loaded - createTrayIconMenu(); + if (trayIcon) { + // do so only if trayIcon is already set + trayIconMenu = new QMenu(this); + trayIcon->setContextMenu(trayIconMenu); + + connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason))); + + createIconMenu(trayIconMenu); + +#ifdef Q_OS_MAC + // Note: On Mac, the dock icon is also used to provide same functionality. + MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance(); + dockIconHandler->setMainWindow((QMainWindow *)this); + dockIconMenu = dockIconHandler->dockMenu(); + + createIconMenu(dockIconMenu); +#endif + } // Keep up to date with client setNumConnections(clientModel->getNumConnections()); @@ -601,6 +620,13 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel) // Disable context menu on tray icon trayIconMenu->clear(); } +#ifdef Q_OS_MAC + if(dockIconMenu) + { + // Disable context menu on dock icon + dockIconMenu->clear(); + } +#endif } } @@ -661,39 +687,31 @@ void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle) notificator = new Notificator(QApplication::applicationName(), trayIcon, this); } -void BitcoinGUI::createTrayIconMenu() +void BitcoinGUI::createIconMenu(QMenu *pmenu) { - // return if trayIcon is unset (only on non-Mac OSes) - if (!trayIcon) - return; - - trayIconMenu = new QMenu(this); - trayIcon->setContextMenu(trayIconMenu); - - connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason))); - // Configuration of the tray icon (or dock icon) icon menu - trayIconMenu->addAction(toggleHideAction); - trayIconMenu->addSeparator(); - trayIconMenu->addAction(sendCoinsMenuAction); - trayIconMenu->addAction(receiveCoinsMenuAction); - trayIconMenu->addSeparator(); - trayIconMenu->addAction(signMessageAction); - trayIconMenu->addAction(verifyMessageAction); - trayIconMenu->addSeparator(); - trayIconMenu->addAction(optionsAction); - trayIconMenu->addAction(openInfoAction); - trayIconMenu->addAction(openRPCConsoleAction); - trayIconMenu->addAction(openGraphAction); - trayIconMenu->addAction(openPeersAction); - trayIconMenu->addAction(openRepairAction); - trayIconMenu->addSeparator(); - trayIconMenu->addAction(openConfEditorAction); - trayIconMenu->addAction(openMNConfEditorAction); - trayIconMenu->addAction(showBackupsAction); - trayIconMenu->addSeparator(); - trayIconMenu->addAction(quitAction); + pmenu->addAction(toggleHideAction); + pmenu->addSeparator(); + pmenu->addAction(sendCoinsMenuAction); + pmenu->addAction(receiveCoinsMenuAction); + pmenu->addSeparator(); + pmenu->addAction(signMessageAction); + pmenu->addAction(verifyMessageAction); + pmenu->addSeparator(); + pmenu->addAction(optionsAction); + pmenu->addAction(openInfoAction); + pmenu->addAction(openRPCConsoleAction); + pmenu->addAction(openGraphAction); + pmenu->addAction(openPeersAction); + pmenu->addAction(openRepairAction); + pmenu->addSeparator(); + pmenu->addAction(openConfEditorAction); + pmenu->addAction(openMNConfEditorAction); + pmenu->addAction(showBackupsAction); +#ifndef Q_OS_MAC // This is built-in on Mac + pmenu->addSeparator(); + pmenu->addAction(quitAction); +#endif } #ifndef Q_OS_MAC