2018-05-05 22:40:24 +03:00
|
|
|
#include "notifications/Manager.h"
|
2018-07-01 00:23:16 +03:00
|
|
|
#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";
|
|
|
|
}
|
|
|
|
}
|
2018-05-05 22:40:24 +03:00
|
|
|
|
2018-07-11 17:33:02 +03:00
|
|
|
NotificationsManager::NotificationsManager(QObject *parent): QObject(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-05 22:40:24 +03:00
|
|
|
void
|
2018-07-11 17:33:02 +03:00
|
|
|
NotificationsManager::postNotification(const QString &, //roomid
|
|
|
|
const QString &, //eventid
|
|
|
|
const QString &roomname,
|
|
|
|
const QString &sender,
|
|
|
|
const QString &text,
|
|
|
|
const QImage &) //icon
|
2018-05-05 22:40:24 +03:00
|
|
|
{
|
2018-07-01 00:23:16 +03:00
|
|
|
if (!isInitialized)
|
|
|
|
init();
|
|
|
|
|
|
|
|
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
|
2018-07-11 17:33:02 +03:00
|
|
|
if (roomname != sender)
|
|
|
|
templ.setTextField(QString("%1 - %2").arg(sender).arg(roomname).toStdWString(),
|
2018-07-01 00:23:16 +03:00
|
|
|
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());
|
2018-05-05 22:40:24 +03:00
|
|
|
}
|
2018-07-11 17:33:02 +03:00
|
|
|
|
|
|
|
//unused
|
|
|
|
void
|
|
|
|
NotificationsManager::actionInvoked(uint, QString)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationsManager::notificationClosed(uint, uint)
|
|
|
|
{
|
|
|
|
}
|