diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 96 |
1 files changed, 15 insertions, 81 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index 0cbdc5d9c8..9a543e893e 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -75,6 +75,9 @@ #define QT_MAC_SYSTEMTRAY_USE_GROWL #include "qcocoasystemtrayicon.h" + +#ifndef QT_NO_SYSTEMTRAYICON + #include <qtemporaryfile.h> #include <qimagewriter.h> #include <qdebug.h> @@ -83,6 +86,7 @@ #include "qt_mac_p.h" #include "qcocoahelpers.h" +#include <QtGui/private/qcoregraphics_p.h> #import <AppKit/AppKit.h> @@ -91,11 +95,8 @@ QT_USE_NAMESPACE @class QT_MANGLE_NAMESPACE(QNSMenu); @class QT_MANGLE_NAMESPACE(QNSImageView); -@interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - <NSUserNotificationCenterDelegate> -#endif - { +@interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject <NSUserNotificationCenterDelegate> +{ @public QCocoaSystemTrayIcon *systray; NSStatusItem *item; @@ -109,11 +110,8 @@ QT_USE_NAMESPACE -(QRectF)geometry; - (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton; - (void)doubleClickSelector:(id)sender; - -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification; - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification; -#endif @end @interface QT_MANGLE_NAMESPACE(QNSImageView) : NSImageView { @@ -142,19 +140,11 @@ class QSystemTrayIconSys public: QSystemTrayIconSys(QCocoaSystemTrayIcon *sys) { item = [[QNSStatusItem alloc] initWithSysTray:sys]; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item]; - } -#endif + [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item]; } ~QSystemTrayIconSys() { [[[item item] view] setHidden: YES]; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil]; - } -#endif + [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil]; [item release]; } QNSStatusItem *item; @@ -296,71 +286,15 @@ bool QCocoaSystemTrayIcon::supportsMessages() const void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &message, const QIcon& icon, MessageIcon, int) { + Q_UNUSED(icon); if (!m_sys) return; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { - NSUserNotification *notification = [[NSUserNotification alloc] init]; - notification.title = [NSString stringWithUTF8String:title.toUtf8().data()]; - notification.informativeText = [NSString stringWithUTF8String:message.toUtf8().data()]; - - [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; + NSUserNotification *notification = [[NSUserNotification alloc] init]; + notification.title = [NSString stringWithUTF8String:title.toUtf8().data()]; + notification.informativeText = [NSString stringWithUTF8String:message.toUtf8().data()]; - return; - } -#endif - -#ifdef QT_MAC_SYSTEMTRAY_USE_GROWL - // Make sure that we have Growl installed on the machine we are running on. - QCFType<CFURLRef> cfurl; - OSStatus status = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, - CFSTR("growlTicket"), kLSRolesAll, 0, &cfurl); - if (status == kLSApplicationNotFoundErr) - return; - QCFType<CFBundleRef> bundle = CFBundleCreate(0, cfurl); - - if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR("com.Growl.GrowlHelperApp"), - kCFCompareCaseInsensitive | kCFCompareBackwards) != kCFCompareEqualTo) - return; - QPixmap notificationIconPixmap = icon.pixmap(32, 32); - QTemporaryFile notificationIconFile; - QString notificationType(QLatin1String("Notification")), notificationIcon, notificationApp(qt_mac_applicationName()); - if (notificationApp.isEmpty()) - notificationApp = QLatin1String("Application"); - if (!notificationIconPixmap.isNull() && notificationIconFile.open()) { - QImageWriter writer(¬ificationIconFile, "PNG"); - if (writer.write(notificationIconPixmap.toImage())) - notificationIcon = QLatin1String("image from location \"file://") + notificationIconFile.fileName() + QLatin1String("\""); - } - const QString script(QLatin1String( - "tell application \"System Events\"\n" - "set isRunning to (count of (every process whose bundle identifier is \"com.Growl.GrowlHelperApp\")) > 0\n" - "end tell\n" - "if isRunning\n" - "tell application id \"com.Growl.GrowlHelperApp\"\n" - "-- Make a list of all the notification types (all)\n" - "set the allNotificationsList to {\"") + notificationType + QLatin1String("\"}\n" - - "-- Make a list of the notifications (enabled)\n" - "set the enabledNotificationsList to {\"") + notificationType + QLatin1String("\"}\n" - - "-- Register our script with growl.\n" - "register as application \"") + notificationApp + QLatin1String("\" all notifications allNotificationsList default notifications enabledNotificationsList\n" - - "-- Send a Notification...\n") + - QLatin1String("notify with name \"") + notificationType + - QLatin1String("\" title \"") + title + - QLatin1String("\" description \"") + message + - QLatin1String("\" application name \"") + notificationApp + - QLatin1String("\" ") + notificationIcon + - QLatin1String("\nend tell\nend if")); - qt_mac_execute_apple_script(script, 0); -#else - Q_UNUSED(icon); - Q_UNUSED(title); - Q_UNUSED(message); -#endif + [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; } QT_END_NAMESPACE @@ -499,7 +433,6 @@ QT_END_NAMESPACE emit systray->activated(QPlatformSystemTrayIcon::DoubleClick); } -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification { Q_UNUSED(center); Q_UNUSED(notification); @@ -511,7 +444,6 @@ QT_END_NAMESPACE Q_UNUSED(notification); emit systray->messageClicked(); } -#endif @end @@ -536,3 +468,5 @@ private: return qmenu; } @end + +#endif // QT_NO_SYSTEMTRAYICON |