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
This commit is contained in:
parent
dedd338bb7
commit
02a2990720
22 changed files with 359 additions and 73 deletions
|
@ -18,6 +18,7 @@ set(kdeconnectcore_SRCS
|
||||||
backends/devicelink.cpp
|
backends/devicelink.cpp
|
||||||
|
|
||||||
kdeconnectplugin.cpp
|
kdeconnectplugin.cpp
|
||||||
|
kdeconnectpluginconfig.cpp
|
||||||
pluginloader.cpp
|
pluginloader.cpp
|
||||||
|
|
||||||
kdeconnectconfig.cpp
|
kdeconnectconfig.cpp
|
||||||
|
|
|
@ -188,6 +188,8 @@ KdeConnectConfig::DeviceInfo KdeConnectConfig::getTrustedDevice(QString id)
|
||||||
void KdeConnectConfig::removeTrustedDevice(QString deviceId)
|
void KdeConnectConfig::removeTrustedDevice(QString deviceId)
|
||||||
{
|
{
|
||||||
d->config->group("trusted_devices").deleteGroup(deviceId);
|
d->config->group("trusted_devices").deleteGroup(deviceId);
|
||||||
|
|
||||||
|
//We do not remove the config files.
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir KdeConnectConfig::deviceConfigDir(QString deviceId)
|
QDir KdeConnectConfig::deviceConfigDir(QString deviceId)
|
||||||
|
@ -195,3 +197,11 @@ QDir KdeConnectConfig::deviceConfigDir(QString deviceId)
|
||||||
QString deviceConfigPath = baseConfigDir().absoluteFilePath(deviceId);
|
QString deviceConfigPath = baseConfigDir().absoluteFilePath(deviceId);
|
||||||
return QDir(deviceConfigPath);
|
return QDir(deviceConfigPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDir KdeConnectConfig::pluginConfigDir(QString deviceId, QString pluginName)
|
||||||
|
{
|
||||||
|
QString deviceConfigPath = baseConfigDir().absoluteFilePath(deviceId);
|
||||||
|
QString pluginConfigDir = QDir(deviceConfigPath).absoluteFilePath(pluginName);
|
||||||
|
return QDir(pluginConfigDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ public:
|
||||||
|
|
||||||
static KdeConnectConfig* instance();
|
static KdeConnectConfig* instance();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Our own info
|
* Our own info
|
||||||
*/
|
*/
|
||||||
|
@ -54,25 +53,28 @@ public:
|
||||||
|
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Trusted devices
|
* Trusted devices
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QStringList trustedDevices(); //Get a list of ids
|
QStringList trustedDevices(); //list of ids
|
||||||
void removeTrustedDevice(QString id);
|
void removeTrustedDevice(QString id);
|
||||||
void addTrustedDevice(QString id, QString name, QString type, QString publicKey);
|
void addTrustedDevice(QString id, QString name, QString type, QString publicKey);
|
||||||
KdeConnectConfig::DeviceInfo getTrustedDevice(QString id);
|
KdeConnectConfig::DeviceInfo getTrustedDevice(QString id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Paths for config files, there is no guarantee the directories already exist
|
||||||
|
*/
|
||||||
QDir baseConfigDir();
|
QDir baseConfigDir();
|
||||||
QDir deviceConfigDir(QString deviceId);
|
QDir deviceConfigDir(QString deviceId);
|
||||||
|
QDir pluginConfigDir(QString deviceId, QString pluginName); //Used by KdeConnectPluginConfig
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KdeConnectConfig();
|
KdeConnectConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<KdeConnectConfigPrivate> d;
|
QScopedPointer<KdeConnectConfigPrivate> d;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,20 +19,34 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "kdeconnectplugin.h"
|
#include "kdeconnectplugin.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
struct KdeConnectPluginPrivate
|
struct KdeConnectPluginPrivate
|
||||||
{
|
{
|
||||||
Device* mDevice;
|
Device* mDevice;
|
||||||
|
QString mPluginName;
|
||||||
QSet<QString> mOutgoingTypes;
|
QSet<QString> mOutgoingTypes;
|
||||||
|
KdeConnectPluginConfig* mConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
KdeConnectPlugin::KdeConnectPlugin(QObject* parent, const QVariantList& args)
|
KdeConnectPlugin::KdeConnectPlugin(QObject* parent, const QVariantList& args)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, d(new KdeConnectPluginPrivate)
|
, d(new KdeConnectPluginPrivate)
|
||||||
{
|
{
|
||||||
d->mDevice = qvariant_cast< Device* >(args.first());
|
d->mDevice = qvariant_cast< Device* >(args.at(0));
|
||||||
d->mOutgoingTypes = args.last().toStringList().toSet();
|
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()
|
KdeConnectPlugin::~KdeConnectPlugin()
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <QVariantList>
|
#include <QVariantList>
|
||||||
|
|
||||||
#include "kdeconnectcore_export.h"
|
#include "kdeconnectcore_export.h"
|
||||||
|
#include "kdeconnectpluginconfig.h"
|
||||||
#include "networkpackage.h"
|
#include "networkpackage.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
|
@ -44,6 +45,8 @@ public:
|
||||||
|
|
||||||
bool sendPackage(NetworkPackage& np) const;
|
bool sendPackage(NetworkPackage& np) const;
|
||||||
|
|
||||||
|
KdeConnectPluginConfig* config() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
/**
|
/**
|
||||||
* Returns true if it has handled the package in some way
|
* Returns true if it has handled the package in some way
|
||||||
|
|
67
core/kdeconnectpluginconfig.cpp
Normal file
67
core/kdeconnectpluginconfig.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2015 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 "kdeconnectpluginconfig.h"
|
||||||
|
|
||||||
|
#include <KF5/KConfigCore/kconfig.h>
|
||||||
|
#include <KConfigGroup>
|
||||||
|
#include <KSharedConfig>
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
#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();
|
||||||
|
}
|
68
core/kdeconnectpluginconfig.h
Normal file
68
core/kdeconnectpluginconfig.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2015 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 KDECONNECTPLUGINCONFIG_H
|
||||||
|
#define KDECONNECTPLUGINCONFIG_H
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#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<typename T> T get(const QString& key, const T& defaultValue = default_arg<T>::get()) {
|
||||||
|
return get(key, QVariant(defaultValue)).template value<T>(); //Important note: Awesome template syntax is awesome
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QScopedPointer<KdeConnectPluginConfigPrivate> d;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -57,13 +57,13 @@ KPluginInfo PluginLoader::getPluginInfo(const QString& name) const
|
||||||
return KPluginInfo(service);
|
return KPluginInfo(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
KdeConnectPlugin* PluginLoader::instantiatePluginForDevice(const QString& name, Device* device) const
|
KdeConnectPlugin* PluginLoader::instantiatePluginForDevice(const QString& pluginName, Device* device) const
|
||||||
{
|
{
|
||||||
KdeConnectPlugin* ret = 0;
|
KdeConnectPlugin* ret = 0;
|
||||||
|
|
||||||
KService::Ptr service = plugins[name];
|
KService::Ptr service = plugins[pluginName];
|
||||||
if (!service) {
|
if (!service) {
|
||||||
qCDebug(KDECONNECT_CORE) << "Plugin unknown" << name;
|
qCDebug(KDECONNECT_CORE) << "Plugin unknown" << pluginName;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ KdeConnectPlugin* PluginLoader::instantiatePluginForDevice(const QString& name,
|
||||||
|
|
||||||
QVariant deviceVariant = QVariant::fromValue<Device*>(device);
|
QVariant deviceVariant = QVariant::fromValue<Device*>(device);
|
||||||
|
|
||||||
ret = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << outgoingInterfaces);
|
ret = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << pluginName << outgoingInterfaces);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
qCDebug(KDECONNECT_CORE) << "Error loading plugin";
|
qCDebug(KDECONNECT_CORE) << "Error loading plugin";
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-kcm")
|
add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-kcm")
|
||||||
|
|
||||||
|
find_package(KF5KCMUtils 5.9 REQUIRED)
|
||||||
|
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${CMAKE_SOURCE_DIR}
|
${CMAKE_SOURCE_DIR}
|
||||||
|
|
|
@ -182,6 +182,8 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
|
||||||
kcmUi->pluginSelector = new KPluginSelector(this);
|
kcmUi->pluginSelector = new KPluginSelector(this);
|
||||||
kcmUi->verticalLayout_2->addWidget(kcmUi->pluginSelector);
|
kcmUi->verticalLayout_2->addWidget(kcmUi->pluginSelector);
|
||||||
|
|
||||||
|
kcmUi->pluginSelector->setConfigurationArguments(QStringList(currentDevice->id()));
|
||||||
|
|
||||||
kcmUi->name_label->setText(currentDevice->name());
|
kcmUi->name_label->setText(currentDevice->name());
|
||||||
kcmUi->status_label->setText(currentDevice->isPaired()? i18n("(paired)") : i18n("(unpaired)"));
|
kcmUi->status_label->setText(currentDevice->isPaired()? i18n("(paired)") : i18n("(unpaired)"));
|
||||||
|
|
||||||
|
|
29
kcmplugin/CMakeLists.txt
Normal file
29
kcmplugin/CMakeLists.txt
Normal file
|
@ -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})
|
60
kcmplugin/kdeconnectpluginkcm.cpp
Normal file
60
kcmplugin/kdeconnectpluginkcm.cpp
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* 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 "kdeconnectpluginkcm.h"
|
||||||
|
|
||||||
|
#include <KAboutData>
|
||||||
|
#include <KService>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
58
kcmplugin/kdeconnectpluginkcm.h
Normal file
58
kcmplugin/kdeconnectpluginkcm.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2015 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 KDECONNECTPLUGINKCM_H
|
||||||
|
#define KDECONNECTPLUGINKCM_H
|
||||||
|
|
||||||
|
#include <KCModule>
|
||||||
|
|
||||||
|
#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<KdeConnectPluginKcmPrivate> d;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -5,11 +5,10 @@ set(kdeconnect_pausemusic_SRCS
|
||||||
add_library(kdeconnect_pausemusic MODULE ${kdeconnect_pausemusic_SRCS})
|
add_library(kdeconnect_pausemusic MODULE ${kdeconnect_pausemusic_SRCS})
|
||||||
|
|
||||||
target_link_libraries(kdeconnect_pausemusic
|
target_link_libraries(kdeconnect_pausemusic
|
||||||
|
kdeconnectcore
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
Qt5::DBus
|
Qt5::DBus
|
||||||
KF5::ConfigCore
|
|
||||||
KF5::Service
|
KF5::Service
|
||||||
kdeconnectcore
|
|
||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS kdeconnect_pausemusic DESTINATION ${PLUGIN_INSTALL_DIR} )
|
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} )
|
add_library(kdeconnect_pausemusic_config MODULE ${kdeconnect_pausemusic_config_SRCS} )
|
||||||
target_link_libraries( kdeconnect_pausemusic_config
|
target_link_libraries( kdeconnect_pausemusic_config
|
||||||
Qt5::Core
|
kdeconnectcore
|
||||||
|
kdeconnectpluginkcm
|
||||||
KF5::I18n
|
KF5::I18n
|
||||||
KF5::KCMUtils
|
KF5::KCMUtils
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,20 +19,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pausemusic_config.h"
|
#include "pausemusic_config.h"
|
||||||
|
#include "ui_pausemusic_config.h"
|
||||||
|
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
#include <KSharedConfig>
|
|
||||||
#include <KConfigGroup>
|
|
||||||
#include <KAboutData>
|
|
||||||
|
|
||||||
#include "ui_pausemusic_config.h"
|
|
||||||
|
|
||||||
K_PLUGIN_FACTORY(PauseMusicConfigFactory, registerPlugin<PauseMusicConfig>();)
|
K_PLUGIN_FACTORY(PauseMusicConfigFactory, registerPlugin<PauseMusicConfig>();)
|
||||||
|
|
||||||
PauseMusicConfig::PauseMusicConfig(QWidget *parent, const QVariantList& )
|
PauseMusicConfig::PauseMusicConfig(QWidget *parent, const QVariantList& args)
|
||||||
: KCModule(KAboutData::pluginData("kdeconnect_pausemusic_config"), parent)
|
: KdeConnectPluginKcm(parent, args, "kdeconnect_pausemusic_config")
|
||||||
, m_ui(new Ui::PauseMusicConfigUi())
|
, m_ui(new Ui::PauseMusicConfigUi())
|
||||||
, m_cfg(KSharedConfig::openConfig("kdeconnect/plugins/pausemusic"))
|
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -57,29 +52,27 @@ void PauseMusicConfig::defaults()
|
||||||
Q_EMIT changed(true);
|
Q_EMIT changed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PauseMusicConfig::load()
|
void PauseMusicConfig::load()
|
||||||
{
|
{
|
||||||
KCModule::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_talking->setChecked(talking);
|
||||||
m_ui->rad_ringing->setChecked(!talking);
|
m_ui->rad_ringing->setChecked(!talking);
|
||||||
|
|
||||||
bool pause = m_cfg->group("actions").readEntry("pause", true);
|
bool pause = config()->get("actionPause", true);
|
||||||
bool mute = m_cfg->group("actions").readEntry("mute", false);
|
bool mute = config()->get("actionMute", false);
|
||||||
m_ui->check_pause->setChecked(pause);
|
m_ui->check_pause->setChecked(pause);
|
||||||
m_ui->check_mute->setChecked(mute);
|
m_ui->check_mute->setChecked(mute);
|
||||||
|
|
||||||
Q_EMIT changed(false);
|
Q_EMIT changed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PauseMusicConfig::save()
|
void PauseMusicConfig::save()
|
||||||
{
|
{
|
||||||
m_cfg->group("condition").writeEntry("talking_only", m_ui->rad_talking->isChecked());
|
config()->set("conditionTalking", m_ui->rad_talking->isChecked());
|
||||||
m_cfg->group("actions").writeEntry("pause", m_ui->check_pause->isChecked());
|
config()->set("actionPause", m_ui->check_pause->isChecked());
|
||||||
m_cfg->group("actions").writeEntry("mute", m_ui->check_mute->isChecked());
|
config()->set("actionMute", m_ui->check_mute->isChecked());
|
||||||
KCModule::save();
|
KCModule::save();
|
||||||
|
|
||||||
Q_EMIT changed(false);
|
Q_EMIT changed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,14 @@
|
||||||
#ifndef PAUSEMUSIC_CONFIG_H
|
#ifndef PAUSEMUSIC_CONFIG_H
|
||||||
#define PAUSEMUSIC_CONFIG_H
|
#define PAUSEMUSIC_CONFIG_H
|
||||||
|
|
||||||
#include <kcmodule.h>
|
#include "kcmplugin/kdeconnectpluginkcm.h"
|
||||||
#include <ksharedconfig.h>
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PauseMusicConfigUi;
|
class PauseMusicConfigUi;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PauseMusicConfig
|
class PauseMusicConfig
|
||||||
: public KCModule
|
: public KdeConnectPluginKcm
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -43,7 +42,6 @@ public Q_SLOTS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::PauseMusicConfigUi* m_ui;
|
Ui::PauseMusicConfigUi* m_ui;
|
||||||
KSharedConfigPtr m_cfg;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,15 +23,12 @@
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <QDBusConnectionInterface>
|
#include <QDBusConnectionInterface>
|
||||||
#include <QDBusReply>
|
|
||||||
#include <QDBusMessage>
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusReply>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include <KSharedConfig>
|
|
||||||
#include <KConfigGroup>
|
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
|
|
||||||
#include <core/networkpackage.h>
|
|
||||||
|
|
||||||
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PauseMusicPlugin >(); )
|
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PauseMusicPlugin >(); )
|
||||||
|
|
||||||
//TODO: Port this away from KMix to use only Pulseaudio
|
//TODO: Port this away from KMix to use only Pulseaudio
|
||||||
|
@ -55,7 +52,6 @@ int PauseMusicPlugin::isKMixMuted() {
|
||||||
return (mixerInterface.property("volume").toInt() == 0);
|
return (mixerInterface.property("volume").toInt() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
|
PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
|
||||||
: KdeConnectPlugin(parent, args)
|
: KdeConnectPlugin(parent, args)
|
||||||
, muted(false)
|
, muted(false)
|
||||||
|
@ -65,9 +61,7 @@ PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
|
||||||
|
|
||||||
bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
|
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
|
bool pauseOnlyWhenTalking = config()->get("conditionTalking", false);
|
||||||
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/pausemusic");
|
|
||||||
bool pauseOnlyWhenTalking = config->group("condition").readEntry("talking_only", false);
|
|
||||||
|
|
||||||
if (pauseOnlyWhenTalking) {
|
if (pauseOnlyWhenTalking) {
|
||||||
if (np.get<QString>("event") != "talking") {
|
if (np.get<QString>("event") != "talking") {
|
||||||
|
@ -81,8 +75,8 @@ bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
|
||||||
|
|
||||||
bool pauseConditionFulfilled = !np.get<bool>("isCancel");
|
bool pauseConditionFulfilled = !np.get<bool>("isCancel");
|
||||||
|
|
||||||
bool pause = config->group("actions").readEntry("pause", true);
|
bool pause = config()->get("actionPause", true);
|
||||||
bool mute = config->group("actions").readEntry("mute", false);
|
bool mute = config()->get("actionMute", false);
|
||||||
|
|
||||||
if (pauseConditionFulfilled) {
|
if (pauseConditionFulfilled) {
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KNotification>
|
#include <KNotification>
|
||||||
#include <KRun>
|
#include <KRun>
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <KFilePlacesModel>
|
#include <KFilePlacesModel>
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
|
|
||||||
|
@ -158,8 +157,8 @@ bool SftpPlugin::receivePackage(const NetworkPackage& np)
|
||||||
|
|
||||||
QString SftpPlugin::mountPoint()
|
QString SftpPlugin::mountPoint()
|
||||||
{
|
{
|
||||||
const QString mountDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
|
QDir mountDir = config()->privateDirectory();
|
||||||
return QDir(mountDir).absoluteFilePath(deviceId);
|
return mountDir.absoluteFilePath(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SftpPlugin::onMounted()
|
void SftpPlugin::onMounted()
|
||||||
|
|
|
@ -26,8 +26,8 @@ ki18n_wrap_ui( kdeconnect_share_config_SRCS share_config.ui )
|
||||||
|
|
||||||
add_library(kdeconnect_share_config MODULE ${kdeconnect_share_config_SRCS} )
|
add_library(kdeconnect_share_config MODULE ${kdeconnect_share_config_SRCS} )
|
||||||
target_link_libraries( kdeconnect_share_config
|
target_link_libraries( kdeconnect_share_config
|
||||||
|
kdeconnectpluginkcm
|
||||||
KF5::I18n
|
KF5::I18n
|
||||||
KF5::KCMUtils
|
|
||||||
KF5::CoreAddons
|
KF5::CoreAddons
|
||||||
KF5::ConfigWidgets
|
KF5::ConfigWidgets
|
||||||
KF5::KIOWidgets
|
KF5::KIOWidgets
|
||||||
|
|
|
@ -19,24 +19,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "share_config.h"
|
#include "share_config.h"
|
||||||
|
#include "ui_share_config.h"
|
||||||
|
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include <KConfigGroup>
|
|
||||||
#include <KPluginFactory>
|
|
||||||
#include <KSharedConfig>
|
|
||||||
#include <KUrlRequester>
|
#include <KUrlRequester>
|
||||||
#include <KAboutData>
|
#include <KPluginFactory>
|
||||||
#include <KCModule>
|
|
||||||
|
|
||||||
#include "ui_share_config.h"
|
|
||||||
|
|
||||||
K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin<ShareConfig>();)
|
K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin<ShareConfig>();)
|
||||||
|
|
||||||
ShareConfig::ShareConfig(QWidget *parent, const QVariantList& )
|
ShareConfig::ShareConfig(QWidget *parent, const QVariantList& args)
|
||||||
: KCModule(KAboutData::pluginData("kdeconnect_share_config"), parent)
|
: KdeConnectPluginKcm(parent, args, "kdeconnect_share_config")
|
||||||
, m_ui(new Ui::ShareConfigUi())
|
, m_ui(new Ui::ShareConfigUi())
|
||||||
, m_cfg(KSharedConfig::openConfig("kdeconnect/plugins/share"))
|
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -57,21 +51,18 @@ void ShareConfig::defaults()
|
||||||
Q_EMIT changed(true);
|
Q_EMIT changed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ShareConfig::load()
|
void ShareConfig::load()
|
||||||
{
|
{
|
||||||
KCModule::load();
|
KCModule::load();
|
||||||
|
|
||||||
m_ui->kurlrequester->setUrl(m_cfg->group("receive").readEntry("path",
|
m_ui->kurlrequester->setUrl(config()->get("incoming_path", QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)));
|
||||||
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)));
|
|
||||||
|
|
||||||
Q_EMIT changed(false);
|
Q_EMIT changed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ShareConfig::save()
|
void ShareConfig::save()
|
||||||
{
|
{
|
||||||
m_cfg->group("receive").writeEntry("path", m_ui->kurlrequester->text());
|
config()->set("incoming_path", m_ui->kurlrequester->text());
|
||||||
|
|
||||||
KCModule::save();
|
KCModule::save();
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,14 @@
|
||||||
#ifndef SHARE_CONFIG_H
|
#ifndef SHARE_CONFIG_H
|
||||||
#define SHARE_CONFIG_H
|
#define SHARE_CONFIG_H
|
||||||
|
|
||||||
#include <kcmodule.h>
|
#include "kcmplugin/kdeconnectpluginkcm.h"
|
||||||
#include <ksharedconfig.h>
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ShareConfigUi;
|
class ShareConfigUi;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ShareConfig
|
class ShareConfig
|
||||||
: public KCModule
|
: public KdeConnectPluginKcm
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -43,7 +42,6 @@ public Q_SLOTS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ShareConfigUi* m_ui;
|
Ui::ShareConfigUi* m_ui;
|
||||||
KSharedConfigPtr m_cfg;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,8 @@ SharePlugin::SharePlugin(QObject* parent, const QVariantList& args)
|
||||||
|
|
||||||
QUrl SharePlugin::destinationDir() const
|
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
|
const QString defaultDownloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||||
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/share");
|
QString dir = config()->get<QString>("incoming_path", defaultDownloadPath);
|
||||||
const QString downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
|
||||||
QString dir = config->group("receive").readEntry("path", downloadPath);
|
|
||||||
|
|
||||||
if (dir.contains("%1")) {
|
if (dir.contains("%1")) {
|
||||||
dir = dir.arg(device()->name());
|
dir = dir.arg(device()->name());
|
||||||
|
@ -106,7 +104,6 @@ bool SharePlugin::receivePackage(const NetworkPackage& np)
|
||||||
|
|
||||||
NetworkPackage out(PACKAGE_TYPE_SHARE);
|
NetworkPackage out(PACKAGE_TYPE_SHARE);
|
||||||
out.set("filename", mDestinationDir + "itworks.txt");
|
out.set("filename", mDestinationDir + "itworks.txt");
|
||||||
//TODO: Use shared pointers
|
|
||||||
AutoClosingQFile* file = new AutoClosingQFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc"); //Test file to transfer
|
AutoClosingQFile* file = new AutoClosingQFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc"); //Test file to transfer
|
||||||
|
|
||||||
out.setPayload(file, file->size());
|
out.setPayload(file, file->size());
|
||||||
|
|
Loading…
Reference in a new issue