solve MacOS Catalina compile
This commit is contained in:
@@ -393,7 +393,7 @@ case $host in
|
||||
fi
|
||||
|
||||
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"
|
||||
;;
|
||||
*linux*)
|
||||
|
||||
@@ -23,7 +23,7 @@ class GlobalConfig final : public Config
|
||||
{
|
||||
public:
|
||||
GlobalConfig();
|
||||
const CChainParams &GetChainParams() const;
|
||||
const CChainParams &GetChainParams() const override;
|
||||
void SetCashAddrEncoding(bool) override;
|
||||
bool UseCashAddrEncoding() const override;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QDateTime>
|
||||
#include <QDesktopWidget>
|
||||
#include <QDragEnterEvent>
|
||||
@@ -47,7 +48,6 @@
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QMimeData>
|
||||
#include <QProgressBar>
|
||||
#include <QProgressDialog>
|
||||
#include <QSettings>
|
||||
#include <QShortcut>
|
||||
@@ -56,14 +56,8 @@
|
||||
#include <QStyle>
|
||||
#include <QTimer>
|
||||
#include <QToolBar>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <QTextDocument>
|
||||
#include <QUrl>
|
||||
#else
|
||||
#include <QUrlQuery>
|
||||
#endif
|
||||
#include <QVBoxLayout>
|
||||
|
||||
const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
|
||||
#if defined(Q_OS_MAC)
|
||||
@@ -143,20 +137,10 @@ BitcoinGUI::BitcoinGUI(const Config *cfg, const PlatformStyle *platformStyle, co
|
||||
windowTitle += tr("Node");
|
||||
}
|
||||
windowTitle += " " + networkStyle->getTitleAddText();
|
||||
#ifndef Q_OS_MAC
|
||||
QApplication::setWindowIcon(networkStyle->getTrayAndWindowIcon());
|
||||
setWindowIcon(networkStyle->getTrayAndWindowIcon());
|
||||
#else
|
||||
MacDockIconHandler::instance()->setIcon(networkStyle->getAppIcon());
|
||||
#endif
|
||||
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);
|
||||
helpMessageDialog = new HelpMessageDialog(this, false);
|
||||
#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,
|
||||
// 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();
|
||||
if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
|
||||
{
|
||||
@@ -609,7 +593,7 @@ void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
|
||||
void BitcoinGUI::createTrayIconMenu()
|
||||
{
|
||||
#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)
|
||||
return;
|
||||
|
||||
@@ -619,10 +603,12 @@ 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.
|
||||
// Note: On macOS, the Dock icon is used to provide the tray's functionality.
|
||||
MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
|
||||
dockIconHandler->setMainWindow((QMainWindow *)this);
|
||||
trayIconMenu = dockIconHandler->dockMenu();
|
||||
connect(dockIconHandler, &MacDockIconHandler::dockIconClicked, this, &BitcoinGUI::macosDockIconActivated);
|
||||
|
||||
trayIconMenu = new QMenu(this);
|
||||
trayIconMenu->setAsDockMenu();
|
||||
#endif
|
||||
|
||||
// Configuration of the tray icon (or dock icon) icon menu
|
||||
@@ -636,7 +622,7 @@ void BitcoinGUI::createTrayIconMenu()
|
||||
trayIconMenu->addSeparator();
|
||||
trayIconMenu->addAction(optionsAction);
|
||||
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->addAction(quitAction);
|
||||
#endif
|
||||
@@ -651,6 +637,12 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
toggleHidden();
|
||||
}
|
||||
}
|
||||
#else
|
||||
void BitcoinGUI::macosDockIconActivated()
|
||||
{
|
||||
show();
|
||||
activateWindow();
|
||||
}
|
||||
#endif
|
||||
|
||||
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
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
#define BITCOIN_QT_BITCOINGUI_H
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include "config/bitcoin-config.h"
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
|
||||
#include "amount.h"
|
||||
#include <amount.h>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QMainWindow>
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <QPoint>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ClientModel;
|
||||
class NetworkStyle;
|
||||
class Notificator;
|
||||
@@ -36,6 +38,7 @@ class CWallet;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QComboBox;
|
||||
class QProgressBar;
|
||||
class QProgressDialog;
|
||||
QT_END_NAMESPACE
|
||||
@@ -228,6 +231,9 @@ private Q_SLOTS:
|
||||
#ifndef Q_OS_MAC
|
||||
/** Handle tray icon clicked */
|
||||
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
#else
|
||||
/** Handle macOS Dock icon clicked */
|
||||
void macosDockIconActivated();
|
||||
#endif
|
||||
|
||||
/** 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
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
|
||||
#include <QProcess>
|
||||
extern double NSAppKitVersionNumber;
|
||||
#if !defined(NSAppKitVersionNumber10_8)
|
||||
#define NSAppKitVersionNumber10_8 1187
|
||||
@@ -82,6 +84,7 @@ extern double NSAppKitVersionNumber;
|
||||
#if !defined(NSAppKitVersionNumber10_9)
|
||||
#define NSAppKitVersionNumber10_9 1265
|
||||
#endif
|
||||
void ForceActivation();
|
||||
#endif
|
||||
|
||||
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
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_QT_MACDOCKICONHANDLER_H
|
||||
#define BITCOIN_QT_MACDOCKICONHANDLER_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QObject>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QIcon;
|
||||
class QMenu;
|
||||
class QWidget;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
/** Macintosh-specific dock icon handler.
|
||||
/** macOS-specific Dock icon handler.
|
||||
*/
|
||||
class MacDockIconHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
~MacDockIconHandler();
|
||||
|
||||
QMenu *dockMenu();
|
||||
void setIcon(const QIcon &icon);
|
||||
void setMainWindow(QMainWindow *window);
|
||||
static MacDockIconHandler *instance();
|
||||
static void cleanup();
|
||||
void handleDockIconClickEvent();
|
||||
|
||||
Q_SIGNALS:
|
||||
void dockIconClicked();
|
||||
|
||||
private:
|
||||
MacDockIconHandler();
|
||||
|
||||
QWidget *m_dummyWidget;
|
||||
QMenu *m_dockMenu;
|
||||
QMainWindow *mainWindow;
|
||||
};
|
||||
|
||||
#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
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "macdockiconhandler.h"
|
||||
|
||||
#include <QImageWriter>
|
||||
#include <QMenu>
|
||||
#include <QBuffer>
|
||||
#include <QWidget>
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <objc/runtime.h>
|
||||
|
||||
#undef slots
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <objc/objc.h>
|
||||
#include <objc/message.h>
|
||||
static MacDockIconHandler *s_instance = nullptr;
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
extern void qt_mac_set_dock_menu(QMenu *);
|
||||
#endif
|
||||
|
||||
static MacDockIconHandler *s_instance = NULL;
|
||||
|
||||
bool dockClickHandler(id self,SEL _cmd,...) {
|
||||
bool dockClickHandler(id self, SEL _cmd, ...) {
|
||||
Q_UNUSED(self)
|
||||
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;
|
||||
}
|
||||
|
||||
void setupDockClickHandler() {
|
||||
Class cls = objc_getClass("NSApplication");
|
||||
id appInst = objc_msgSend((id)cls, sel_registerName("sharedApplication"));
|
||||
|
||||
if (appInst != NULL) {
|
||||
id delegate = objc_msgSend(appInst, sel_registerName("delegate"));
|
||||
Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class"));
|
||||
Class delClass = (Class)[[[NSApplication sharedApplication] delegate] 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()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
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()
|
||||
@@ -122,13 +42,12 @@ void MacDockIconHandler::cleanup()
|
||||
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)
|
||||
{
|
||||
this->mainWindow->activateWindow();
|
||||
this->mainWindow->show();
|
||||
}
|
||||
|
||||
Q_EMIT this->dockIconClicked();
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
@@ -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
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -7,22 +7,19 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
/** Macintosh-specific notification handler (supports UserNotificationCenter and Growl).
|
||||
/** Macintosh-specific notification handler (supports UserNotificationCenter).
|
||||
*/
|
||||
class MacNotificationHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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);
|
||||
|
||||
/** executes AppleScript */
|
||||
void sendAppleScript(const QString &script);
|
||||
|
||||
/** check if OS can handle UserNotifications */
|
||||
bool hasUserNotificationCenterSupport(void);
|
||||
bool hasUserNotificationCenterSupport();
|
||||
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
|
||||
// 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
|
||||
if(this->hasUserNotificationCenterSupport()) {
|
||||
// okay, seems like 10.8+
|
||||
QByteArray utf8 = title.toUtf8();
|
||||
char* cString = (char *)utf8.constData();
|
||||
NSString *titleMac = [[NSString alloc] initWithUTF8String:cString];
|
||||
|
||||
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];
|
||||
NSUserNotification* userNotification = [[NSUserNotification alloc] init];
|
||||
userNotification.title = title.toNSString();
|
||||
userNotification.informativeText = text.toNSString();
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: userNotification];
|
||||
[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)
|
||||
{
|
||||
Class possibleClass = NSClassFromString(@"NSUserNotificationCenter");
|
||||
@@ -75,7 +46,7 @@ bool MacNotificationHandler::hasUserNotificationCenterSupport(void)
|
||||
|
||||
MacNotificationHandler *MacNotificationHandler::instance()
|
||||
{
|
||||
static MacNotificationHandler *s_instance = NULL;
|
||||
static MacNotificationHandler *s_instance = nullptr;
|
||||
if (!s_instance) {
|
||||
s_instance = new MacNotificationHandler();
|
||||
|
||||
|
||||
@@ -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
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "notificator.h"
|
||||
#include <qt/notificator.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QByteArray>
|
||||
#include <QIcon>
|
||||
#include <QImageWriter>
|
||||
#include <QMessageBox>
|
||||
#include <QMetaType>
|
||||
@@ -24,7 +23,7 @@
|
||||
// #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
|
||||
#ifdef Q_OS_MAC
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include "macnotificationhandler.h"
|
||||
#include <qt/macnotificationhandler.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -33,17 +32,17 @@
|
||||
const int FREEDESKTOP_NOTIFICATION_ICON_SIZE = 128;
|
||||
#endif
|
||||
|
||||
Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon, QWidget *parent) :
|
||||
QObject(parent),
|
||||
parent(parent),
|
||||
programName(programName),
|
||||
Notificator::Notificator(const QString &_programName, QSystemTrayIcon *_trayIcon, QWidget *_parent) :
|
||||
QObject(_parent),
|
||||
parent(_parent),
|
||||
programName(_programName),
|
||||
mode(None),
|
||||
trayIcon(trayicon)
|
||||
trayIcon(_trayIcon)
|
||||
#ifdef USE_DBUS
|
||||
,interface(0)
|
||||
#endif
|
||||
{
|
||||
if(trayicon && trayicon->supportsMessages())
|
||||
if(_trayIcon && _trayIcon->supportsMessages())
|
||||
{
|
||||
mode = QSystemTray;
|
||||
}
|
||||
@@ -60,22 +59,6 @@ Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon,
|
||||
if( MacNotificationHandler::instance()->hasUserNotificationCenterSupport()) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -93,7 +76,7 @@ class FreedesktopImage
|
||||
{
|
||||
public:
|
||||
FreedesktopImage() {}
|
||||
FreedesktopImage(const QImage &img);
|
||||
explicit FreedesktopImage(const QImage &img);
|
||||
|
||||
static int metaType();
|
||||
|
||||
@@ -241,52 +224,6 @@ void Notificator::notifySystray(Class cls, const QString &title, const QString &
|
||||
|
||||
// Based on Qt's tray icon implementation
|
||||
#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) {
|
||||
// icon is not supported by the user notification center yet. OSX will use the app icon.
|
||||
MacNotificationHandler::instance()->showNotification(title, text);
|
||||
@@ -310,10 +247,6 @@ void Notificator::notify(Class cls, const QString &title, const QString &text, c
|
||||
case UserNotificationCenter:
|
||||
notifyMacUserNotificationCenter(cls, title, text, icon);
|
||||
break;
|
||||
case Growl12:
|
||||
case Growl13:
|
||||
notifyGrowl(cls, title, text, icon);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
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
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define BITCOIN_QT_NOTIFICATOR_H
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include "config/bitcoin-config.h"
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
|
||||
#include <QIcon>
|
||||
@@ -58,8 +58,6 @@ private:
|
||||
None, /**< Ignore informational notifications, and show a modal pop-up dialog for Critical notifications. */
|
||||
Freedesktop, /**< Use DBus org.freedesktop.Notifications */
|
||||
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) */
|
||||
};
|
||||
QString programName;
|
||||
@@ -72,7 +70,6 @@ private:
|
||||
#endif
|
||||
void notifySystray(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
|
||||
#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);
|
||||
#endif
|
||||
};
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user