diff --git a/import/configgroup.cpp b/import/configgroup.cpp index 96444ac..f9d9898 100644 --- a/import/configgroup.cpp +++ b/import/configgroup.cpp @@ -1,197 +1,196 @@ /* * Copyright 2011-2012 by Sebastian Kügler * Copyright 2013 by Aaron Seigo * * 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 #include #include #include #include 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(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 -#include "configgroup.moc" diff --git a/import/package.cpp b/import/package.cpp index 5a0e98b..8197feb 100644 --- a/import/package.cpp +++ b/import/package.cpp @@ -1,92 +1,89 @@ /*************************************************************************** * Copyright 2011 Marco Martin * * * * 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 #include #include #include 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()); } - -#include "package.moc" - diff --git a/import/settingscomponent.cpp b/import/settingscomponent.cpp index 1d14584..5a2fc24 100644 --- a/import/settingscomponent.cpp +++ b/import/settingscomponent.cpp @@ -1,229 +1,225 @@ /* Copyright 2011 Marco Martin 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 #include #include #include #include #include #include #include #include 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(); 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(); } } QString SettingsComponent::name() const { if (d->settingsModule) { return d->settingsModule->name(); } return QString(); } void SettingsComponent::setName(const QString &name) { if (d->settingsModule && d->settingsModule->name() != name) { d->settingsModule->setName(name); emit nameChanged(); } } - - -#include "settingscomponent.moc" - diff --git a/import/settingsmodule.cpp b/import/settingsmodule.cpp index 6bcdb95..e526fcd 100644 --- a/import/settingsmodule.cpp +++ b/import/settingsmodule.cpp @@ -1,109 +1,107 @@ /* * Copyright 2011 Sebastian Kügler * * 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. */ #include "settingsmodule.h" class SettingsModulePrivate { public: QString name; QString description; QString module; QString iconName; QString category; }; SettingsModule::SettingsModule(QObject *parent, const QVariantList &v) : QObject(parent), d(new SettingsModulePrivate) { Q_UNUSED(v); } SettingsModule::~SettingsModule() { delete d; } QString SettingsModule::name() const { return d->name; } QString SettingsModule::description() const { return d->description; } QString SettingsModule::module() const { return d->module; } QString SettingsModule::iconName() const { return d->iconName; } QString SettingsModule::category() const { return d->category; } void SettingsModule::setName(const QString &name) { if (d->name != name) { d->name = name; emit nameChanged(); } } void SettingsModule::setDescription(const QString &description) { if (d->description != description) { d->description = description; emit descriptionChanged(); } } void SettingsModule::setIconName(const QString &iconName) { if (d->iconName != iconName) { d->iconName = iconName; emit iconNameChanged(); } } void SettingsModule::setModule(const QString &module) { if (d->module != module) { d->module = module; emit moduleChanged(); } } void SettingsModule::setCategory(const QString &category) { if (d->category != category) { d->category = category; emit categoryChanged(); } } - -#include "settingsmodule.moc" diff --git a/import/settingsmodulesmodel.cpp b/import/settingsmodulesmodel.cpp index e97b668..13f6e79 100644 --- a/import/settingsmodulesmodel.cpp +++ b/import/settingsmodulesmodel.cpp @@ -1,185 +1,183 @@ /*************************************************************************** * * * Copyright 2011 Sebastian Kügler * * * * 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) 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 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 "settingsmodulesmodel.h" #include #include #include #include #include #include #include #include #include class SettingsModulesModelPrivate { public: SettingsModulesModelPrivate(SettingsModulesModel *parent) : populateTimer(new QTimer(parent)) {} QList settingsModules; QTimer *populateTimer; QString appName; QString formFactor; }; SettingsModulesModel::SettingsModulesModel(QQmlComponent *parent) : QQmlComponent(parent), d(new SettingsModulesModelPrivate(this)) { qDebug() << "Creating SettingsModel"; d->populateTimer->setInterval(0); d->populateTimer->setSingleShot(true); connect(d->populateTimer, &QTimer::timeout, this, &SettingsModulesModel::populate); d->populateTimer->start(); connect(this, &SettingsModulesModel::formFactorChanged, this, &SettingsModulesModel::populate); } SettingsModulesModel::~SettingsModulesModel() { delete d; } QQmlListProperty SettingsModulesModel::settingsModules() { return QQmlListProperty(this, d->settingsModules); } QString SettingsModulesModel::application() const { return d->appName; } void SettingsModulesModel::setApplication(const QString &appName) { qDebug() << "setting application to" << appName; if (d->appName != appName) { d->appName = appName; for (auto m: d->settingsModules) { m->deleteLater(); } d->settingsModules.clear(); emit applicationChanged(); emit settingsModulesChanged(); d->populateTimer->start(); } } bool compareModules(const SettingsModule *l, const SettingsModule *r) { if (l == r) { return false; } if (!l) { return false; } else if (!r) { return true; } // base it on the category weighting; if neither has a category weight the compare // strings KConfigGroup orderConfig(KSharedConfig::openConfig(), "SettingsCategoryWeights"); const int lG = orderConfig.readEntry(l->category(), -1); const int rG = orderConfig.readEntry(r->category(), -1); //qDebug() << l->name() << l->category() << lG << " vs " << r->name() << r->category() << rG; if (lG < 0) { if (rG > 0) { return false; } int rv = l->category().compare(r->category(), Qt::CaseInsensitive); if (rv == 0) { rv = l->name().compare(r->name(), Qt::CaseInsensitive); } return rv < 0; } else if (rG < 0) { return true; } if (lG == rG) { return l->name().compare(r->name(), Qt::CaseInsensitive) < 0; } return lG > rG; } void SettingsModulesModel::populate() { for (auto m: d->settingsModules) { m->deleteLater(); } d->settingsModules.clear(); QSet seen; // track dupes auto plugins = KPluginLoader::findPlugins("kcms"); for (auto plugin : KPackage::PackageLoader::self()->listPackages(QString(), "kpackage/kcms/")) { plugins << plugin; } for (auto plugin : plugins) { if (seen.contains(plugin.pluginId())) { continue; } // Filter out modules that are not explicitely suitable for the "handset" formfactor if (!formFactor().isEmpty() && !plugin.formFactors().contains(formFactor()) && formFactor() != QStringLiteral("all")) { continue; } SettingsModule* item = new SettingsModule(this); item->setName(plugin.name()); item->setDescription(plugin.description()); item->setIconName(plugin.iconName()); item->setModule(plugin.pluginId()); item->setCategory(plugin.category()); d->settingsModules.append(item); seen.insert(plugin.pluginId()); } qStableSort(d->settingsModules.begin(), d->settingsModules.end(), compareModules); //emit dataChanged(); emit settingsModulesChanged(); } QString SettingsModulesModel::formFactor() const { return d->formFactor; } void SettingsModulesModel::setFormFactor(const QString& f) { if (d->formFactor != f) { d->formFactor = f; emit formFactorChanged(); } } - -#include "settingsmodulesmodel.moc" diff --git a/modules/time/timezone.cpp b/modules/time/timezone.cpp index 57d8081..a934022 100644 --- a/modules/time/timezone.cpp +++ b/modules/time/timezone.cpp @@ -1,64 +1,62 @@ /* Copyright 2005 S.R.Haque . Copyright 2009 David Faure Copyright 2011 Sebastian Kügler This file is part of the KDE project This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2, as published by the Free Software Foundation. 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 "timezone.h" #include #include #include #include class TimeZonePrivate { public: TimeZone *q; KTimeZone zone; QString name; }; TimeZone::TimeZone(const KTimeZone &zone, QObject* parent) : QObject(parent) { d = new TimeZonePrivate; d->q = this; d->zone = zone; setName(zone.name()); //qDebug() << "new tz: " << d->name; } TimeZone::~TimeZone() { delete d; } QString TimeZone::name() { return d->name; } void TimeZone::setName(const QString &n) { d->name = n; emit nameChanged(); } - -#include "timezone.moc" diff --git a/modules/time/timezonesmodel.cpp b/modules/time/timezonesmodel.cpp index 6cfb16c..4bc52d7 100644 --- a/modules/time/timezonesmodel.cpp +++ b/modules/time/timezonesmodel.cpp @@ -1,46 +1,43 @@ /* * Copyright 2011 Marco Martin * * 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. */ #include "timezonesmodel.h" TimeZonesModel::TimeZonesModel(QObject *parent) : QStandardItemModel(parent) { QHash roleNames; roleNames[Qt::DisplayRole] = "display"; roleNames[Qt::UserRole+1] = "continent"; setRoleNames(roleNames); connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged())); connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(countChanged())); connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(countChanged())); } QVariantHash TimeZonesModel::get(int i) const { QModelIndex idx = index(i, 0); QVariantHash hash; hash["display"] = data(idx, Qt::DisplayRole); hash["continent"] = data(idx, Qt::UserRole+1); return hash; } - -#include "timezonesmodel.moc" -