Change structure.

This commit is contained in:
Black Hat 2018-10-20 13:28:51 +08:00
parent 16e7f5003c
commit 6339fd78a2
2 changed files with 13 additions and 14 deletions

View File

@ -39,7 +39,7 @@ class NotificationsManager : public QObject {
// these slots are platform specific (D-Bus only) // these slots are platform specific (D-Bus only)
// but Qt slot declarations can not be inside an ifdef! // but Qt slot declarations can not be inside an ifdef!
private slots: public slots:
void actionInvoked(uint id, QString action); void actionInvoked(uint id, QString action);
void notificationClosed(uint id, uint reason); void notificationClosed(uint id, uint reason);
}; };

View File

@ -3,23 +3,26 @@
using namespace WinToastLib; using namespace WinToastLib;
class CustomHandler : public QObject, public IWinToastHandler { class CustomHandler : public IWinToastHandler {
Q_OBJECT
public: public:
void toastActivated() { emit activated(notificationID); } CustomHandler(NotificationsManager* parent) : notificationsManager(parent) {}
void toastActivated(int) { emit activated(notificationID); } void toastActivated() {
notificationsManager->actionInvoked(notificationID, "");
}
void toastActivated(int) {
notificationsManager->actionInvoked(notificationID, "");
}
void toastFailed() { void toastFailed() {
std::wcout << L"Error showing current toast" << std::endl; std::wcout << L"Error showing current toast" << std::endl;
} }
void toastDismissed(WinToastDismissalReason) { void toastDismissed(WinToastDismissalReason) {
emit dismissed(notificationID); notificationsManager->notificationClosed(notificationID, 0);
} }
uint notificationID; uint notificationID;
signals: private:
void activated(uint id); NotificationsManager* notificationsManager;
void dismissed(uint id);
}; };
namespace { namespace {
@ -61,14 +64,10 @@ void NotificationsManager::postNotification(
// TODO: implement room or user avatar // TODO: implement room or user avatar
// templ.setImagePath(L"C:/example.png"); // templ.setImagePath(L"C:/example.png");
CustomHandler *customHandler = new CustomHandler(); CustomHandler *customHandler = new CustomHandler(this);
count++; count++;
customHandler->notificationID = count; customHandler->notificationID = count;
notificationIds[count] = roomEventId{room_id, event_id}; notificationIds[count] = roomEventId{room_id, event_id};
connect(customHandler, &CustomHandler::activated, this,
[=](uint id) { this->actionInvoked(id, ""); });
connect(customHandler, &CustomHandler::dismissed, this,
[=](uint id) { this->notificationClosed(id, 0); });
WinToast::instance()->showToast(templ, customHandler); WinToast::instance()->showToast(templ, customHandler);
} }