Commit 095a7a23 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

New QML Class: SharedConfig

A simple QML wrapper for KSharedConfig. Makes it possible to have our own
configuration file instead of having our configuration buried in plasma
applet configurations.
parent 87c02126
......@@ -6,6 +6,7 @@ set(salcomponents_SRCS
placesmodel.cpp
powermodel.cpp
runnerinfoprovider.cpp
sharedconfig.cpp
salrunnermodel.cpp
salservicemodel.cpp
salcomponentsplugin.cpp
......
......@@ -24,6 +24,7 @@
#include <Plasma/QueryMatch>
#include "sharedconfig.h"
#include "favoriteappsmodel.h"
#include "pagemodel.h"
#include "placesmodel.h"
......@@ -41,6 +42,7 @@ void SalComponentsPlugin::registerTypes(const char *uri)
qmlRegisterType<PlacesModel>(uri, 0, 1, "PlacesModel");
qmlRegisterType<PowerModel>(uri, 0, 1, "PowerModel");
qmlRegisterType<RunnerInfoProvider>(uri, 0, 1, "RunnerInfoProvider");
qmlRegisterType<SharedConfig>(uri, 0, 1, "SharedConfig");
qmlRegisterType<SalRunnerModel>(uri, 0, 1, "SalRunnerModel");
qmlRegisterType<SalServiceModel>(uri, 0, 1, "SalServiceModel");
qmlRegisterInterface<Plasma::QueryMatch>("QueryMatch");
......
/*
* Copyright 2012 Aurélien Gâteau <agateau@kde.org>
*
* 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 Library 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.
*/
// Self
#include <sharedconfig.h>
// Local
// KDE
#include <KConfigGroup>
// Qt
SharedConfig::SharedConfig(QObject *parent)
: QObject(parent)
{
}
QString SharedConfig::name() const
{
return m_config ? m_config->name() : QString();
}
void SharedConfig::setName(const QString &newName)
{
if (newName == name()) {
return;
}
m_config = KSharedConfig::openConfig(newName);
nameChanged(newName);
}
QString SharedConfig::readEntry(const QString &groupName, const QString &key, const QString &defaultValue)
{
KConfigGroup group(m_config, groupName);
return group.readEntry(key, defaultValue);
}
#include <sharedconfig.moc>
/*
* Copyright 2012 Aurélien Gâteau <agateau@kde.org>
*
* 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 Library 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 SHAREDCONFIG_H
#define SHAREDCONFIG_H
// Local
// Qt
#include <QObject>
// KDE
#include <KSharedConfig>
/**
* Simple QML wrapper for KSharedConfig
*/
class SharedConfig : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged);
public:
explicit SharedConfig(QObject *parent = 0);
QString name() const;
void setName(const QString &name);
Q_INVOKABLE QString readEntry(const QString &group, const QString &key, const QString &defaultValue = QString());
Q_SIGNALS:
void nameChanged(const QString &);
private:
KSharedConfig::Ptr m_config;
};
#endif /* SHAREDCONFIG_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment