Ooops missing files from last commit
This commit is contained in:
parent
18b3945da0
commit
e91300d8e9
4 changed files with 295 additions and 0 deletions
47
daemon/plugins/notifications/notification.cpp
Normal file
47
daemon/plugins/notifications/notification.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* <one line to give the library's name and an idea of what it does.>
|
||||
* Copyright 2013 <copyright holder> <email>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "notification.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDebug>
|
||||
|
||||
Notification::Notification(const NetworkPackage& np, QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
mId = np.get<QString>("id");
|
||||
mAppName = np.get<QString>("appName");
|
||||
mTicker = np.get<QString>("ticker");
|
||||
mDismissable = np.get<bool>("isClearable");
|
||||
}
|
||||
|
||||
Notification::~Notification()
|
||||
{
|
||||
qDebug() << "Destroying notification" << mId;
|
||||
}
|
||||
|
||||
void Notification::dismiss()
|
||||
{
|
||||
if (mDismissable) {
|
||||
Q_EMIT dismissRequested(this);
|
||||
}
|
||||
}
|
65
daemon/plugins/notifications/notification.h
Normal file
65
daemon/plugins/notifications/notification.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* <one line to give the library's name and an idea of what it does.>
|
||||
* Copyright 2013 <copyright holder> <email>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NOTIFICATION_H
|
||||
#define NOTIFICATION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "../../networkpackage.h"
|
||||
|
||||
class Notification
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.notifications.notification")
|
||||
Q_PROPERTY(QString internalId READ internalId)
|
||||
Q_PROPERTY(QString appName READ appName)
|
||||
Q_PROPERTY(QString ticker READ ticker)
|
||||
Q_PROPERTY(QString dismissable READ dismissable)
|
||||
|
||||
public:
|
||||
Notification(const NetworkPackage& np, QObject* parent);
|
||||
virtual ~Notification();
|
||||
|
||||
QString internalId() { return mId; }
|
||||
QString appName() { return mAppName; }
|
||||
QString ticker() { return mTicker; }
|
||||
bool dismissable() { return mDismissable; }
|
||||
|
||||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE void dismiss();
|
||||
|
||||
Q_SIGNALS:
|
||||
void dismissRequested(Notification* self);
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
QString mAppName;
|
||||
QString mTicker;
|
||||
//QIcon mIcon;
|
||||
bool mDismissable;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
118
daemon/plugins/notifications/notificationsdbusinterface.cpp
Normal file
118
daemon/plugins/notifications/notificationsdbusinterface.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "notificationsdbusinterface.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDBusConnection>
|
||||
|
||||
NotificationsDbusInterface::NotificationsDbusInterface(Device* device, QObject *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
, mDevice(device)
|
||||
, mLastId(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NotificationsDbusInterface::~NotificationsDbusInterface()
|
||||
{
|
||||
qDeleteAll(mNotifications);
|
||||
}
|
||||
|
||||
QStringList NotificationsDbusInterface::activeNotifications()
|
||||
{
|
||||
return mNotifications.keys();
|
||||
}
|
||||
|
||||
void NotificationsDbusInterface::processPackage(const NetworkPackage& np)
|
||||
{
|
||||
if (np.get<bool>("isCancel")) {
|
||||
removeNotification(np.get<QString>("id"));
|
||||
} else {
|
||||
Notification* noti = new Notification(np, this);
|
||||
addNotification(noti);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationsDbusInterface::addNotification(Notification* noti)
|
||||
{
|
||||
const QString& internalId = noti->internalId();
|
||||
|
||||
if (mInternalIdToPublicId.contains(internalId)) {
|
||||
removeNotification(internalId);
|
||||
}
|
||||
|
||||
connect(noti, SIGNAL(dismissRequested(Notification*)),
|
||||
this, SLOT(dismissRequested(Notification*)));
|
||||
|
||||
const QString& publicId = newId();
|
||||
mNotifications[publicId] = noti;
|
||||
mInternalIdToPublicId[internalId] = publicId;
|
||||
|
||||
QDBusConnection::sessionBus().registerObject(mDevice->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents);
|
||||
Q_EMIT notificationPosted(publicId);
|
||||
}
|
||||
|
||||
void NotificationsDbusInterface::removeNotification(const QString& internalId)
|
||||
{
|
||||
qDebug() << "removeNotification" << internalId;
|
||||
|
||||
if (!mInternalIdToPublicId.contains(internalId)) {
|
||||
qDebug() << "Not found";
|
||||
return;
|
||||
}
|
||||
|
||||
QString publicId = mInternalIdToPublicId[internalId];
|
||||
mInternalIdToPublicId.remove(internalId);
|
||||
|
||||
if (!mNotifications.contains(publicId)) {
|
||||
qDebug() << "Not found";
|
||||
return;
|
||||
}
|
||||
|
||||
Notification* noti = mNotifications[publicId];
|
||||
mNotifications.remove(publicId);
|
||||
|
||||
//Deleting the notification will unregister it automatically?
|
||||
//QDBusConnection::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId);
|
||||
noti->deleteLater();
|
||||
|
||||
Q_EMIT notificationRemoved(publicId);
|
||||
|
||||
}
|
||||
|
||||
void NotificationsDbusInterface::dismissRequested(Notification* notification)
|
||||
{
|
||||
const QString& internalId = notification->internalId();
|
||||
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
|
||||
np.set<QString>("cancel", internalId);
|
||||
mDevice->sendPackage(np);
|
||||
|
||||
//This should be called automatically back from server
|
||||
//removeNotification(internalId);
|
||||
}
|
||||
|
||||
QString NotificationsDbusInterface::newId()
|
||||
{
|
||||
return QString::number(++mLastId);
|
||||
}
|
||||
|
||||
|
65
daemon/plugins/notifications/notificationsdbusinterface.h
Normal file
65
daemon/plugins/notifications/notificationsdbusinterface.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NOTIFICATIONSDBUSINTERFACE_H
|
||||
#define NOTIFICATIONSDBUSINTERFACE_H
|
||||
|
||||
#include <QDBusAbstractAdaptor>
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "../../device.h"
|
||||
#include "notification.h"
|
||||
|
||||
class NotificationsDbusInterface
|
||||
: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.notifications")
|
||||
|
||||
public:
|
||||
explicit NotificationsDbusInterface(Device* device, QObject *parent);
|
||||
virtual ~NotificationsDbusInterface();
|
||||
|
||||
void processPackage(const NetworkPackage& np);
|
||||
|
||||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE QStringList activeNotifications();
|
||||
void dismissRequested(Notification* notification);
|
||||
|
||||
Q_SIGNALS:
|
||||
void notificationPosted(const QString& publicId);
|
||||
void notificationRemoved(const QString& publicId);
|
||||
|
||||
private /*methods*/:
|
||||
void addNotification(Notification* noti);
|
||||
void removeNotification(const QString& internalId);
|
||||
QString newId(); //Generates successive identifitiers to use as public ids
|
||||
|
||||
private /*attributes*/:
|
||||
Device* mDevice;
|
||||
QHash<QString, Notification*> mNotifications;
|
||||
QHash<QString, QString> mInternalIdToPublicId;
|
||||
int mLastId;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue