This repository has been archived by the owner on Oct 17, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement dekstop notifications on Windows (#290)
- Loading branch information
Showing
3 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
build | ||
tags | ||
.clang_complete | ||
*wintoastlib* | ||
|
||
# C++ objects and libs | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,48 @@ | ||
#include "notifications/Manager.h" | ||
#include "wintoastlib.h" | ||
|
||
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 {} | ||
}; | ||
|
||
namespace { | ||
bool isInitialized = false; | ||
|
||
void | ||
init() | ||
{ | ||
isInitialized = true; | ||
|
||
WinToast::instance()->setAppName(L"Nheko"); | ||
WinToast::instance()->setAppUserModelId(WinToast::configureAUMI(L"nheko", L"nheko")); | ||
if (!WinToast::instance()->initialize()) | ||
std::wcout << "Your system in not compatible with toast notifications\n"; | ||
} | ||
} | ||
|
||
void | ||
NotificationsManager::postNotification(const QString &, const QString &, const QString &) | ||
NotificationsManager::postNotification(const QString &room, const QString &user, const QString &msg) | ||
{ | ||
// TODO: To be implemented | ||
if (!isInitialized) | ||
init(); | ||
|
||
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02); | ||
if (room != user) | ||
templ.setTextField(QString("%1 - %2").arg(user).arg(room).toStdWString(), | ||
WinToastTemplate::FirstLine); | ||
else | ||
templ.setTextField(QString("%1").arg(user).toStdWString(), | ||
WinToastTemplate::FirstLine); | ||
templ.setTextField(QString("%1").arg(msg).toStdWString(), WinToastTemplate::SecondLine); | ||
// TODO: implement room or user avatar | ||
// templ.setImagePath(L"C:/example.png"); | ||
|
||
WinToast::instance()->showToast(templ, new CustomHandler()); | ||
} |