Commit c0b57835 authored by Nicolas Fella's avatar Nicolas Fella

[WIP] rewrite everything

parent d95695f6
......@@ -57,7 +57,6 @@ if (KAccounts_FOUND AND AccountsQt5_FOUND AND SignOnQt5_FOUND)
endif()
add_subdirectory(src)
add_subdirectory(import)
add_subdirectory(modules)
install(DIRECTORY package/ DESTINATION ${KDE_INSTALL_DATAROOTDIR}/kpackage/genericqml/org.kde.plasma.settings)
......
project(settings)
set(settings_SRCS
package.cpp
settingsplugin.cpp
settingsmodule.cpp
settingsmodulesmodel.cpp
settingscomponent.cpp
configgroup.cpp
)
add_library(settingsplugin SHARED ${settings_SRCS})
target_link_libraries(settingsplugin
Qt5::Core
Qt5::Qml
Qt5::Quick
KF5::I18n
KF5::Package
KF5::QuickAddons
KF5::ConfigCore
)
install(TARGETS settingsplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/active/settings)
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/active/settings)
install(FILES SettingsItem.qml DESTINATION ${QML_INSTALL_DIR}/org/kde/active/settings)
You can find documentation for using the Active Settins infrastructure at
http://techbase.kde.org/Development/Tutorials/Plasma/QML/ActiveSettings
// -*- coding: iso-8859-1 -*-
/*
* Copyright 2011-2012 Sebastian Kügler <sebas@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.
*/
import QtQuick 2.2
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.mobilecomponents 0.2 as MobileComponents
import org.kde.active.settings 2.0 as ActiveSettings
PlasmaComponents.PageStack {
id: moduleContainer
objectName: "moduleContainer"
property alias module: settingsComponent.module
property alias icon: settingsComponent.icon
signal moduleLoaded
function pushModule(module) {
switcherPackage.name = module
var mainscript = switcherPackage.filePath("mainscript");
//print("Loading mainscript: " + mainscript);
settingsLoader.source = mainscript;
moduleContainer.push(settingsLoader);
moduleContainer.module = module
}
clip: true
Loader {
id: settingsLoader
anchors.fill: parent
}
ActiveSettings.SettingsComponent {
id: settingsComponent
onModuleChanged: {
if (module == "") {
moduleContainer.pop();
} else if (switcherPackage.name != module) {
switcherPackage.name = module
//print(" Loading package: " + switcherPackage.filePath("mainscript") + " " + module);
var mainscript = switcherPackage.filePath("mainscript");
settingsLoader.source = switcherPackage.filePath("mainscript");
//moduleContainer.replace(switcherPackage.filePath("mainscript"));
print("Loaded mainscript: " + mainscript);
moduleLoaded();
}
}
}
ActiveSettings.Package {
id: switcherPackage
}
}
/*
* Copyright 2011-2012 by Sebastian Kügler <sebas@kde.org>
* Copyright 2013 by Aaron Seigo <aseigo@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 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 "configgroup.h"
#include <QtCore/QTimer>
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QDebug>
namespace Plasma
{
class ConfigGroupPrivate {
public:
ConfigGroupPrivate(ConfigGroup *q)
: q(q),
config(nullptr),
configGroup(nullptr)
{}
~ConfigGroupPrivate()
{
delete configGroup;
}
ConfigGroup* q;
KSharedConfigPtr config;
KConfigGroup *configGroup;
QString file;
QTimer *syncTimer;
QString group;
};
ConfigGroup::ConfigGroup(QQuickItem *parent)
: QQuickItem(parent),
d(new ConfigGroupPrivate(this))
{
// Delay and compress everything within 5 seconds into one sync
d->syncTimer = new QTimer(this);
d->syncTimer->setSingleShot(true);
d->syncTimer->setInterval(1500);
connect(d->syncTimer, &QTimer::timeout, this, &ConfigGroup::sync);
}
ConfigGroup::~ConfigGroup()
{
if (d->syncTimer->isActive()) {
qDebug() << "SYNC......";
d->syncTimer->stop();
d->configGroup->sync();
}
delete d;
}
KConfigGroup* ConfigGroup::configGroup()
{
return d->configGroup;
}
QString ConfigGroup::file() const
{
return d->file;
}
void ConfigGroup::setFile(const QString& filename)
{
if (d->file == filename) {
return;
}
d->file = filename;
readConfigFile();
emit fileChanged();
}
QString ConfigGroup::group() const
{
return d->group;
}
void ConfigGroup::setGroup(const QString& groupname)
{
if (d->group == groupname) {
return;
}
d->group = groupname;
qDebug() << "Set group name: " << groupname;
readConfigFile();
emit groupChanged();
emit keyListChanged();
}
QStringList ConfigGroup::keyList() const
{
if (!d->configGroup) {
return QStringList();
}
return d->configGroup->keyList();
}
QStringList ConfigGroup::groupList() const
{
return d->configGroup->groupList();
}
bool ConfigGroup::readConfigFile()
{
// Find parent ConfigGroup
ConfigGroup* parentGroup = nullptr;
QObject* current = parent();
while (current) {
parentGroup = qobject_cast<ConfigGroup*>(current);
if (parentGroup) {
break;
}
current = current->parent();
}
delete d->configGroup;
d->configGroup = nullptr;
if (parentGroup) {
d->configGroup = new KConfigGroup(parentGroup->configGroup(), d->group);
return true;
} else {
if (d->file.isEmpty()) {
//qWarning() << "Could not find KConfig Parent: specify a file or parent to another ConfigGroup";
return false;
}
d->config = KSharedConfig::openConfig(d->file);
d->configGroup = new KConfigGroup(d->config, d->group);
qDebug() << "Opened config" << d->configGroup->entryMap();
return true;
}
}
// Bound methods and slots
bool ConfigGroup::writeEntry(const QString& key, const QVariant& value)
{
if (!d->configGroup) {
return false;
}
d->configGroup->writeEntry(key, value);
d->syncTimer->start();
return true;
}
QVariant ConfigGroup::readEntry(const QString& key)
{
if (!d->configGroup) {
return QVariant();
}
const QVariant value = d->configGroup->readEntry(key, QVariant(""));
qDebug() << " reading setting: " << key << value;
return value;
}
void ConfigGroup::deleteEntry(const QString& key)
{
d->configGroup->deleteEntry(key);
d->syncTimer->start();
}
void ConfigGroup::sync()
{
if (d->configGroup) {
qDebug() << "synching config...";
d->configGroup->sync();
}
}
} // namespace Plasma
/*
* Copyright 2011-2012 by Sebastian Kügler <sebas@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 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 CONFIGGROUP_H
#define CONFIGGROUP_H
#include <QObject>
#include <QQuickItem>
#include <QVariant>
class KConfigGroup;
namespace Plasma
{
class ConfigGroupPrivate;
class ConfigGroup : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(QString file READ file WRITE setFile NOTIFY fileChanged)
Q_PROPERTY(QString group READ group WRITE setGroup NOTIFY groupChanged)
Q_PROPERTY(QStringList keyList READ keyList NOTIFY keyListChanged)
Q_PROPERTY(QStringList groupList READ groupList NOTIFY groupListChanged)
public:
ConfigGroup(QQuickItem* parent=nullptr);
~ConfigGroup() override;
KConfigGroup* configGroup();
QString file() const;
void setFile(const QString &filename);
QString group() const;
void setGroup(const QString &groupname);
QStringList keyList() const;
QStringList groupList() const;
Q_INVOKABLE QVariant readEntry(const QString &key);
Q_INVOKABLE bool writeEntry(const QString &key, const QVariant &value);
Q_INVOKABLE void deleteEntry(const QString& key);
Q_SIGNALS:
void fileChanged();
void groupChanged();
void keyListChanged();
void groupListChanged();
private:
ConfigGroupPrivate* d;
bool readConfigFile();
private Q_SLOTS:
void sync();
};
}
#endif
/***************************************************************************
* Copyright 2011 Marco Martin <mart@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 of the License, 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 . *
***************************************************************************/
#include "package.h"
#include <QStandardPaths>
#include <QDebug>
#include <KLocalizedString>
#include <KPackage/PackageLoader>
Package::Package(QObject *parent)
: QObject(parent)
{
}
Package::~Package()
{
}
QString Package::name() const
{
return m_name;
}
void Package::setName(const QString &name)
{
if (m_name == name) {
return;
}
m_name = name;
m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML"));
m_package.setPath(name);
QString domain = QStringLiteral("plasma_package_") + name;
KLocalizedString::setApplicationDomain(domain.toLocal8Bit().data());
emit nameChanged(name);
emit visibleNameChanged();
}
QString Package::visibleName() const
{
if (!m_package.isValid()) {
return QString();
}
return m_package.metadata().name();
}
QString Package::filePath(const QString &fileType, const QString &fileName) const
{
if (!m_package.isValid()) {
return QString();
}
if (fileName.isEmpty()) {
return m_package.filePath(fileType.toLatin1());
} else {
return m_package.filePath(fileType.toLatin1(), fileName);
}
}
QString Package::filePath(const QString &fileType) const
{
if (!m_package.isValid()) {
return QString();
}
return m_package.filePath(fileType.toLatin1());
}
/***************************************************************************
* Copyright 2011 Marco Martin <mart@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 of the License, 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 PACKAGE_H
#define PACKAGE_H
#include <QQuickItem>
#include <QUrl>
#include <KPackage/Package>
class QTimer;
class Package : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString visibleName READ visibleName NOTIFY visibleNameChanged)
public:
Package(QObject *parent = nullptr);
~Package() override;
QString name() const;
void setName(const QString &name);
Q_INVOKABLE QString filePath(const QString &fileType, const QString &filename) const;
Q_INVOKABLE QString filePath(const QString &fileType) const;
QString visibleName() const;
Q_SIGNALS:
void nameChanged(const QString &);
void visibleNameChanged();
private:
QString m_name;
KPackage::Package m_package;
};
#endif
module org.kde.active.settings
plugin settingsplugin
SettingsItem 2.0 SettingsItem.qml
/*
Copyright 2011 Marco Martin <notmart@gmail.com>
This library 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 of the License, or (at your option) any later version.
This library 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 library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "settingscomponent.h"
#include "settingsmodule.h"
#include <QQmlEngine>
#include <QQmlComponent>
#include <QDebug>
#include <KPluginMetaData>
#include <KPluginLoader>
#include <KPluginFactory>
#include <kquickaddons/configmodule.h>
#include <KPackage/Package>
#include <KPackage/PackageLoader>
class SettingsComponentPrivate {
public:
QString module;
QString icon;
SettingsModule *settingsModule;
KQuickAddons::ConfigModule *kcm;
bool valid : 1;
KPackage::Package package;
};
SettingsComponent::SettingsComponent(QQuickItem *parent)
: QQuickItem(parent)
{
d = new SettingsComponentPrivate;
d->package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML"));
d->settingsModule = nullptr;
d->kcm = nullptr;
d->valid = false;
}
SettingsComponent::~SettingsComponent()
{
}
void SettingsComponent::loadModule(const QString &name)
{
d->settingsModule->deleteLater();
d->settingsModule = nullptr;
d->kcm->deleteLater();
d->kcm = nullptr;
d->package.setPath(name);
//KGlobal::locale()->insertCatalog("plasma_package_" + name);
#warning "Re-enable translation catalog, port insertCatalog"
QString pluginName = name;
QString query;
if (pluginName.isEmpty()) {
qDebug() << "Not loading plugin ..." << pluginName;
return;
}
const QString plugin = KPluginLoader::findPlugin(QLatin1String("kcms/") + name);
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML");
package.setDefaultPackageRoot("kpackage/kcms");
package.setPath(name);
KPluginMetaData info(package.metadata());
//try pure QML mode
if (plugin.isEmpty()) {
d->kcm = new KQuickAddons::ConfigModule(info, this, QVariantList());
} else {
//qml-kcm mode
KPluginLoader loader(plugin);
KPluginFactory* factory = loader.factory();
if (!factory) {
qWarning() << "Error loading KCM plugin:" << loader.errorString();
d->valid = false;
emit validChanged();
return;
} else {
d->kcm = factory->create<KQuickAddons::ConfigModule >();
if (!d->kcm) {
qWarning() << "Error creating object from plugin" << loader.fileName();
d->valid = false;
emit validChanged();
return;
}
}
}
d->settingsModule = new SettingsModule(this);
connect(d->settingsModule, &SettingsModule::nameChanged, this, &SettingsComponent::nameChanged);
connect(d->settingsModule, &SettingsModule::descriptionChanged,
this, &SettingsComponent::descriptionChanged);
if (!d->kcm->mainUi()) {
d->valid = false;
emit validChanged();
return;
}
d->kcm->mainUi()->setParentItem(this);
{
//set anchors
QQmlExpression expr(QtQml::qmlContext(d->kcm->mainUi()), d->kcm->mainUi(), "parent");
QQmlProperty prop(d->kcm->mainUi(), "anchors.fill");
prop.write(expr.evaluate());
}
d->kcm->load();
//instant apply
connect(d->kcm, &KQuickAddons::ConfigModule::needsSaveChanged, [=]() {
if (d->kcm->needsSave()) {
d->kcm->save();
}
});
d->settingsModule->setName(info.name());
setIcon(info.iconName());
d->settingsModule->setDescription(info.description());
d->settingsModule->setModule(info.pluginId());
d->valid = true;
emit mainUiChanged();
emit kcmChanged();
emit validChanged();
}
QQuickItem *SettingsComponent::mainUi() const
{
if (d->kcm) {
return d->kcm->mainUi();
}
return nullptr;
}
KQuickAddons::ConfigModule *SettingsComponent::kcm() const
{
return d->kcm;
}
bool SettingsComponent::isValid() const
{
return d->valid;
}
QString SettingsComponent::description() const
{
if (d->settingsModule) {
return d->settingsModule->description();
}
return QString();
}
void SettingsComponent::setDescription(const QString &description)
{
if (d->settingsModule && d->settingsModule->description() != description) {
d->settingsModule->setDescription(description);
emit descriptionChanged();
}
}
QString SettingsComponent::icon() const
{
return d->icon;
}
void SettingsComponent::setIcon(const QString& name)
{
if (name != d->icon) {
d->icon = name;
emit iconChanged();
}
}
QString SettingsComponent::module() const
{
return d->module;
}
void SettingsComponent::setModule(const QString &module)
{
if (d->module != module) {
d->module = module;
loadModule(module);
emit moduleChanged();