Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt: Notificator class refactoring. Notificator always takes 3 args. Remove Growl support. #2352

Merged
merged 3 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ void BitcoinGUI::createTrayIcon()
trayIcon->show();
#endif

notificator = new Notificator(qApp->applicationName(), trayIcon);
notificator = new Notificator(qApp->applicationName(), trayIcon, this);
}

void BitcoinGUI::createTrayIconMenu()
Expand Down
7 changes: 2 additions & 5 deletions src/qt/macnotificationhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@

#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);
static MacNotificationHandler *instance();
Expand Down
14 changes: 0 additions & 14 deletions src/qt/macnotificationhandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@
}
}

// 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");
Expand Down
17 changes: 8 additions & 9 deletions src/qt/notificator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ programName(_programName),
mode(None),
trayIcon(_trayIcon)
#ifdef USE_DBUS
,interface(0)
,interface(nullptr)
#endif
{
if(_trayIcon && _trayIcon->supportsMessages())
Expand Down Expand Up @@ -154,14 +154,14 @@ QVariant FreedesktopImage::toVariant(const QImage &img)

void Notificator::notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout)
{
Q_UNUSED(cls);
// Arguments for DBus call:
// https://developer.gnome.org/notification-spec/
// Arguments for DBus "Notify" call:
QList<QVariant> args;

// Program Name:
args.append(programName);

// Unique ID of this notification type:
// Replaces ID; A value of 0 means that this notification won't replace any existing notifications:
args.append(0U);

// Application Icon, empty string
Expand Down Expand Up @@ -209,9 +209,8 @@ void Notificator::notifyDBus(Class cls, const QString &title, const QString &tex
}
#endif

void Notificator::notifySystray(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout)
void Notificator::notifySystray(Class cls, const QString &title, const QString &text, int millisTimeout)
{
Q_UNUSED(icon);
QSystemTrayIcon::MessageIcon sicon = QSystemTrayIcon::NoIcon;
switch(cls) // Set icon based on class
{
Expand All @@ -224,7 +223,7 @@ void Notificator::notifySystray(Class cls, const QString &title, const QString &

// Based on Qt's tray icon implementation
#ifdef Q_OS_MAC
void Notificator::notifyMacUserNotificationCenter(Class cls, const QString &title, const QString &text, const QIcon &icon) {
void Notificator::notifyMacUserNotificationCenter(const QString &title, const QString &text) {
// icon is not supported by the user notification center yet. OSX will use the app icon.
MacNotificationHandler::instance()->showNotification(title, text);
}
Expand All @@ -241,11 +240,11 @@ void Notificator::notify(Class cls, const QString &title, const QString &text, c
break;
#endif
case QSystemTray:
notifySystray(cls, title, text, icon, millisTimeout);
notifySystray(cls, title, text, millisTimeout);
break;
#ifdef Q_OS_MAC
case UserNotificationCenter:
notifyMacUserNotificationCenter(cls, title, text, icon);
notifyMacUserNotificationCenter(title, text);
break;
#endif
default:
Expand Down
11 changes: 4 additions & 7 deletions src/qt/notificator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Notificator: public QObject
/** Create a new notificator.
@note Ownership of trayIcon is not transferred to this object.
*/
Notificator(const QString &programName=QString(), QSystemTrayIcon *trayIcon=0, QWidget *parent=0);
Notificator(const QString &programName, QSystemTrayIcon *trayIcon, QWidget *parent);
~Notificator();

// Message class
Expand Down Expand Up @@ -48,9 +48,7 @@ public slots:
enum Mode {
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) */
QSystemTray, /**< Use QSystemTrayIcon::showMessage() */
UserNotificationCenter /**< Use the 10.8+ User Notification Center (Mac only) */
};
QString programName;
Expand All @@ -61,10 +59,9 @@ public slots:

void notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
#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, 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);
void notifyMacUserNotificationCenter(const QString &title, const QString &text);
#endif
};

Expand Down