update to 0.4 preview
[novacoin.git] / src / qt / notificator.cpp
index a2314ca..8028190 100644 (file)
@@ -16,7 +16,7 @@
 #include <stdint.h>
 #endif
 
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
 #include <ApplicationServices/ApplicationServices.h>
 extern bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret);
 #endif
@@ -46,16 +46,19 @@ Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon,
         mode = Freedesktop;
     }
 #endif
-#ifdef Q_WS_MAC
+#ifdef Q_OS_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;
+            if (CFStringHasSuffix(CFURLGetString(cfurl), CFSTR("/Growl.app/")))
+                mode = Growl13;
+            else
+                mode = Growl12;
         }
+        CFRelease(cfurl);
         CFRelease(bundle);
     }
 #endif
@@ -79,7 +82,7 @@ public:
 
     static int metaType();
 
-    // Image to variant that can be marshaled over DBus
+    // Image to variant that can be marshalled over DBus
     static QVariant toVariant(const QImage &img);
 
 private:
@@ -222,11 +225,11 @@ void Notificator::notifySystray(Class cls, const QString &title, const QString &
 }
 
 // Based on Qt's tray icon implementation
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
 void Notificator::notifyGrowl(Class cls, const QString &title, const QString &text, const QIcon &icon)
 {
     const QString script(
-        "tell application \"GrowlHelperApp\"\n"
+        "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
@@ -265,7 +268,8 @@ void Notificator::notifyGrowl(Class cls, const QString &title, const QString &te
     QString quotedTitle(title), quotedText(text);
     quotedTitle.replace("\\", "\\\\").replace("\"", "\\");
     quotedText.replace("\\", "\\\\").replace("\"", "\\");
-    qt_mac_execute_apple_script(script.arg(notificationApp, quotedTitle, quotedText, notificationIcon), 0);
+    QString growlApp(this->mode == Notificator::Growl13 ? "Growl" : "GrowlHelperApp");
+    qt_mac_execute_apple_script(script.arg(notificationApp, quotedTitle, quotedText, notificationIcon, growlApp), 0);
 }
 #endif
 
@@ -281,15 +285,16 @@ 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:
+#ifdef Q_OS_MAC
+    case Growl12:
+    case Growl13:
         notifyGrowl(cls, title, text, icon);
         break;
 #endif
     default:
         if(cls == Critical)
         {
-            // Fall back to old fashioned popup dialog if critical and no other notification available
+            // Fall back to old fashioned pop-up dialog if critical and no other notification available
             QMessageBox::critical(parent, title, text, QMessageBox::Ok, QMessageBox::Ok);
         }
         break;