diff --git a/core/daemon.h b/core/daemon.h index 5ffb8a2f8..0d3742c5e 100644 --- a/core/daemon.h +++ b/core/daemon.h @@ -73,6 +73,8 @@ public Q_SLOTS: Q_SCRIPTABLE QString deviceIdByName(const QString& name) const; + Q_SCRIPTABLE virtual void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) = 0; + Q_SIGNALS: Q_SCRIPTABLE void deviceAdded(const QString& id); Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed diff --git a/daemon/kdeconnectd.cpp b/daemon/kdeconnectd.cpp index 7c8560971..27feb43dd 100644 --- a/daemon/kdeconnectd.cpp +++ b/daemon/kdeconnectd.cpp @@ -68,6 +68,17 @@ public: return m_nam; } + Q_SCRIPTABLE void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) override + { + KNotification* notification = new KNotification(eventId); //KNotification::Persistent + notification->setIconName(iconName); + notification->setComponentName(QStringLiteral("kdeconnect")); + notification->setTitle(title); + notification->setText(text); + notification->sendEvent(); + } + + private: QNetworkAccessManager* m_nam; }; diff --git a/plugins/battery/CMakeLists.txt b/plugins/battery/CMakeLists.txt index 26f6f0763..6276e6aa0 100644 --- a/plugins/battery/CMakeLists.txt +++ b/plugins/battery/CMakeLists.txt @@ -8,6 +8,6 @@ kdeconnect_add_plugin(kdeconnect_battery JSON kdeconnect_battery.json SOURCES ${ target_link_libraries(kdeconnect_battery kdeconnectcore Qt5::DBus + Qt5::Gui KF5::I18n - KF5::Notifications ) diff --git a/plugins/battery/batteryplugin.cpp b/plugins/battery/batteryplugin.cpp index 40316c154..3bf8b2435 100644 --- a/plugins/battery/batteryplugin.cpp +++ b/plugins/battery/batteryplugin.cpp @@ -20,11 +20,12 @@ #include "batteryplugin.h" -#include #include #include #include +#include + #include "batterydbusinterface.h" K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_battery.json", registerPlugin< BatteryPlugin >(); ) @@ -71,12 +72,8 @@ bool BatteryPlugin::receivePacket(const NetworkPacket& np) } if ( thresholdEvent == ThresholdBatteryLow && !isCharging ) { - KNotification* notification = new KNotification(QStringLiteral("batteryLow")); - notification->setIconName(QStringLiteral("battery-040")); - notification->setComponentName(QStringLiteral("kdeconnect")); - notification->setTitle(i18nc("device name: low battery", "%1: Low Battery", device()->name())); - notification->setText(i18n("Battery at %1%", currentCharge)); - notification->sendEvent(); + Daemon::instance()->sendSimpleNotification(QStringLiteral("batteryLow"), i18nc("device name: low battery", "%1: Low Battery", device()->name()), i18n("Battery at %1%", currentCharge), QStringLiteral("battery-040")); + } return true; diff --git a/plugins/notifications/notificationsplugin.h b/plugins/notifications/notificationsplugin.h index b8e0a3e42..e5890e60a 100644 --- a/plugins/notifications/notificationsplugin.h +++ b/plugins/notifications/notificationsplugin.h @@ -21,8 +21,6 @@ #ifndef NOTIFICATIONSPLUGIN_H #define NOTIFICATIONSPLUGIN_H -#include - #include #define PACKET_TYPE_NOTIFICATION_REQUEST QStringLiteral("kdeconnect.notification.request") @@ -44,7 +42,7 @@ class NotificationsPlugin public: explicit NotificationsPlugin(QObject* parent, const QVariantList& args); ~NotificationsPlugin() override; - + bool receivePacket(const NetworkPacket& np) override; void connected() override; diff --git a/plugins/ping/CMakeLists.txt b/plugins/ping/CMakeLists.txt index 99f7c83ec..1ea45d166 100644 --- a/plugins/ping/CMakeLists.txt +++ b/plugins/ping/CMakeLists.txt @@ -8,5 +8,4 @@ target_link_libraries(kdeconnect_ping kdeconnectcore Qt5::DBus KF5::I18n - KF5::Notifications ) diff --git a/plugins/ping/pingplugin.cpp b/plugins/ping/pingplugin.cpp index 41fb3b017..a1d34bd15 100644 --- a/plugins/ping/pingplugin.cpp +++ b/plugins/ping/pingplugin.cpp @@ -20,7 +20,6 @@ #include "pingplugin.h" -#include #include #include @@ -29,6 +28,7 @@ #include #include +#include K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_ping.json", registerPlugin< PingPlugin >(); ) @@ -47,12 +47,7 @@ PingPlugin::~PingPlugin() bool PingPlugin::receivePacket(const NetworkPacket& np) { - KNotification* notification = new KNotification(QStringLiteral("pingReceived")); //KNotification::Persistent - notification->setIconName(QStringLiteral("dialog-ok")); - notification->setComponentName(QStringLiteral("kdeconnect")); - notification->setTitle(device()->name()); - notification->setText(np.get(QStringLiteral("message"),i18n("Ping!"))); //This can be a source of spam - notification->sendEvent(); + Daemon::instance()->sendSimpleNotification(QStringLiteral("pingReceived"), device()->name(), np.get(QStringLiteral("message"),i18n("Ping!")), QStringLiteral("dialog-ok")); return true; } diff --git a/plugins/sftp/sftpplugin.h b/plugins/sftp/sftpplugin.h index c58b7b89a..8539e31d9 100644 --- a/plugins/sftp/sftpplugin.h +++ b/plugins/sftp/sftpplugin.h @@ -26,14 +26,12 @@ #define PACKET_TYPE_SFTP_REQUEST QStringLiteral("kdeconnect.sftp.request") -class KNotification; - class SftpPlugin : public KdeConnectPlugin { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.sftp") - + public: explicit SftpPlugin(QObject* parent, const QVariantList& args); ~SftpPlugin() override; @@ -61,12 +59,12 @@ private Q_SLOTS: void onMounted(); void onUnmounted(); void onFailed(const QString& message); - + private: void knotify(int type, const QString& text, const QPixmap& icon) const; void addToDolphin(); void removeFromDolphin(); - + private: struct Pimpl; QScopedPointer d; diff --git a/plugins/share/shareplugin.h b/plugins/share/shareplugin.h index 9b357d7b5..2a9debeb5 100644 --- a/plugins/share/shareplugin.h +++ b/plugins/share/shareplugin.h @@ -21,7 +21,6 @@ #ifndef SHAREPLUGIN_H #define SHAREPLUGIN_H -#include #include #include diff --git a/tests/testdaemon.h b/tests/testdaemon.h index 9d45aada7..501f4f549 100644 --- a/tests/testdaemon.h +++ b/tests/testdaemon.h @@ -50,6 +50,11 @@ public: return m_nam; } + Q_SCRIPTABLE virtual void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) override + { + qDebug() << eventId << title << text << iconName; + } + private: QNetworkAccessManager* m_nam; };