diff --git a/import/configgroup.cpp b/import/configgroup.cpp index dfbfa57..96444ac 100644 --- a/import/configgroup.cpp +++ b/import/configgroup.cpp @@ -1,197 +1,197 @@ /* * 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(0), - configGroup(0) + 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 = 0; + ConfigGroup* parentGroup = nullptr; QObject* current = parent(); while (current) { parentGroup = qobject_cast(current); if (parentGroup) { break; } current = current->parent(); } delete d->configGroup; - d->configGroup = 0; + 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/configgroup.h b/import/configgroup.h index 3354e84..62b6069 100644 --- a/import/configgroup.h +++ b/import/configgroup.h @@ -1,76 +1,76 @@ /* * Copyright 2011-2012 by 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 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 #include #include 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=0); - ~ConfigGroup(); + 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 diff --git a/import/package.h b/import/package.h index 1598a39..f694e02 100644 --- a/import/package.h +++ b/import/package.h @@ -1,55 +1,55 @@ /*************************************************************************** * 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 . * ***************************************************************************/ #ifndef PACKAGE_H #define PACKAGE_H #include #include #include 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 = 0); - ~Package(); + 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 diff --git a/import/settingscomponent.cpp b/import/settingscomponent.cpp index b899014..1d14584 100644 --- a/import/settingscomponent.cpp +++ b/import/settingscomponent.cpp @@ -1,229 +1,229 @@ /* 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 = 0; - d->kcm = 0; + d->settingsModule = nullptr; + d->kcm = nullptr; d->valid = false; } SettingsComponent::~SettingsComponent() { } void SettingsComponent::loadModule(const QString &name) { d->settingsModule->deleteLater(); - d->settingsModule = 0; + d->settingsModule = nullptr; d->kcm->deleteLater(); - d->kcm = 0; + 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/settingscomponent.h b/import/settingscomponent.h index 7b0ff08..4835f63 100644 --- a/import/settingscomponent.h +++ b/import/settingscomponent.h @@ -1,76 +1,76 @@ /* Copyright 2011 Sebastian Kügler 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. */ #ifndef SETTINGSCOMPONENT_H #define SETTINGSCOMPONENT_H #include class SettingsComponentPrivate; namespace KQuickAddons { class ConfigModule; } class SettingsComponent : public QQuickItem { Q_OBJECT Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged) Q_PROPERTY(QString module READ module WRITE setModule NOTIFY moduleChanged) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) Q_PROPERTY(QQuickItem *mainUi READ mainUi NOTIFY mainUiChanged) Q_PROPERTY(KQuickAddons::ConfigModule *kcm READ kcm NOTIFY kcmChanged) public: - SettingsComponent(QQuickItem *parent = 0); - ~SettingsComponent(); + SettingsComponent(QQuickItem *parent = nullptr); + ~SettingsComponent() override; QString description() const; QString module() const; QString name() const; QString icon() const; bool isValid() const; QQuickItem *mainUi() const; KQuickAddons::ConfigModule *kcm() const; Q_SIGNALS: void descriptionChanged(); void moduleChanged(); void nameChanged(); void iconChanged(); void validChanged(); void mainUiChanged(); void kcmChanged(); public Q_SLOTS: void setModule(const QString &module); void setDescription(const QString &description); void setName(const QString &name); void setIcon(const QString &name); void loadModule(const QString &name); private: SettingsComponentPrivate* d; }; #endif diff --git a/import/settingsmodule.h b/import/settingsmodule.h index b5d8b8a..0ace615 100644 --- a/import/settingsmodule.h +++ b/import/settingsmodule.h @@ -1,73 +1,73 @@ /* * 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. */ #ifndef SETTINGSMODULE_H #define SETTINGSMODULE_H #include #include class SettingsModulePrivate; /** * @class SettingsModule A class to manage settings from declarative UIs. * This class serves two functions: * - Provide a plugin implementation * - Provide a settings module * This is done from one class in order to simplify the code. You can export * any QObject-based class through qmlRegisterType(), however. */ class SettingsModule : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged) Q_PROPERTY(QString module READ module WRITE setModule NOTIFY moduleChanged) Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged) Q_PROPERTY(QString category READ category WRITE setCategory NOTIFY categoryChanged) public: - explicit SettingsModule(QObject *parent = 0, const QVariantList &v = QVariantList()); - virtual ~SettingsModule(); + explicit SettingsModule(QObject *parent = nullptr, const QVariantList &v = QVariantList()); + ~SettingsModule() override; QString name() const; QString description() const; QString iconName() const; QString module() const; QString category() const; public Q_SLOTS: void setName(const QString &name); void setDescription(const QString &description); void setModule(const QString &module); void setIconName(const QString &iconName); void setCategory(const QString &category); Q_SIGNALS: void nameChanged(); void descriptionChanged(); void moduleChanged(); void iconNameChanged(); void categoryChanged(); private: SettingsModulePrivate *d; }; #endif diff --git a/import/settingsmodulesmodel.h b/import/settingsmodulesmodel.h index b58ceab..5276bbd 100644 --- a/import/settingsmodulesmodel.h +++ b/import/settingsmodulesmodel.h @@ -1,65 +1,65 @@ /*************************************************************************** * * * 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 . * ***************************************************************************/ #ifndef COMPLETIONMODEL_H #define COMPLETIONMODEL_H #include #include #include #include "settingsmodule.h" class History; class SettingsModulesModelPrivate; class SettingsModulesModel : public QQmlComponent { Q_OBJECT Q_PROPERTY(QQmlListProperty settingsModules READ settingsModules NOTIFY settingsModulesChanged) Q_PROPERTY(QString application READ application WRITE setApplication NOTIFY applicationChanged) Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged) public: - SettingsModulesModel(QQmlComponent* parent = 0); - ~SettingsModulesModel(); + SettingsModulesModel(QQmlComponent* parent = nullptr); + ~SettingsModulesModel() override; QQmlListProperty settingsModules(); QString application() const; void setApplication(const QString &appname); QString formFactor() const; void setFormFactor(const QString &f); public Q_SLOTS: void populate(); Q_SIGNALS: void dataChanged(); void settingsModulesChanged(); void applicationChanged(); void formFactorChanged(); private: SettingsModulesModelPrivate * const d; }; #endif // COMPLETIONMODEL_H diff --git a/import/settingsplugin.h b/import/settingsplugin.h index 1ad741f..cf90549 100644 --- a/import/settingsplugin.h +++ b/import/settingsplugin.h @@ -1,38 +1,38 @@ /* * Copyright 2011-2014 by 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. */ #ifndef SETTINGSPLUGIN_H #define SETTINGSPLUGIN_H #include #include class SettingsPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") public: //void initializeEngine(QQmlEngine *engine, const char *uri); - void registerTypes(const char *uri); + void registerTypes(const char *uri) override; }; #endif diff --git a/modules/development/develsettings.h b/modules/development/develsettings.h index a2b7aad..a6631b1 100644 --- a/modules/development/develsettings.h +++ b/modules/development/develsettings.h @@ -1,52 +1,52 @@ /* * Copyright 2012 Aaron Seigo * Copyright 2015 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. */ #ifndef DEVELSETTINGS_H #define DEVELSETTINGS_H #include #include #include #include class DevelSettings : public KQuickAddons::ConfigModule { Q_OBJECT Q_PROPERTY(bool sshEnabled READ sshEnabled WRITE enableSsh NOTIFY enableSshChanged) public: DevelSettings(QObject* parent, const QVariantList& args); - virtual ~DevelSettings(); + ~DevelSettings() override; bool sshEnabled() const; void enableSsh(bool enable); Q_SIGNALS: void enableSshChanged(bool enabled); void showTerminalChanged(bool shown); private: bool m_sshEnabled; bool m_terminalShown; bool m_cursorVisible; QString m_terminalApp; QProcess m_getpropProcess; }; #endif diff --git a/modules/development/sshdhelper.h b/modules/development/sshdhelper.h index fdf8cc5..c963861 100644 --- a/modules/development/sshdhelper.h +++ b/modules/development/sshdhelper.h @@ -1,38 +1,38 @@ /* * Copyright 2012 Aaron Seigo * * 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. */ #ifndef SSHD_HELPER_H #define SSHD_HELPER_H #include using namespace KAuth; class SshdHelper : public QObject { Q_OBJECT public: - SshdHelper(QObject *parent = 0); + SshdHelper(QObject *parent = nullptr); public slots: ActionReply start(const QVariantMap &map); ActionReply stop(const QVariantMap &map); }; #endif // SSHD_HELPER_H diff --git a/modules/theme/themelistmodel.h b/modules/theme/themelistmodel.h index b183406..3607127 100644 --- a/modules/theme/themelistmodel.h +++ b/modules/theme/themelistmodel.h @@ -1,81 +1,81 @@ /* * ThemeListModel * Copyright (C) 2002 Karol Szwed * Copyright (C) 2002 Daniel Molkentin * Copyright (C) 2007 Urs Wolfer * Copyright (C) 2009 by Davide Bettio * Copyright (C) 2015 Marco Martin * Portions Copyright (C) 2007 Paolo Capriotti * Portions Copyright (C) 2007 Ivan Cukic * Portions Copyright (C) 2008 by Petri Damsten * Portions Copyright (C) 2000 TrollTech AS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License version 2 as published by the Free Software Foundation. * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef THEMELISTMODEL_H #define THEMELISTMODEL_H #include namespace Plasma { class FrameSvg; } //Theme selector code by Andre Duffeck (modified to add package description) class ThemeInfo { public: QString package; QString description; QString author; QString version; QString themeRoot; }; class ThemeListModel : public QAbstractListModel { Q_OBJECT public: enum { PackageNameRole = Qt::UserRole, PackageDescriptionRole = Qt::UserRole + 1, PackageAuthorRole = Qt::UserRole + 2, PackageVersionRole = Qt::UserRole + 3 }; - ThemeListModel(QObject *parent = 0); - virtual ~ThemeListModel(); + ThemeListModel(QObject *parent = nullptr); + ~ThemeListModel() override; - virtual QHash roleNames() const; + QHash roleNames() const override; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex indexOf(const QString &path) const; void reload(); void clearThemeList(); Q_INVOKABLE QVariantMap get(int index) const; private: QHash m_roleNames; QMap m_themes; }; #endif diff --git a/modules/theme/themesettings.h b/modules/theme/themesettings.h index 2ebcc68..1c28c98 100644 --- a/modules/theme/themesettings.h +++ b/modules/theme/themesettings.h @@ -1,67 +1,67 @@ /*************************************************************************** * * * Copyright 2015 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 . * ***************************************************************************/ #ifndef THEMESETTINGS_H #define THEMESETTINGS_H #include #include #include #include namespace Plasma { class Theme; } class ThemeListModel; class ThemeSettings : public KQuickAddons::ConfigModule { Q_OBJECT Q_PROPERTY(QString themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged) Q_PROPERTY(ThemeListModel *themeListModel READ themeListModel CONSTANT) Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) public: ThemeSettings(QObject* parent, const QVariantList& args); - virtual ~ThemeSettings(); + ~ThemeSettings() override; QString themeName() const; void setThemeName(const QString &theme); int fontSize() const; void setFontSize(int pointSize); ThemeListModel *themeListModel(); Q_SIGNALS: void themeNameChanged(); void fontSizeChanged(); private: Plasma::Theme *m_theme; QString m_themeName; ThemeListModel *m_themeListModel; QFont m_font; }; #endif // THEMESETTINGS_H diff --git a/modules/time/timesettings.cpp b/modules/time/timesettings.cpp index e49fd0f..0b05897 100644 --- a/modules/time/timesettings.cpp +++ b/modules/time/timesettings.cpp @@ -1,393 +1,393 @@ /************************************************************************** * * * Copyright 2005 S.R.Haque . * * Copyright 2009 David Faure * * Copyright 2011-2015 Sebastian Kügler * * Copyright 2015 David Edmundson * * * * 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 "timesettings.h" #include "timezone.h" #include "timezonesmodel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "timedated_interface.h" #define FORMAT24H "HH:mm:ss" #define FORMAT12H "h:mm:ss ap" K_PLUGIN_FACTORY_WITH_JSON(TimeSettingsFactory, "timesettings.json", registerPlugin();) class TimeSettingsPrivate { public: TimeSettings *q; QString timeFormat; QString timezone; QObject *timeZonesModel; QString timeZoneFilter; QString currentTimeText; QTime currentTime; QDate currentDate; QTimer *timer; bool useNtp; QString errorString; void initSettings(); void initTimeZones(); QString displayName(const KTimeZone &zone); KSharedConfigPtr localeConfig; KConfigGroup localeSettings; KTimeZones *timeZones; QList timezones; }; TimeSettings::TimeSettings(QObject* parent, const QVariantList& args) : KQuickAddons::ConfigModule(parent, args) { qDebug() << "time settings init"; d = new TimeSettingsPrivate; d->q = this; - d->timeZones = 0; - d->timeZonesModel = 0; + d->timeZones = nullptr; + d->timeZonesModel = nullptr; setTimeZone(KSystemTimeZones::local().name()); KAboutData* about = new KAboutData("kcm_mobile_time", i18n("Configure Date and Time"), "0.1", QString(), KAboutLicense::LGPL); about->addAuthor(i18n("Sebastian Kügler"), QString(), "sebas@kde.org"); setAboutData(about); setButtons(Apply | Default); d->initSettings(); // Just for testing that data gets through d->timer = new QTimer(this); d->timer->setInterval(1000); connect(d->timer, &QTimer::timeout, this, &TimeSettings::timeout); d->timer->start(); qDebug() << "TimeSettings module loaded."; } TimeSettings::~TimeSettings() { delete d; } void TimeSettingsPrivate::initTimeZones() { // Collect zones by localized city names, so that they can be sorted properly. QStringList cities; QStringList tz; QHash zonesByCity; if (!timeZones) { timeZones = KSystemTimeZones::timeZones(); // add UTC to the defaults default KTimeZone utc = KTimeZone::utc(); cities.append(utc.name()); zonesByCity.insert(utc.name(), utc); } //qDebug() << " TZ: cities: " << cities; const KTimeZones::ZoneMap zones = timeZones->zones(); QList _zones; QStandardItemModel *_zonesModel = new TimeZonesModel(q); for ( KTimeZones::ZoneMap::ConstIterator it = zones.begin(); it != zones.end(); ++it ) { const KTimeZone zone = it.value(); if (timeZoneFilter.isEmpty() || zone.name().contains(timeZoneFilter, Qt::CaseInsensitive)) { TimeZone *_zone = new TimeZone(zone); _zones.append(_zone); QStandardItem *item = new QStandardItem(_zone->name()); item->setData(_zone->name().split('/').first(), Qt::UserRole+1); _zonesModel->appendRow(item); } } qDebug() << "Found: " << _zones.count() << " timezones."; //qSort( cities.begin(), cities.end(), localeLessThan ); q->setTimeZones(_zones); q->setTimeZonesModel(_zonesModel); } QString TimeSettingsPrivate::displayName( const KTimeZone &zone ) { return zone.name().toUtf8().replace( '_', ' ' ); } void TimeSettingsPrivate::initSettings() { localeConfig = KSharedConfig::openConfig("kdeglobals", KConfig::SimpleConfig); localeSettings = KConfigGroup(localeConfig, "Locale"); q->setTimeFormat( localeSettings.readEntry( "TimeFormat", QString(FORMAT24H) ) ); // FIXME?! OrgFreedesktopTimedate1Interface timeDatedIface("org.freedesktop.timedate1", "/org/freedesktop/timedate1", QDBusConnection::systemBus()); //the server list is not relevant for timesyncd, it fetches it from the network useNtp = timeDatedIface.nTP(); } void TimeSettings::timeout() { setCurrentTime(QTime::currentTime()); setCurrentDate(QDate::currentDate()); notify(); } QString TimeSettings::currentTimeText() { return d->currentTimeText; } QTime TimeSettings::currentTime() const { return d->currentTime; } void TimeSettings::setCurrentTime(const QTime ¤tTime) { if (d->currentTime != currentTime) { d->currentTime = currentTime; d->currentTimeText = QLocale().toString(QTime::currentTime(), d->timeFormat); emit currentTimeChanged(); } } QDate TimeSettings::currentDate() const { return d->currentDate; } void TimeSettings::setCurrentDate(const QDate ¤tDate) { if (d->currentDate != currentDate) { d->currentDate = currentDate; emit currentDateChanged(); } } bool TimeSettings::useNtp() const { return d->useNtp; } void TimeSettings::setUseNtp(bool ntp) { if (d->useNtp != ntp) { d->useNtp = ntp; saveTime(); emit useNtpChanged(); } } bool TimeSettings::saveTime() { OrgFreedesktopTimedate1Interface timedateIface("org.freedesktop.timedate1", "/org/freedesktop/timedate1", QDBusConnection::systemBus()); bool rc = true; //final arg in each method is "user-interaction" i.e whether it's OK for polkit to ask for auth //we cannot send requests up front then block for all replies as we need NTP to be disabled before we can make a call to SetTime //timedated processes these in parallel and will return an error otherwise auto reply = timedateIface.SetNTP(useNtp(), true); reply.waitForFinished(); if (reply.isError()) { d->errorString = i18n("Unable to change NTP settings"); emit errorStringChanged(); qWarning() << "Failed to enable NTP" << reply.error().name() << reply.error().message(); rc = false; } if (!useNtp()) { QDateTime userTime; userTime.setTime(currentTime()); userTime.setDate(currentDate()); qDebug() << "Setting userTime: " << userTime; qint64 timeDiff = userTime.toMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch(); //*1000 for milliseconds -> microseconds auto reply = timedateIface.SetTime(timeDiff * 1000, true, true); reply.waitForFinished(); if (reply.isError()) { d->errorString = i18n("Unable to set current time"); emit errorStringChanged(); qWarning() << "Failed to set current time" << reply.error().name() << reply.error().message(); rc = false; } } saveTimeZone(timeZone()); return rc; } void TimeSettings::saveTimeZone(const QString &newtimezone) { qDebug() << "Saving timezone to config: " << newtimezone; OrgFreedesktopTimedate1Interface timedateIface("org.freedesktop.timedate1", "/org/freedesktop/timedate1", QDBusConnection::systemBus()); if (!newtimezone.isEmpty()) { qDebug() << "Setting timezone: " << newtimezone; auto reply = timedateIface.SetTimezone(newtimezone, true); reply.waitForFinished(); if (reply.isError()) { d->errorString = i18n("Unable to set timezone"); emit errorStringChanged(); qWarning() << "Failed to set timezone" << reply.error().name() << reply.error().message(); } } setTimeZone(newtimezone); emit timeZoneChanged(); notify(); } QString TimeSettings::timeFormat() { return d->timeFormat; } void TimeSettings::setTimeFormat(const QString &timeFormat) { if (d->timeFormat != timeFormat) { d->timeFormat = timeFormat; d->localeSettings.writeEntry("TimeFormat", timeFormat); d->localeConfig->sync(); QDBusMessage msg = QDBusMessage::createSignal("/org/kde/kcmshell_clock", "org.kde.kcmshell_clock", "clockUpdated"); QDBusConnection::sessionBus().send(msg); qDebug() << "time format is now: " << QLocale().toString(QTime::currentTime(), d->timeFormat); emit timeFormatChanged(); timeout(); } } QString TimeSettings::timeZone() { return d->timezone; } void TimeSettings::setTimeZone(const QString &timezone) { if (d->timezone != timezone) { d->timezone = timezone; qDebug() << "timezone changed to: " << timezone; emit timeZoneChanged(); timeout(); } } QList TimeSettings::timeZones() { if (!d->timeZones) { d->initTimeZones(); } return d->timezones; } void TimeSettings::setTimeZones(QList timezones) { d->timezones = timezones; emit timeZonesChanged(); } QObject* TimeSettings::timeZonesModel() { if (!d->timeZones) { d->initTimeZones(); } return d->timeZonesModel; } void TimeSettings::setTimeZonesModel(QObject* timezones) { d->timeZonesModel = timezones; emit timeZonesModelChanged(); } void TimeSettings::timeZoneFilterChanged(const QString &filter) { d->timeZoneFilter = filter; d->timeZoneFilter.replace(' ', '_'); d->initTimeZones(); emit timeZonesChanged(); } bool TimeSettings::twentyFour() { return timeFormat() == FORMAT24H; } void TimeSettings::setTwentyFour(bool t) { if (twentyFour() != t) { if (t) { setTimeFormat(FORMAT24H); } else { setTimeFormat(FORMAT12H); } qDebug() << "T24 toggled: " << t << d->timeFormat; emit twentyFourChanged(); emit currentTimeChanged(); timeout(); } } QString TimeSettings::errorString() { return d->errorString; } void TimeSettings::notify() { QDBusMessage msg = QDBusMessage::createSignal("/org/kde/kcmshell_clock", "org.kde.kcmshell_clock", "clockUpdated"); QDBusConnection::sessionBus().send(msg); } #include "timesettings.moc" diff --git a/modules/time/timesettings.h b/modules/time/timesettings.h index da5000f..571de72 100644 --- a/modules/time/timesettings.h +++ b/modules/time/timesettings.h @@ -1,119 +1,119 @@ /*************************************************************************** * * * Copyright 2011-2015 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 . * ***************************************************************************/ #ifndef TIMESETTINGS_H #define TIMESETTINGS_H #include #include #include #include #include #include #include //#include "settingsmodule.h" class TimeSettingsPrivate; /** * @class TimeSettings A class to manage time and date related settings. This class serves two functions: * - Provide a plugin implementation * - Provide a settings module * This is done from one class in order to simplify the code. You can export any QObject-based * class through qmlRegisterType(), however. */ class TimeSettings : public KQuickAddons::ConfigModule { Q_OBJECT Q_PROPERTY(QString timeFormat READ timeFormat WRITE setTimeFormat NOTIFY timeFormatChanged) Q_PROPERTY(bool twentyFour READ twentyFour WRITE setTwentyFour NOTIFY twentyFourChanged) Q_PROPERTY(QString timeZone READ timeZone WRITE setTimeZone NOTIFY timeZoneChanged) Q_PROPERTY(QList timeZones READ timeZones WRITE setTimeZones NOTIFY timeZonesChanged) Q_PROPERTY(QObject* timeZonesModel READ timeZonesModel WRITE setTimeZonesModel NOTIFY timeZonesModelChanged) Q_PROPERTY(QTime currentTime READ currentTime WRITE setCurrentTime NOTIFY currentTimeChanged) Q_PROPERTY(QDate currentDate READ currentDate WRITE setCurrentDate NOTIFY currentDateChanged) Q_PROPERTY(bool useNtp READ useNtp WRITE setUseNtp NOTIFY useNtpChanged) Q_PROPERTY(QString currentTimeText READ currentTimeText NOTIFY currentTimeTextChanged) Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) public: /** * @name Settings Module Constructor * * @arg parent The parent object * @arg list Arguments, currently unused */ TimeSettings(QObject* parent, const QVariantList& args); - virtual ~TimeSettings(); + ~TimeSettings() override; QString currentTimeText(); QTime currentTime() const; void setCurrentTime(const QTime &time); QDate currentDate() const; void setCurrentDate(const QDate &date); bool useNtp() const; void setUseNtp(bool ntp); QString timeFormat(); QString timeZone(); QList timeZones(); QObject* timeZonesModel(); bool twentyFour(); QString errorString(); public Q_SLOTS: void setTimeZone(const QString &timezone); void setTimeZones(const QList timezones); void setTimeZonesModel(QObject* timezones); void setTimeFormat(const QString &timeFormat); void setTwentyFour(bool t); void timeout(); bool saveTime(); void notify(); Q_INVOKABLE void timeZoneFilterChanged(const QString &filter); Q_INVOKABLE void saveTimeZone(const QString &newtimezone); Q_SIGNALS: void currentTimeTextChanged(); void currentTimeChanged(); void currentDateChanged(); void twentyFourChanged(); void timeFormatChanged(); void timeZoneChanged(); void timeZonesChanged(); void timeZonesModelChanged(); void useNtpChanged(); void errorStringChanged(); protected: QString findNtpUtility(); private: TimeSettingsPrivate* d; }; #endif // TIMESETTINGS_H diff --git a/modules/time/timezone.h b/modules/time/timezone.h index e1af41e..da601e2 100644 --- a/modules/time/timezone.h +++ b/modules/time/timezone.h @@ -1,51 +1,51 @@ /*************************************************************************** * * * 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 . * ***************************************************************************/ #ifndef TIMEZONE_H #define TIMEZONE_H #include #include #include class TimeZonePrivate; class TimeZone : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) public: - explicit TimeZone(const KTimeZone &zone, QObject *parent = 0); - virtual ~TimeZone(); + explicit TimeZone(const KTimeZone &zone, QObject *parent = nullptr); + ~TimeZone() override; QString name(); public Q_SLOTS: void setName(const QString &n); Q_SIGNALS: void nameChanged(); private: TimeZonePrivate* d; }; #endif // TIMEZONE_H diff --git a/modules/time/timezonesmodel.h b/modules/time/timezonesmodel.h index 793a562..f68cb77 100644 --- a/modules/time/timezonesmodel.h +++ b/modules/time/timezonesmodel.h @@ -1,40 +1,40 @@ /* * 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. */ #ifndef TIMEZONESMODEL_H #define TIMEZONESMODEL_H #include class TimeZonesModel: public QStandardItemModel { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) public: - TimeZonesModel(QObject *parent=0); + TimeZonesModel(QObject *parent=nullptr); Q_INVOKABLE QVariantHash get(int i) const; int count() const {return rowCount();} Q_SIGNALS: void countChanged(); }; #endif diff --git a/src/settingsapp.h b/src/settingsapp.h index fc36517..89bd39f 100644 --- a/src/settingsapp.h +++ b/src/settingsapp.h @@ -1,46 +1,46 @@ /*************************************************************************** * * * Copyright 2011-2014 Sebastian Kügler * * Copyright 2017 Marco Martin * * * * 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 . * ***************************************************************************/ #ifndef SETTINGSAPP_H #define SETTINGSAPP_H #include #include class SettingsApp : public QObject { Q_OBJECT public: - explicit SettingsApp(QCommandLineParser &parser, QObject *parent = 0 ); - ~SettingsApp(); + explicit SettingsApp(QCommandLineParser &parser, QObject *parent = nullptr ); + ~SettingsApp() override; Q_SIGNALS: void moduleRequested(const QString &module); void activateRequested(); private: void setupKDBus(); QCommandLineParser *m_parser; }; #endif // SettingsApp_H