[UI] TrayIcon + TrayIconMenu for OSX (review changes)

This commit is contained in:
crowning- 2016-11-16 22:04:33 +01:00 committed by GitHub
parent 12691e15d4
commit 9071136c9b

View File

@ -110,6 +110,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n
showHelpMessageAction(0), showHelpMessageAction(0),
trayIcon(0), trayIcon(0),
trayIconMenu(0), trayIconMenu(0),
dockIconMenu(0),
notificator(0), notificator(0),
rpcConsole(0), rpcConsole(0),
helpMessageDialog(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, // 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 // 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 // Keep up to date with client
setNumConnections(clientModel->getNumConnections()); setNumConnections(clientModel->getNumConnections());
@ -601,6 +620,13 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
// Disable context menu on tray icon // Disable context menu on tray icon
trayIconMenu->clear(); 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); 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 // Configuration of the tray icon (or dock icon) icon menu
trayIconMenu->addAction(toggleHideAction); pmenu->addAction(toggleHideAction);
trayIconMenu->addSeparator(); pmenu->addSeparator();
trayIconMenu->addAction(sendCoinsMenuAction); pmenu->addAction(sendCoinsMenuAction);
trayIconMenu->addAction(receiveCoinsMenuAction); pmenu->addAction(receiveCoinsMenuAction);
trayIconMenu->addSeparator(); pmenu->addSeparator();
trayIconMenu->addAction(signMessageAction); pmenu->addAction(signMessageAction);
trayIconMenu->addAction(verifyMessageAction); pmenu->addAction(verifyMessageAction);
trayIconMenu->addSeparator(); pmenu->addSeparator();
trayIconMenu->addAction(optionsAction); pmenu->addAction(optionsAction);
trayIconMenu->addAction(openInfoAction); pmenu->addAction(openInfoAction);
trayIconMenu->addAction(openRPCConsoleAction); pmenu->addAction(openRPCConsoleAction);
trayIconMenu->addAction(openGraphAction); pmenu->addAction(openGraphAction);
trayIconMenu->addAction(openPeersAction); pmenu->addAction(openPeersAction);
trayIconMenu->addAction(openRepairAction); pmenu->addAction(openRepairAction);
trayIconMenu->addSeparator(); pmenu->addSeparator();
trayIconMenu->addAction(openConfEditorAction); pmenu->addAction(openConfEditorAction);
trayIconMenu->addAction(openMNConfEditorAction); pmenu->addAction(openMNConfEditorAction);
trayIconMenu->addAction(showBackupsAction); pmenu->addAction(showBackupsAction);
trayIconMenu->addSeparator(); #ifndef Q_OS_MAC // This is built-in on Mac
trayIconMenu->addAction(quitAction); pmenu->addSeparator();
pmenu->addAction(quitAction);
#endif
} }
#ifndef Q_OS_MAC #ifndef Q_OS_MAC