Implement dekstop notifications on Windows (#290)

This commit is contained in:
Konstantinos Sideris 2018-07-01 00:23:16 +03:00
parent 765ff5dcb5
commit 95ce2ef920
3 changed files with 55 additions and 3 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
build
tags
.clang_complete
*wintoastlib*
# C++ objects and libs

View file

@ -323,7 +323,17 @@ if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation")
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerMac.mm)
elseif (WIN32)
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp)
file(DOWNLOAD
"https://raw.githubusercontent.com/mohabouje/WinToast/41ed1c58d5dce0ee9c01dbdeac05be45358d4f57/src/wintoastlib.cpp"
${PROJECT_SOURCE_DIR}/src/wintoastlib.cpp
EXPECTED_HASH SHA256=1A1A7CE41C1052B12946798F4A6C67CE1FAD209C967F5ED4D720B173527E2073)
file(DOWNLOAD
"https://raw.githubusercontent.com/mohabouje/WinToast/41ed1c58d5dce0ee9c01dbdeac05be45358d4f57/src/wintoastlib.h"
${PROJECT_SOURCE_DIR}/include/wintoastlib.h
EXPECTED_HASH SHA256=b4481023c5782733795838be22bf1a75f45d87458cd4d9a5a75f664a146eea11)
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp src/wintoastlib.cpp)
else ()
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerLinux.cpp)
endif ()

View file

@ -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
NotificationsManager::postNotification(const QString &, const QString &, const QString &)
init()
{
// TODO: To be implemented
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 &room, const QString &user, const QString &msg)
{
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());
}