Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[backport#14975] qt: Refactoring with QString::toNSString()
Summary:
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

---

Backport of Core [[bitcoin/bitcoin#14975 | PR14975]]

Test Plan:
  ninja all check check-functional

I don't have macOS to run the suite sadly

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D8132
  • Loading branch information
jonasschnelli authored and majcosta committed Oct 26, 2020
1 parent 82ded1d commit 97264f0
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/qt/macnotificationhandler.mm
Expand Up @@ -23,32 +23,12 @@ - (NSString *)__bundleIdentifier {
const QString &text) {
// 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];
}
}
Expand Down

0 comments on commit 97264f0

Please sign in to comment.