solve MacOS Catalina compile
This commit is contained in:
@@ -393,7 +393,7 @@ case $host in
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
|
AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
|
||||||
CPPFLAGS="$CPPFLAGS -DMAC_OSX"
|
CPPFLAGS="$CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0"
|
||||||
OBJCXXFLAGS="$CXXFLAGS"
|
OBJCXXFLAGS="$CXXFLAGS"
|
||||||
;;
|
;;
|
||||||
*linux*)
|
*linux*)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class GlobalConfig final : public Config
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GlobalConfig();
|
GlobalConfig();
|
||||||
const CChainParams &GetChainParams() const;
|
const CChainParams &GetChainParams() const override;
|
||||||
void SetCashAddrEncoding(bool) override;
|
void SetCashAddrEncoding(bool) override;
|
||||||
bool UseCashAddrEncoding() const override;
|
bool UseCashAddrEncoding() const override;
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QComboBox>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QDragEnterEvent>
|
#include <QDragEnterEvent>
|
||||||
@@ -47,7 +48,6 @@
|
|||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QProgressBar>
|
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
@@ -56,14 +56,8 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
#if QT_VERSION < 0x050000
|
|
||||||
#include <QTextDocument>
|
|
||||||
#include <QUrl>
|
|
||||||
#else
|
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#endif
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
|
const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
@@ -143,20 +137,10 @@ BitcoinGUI::BitcoinGUI(const Config *cfg, const PlatformStyle *platformStyle, co
|
|||||||
windowTitle += tr("Node");
|
windowTitle += tr("Node");
|
||||||
}
|
}
|
||||||
windowTitle += " " + networkStyle->getTitleAddText();
|
windowTitle += " " + networkStyle->getTitleAddText();
|
||||||
#ifndef Q_OS_MAC
|
|
||||||
QApplication::setWindowIcon(networkStyle->getTrayAndWindowIcon());
|
QApplication::setWindowIcon(networkStyle->getTrayAndWindowIcon());
|
||||||
setWindowIcon(networkStyle->getTrayAndWindowIcon());
|
setWindowIcon(networkStyle->getTrayAndWindowIcon());
|
||||||
#else
|
|
||||||
MacDockIconHandler::instance()->setIcon(networkStyle->getAppIcon());
|
|
||||||
#endif
|
|
||||||
setWindowTitle(windowTitle);
|
setWindowTitle(windowTitle);
|
||||||
|
|
||||||
#if defined(Q_OS_MAC) && QT_VERSION < 0x050000
|
|
||||||
// This property is not implemented in Qt 5. Setting it has no effect.
|
|
||||||
// A replacement API (QtMacUnifiedToolBar) is available in QtMacExtras.
|
|
||||||
setUnifiedTitleAndToolBarOnMac(true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rpcConsole = new RPCConsole(platformStyle, 0);
|
rpcConsole = new RPCConsole(platformStyle, 0);
|
||||||
helpMessageDialog = new HelpMessageDialog(this, false);
|
helpMessageDialog = new HelpMessageDialog(this, false);
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
@@ -244,7 +228,7 @@ BitcoinGUI::BitcoinGUI(const Config *cfg, const PlatformStyle *platformStyle, co
|
|||||||
|
|
||||||
// Override style sheet for progress bar for styles that have a segmented progress bar,
|
// Override style sheet for progress bar for styles that have a segmented progress bar,
|
||||||
// as they make the text unreadable (workaround for issue #1071)
|
// as they make the text unreadable (workaround for issue #1071)
|
||||||
// See https://qt-project.org/doc/qt-4.8/gallery.html
|
// See https://doc.qt.io/qt-5/gallery.html
|
||||||
QString curStyle = QApplication::style()->metaObject()->className();
|
QString curStyle = QApplication::style()->metaObject()->className();
|
||||||
if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
|
if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
|
||||||
{
|
{
|
||||||
@@ -609,7 +593,7 @@ void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
|
|||||||
void BitcoinGUI::createTrayIconMenu()
|
void BitcoinGUI::createTrayIconMenu()
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
// return if trayIcon is unset (only on non-Mac OSes)
|
// return if trayIcon is unset (only on non-macOSes)
|
||||||
if (!trayIcon)
|
if (!trayIcon)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -619,10 +603,12 @@ void BitcoinGUI::createTrayIconMenu()
|
|||||||
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||||
this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
|
this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
|
||||||
#else
|
#else
|
||||||
// Note: On Mac, the dock icon is used to provide the tray's functionality.
|
// Note: On macOS, the Dock icon is used to provide the tray's functionality.
|
||||||
MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
|
MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
|
||||||
dockIconHandler->setMainWindow((QMainWindow *)this);
|
connect(dockIconHandler, &MacDockIconHandler::dockIconClicked, this, &BitcoinGUI::macosDockIconActivated);
|
||||||
trayIconMenu = dockIconHandler->dockMenu();
|
|
||||||
|
trayIconMenu = new QMenu(this);
|
||||||
|
trayIconMenu->setAsDockMenu();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Configuration of the tray icon (or dock icon) icon menu
|
// Configuration of the tray icon (or dock icon) icon menu
|
||||||
@@ -636,7 +622,7 @@ void BitcoinGUI::createTrayIconMenu()
|
|||||||
trayIconMenu->addSeparator();
|
trayIconMenu->addSeparator();
|
||||||
trayIconMenu->addAction(optionsAction);
|
trayIconMenu->addAction(optionsAction);
|
||||||
trayIconMenu->addAction(openRPCConsoleAction);
|
trayIconMenu->addAction(openRPCConsoleAction);
|
||||||
#ifndef Q_OS_MAC // This is built-in on Mac
|
#ifndef Q_OS_MAC // This is built-in on macOS
|
||||||
trayIconMenu->addSeparator();
|
trayIconMenu->addSeparator();
|
||||||
trayIconMenu->addAction(quitAction);
|
trayIconMenu->addAction(quitAction);
|
||||||
#endif
|
#endif
|
||||||
@@ -651,6 +637,12 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
|||||||
toggleHidden();
|
toggleHidden();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void BitcoinGUI::macosDockIconActivated()
|
||||||
|
{
|
||||||
|
show();
|
||||||
|
activateWindow();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void BitcoinGUI::optionsClicked()
|
void BitcoinGUI::optionsClicked()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -6,10 +6,10 @@
|
|||||||
#define BITCOIN_QT_BITCOINGUI_H
|
#define BITCOIN_QT_BITCOINGUI_H
|
||||||
|
|
||||||
#if defined(HAVE_CONFIG_H)
|
#if defined(HAVE_CONFIG_H)
|
||||||
#include "config/bitcoin-config.h"
|
#include <config/bitcoin-config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "amount.h"
|
#include <amount.h>
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class ClientModel;
|
class ClientModel;
|
||||||
class NetworkStyle;
|
class NetworkStyle;
|
||||||
class Notificator;
|
class Notificator;
|
||||||
@@ -36,6 +38,7 @@ class CWallet;
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
class QAction;
|
||||||
|
class QComboBox;
|
||||||
class QProgressBar;
|
class QProgressBar;
|
||||||
class QProgressDialog;
|
class QProgressDialog;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
@@ -228,6 +231,9 @@ private Q_SLOTS:
|
|||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
/** Handle tray icon clicked */
|
/** Handle tray icon clicked */
|
||||||
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
|
#else
|
||||||
|
/** Handle macOS Dock icon clicked */
|
||||||
|
void macosDockIconActivated();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */
|
/** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ static boost::filesystem::detail::utf8_codecvt_facet utf8;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
extern double NSAppKitVersionNumber;
|
extern double NSAppKitVersionNumber;
|
||||||
#if !defined(NSAppKitVersionNumber10_8)
|
#if !defined(NSAppKitVersionNumber10_8)
|
||||||
#define NSAppKitVersionNumber10_8 1187
|
#define NSAppKitVersionNumber10_8 1187
|
||||||
@@ -82,6 +84,7 @@ extern double NSAppKitVersionNumber;
|
|||||||
#if !defined(NSAppKitVersionNumber10_9)
|
#if !defined(NSAppKitVersionNumber10_9)
|
||||||
#define NSAppKitVersionNumber10_9 1265
|
#define NSAppKitVersionNumber10_9 1265
|
||||||
#endif
|
#endif
|
||||||
|
void ForceActivation();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace GUIUtil {
|
namespace GUIUtil {
|
||||||
|
|||||||
@@ -1,44 +1,27 @@
|
|||||||
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#ifndef BITCOIN_QT_MACDOCKICONHANDLER_H
|
#ifndef BITCOIN_QT_MACDOCKICONHANDLER_H
|
||||||
#define BITCOIN_QT_MACDOCKICONHANDLER_H
|
#define BITCOIN_QT_MACDOCKICONHANDLER_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
/** macOS-specific Dock icon handler.
|
||||||
class QIcon;
|
|
||||||
class QMenu;
|
|
||||||
class QWidget;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
/** Macintosh-specific dock icon handler.
|
|
||||||
*/
|
*/
|
||||||
class MacDockIconHandler : public QObject
|
class MacDockIconHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~MacDockIconHandler();
|
|
||||||
|
|
||||||
QMenu *dockMenu();
|
|
||||||
void setIcon(const QIcon &icon);
|
|
||||||
void setMainWindow(QMainWindow *window);
|
|
||||||
static MacDockIconHandler *instance();
|
static MacDockIconHandler *instance();
|
||||||
static void cleanup();
|
static void cleanup();
|
||||||
void handleDockIconClickEvent();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void dockIconClicked();
|
void dockIconClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MacDockIconHandler();
|
MacDockIconHandler();
|
||||||
|
|
||||||
QWidget *m_dummyWidget;
|
|
||||||
QMenu *m_dockMenu;
|
|
||||||
QMainWindow *mainWindow;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_QT_MACDOCKICONHANDLER_H
|
#endif // BITCOIN_QT_MACDOCKICONHANDLER_H
|
||||||
|
|||||||
@@ -1,113 +1,33 @@
|
|||||||
// Copyright (c) 2011-2013 The Bitcoin Core developers
|
// Copyright (c) 2011-2019 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include "macdockiconhandler.h"
|
#include "macdockiconhandler.h"
|
||||||
|
|
||||||
#include <QImageWriter>
|
#include <AppKit/AppKit.h>
|
||||||
#include <QMenu>
|
#include <objc/runtime.h>
|
||||||
#include <QBuffer>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
#undef slots
|
static MacDockIconHandler *s_instance = nullptr;
|
||||||
#include <Cocoa/Cocoa.h>
|
|
||||||
#include <objc/objc.h>
|
|
||||||
#include <objc/message.h>
|
|
||||||
|
|
||||||
#if QT_VERSION < 0x050000
|
bool dockClickHandler(id self, SEL _cmd, ...) {
|
||||||
extern void qt_mac_set_dock_menu(QMenu *);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static MacDockIconHandler *s_instance = NULL;
|
|
||||||
|
|
||||||
bool dockClickHandler(id self,SEL _cmd,...) {
|
|
||||||
Q_UNUSED(self)
|
Q_UNUSED(self)
|
||||||
Q_UNUSED(_cmd)
|
Q_UNUSED(_cmd)
|
||||||
|
|
||||||
s_instance->handleDockIconClickEvent();
|
Q_EMIT s_instance->dockIconClicked();
|
||||||
|
|
||||||
// Return NO (false) to suppress the default OS X actions
|
// Return NO (false) to suppress the default macOS actions
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupDockClickHandler() {
|
void setupDockClickHandler() {
|
||||||
Class cls = objc_getClass("NSApplication");
|
Class delClass = (Class)[[[NSApplication sharedApplication] delegate] class];
|
||||||
id appInst = objc_msgSend((id)cls, sel_registerName("sharedApplication"));
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
|
||||||
|
class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
|
||||||
if (appInst != NULL) {
|
|
||||||
id delegate = objc_msgSend(appInst, sel_registerName("delegate"));
|
|
||||||
Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class"));
|
|
||||||
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
|
|
||||||
if (class_getInstanceMethod(delClass, shouldHandle))
|
|
||||||
class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
|
|
||||||
else
|
|
||||||
class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,"B@:");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MacDockIconHandler::MacDockIconHandler() : QObject()
|
MacDockIconHandler::MacDockIconHandler() : QObject()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
|
|
||||||
setupDockClickHandler();
|
setupDockClickHandler();
|
||||||
this->m_dummyWidget = new QWidget();
|
|
||||||
this->m_dockMenu = new QMenu(this->m_dummyWidget);
|
|
||||||
this->setMainWindow(NULL);
|
|
||||||
#if QT_VERSION < 0x050000
|
|
||||||
qt_mac_set_dock_menu(this->m_dockMenu);
|
|
||||||
#elif QT_VERSION >= 0x050200
|
|
||||||
this->m_dockMenu->setAsDockMenu();
|
|
||||||
#endif
|
|
||||||
[pool release];
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacDockIconHandler::setMainWindow(QMainWindow *window) {
|
|
||||||
this->mainWindow = window;
|
|
||||||
}
|
|
||||||
|
|
||||||
MacDockIconHandler::~MacDockIconHandler()
|
|
||||||
{
|
|
||||||
delete this->m_dummyWidget;
|
|
||||||
this->setMainWindow(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
QMenu *MacDockIconHandler::dockMenu()
|
|
||||||
{
|
|
||||||
return this->m_dockMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacDockIconHandler::setIcon(const QIcon &icon)
|
|
||||||
{
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
NSImage *image = nil;
|
|
||||||
if (icon.isNull())
|
|
||||||
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
|
|
||||||
else {
|
|
||||||
// generate NSImage from QIcon and use this as dock icon.
|
|
||||||
QSize size = icon.actualSize(QSize(128, 128));
|
|
||||||
QPixmap pixmap = icon.pixmap(size);
|
|
||||||
|
|
||||||
// Write image into a R/W buffer from raw pixmap, then save the image.
|
|
||||||
QBuffer notificationBuffer;
|
|
||||||
if (!pixmap.isNull() && notificationBuffer.open(QIODevice::ReadWrite)) {
|
|
||||||
QImageWriter writer(¬ificationBuffer, "PNG");
|
|
||||||
if (writer.write(pixmap.toImage())) {
|
|
||||||
NSData* macImgData = [NSData dataWithBytes:notificationBuffer.buffer().data()
|
|
||||||
length:notificationBuffer.buffer().size()];
|
|
||||||
image = [[NSImage alloc] initWithData:macImgData];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!image) {
|
|
||||||
// if testnet image could not be created, load std. app icon
|
|
||||||
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[NSApp setApplicationIconImage:image];
|
|
||||||
[image release];
|
|
||||||
[pool release];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MacDockIconHandler *MacDockIconHandler::instance()
|
MacDockIconHandler *MacDockIconHandler::instance()
|
||||||
@@ -122,13 +42,12 @@ void MacDockIconHandler::cleanup()
|
|||||||
delete s_instance;
|
delete s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacDockIconHandler::handleDockIconClickEvent()
|
/**
|
||||||
|
* Force application activation on macOS. With Qt 5.5.1 this is required when
|
||||||
|
* an action in the Dock menu is triggered.
|
||||||
|
* TODO: Define a Qt version where it's no-longer necessary.
|
||||||
|
*/
|
||||||
|
void ForceActivation()
|
||||||
{
|
{
|
||||||
if (this->mainWindow)
|
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||||
{
|
|
||||||
this->mainWindow->activateWindow();
|
|
||||||
this->mainWindow->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT this->dockIconClicked();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2011-2014 The Bitcoin Core developers
|
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -7,22 +7,19 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
/** Macintosh-specific notification handler (supports UserNotificationCenter and Growl).
|
/** Macintosh-specific notification handler (supports UserNotificationCenter).
|
||||||
*/
|
*/
|
||||||
class MacNotificationHandler : public QObject
|
class MacNotificationHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** shows a 10.8+ UserNotification in the UserNotificationCenter
|
/** shows a macOS 10.8+ UserNotification in the UserNotificationCenter
|
||||||
*/
|
*/
|
||||||
void showNotification(const QString &title, const QString &text);
|
void showNotification(const QString &title, const QString &text);
|
||||||
|
|
||||||
/** executes AppleScript */
|
|
||||||
void sendAppleScript(const QString &script);
|
|
||||||
|
|
||||||
/** check if OS can handle UserNotifications */
|
/** check if OS can handle UserNotifications */
|
||||||
bool hasUserNotificationCenterSupport(void);
|
bool hasUserNotificationCenterSupport();
|
||||||
static MacNotificationHandler *instance();
|
static MacNotificationHandler *instance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2011-2013 The Bitcoin Core developers
|
// Copyright (c) 2011-2020 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -24,43 +24,14 @@ void MacNotificationHandler::showNotification(const QString &title, const QStrin
|
|||||||
{
|
{
|
||||||
// check if users OS has support for NSUserNotification
|
// check if users OS has support for NSUserNotification
|
||||||
if(this->hasUserNotificationCenterSupport()) {
|
if(this->hasUserNotificationCenterSupport()) {
|
||||||
// okay, seems like 10.8+
|
NSUserNotification* userNotification = [[NSUserNotification alloc] init];
|
||||||
QByteArray utf8 = title.toUtf8();
|
userNotification.title = title.toNSString();
|
||||||
char* cString = (char *)utf8.constData();
|
userNotification.informativeText = text.toNSString();
|
||||||
NSString *titleMac = [[NSString alloc] initWithUTF8String:cString];
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: userNotification];
|
||||||
|
|
||||||
utf8 = text.toUtf8();
|
|
||||||
cString = (char *)utf8.constData();
|
|
||||||
NSString *textMac = [[NSString alloc] initWithUTF8String:cString];
|
|
||||||
|
|
||||||
// do everything weak linked (because we will keep <10.8 compatibility)
|
|
||||||
id userNotification = [[NSClassFromString(@"NSUserNotification") alloc] init];
|
|
||||||
[userNotification performSelector:@selector(setTitle:) withObject:titleMac];
|
|
||||||
[userNotification performSelector:@selector(setInformativeText:) withObject:textMac];
|
|
||||||
|
|
||||||
id notificationCenterInstance = [NSClassFromString(@"NSUserNotificationCenter") performSelector:@selector(defaultUserNotificationCenter)];
|
|
||||||
[notificationCenterInstance performSelector:@selector(deliverNotification:) withObject:userNotification];
|
|
||||||
|
|
||||||
[titleMac release];
|
|
||||||
[textMac release];
|
|
||||||
[userNotification release];
|
[userNotification release];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendAppleScript just take a QString and executes it as apple script
|
|
||||||
void MacNotificationHandler::sendAppleScript(const QString &script)
|
|
||||||
{
|
|
||||||
QByteArray utf8 = script.toUtf8();
|
|
||||||
char* cString = (char *)utf8.constData();
|
|
||||||
NSString *scriptApple = [[NSString alloc] initWithUTF8String:cString];
|
|
||||||
|
|
||||||
NSAppleScript *as = [[NSAppleScript alloc] initWithSource:scriptApple];
|
|
||||||
NSDictionary *err = nil;
|
|
||||||
[as executeAndReturnError:&err];
|
|
||||||
[as release];
|
|
||||||
[scriptApple release];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MacNotificationHandler::hasUserNotificationCenterSupport(void)
|
bool MacNotificationHandler::hasUserNotificationCenterSupport(void)
|
||||||
{
|
{
|
||||||
Class possibleClass = NSClassFromString(@"NSUserNotificationCenter");
|
Class possibleClass = NSClassFromString(@"NSUserNotificationCenter");
|
||||||
@@ -75,10 +46,10 @@ bool MacNotificationHandler::hasUserNotificationCenterSupport(void)
|
|||||||
|
|
||||||
MacNotificationHandler *MacNotificationHandler::instance()
|
MacNotificationHandler *MacNotificationHandler::instance()
|
||||||
{
|
{
|
||||||
static MacNotificationHandler *s_instance = NULL;
|
static MacNotificationHandler *s_instance = nullptr;
|
||||||
if (!s_instance) {
|
if (!s_instance) {
|
||||||
s_instance = new MacNotificationHandler();
|
s_instance = new MacNotificationHandler();
|
||||||
|
|
||||||
Class aPossibleClass = objc_getClass("NSBundle");
|
Class aPossibleClass = objc_getClass("NSBundle");
|
||||||
if (aPossibleClass) {
|
if (aPossibleClass) {
|
||||||
// change NSBundle -bundleIdentifier method to return a correct bundle identifier
|
// change NSBundle -bundleIdentifier method to return a correct bundle identifier
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
// Copyright (c) 2011-2014 The Bitcoin Core developers
|
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include "notificator.h"
|
#include <qt/notificator.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QIcon>
|
|
||||||
#include <QImageWriter>
|
#include <QImageWriter>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
@@ -24,7 +23,7 @@
|
|||||||
// #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
|
// #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
#include "macnotificationhandler.h"
|
#include <qt/macnotificationhandler.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -33,17 +32,17 @@
|
|||||||
const int FREEDESKTOP_NOTIFICATION_ICON_SIZE = 128;
|
const int FREEDESKTOP_NOTIFICATION_ICON_SIZE = 128;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon, QWidget *parent) :
|
Notificator::Notificator(const QString &_programName, QSystemTrayIcon *_trayIcon, QWidget *_parent) :
|
||||||
QObject(parent),
|
QObject(_parent),
|
||||||
parent(parent),
|
parent(_parent),
|
||||||
programName(programName),
|
programName(_programName),
|
||||||
mode(None),
|
mode(None),
|
||||||
trayIcon(trayicon)
|
trayIcon(_trayIcon)
|
||||||
#ifdef USE_DBUS
|
#ifdef USE_DBUS
|
||||||
,interface(0)
|
,interface(0)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if(trayicon && trayicon->supportsMessages())
|
if(_trayIcon && _trayIcon->supportsMessages())
|
||||||
{
|
{
|
||||||
mode = QSystemTray;
|
mode = QSystemTray;
|
||||||
}
|
}
|
||||||
@@ -60,22 +59,6 @@ Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon,
|
|||||||
if( MacNotificationHandler::instance()->hasUserNotificationCenterSupport()) {
|
if( MacNotificationHandler::instance()->hasUserNotificationCenterSupport()) {
|
||||||
mode = UserNotificationCenter;
|
mode = UserNotificationCenter;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// Check if Growl is installed (based on Qt's tray icon implementation)
|
|
||||||
CFURLRef cfurl;
|
|
||||||
OSStatus status = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, CFSTR("growlTicket"), kLSRolesAll, 0, &cfurl);
|
|
||||||
if (status != kLSApplicationNotFoundErr) {
|
|
||||||
CFBundleRef bundle = CFBundleCreate(0, cfurl);
|
|
||||||
if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR("com.Growl.GrowlHelperApp"), kCFCompareCaseInsensitive | kCFCompareBackwards) == kCFCompareEqualTo) {
|
|
||||||
if (CFStringHasSuffix(CFURLGetString(cfurl), CFSTR("/Growl.app/")))
|
|
||||||
mode = Growl13;
|
|
||||||
else
|
|
||||||
mode = Growl12;
|
|
||||||
}
|
|
||||||
CFRelease(cfurl);
|
|
||||||
CFRelease(bundle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +76,7 @@ class FreedesktopImage
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FreedesktopImage() {}
|
FreedesktopImage() {}
|
||||||
FreedesktopImage(const QImage &img);
|
explicit FreedesktopImage(const QImage &img);
|
||||||
|
|
||||||
static int metaType();
|
static int metaType();
|
||||||
|
|
||||||
@@ -241,52 +224,6 @@ void Notificator::notifySystray(Class cls, const QString &title, const QString &
|
|||||||
|
|
||||||
// Based on Qt's tray icon implementation
|
// Based on Qt's tray icon implementation
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
void Notificator::notifyGrowl(Class cls, const QString &title, const QString &text, const QIcon &icon)
|
|
||||||
{
|
|
||||||
const QString script(
|
|
||||||
"tell application \"%5\"\n"
|
|
||||||
" set the allNotificationsList to {\"Notification\"}\n" // -- Make a list of all the notification types (all)
|
|
||||||
" set the enabledNotificationsList to {\"Notification\"}\n" // -- Make a list of the notifications (enabled)
|
|
||||||
" register as application \"%1\" all notifications allNotificationsList default notifications enabledNotificationsList\n" // -- Register our script with Growl
|
|
||||||
" notify with name \"Notification\" title \"%2\" description \"%3\" application name \"%1\"%4\n" // -- Send a Notification
|
|
||||||
"end tell"
|
|
||||||
);
|
|
||||||
|
|
||||||
QString notificationApp(QApplication::applicationName());
|
|
||||||
if (notificationApp.isEmpty())
|
|
||||||
notificationApp = "Application";
|
|
||||||
|
|
||||||
QPixmap notificationIconPixmap;
|
|
||||||
if (icon.isNull()) { // If no icon specified, set icon based on class
|
|
||||||
QStyle::StandardPixmap sicon = QStyle::SP_MessageBoxQuestion;
|
|
||||||
switch (cls)
|
|
||||||
{
|
|
||||||
case Information: sicon = QStyle::SP_MessageBoxInformation; break;
|
|
||||||
case Warning: sicon = QStyle::SP_MessageBoxWarning; break;
|
|
||||||
case Critical: sicon = QStyle::SP_MessageBoxCritical; break;
|
|
||||||
}
|
|
||||||
notificationIconPixmap = QApplication::style()->standardPixmap(sicon);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QSize size = icon.actualSize(QSize(48, 48));
|
|
||||||
notificationIconPixmap = icon.pixmap(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString notificationIcon;
|
|
||||||
QTemporaryFile notificationIconFile;
|
|
||||||
if (!notificationIconPixmap.isNull() && notificationIconFile.open()) {
|
|
||||||
QImageWriter writer(¬ificationIconFile, "PNG");
|
|
||||||
if (writer.write(notificationIconPixmap.toImage()))
|
|
||||||
notificationIcon = QString(" image from location \"file://%1\"").arg(notificationIconFile.fileName());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString quotedTitle(title), quotedText(text);
|
|
||||||
quotedTitle.replace("\\", "\\\\").replace("\"", "\\");
|
|
||||||
quotedText.replace("\\", "\\\\").replace("\"", "\\");
|
|
||||||
QString growlApp(this->mode == Notificator::Growl13 ? "Growl" : "GrowlHelperApp");
|
|
||||||
MacNotificationHandler::instance()->sendAppleScript(script.arg(notificationApp, quotedTitle, quotedText, notificationIcon, growlApp));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Notificator::notifyMacUserNotificationCenter(Class cls, const QString &title, const QString &text, const QIcon &icon) {
|
void Notificator::notifyMacUserNotificationCenter(Class cls, const QString &title, const QString &text, const QIcon &icon) {
|
||||||
// icon is not supported by the user notification center yet. OSX will use the app icon.
|
// icon is not supported by the user notification center yet. OSX will use the app icon.
|
||||||
MacNotificationHandler::instance()->showNotification(title, text);
|
MacNotificationHandler::instance()->showNotification(title, text);
|
||||||
@@ -310,10 +247,6 @@ void Notificator::notify(Class cls, const QString &title, const QString &text, c
|
|||||||
case UserNotificationCenter:
|
case UserNotificationCenter:
|
||||||
notifyMacUserNotificationCenter(cls, title, text, icon);
|
notifyMacUserNotificationCenter(cls, title, text, icon);
|
||||||
break;
|
break;
|
||||||
case Growl12:
|
|
||||||
case Growl13:
|
|
||||||
notifyGrowl(cls, title, text, icon);
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
if(cls == Critical)
|
if(cls == Critical)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#define BITCOIN_QT_NOTIFICATOR_H
|
#define BITCOIN_QT_NOTIFICATOR_H
|
||||||
|
|
||||||
#if defined(HAVE_CONFIG_H)
|
#if defined(HAVE_CONFIG_H)
|
||||||
#include "config/bitcoin-config.h"
|
#include <config/bitcoin-config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
@@ -58,8 +58,6 @@ private:
|
|||||||
None, /**< Ignore informational notifications, and show a modal pop-up dialog for Critical notifications. */
|
None, /**< Ignore informational notifications, and show a modal pop-up dialog for Critical notifications. */
|
||||||
Freedesktop, /**< Use DBus org.freedesktop.Notifications */
|
Freedesktop, /**< Use DBus org.freedesktop.Notifications */
|
||||||
QSystemTray, /**< Use QSystemTray::showMessage */
|
QSystemTray, /**< Use QSystemTray::showMessage */
|
||||||
Growl12, /**< Use the Growl 1.2 notification system (Mac only) */
|
|
||||||
Growl13, /**< Use the Growl 1.3 notification system (Mac only) */
|
|
||||||
UserNotificationCenter /**< Use the 10.8+ User Notification Center (Mac only) */
|
UserNotificationCenter /**< Use the 10.8+ User Notification Center (Mac only) */
|
||||||
};
|
};
|
||||||
QString programName;
|
QString programName;
|
||||||
@@ -72,7 +70,6 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
void notifySystray(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
|
void notifySystray(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
void notifyGrowl(Class cls, const QString &title, const QString &text, const QIcon &icon);
|
|
||||||
void notifyMacUserNotificationCenter(Class cls, const QString &title, const QString &text, const QIcon &icon);
|
void notifyMacUserNotificationCenter(Class cls, const QString &title, const QString &text, const QIcon &icon);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user