Implemented notifications plugin
It exports a dbus interface to manipulate notifications
This commit is contained in:
parent
8627c8da51
commit
18b3945da0
3 changed files with 47 additions and 9 deletions
|
@ -3,7 +3,9 @@ include (KDE4Defaults)
|
|||
include_directories(${KDE4_INCLUDES})
|
||||
|
||||
set(kdeconnect_notifications_SRCS
|
||||
notification.cpp
|
||||
notificationsplugin.cpp
|
||||
notificationsdbusinterface.cpp
|
||||
../kdeconnectplugin.cpp
|
||||
../pluginloader.cpp
|
||||
../../networkpackage.cpp
|
||||
|
@ -21,3 +23,19 @@ target_link_libraries(kdeconnect_notifications
|
|||
|
||||
install(TARGETS kdeconnect_notifications DESTINATION ${PLUGIN_INSTALL_DIR} )
|
||||
install(FILES kdeconnect_notifications.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
|
||||
|
||||
include(../../../cmakemacros.txt)
|
||||
|
||||
generate_and_install_dbus_interface(
|
||||
kdeconnect_notifications
|
||||
notificationsdbusinterface.h
|
||||
org.kde.kdeconnect.device.notifications.xml
|
||||
OPTIONS -a
|
||||
)
|
||||
|
||||
generate_and_install_dbus_interface(
|
||||
kdeconnect_notifications
|
||||
notification.h
|
||||
org.kde.kdeconnect.device.notifications.notification.xml
|
||||
OPTIONS -a
|
||||
)
|
||||
|
|
|
@ -21,7 +21,10 @@
|
|||
#include "notificationsplugin.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <kicon.h>
|
||||
|
||||
#include <KIcon>
|
||||
|
||||
#include "notificationsdbusinterface.h"
|
||||
|
||||
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< NotificationsPlugin >(); )
|
||||
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_notifications", "kdeconnect_notifications") )
|
||||
|
@ -29,20 +32,32 @@ K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_notifications", "kdeconnect
|
|||
NotificationsPlugin::NotificationsPlugin(QObject* parent, const QVariantList& args)
|
||||
: KdeConnectPlugin(parent, args)
|
||||
{
|
||||
trayIcon = new KStatusNotifierItem(this);
|
||||
trayIcon->setIconByName("smartphone");
|
||||
trayIcon->setTitle(device()->name());
|
||||
notificationsDbusInterface = new NotificationsDbusInterface(device(), parent);
|
||||
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
|
||||
np.set("request",true);
|
||||
device()->sendPackage(np);
|
||||
}
|
||||
|
||||
NotificationsPlugin::~NotificationsPlugin()
|
||||
{
|
||||
delete trayIcon;
|
||||
//FIXME: Qt dbus does not allow to remove an adaptor! (it causes a crash in
|
||||
// the next dbus access to its parent). The implication of not deleting this
|
||||
// is that disabling the plugin does not remove the interface (that will
|
||||
// return outdated values) and that enabling it again instantiates a second
|
||||
// adaptor.
|
||||
|
||||
//notificationsDbusInterface->deleteLater();
|
||||
|
||||
}
|
||||
|
||||
bool NotificationsPlugin::receivePackage(const NetworkPackage& np)
|
||||
{
|
||||
if (np.type() != PACKAGE_TYPE_NOTIFICATION) return false;
|
||||
|
||||
notificationsDbusInterface->processPackage(np);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,14 +18,19 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NOTIFICATIONPACKAGEINTERFACE_H
|
||||
#define NOTIFICATIONPACKAGEINTERFACE_H
|
||||
#ifndef NOTIFICATIONSPLUGIN_H
|
||||
#define NOTIFICATIONSPLUGIN_H
|
||||
|
||||
#include <knotification.h>
|
||||
|
||||
#include "../kdeconnectplugin.h"
|
||||
|
||||
#include <KStatusNotifierItem>
|
||||
/*
|
||||
* This class is just a proxy for NotificationsDbusInterface
|
||||
* because it can not inherit from QDBusAbstractAdaptor and
|
||||
* KdeConnectPlugin at the same time (both are QObject)
|
||||
*/
|
||||
class NotificationsDbusInterface;
|
||||
|
||||
class NotificationsPlugin
|
||||
: public KdeConnectPlugin
|
||||
|
@ -40,7 +45,7 @@ public Q_SLOTS:
|
|||
virtual bool receivePackage(const NetworkPackage& np);
|
||||
|
||||
private:
|
||||
KStatusNotifierItem* trayIcon;
|
||||
NotificationsDbusInterface* notificationsDbusInterface;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue