Commit 8f777040 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

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
parent b5420048
......@@ -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)
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)
include_directories(${CMAKE_SOURCE_DIR})
......
......@@ -41,7 +41,6 @@ PRIVATE
Qt5::Gui
KF5::I18n
KF5::ConfigCore
KF5::Notifications
)
set_target_properties(kdeconnectcore PROPERTIES
......
......@@ -36,6 +36,8 @@
#include "backends/devicelink.h"
#include "backends/linkprovider.h"
Q_GLOBAL_STATIC(Daemon*, s_instance)
struct DaemonPrivate
{
//Different ways to find devices and connect to them
......@@ -45,10 +47,18 @@ struct DaemonPrivate
QMap<QString, Device*> mDevices;
};
Daemon* Daemon::instance()
{
Q_ASSERT(s_instance.exists());
return *s_instance;
}
Daemon::Daemon(QObject *parent)
: QObject(parent)
, d(new DaemonPrivate)
{
Q_ASSERT(!s_instance.exists());
*s_instance = this;
qCDebug(KDECONNECT_CORE) << "KdeConnect daemon starting";
//Load backends
......
......@@ -30,6 +30,7 @@
class DaemonPrivate;
class NetworkPackage;
class DeviceLink;
class Device;
class KDECONNECTCORE_EXPORT Daemon
: public QObject
......@@ -42,6 +43,12 @@ public:
~Daemon();
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
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
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_SCRIPTABLE void deviceAdded(const QString& id);
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
......
......@@ -30,7 +30,6 @@
#include <KSharedConfig>
#include <KConfigGroup>
#include <KNotification>
#include <KLocalizedString>
#include <QIcon>
#include <QDir>
......@@ -43,6 +42,7 @@
#include "backends/linkprovider.h"
#include "networkpackage.h"
#include "kdeconnectconfig.h"
#include "daemon.h"
Q_LOGGING_CATEGORY(KDECONNECT_CORE, "kdeconnect.core")
......@@ -352,21 +352,11 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
setAsPaired();
} else {
qCDebug(KDECONNECT_CORE) << "Pair request";
KNotification* notification = new KNotification("pairingRequest");
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();
Daemon::instance()->requestPairing(this);
m_pairStatus = Device::RequestedByPeer;
}
} else {
......
......@@ -20,7 +20,6 @@
#include "kdeconnectconfig.h"
#include <KNotification>
#include <KLocalizedString>
#include <QtCrypto>
......@@ -37,6 +36,7 @@
#include "core_debug.h"
#include "dbushelper.h"
#include "daemon.h"
struct KdeConnectConfigPrivate {
......@@ -61,9 +61,9 @@ KdeConnectConfig::KdeConnectConfig()
{
//qCDebug(KDECONNECT_CORE) << "QCA supported capabilities:" << QCA::supportedFeatures().join(",");
if(!QCA::isSupported("rsa")) {
KNotification::event(KNotification::Error,
QLatin1String("KDE Connect failed to start"), //Should not happen, not worth i18n
QLatin1String("Could not find support for RSA in your QCA installation. If your"
Daemon::instance()->reportError(
i18n("KDE Connect failed to start"),
i18n("Could not find support for RSA in your QCA installation. If your"
"distribution provides separate packages for QCA-ossl and QCA-gnupg,"
"make sure you have them installed and try again."));
return;
......@@ -99,8 +99,7 @@ KdeConnectConfig::KdeConnectConfig()
d->privateKey = QCA::KeyGenerator().createRSA(2048);
if (!privKey.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
KNotification::event(KNotification::StandardEvent::Error, QLatin1String("KDE Connect"),
i18n("Could not store private key file: %1", keyPath));
Daemon::instance()->reportError(QLatin1String("KDE Connect"), i18n("Could not store private key file: %1", keyPath));
} else {
privKey.setPermissions(strict);
privKey.write(d->privateKey.toPEM().toLatin1());
......
project(kdeconnectd)
find_package(KF5 REQUIRED COMPONENTS Notifications)
add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-daemon")
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(org.kde.kdeconnect.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service)
......
......@@ -27,8 +27,11 @@
#include <QApplication>
#include <KDBusService>
#include <KNotification>
#include <KLocalizedString>
#include "core/daemon.h"
#include "core/device.h"
#include "kdeconnect-version.h"
static int sigtermfd[2];
......@@ -58,6 +61,33 @@ void initializeTermHandlers(QCoreApplication* app, Daemon* daemon)
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[])
{
QApplication app(argc, argv);
......@@ -68,9 +98,11 @@ int main(int argc, char* argv[])
KDBusService dbusService(KDBusService::Unique);
Daemon* daemon = new Daemon(0);
Daemon* daemon = new DesktopDaemon;
QObject::connect(daemon, SIGNAL(destroyed(QObject*)), &app, SLOT(quit()));
initializeTermHandlers(&app, daemon);
return app.exec();
}
#include "kdeconnectd.moc"
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_battery_SRCS
batteryplugin.cpp
batterydbusinterface.cpp
......
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_notifications_SRCS
notification.cpp
notificationsplugin.cpp
......
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_ping_SRCS
pingplugin.cpp
)
......
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_screensaver_inhibit_SRCS
screensaverinhibitplugin.cpp
)
......
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_sftp_SRCS
mounter.cpp
mountloop.cpp
......
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_share_SRCS
shareplugin.cpp
autoclosingqfile.cpp
......@@ -27,6 +29,7 @@ target_link_libraries( kdeconnect_share_config
KF5::CoreAddons
KF5::ConfigWidgets
KF5::KIOWidgets
KF5::Notifications
)
install(TARGETS kdeconnect_share_config DESTINATION ${PLUGIN_INSTALL_DIR} )
......
find_package(KF5 REQUIRED COMPONENTS Notifications)
set(kdeconnect_telephony_SRCS
telephonyplugin.cpp
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment