diff --git a/core/daemon.h b/core/daemon.h --- a/core/daemon.h +++ b/core/daemon.h @@ -73,6 +73,8 @@ 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 --- a/daemon/kdeconnectd.cpp +++ b/daemon/kdeconnectd.cpp @@ -68,6 +68,17 @@ 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 --- a/plugins/battery/CMakeLists.txt +++ b/plugins/battery/CMakeLists.txt @@ -1,4 +1,3 @@ -find_package(KF5 REQUIRED COMPONENTS Notifications) set(kdeconnect_battery_SRCS batteryplugin.cpp @@ -10,6 +9,6 @@ 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 --- 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 @@ } 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 --- 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 @@ 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 --- a/plugins/ping/CMakeLists.txt +++ b/plugins/ping/CMakeLists.txt @@ -1,4 +1,3 @@ -find_package(KF5 REQUIRED COMPONENTS Notifications) set(kdeconnect_ping_SRCS pingplugin.cpp @@ -10,5 +9,4 @@ kdeconnectcore Qt5::DBus KF5::I18n - KF5::Notifications ) diff --git a/plugins/ping/pingplugin.cpp b/plugins/ping/pingplugin.cpp --- a/plugins/ping/pingplugin.cpp +++ b/plugins/ping/pingplugin.cpp @@ -20,15 +20,15 @@ #include "pingplugin.h" -#include #include #include #include #include #include #include +#include K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_ping.json", registerPlugin< PingPlugin >(); ) @@ -47,12 +47,7 @@ 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 --- 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 @@ 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 --- 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 --- a/tests/testdaemon.h +++ b/tests/testdaemon.h @@ -50,6 +50,11 @@ 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; };