Merge pull request #1142 from crowning-/patch-1
[UI] TrayIcon + TrayIconMenu for OSX
This commit is contained in:
commit
7a005a911e
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,58 +679,38 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
|
|||||||
|
|
||||||
void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
|
void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_MAC
|
|
||||||
trayIcon = new QSystemTrayIcon(this);
|
trayIcon = new QSystemTrayIcon(this);
|
||||||
QString toolTip = tr("Dash Core client") + " " + networkStyle->getTitleAddText();
|
QString toolTip = tr("Dash Core client") + " " + networkStyle->getTitleAddText();
|
||||||
trayIcon->setToolTip(toolTip);
|
trayIcon->setToolTip(toolTip);
|
||||||
trayIcon->setIcon(networkStyle->getTrayAndWindowIcon());
|
trayIcon->setIcon(networkStyle->getTrayAndWindowIcon());
|
||||||
trayIcon->show();
|
trayIcon->show();
|
||||||
#endif
|
|
||||||
|
|
||||||
notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
|
notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitcoinGUI::createTrayIconMenu()
|
void BitcoinGUI::createIconMenu(QMenu *pmenu)
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_MAC
|
|
||||||
// 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)));
|
|
||||||
#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
|
// 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);
|
||||||
#ifndef Q_OS_MAC // This is built-in on Mac
|
#ifndef Q_OS_MAC // This is built-in on Mac
|
||||||
trayIconMenu->addSeparator();
|
pmenu->addSeparator();
|
||||||
trayIconMenu->addAction(quitAction);
|
pmenu->addAction(quitAction);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ private:
|
|||||||
|
|
||||||
QSystemTrayIcon *trayIcon;
|
QSystemTrayIcon *trayIcon;
|
||||||
QMenu *trayIconMenu;
|
QMenu *trayIconMenu;
|
||||||
|
QMenu *dockIconMenu;
|
||||||
Notificator *notificator;
|
Notificator *notificator;
|
||||||
RPCConsole *rpcConsole;
|
RPCConsole *rpcConsole;
|
||||||
HelpMessageDialog *helpMessageDialog;
|
HelpMessageDialog *helpMessageDialog;
|
||||||
@ -145,7 +146,7 @@ private:
|
|||||||
/** Create system tray icon and notification */
|
/** Create system tray icon and notification */
|
||||||
void createTrayIcon(const NetworkStyle *networkStyle);
|
void createTrayIcon(const NetworkStyle *networkStyle);
|
||||||
/** Create system tray menu (or setup the dock menu) */
|
/** Create system tray menu (or setup the dock menu) */
|
||||||
void createTrayIconMenu();
|
void createIconMenu(QMenu *pmenu);
|
||||||
|
|
||||||
/** Enable or disable all wallet-related actions */
|
/** Enable or disable all wallet-related actions */
|
||||||
void setWalletActionsEnabled(bool enabled);
|
void setWalletActionsEnabled(bool enabled);
|
||||||
|
Loading…
Reference in New Issue
Block a user