From 02a2990720f6d41649151e03c318a48fff4379ce Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Fri, 13 Mar 2015 21:19:39 -0700 Subject: [PATCH] Added a baseclass for the plugins' KCMs and a class for the plugins' config Centralizing the plugins' config will ensure that all the plugins store it the same way (ie: not in random files scattered around, like until now). The base KCM class, together with the already existing base plugin class, will give easy access to all the plugins to this centralized config. Also, now the settings are not shared across devices (that is: every device can have different config for a same plugin). Note: This commit requires KCMUtils 5.9 REVIEW: 122927 --- core/CMakeLists.txt | 1 + core/kdeconnectconfig.cpp | 10 ++++ core/kdeconnectconfig.h | 10 ++-- core/kdeconnectplugin.cpp | 18 ++++++- core/kdeconnectplugin.h | 3 ++ core/kdeconnectpluginconfig.cpp | 67 +++++++++++++++++++++++ core/kdeconnectpluginconfig.h | 68 ++++++++++++++++++++++++ core/pluginloader.cpp | 8 +-- kcm/CMakeLists.txt | 2 + kcm/kcm.cpp | 2 + kcmplugin/CMakeLists.txt | 29 ++++++++++ kcmplugin/kdeconnectpluginkcm.cpp | 60 +++++++++++++++++++++ kcmplugin/kdeconnectpluginkcm.h | 58 ++++++++++++++++++++ plugins/pausemusic/CMakeLists.txt | 6 +-- plugins/pausemusic/pausemusic_config.cpp | 27 ++++------ plugins/pausemusic/pausemusic_config.h | 6 +-- plugins/pausemusic/pausemusicplugin.cpp | 16 ++---- plugins/sftp/sftpplugin.cpp | 5 +- plugins/share/CMakeLists.txt | 2 +- plugins/share/share_config.cpp | 21 +++----- plugins/share/share_config.h | 6 +-- plugins/share/shareplugin.cpp | 7 +-- 22 files changed, 359 insertions(+), 73 deletions(-) create mode 100644 core/kdeconnectpluginconfig.cpp create mode 100644 core/kdeconnectpluginconfig.h create mode 100644 kcmplugin/CMakeLists.txt create mode 100644 kcmplugin/kdeconnectpluginkcm.cpp create mode 100644 kcmplugin/kdeconnectpluginkcm.h diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 83f5ded91..c9a495e51 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -18,6 +18,7 @@ set(kdeconnectcore_SRCS backends/devicelink.cpp kdeconnectplugin.cpp + kdeconnectpluginconfig.cpp pluginloader.cpp kdeconnectconfig.cpp diff --git a/core/kdeconnectconfig.cpp b/core/kdeconnectconfig.cpp index 403571e05..fbe8eeb87 100644 --- a/core/kdeconnectconfig.cpp +++ b/core/kdeconnectconfig.cpp @@ -188,6 +188,8 @@ KdeConnectConfig::DeviceInfo KdeConnectConfig::getTrustedDevice(QString id) void KdeConnectConfig::removeTrustedDevice(QString deviceId) { d->config->group("trusted_devices").deleteGroup(deviceId); + + //We do not remove the config files. } QDir KdeConnectConfig::deviceConfigDir(QString deviceId) @@ -195,3 +197,11 @@ QDir KdeConnectConfig::deviceConfigDir(QString deviceId) QString deviceConfigPath = baseConfigDir().absoluteFilePath(deviceId); return QDir(deviceConfigPath); } + +QDir KdeConnectConfig::pluginConfigDir(QString deviceId, QString pluginName) +{ + QString deviceConfigPath = baseConfigDir().absoluteFilePath(deviceId); + QString pluginConfigDir = QDir(deviceConfigPath).absoluteFilePath(pluginName); + return QDir(pluginConfigDir); +} + diff --git a/core/kdeconnectconfig.h b/core/kdeconnectconfig.h index d1e721a1e..e796a740c 100644 --- a/core/kdeconnectconfig.h +++ b/core/kdeconnectconfig.h @@ -39,7 +39,6 @@ public: static KdeConnectConfig* instance(); - /* * Our own info */ @@ -54,25 +53,28 @@ public: void setName(QString name); - /* * Trusted devices */ - QStringList trustedDevices(); //Get a list of ids + QStringList trustedDevices(); //list of ids void removeTrustedDevice(QString id); void addTrustedDevice(QString id, QString name, QString type, QString publicKey); KdeConnectConfig::DeviceInfo getTrustedDevice(QString id); - + /* + * Paths for config files, there is no guarantee the directories already exist + */ QDir baseConfigDir(); QDir deviceConfigDir(QString deviceId); + QDir pluginConfigDir(QString deviceId, QString pluginName); //Used by KdeConnectPluginConfig private: KdeConnectConfig(); private: QScopedPointer d; + }; #endif diff --git a/core/kdeconnectplugin.cpp b/core/kdeconnectplugin.cpp index e7f72c60b..3f499c97c 100644 --- a/core/kdeconnectplugin.cpp +++ b/core/kdeconnectplugin.cpp @@ -19,20 +19,34 @@ */ #include "kdeconnectplugin.h" + #include struct KdeConnectPluginPrivate { Device* mDevice; + QString mPluginName; QSet mOutgoingTypes; + KdeConnectPluginConfig* mConfig; }; KdeConnectPlugin::KdeConnectPlugin(QObject* parent, const QVariantList& args) : QObject(parent) , d(new KdeConnectPluginPrivate) { - d->mDevice = qvariant_cast< Device* >(args.first()); - d->mOutgoingTypes = args.last().toStringList().toSet(); + d->mDevice = qvariant_cast< Device* >(args.at(0)); + d->mPluginName = args.at(1).toString(); + d->mOutgoingTypes = args.at(2).toStringList().toSet(); + d->mConfig = 0; +} + +KdeConnectPluginConfig* KdeConnectPlugin::config() const +{ + //Create on demand, because not every plugin will use it + if (!d->mConfig) { + d->mConfig = new KdeConnectPluginConfig(d->mDevice->id(), d->mPluginName); + } + return d->mConfig; } KdeConnectPlugin::~KdeConnectPlugin() diff --git a/core/kdeconnectplugin.h b/core/kdeconnectplugin.h index 564786c29..297bf0c84 100644 --- a/core/kdeconnectplugin.h +++ b/core/kdeconnectplugin.h @@ -25,6 +25,7 @@ #include #include "kdeconnectcore_export.h" +#include "kdeconnectpluginconfig.h" #include "networkpackage.h" #include "device.h" @@ -44,6 +45,8 @@ public: bool sendPackage(NetworkPackage& np) const; + KdeConnectPluginConfig* config() const; + public Q_SLOTS: /** * Returns true if it has handled the package in some way diff --git a/core/kdeconnectpluginconfig.cpp b/core/kdeconnectpluginconfig.cpp new file mode 100644 index 000000000..72d04e4dc --- /dev/null +++ b/core/kdeconnectpluginconfig.cpp @@ -0,0 +1,67 @@ +/** + * 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 "kdeconnectpluginconfig.h" + +#include +#include +#include + +#include + +#include "interfaces/dbusinterfaces.h" +#include "kdeconnectconfig.h" + +struct KdeConnectPluginConfigPrivate +{ + QDir mConfigDir; + QSettings* mConfig; +}; + +KdeConnectPluginConfig::KdeConnectPluginConfig(const QString& deviceId, const QString& pluginName) + : d(new KdeConnectPluginConfigPrivate()) +{ + d->mConfigDir = KdeConnectConfig::instance()->pluginConfigDir(deviceId, pluginName); + QDir().mkpath(d->mConfigDir.path()); + + d->mConfig = new QSettings(d->mConfigDir.absoluteFilePath("config"), QSettings::IniFormat); +} + +KdeConnectPluginConfig::~KdeConnectPluginConfig() +{ + delete d->mConfig; +} + +QDir KdeConnectPluginConfig::privateDirectory() +{ + return d->mConfigDir; +} + +QVariant KdeConnectPluginConfig::get(const QString& key, const QVariant& defaultValue) +{ + d->mConfig->sync(); + return d->mConfig->value(key, defaultValue); +} + +void KdeConnectPluginConfig::set(const QString& key, const QVariant& value) +{ + d->mConfig->setValue(key, value); + d->mConfig->sync(); +} diff --git a/core/kdeconnectpluginconfig.h b/core/kdeconnectpluginconfig.h new file mode 100644 index 000000000..96195e4be --- /dev/null +++ b/core/kdeconnectpluginconfig.h @@ -0,0 +1,68 @@ +/** + * 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 KDECONNECTPLUGINCONFIG_H +#define KDECONNECTPLUGINCONFIG_H + +#include +#include +#include +#include + +#include "default_args.h" +#include "kdeconnectcore_export.h" + +struct KdeConnectPluginConfigPrivate; + +class KDECONNECTCORE_EXPORT KdeConnectPluginConfig +{ +public: + KdeConnectPluginConfig(const QString& deviceId, const QString& pluginName); + ~KdeConnectPluginConfig(); + + /** + * A directory to store stuff for this device and plugin. It's private in the sense + * of not-shared with other plugins or devices, not from a security point of view. + */ + QDir privateDirectory(); + + /** + * Store a key-value pair in this config object + */ + void set(const QString& key, const QVariant& value); + + /** + * Read a key-value pair from this config object + */ + QVariant get(const QString& key, const QVariant& defaultValue); + + /** + * Convenience method that will convert the QVariant to whatever type for you + */ + template T get(const QString& key, const T& defaultValue = default_arg::get()) { + return get(key, QVariant(defaultValue)).template value(); //Important note: Awesome template syntax is awesome + } + + +private: + QScopedPointer d; +}; + +#endif diff --git a/core/pluginloader.cpp b/core/pluginloader.cpp index 37bd4baac..b6f01396a 100644 --- a/core/pluginloader.cpp +++ b/core/pluginloader.cpp @@ -57,13 +57,13 @@ KPluginInfo PluginLoader::getPluginInfo(const QString& name) const return KPluginInfo(service); } -KdeConnectPlugin* PluginLoader::instantiatePluginForDevice(const QString& name, Device* device) const +KdeConnectPlugin* PluginLoader::instantiatePluginForDevice(const QString& pluginName, Device* device) const { KdeConnectPlugin* ret = 0; - KService::Ptr service = plugins[name]; + KService::Ptr service = plugins[pluginName]; if (!service) { - qCDebug(KDECONNECT_CORE) << "Plugin unknown" << name; + qCDebug(KDECONNECT_CORE) << "Plugin unknown" << pluginName; return ret; } @@ -77,7 +77,7 @@ KdeConnectPlugin* PluginLoader::instantiatePluginForDevice(const QString& name, QVariant deviceVariant = QVariant::fromValue(device); - ret = factory->create(device, QVariantList() << deviceVariant << outgoingInterfaces); + ret = factory->create(device, QVariantList() << deviceVariant << pluginName << outgoingInterfaces); if (!ret) { qCDebug(KDECONNECT_CORE) << "Error loading plugin"; return ret; diff --git a/kcm/CMakeLists.txt b/kcm/CMakeLists.txt index 03796a06a..568972bb5 100644 --- a/kcm/CMakeLists.txt +++ b/kcm/CMakeLists.txt @@ -1,5 +1,7 @@ add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-kcm") +find_package(KF5KCMUtils 5.9 REQUIRED) + include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 8c377fa8c..806d99fe6 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -182,6 +182,8 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current) kcmUi->pluginSelector = new KPluginSelector(this); kcmUi->verticalLayout_2->addWidget(kcmUi->pluginSelector); + kcmUi->pluginSelector->setConfigurationArguments(QStringList(currentDevice->id())); + kcmUi->name_label->setText(currentDevice->name()); kcmUi->status_label->setText(currentDevice->isPaired()? i18n("(paired)") : i18n("(unpaired)")); diff --git a/kcmplugin/CMakeLists.txt b/kcmplugin/CMakeLists.txt new file mode 100644 index 000000000..aeb60d22c --- /dev/null +++ b/kcmplugin/CMakeLists.txt @@ -0,0 +1,29 @@ +project(kdeconnectpluginkcm) + +add_definitions(-DTRANSLATION_DOMAIN=\"kdeconnect-core\") + +set(kdeconnectpluginkcm_SRCS + kdeconnectpluginkcm.cpp +) + +add_library(kdeconnectpluginkcm SHARED ${kdeconnectpluginkcm_SRCS}) +target_link_libraries(kdeconnectpluginkcm +PUBLIC + kdeconnectcore +PRIVATE + Qt5::DBus + Qt5::Gui + KF5::I18n + KF5::ConfigCore + KF5::KCMUtils +) + +set_target_properties(kdeconnectpluginkcm PROPERTIES + VERSION ${KDECONNECT_VERSION} + SOVERSION ${KDECONNECT_VERSION_MAJOR} +) + +target_include_directories(kdeconnectpluginkcm PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +generate_export_header(kdeconnectpluginkcm EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}../core/kdeconnectcore_export.h BASE_NAME kdeconnectpluginkcm) + +install(TARGETS kdeconnectpluginkcm EXPORT kdeconnectLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/kcmplugin/kdeconnectpluginkcm.cpp b/kcmplugin/kdeconnectpluginkcm.cpp new file mode 100644 index 000000000..aa42e4e02 --- /dev/null +++ b/kcmplugin/kdeconnectpluginkcm.cpp @@ -0,0 +1,60 @@ +/** + * 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 "kdeconnectpluginkcm.h" + +#include +#include + +struct KdeConnectPluginKcmPrivate +{ + QString mDeviceId; + QString mPluginName; + KdeConnectPluginConfig* mConfig; +}; + +KdeConnectPluginKcm::KdeConnectPluginKcm(QWidget* parent, const QVariantList& args, const QString& componentName) + : KCModule(KAboutData::pluginData(componentName), parent, args) + , d(new KdeConnectPluginKcmPrivate()) +{ + + d->mDeviceId = args.at(0).toString(); + //The parent of the config should be the plugin itself + d->mPluginName = KService::serviceByDesktopName(componentName).constData()->property("X-KDE-ParentComponents").toString(); + + d->mConfig = new KdeConnectPluginConfig(d->mDeviceId, d->mPluginName); +} + +KdeConnectPluginKcm::~KdeConnectPluginKcm() +{ + +} + +KdeConnectPluginConfig* KdeConnectPluginKcm::config() const +{ + return d->mConfig; +} + +QString KdeConnectPluginKcm::deviceId() const +{ + return d->mDeviceId; +} + + diff --git a/kcmplugin/kdeconnectpluginkcm.h b/kcmplugin/kdeconnectpluginkcm.h new file mode 100644 index 000000000..e6b604f1d --- /dev/null +++ b/kcmplugin/kdeconnectpluginkcm.h @@ -0,0 +1,58 @@ +/** + * 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 KDECONNECTPLUGINKCM_H +#define KDECONNECTPLUGINKCM_H + +#include + +#include "core/kdeconnectcore_export.h" +#include "core/kdeconnectpluginconfig.h" + +struct KdeConnectPluginKcmPrivate; + +/** + * Inheriting your plugin's KCM from this class gets you a easy way to share + * configuration values between the KCM and the plugin. + */ +class KDECONNECTCORE_EXPORT KdeConnectPluginKcm + : public KCModule +{ + Q_OBJECT + +public: + KdeConnectPluginKcm(QWidget* parent, const QVariantList& args, const QString& componentName); + virtual ~KdeConnectPluginKcm(); + + /** + * The device this kcm is instantiated for + */ + QString deviceId() const; + + /** + * The object where to save the config, so the plugin can access it + */ + KdeConnectPluginConfig* config() const; + +private: + QScopedPointer d; +}; + +#endif diff --git a/plugins/pausemusic/CMakeLists.txt b/plugins/pausemusic/CMakeLists.txt index 44d0902f6..2f9f42bfe 100644 --- a/plugins/pausemusic/CMakeLists.txt +++ b/plugins/pausemusic/CMakeLists.txt @@ -5,11 +5,10 @@ set(kdeconnect_pausemusic_SRCS add_library(kdeconnect_pausemusic MODULE ${kdeconnect_pausemusic_SRCS}) target_link_libraries(kdeconnect_pausemusic + kdeconnectcore Qt5::Core Qt5::DBus - KF5::ConfigCore KF5::Service - kdeconnectcore ) install(TARGETS kdeconnect_pausemusic DESTINATION ${PLUGIN_INSTALL_DIR} ) @@ -24,7 +23,8 @@ ki18n_wrap_ui( kdeconnect_pausemusic_config_SRCS pausemusic_config.ui ) add_library(kdeconnect_pausemusic_config MODULE ${kdeconnect_pausemusic_config_SRCS} ) target_link_libraries( kdeconnect_pausemusic_config - Qt5::Core + kdeconnectcore + kdeconnectpluginkcm KF5::I18n KF5::KCMUtils ) diff --git a/plugins/pausemusic/pausemusic_config.cpp b/plugins/pausemusic/pausemusic_config.cpp index 5890187d4..de5fdaa79 100644 --- a/plugins/pausemusic/pausemusic_config.cpp +++ b/plugins/pausemusic/pausemusic_config.cpp @@ -19,20 +19,15 @@ */ #include "pausemusic_config.h" +#include "ui_pausemusic_config.h" #include -#include -#include -#include - -#include "ui_pausemusic_config.h" K_PLUGIN_FACTORY(PauseMusicConfigFactory, registerPlugin();) -PauseMusicConfig::PauseMusicConfig(QWidget *parent, const QVariantList& ) - : KCModule(KAboutData::pluginData("kdeconnect_pausemusic_config"), parent) +PauseMusicConfig::PauseMusicConfig(QWidget *parent, const QVariantList& args) + : KdeConnectPluginKcm(parent, args, "kdeconnect_pausemusic_config") , m_ui(new Ui::PauseMusicConfigUi()) - , m_cfg(KSharedConfig::openConfig("kdeconnect/plugins/pausemusic")) { m_ui->setupUi(this); @@ -57,29 +52,27 @@ void PauseMusicConfig::defaults() Q_EMIT changed(true); } - void PauseMusicConfig::load() { KCModule::load(); - bool talking = m_cfg->group("condition").readEntry("talking_only", false); + bool talking = config()->get("conditionTalking", false); m_ui->rad_talking->setChecked(talking); m_ui->rad_ringing->setChecked(!talking); - bool pause = m_cfg->group("actions").readEntry("pause", true); - bool mute = m_cfg->group("actions").readEntry("mute", false); + bool pause = config()->get("actionPause", true); + bool mute = config()->get("actionMute", false); m_ui->check_pause->setChecked(pause); m_ui->check_mute->setChecked(mute); + Q_EMIT changed(false); } - void PauseMusicConfig::save() { - m_cfg->group("condition").writeEntry("talking_only", m_ui->rad_talking->isChecked()); - m_cfg->group("actions").writeEntry("pause", m_ui->check_pause->isChecked()); - m_cfg->group("actions").writeEntry("mute", m_ui->check_mute->isChecked()); + config()->set("conditionTalking", m_ui->rad_talking->isChecked()); + config()->set("actionPause", m_ui->check_pause->isChecked()); + config()->set("actionMute", m_ui->check_mute->isChecked()); KCModule::save(); - Q_EMIT changed(false); } diff --git a/plugins/pausemusic/pausemusic_config.h b/plugins/pausemusic/pausemusic_config.h index 075e2958d..180ebaf21 100644 --- a/plugins/pausemusic/pausemusic_config.h +++ b/plugins/pausemusic/pausemusic_config.h @@ -21,15 +21,14 @@ #ifndef PAUSEMUSIC_CONFIG_H #define PAUSEMUSIC_CONFIG_H -#include -#include +#include "kcmplugin/kdeconnectpluginkcm.h" namespace Ui { class PauseMusicConfigUi; } class PauseMusicConfig - : public KCModule + : public KdeConnectPluginKcm { Q_OBJECT public: @@ -43,7 +42,6 @@ public Q_SLOTS: private: Ui::PauseMusicConfigUi* m_ui; - KSharedConfigPtr m_cfg; }; diff --git a/plugins/pausemusic/pausemusicplugin.cpp b/plugins/pausemusic/pausemusicplugin.cpp index a9cdc6811..b6cf34a38 100644 --- a/plugins/pausemusic/pausemusicplugin.cpp +++ b/plugins/pausemusic/pausemusicplugin.cpp @@ -23,15 +23,12 @@ #include #include #include -#include #include +#include +#include -#include -#include #include -#include - K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PauseMusicPlugin >(); ) //TODO: Port this away from KMix to use only Pulseaudio @@ -55,7 +52,6 @@ int PauseMusicPlugin::isKMixMuted() { return (mixerInterface.property("volume").toInt() == 0); } - PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args) : KdeConnectPlugin(parent, args) , muted(false) @@ -65,9 +61,7 @@ PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args) bool PauseMusicPlugin::receivePackage(const NetworkPackage& np) { - //FIXME: There should be a better way to listen to changes in the config file instead of reading the value each time - KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/pausemusic"); - bool pauseOnlyWhenTalking = config->group("condition").readEntry("talking_only", false); + bool pauseOnlyWhenTalking = config()->get("conditionTalking", false); if (pauseOnlyWhenTalking) { if (np.get("event") != "talking") { @@ -81,8 +75,8 @@ bool PauseMusicPlugin::receivePackage(const NetworkPackage& np) bool pauseConditionFulfilled = !np.get("isCancel"); - bool pause = config->group("actions").readEntry("pause", true); - bool mute = config->group("actions").readEntry("mute", false); + bool pause = config()->get("actionPause", true); + bool mute = config()->get("actionMute", false); if (pauseConditionFulfilled) { diff --git a/plugins/sftp/sftpplugin.cpp b/plugins/sftp/sftpplugin.cpp index 87e53ddf6..88f8a3657 100644 --- a/plugins/sftp/sftpplugin.cpp +++ b/plugins/sftp/sftpplugin.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -158,8 +157,8 @@ bool SftpPlugin::receivePackage(const NetworkPackage& np) QString SftpPlugin::mountPoint() { - const QString mountDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); - return QDir(mountDir).absoluteFilePath(deviceId); + QDir mountDir = config()->privateDirectory(); + return mountDir.absoluteFilePath(deviceId); } void SftpPlugin::onMounted() diff --git a/plugins/share/CMakeLists.txt b/plugins/share/CMakeLists.txt index 478386490..7016e263f 100644 --- a/plugins/share/CMakeLists.txt +++ b/plugins/share/CMakeLists.txt @@ -26,8 +26,8 @@ ki18n_wrap_ui( kdeconnect_share_config_SRCS share_config.ui ) add_library(kdeconnect_share_config MODULE ${kdeconnect_share_config_SRCS} ) target_link_libraries( kdeconnect_share_config + kdeconnectpluginkcm KF5::I18n - KF5::KCMUtils KF5::CoreAddons KF5::ConfigWidgets KF5::KIOWidgets diff --git a/plugins/share/share_config.cpp b/plugins/share/share_config.cpp index 397547ac1..c41853420 100644 --- a/plugins/share/share_config.cpp +++ b/plugins/share/share_config.cpp @@ -19,24 +19,18 @@ */ #include "share_config.h" +#include "ui_share_config.h" #include -#include -#include -#include #include -#include -#include - -#include "ui_share_config.h" +#include K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin();) -ShareConfig::ShareConfig(QWidget *parent, const QVariantList& ) - : KCModule(KAboutData::pluginData("kdeconnect_share_config"), parent) +ShareConfig::ShareConfig(QWidget *parent, const QVariantList& args) + : KdeConnectPluginKcm(parent, args, "kdeconnect_share_config") , m_ui(new Ui::ShareConfigUi()) - , m_cfg(KSharedConfig::openConfig("kdeconnect/plugins/share")) { m_ui->setupUi(this); @@ -57,21 +51,18 @@ void ShareConfig::defaults() Q_EMIT changed(true); } - void ShareConfig::load() { KCModule::load(); - m_ui->kurlrequester->setUrl(m_cfg->group("receive").readEntry("path", - QStandardPaths::writableLocation(QStandardPaths::DownloadLocation))); + m_ui->kurlrequester->setUrl(config()->get("incoming_path", QStandardPaths::writableLocation(QStandardPaths::DownloadLocation))); Q_EMIT changed(false); } - void ShareConfig::save() { - m_cfg->group("receive").writeEntry("path", m_ui->kurlrequester->text()); + config()->set("incoming_path", m_ui->kurlrequester->text()); KCModule::save(); diff --git a/plugins/share/share_config.h b/plugins/share/share_config.h index 7743fcc9c..b3f837cb5 100644 --- a/plugins/share/share_config.h +++ b/plugins/share/share_config.h @@ -21,15 +21,14 @@ #ifndef SHARE_CONFIG_H #define SHARE_CONFIG_H -#include -#include +#include "kcmplugin/kdeconnectpluginkcm.h" namespace Ui { class ShareConfigUi; } class ShareConfig - : public KCModule + : public KdeConnectPluginKcm { Q_OBJECT public: @@ -43,7 +42,6 @@ public Q_SLOTS: private: Ui::ShareConfigUi* m_ui; - KSharedConfigPtr m_cfg; }; diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp index 2fd689c74..049f57d72 100644 --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -81,10 +81,8 @@ SharePlugin::SharePlugin(QObject* parent, const QVariantList& args) QUrl SharePlugin::destinationDir() const { - //FIXME: There should be a better way to listen to changes in the config file instead of reading the value each time - KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/share"); - const QString downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); - QString dir = config->group("receive").readEntry("path", downloadPath); + const QString defaultDownloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + QString dir = config()->get("incoming_path", defaultDownloadPath); if (dir.contains("%1")) { dir = dir.arg(device()->name()); @@ -106,7 +104,6 @@ bool SharePlugin::receivePackage(const NetworkPackage& np) NetworkPackage out(PACKAGE_TYPE_SHARE); out.set("filename", mDestinationDir + "itworks.txt"); - //TODO: Use shared pointers AutoClosingQFile* file = new AutoClosingQFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc"); //Test file to transfer out.setPayload(file, file->size());