diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index f25edbcc5..d412396a7 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -18,6 +18,7 @@ set(kded_kdeconnect_SRCS kdeconnectplugin.cpp pluginloader.cpp + kdeconnectconfig.cpp dbushelper.cpp networkpackage.cpp filetransferjob.cpp diff --git a/core/backends/devicelink.cpp b/core/backends/devicelink.cpp index 4f90754d8..e4a13ca1b 100644 --- a/core/backends/devicelink.cpp +++ b/core/backends/devicelink.cpp @@ -19,6 +19,7 @@ */ #include "devicelink.h" +#include "kdeconnectconfig.h" #include "linkprovider.h" DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent) @@ -29,5 +30,7 @@ DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent) Q_ASSERT(!deviceId.isEmpty()); setProperty("deviceId", deviceId); + + mPrivateKey = KdeConnectConfig::instance()->privateKey(); } diff --git a/core/backends/devicelink.h b/core/backends/devicelink.h index f8d652175..af1fe1251 100644 --- a/core/backends/devicelink.h +++ b/core/backends/devicelink.h @@ -44,8 +44,6 @@ public: virtual bool sendPackage(NetworkPackage& np) = 0; virtual bool sendPackageEncrypted(QCA::PublicKey& publicKey, NetworkPackage& np) = 0; - void setPrivateKey(const QCA::PrivateKey& privateKey) { mPrivateKey = privateKey; } - Q_SIGNALS: void receivedPackage(const NetworkPackage& np); diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index fb819d160..f289e9722 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -30,10 +30,8 @@ #include #include -#include -#include - #include "landevicelink.h" +#include void LanLinkProvider::configureSocket(QTcpSocket* socket) { @@ -124,10 +122,7 @@ void LanLinkProvider::newUdpConnection() return; } - KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc"); - const QString myId = config->group("myself").readEntry("id",""); - - if (receivedPackage->get("deviceId") == myId) { + if (receivedPackage->get("deviceId") == KdeConnectConfig::instance()->deviceId()) { //kDebug(debugArea()) << "Ignoring my own broadcast"; delete receivedPackage; return; diff --git a/core/daemon.cpp b/core/daemon.cpp index bbdc073e5..e7fff1ed6 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -20,23 +20,14 @@ #include "daemon.h" -#include -#include -#include -#include #include #include #include -#include -#include #include - -#include -#include -#include +#include #include "core_debug.h" -#include "dbushelper.h" +#include "kdeconnectconfig.h" #include "networkpackage.h" #include "backends/lan/lanlinkprovider.h" #include "backends/loopback/loopbacklinkprovider.h" @@ -45,7 +36,6 @@ #include "backends/devicelink.h" #include "backends/linkprovider.h" -#include struct DaemonPrivate { //Different ways to find devices and connect to them @@ -53,10 +43,6 @@ struct DaemonPrivate //Every known device QMap mDevices; - - // The Initializer object sets things up, and also does cleanup when it goes out of scope - // Note it's not being used anywhere. That's inteneded - QCA::Initializer mQcaInitializer; }; Daemon::Daemon(QObject *parent) @@ -65,63 +51,12 @@ Daemon::Daemon(QObject *parent) { qCDebug(KDECONNECT_CORE) << "KdeConnect daemon starting"; - KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc"); - - if (!config->group("myself").hasKey("id")) { - QString uuid = QUuid::createUuid().toString(); - DbusHelper::filterNonExportableCharacters(uuid); - config->group("myself").writeEntry("id", uuid); - config->sync(); - qCDebug(KDECONNECT_CORE) << "My id:" << uuid; - } - - //qCDebug(KDECONNECT_CORE) << "QCA supported capabilities:" << QCA::supportedFeatures().join(","); - if(!QCA::isSupported("rsa")) { - //TODO: Display this in a notification or another visible way - qCCritical(KDECONNECT_CORE) << "Error: KDE Connect could not find support for RSA in your QCA installation, if your distribution provides" - << "separate packages for QCA-ossl and QCA-gnupg plugins, make sure you have them installed and try again"; - return; - } - - const QFile::Permissions strict = QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser; - - const QString privateKeyPath = Device::privateKeyPath(); - if (!QFile::exists(privateKeyPath)) - { - QDir::root().mkpath(QFileInfo(privateKeyPath).dir().path()); - - QFile privKey(privateKeyPath); - - if (!privKey.open(QIODevice::ReadWrite | QIODevice::Truncate)) - { - qCCritical(KDECONNECT_CORE) << "Error: KDE Connect could not create private keys file: " << privateKeyPath; - return; - } - - if (!privKey.setPermissions(strict)) - { - qCDebug(KDECONNECT_CORE) << "Error: KDE Connect could not set permissions for private file: " << privateKeyPath; - } - - privKey.write(QCA::KeyGenerator().createRSA(2048).toPEM().toLatin1()); - } - - if (QFile::permissions(privateKeyPath) != strict) - { - qCDebug(KDECONNECT_CORE) << "Error: KDE Connect detects wrong permissions for private file " << privateKeyPath; - } - - //Register on DBus - QDBusConnection::sessionBus().registerService("org.kde.kdeconnect"); - QDBusConnection::sessionBus().registerObject("/modules/kdeconnect", this, QDBusConnection::ExportScriptableContents); - - //Load backends (hardcoded by now, should be plugins in a future) + //Load backends d->mLinkProviders.insert(new LanLinkProvider()); //d->mLinkProviders.insert(new LoopbackLinkProvider()); //Read remebered paired devices - const KConfigGroup& known = config->group("trusted_devices"); - const QStringList& list = known.groupList(); + const QStringList& list = KdeConnectConfig::instance()->trustedDevices(); Q_FOREACH(const QString& id, list) { Device* device = new Device(this, id); connect(device, SIGNAL(reachableStatusChanged()), @@ -147,6 +82,10 @@ Daemon::Daemon(QObject *parent) a, SLOT(onNetworkChange(QNetworkSession::State))); } + //Register on DBus + QDBusConnection::sessionBus().registerService("org.kde.kdeconnect"); + QDBusConnection::sessionBus().registerObject("/modules/kdeconnect", this, QDBusConnection::ExportScriptableContents); + qCDebug(KDECONNECT_CORE) << "KdeConnect daemon started"; } @@ -158,7 +97,6 @@ void Daemon::setDiscoveryEnabled(bool b) else a->onStop(); } - } void Daemon::forceOnNetworkChange() @@ -181,7 +119,6 @@ QStringList Daemon::devices(bool onlyReachable, bool onlyVisible) const void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl) { - const QString& id = identityPackage.get("deviceId"); //qCDebug(KDECONNECT_CORE) << "Device discovered" << id << "via" << dl->provider()->name(); @@ -201,12 +138,10 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* } Q_EMIT deviceVisibilityChanged(id, true); - } void Daemon::onDeviceReachableStatusChanged() { - Device* device = (Device*)sender(); QString id = device->id(); @@ -217,6 +152,7 @@ void Daemon::onDeviceReachableStatusChanged() if (!device->isReachable()) { if (!device->isPaired()) { + qCDebug(KDECONNECT_CORE) << "Destroying device" << device->name(); Q_EMIT deviceRemoved(id); d->mDevices.remove(id); @@ -224,7 +160,6 @@ void Daemon::onDeviceReachableStatusChanged() } } - } Daemon::~Daemon() diff --git a/core/device.cpp b/core/device.cpp index 530bb090a..67030ff01 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "core_debug.h" #include "kdeconnectplugin.h" @@ -40,39 +41,21 @@ #include "backends/devicelink.h" #include "backends/linkprovider.h" #include "networkpackage.h" +#include "kdeconnectconfig.h" Q_LOGGING_CATEGORY(KDECONNECT_CORE, "kdeconnect.core") -QCA::PrivateKey initPrivateKey() -{ - QCA::PrivateKey ret; - QFile privKey(Device::privateKeyPath()); - if (privKey.open(QIODevice::ReadOnly)) - ret = QCA::PrivateKey::fromPEM(privKey.readAll()); - else { - qWarning() << "Could not open the private key" << Device::privateKeyPath(); - } - - Q_ASSERT(!ret.isNull()); - - return ret; -} -Q_GLOBAL_STATIC_WITH_ARGS(QCA::PrivateKey, s_privateKey, (initPrivateKey())) - Device::Device(QObject* parent, const QString& id) : QObject(parent) , m_deviceId(id) , m_pairStatus(Device::Paired) , m_protocolVersion(NetworkPackage::ProtocolVersion) //We don't know it yet { - KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc"); - KConfigGroup data = config->group("trusted_devices").group(id); + KdeConnectConfig::DeviceInfo info = KdeConnectConfig::instance()->getTrustedDevice(id); - m_deviceName = data.readEntry("deviceName", QLatin1String("unnamed")); - m_deviceType = str2type(data.readEntry("deviceType", QLatin1String("unknown"))); - - const QString& key = data.readEntry("publicKey", QString()); - m_publicKey = QCA::RSAPublicKey::fromPEM(key); + m_deviceName = info.deviceName; + m_deviceType = str2type(info.deviceType); + m_publicKey = QCA::RSAPublicKey::fromPEM(info.publicKey); //Register in bus QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); @@ -117,8 +100,7 @@ void Device::reloadPlugins() if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices - QString path = QStandardPaths::locate(QStandardPaths::ConfigLocation, "kdeconnect/", QStandardPaths::LocateDirectory) + id(); - KConfigGroup pluginStates = KSharedConfig::openConfig(path)->group("Plugins"); + KConfigGroup pluginStates = KSharedConfig::openConfig(pluginsConfigFile())->group("Plugins"); PluginLoader* loader = PluginLoader::instance(); @@ -183,6 +165,11 @@ void Device::reloadPlugins() } +QString Device::pluginsConfigFile() const +{ + return KdeConnectConfig::instance()->deviceConfigDir(id()).absoluteFilePath("config"); +} + void Device::requestPair() { switch(m_pairStatus) { @@ -226,8 +213,7 @@ void Device::unpair() { m_pairStatus = Device::NotPaired; - KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc"); - config->group("trusted_devices").deleteGroup(id()); + KdeConnectConfig::instance()->removeTrustedDevice(id()); NetworkPackage np(PACKAGE_TYPE_PAIR); np.set("pair", false); @@ -271,12 +257,9 @@ void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link) m_deviceName = identityPackage.get("deviceName"); m_deviceType = str2type(identityPackage.get("deviceType")); - Q_ASSERT(!s_privateKey->isNull()); - link->setPrivateKey(*s_privateKey); - //Theoretically we will never add two links from the same provider (the provider should destroy //the old one before this is called), so we do not have to worry about destroying old links. - //Actually, we should not destroy them or the provider will store an invalid ref! + //-- Actually, we should not destroy them or the provider will store an invalid ref! connect(link, SIGNAL(receivedPackage(NetworkPackage)), this, SLOT(privateReceivedPackage(NetworkPackage))); @@ -310,11 +293,6 @@ void Device::removeLink(DeviceLink* link) } } -QString Device::privateKeyPath() -{ - return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/org.kde.kdeconnect/key.pem"); -} - bool Device::sendPackage(NetworkPackage& np) { if (np.type() != PACKAGE_TYPE_PAIR && isPaired()) { @@ -413,8 +391,10 @@ void Device::privateReceivedPackage(const NetworkPackage& np) } } else { qCDebug(KDECONNECT_CORE) << "device" << name() << "not paired, ignoring package" << np.type(); - unpair(); + //FIXME: Uncommenting this fixes a bug where trying to pair from kde does not work, but I want to investigate the root cause of the bug first (01/03/15) + //if (m_pairStatus != Device::Requested) + unpair(); } } @@ -423,7 +403,7 @@ bool Device::sendOwnPublicKey() { NetworkPackage np(PACKAGE_TYPE_PAIR); np.set("pair", true); - np.set("publicKey", s_privateKey->toPublicKey().toPEM()); + np.set("publicKey", KdeConnectConfig::instance()->publicKey().toPEM()); bool success = sendPackage(np); return success; } @@ -466,7 +446,8 @@ void Device::setAsPaired() m_pairingTimeut.stop(); //Just in case it was started - storeAsTrusted(); //Save to the config as trusted + //Save device info in the config + KdeConnectConfig::instance()->addTrustedDevice(id(), name(), type2str(m_deviceType), m_publicKey.toPEM()); reloadPlugins(); //Will actually load the plugins @@ -474,15 +455,6 @@ void Device::setAsPaired() } -void Device::storeAsTrusted() -{ - KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc"); - config->group("trusted_devices").group(id()).writeEntry("publicKey", m_publicKey.toPEM()); - config->group("trusted_devices").group(id()).writeEntry("deviceName", name()); - config->group("trusted_devices").group(id()).writeEntry("deviceType", type2str(m_deviceType)); - config->sync(); -} - QStringList Device::availableLinks() const { QStringList sl; diff --git a/core/device.h b/core/device.h index 5ced32d2f..ab5794323 100644 --- a/core/device.h +++ b/core/device.h @@ -62,7 +62,7 @@ class KDECONNECTCORE_EXPORT Device public: /** - * Reads the @p device from KConfig + * Restores the @p device from the saved configuration * * We already know it but we need to wait for an incoming DeviceLink to communicate */ @@ -85,8 +85,6 @@ public: //Add and remove links void addLink(const NetworkPackage& identityPackage, DeviceLink*); void removeLink(DeviceLink*); - - static QString privateKeyPath(); Q_SCRIPTABLE bool isPaired() const { return m_pairStatus==Device::Paired; } Q_SCRIPTABLE bool pairRequested() const { return m_pairStatus==Device::Requested; } @@ -97,6 +95,8 @@ public: Q_SCRIPTABLE QStringList loadedPlugins() const; Q_SCRIPTABLE bool hasPlugin(const QString& name) const; + Q_SCRIPTABLE QString pluginsConfigFile() const; + public Q_SLOTS: ///sends a @p np package to the device virtual bool sendPackage(NetworkPackage& np); @@ -139,7 +139,6 @@ private: QSet m_outgoingCapabilities; void setAsPaired(); - void storeAsTrusted(); bool sendOwnPublicKey(); }; diff --git a/core/kdeconnectconfig.cpp b/core/kdeconnectconfig.cpp new file mode 100644 index 000000000..adfcc9d0d --- /dev/null +++ b/core/kdeconnectconfig.cpp @@ -0,0 +1,194 @@ +/** + * Copyright 2015 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 "kdeconnectconfig.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core_debug.h" +#include "dbushelper.h" + +struct KdeConnectConfigPrivate { + + // The Initializer object sets things up, and also does cleanup when it goes out of scope + // Note it's not being used anywhere. That's inteneded + QCA::Initializer mQcaInitializer; + + QCA::PrivateKey privateKey; + + KSharedConfigPtr config; + +}; + +KdeConnectConfig* KdeConnectConfig::instance() +{ + static KdeConnectConfig* kcc = new KdeConnectConfig(); + return kcc; +} + +KdeConnectConfig::KdeConnectConfig() + : d(new KdeConnectConfigPrivate) { + + //qCDebug(KDECONNECT_CORE) << "QCA supported capabilities:" << QCA::supportedFeatures().join(","); + if(!QCA::isSupported("rsa")) { + //TODO: Display this in a more visible way (notification?) + qCCritical(KDECONNECT_CORE) << "Error: KDE Connect could not find support for RSA in your QCA installation, if your distribution provides" + << "separate packages for QCA-ossl and QCA-gnupg plugins, make sure you have them installed and try again"; + return; + } + + //Make sure base directory exists + QDir().mkpath(baseConfigDir().path()); + + //.config/kdeconnect/config + d->config = KSharedConfig::openConfig(baseConfigDir().absoluteFilePath("config"), KSharedConfig::SimpleConfig); + + if (!d->config->group("myself").hasKey("id")) { + QString uuid = QUuid::createUuid().toString(); + DbusHelper::filterNonExportableCharacters(uuid); + d->config->group("myself").writeEntry("id", uuid); + d->config->sync(); + qCDebug(KDECONNECT_CORE) << "My id:" << uuid; + } + + const QFile::Permissions strict = QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser; + + QString keyPath = privateKeyPath(); + QFile privKey(keyPath); + if (privKey.exists() && privKey.open(QIODevice::ReadOnly)) + { + d->privateKey = QCA::PrivateKey::fromPEM(privKey.readAll()); + } + else + { + if (!privKey.open(QIODevice::ReadWrite | QIODevice::Truncate)) { + //TODO: Display this in a more visible way (notification?) + qCCritical(KDECONNECT_CORE) << "Error: KDE Connect could not create private key file: " << keyPath; + QApplication::exit(-1); + } + privKey.setPermissions(strict); + + d->privateKey = QCA::KeyGenerator().createRSA(2048); + + privKey.write(d->privateKey.toPEM().toLatin1()); + } + + //Extra security check + if (QFile::permissions(keyPath) != strict) { + qCDebug(KDECONNECT_CORE) << "Error: KDE Connect detects wrong permissions for private key file " << keyPath; + } +} + +QString KdeConnectConfig::name() { + QString defaultName = qgetenv("USER") + "@" + QHostInfo::localHostName(); + QString name = d->config->group("myself").readEntry("name", defaultName); + return name; +} + +void KdeConnectConfig::setName(QString name) +{ + d->config->group("myself").writeEntry("name", name); + d->config->sync(); +} + +QString KdeConnectConfig::deviceType() +{ + return "desktop"; // TODO +} + +QString KdeConnectConfig::deviceId() { + return d->config->group("myself").readEntry("id", ""); +} + +QString KdeConnectConfig::privateKeyPath() +{ + return baseConfigDir().absoluteFilePath("privateKey.pem"); +} + +QCA::PrivateKey KdeConnectConfig::privateKey() +{ + return d->privateKey; +} + +QCA::PublicKey KdeConnectConfig::publicKey() +{ + return d->privateKey.toPublicKey(); +} + +QDir KdeConnectConfig::baseConfigDir() +{ + QString configPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); + QString kdeconnectConfigPath = QDir(configPath).absoluteFilePath("kdeconnect"); + return QDir(kdeconnectConfigPath); +} + +QStringList KdeConnectConfig::trustedDevices() +{ + const KConfigGroup& known = d->config->group("trusted_devices"); + const QStringList& list = known.groupList(); + return list; +} + +void KdeConnectConfig::addTrustedDevice(QString id, QString name, QString type, QString publicKey) +{ + KConfigGroup device = d->config->group("trusted_devices").group(id); + device.writeEntry("deviceName", name); + device.writeEntry("deviceType", type); + device.writeEntry("publicKey", publicKey); + d->config->sync(); + + QDir().mkpath(deviceConfigDir(id).path()); +} + +KdeConnectConfig::DeviceInfo KdeConnectConfig::getTrustedDevice(QString id) +{ + KConfigGroup data = d->config->group("trusted_devices").group(id); + + KdeConnectConfig::DeviceInfo info; + info.deviceName = data.readEntry("deviceName", QLatin1String("unnamed")); + info.deviceType = data.readEntry("deviceType", QLatin1String("unknown")); + info.publicKey = data.readEntry("publicKey", QString()); + + return info; +} + +void KdeConnectConfig::removeTrustedDevice(QString deviceId) +{ + d->config->group("trusted_devices").deleteGroup(deviceId); +} + +QDir KdeConnectConfig::deviceConfigDir(QString deviceId) +{ + QString deviceConfigPath = baseConfigDir().absoluteFilePath(deviceId); + return QDir(deviceConfigPath); +} diff --git a/core/kdeconnectconfig.h b/core/kdeconnectconfig.h new file mode 100644 index 000000000..d1e721a1e --- /dev/null +++ b/core/kdeconnectconfig.h @@ -0,0 +1,78 @@ +/** + * Copyright 2015 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 KDECONNECTCONFIG_H +#define KDECONNECTCONFIG_H + +#include +#include + +#include "kdeconnectcore_export.h" + +class KdeConnectConfigPrivate; + +class KDECONNECTCORE_EXPORT KdeConnectConfig +{ +public: + struct DeviceInfo { + QString deviceName; + QString deviceType; + QString publicKey; + }; + + static KdeConnectConfig* instance(); + + + /* + * Our own info + */ + + QString deviceId(); + QString name(); + QString deviceType(); + + QString privateKeyPath(); + QCA::PrivateKey privateKey(); + QCA::PublicKey publicKey(); + + void setName(QString name); + + + /* + * Trusted devices + */ + + QStringList trustedDevices(); //Get a list of ids + void removeTrustedDevice(QString id); + void addTrustedDevice(QString id, QString name, QString type, QString publicKey); + KdeConnectConfig::DeviceInfo getTrustedDevice(QString id); + + + QDir baseConfigDir(); + QDir deviceConfigDir(QString deviceId); + +private: + KdeConnectConfig(); + +private: + QScopedPointer d; +}; + +#endif diff --git a/core/kdeconnectplugin.cpp b/core/kdeconnectplugin.cpp index fd609acba..e7f72c60b 100644 --- a/core/kdeconnectplugin.cpp +++ b/core/kdeconnectplugin.cpp @@ -25,10 +25,6 @@ struct KdeConnectPluginPrivate { Device* mDevice; QSet mOutgoingTypes; - - // The Initializer object sets things up, and also does cleanup when it goes out of scope - // Since the plugins use their own memory, they need their own initializer in order to send encrypted packages - QCA::Initializer init; }; KdeConnectPlugin::KdeConnectPlugin(QObject* parent, const QVariantList& args) diff --git a/core/networkpackage.cpp b/core/networkpackage.cpp index c330a2d79..99f581925 100644 --- a/core/networkpackage.cpp +++ b/core/networkpackage.cpp @@ -21,23 +21,19 @@ #include "networkpackage.h" #include "core_debug.h" -#include -#include - #include #include #include #include -#include -#include #include -#include +#include #include #include #include "dbushelper.h" #include "filetransferjob.h" #include "pluginloader.h" +#include "kdeconnectconfig.h" const QCA::EncryptionAlgorithm NetworkPackage::EncryptionAlgorithm = QCA::EME_PKCS1v15; const int NetworkPackage::ProtocolVersion = 5; @@ -53,15 +49,15 @@ NetworkPackage::NetworkPackage(const QString& type) void NetworkPackage::createIdentityPackage(NetworkPackage* np) { - KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc"); - const QString id = config->group("myself").readEntry("id",""); + KdeConnectConfig* config = KdeConnectConfig::instance(); + const QString id = config->deviceId(); np->mId = QString::number(QDateTime::currentMSecsSinceEpoch()); np->mType = PACKAGE_TYPE_IDENTITY; np->mPayload = QSharedPointer(); np->mPayloadSize = 0; np->set("deviceId", id); - np->set("deviceName", qgetenv("USER") + "@" + QHostInfo::localHostName()); - np->set("deviceType", "desktop"); //TODO: Detect laptop, tablet, phone... + np->set("deviceName", config->name()); + np->set("deviceType", config->deviceType()); np->set("protocolVersion", NetworkPackage::ProtocolVersion); np->set("SupportedIncomingInterfaces", PluginLoader::instance()->incomingInterfaces().join(",")); np->set("SupportedOutgoingInterfaces", PluginLoader::instance()->outgoingInterfaces().join(",")); diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp index 78bec8b75..b86bf5670 100644 --- a/interfaces/devicesmodel.cpp +++ b/interfaces/devicesmodel.cpp @@ -23,9 +23,6 @@ #include #include - -#include -#include #include #include "dbusinterfaces.h" diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 1c10c0824..e817fd5f2 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -142,7 +142,7 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current) } } - //FIXME: KPluginSelector has no way to remove a list of plugins and load another, so we need to destroy and recreate it each time + //KPluginSelector has no way to remove a list of plugins and load another, so we need to destroy and recreate it each time delete kcmUi->pluginSelector; kcmUi->pluginSelector = new KPluginSelector(this); kcmUi->verticalLayout_2->addWidget(kcmUi->pluginSelector); @@ -159,9 +159,7 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current) KService::List offers = KServiceTypeTrader::self()->query("KdeConnect/Plugin"); QList scriptinfos = KPluginInfo::fromServices(offers); - - QString path = QStandardPaths::locate(QStandardPaths::ConfigLocation, "kdeconnect/", QStandardPaths::LocateDirectory); - KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(path + currentDevice->id()); + KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(currentDevice->pluginsConfigFile()); kcmUi->pluginSelector->addPlugins(scriptinfos, KPluginSelector::ReadConfigFile, i18n("Plugins"), QString(), deviceConfig); connect(kcmUi->pluginSelector, SIGNAL(changed(bool)), diff --git a/kcm/kcm.h b/kcm/kcm.h index ce64996b9..61ca8f87d 100644 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -21,18 +21,10 @@ #ifndef KDECONNECTKCM_H #define KDECONNECTKCM_H +#include #include -#include - -#include -#include class QModelIndex; -class AccountsModel; -class AccountWidget; -class QStackedLayout; -class QItemSelectionModel; -class QDBusInterface; class DeviceDbusInterface; class DevicesModel; class DevicesSortProxyModel; diff --git a/plugins/sftp/mounter.cpp b/plugins/sftp/mounter.cpp index 9ced0ed7c..70dcd19d5 100644 --- a/plugins/sftp/mounter.cpp +++ b/plugins/sftp/mounter.cpp @@ -26,6 +26,7 @@ #include "mounter.h" #include "sftp_debug.h" +#include static const char* idleTimeout_c = "idleTimeout"; @@ -133,7 +134,7 @@ void Mounter::onPakcageReceived(const NetworkPackage& np) << "-p" << np.get("port") << "-d" << "-f" - << "-o" << "IdentityFile=" + m_sftp->device()->privateKeyPath() + << "-o" << "IdentityFile=" + KdeConnectConfig::instance()->privateKeyPath() << "-o" << "StrictHostKeyChecking=no" //Do not ask for confirmation because it is not a known host << "-o" << "UserKnownHostsFile=/dev/null"; //Prevent storing as a known host