Migrated notifications to new plugin format. Now it is called 'telephony plugin' because we will have a different plugin for notification syncing

This commit is contained in:
Albert Vaca 2013-08-13 23:26:09 +02:00
parent 238d81a408
commit 925e3abb3e
5 changed files with 59 additions and 35 deletions

View file

@ -5,3 +5,4 @@ add_subdirectory(ping)
add_subdirectory(pausemusic) add_subdirectory(pausemusic)
add_subdirectory(mpriscontrol) add_subdirectory(mpriscontrol)
add_subdirectory(clipboard) add_subdirectory(clipboard)
add_subdirectory(telephony)

View file

@ -0,0 +1,20 @@
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories(${KDE4_INCLUDES})
set(kdeconnect_telephony_SRCS
telephonyplugin.cpp
../kdeconnectplugin.cpp
)
kde4_add_plugin(kdeconnect_telephony ${kdeconnect_telephony_SRCS})
target_link_libraries(kdeconnect_telephony
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
${QT_QTNETWORK_LIBRARY}
qjson
)
install(TARGETS kdeconnect_telephony DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_telephony.desktop DESTINATION ${SERVICES_INSTALL_DIR} )

View file

@ -0,0 +1,15 @@
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=KdeConnect/Plugin
X-KDE-Library=kdeconnect_telephony
X-KDE-PluginInfo-Author=Albert Vaca
X-KDE-PluginInfo-Email=albertvaka@gmail.com
X-KDE-PluginInfo-Name=kdeconnect_telephony
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://albertvaka.wordpress.com
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=preferences-desktop-notification
Name=Telephony integration
Comment=Currently it only shows notifications for calls and SMS

View file

