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:
parent
238d81a408
commit
925e3abb3e
5 changed files with 59 additions and 35 deletions
|
@ -5,3 +5,4 @@ add_subdirectory(ping)
|
|||
add_subdirectory(pausemusic)
|
||||
add_subdirectory(mpriscontrol)
|
||||
add_subdirectory(clipboard)
|
||||
add_subdirectory(telephony)
|
20
daemon/plugins/telephony/CMakeLists.txt
Normal file
20
daemon/plugins/telephony/CMakeLists.txt
Normal 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} )
|
15
daemon/plugins/telephony/kdeconnect_telephony.desktop
Normal file
15
daemon/plugins/telephony/kdeconnect_telephony.desktop
Normal 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
|
|
@ -18,23 +18,21 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "notificationpackageinterface.h"
|
||||
#include "telephonyplugin.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <kicon.h>
|
||||
|
||||
NotificationPackageInterface::NotificationPackageInterface(QObject* parent)
|
||||
: PackageInterface(parent)
|
||||
TelephonyPlugin::TelephonyPlugin(QObject *parent, const QVariantList &args)
|
||||
: KdeConnectPlugin(parent, args)
|
||||
{
|
||||
//TODO: Split in EventNotificationInterface and NotificationDrawerSyncInterface
|
||||
|
||||
trayIcon = new KStatusNotifierItem(parent);
|
||||
trayIcon->setIconByName("pda");
|
||||
trayIcon->setTitle("KdeConnect");
|
||||
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());
|
||||
|
@ -44,8 +42,7 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
|
|||
QString title, content, type, icon;
|
||||
bool transient;
|
||||
|
||||
title = deviceName;
|
||||
|
||||
title = device()->name();
|
||||
|
||||
if (npType == "ringing") {
|
||||
type = "callReceived";
|
||||
|
@ -65,16 +62,6 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
|
|||
+ ":\n"
|
||||
+ np.get<QString>("messageBody","");
|
||||
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 {
|
||||
//TODO: return NULL if !debug
|
||||
type = "unknownEvent";
|
||||
|
@ -89,7 +76,7 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
|
|||
if (transient) {
|
||||
trayIcon->setStatus(KStatusNotifierItem::Active);
|
||||
|
||||
KNotification* notification = new KNotification(type); //KNotification::Persistent
|
||||
KNotification* notification = new KNotification(type);
|
||||
notification->setPixmap(KIcon(icon).pixmap(48, 48));
|
||||
notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
|
||||
notification->setTitle(title);
|
||||
|
@ -98,7 +85,8 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
|
|||
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->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
|
||||
notification->setTitle(title);
|
||||
|
@ -112,7 +100,7 @@ KNotification* NotificationPackageInterface::createNotification(const QString& d
|
|||
|
||||
}
|
||||
|
||||
void NotificationPackageInterface::notificationAttended()
|
||||
void TelephonyPlugin::notificationAttended()
|
||||
{
|
||||
KNotification* normalNotification = (KNotification*)sender();
|
||||
QString id = normalNotification->property("id").toString();
|
||||
|
@ -125,7 +113,7 @@ void NotificationPackageInterface::notificationAttended()
|
|||
}
|
||||
}
|
||||
|
||||
void NotificationPackageInterface::showPendingNotifications()
|
||||
void TelephonyPlugin::showPendingNotifications()
|
||||
{
|
||||
trayIcon->setStatus(KStatusNotifierItem::Passive);
|
||||
Q_FOREACH (KNotification* notification, pendingNotifications) {
|
||||
|
@ -134,7 +122,7 @@ void NotificationPackageInterface::showPendingNotifications()
|
|||
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;
|
||||
|
@ -147,7 +135,7 @@ bool NotificationPackageInterface::receivePackage(const Device& device, const Ne
|
|||
|
||||
} else {
|
||||
|
||||
KNotification* n = createNotification(device.name(), np);
|
||||
KNotification* n = createNotification(np);
|
||||
if (n != NULL) n->sendEvent();
|
||||
|
||||
}
|
|
@ -18,33 +18,33 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NOTIFICATIONPACKAGEINTERFACE_H
|
||||
#define NOTIFICATIONPACKAGEINTERFACE_H
|
||||
#ifndef TELEPHONYPLUGIN_H
|
||||
#define TELEPHONYPLUGIN_H
|
||||
|
||||
#include <knotification.h>
|
||||
|
||||
#include "packageinterface.h"
|
||||
#include "../kdeconnectplugin.h"
|
||||
|
||||
#include <KStatusNotifierItem>
|
||||
|
||||
class NotificationPackageInterface
|
||||
: public PackageInterface
|
||||
class TelephonyPlugin
|
||||
: public KdeConnectPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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:
|
||||
KNotification* createNotification(const QString& deviceName,const NetworkPackage& np);
|
||||
KNotification* createNotification(const NetworkPackage& np);
|
||||
KStatusNotifierItem* trayIcon;
|
||||
QHash<QString, KNotification*> pendingNotifications;
|
||||
|
||||
public slots:
|
||||
void showPendingNotifications();
|
||||
void notificationAttended();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue