Merge #14975: qt: Refactoring with QString::toNSString()

4d454dcb6 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
This commit is contained in:
Jonas Schnelli 2018-12-17 19:53:25 -10:00
commit e7b88ecbc9
No known key found for this signature in database
GPG key ID: 1EB776BB03C7922D

View file

@ -24,25 +24,10 @@ void MacNotificationHandler::showNotification(const QString &title, const QStrin
{
// check if users OS has support for NSUserNotification
if(this->hasUserNotificationCenterSupport()) {
// okay, seems like 10.8+
QByteArray utf8 = title.toUtf8();
char* cString = (char *)utf8.constData();
NSString *titleMac = [[NSString alloc] initWithUTF8String:cString];
utf8 = text.toUtf8();
cString = (char *)utf8.constData();
NSString *textMac = [[NSString alloc] initWithUTF8String:cString];
// do everything weak linked (because we will keep <10.8 compatibility)
id userNotification = [[NSClassFromString(@"NSUserNotification") alloc] init];
[userNotification performSelector:@selector(setTitle:) withObject:titleMac];
[userNotification performSelector:@selector(setInformativeText:) withObject:textMac];
id notificationCenterInstance = [NSClassFromString(@"NSUserNotificationCenter") performSelector:@selector(defaultUserNotificationCenter)];
[notificationCenterInstance performSelector:@selector(deliverNotification:) withObject:userNotification];
[titleMac release];
[textMac release];
NSUserNotification* userNotification = [[NSUserNotification alloc] init];
userNotification.title = title.toNSString();
userNotification.informativeText = text.toNSString();
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: userNotification];
[userNotification release];
}
}