Commit a53ec2a9 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Notification Plugin can now receive payloads with the notification icon

parent e20adde7
......@@ -23,13 +23,14 @@
#include <QDBusConnection>
#include <QDebug>
Notification::Notification(const NetworkPackage& np, QObject* parent)
Notification::Notification(const NetworkPackage& np, const QString& iconPath, QObject* parent)
: QObject(parent)
{
mId = np.get<QString>("id");
mAppName = np.get<QString>("appName");
mTicker = np.get<QString>("ticker");
mDismissable = np.get<bool>("isClearable");
mIconPath = iconPath;
}
Notification::~Notification()
......
......@@ -34,15 +34,17 @@ class Notification
Q_PROPERTY(QString internalId READ internalId)
Q_PROPERTY(QString appName READ appName)
Q_PROPERTY(QString ticker READ ticker)
Q_PROPERTY(QString iconPath READ iconPath)
Q_PROPERTY(bool dismissable READ dismissable)
public:
Notification(const NetworkPackage& np, QObject* parent);
Notification(const NetworkPackage& np, const QString& iconPath, QObject* parent);
virtual ~Notification();
QString internalId() { return mId; }
QString appName() { return mAppName; }
QString ticker() { return mTicker; }
QString iconPath() { return mIconPath; }
bool dismissable() { return mDismissable; }
public Q_SLOTS:
......@@ -55,7 +57,7 @@ private:
QString mId;
QString mAppName;
QString mTicker;
//QIcon mIcon;
QString mIconPath;
bool mDismissable;
};
......
......@@ -20,11 +20,15 @@
#include "notificationsdbusinterface.h"
#include "../../filetransferjob.h"
#include <QDebug>
#include <qdir.h>
#include <QDBusConnection>
#include <KNotification>
#include <KIcon>
#include <KMD5>
NotificationsDbusInterface::NotificationsDbusInterface(Device* device, QObject *parent)
: QDBusAbstractAdaptor(parent)
......@@ -49,9 +53,17 @@ void NotificationsDbusInterface::processPackage(const NetworkPackage& np)
if (np.get<bool>("isCancel")) {
removeNotification(np.get<QString>("id"));
} else {
Notification* noti = new Notification(np, this);
//TODO: Store the app icon if any under tmp with the app name as filename (so we only store one per app) and export the path to that file to dbus inside Notification
QString destination;
if (np.hasPayload()) {
//TODO: Store the image with extension?
destination = QDir::temp().absoluteFilePath("kdeconnect/"+KMD5(np.get<QString>("appName").toLatin1()).hexDigest());
FileTransferJob* job = np.createPayloadTransferJob(destination);
job->start();
}
Notification* noti = new Notification(np, destination, this);
addNotification(noti);
//Do not show updates to existent notification nor answers to a initialization request
if (!mInternalIdToPublicId.contains(noti->internalId()) && !np.get<bool>("requestAnswer", false)) {
......@@ -63,7 +75,6 @@ void NotificationsDbusInterface::processPackage(const NetworkPackage& np)
notification->sendEvent();
}
addNotification(noti);
}
}
......
......@@ -38,7 +38,7 @@ NotificationsPlugin::NotificationsPlugin(QObject* parent, const QVariantList& ar
void NotificationsPlugin::connected()
{
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
np.set("request",true);
np.set("request", true);
device()->sendPackage(np);
}
......
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