aboutsummaryrefslogtreecommitdiff
path: root/src/qt/notificator.cpp
diff options
context:
space:
mode:
authorp2k <patrick.p2k.schneider@gmail.com>2011-10-07 13:21:45 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-10-09 21:19:44 +0200
commit527137e3ee542da5ecd4d04364fac0eb0067a2a4 (patch)
treee3ef2f32ef2d23e8d54175703fa3e36cd3ca0c1a /src/qt/notificator.cpp
parentd934e7e3ddd7d919e58f76705439cdb15c745951 (diff)
downloadbitcoin-527137e3ee542da5ecd4d04364fac0eb0067a2a4.tar.xz
Improved Mac experience; QDoubleSpinBox for BitcoinAmountField
Now it can't be told if this is was a Windows App before. All Mac design principles are fulfilled and some cosmetics have been applied to suit the native look and feel. The biggest change there is the proper use of the Dock icon which takes the role of the Tray icon on Mac. The QDoubleSpinBox improves entering of Bitcoin amounts, no two separate fields are required anymore. All functionality and validation effects have been retained; pressing the comma key will be internally translated to a period to keep it consistent throughout the application and eases entering in countries which use the comma as decimal separator. Additionally, Notificator now supports Growl, Mac's native notification system. This is provided via Apple Script in order to avoid linking to Growl on compile time. Other changes involve encapsulation of Toolbar and Menubar creation, loading of Qt's own translation and some clean up.
Diffstat (limited to 'src/qt/notificator.cpp')
-rw-r--r--src/qt/notificator.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/qt/notificator.cpp b/src/qt/notificator.cpp
index cf0c0a3901..a2314caa47 100644
--- a/src/qt/notificator.cpp
+++ b/src/qt/notificator.cpp
@@ -8,12 +8,19 @@
#include <QByteArray>
#include <QSystemTrayIcon>
#include <QMessageBox>
+#include <QTemporaryFile>
+#include <QImageWriter>
#ifdef USE_DBUS
#include <QtDBus/QtDBus>
#include <stdint.h>
#endif
+#ifdef Q_WS_MAC
+#include <ApplicationServices/ApplicationServices.h>
+extern bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret);
+#endif
+
// https://wiki.ubuntu.com/NotificationDevelopmentGuidelines recommends at least 128
const int FREEDESKTOP_NOTIFICATION_ICON_SIZE = 128;
@@ -39,6 +46,19 @@ Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon,
mode = Freedesktop;
}
#endif
+#ifdef Q_WS_MAC
+ // 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);
+ CFRelease(cfurl);
+ if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR("com.Growl.GrowlHelperApp"), kCFCompareCaseInsensitive | kCFCompareBackwards) == kCFCompareEqualTo) {
+ mode = Growl;
+ }
+ CFRelease(bundle);
+ }
+#endif
}
Notificator::~Notificator()
@@ -201,6 +221,54 @@ void Notificator::notifySystray(Class cls, const QString &title, const QString &
trayIcon->showMessage(title, text, sicon, millisTimeout);
}
+// Based on Qt's tray icon implementation
+#ifdef Q_WS_MAC
+void Notificator::notifyGrowl(Class cls, const QString &title, const QString &text, const QIcon &icon)
+{
+ const QString script(
+ "tell application \"GrowlHelperApp\"\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(&notificationIconFile, "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("\"", "\\");
+ qt_mac_execute_apple_script(script.arg(notificationApp, quotedTitle, quotedText, notificationIcon), 0);
+}
+#endif
+
void Notificator::notify(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout)
{
switch(mode)
@@ -213,6 +281,11 @@ void Notificator::notify(Class cls, const QString &title, const QString &text, c
case QSystemTray:
notifySystray(cls, title, text, icon, millisTimeout);
break;
+#ifdef Q_WS_MAC
+ case Growl:
+ notifyGrowl(cls, title, text, icon);
+ break;
+#endif
default:
if(cls == Critical)
{