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
|
||||
|
||||
kdeconnectplugin.cpp
|
||||
kdeconnectpluginconfig.cpp
|
||||
pluginloader.cpp
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<KdeConnectConfigPrivate> d;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,20 +19,34 @@
|
|||
*/
|
||||
|
||||
#include "kdeconnectplugin.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
struct KdeConnectPluginPrivate
|
||||
{
|
||||
Device* mDevice;
|
||||
QString mPluginName;
|
||||
QSet<QString> 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()
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QVariantList>
|
||||
|
||||
#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
|
||||
|
|
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);
|
||||
}
|
||||
|
||||
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*>(device);
|
||||
|
||||
ret = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << outgoingInterfaces);
|
||||
ret = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << pluginName << outgoingInterfaces);
|
||||
if (!ret) {
|
||||
qCDebug(KDECONNECT_CORE) << "Error loading plugin";
|
||||
return ret;
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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)"));
|
||||
|
||||
|
|
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})
|
||||
|
||||
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
|
||||
)
|
||||
|
|
|
@ -19,20 +19,15 @@
|
|||
*/
|
||||
|
||||
#include "pausemusic_config.h"
|
||||
#include "ui_pausemusic_config.h"
|
||||
|
||||
#include <KPluginFactory>
|
||||
#include <KSharedConfig>
|
||||
#include <KConfigGroup>
|
||||
#include <KAboutData>
|
||||
|
||||
#include "ui_pausemusic_config.h"
|
||||
|
||||
K_PLUGIN_FACTORY(PauseMusicConfigFactory, registerPlugin<PauseMusicConfig>();)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,15 +21,14 @@
|
|||
#ifndef PAUSEMUSIC_CONFIG_H
|
||||
#define PAUSEMUSIC_CONFIG_H
|
||||
|
||||
#include <kcmodule.h>
|
||||
#include <ksharedconfig.h>
|
||||
#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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -23,15 +23,12 @@
|
|||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusReply>
|
||||
#include <QDebug>
|
||||
|
||||
#include <KSharedConfig>
|
||||
#include <KConfigGroup>
|
||||
#include <KPluginFactory>
|
||||
|
||||
#include <core/networkpackage.h>
|
||||
|
||||
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<QString>("event") != "talking") {
|
||||
|
@ -81,8 +75,8 @@ bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
|
|||
|
||||
bool pauseConditionFulfilled = !np.get<bool>("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) {
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <KLocalizedString>
|
||||
#include <KNotification>
|
||||
#include <KRun>
|
||||
#include <QStandardPaths>
|
||||
#include <KFilePlacesModel>
|
||||
#include <KPluginFactory>
|
||||
|
||||
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,24 +19,18 @@
|
|||
*/
|
||||
|
||||
#include "share_config.h"
|
||||
#include "ui_share_config.h"
|
||||
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KPluginFactory>
|
||||
#include <KSharedConfig>
|
||||
#include <KUrlRequester>
|
||||
#include <KAboutData>
|
||||
#include <KCModule>
|
||||
|
||||
#include "ui_share_config.h"
|
||||
#include <KPluginFactory>
|
||||
|
||||
K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin<ShareConfig>();)
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -21,15 +21,14 @@
|
|||
#ifndef SHARE_CONFIG_H
|
||||
#define SHARE_CONFIG_H
|
||||
|
||||
#include <kcmodule.h>
|
||||
#include <ksharedconfig.h>
|
||||
#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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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<QString>("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());
|
||||
|
|
Loading…
Reference in a new issue