From ede9e37b40d89a908fa0d9bb0bbca27a2fc57d87 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Fri, 21 Jul 2023 13:26:19 +0300 Subject: [PATCH] Use KPluginMetaData::pluginId for getting config plugin name By removing the postfix we consistently use, we get exactly the same string as before However, all our pluginId logic is now done as part of the buildsystem. Before, they were in the JSON metadata, the buildsystem and the string constructor parameter KPluginFactory has the KPluginMetaData object in any case, do using it doesn't create any overhead. --- kcmplugin/kdeconnectpluginkcm.cpp | 9 ++++----- kcmplugin/kdeconnectpluginkcm.h | 3 ++- plugins/clipboard/clipboard_config.cpp | 4 ++-- plugins/clipboard/clipboard_config.h | 2 +- plugins/findthisdevice/findthisdevice_config.cpp | 4 ++-- plugins/findthisdevice/findthisdevice_config.h | 2 +- plugins/pausemusic/pausemusic_config.cpp | 4 ++-- plugins/pausemusic/pausemusic_config.h | 2 +- plugins/runcommand/runcommand_config.cpp | 4 ++-- plugins/runcommand/runcommand_config.h | 2 +- plugins/sendnotifications/sendnotifications_config.cpp | 4 ++-- plugins/sendnotifications/sendnotifications_config.h | 2 +- plugins/share/share_config.cpp | 4 ++-- plugins/share/share_config.h | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/kcmplugin/kdeconnectpluginkcm.cpp b/kcmplugin/kdeconnectpluginkcm.cpp index b4b3cdd12..9c97bf953 100644 --- a/kcmplugin/kdeconnectpluginkcm.cpp +++ b/kcmplugin/kdeconnectpluginkcm.cpp @@ -6,16 +6,13 @@ #include "kdeconnectpluginkcm.h" -#include -#include - struct KdeConnectPluginKcmPrivate { QString m_deviceId; QString m_pluginName; KdeConnectPluginConfig *m_config = nullptr; }; -KdeConnectPluginKcm::KdeConnectPluginKcm(QObject *parent, const QVariantList &args, const QString &pluginName) +KdeConnectPluginKcm::KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args) #if QT_VERSION_MAJOR < 6 : KCModule(qobject_cast(parent), args) #else @@ -23,8 +20,10 @@ KdeConnectPluginKcm::KdeConnectPluginKcm(QObject *parent, const QVariantList &ar #endif , d(new KdeConnectPluginKcmPrivate()) { + Q_ASSERT(data.isValid()); // Even if we have empty metadata, it should be valid! d->m_deviceId = args.at(0).toString(); - d->m_pluginName = pluginName; + 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); diff --git a/kcmplugin/kdeconnectpluginkcm.h b/kcmplugin/kdeconnectpluginkcm.h index 7c34b7d45..ea1e2f4bb 100644 --- a/kcmplugin/kdeconnectpluginkcm.h +++ b/kcmplugin/kdeconnectpluginkcm.h @@ -8,6 +8,7 @@ #define KDECONNECTPLUGINKCM_H #include +#include // Not in KCModule header of older KF5 versions #include #include "core/kdeconnectpluginconfig.h" @@ -24,7 +25,7 @@ class KDECONNECTPLUGINKCM_EXPORT KdeConnectPluginKcm : public KCModule Q_OBJECT public: - KdeConnectPluginKcm(QObject *parent, const QVariantList &args, const QString &componentName); + KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args); ~KdeConnectPluginKcm() override; /** diff --git a/plugins/clipboard/clipboard_config.cpp b/plugins/clipboard/clipboard_config.cpp index 72f50d394..0730fe581 100644 --- a/plugins/clipboard/clipboard_config.cpp +++ b/plugins/clipboard/clipboard_config.cpp @@ -11,8 +11,8 @@ K_PLUGIN_FACTORY(ClipboardConfigFactory, registerPlugin();) -ClipboardConfig::ClipboardConfig(QObject *parent, const QVariantList &args) - : KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_clipboard")) +ClipboardConfig::ClipboardConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KdeConnectPluginKcm(parent, data, args) , m_ui(new Ui::ClipboardConfigUi()) { m_ui->setupUi(widget()); diff --git a/plugins/clipboard/clipboard_config.h b/plugins/clipboard/clipboard_config.h index e30a98b29..7624d3603 100644 --- a/plugins/clipboard/clipboard_config.h +++ b/plugins/clipboard/clipboard_config.h @@ -18,7 +18,7 @@ class ClipboardConfig : public KdeConnectPluginKcm { Q_OBJECT public: - ClipboardConfig(QObject *parent, const QVariantList &); + ClipboardConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &); ~ClipboardConfig() override; void save() override; diff --git a/plugins/findthisdevice/findthisdevice_config.cpp b/plugins/findthisdevice/findthisdevice_config.cpp index 76bef33a3..cd3f9e301 100644 --- a/plugins/findthisdevice/findthisdevice_config.cpp +++ b/plugins/findthisdevice/findthisdevice_config.cpp @@ -21,8 +21,8 @@ K_PLUGIN_FACTORY(FindThisDeviceConfigFactory, registerPlugin();) -FindThisDeviceConfig::FindThisDeviceConfig(QObject *parent, const QVariantList &args) - : KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_findthisdevice")) +FindThisDeviceConfig::FindThisDeviceConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KdeConnectPluginKcm(parent, data, args) , m_ui(new Ui::FindThisDeviceConfigUi()) { m_ui->setupUi(widget()); diff --git a/plugins/findthisdevice/findthisdevice_config.h b/plugins/findthisdevice/findthisdevice_config.h index d1e2ff111..c86759c3d 100644 --- a/plugins/findthisdevice/findthisdevice_config.h +++ b/plugins/findthisdevice/findthisdevice_config.h @@ -18,7 +18,7 @@ class FindThisDeviceConfig : public KdeConnectPluginKcm { Q_OBJECT public: - FindThisDeviceConfig(QObject *parent, const QVariantList &); + FindThisDeviceConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &); ~FindThisDeviceConfig() override; void save() override; diff --git a/plugins/pausemusic/pausemusic_config.cpp b/plugins/pausemusic/pausemusic_config.cpp index 397ac89f6..ec768c71b 100644 --- a/plugins/pausemusic/pausemusic_config.cpp +++ b/plugins/pausemusic/pausemusic_config.cpp @@ -11,8 +11,8 @@ K_PLUGIN_FACTORY(PauseMusicConfigFactory, registerPlugin();) -PauseMusicConfig::PauseMusicConfig(QObject *parent, const QVariantList &args) - : KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_pausemusic")) +PauseMusicConfig::PauseMusicConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KdeConnectPluginKcm(parent, data, args) , m_ui(new Ui::PauseMusicConfigUi()) { m_ui->setupUi(widget()); diff --git a/plugins/pausemusic/pausemusic_config.h b/plugins/pausemusic/pausemusic_config.h index 8906f3f14..8879af4c1 100644 --- a/plugins/pausemusic/pausemusic_config.h +++ b/plugins/pausemusic/pausemusic_config.h @@ -18,7 +18,7 @@ class PauseMusicConfig : public KdeConnectPluginKcm { Q_OBJECT public: - PauseMusicConfig(QObject *parent, const QVariantList &); + PauseMusicConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &); ~PauseMusicConfig() override; void save() override; diff --git a/plugins/runcommand/runcommand_config.cpp b/plugins/runcommand/runcommand_config.cpp index 101fb8a62..fb8338ae7 100644 --- a/plugins/runcommand/runcommand_config.cpp +++ b/plugins/runcommand/runcommand_config.cpp @@ -26,8 +26,8 @@ K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin();) -RunCommandConfig::RunCommandConfig(QObject *parent, const QVariantList &args) - : KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_runcommand")) +RunCommandConfig::RunCommandConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KdeConnectPluginKcm(parent, data, args) { // The qdbus executable name is different on some systems QString qdbusExe = QStringLiteral("qdbus-qt5"); diff --git a/plugins/runcommand/runcommand_config.h b/plugins/runcommand/runcommand_config.h index 8d1429614..27ab4eda4 100644 --- a/plugins/runcommand/runcommand_config.h +++ b/plugins/runcommand/runcommand_config.h @@ -16,7 +16,7 @@ class RunCommandConfig : public KdeConnectPluginKcm { Q_OBJECT public: - RunCommandConfig(QObject *parent, const QVariantList &); + RunCommandConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &); void save() override; void load() override; diff --git a/plugins/sendnotifications/sendnotifications_config.cpp b/plugins/sendnotifications/sendnotifications_config.cpp index 2ab9ba7be..6607a0596 100644 --- a/plugins/sendnotifications/sendnotifications_config.cpp +++ b/plugins/sendnotifications/sendnotifications_config.cpp @@ -13,8 +13,8 @@ K_PLUGIN_FACTORY(SendNotificationsConfigFactory, registerPlugin();) -SendNotificationsConfig::SendNotificationsConfig(QObject *parent, const QVariantList &args) - : KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_sendnotifications")) +SendNotificationsConfig::SendNotificationsConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KdeConnectPluginKcm(parent, data, args) , m_ui(new Ui::SendNotificationsConfigUi()) , appModel(new NotifyingApplicationModel) { diff --git a/plugins/sendnotifications/sendnotifications_config.h b/plugins/sendnotifications/sendnotifications_config.h index 19486378b..8fb29c846 100644 --- a/plugins/sendnotifications/sendnotifications_config.h +++ b/plugins/sendnotifications/sendnotifications_config.h @@ -20,7 +20,7 @@ class SendNotificationsConfig : public KdeConnectPluginKcm { Q_OBJECT public: - SendNotificationsConfig(QObject *parent, const QVariantList &); + SendNotificationsConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &); ~SendNotificationsConfig() override; void save() override; diff --git a/plugins/share/share_config.cpp b/plugins/share/share_config.cpp index 53cc7badb..ac6d56280 100644 --- a/plugins/share/share_config.cpp +++ b/plugins/share/share_config.cpp @@ -14,8 +14,8 @@ K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin();) -ShareConfig::ShareConfig(QObject *parent, const QVariantList &args) - : KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_share")) +ShareConfig::ShareConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KdeConnectPluginKcm(parent, data, args) , m_ui(new Ui::ShareConfigUi()) { m_ui->setupUi(widget()); diff --git a/plugins/share/share_config.h b/plugins/share/share_config.h index b98be0b8e..746d80c74 100644 --- a/plugins/share/share_config.h +++ b/plugins/share/share_config.h @@ -18,7 +18,7 @@ class ShareConfig : public KdeConnectPluginKcm { Q_OBJECT public: - ShareConfig(QObject *parent, const QVariantList &); + ShareConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args); ~ShareConfig() override; void save() override;