From 0b5fbe00bb663669854199a24cc1f0a127d12143 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Wed, 25 May 2016 12:49:13 -0600 Subject: [PATCH] Split plugins for sending and receiving notifications CCMAIL: holger.k@elberer.de --- plugins/CMakeLists.txt | 1 + plugins/notifications/CMakeLists.txt | 23 -------- .../kdeconnect_notifications.json | 50 +---------------- plugins/notifications/notificationsplugin.cpp | 2 - plugins/sendnotifications/CMakeLists.txt | 38 +++++++++++++ .../kdeconnect_sendnotifications.json | 29 ++++++++++ ...econnect_sendnotifications_config.desktop} | 4 +- .../notificationslistener.cpp | 29 +++++----- .../notificationslistener.h | 5 +- .../notifyingapplication.cpp | 0 .../notifyingapplication.h | 0 .../notifyingapplicationmodel.cpp | 0 .../notifyingapplicationmodel.h | 0 .../sendnotification_debug.h | 28 ++++++++++ .../sendnotifications_config.cpp} | 24 ++++---- .../sendnotifications_config.h} | 14 ++--- .../sendnotifications_config.ui} | 4 +- .../sendnotificationsplugin.cpp | 54 ++++++++++++++++++ .../sendnotificationsplugin.h | 55 +++++++++++++++++++ tests/CMakeLists.txt | 8 +-- tests/testnotificationlistener.cpp | 24 +++----- 21 files changed, 256 insertions(+), 136 deletions(-) create mode 100644 plugins/sendnotifications/CMakeLists.txt create mode 100644 plugins/sendnotifications/kdeconnect_sendnotifications.json rename plugins/{notifications/kdeconnect_notifications_config.desktop => sendnotifications/kdeconnect_sendnotifications_config.desktop} (93%) rename plugins/{notifications => sendnotifications}/notificationslistener.cpp (83%) rename plugins/{notifications => sendnotifications}/notificationslistener.h (87%) rename plugins/{notifications => sendnotifications}/notifyingapplication.cpp (100%) rename plugins/{notifications => sendnotifications}/notifyingapplication.h (100%) rename plugins/{notifications => sendnotifications}/notifyingapplicationmodel.cpp (100%) rename plugins/{notifications => sendnotifications}/notifyingapplicationmodel.h (100%) create mode 100644 plugins/sendnotifications/sendnotification_debug.h rename plugins/{notifications/notifications_config.cpp => sendnotifications/sendnotifications_config.cpp} (85%) rename plugins/{notifications/notifications_config.h => sendnotifications/sendnotifications_config.h} (81%) rename plugins/{notifications/notifications_config.ui => sendnotifications/sendnotifications_config.ui} (98%) create mode 100644 plugins/sendnotifications/sendnotificationsplugin.cpp create mode 100644 plugins/sendnotifications/sendnotificationsplugin.h diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index bc907493f..2a49306f4 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(clipboard) add_subdirectory(telephony) add_subdirectory(share) add_subdirectory(notifications) +add_subdirectory(sendnotifications) add_subdirectory(battery) add_subdirectory(runcommand) if(NOT WIN32) diff --git a/plugins/notifications/CMakeLists.txt b/plugins/notifications/CMakeLists.txt index d74cca6b2..6f7eb7230 100644 --- a/plugins/notifications/CMakeLists.txt +++ b/plugins/notifications/CMakeLists.txt @@ -4,8 +4,6 @@ set(kdeconnect_notifications_SRCS notification.cpp notificationsplugin.cpp notificationsdbusinterface.cpp - notificationslistener.cpp - notifyingapplication.cpp ) kdeconnect_add_plugin(kdeconnect_notifications JSON kdeconnect_notifications.json SOURCES ${kdeconnect_notifications_SRCS}) @@ -17,24 +15,3 @@ target_link_libraries(kdeconnect_notifications KF5::I18n KF5::IconThemes ) - -####################################### -# Config - -set( kdeconnect_notifications_config_SRCS - notifications_config.cpp - notifyingapplication.cpp - notifyingapplicationmodel.cpp -) -ki18n_wrap_ui( kdeconnect_notifications_config_SRCS notifications_config.ui ) - -add_library(kdeconnect_notifications_config MODULE ${kdeconnect_notifications_config_SRCS} ) -target_link_libraries( kdeconnect_notifications_config - kdeconnectcore - kdeconnectpluginkcm - KF5::I18n - KF5::KCMUtils -) - -install( TARGETS kdeconnect_notifications_config DESTINATION ${PLUGIN_INSTALL_DIR} ) -install( FILES kdeconnect_notifications_config.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) diff --git a/plugins/notifications/kdeconnect_notifications.json b/plugins/notifications/kdeconnect_notifications.json index d69643676..ee7a3ec76 100644 --- a/plugins/notifications/kdeconnect_notifications.json +++ b/plugins/notifications/kdeconnect_notifications.json @@ -8,58 +8,12 @@ "Name[x-test]": "xxAlbert Vacaxx" } ], - "Description": "Show phone notifications on your computer and keep them in sync", - "Description[ast]": "Amuesa los avisos del preséu nel to ordenador in caltiénlos sincronizaos", - "Description[ca@valencia]": "Mostra les notificacions del telèfon a l'ordinador i les manté sincronitzades", - "Description[ca]": "Mostra les notificacions del telèfon a l'ordinador i les manté sincronitzades", - "Description[cs]": "Zobrazit upozornění telefonu v počítači a udržovat je synchronizovaná", - "Description[de]": "Benachrichtigungen auf Ihren Rechner anzeigen und abgleichen", - "Description[es]": "Mostrar notificaciones del teléfono en su equipo y mantenerlas en sincronía", - "Description[fi]": "Näytä puhelimen ilmoitukset tietokoneellasi ja pidä ne ajan tasalla", - "Description[gl]": "Mostre notificacións dun teléfono móbil no computador e deixe que as notificacións se sincronicen co teléfono.", - "Description[hu]": "A telefon értesítéseinek megjelenítése a számítógépén és azok szinkronizációja", - "Description[it]": "Mostra le notifiche del telefono sul tuo computer e tienile sincronizzate", - "Description[ko]": "휴대폰 알림을 컴퓨터에 표시하기", - "Description[nl]": "Telefoonmeldingen op uw computer tonen en ze gesynchroniseerd houden", - "Description[nn]": "Vis telefonvarslingar på datamaskina, og hald dei synkronisert", - "Description[pl]": "Pokaż powiadomienia telefonu na swoim komputerze i synchronizuj je", - "Description[pt]": "Mostrar as notificações do telefone no seu computador e mantê-las sincronizadas", - "Description[pt_BR]": "Mostra as notificações do celular no seu computador e as mantém sincronizadas", - "Description[ru]": "Показ уведомлений с телефона на компьютере и их синхронизация", - "Description[sk]": "Zobraziť oznámenia telefónu na vašom počítači a udržať ich synchronizované", - "Description[sv]": "Visa telefonunderrättelser på datorn och håll dem synkroniserade", - "Description[tr]": "Telefon bildirimlerini bilgisayarınızla eşitler ve eşzamanlı tutar", - "Description[uk]": "Показ сповіщень з телефону на вашому комп’ютері та підтримання синхронізації даних сповіщень", - "Description[x-test]": "xxShow phone notifications on your computer and keep them in syncxx", - "Description[zh_CN]": "在电脑显示手机通知并保持同步", + "Description": "Show device's notifications on this computer and keep them in sync", "EnabledByDefault": true, "Icon": "preferences-desktop-notification", "Id": "kdeconnect_notifications", "License": "GPL", - "Name": "Notification sync", - "Name[ast]": "Sincronización d'avisos", - "Name[ca@valencia]": "Sincronització de les notificacions", - "Name[ca]": "Sincronització de les notificacions", - "Name[cs]": "Synchronizace upozornění", - "Name[de]": "Benachrichtigungs-Abgleich", - "Name[es]": "Sincronización de notificaciones", - "Name[fi]": "Ilmoitusten synkronointi", - "Name[gl]": "Sincronización de notificacións", - "Name[hu]": "Értesítésszinkronizáció", - "Name[it]": "Sincronizzazione notifiche", - "Name[ko]": "알림 동기화", - "Name[nl]": "Synchronisatie van meldingen", - "Name[nn]": "Synkronisering av varslingar", - "Name[pl]": "Powiadomienia synchronizacji", - "Name[pt]": "Sincronização de notificações", - "Name[pt_BR]": "Sincronização de notificações", - "Name[ru]": "Синхронизация уведомлений", - "Name[sk]": "Synchronizácia pripomienok", - "Name[sv]": "Underrättelsesynkronisering", - "Name[tr]": "Bildirim eşitleme", - "Name[uk]": "Синхронізація сповіщень", - "Name[x-test]": "xxNotification syncxx", - "Name[zh_CN]": "通知同步", + "Name": "Receive notifications", "ServiceTypes": [ "KdeConnect/Plugin" ], diff --git a/plugins/notifications/notificationsplugin.cpp b/plugins/notifications/notificationsplugin.cpp index f47f5d8dc..a21daaf6f 100644 --- a/plugins/notifications/notificationsplugin.cpp +++ b/plugins/notifications/notificationsplugin.cpp @@ -21,7 +21,6 @@ #include "notificationsplugin.h" #include "notificationsdbusinterface.h" -#include "notificationslistener.h" #include "notification_debug.h" #include @@ -34,7 +33,6 @@ NotificationsPlugin::NotificationsPlugin(QObject* parent, const QVariantList& ar : KdeConnectPlugin(parent, args) { notificationsDbusInterface = new NotificationsDbusInterface(this); - notificationsListener = new NotificationsListener(this, notificationsDbusInterface); } void NotificationsPlugin::connected() diff --git a/plugins/sendnotifications/CMakeLists.txt b/plugins/sendnotifications/CMakeLists.txt new file mode 100644 index 000000000..76ad88824 --- /dev/null +++ b/plugins/sendnotifications/CMakeLists.txt @@ -0,0 +1,38 @@ +find_package(KF5 REQUIRED COMPONENTS Notifications KCMUtils I18n IconThemes) + +set(kdeconnect_sendnotifications_SRCS + sendnotificationsplugin.cpp + notificationslistener.cpp + notifyingapplication.cpp +) + +kdeconnect_add_plugin(kdeconnect_sendnotifications JSON kdeconnect_sendnotifications.json SOURCES ${kdeconnect_sendnotifications_SRCS}) + +target_link_libraries(kdeconnect_sendnotifications + kdeconnectcore + Qt5::DBus + KF5::Notifications + KF5::I18n + KF5::IconThemes +) + +####################################### +# Config + +set( kdeconnect_sendnotifications_config_SRCS + sendnotifications_config.cpp + notifyingapplication.cpp + notifyingapplicationmodel.cpp +) +ki18n_wrap_ui( kdeconnect_sendnotifications_config_SRCS sendnotifications_config.ui ) + +add_library(kdeconnect_sendnotifications_config MODULE ${kdeconnect_sendnotifications_config_SRCS} ) +target_link_libraries( kdeconnect_sendnotifications_config + kdeconnectcore + kdeconnectpluginkcm + KF5::I18n + KF5::KCMUtils +) + +install( TARGETS kdeconnect_sendnotifications_config DESTINATION ${PLUGIN_INSTALL_DIR} ) +install( FILES kdeconnect_sendnotifications_config.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) diff --git a/plugins/sendnotifications/kdeconnect_sendnotifications.json b/plugins/sendnotifications/kdeconnect_sendnotifications.json new file mode 100644 index 000000000..8eb68a6df --- /dev/null +++ b/plugins/sendnotifications/kdeconnect_sendnotifications.json @@ -0,0 +1,29 @@ +{ + "Encoding": "UTF-8", + "KPlugin": { + "Authors": [ + { + "Email": "holger.k@elberer.de", + "Name": "Holger Kaelberer", + "Name[x-test]": "xxAlbert Vacaxx" + } + ], + "Description": "Broadcast this computer's notifications, so the can be shown in other devices.", + "EnabledByDefault": false, + "Icon": "preferences-desktop-notification", + "Id": "kdeconnect_sendnotifications", + "License": "GPL", + "Name": "Send notifications", + "ServiceTypes": [ + "KdeConnect/Plugin" + ], + "Version": "0.1", + "Website": "http://albertvaka.wordpress.com" + }, + "X-KdeConnect-OutgoingPackageType": [ + "kdeconnect.notification" + ], + "X-KdeConnect-SupportedPackageType": [ + "kdeconnect.notification" + ] +} \ No newline at end of file diff --git a/plugins/notifications/kdeconnect_notifications_config.desktop b/plugins/sendnotifications/kdeconnect_sendnotifications_config.desktop similarity index 93% rename from plugins/notifications/kdeconnect_notifications_config.desktop rename to plugins/sendnotifications/kdeconnect_sendnotifications_config.desktop index b582e1f97..51d937ab1 100644 --- a/plugins/notifications/kdeconnect_notifications_config.desktop +++ b/plugins/sendnotifications/kdeconnect_sendnotifications_config.desktop @@ -2,8 +2,8 @@ Type=Service X-KDE-ServiceTypes=KCModule -X-KDE-Library=kdeconnect_notifications_config -X-KDE-ParentComponents=kdeconnect_notifications +X-KDE-Library=kdeconnect_sendnotifications_config +X-KDE-ParentComponents=kdeconnect_sendnotifications Name=Notification synchronization plugin settings Name[ar]=إعدادات ملحقة مزامنة الإخطارات diff --git a/plugins/notifications/notificationslistener.cpp b/plugins/sendnotifications/notificationslistener.cpp similarity index 83% rename from plugins/notifications/notificationslistener.cpp rename to plugins/sendnotifications/notificationslistener.cpp index d21f3d733..9a51167d3 100644 --- a/plugins/notifications/notificationslistener.cpp +++ b/plugins/sendnotifications/notificationslistener.cpp @@ -30,16 +30,13 @@ #include #include "notificationslistener.h" -#include "notificationsplugin.h" -#include "notification_debug.h" -#include "notificationsdbusinterface.h" +#include "sendnotificationsplugin.h" +#include "sendnotification_debug.h" #include "notifyingapplication.h" -NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin, - NotificationsDbusInterface* aDbusInterface) +NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin) : QDBusAbstractAdaptor(aPlugin), - mPlugin(aPlugin), - dbusInterface(aDbusInterface) + mPlugin(aPlugin) { qRegisterMetaTypeStreamOperators("NotifyingApplication"); @@ -48,12 +45,12 @@ NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin, this, QDBusConnection::ExportScriptableContents); if (!ret) - qCWarning(KDECONNECT_PLUGIN_NOTIFICATION) + qCWarning(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Error registering notifications listener for device" << mPlugin->device()->name() << ":" << QDBusConnection::sessionBus().lastError(); else - qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) + qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Registered notifications listener for device" << mPlugin->device()->name(); @@ -69,7 +66,7 @@ NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin, NotificationsListener::~NotificationsListener() { - qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsListener"; + qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Destroying NotificationsListener"; QDBusInterface iface("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); QDBusMessage res = iface.call("RemoveMatch", @@ -86,7 +83,7 @@ void NotificationsListener::loadApplications() if (!applications.contains(app.name)) applications.insert(app.name, app); } - //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Loaded" << applications.size() << " applications"; + //qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Loaded" << applications.size() << " applications"; } uint NotificationsListener::Notify(const QString &appName, uint replacesId, @@ -98,7 +95,7 @@ uint NotificationsListener::Notify(const QString &appName, uint replacesId, static int id = 0; Q_UNUSED(actions); - //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Got notification appName=" << appName << "replacesId=" << replacesId << "appIcon=" << appIcon << "summary=" << summary << "body=" << body << "actions=" << actions << "hints=" << hints << "timeout=" << timeout; + //qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Got notification appName=" << appName << "replacesId=" << replacesId << "appIcon=" << appIcon << "summary=" << summary << "body=" << body << "actions=" << actions << "hints=" << hints << "timeout=" << timeout; // skip our own notifications if (appName == QLatin1String("KDE Connect")) @@ -117,7 +114,7 @@ uint NotificationsListener::Notify(const QString &appName, uint replacesId, for (const auto& a: applications.values()) list << QVariant::fromValue(a); mPlugin->config()->setList("applications", list); - //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Added new application to config:" << app; + //qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Added new application to config:" << app; } else app = applications.value(appName); @@ -146,7 +143,7 @@ uint NotificationsListener::Notify(const QString &appName, uint replacesId, app.blacklistExpression.match(ticker).hasMatch()) return 0; - //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Sending notification from" << appName << ":" < 0 ? replacesId : ++id)); np.set("appName", appName); @@ -166,11 +163,11 @@ uint NotificationsListener::Notify(const QString &appName, uint replacesId, KIconTheme hicolor(QStringLiteral("hicolor")); if (hicolor.isValid()) { iconPath = hicolor.iconPath(appIcon + ".png", size, KIconLoader::MatchBest); - //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Found non-png icon in default theme trying fallback to hicolor:" << iconPath; + //qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Found non-png icon in default theme trying fallback to hicolor:" << iconPath; } } if (iconPath.endsWith(QLatin1String(".png"))) { - //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Appending icon " << iconPath; + //qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Appending icon " << iconPath; QSharedPointer iconFile(new QFile(iconPath)); np.setPayload(iconFile, iconFile->size()); } diff --git a/plugins/notifications/notificationslistener.h b/plugins/sendnotifications/notificationslistener.h similarity index 87% rename from plugins/notifications/notificationslistener.h rename to plugins/sendnotifications/notificationslistener.h index dfa37b8a9..ac021efdc 100644 --- a/plugins/notifications/notificationslistener.h +++ b/plugins/sendnotifications/notificationslistener.h @@ -22,7 +22,6 @@ #include class KdeConnectPlugin; -class NotificationsDbusInterface; class Notification; struct NotifyingApplication; @@ -32,13 +31,11 @@ class NotificationsListener : public QDBusAbstractAdaptor Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications") public: - explicit NotificationsListener(KdeConnectPlugin* aPlugin, - NotificationsDbusInterface* aDbusInterface); + explicit NotificationsListener(KdeConnectPlugin* aPlugin); virtual ~NotificationsListener(); protected: KdeConnectPlugin* mPlugin; - NotificationsDbusInterface* dbusInterface; QHash applications; public Q_SLOTS: diff --git a/plugins/notifications/notifyingapplication.cpp b/plugins/sendnotifications/notifyingapplication.cpp similarity index 100% rename from plugins/notifications/notifyingapplication.cpp rename to plugins/sendnotifications/notifyingapplication.cpp diff --git a/plugins/notifications/notifyingapplication.h b/plugins/sendnotifications/notifyingapplication.h similarity index 100% rename from plugins/notifications/notifyingapplication.h rename to plugins/sendnotifications/notifyingapplication.h diff --git a/plugins/notifications/notifyingapplicationmodel.cpp b/plugins/sendnotifications/notifyingapplicationmodel.cpp similarity index 100% rename from plugins/notifications/notifyingapplicationmodel.cpp rename to plugins/sendnotifications/notifyingapplicationmodel.cpp diff --git a/plugins/notifications/notifyingapplicationmodel.h b/plugins/sendnotifications/notifyingapplicationmodel.h similarity index 100% rename from plugins/notifications/notifyingapplicationmodel.h rename to plugins/sendnotifications/notifyingapplicationmodel.h diff --git a/plugins/sendnotifications/sendnotification_debug.h b/plugins/sendnotifications/sendnotification_debug.h new file mode 100644 index 000000000..9050139ae --- /dev/null +++ b/plugins/sendnotifications/sendnotification_debug.h @@ -0,0 +1,28 @@ +/** + * Copyright 2014 Alejandro Fiestas Olivares + * + * 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 . + */ + +#ifndef SENDNOTIFICATION_DEBUG_H +#define SENDNOTIFICATION_DEBUG_H + +#include + +Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_SENDNOTIFICATION) + +#endif //NOTIFICATION_DEBUG_H diff --git a/plugins/notifications/notifications_config.cpp b/plugins/sendnotifications/sendnotifications_config.cpp similarity index 85% rename from plugins/notifications/notifications_config.cpp rename to plugins/sendnotifications/sendnotifications_config.cpp index d9532a78d..59a42dfe6 100644 --- a/plugins/notifications/notifications_config.cpp +++ b/plugins/sendnotifications/sendnotifications_config.cpp @@ -18,18 +18,18 @@ * along with this program. If not, see . */ -#include "notifications_config.h" -#include "ui_notifications_config.h" +#include "sendnotifications_config.h" +#include "ui_sendnotifications_config.h" #include "notifyingapplicationmodel.h" #include #include -K_PLUGIN_FACTORY(NotificationsConfigFactory, registerPlugin();) +K_PLUGIN_FACTORY(SendNotificationsConfigFactory, registerPlugin();) -NotificationsConfig::NotificationsConfig(QWidget *parent, const QVariantList& args) - : KdeConnectPluginKcm(parent, args, "kdeconnect_notifications_config") - , m_ui(new Ui::NotificationsConfigUi()) +SendNotificationsConfig::SendNotificationsConfig(QWidget *parent, const QVariantList& args) + : KdeConnectPluginKcm(parent, args, "kdeconnect_sendnotifications_config") + , m_ui(new Ui::SendNotificationsConfigUi()) , appModel(new NotifyingApplicationModel) { qRegisterMetaTypeStreamOperators("NotifyingApplication"); @@ -58,12 +58,12 @@ NotificationsConfig::NotificationsConfig(QWidget *parent, const QVariantList& ar connect(config(), SIGNAL(configChanged()), this, SLOT(loadApplications())); } -NotificationsConfig::~NotificationsConfig() +SendNotificationsConfig::~SendNotificationsConfig() { delete m_ui; } -void NotificationsConfig::defaults() +void SendNotificationsConfig::defaults() { KCModule::defaults(); m_ui->check_persistent->setChecked(false); @@ -73,7 +73,7 @@ void NotificationsConfig::defaults() Q_EMIT changed(true); } -void NotificationsConfig::loadApplications() +void SendNotificationsConfig::loadApplications() { appModel->clearApplications(); QVariantList list = config()->getList("applications"); @@ -85,7 +85,7 @@ void NotificationsConfig::loadApplications() } } -void NotificationsConfig::load() +void SendNotificationsConfig::load() { KCModule::load(); bool persistent = config()->get("generalPersistent", false); @@ -101,7 +101,7 @@ void NotificationsConfig::load() Q_EMIT changed(false); } -void NotificationsConfig::save() +void SendNotificationsConfig::save() { config()->set("generalPersistent", m_ui->check_persistent->isChecked()); config()->set("generalIncludeBody", m_ui->check_body->isChecked()); @@ -116,4 +116,4 @@ void NotificationsConfig::save() Q_EMIT changed(false); } -#include "notifications_config.moc" +#include "sendnotifications_config.moc" diff --git a/plugins/notifications/notifications_config.h b/plugins/sendnotifications/sendnotifications_config.h similarity index 81% rename from plugins/notifications/notifications_config.h rename to plugins/sendnotifications/sendnotifications_config.h index fedbfc6c8..3a5b17675 100644 --- a/plugins/notifications/notifications_config.h +++ b/plugins/sendnotifications/sendnotifications_config.h @@ -18,24 +18,24 @@ * along with this program. If not, see . */ -#ifndef NOTIFICATIONS_CONFIG_H -#define NOTIFICATIONS_CONFIG_H +#ifndef SENDNOTIFICATIONS_CONFIG_H +#define SENDNOTIFICATIONS_CONFIG_H #include "kcmplugin/kdeconnectpluginkcm.h" namespace Ui { - class NotificationsConfigUi; + class SendNotificationsConfigUi; } class NotifyingApplicationModel; -class NotificationsConfig +class SendNotificationsConfig : public KdeConnectPluginKcm { Q_OBJECT public: - NotificationsConfig(QWidget *parent, const QVariantList&); - virtual ~NotificationsConfig(); + SendNotificationsConfig(QWidget *parent, const QVariantList&); + virtual ~SendNotificationsConfig(); public Q_SLOTS: virtual void save() override; @@ -46,7 +46,7 @@ private Q_SLOTS: void loadApplications(); private: - Ui::NotificationsConfigUi* m_ui; + Ui::SendNotificationsConfigUi* m_ui; NotifyingApplicationModel* appModel; }; diff --git a/plugins/notifications/notifications_config.ui b/plugins/sendnotifications/sendnotifications_config.ui similarity index 98% rename from plugins/notifications/notifications_config.ui rename to plugins/sendnotifications/sendnotifications_config.ui index 83b26cc02..c1ef29a70 100644 --- a/plugins/notifications/notifications_config.ui +++ b/plugins/sendnotifications/sendnotifications_config.ui @@ -1,7 +1,7 @@ - NotificationsConfigUi - + SendNotificationsConfigUi + Qt::WindowModal diff --git a/plugins/sendnotifications/sendnotificationsplugin.cpp b/plugins/sendnotifications/sendnotificationsplugin.cpp new file mode 100644 index 000000000..40dcf8c36 --- /dev/null +++ b/plugins/sendnotifications/sendnotificationsplugin.cpp @@ -0,0 +1,54 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "sendnotificationsplugin.h" + +#include "notificationslistener.h" +#include "sendnotification_debug.h" + +#include + +K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_sendnotifications.json", registerPlugin< SendNotificationsPlugin >(); ) + +Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_SENDNOTIFICATION, "kdeconnect.plugin.sendnotification") + +SendNotificationsPlugin::SendNotificationsPlugin(QObject* parent, const QVariantList& args) + : KdeConnectPlugin(parent, args) +{ + notificationsListener = new NotificationsListener(this); +} + +SendNotificationsPlugin::~SendNotificationsPlugin() +{ + delete notificationsListener; +} + +bool SendNotificationsPlugin::receivePackage(const NetworkPackage& np) +{ + Q_UNUSED(np); + return true; +} + +void SendNotificationsPlugin::connected() +{ + +} + +#include "sendnotificationsplugin.moc" diff --git a/plugins/sendnotifications/sendnotificationsplugin.h b/plugins/sendnotifications/sendnotificationsplugin.h new file mode 100644 index 000000000..fcb893546 --- /dev/null +++ b/plugins/sendnotifications/sendnotificationsplugin.h @@ -0,0 +1,55 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef SENDNOTIFICATIONSPLUGIN_H +#define SENDNOTIFICATIONSPLUGIN_H + +#include + +#include +#define PACKAGE_TYPE_NOTIFICATION QLatin1String("kdeconnect.notification") + +/* + * 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 NotificationsListener; + +class SendNotificationsPlugin + : public KdeConnectPlugin +{ + Q_OBJECT + +public: + explicit SendNotificationsPlugin(QObject *parent, const QVariantList &args); + virtual ~SendNotificationsPlugin(); + +public Q_SLOTS: + virtual bool receivePackage(const NetworkPackage& np) override; + virtual void connected() override; + +protected: + NotificationsListener* notificationsListener; + +}; + +#endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 812b4a350..54d7e09cd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,10 +20,8 @@ ecm_add_test(networkpackagetests.cpp LINK_LIBRARIES ${kdeconnect_libraries}) ecm_add_test(testsocketlinereader.cpp ../core/backends/lan/socketlinereader.cpp TEST_NAME testsocketlinereader LINK_LIBRARIES ${kdeconnect_libraries}) ecm_add_test(downloadjobtest.cpp ../core/backends/lan/downloadjob.cpp TEST_NAME downloadjobtest LINK_LIBRARIES ${kdeconnect_libraries}) ecm_add_test(testnotificationlistener.cpp - ../plugins/notifications/notificationslistener.cpp - ../plugins/notifications/notificationsplugin.cpp - ../plugins/notifications/notification.cpp - ../plugins/notifications/notifyingapplication.cpp - ../plugins/notifications/notificationsdbusinterface.cpp + ../plugins/sendnotifications/sendnotificationsplugin.cpp + ../plugins/sendnotifications/notificationslistener.cpp + ../plugins/sendnotifications/notifyingapplication.cpp TEST_NAME testnotificationlistener LINK_LIBRARIES ${kdeconnect_libraries} Qt5::DBus KF5::Notifications KF5::IconThemes) diff --git a/tests/testnotificationlistener.cpp b/tests/testnotificationlistener.cpp index b43a7d394..45597fa5b 100644 --- a/tests/testnotificationlistener.cpp +++ b/tests/testnotificationlistener.cpp @@ -31,18 +31,17 @@ #include "core/device.h" #include "core/kdeconnectplugin.h" #include "kdeconnect-version.h" -#include "plugins/notifications/notificationsplugin.h" -#include "plugins/notifications/notificationslistener.h" -#include "plugins/notifications/notificationsdbusinterface.h" -#include "plugins/notifications/notifyingapplication.h" +#include "plugins/sendnotifications/sendnotificationsplugin.h" +#include "plugins/sendnotifications/notificationslistener.h" +#include "plugins/sendnotifications/notifyingapplication.h" // Tweaked NotificationsPlugin for testing -class TestNotificationsPlugin : public NotificationsPlugin +class TestNotificationsPlugin : public SendNotificationsPlugin { Q_OBJECT public: explicit TestNotificationsPlugin(QObject *parent, const QVariantList &args) - : NotificationsPlugin(parent, args) + : SendNotificationsPlugin(parent, args) { } @@ -59,10 +58,6 @@ public: notificationsListener = value; } - NotificationsDbusInterface* getNotificationsDbusInterface() const - { - return notificationsDbusInterface; - } }; // Tweaked Device for testing: @@ -116,9 +111,8 @@ class TestedNotificationsListener: public NotificationsListener { public: - explicit TestedNotificationsListener(KdeConnectPlugin* aPlugin, - NotificationsDbusInterface* aDbusInterface) - : NotificationsListener(aPlugin, aDbusInterface) + explicit TestedNotificationsListener(KdeConnectPlugin* aPlugin) + : NotificationsListener(aPlugin) {} virtual ~TestedNotificationsListener() @@ -160,7 +154,7 @@ void TestNotificationListener::testNotify() // QString dId("testid"); - TestDevice *d = new TestDevice(nullptr, dId); // not setting any parent or we will double free the dbusInterface + TestDevice *d = new TestDevice(nullptr, dId); int proxiedNotifications = 0; QCOMPARE(proxiedNotifications, d->getSentPackages()); @@ -172,7 +166,7 @@ void TestNotificationListener::testNotify() delete plugin->getNotificationsListener(); // inject our tweaked NotificationsListener: - TestedNotificationsListener* listener = new TestedNotificationsListener(plugin, plugin->getNotificationsDbusInterface()); + TestedNotificationsListener* listener = new TestedNotificationsListener(plugin); QVERIFY(listener); plugin->setNotificationsListener(listener); QCOMPARE(listener, plugin->getNotificationsListener());