summary refs log tree commit diff
path: root/src/notifications
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2021-03-02 20:35:03 -0500
committerNicolas Werner <nicolas.werner@hotmail.de>2021-03-17 19:18:07 +0100
commit41737ac22c3689324e4296d6fdfc9677a86d70e6 (patch)
tree3b62e44665cada210cbef848ed5eeb41e8aa5322 /src/notifications
parentDon't create a QImage every time (diff)
downloadnheko-41737ac22c3689324e4296d6fdfc9677a86d70e6.tar.xz
Simplify image loading
Diffstat (limited to 'src/notifications')
-rw-r--r--src/notifications/Manager.h4
-rw-r--r--src/notifications/ManagerMac.cpp12
-rw-r--r--src/notifications/ManagerMac.mm6
3 files changed, 6 insertions, 16 deletions
diff --git a/src/notifications/Manager.h b/src/notifications/Manager.h

index 825da4c8..a1ef9f98 100644 --- a/src/notifications/Manager.h +++ b/src/notifications/Manager.h
@@ -79,9 +79,7 @@ private: void objCxxPostNotification(const QString &title, const QString &subtitle, const QString &informativeText, - const QImage *bodyImage); - - QImage *getImgOrNullptr(const QString &path); + const QImage &bodyImage); #endif #if defined(Q_OS_WINDOWS) diff --git a/src/notifications/ManagerMac.cpp b/src/notifications/ManagerMac.cpp
index 1bf1577f..de5d0875 100644 --- a/src/notifications/ManagerMac.cpp +++ b/src/notifications/ManagerMac.cpp
@@ -39,9 +39,9 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif cache::displayName(QString::fromStdString(notification.room_id), QString::fromStdString(mtx::accessors::sender(notification.event))); - QImage *image = nullptr; + QImage image; if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image) - image = getImgOrNullptr(cacheImage(notification.event)); + image = QImage{cacheImage(notification.event)}; const auto isEncrypted = std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( @@ -61,11 +61,3 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif room_name, messageInfo, formatNotification(notification), image); } } - -QImage * -NotificationsManager::getImgOrNullptr(const QString &path) -{ - if (QFile::exists(path)) - return nullptr; - return new QImage{path}; -} diff --git a/src/notifications/ManagerMac.mm b/src/notifications/ManagerMac.mm
index 226bcce0..33b7b6af 100644 --- a/src/notifications/ManagerMac.mm +++ b/src/notifications/ManagerMac.mm
@@ -19,7 +19,7 @@ void NotificationsManager::objCxxPostNotification(const QString &title, const QString &subtitle, const QString &informativeText, - const QImage *bodyImage) + const QImage &bodyImage) { NSUserNotification *notif = [[NSUserNotification alloc] init]; @@ -29,8 +29,8 @@ NotificationsManager::objCxxPostNotification(const QString &title, notif.informativeText = informativeText.toNSString(); notif.soundName = NSUserNotificationDefaultSoundName; - if (bodyImage != nullptr) - notif.contentImage = [[NSImage alloc] initWithCGImage: bodyImage->toCGImage() size: NSZeroSize]; + if (!bodyImage.isNull()) + notif.contentImage = [[NSImage alloc] initWithCGImage: bodyImage.toCGImage() size: NSZeroSize]; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif]; [notif autorelease];