Split plugins for sending and receiving notifications
CCMAIL: holger.k@elberer.de
This commit is contained in:
parent
932d8db6bc
commit
0b5fbe00bb
21 changed files with 256 additions and 136 deletions
|
@ -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)
|
||||
|
|
|
@ -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} )
|
||||
|
|
|
@ -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"
|
||||
],
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "notificationsplugin.h"
|
||||
|
||||
#include "notificationsdbusinterface.h"
|
||||
#include "notificationslistener.h"
|
||||
#include "notification_debug.h"
|
||||
|
||||
#include <KPluginFactory>
|
||||
|
@ -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()
|
||||
|
|
38
plugins/sendnotifications/CMakeLists.txt
Normal file
38
plugins/sendnotifications/CMakeLists.txt
Normal file
|
@ -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} )
|
29
plugins/sendnotifications/kdeconnect_sendnotifications.json
Normal file
29
plugins/sendnotifications/kdeconnect_sendnotifications.json
Normal file
|
@ -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"
|
||||
]
|
||||
}
|
|
@ -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]=إعدادات ملحقة مزامنة الإخطارات
|
|
@ -30,16 +30,13 @@
|
|||
#include <core/kdeconnectplugin.h>
|
||||
|
||||
#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>("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<NotifyingApplication>(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 << ":" <<ticker << "; appIcon=" << appIcon;
|
||||
//qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Sending notification from" << appName << ":" <<ticker << "; appIcon=" << appIcon;
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
|
||||
np.set("id", QString::number(replacesId > 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<QIODevice> iconFile(new QFile(iconPath));
|
||||
np.setPayload(iconFile, iconFile->size());
|
||||
}
|
|
@ -22,7 +22,6 @@
|
|||
#include <core/device.h>
|
||||
|
||||
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<QString, NotifyingApplication> applications;
|
||||
|
||||
public Q_SLOTS:
|
28
plugins/sendnotifications/sendnotification_debug.h
Normal file
28
plugins/sendnotifications/sendnotification_debug.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* Copyright 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
|
||||
*
|
||||
* 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 SENDNOTIFICATION_DEBUG_H
|
||||
#define SENDNOTIFICATION_DEBUG_H
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_SENDNOTIFICATION)
|
||||
|
||||
#endif //NOTIFICATION_DEBUG_H
|
|
@ -18,18 +18,18 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "notifications_config.h"
|
||||
#include "ui_notifications_config.h"
|
||||
#include "sendnotifications_config.h"
|
||||
#include "ui_sendnotifications_config.h"
|
||||
#include "notifyingapplicationmodel.h"
|
||||
|
||||
#include <KCModule>
|
||||
#include <KPluginFactory>
|
||||
|
||||
K_PLUGIN_FACTORY(NotificationsConfigFactory, registerPlugin<NotificationsConfig>();)
|
||||
K_PLUGIN_FACTORY(SendNotificationsConfigFactory, registerPlugin<SendNotificationsConfig>();)
|
||||
|
||||
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>("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"
|
|
@ -18,24 +18,24 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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;
|
||||
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NotificationsConfigUi</class>
|
||||
<widget class="QWidget" name="NotificationsConfigUi">
|
||||
<class>SendNotificationsConfigUi</class>
|
||||
<widget class="QWidget" name="SendNotificationsConfigUi">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::WindowModal</enum>
|
||||
</property>
|
54
plugins/sendnotifications/sendnotificationsplugin.cpp
Normal file
54
plugins/sendnotifications/sendnotificationsplugin.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* 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 "sendnotificationsplugin.h"
|
||||
|
||||
#include "notificationslistener.h"
|
||||
#include "sendnotification_debug.h"
|
||||
|
||||
#include <KPluginFactory>
|
||||
|
||||
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"
|
55
plugins/sendnotifications/sendnotificationsplugin.h
Normal file
55
plugins/sendnotifications/sendnotificationsplugin.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* 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 SENDNOTIFICATIONSPLUGIN_H
|
||||
#define SENDNOTIFICATIONSPLUGIN_H
|
||||
|
||||
#include <knotification.h>
|
||||
|
||||
#include <core/kdeconnectplugin.h>
|
||||
#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
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue