Commit ebc316f7 authored by Adam Pigg's avatar Adam Pigg Committed by Matthijs Tijink

Add a method for creating simple notifications

Summary:
Add a helper function to the daemon interface, which must be subclassed
by the implementations, which creates a simple notification.

For more complex needs, involving interacting with the notification, it
will still be nescessary to use KNotification directly, but this allows
for other future implementations to create a simple notification without
ifdef'ing the code.

Reviewers: kdeconnect, apol

Reviewed By: apol

Subscribers: kdeconnect

Differential Revision: https://phabricator.kde.org/D11104
parent f7656cef
......@@ -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
......
......@@ -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;
};
......
......@@ -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
)
......@@ -20,11 +20,12 @@
#include "batteryplugin.h"
#include <KNotification>
#include <QIcon>
#include <KLocalizedString>
#include <KPluginFactory>
#include <core/daemon.h>
#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;
......
......@@ -21,8 +21,6 @@
#ifndef NOTIFICATIONSPLUGIN_H
#define NOTIFICATIONSPLUGIN_H
#include <knotification.h>
#include <core/kdeconnectplugin.h>
#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;
......
......@@ -8,5 +8,4 @@ target_link_libraries(kdeconnect_ping
kdeconnectcore
Qt5::DBus
KF5::I18n
KF5::Notifications
)
......@@ -20,7 +20,6 @@
#include "pingplugin.h"
#include <KNotification>
#include <KLocalizedString>
#include <KPluginFactory>
......@@ -29,6 +28,7 @@
#include <QLoggingCategory>
#include <core/device.h>
#include <core/daemon.h>
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<QString>(QStringLiteral("message"),i18n("Ping!"))); //This can be a source of spam
notification->sendEvent();
Daemon::instance()->sendSimpleNotification(QStringLiteral("pingReceived"), device()->name(), np.get<QString>(QStringLiteral("message"),i18n("Ping!")), QStringLiteral("dialog-ok"));
return true;
}
......
......@@ -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<Pimpl> d;
......
......@@ -21,7 +21,6 @@
#ifndef SHAREPLUGIN_H
#define SHAREPLUGIN_H
#include <KNotification>
#include <KIO/Job>
#include <core/kdeconnectplugin.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;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment