summary refs log tree commit diff
path: root/src/notifications/ManagerWin.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-09-18 00:22:33 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-09-18 00:45:50 +0200
commitcfca7157b98c9dc8e0852fe6484bc3f75008af7d (patch)
tree32b92340908a9374214ec7b84c1fac7ea338f56d /src/notifications/ManagerWin.cpp
parentMerge pull request #728 from Thulinma/goto (diff)
downloadnheko-cfca7157b98c9dc8e0852fe6484bc3f75008af7d.tar.xz
Change indentation to 4 spaces
Diffstat (limited to 'src/notifications/ManagerWin.cpp')
-rw-r--r--src/notifications/ManagerWin.cpp88
1 files changed, 42 insertions, 46 deletions
diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp

index fe7830a7..4376e4d8 100644 --- a/src/notifications/ManagerWin.cpp +++ b/src/notifications/ManagerWin.cpp
@@ -20,10 +20,10 @@ using namespace WinToastLib; class CustomHandler : public IWinToastHandler { public: - void toastActivated() const {} - void toastActivated(int) const {} - void toastFailed() const { std::wcout << L"Error showing current toast" << std::endl; } - void toastDismissed(WinToastDismissalReason) const {} + void toastActivated() const {} + void toastActivated(int) const {} + void toastFailed() const { std::wcout << L"Error showing current toast" << std::endl; } + void toastDismissed(WinToastDismissalReason) const {} }; namespace { @@ -32,12 +32,12 @@ bool isInitialized = false; void init() { - isInitialized = true; + isInitialized = true; - WinToast::instance()->setAppName(L"Nheko"); - WinToast::instance()->setAppUserModelId(WinToast::configureAUMI(L"nheko", L"nheko")); - if (!WinToast::instance()->initialize()) - std::wcout << "Your system is not compatible with toast notifications\n"; + WinToast::instance()->setAppName(L"Nheko"); + WinToast::instance()->setAppUserModelId(WinToast::configureAUMI(L"nheko", L"nheko")); + if (!WinToast::instance()->initialize()) + std::wcout << "Your system is not compatible with toast notifications\n"; } } @@ -49,41 +49,37 @@ void NotificationsManager::postNotification(const mtx::responses::Notification &notification, const QImage &icon) { - const auto room_name = - QString::fromStdString(cache::singleRoomInfo(notification.room_id).name); - const auto sender = - cache::displayName(QString::fromStdString(notification.room_id), - QString::fromStdString(mtx::accessors::sender(notification.event))); + const auto room_name = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name); + const auto sender = + cache::displayName(QString::fromStdString(notification.room_id), + QString::fromStdString(mtx::accessors::sender(notification.event))); - const auto isEncrypted = - std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( - &notification.event) != nullptr; - const auto isReply = utils::isReply(notification.event); + const auto isEncrypted = std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( + &notification.event) != nullptr; + const auto isReply = utils::isReply(notification.event); - auto formatNotification = [this, notification, sender] { - const auto template_ = getMessageTemplate(notification); - if (std::holds_alternative< - mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( - notification.event)) { - return template_; - } + auto formatNotification = [this, notification, sender] { + const auto template_ = getMessageTemplate(notification); + if (std::holds_alternative<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( + notification.event)) { + return template_; + } - return template_.arg( - utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body); - }; + return template_.arg(utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body); + }; - const auto line1 = - (room_name == sender) ? sender : QString("%1 - %2").arg(sender).arg(room_name); - const auto line2 = (isEncrypted ? (isReply ? tr("%1 replied with an encrypted message") - : tr("%1 sent an encrypted message")) - : formatNotification()); + const auto line1 = + (room_name == sender) ? sender : QString("%1 - %2").arg(sender).arg(room_name); + const auto line2 = (isEncrypted ? (isReply ? tr("%1 replied with an encrypted message") + : tr("%1 sent an encrypted message")) + : formatNotification()); - auto iconPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + - room_name + "-room-avatar.png"; - if (!icon.save(iconPath)) - iconPath.clear(); + auto iconPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + room_name + + "-room-avatar.png"; + if (!icon.save(iconPath)) + iconPath.clear(); - systemPostNotification(line1, line2, iconPath); + systemPostNotification(line1, line2, iconPath); } void @@ -91,17 +87,17 @@ NotificationsManager::systemPostNotification(const QString &line1, const QString &line2, const QString &iconPath) { - if (!isInitialized) - init(); + if (!isInitialized) + init(); - auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02); - templ.setTextField(line1.toStdWString(), WinToastTemplate::FirstLine); - templ.setTextField(line2.toStdWString(), WinToastTemplate::SecondLine); + auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02); + templ.setTextField(line1.toStdWString(), WinToastTemplate::FirstLine); + templ.setTextField(line2.toStdWString(), WinToastTemplate::SecondLine); - if (!iconPath.isNull()) - templ.setImagePath(iconPath.toStdWString()); + if (!iconPath.isNull()) + templ.setImagePath(iconPath.toStdWString()); - WinToast::instance()->showToast(templ, new CustomHandler()); + WinToast::instance()->showToast(templ, new CustomHandler()); } void NotificationsManager::actionInvoked(uint, QString) {}