blob: 1e35b3f98a9386a1424b0cd6e250b945763b3ac3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include <QString>
#import <Foundation/NSString.h>
#import <Foundation/NSUserNotification.h>
#import <dispatch/dispatch.h>
@interface OurDelegate : NSObject <NSUserNotificationCenterDelegate>
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification;
@end
@implementation OurDelegate
// Always show, even if app is active at the moment.
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification
{
Q_UNUSED(center)
Q_UNUSED(notification)
return YES;
}
@end
namespace OCC {
void *createOsXNotificationCenterDelegate()
{
auto delegate = [[OurDelegate alloc] init];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:delegate];
return delegate;
}
void releaseOsXNotificationCenterDelegate(void *delegate)
{
[static_cast<OurDelegate *>(delegate) release];
}
void sendOsXUserNotification(const QString &title, const QString &message)
{
@autoreleasepool {
NSUserNotification *notification = [[[NSUserNotification alloc] init] autorelease];
[notification setTitle:[NSString stringWithUTF8String:title.toUtf8().data()]];
[notification setInformativeText:[NSString stringWithUTF8String:message.toUtf8().data()]];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
}
} // namespace OCC
|