@ -18,23 +18,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "notificationpackageinterface.h" #include "telephonyplugin.h"
#include <QDebug> #include <QDebug>
#include <kicon.h> #include <kicon.h>
NotificationPackageInterface::NotificationPackageInterface(QObject* parent) TelephonyPlugin::TelephonyPlugin(QObject *parent, const QVariantList &args)
: PackageInterface(parent) : KdeConnectPlugin(parent, args)
{ {
//TODO: Split in EventNotificationInterface and NotificationDrawerSyncInterface
trayIcon = new KStatusNotifierItem(parent); trayIcon = new KStatusNotifierItem(parent);
trayIcon->setIconByName("pda"); trayIcon->setIconByName("pda");
trayIcon->setTitle("KdeConnect"); trayIcon->setTitle("KdeConnect");
connect(trayIcon,SIGNAL(activateRequested(bool,QPoint)),this,SLOT(showPendingNotifications())); connect(trayIcon,SIGNAL(activateRequested(bool,QPoint)),this,SLOT(showPendingNotifications()));
} }
KNotification* NotificationPackageInterface::createNotification(const QString& deviceName, const NetworkPackage& np) KNotification* TelephonyPlugin::createNotification(const NetworkPackage& np)
{ {
QString id = QString::number(np.id()); QString id = QString::number(np.id());
@ -44,8 +42,7 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
QString title, content, type, icon; QString title, content, type, icon;
bool transient; bool transient;
title = deviceName; title = device()->name();
if (npType == "ringing") { if (npType == "ringing") {
type = "callReceived"; type = "callReceived";
@ -65,16 +62,6 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
+ ":\n" + ":\n"
+ np.get<QString>("messageBody",""); + np.get<QString>("messageBody","");
transient = true; transient = true;
} else if (npType == "battery") {
type = "battery100";
icon = "battery-100";
content = "Battery at " + np.get<QString>("batteryLevel") + "%";
transient = false;
} else if (npType == "notification") {
type = "pingReceived";
icon = "dialog-ok";
content = np.get<QString>("notificationContent");
transient = false;
} else { } else {
//TODO: return NULL if !debug //TODO: return NULL if !debug
type = "unknownEvent"; type = "unknownEvent";
@ -89,7 +76,7 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
if (transient) { if (transient) {
trayIcon->setStatus(KStatusNotifierItem::Active); trayIcon->setStatus(KStatusNotifierItem::Active);
KNotification* notification = new KNotification(type); //KNotification::Persistent KNotification* notification = new KNotification(type);
notification->setPixmap(KIcon(icon).pixmap(48, 48)); notification->setPixmap(KIcon(icon).pixmap(48, 48));
notification->setComponentData(KComponentData("kdeconnect", "kdeconnect")); notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
notification->setTitle(title); notification->setTitle(title);
@ -98,7 +85,8 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
pendingNotifications.insert(id, notification); pendingNotifications.insert(id, notification);
} }
KNotification* notification = new KNotification(type); //KNotification::Persistent
KNotification* notification = new KNotification(type); //, KNotification::Persistent
notification->setPixmap(KIcon(icon).pixmap(48, 48)); notification->setPixmap(KIcon(icon).pixmap(48, 48));
notification->setComponentData(KComponentData("kdeconnect", "kdeconnect")); notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
notification->setTitle(title); notification->setTitle(title);
@ -112,7 +100,7 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
} }
void NotificationPackageInterface::notificationAttended() void TelephonyPlugin::notificationAttended()
{ {
KNotification* normalNotification = (KNotification*)sender(); KNotification* normalNotification = (KNotification*)sender();
QString id = normalNotification->property("id").toString(); QString id = normalNotification->property("id").toString();
@ -125,7 +113,7 @@ void NotificationPackageInterface::notificationAttended()
} }
} }
void NotificationPackageInterface::showPendingNotifications() void TelephonyPlugin::showPendingNotifications()
{ {
trayIcon->setStatus(KStatusNotifierItem::Passive); trayIcon->setStatus(KStatusNotifierItem::Passive);
Q_FOREACH (KNotification* notification, pendingNotifications) { Q_FOREACH (KNotification* notification, pendingNotifications) {
@ -134,7 +122,7 @@ void NotificationPackageInterface::showPendingNotifications()
pendingNotifications.clear(); pendingNotifications.clear();
} }
bool NotificationPackageInterface::receivePackage(const Device& device, const NetworkPackage& np) bool TelephonyPlugin::receivePackage(const NetworkPackage& np)
{ {
if (np.type() != PACKAGE_TYPE_NOTIFICATION) return false; if (np.type() != PACKAGE_TYPE_NOTIFICATION) return false;
@ -147,7 +135,7 @@ bool NotificationPackageInterface::receivePackage(const Device& device, const Ne
} else { } else {
KNotification* n = createNotification(device.name(), np); KNotification* n = createNotification(np);
if (n != NULL) n->sendEvent(); if (n != NULL) n->sendEvent();
} }

View file

@ -18,33 +18,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef NOTIFICATIONPACKAGEINTERFACE_H #ifndef TELEPHONYPLUGIN_H
#define NOTIFICATIONPACKAGEINTERFACE_H #define TELEPHONYPLUGIN_H
#include <knotification.h> #include <knotification.h>
#include "packageinterface.h" #include "../kdeconnectplugin.h"
#include <KStatusNotifierItem> #include <KStatusNotifierItem>
class NotificationPackageInterface class TelephonyPlugin
: public PackageInterface : public KdeConnectPlugin
{ {
Q_OBJECT Q_OBJECT
public: public:
NotificationPackageInterface(QObject* parent = 0); explicit TelephonyPlugin(QObject *parent, const QVariantList &args);
virtual bool receivePackage(const Device&, const NetworkPackage& np); public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np);
void showPendingNotifications();
void notificationAttended();
private: private:
KNotification* createNotification(const QString& deviceName,const NetworkPackage& np); KNotification* createNotification(const NetworkPackage& np);
KStatusNotifierItem* trayIcon; KStatusNotifierItem* trayIcon;
QHash<QString, KNotification*> pendingNotifications; QHash<QString, KNotification*> pendingNotifications;
public slots:
void showPendingNotifications();
void notificationAttended();
}; };
#endif #endif