Remove KNotifications dependency from libkdeconnectcore

Moves the implementation into the actual daemon. This opens the
possibility for different ways to expose these notifications depending on
where the libkdeconnect will be deployed.

REVIEW: 123076
This commit is contained in:
Aleix Pol 2015-03-24 12:26:37 +01:00
parent b5420048f9
commit 8f777040f7
15 changed files with 79 additions and 22 deletions

View file

@ -11,7 +11,7 @@ find_package(ECM 0.0.9 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake)
find_package(Qt5 5.2 REQUIRED COMPONENTS Quick Test) find_package(Qt5 5.2 REQUIRED COMPONENTS Quick Test)
find_package(KF5 REQUIRED COMPONENTS I18n KIO Notifications ConfigWidgets DBusAddons KCMUtils IconThemes) find_package(KF5 REQUIRED COMPONENTS I18n KIO ConfigWidgets DBusAddons KCMUtils IconThemes)
find_package(Qca-qt5 2.1.0 REQUIRED) find_package(Qca-qt5 2.1.0 REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR})

View file

@ -41,7 +41,6 @@ PRIVATE
Qt5::Gui Qt5::Gui
KF5::I18n KF5::I18n
KF5::ConfigCore KF5::ConfigCore
KF5::Notifications
) )
set_target_properties(kdeconnectcore PROPERTIES set_target_properties(kdeconnectcore PROPERTIES

View file

@ -36,6 +36,8 @@
#include "backends/devicelink.h" #include "backends/devicelink.h"
#include "backends/linkprovider.h" #include "backends/linkprovider.h"
Q_GLOBAL_STATIC(Daemon*, s_instance)
struct DaemonPrivate struct DaemonPrivate
{ {
//Different ways to find devices and connect to them //Different ways to find devices and connect to them
@ -45,10 +47,18 @@ struct DaemonPrivate
QMap<QString, Device*> mDevices; QMap<QString, Device*> mDevices;
}; };
Daemon* Daemon::instance()
{
Q_ASSERT(s_instance.exists());
return *s_instance;
}
Daemon::Daemon(QObject *parent) Daemon::Daemon(QObject *parent)
: QObject(parent) : QObject(parent)
, d(new DaemonPrivate) , d(new DaemonPrivate)
{ {
Q_ASSERT(!s_instance.exists());
*s_instance = this;
qCDebug(KDECONNECT_CORE) << "KdeConnect daemon starting"; qCDebug(KDECONNECT_CORE) << "KdeConnect daemon starting";
//Load backends //Load backends

View file

@ -30,6 +30,7 @@
class DaemonPrivate; class DaemonPrivate;
class NetworkPackage; class NetworkPackage;
class DeviceLink; class DeviceLink;
class Device;
class KDECONNECTCORE_EXPORT Daemon class KDECONNECTCORE_EXPORT Daemon
: public QObject : public QObject
@ -42,6 +43,12 @@ public:
~Daemon(); ~Daemon();
public Q_SLOTS: public Q_SLOTS:
/**
* Returns the daemon.
*
* Note this can't be called before constructing the Daemon.
*/
static Daemon* instance();
//After calling this, signal deviceDiscovered will be triggered for each device //After calling this, signal deviceDiscovered will be triggered for each device
Q_SCRIPTABLE void setDiscoveryEnabled(bool b); Q_SCRIPTABLE void setDiscoveryEnabled(bool b);
@ -54,6 +61,9 @@ public Q_SLOTS:
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id //Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyVisible = false) const; Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyVisible = false) const;
virtual void requestPairing(Device *d) = 0;
virtual void reportError(const QString &title, const QString &description) = 0;
Q_SIGNALS: Q_SIGNALS:
Q_SCRIPTABLE void deviceAdded(const QString& id); Q_SCRIPTABLE void deviceAdded(const QString& id);
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed

View file

@ -30,7 +30,6 @@
#include <KSharedConfig> #include <KSharedConfig>
#include <KConfigGroup> #include <KConfigGroup>
#include <KNotification>
#include <KLocalizedString> #include <KLocalizedString>
#include <QIcon> #include <QIcon>
#include <QDir> #include <QDir>
@ -43,6 +42,7 @@
#include "backends/linkprovider.h" #include "backends/linkprovider.h"
#include "networkpackage.h" #include "networkpackage.h"
#include "kdeconnectconfig.h" #include "kdeconnectconfig.h"
#include "daemon.h"
Q_LOGGING_CATEGORY(KDECONNECT_CORE, "kdeconnect.core") Q_LOGGING_CATEGORY(KDECONNECT_CORE, "kdeconnect.core")
@ -352,21 +352,11 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
setAsPaired(); setAsPaired();
} else { } else {
qCDebug(KDECONNECT_CORE) << "Pair request"; qCDebug(KDECONNECT_CORE) << "Pair request";
KNotification* notification = new KNotification("pairingRequest"); Daemon::instance()->requestPairing(this);
notification->setIconName(QStringLiteral("dialog-information"));
notification->setComponentName("kdeconnect");
notification->setText(i18n("Pairing request from %1", m_deviceName));
notification->setActions(QStringList() << i18n("Accept") << i18n("Reject"));
connect(notification, &KNotification::ignored, this, &Device::rejectPairing);
connect(notification, &KNotification::action1Activated, this, &Device::acceptPairing);
connect(notification, &KNotification::action2Activated, this, &Device::rejectPairing);
notification->sendEvent();
m_pairStatus = Device::RequestedByPeer; m_pairStatus = Device::RequestedByPeer;
} }
} else { } else {

View file

@ -20,7 +20,6 @@
#include "kdeconnectconfig.h" #include "kdeconnectconfig.h"
#include <KNotification>
#include <KLocalizedString> #include <KLocalizedString>
#include <QtCrypto> #include <QtCrypto>
@ -37,6 +36,7 @@
#include "core_debug.h" #include "core_debug.h"
#include "dbushelper.h" #include "dbushelper.h"
#include "daemon.h"
struct KdeConnectConfigPrivate { struct KdeConnectConfigPrivate {
@ -61,9 +61,9 @@ KdeConnectConfig::KdeConnectConfig()
{ {
//qCDebug(KDECONNECT_CORE) << "QCA supported capabilities:" << QCA::supportedFeatures().join(","); //qCDebug(KDECONNECT_CORE) << "QCA supported capabilities:" << QCA::supportedFeatures().join(",");
if(!QCA::isSupported("rsa")) { if(!QCA::isSupported("rsa")) {
KNotification::event(KNotification::Error, Daemon::instance()->reportError(
QLatin1String("KDE Connect failed to start"), //Should not happen, not worth i18n i18n("KDE Connect failed to start"),
QLatin1String("Could not find support for RSA in your QCA installation. If your" i18n("Could not find support for RSA in your QCA installation. If your"
"distribution provides separate packages for QCA-ossl and QCA-gnupg," "distribution provides separate packages for QCA-ossl and QCA-gnupg,"
"make sure you have them installed and try again.")); "make sure you have them installed and try again."));
return; return;
@ -99,8 +99,7 @@ KdeConnectConfig::KdeConnectConfig()
d->privateKey = QCA::KeyGenerator().createRSA(2048); d->privateKey = QCA::KeyGenerator().createRSA(2048);
if (!privKey.open(QIODevice::ReadWrite | QIODevice::Truncate)) { if (!privKey.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
KNotification::event(KNotification::StandardEvent::Error, QLatin1String("KDE Connect"), Daemon::instance()->reportError(QLatin1String("KDE Connect"), i18n("Could not store private key file: %1", keyPath));
i18n("Could not store private key file: %1", keyPath));
} else { } else {
privKey.setPermissions(strict); privKey.setPermissions(strict);
privKey.write(d->privateKey.toPEM().toLatin1()); privKey.write(d->privateKey.toPEM().toLatin1());

View file

@ -1,9 +1,11 @@
project(kdeconnectd) project(kdeconnectd)
find_package(KF5 REQUIRED COMPONENTS Notifications)
add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-daemon") add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-daemon")
add_executable(kdeconnectd kdeconnectd.cpp) add_executable(kdeconnectd kdeconnectd.cpp)
target_link_libraries(kdeconnectd kdeconnectcore KF5::DBusAddons Qt5::Widgets) target_link_libraries(kdeconnectd kdeconnectcore KF5::DBusAddons KF5::Notifications KF5::I18n Qt5::Widgets)
configure_file(kdeconnectd.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop) configure_file(kdeconnectd.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop)
configure_file(org.kde.kdeconnect.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service) configure_file(org.kde.kdeconnect.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service)

View file

@ -27,8 +27,11 @@
#include <QApplication> #include <QApplication>
#include <KDBusService> #include <KDBusService>
#include <KNotification>
#include <KLocalizedString>
#include "core/daemon.h" #include "core/daemon.h"
#include "core/device.h"
#include "kdeconnect-version.h" #include "kdeconnect-version.h"
static int sigtermfd[2]; static int sigtermfd[2];
@ -58,6 +61,33 @@ void initializeTermHandlers(QCoreApplication* app, Daemon* daemon)
sigaction(SIGINT, &action, NULL); sigaction(SIGINT, &action, NULL);
} }
class DesktopDaemon : public Daemon
{
Q_OBJECT
public:
DesktopDaemon(QObject* parent = Q_NULLPTR)
: Daemon(parent)
{}
void requestPairing(Device* d) Q_DECL_OVERRIDE
{
KNotification* notification = new KNotification("pairingRequest");
notification->setIconName(QStringLiteral("dialog-information"));
notification->setComponentName("kdeconnect");
notification->setText(i18n("Pairing request from %1", d->name()));
notification->setActions(QStringList() << i18n("Accept") << i18n("Reject"));
connect(notification, &KNotification::ignored, d, &Device::rejectPairing);
connect(notification, &KNotification::action1Activated, d, &Device::acceptPairing);
connect(notification, &KNotification::action2Activated, d, &Device::rejectPairing);
notification->sendEvent();
}
void reportError(const QString & title, const QString & description) Q_DECL_OVERRIDE
{
KNotification::event(KNotification::Error, title, description);
}
};
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
@ -68,9 +98,11 @@ int main(int argc, char* argv[])
KDBusService dbusService(KDBusService::Unique); KDBusService dbusService(KDBusService::Unique);
Daemon* daemon = new Daemon(0); Daemon* daemon = new DesktopDaemon;
QObject::connect(daemon, SIGNAL(destroyed(QObject*)), &app, SLOT(quit())); QObject::connect(daemon, SIGNAL(destroyed(QObject*)), &app, SLOT(quit()));
initializeTermHandlers(&app, daemon); initializeTermHandlers(&app, daemon);
return app.exec(); return app.exec();
} }
#include "kdeconnectd.moc"

View file

@ -1,3 +1,5 @@
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_battery_SRCS set(kdeconnect_battery_SRCS
batteryplugin.cpp batteryplugin.cpp
batterydbusinterface.cpp batterydbusinterface.cpp

View file

@ -1,3 +1,5 @@
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_notifications_SRCS set(kdeconnect_notifications_SRCS
notification.cpp notification.cpp
notificationsplugin.cpp notificationsplugin.cpp

View file

@ -1,3 +1,5 @@
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_ping_SRCS set(kdeconnect_ping_SRCS
pingplugin.cpp pingplugin.cpp
) )

View file

@ -1,3 +1,5 @@
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_screensaver_inhibit_SRCS set(kdeconnect_screensaver_inhibit_SRCS
screensaverinhibitplugin.cpp screensaverinhibitplugin.cpp
) )

View file

@ -1,3 +1,5 @@
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_sftp_SRCS set(kdeconnect_sftp_SRCS
mounter.cpp mounter.cpp
mountloop.cpp mountloop.cpp

View file

@ -1,3 +1,5 @@
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_share_SRCS set(kdeconnect_share_SRCS
shareplugin.cpp shareplugin.cpp
autoclosingqfile.cpp autoclosingqfile.cpp
@ -27,6 +29,7 @@ target_link_libraries( kdeconnect_share_config
KF5::CoreAddons KF5::CoreAddons
KF5::ConfigWidgets KF5::ConfigWidgets
KF5::KIOWidgets KF5::KIOWidgets
KF5::Notifications
) )
install(TARGETS kdeconnect_share_config DESTINATION ${PLUGIN_INSTALL_DIR} ) install(TARGETS kdeconnect_share_config DESTINATION ${PLUGIN_INSTALL_DIR} )

View file

@ -1,3 +1,5 @@
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_telephony_SRCS set(kdeconnect_telephony_SRCS
telephonyplugin.cpp telephonyplugin.cpp
) )