diff --git a/core/kdeconnectpluginconfig.cpp b/core/kdeconnectpluginconfig.cpp index 76ee023f6..18def7853 100644 --- a/core/kdeconnectpluginconfig.cpp +++ b/core/kdeconnectpluginconfig.cpp @@ -21,13 +21,15 @@ struct KdeConnectPluginConfigPrivate { QDBusMessage m_signal; }; -KdeConnectPluginConfig::KdeConnectPluginConfig() - : d(new KdeConnectPluginConfigPrivate()) +KdeConnectPluginConfig::KdeConnectPluginConfig(QObject *parent) + : QObject(parent) + , d(new KdeConnectPluginConfigPrivate()) { } -KdeConnectPluginConfig::KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName) - : d(new KdeConnectPluginConfigPrivate()) +KdeConnectPluginConfig::KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName, QObject *parent) + : QObject(parent) + , d(new KdeConnectPluginConfigPrivate()) { d->m_configDir = KdeConnectConfig::instance().pluginConfigDir(deviceId, pluginName); QDir().mkpath(d->m_configDir.path()); diff --git a/core/kdeconnectpluginconfig.h b/core/kdeconnectpluginconfig.h index 7bd59443e..e4bed1b2a 100644 --- a/core/kdeconnectpluginconfig.h +++ b/core/kdeconnectpluginconfig.h @@ -25,8 +25,8 @@ class KDECONNECTCORE_EXPORT KdeConnectPluginConfig : public QObject Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY configChanged) public: - KdeConnectPluginConfig(); - KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName); + explicit KdeConnectPluginConfig(QObject *parent = nullptr); + explicit KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName, QObject *parent = nullptr); ~KdeConnectPluginConfig() override; /** diff --git a/kcmplugin/kdeconnectpluginkcm.cpp b/kcmplugin/kdeconnectpluginkcm.cpp index c995debd0..0f6668a5c 100644 --- a/kcmplugin/kdeconnectpluginkcm.cpp +++ b/kcmplugin/kdeconnectpluginkcm.cpp @@ -6,42 +6,17 @@ #include "kdeconnectpluginkcm.h" -struct KdeConnectPluginKcmPrivate { - QString m_deviceId; - QString m_pluginName; - KdeConnectPluginConfig *m_config = nullptr; -}; - KdeConnectPluginKcm::KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args) #if QT_VERSION_MAJOR < 6 : KCModule(qobject_cast(parent), args) #else : KCModule(parent) #endif - , d(new KdeConnectPluginKcmPrivate()) + , m_deviceId(args.at(0).toString()) + // The plugin name is the KCMs ID with the postfix removed + , m_config(new KdeConnectPluginConfig(m_deviceId, args.at(1).toString().remove(QLatin1String("_config")), this)) { Q_ASSERT(data.isValid()); // Even if we have empty metadata, it should be valid! - d->m_deviceId = args.at(0).toString(); - const static QRegularExpression removeConfigPostfix(QStringLiteral("_config$")); - d->m_pluginName = data.pluginId().remove(removeConfigPostfix); - - // The parent of the config should be the plugin itself - d->m_config = new KdeConnectPluginConfig(d->m_deviceId, d->m_pluginName); -} - -KdeConnectPluginKcm::~KdeConnectPluginKcm() -{ - delete d->m_config; -} - -KdeConnectPluginConfig *KdeConnectPluginKcm::config() const -{ - return d->m_config; -} - -QString KdeConnectPluginKcm::deviceId() const -{ - return d->m_deviceId; } #include "moc_kdeconnectpluginkcm.cpp" diff --git a/kcmplugin/kdeconnectpluginkcm.h b/kcmplugin/kdeconnectpluginkcm.h index ea1e2f4bb..2559a61a1 100644 --- a/kcmplugin/kdeconnectpluginkcm.h +++ b/kcmplugin/kdeconnectpluginkcm.h @@ -4,8 +4,7 @@ * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -#ifndef KDECONNECTPLUGINKCM_H -#define KDECONNECTPLUGINKCM_H +#pragma once #include #include // Not in KCModule header of older KF5 versions @@ -14,8 +13,6 @@ #include "core/kdeconnectpluginconfig.h" #include "kdeconnectpluginkcm_export.h" -struct KdeConnectPluginKcmPrivate; - /** * Inheriting your plugin's KCM from this class gets you a easy way to share * configuration values between the KCM and the plugin. @@ -25,18 +22,23 @@ class KDECONNECTPLUGINKCM_EXPORT KdeConnectPluginKcm : public KCModule Q_OBJECT public: - KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args); - ~KdeConnectPluginKcm() override; + explicit KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args); /** * The device this kcm is instantiated for */ - QString deviceId() const; + QString deviceId() const + { + return m_deviceId; + } /** * The object where to save the config, so the plugin can access it */ - KdeConnectPluginConfig *config() const; + KdeConnectPluginConfig *config() const + { + return m_config; + } #if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 105, 0) QWidget *widget() @@ -46,7 +48,7 @@ public: #endif private: - QScopedPointer d; + const QString m_deviceId; + const QString m_pluginName; + KdeConnectPluginConfig *const m_config; }; - -#endif