diff --git a/src/notifybysnore.cpp b/src/notifybysnore.cpp index 66c1208..4a2a5b2 100644 --- a/src/notifybysnore.cpp +++ b/src/notifybysnore.cpp @@ -1,160 +1,125 @@ /* Copyright (C) 2019 Piyush Aggarwal This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "notifybysnore.h" #include "knotification.h" #include "knotifyconfig.h" #include "debug_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include static NotifyBySnore *s_instance = nullptr; -// RUN THIS BEFORE TRYING OR THE NOTIFS WON'T SHOW! -// .\SnoreToast.exe -install "KDE Connect" "C:\CraftRoot\bin\kdeconnectd.exe" "org.kde.kdeconnect.daemon" +// !IMPORTANT! apps must have shortcut appID same as app->applicationName() -// !TODO! NSIS Installer: installing the Shortcut ^ -// !DOCUMENT THIS! apps must have shortcut appID same as app->applicationName() NotifyBySnore::NotifyBySnore(QObject* parent) : KNotificationPlugin(parent) { s_instance = this; app = QCoreApplication::instance(); iconDir = new QTemporaryDir(); - // server = new QLocalServer(); - // server->listen(app->applicationName()); } NotifyBySnore::~NotifyBySnore() { s_instance = nullptr; } void NotifyBySnore::notify(KNotification *notification, KNotifyConfig *config) { if (m_notifications.find(notification->id()) != m_notifications.end() || notification->id() == -1) { qDebug() << "AHAA ! Duplicate for ID: " << notification->id() << " caught!"; return; } proc = new QProcess(); QTemporaryFile iconFile; QStringList arguments; QFile file(iconDir->path() + QString::number(notification->id())); if (!notification->pixmap().isNull()) { notification->pixmap().save(&file, "PNG"); } - - // ACTION! -// QObject::connect(server, &QLocalServer::newConnection, server, [this,notification]() { -// auto sock = server->nextPendingConnection(); -// sock->waitForReadyRead(); -// const QByteArray rawData = sock->readAll(); -// const QString data = -// QString::fromWCharArray(reinterpret_cast(rawData.constData()), -// rawData.size() / sizeof(wchar_t)); -// QMap map; -// for (const auto &str : data.split(QStringLiteral(";"))) { -// const auto index = str.indexOf(QStringLiteral("=")); -// map[str.mid(0, index)] = str.mid(index + 1); -// } -// const auto action = map[QStringLiteral("action")]; -// const auto snoreAction = SnoreToastActions::getAction(action.toStdWString()); -// qDebug() << "THE ID IS : " << notification->id() << "AND THE ACTION IS : " << action; -// // if (action == QStringLiteral("clicked")) { -// NotifyBySnore::notificationActionInvoked(notification->id(), static_cast(snoreAction)); -// -// CRASHES JUST ABOUT HERE BECAUSE OF SOME LOCKED MUTEX. -// }); - + arguments << QStringLiteral("-t") << notification->title(); - arguments << QStringLiteral("-m") << notification->text()+QString::number(notification->id()); + arguments << QStringLiteral("-m") << notification->text(); arguments << QStringLiteral("-p") << file.fileName(); - arguments << QStringLiteral("-appID") << app->applicationName(); // GENERALIZE + arguments << QStringLiteral("-appID") << app->applicationName(); arguments << QStringLiteral("-id") << QString::number(notification->id()); - // arguments << QStringLiteral("-pipename") << server->fullServerName(); - // if (!notification->actions().isEmpty()){ - // arguments << QStringLiteral("-b") << notification->actions().join(QStringLiteral(";")); // MAYBE WORKS? - // } arguments << QStringLiteral("-w"); - m_notifications.insert(notification->id(), notification); // so that KNotifs keep track of displayed notifs + m_notifications.insert(notification->id(), notification); proc->start(program, arguments); - - - - if(proc->waitForStarted(1000)) { qDebug() << "SnoreToast displaying notification by ID: "<< notification->id(); } else { qDebug() << "SnoreToast did not start in time for Notif-Show"; } } void NotifyBySnore::close(KNotification* notification) { const auto it = m_notifications.find(notification->id()); if (it == m_notifications.end()) { return; } qDebug() << "SnoreToast closing notification by ID: "<< notification->id(); proc = new QProcess(); QStringList arguments; arguments << QStringLiteral("-close") << QString::number(notification->id()) << QStringLiteral("-appID") << app->applicationName(); ; proc->start(program, arguments); arguments.clear(); m_notifications.erase(it); if (it.value()) { finish(it.value()); } } void NotifyBySnore::update(KNotification *notification, KNotifyConfig *config) { close(notification); notify(notification, config); } void NotifyBySnore::notificationActionInvoked(int id, int action) { emit actionInvoked(id, action); } diff --git a/src/notifybysnore.h b/src/notifybysnore.h index ac6f5ab..ef3401e 100644 --- a/src/notifybysnore.h +++ b/src/notifybysnore.h @@ -1,54 +1,54 @@ /* Copyright (C) 2019 Piyush Aggarwal This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef NOTIFYBYSNORE_H #define NOTIFYBYSNORE_H #include "knotificationplugin.h" #include #include #include #include #include #include /** Windows notification backend - inspired by Android notification backend. */ class NotifyBySnore : public KNotificationPlugin { Q_OBJECT public: explicit NotifyBySnore(QObject *parent = nullptr); ~NotifyBySnore() override; QString optionName() override { return QStringLiteral("Popup"); } void notify(KNotification *notification, KNotifyConfig *config) override; void close(KNotification * notification) override; void update(KNotification *notification, KNotifyConfig *config) override; void notificationActionInvoked(int id, int action); private: QHash> m_notifications; QString program = QStringLiteral("SnoreToast.exe"); QProcess *proc; - // QLocalServer *server; + QLocalServer *server; QTemporaryDir *iconDir; QCoreApplication *app; }; #endif // NOTIFYBYSNORE_H