kcmplugin: Do not use d-ptr for trivial members that are fully qualified
Also, make this for the most part header only, because it is just a utility class. We could make this entirely header only, but it is not worth it.
This commit is contained in:
parent
473589cd32
commit
b70de1eb21
4 changed files with 24 additions and 45 deletions
|
@ -21,13 +21,15 @@ struct KdeConnectPluginConfigPrivate {
|
||||||
QDBusMessage m_signal;
|
QDBusMessage m_signal;
|
||||||
};
|
};
|
||||||
|
|
||||||
KdeConnectPluginConfig::KdeConnectPluginConfig()
|
KdeConnectPluginConfig::KdeConnectPluginConfig(QObject *parent)
|
||||||
: d(new KdeConnectPluginConfigPrivate())
|
: QObject(parent)
|
||||||
|
, d(new KdeConnectPluginConfigPrivate())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KdeConnectPluginConfig::KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName)
|
KdeConnectPluginConfig::KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName, QObject *parent)
|
||||||
: d(new KdeConnectPluginConfigPrivate())
|
: QObject(parent)
|
||||||
|
, d(new KdeConnectPluginConfigPrivate())
|
||||||
{
|
{
|
||||||
d->m_configDir = KdeConnectConfig::instance().pluginConfigDir(deviceId, pluginName);
|
d->m_configDir = KdeConnectConfig::instance().pluginConfigDir(deviceId, pluginName);
|
||||||
QDir().mkpath(d->m_configDir.path());
|
QDir().mkpath(d->m_configDir.path());
|
||||||
|
|
|
@ -25,8 +25,8 @@ class KDECONNECTCORE_EXPORT KdeConnectPluginConfig : public QObject
|
||||||
Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY configChanged)
|
Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY configChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KdeConnectPluginConfig();
|
explicit KdeConnectPluginConfig(QObject *parent = nullptr);
|
||||||
KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName);
|
explicit KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName, QObject *parent = nullptr);
|
||||||
~KdeConnectPluginConfig() override;
|
~KdeConnectPluginConfig() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,42 +6,17 @@
|
||||||
|
|
||||||
#include "kdeconnectpluginkcm.h"
|
#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)
|
KdeConnectPluginKcm::KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
|
||||||
#if QT_VERSION_MAJOR < 6
|
#if QT_VERSION_MAJOR < 6
|
||||||
: KCModule(qobject_cast<QWidget *>(parent), args)
|
: KCModule(qobject_cast<QWidget *>(parent), args)
|
||||||
#else
|
#else
|
||||||
: KCModule(parent)
|
: KCModule(parent)
|
||||||
#endif
|
#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!
|
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"
|
#include "moc_kdeconnectpluginkcm.cpp"
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef KDECONNECTPLUGINKCM_H
|
#pragma once
|
||||||
#define KDECONNECTPLUGINKCM_H
|
|
||||||
|
|
||||||
#include <KCModule>
|
#include <KCModule>
|
||||||
#include <KPluginMetaData> // Not in KCModule header of older KF5 versions
|
#include <KPluginMetaData> // Not in KCModule header of older KF5 versions
|
||||||
|
@ -14,8 +13,6 @@
|
||||||
#include "core/kdeconnectpluginconfig.h"
|
#include "core/kdeconnectpluginconfig.h"
|
||||||
#include "kdeconnectpluginkcm_export.h"
|
#include "kdeconnectpluginkcm_export.h"
|
||||||
|
|
||||||
struct KdeConnectPluginKcmPrivate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inheriting your plugin's KCM from this class gets you a easy way to share
|
* Inheriting your plugin's KCM from this class gets you a easy way to share
|
||||||
* configuration values between the KCM and the plugin.
|
* configuration values between the KCM and the plugin.
|
||||||
|
@ -25,18 +22,23 @@ class KDECONNECTPLUGINKCM_EXPORT KdeConnectPluginKcm : public KCModule
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
|
explicit KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
|
||||||
~KdeConnectPluginKcm() override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The device this kcm is instantiated for
|
* 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
|
* 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)
|
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 105, 0)
|
||||||
QWidget *widget()
|
QWidget *widget()
|
||||||
|
@ -46,7 +48,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<KdeConnectPluginKcmPrivate> d;
|
const QString m_deviceId;
|
||||||
|
const QString m_pluginName;
|
||||||
|
KdeConnectPluginConfig *const m_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in a new issue