diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2013-10-31 23:04:32 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-01 22:06:27 +0100 |
commit | 279dd24f0b834b2f5e15aca2fd22bb952df30438 (patch) | |
tree | bd35e6c75696327cd80305b775d733099c648471 /src | |
parent | 36c12107171a57f1483602730fe797e5ed2ea5d6 (diff) |
Add helper functions to set/retrieve the application badge
These helper functions wrapp the necessary objective-c calls to set or
retrieve a text (OS X) or number (iOS) on the application icon, also
known as badge.
Change-Id: I34a82c5abc073b63442e12c49a864e65b5428d83
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/macextras/qmacfunctions.h | 11 | ||||
-rw-r--r-- | src/macextras/qmacfunctions.mm | 1 | ||||
-rw-r--r-- | src/macextras/qmacfunctions_ios.mm | 10 | ||||
-rw-r--r-- | src/macextras/qmacfunctions_mac.mm | 12 |
4 files changed, 32 insertions, 2 deletions
diff --git a/src/macextras/qmacfunctions.h b/src/macextras/qmacfunctions.h index 7ab0cdd..0afeb1c 100644 --- a/src/macextras/qmacfunctions.h +++ b/src/macextras/qmacfunctions.h @@ -74,14 +74,21 @@ Q_MACEXTRAS_EXPORT QPixmap fromCGImageRef(CGImageRef image); Q_MACEXTRAS_EXPORT CGContextRef currentCGContext(); -#ifndef Q_OS_IOS +#ifdef Q_OS_OSX +Q_MACEXTRAS_EXPORT void setBadgeLabelText(const QString &text); +Q_MACEXTRAS_EXPORT QString badgeLabelText(); + Q_MACEXTRAS_EXPORT NSImage *toNSImage(const QPixmap &pixmap); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) Q_MACEXTRAS_EXPORT bool isMainWindow(QWindow *window); #endif +#endif // Q_OS_OSX -#endif +#ifdef Q_OS_IOS +Q_MACEXTRAS_EXPORT void setApplicationIconBadgeNumber(int number); +Q_MACEXTRAS_EXPORT int applicationIconBadgeNumber(); +#endif // Q_OS_IOS } QT_END_NAMESPACE diff --git a/src/macextras/qmacfunctions.mm b/src/macextras/qmacfunctions.mm index 3484bbc..0f81cb2 100644 --- a/src/macextras/qmacfunctions.mm +++ b/src/macextras/qmacfunctions.mm @@ -48,6 +48,7 @@ #include "qmacfunctions_p.h" #import <Foundation/Foundation.h> + #ifdef Q_OS_IOS #import <CoreGraphics/CoreGraphics.h> #endif diff --git a/src/macextras/qmacfunctions_ios.mm b/src/macextras/qmacfunctions_ios.mm index 2508941..ddc6a03 100644 --- a/src/macextras/qmacfunctions_ios.mm +++ b/src/macextras/qmacfunctions_ios.mm @@ -54,6 +54,16 @@ CGContextRef currentCGContext() return UIGraphicsGetCurrentContext(); } +void setApplicationIconBadgeNumber(int number) +{ + [[UIApplication sharedApplication] setApplicationIconBadgeNumber: number]; +} + +int applicationIconBadgeNumber() +{ + return [[UIApplication sharedApplication] applicationIconBadgeNumber]; +} + } // namespace QtMac QT_END_NAMESPACE diff --git a/src/macextras/qmacfunctions_mac.mm b/src/macextras/qmacfunctions_mac.mm index 9209c2f..9901314 100644 --- a/src/macextras/qmacfunctions_mac.mm +++ b/src/macextras/qmacfunctions_mac.mm @@ -40,6 +40,8 @@ ****************************************************************************/ #import <Cocoa/Cocoa.h> +#import <AppKit/NSApplication.h> + #include "qmacfunctions.h" #include "qmacfunctions_p.h" @@ -81,6 +83,16 @@ CGContextRef currentCGContext() return reinterpret_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]); } +void setBadgeLabelText(const QString &text) +{ + [[[NSApplication sharedApplication] dockTile] setBadgeLabel:toNSString(text)]; +} + +QString badgeLabelText() +{ + return fromNSString([[[NSApplication sharedApplication] dockTile] badgeLabel]); +} + } // namespace QtMac QT_END_NAMESPACE |