experiment for a declarative config skeleton
maps a KConfigSkeleton to a QQmlPropertyMap, allowing a "declarative" use of configs not sure will be an efficient approach enough but it seems to work correctly
This commit is contained in:
parent
ac5a34dfe4
commit
672b0bdfc1
@ -13,6 +13,7 @@ include_directories(${KDE4_INCLUDE_DIR}/KDE ${PHONON_INCLUDES} ${CMAKE_CURRENT_S
|
||||
|
||||
#DECLARATIVE APPLET
|
||||
set(declarative_appletscript_SRCS
|
||||
declarative/configpropertymap.cpp
|
||||
declarative/packageaccessmanager.cpp
|
||||
declarative/packageaccessmanagerfactory.cpp
|
||||
declarative/qmlobject.cpp
|
||||
|
84
src/scriptengines/qml/declarative/configpropertymap.cpp
Normal file
84
src/scriptengines/qml/declarative/configpropertymap.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2013 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "configpropertymap.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <KConfigSkeletonItem>
|
||||
|
||||
|
||||
ConfigPropertyMap::ConfigPropertyMap(KConfigSkeleton *config, QObject *parent)
|
||||
: QQmlPropertyMap(parent),
|
||||
m_config(config)
|
||||
{
|
||||
connect(config, &KConfigSkeleton::configChanged,
|
||||
this, &ConfigPropertyMap::loadConfig);
|
||||
connect(this, &ConfigPropertyMap::valueChanged,
|
||||
this, &ConfigPropertyMap::writeConfigValue);
|
||||
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
ConfigPropertyMap::~ConfigPropertyMap()
|
||||
{
|
||||
writeConfig();
|
||||
}
|
||||
|
||||
void ConfigPropertyMap::loadConfig()
|
||||
{
|
||||
if (!m_config) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (KConfigSkeletonItem *item, m_config.data()->items()) {
|
||||
insert(item->key(), item->property());
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigPropertyMap::writeConfig()
|
||||
{
|
||||
if (!m_config) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (KConfigSkeletonItem *item, m_config.data()->items()) {
|
||||
item->setProperty(value(item->key()));
|
||||
}
|
||||
|
||||
m_config.data()->blockSignals(true);
|
||||
m_config.data()->writeConfig();
|
||||
m_config.data()->blockSignals(false);
|
||||
}
|
||||
|
||||
void ConfigPropertyMap::writeConfigValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
KConfigSkeletonItem *item = m_config.data()->findItem(key);
|
||||
if (item) {
|
||||
item->setProperty(value);
|
||||
m_config.data()->blockSignals(true);
|
||||
m_config.data()->writeConfig();
|
||||
m_config.data()->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_configpropertymap.cpp"
|
||||
|
||||
|
||||
|
45
src/scriptengines/qml/declarative/configpropertymap.h
Normal file
45
src/scriptengines/qml/declarative/configpropertymap.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2013 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef CONFIGPROPERTYMAP_P
|
||||
#define CONFIGPROPERTYMAP_P
|
||||
|
||||
#include <QQmlPropertyMap>
|
||||
|
||||
#include <KConfigSkeleton>
|
||||
|
||||
|
||||
class ConfigPropertyMap : public QQmlPropertyMap
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ConfigPropertyMap(KConfigSkeleton *config, QObject *parent = 0);
|
||||
~ConfigPropertyMap();
|
||||
|
||||
private Q_SLOTS:
|
||||
void loadConfig();
|
||||
void writeConfig();
|
||||
void writeConfigValue(const QString &key, const QVariant &value);
|
||||
|
||||
private:
|
||||
QWeakPointer<KConfigSkeleton>m_config;
|
||||
};
|
||||
|
||||
#endif
|
@ -42,6 +42,7 @@
|
||||
#include <Plasma/Package>
|
||||
|
||||
#include "containmentinterface.h"
|
||||
#include "declarative/configpropertymap.h"
|
||||
|
||||
Q_DECLARE_METATYPE(AppletInterface*)
|
||||
|
||||
@ -54,6 +55,9 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
|
||||
m_expanded(false)
|
||||
{
|
||||
qmlRegisterType<AppletInterface>();
|
||||
|
||||
m_configuration = new ConfigPropertyMap(applet()->configScheme(), this);
|
||||
|
||||
connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus()));
|
||||
connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving()));
|
||||
connect(applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SIGNAL(immutableChanged()));
|
||||
@ -107,6 +111,11 @@ QString AppletInterface::currentActivity() const
|
||||
return applet()->containment()->activity();
|
||||
}
|
||||
|
||||
QObject* AppletInterface::configuration() const
|
||||
{
|
||||
return m_configuration;
|
||||
}
|
||||
|
||||
QString AppletInterface::icon() const
|
||||
{
|
||||
return applet()->icon();
|
||||
|
@ -35,6 +35,8 @@ class QmlAppletScript;
|
||||
class QSignalMapper;
|
||||
class QSizeF;
|
||||
|
||||
class ConfigPropertyMap;
|
||||
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -58,6 +60,7 @@ class AppletInterface : public QQuickItem
|
||||
Q_PROPERTY(FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
|
||||
Q_PROPERTY(Location location READ location NOTIFY locationChanged)
|
||||
Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY contextChanged)
|
||||
Q_PROPERTY(QObject* configuration READ configuration CONSTANT)
|
||||
Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig)
|
||||
Q_PROPERTY(bool busy WRITE setBusy READ isBusy NOTIFY busyChanged)
|
||||
Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged)
|
||||
@ -184,6 +187,8 @@ enum IntervalAlignment {
|
||||
|
||||
QString currentActivity() const;
|
||||
|
||||
QObject* configuration() const;
|
||||
|
||||
bool isBusy() const;
|
||||
void setBusy(bool busy);
|
||||
|
||||
@ -233,6 +238,8 @@ private:
|
||||
QMap<QString, Plasma::ConfigLoader*> m_configs;
|
||||
|
||||
|
||||
ConfigPropertyMap *m_configuration;
|
||||
|
||||
//UI-specific members ------------------
|
||||
QWeakPointer<QObject> m_uiObject;
|
||||
QWeakPointer<QObject> m_compactUiObject;
|
||||
|
@ -64,6 +64,12 @@ Rectangle {
|
||||
plasmoid.busy = !plasmoid.busy
|
||||
}
|
||||
}
|
||||
TextInput {
|
||||
width: 100
|
||||
height: 22
|
||||
text: plasmoid.configuration.Test
|
||||
onTextChanged: plasmoid.configuration.Test = text
|
||||
}
|
||||
}
|
||||
Component.onCompleted: {
|
||||
print("Test Applet loaded")
|
||||
|
Loading…
Reference in New Issue
Block a user