Skip to content

Commit e7b88ec

Browse files
committed
Merge #14975: qt: Refactoring with QString::toNSString()
4d454dc Refactoring with QString::toNSString (Hennadii Stepanov) Pull request description: This PR makes `MacNotificationHandler::showNotification()` cleaner and more readable. The used `QString::toNSString()` function was introduced in Qt 5.2 which is minimum version now (#14725). The behavior of `MacNotificationHandler::showNotification()` has not been changed. cc: @jonasschnelli Tree-SHA512: 940327a77746ee016415efd3b696ad8ec85dcf12bf3f62e55c9bdc1700415d81a8d03fbc79310982d37a4098786dcaef7cd9702db5498d59d8065447babc27f5
2 parents 27f5a29 + 4d454dc commit e7b88ec

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

src/qt/macnotificationhandler.mm

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,10 @@ - (NSString *)__bundleIdentifier
2424
{
2525
// check if users OS has support for NSUserNotification
2626
if(this->hasUserNotificationCenterSupport()) {
27-
// okay, seems like 10.8+
28-
QByteArray utf8 = title.toUtf8();
29-
char* cString = (char *)utf8.constData();
30-
NSString *titleMac = [[NSString alloc] initWithUTF8String:cString];
31-
32-
utf8 = text.toUtf8();
33-
cString = (char *)utf8.constData();
34-
NSString *textMac = [[NSString alloc] initWithUTF8String:cString];
35-
36-
// do everything weak linked (because we will keep <10.8 compatibility)
37-
id userNotification = [[NSClassFromString(@"NSUserNotification") alloc] init];
38-
[userNotification performSelector:@selector(setTitle:) withObject:titleMac];
39-
[userNotification performSelector:@selector(setInformativeText:) withObject:textMac];
40-
41-
id notificationCenterInstance = [NSClassFromString(@"NSUserNotificationCenter") performSelector:@selector(defaultUserNotificationCenter)];
42-
[notificationCenterInstance performSelector:@selector(deliverNotification:) withObject:userNotification];
43-
44-
[titleMac release];
45-
[textMac release];
27+
NSUserNotification* userNotification = [[NSUserNotification alloc] init];
28+
userNotification.title = title.toNSString();
29+
userNotification.informativeText = text.toNSString();
30+
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: userNotification];
4631
[userNotification release];
4732
}
4833
}

0 commit comments

Comments
 (0)