kcm/decoration: Allow specifying the kcm separately from the decoration
It makes decorations lighter as they don't need to bundle its configuration logic. Deprecates the kcmodule property in favour of kcmoduleName which instead of assuming that the kcm is local to the plugin, it provides the plugin name to find and load.
This commit is contained in:
parent
381de13973
commit
fbbaab3eaf
8 changed files with 64 additions and 21 deletions
|
@ -6,7 +6,6 @@
|
|||
"Name": "Fake Decoration With Shadows"
|
||||
},
|
||||
"org.kde.kdecoration2": {
|
||||
"blur": false,
|
||||
"kcmodule": false
|
||||
"blur": false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace Preview
|
|||
{
|
||||
|
||||
static const QString s_pluginName = QStringLiteral("org.kde.kdecoration2");
|
||||
static const QString s_kcmName = QStringLiteral("org.kde.kdecoration2.kcm");
|
||||
|
||||
PreviewBridge::PreviewBridge(QObject *parent)
|
||||
: DecorationBridge(parent)
|
||||
|
@ -92,6 +93,20 @@ void PreviewBridge::setTheme(const QString &theme)
|
|||
Q_EMIT themeChanged();
|
||||
}
|
||||
|
||||
QString PreviewBridge::kcmoduleName() const
|
||||
{
|
||||
return m_kcmoduleName;
|
||||
}
|
||||
|
||||
void PreviewBridge::setKcmoduleName(const QString &kcmoduleName)
|
||||
{
|
||||
if (m_kcmoduleName == kcmoduleName) {
|
||||
return;
|
||||
}
|
||||
m_kcmoduleName = kcmoduleName;
|
||||
Q_EMIT themeChanged();
|
||||
}
|
||||
|
||||
QString PreviewBridge::plugin() const
|
||||
{
|
||||
return m_plugin;
|
||||
|
@ -155,6 +170,7 @@ DecorationButton *PreviewBridge::createButton(KDecoration2::Decoration *decorati
|
|||
void PreviewBridge::configure(QQuickItem *ctx)
|
||||
{
|
||||
if (!m_valid) {
|
||||
qWarning() << "Cannot show an invalid decoration's configuration dialog";
|
||||
return;
|
||||
}
|
||||
// setup the UI
|
||||
|
@ -169,10 +185,16 @@ void PreviewBridge::configure(QQuickItem *ctx)
|
|||
if (!m_theme.isNull()) {
|
||||
args.insert(QStringLiteral("theme"), m_theme);
|
||||
}
|
||||
Q_ASSERT(!m_kcmoduleName.isEmpty());
|
||||
const auto md = KPluginMetaData::findPluginById(s_kcmName, m_kcmoduleName);
|
||||
const auto result = KPluginFactory::instantiatePlugin<KCModule>(md, dialog, QVariantList({args}));
|
||||
if (!result) {
|
||||
qWarning() << "error loading kcm" << result.errorReason << result.errorText;
|
||||
}
|
||||
|
||||
KCModule *kcm = m_factory->create<KCModule>(dialog, QVariantList({args}));
|
||||
|
||||
KCModule *kcm = result.plugin;
|
||||
if (!kcm) {
|
||||
qWarning() << "Could not find the kcm for" << args << m_kcmoduleName << m_theme;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -223,6 +245,7 @@ BridgeItem::BridgeItem(QObject *parent)
|
|||
connect(m_bridge, &PreviewBridge::themeChanged, this, &BridgeItem::themeChanged);
|
||||
connect(m_bridge, &PreviewBridge::pluginChanged, this, &BridgeItem::pluginChanged);
|
||||
connect(m_bridge, &PreviewBridge::validChanged, this, &BridgeItem::validChanged);
|
||||
connect(m_bridge, &PreviewBridge::kcmoduleNameChanged, this, &BridgeItem::kcmoduleNameChanged);
|
||||
}
|
||||
|
||||
BridgeItem::~BridgeItem()
|
||||
|
|
|
@ -29,6 +29,7 @@ class PreviewBridge : public DecorationBridge
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
|
||||
Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged)
|
||||
Q_PROPERTY(QString kcmoduleName READ kcmoduleName WRITE setKcmoduleName NOTIFY kcmoduleNameChanged)
|
||||
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
|
||||
public:
|
||||
explicit PreviewBridge(QObject *parent = nullptr);
|
||||
|
@ -50,6 +51,8 @@ public:
|
|||
|
||||
void setPlugin(const QString &plugin);
|
||||
QString plugin() const;
|
||||
void setKcmoduleName(const QString &name);
|
||||
QString kcmoduleName() const;
|
||||
void setTheme(const QString &theme);
|
||||
QString theme() const;
|
||||
bool isValid() const;
|
||||
|
@ -64,6 +67,7 @@ Q_SIGNALS:
|
|||
void pluginChanged();
|
||||
void themeChanged();
|
||||
void validChanged();
|
||||
void kcmoduleNameChanged();
|
||||
|
||||
private:
|
||||
void createFactory();
|
||||
|
@ -73,6 +77,7 @@ private:
|
|||
QList<PreviewItem *> m_previewItems;
|
||||
QString m_plugin;
|
||||
QString m_theme;
|
||||
QString m_kcmoduleName;
|
||||
QPointer<KPluginFactory> m_factory;
|
||||
bool m_valid;
|
||||
};
|
||||
|
@ -82,6 +87,7 @@ class BridgeItem : public QObject
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
|
||||
Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged)
|
||||
Q_PROPERTY(QString kcmoduleName READ kcmoduleName WRITE setKcmoduleName NOTIFY kcmoduleNameChanged)
|
||||
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
|
||||
Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge CONSTANT)
|
||||
|
||||
|
@ -101,6 +107,14 @@ public:
|
|||
{
|
||||
m_bridge->setTheme(theme);
|
||||
}
|
||||
QString kcmoduleName() const
|
||||
{
|
||||
return m_bridge->kcmoduleName();
|
||||
}
|
||||
void setKcmoduleName(const QString &name)
|
||||
{
|
||||
m_bridge->setKcmoduleName(name);
|
||||
}
|
||||
QString theme() const
|
||||
{
|
||||
return m_bridge->theme();
|
||||
|
@ -118,6 +132,7 @@ public:
|
|||
Q_SIGNALS:
|
||||
void pluginChanged();
|
||||
void themeChanged();
|
||||
void kcmoduleNameChanged();
|
||||
void validChanged();
|
||||
|
||||
private:
|
||||
|
|
|
@ -50,7 +50,9 @@ QVariant DecorationsModel::data(const QModelIndex &index, int role) const
|
|||
case ThemeNameRole:
|
||||
return d.themeName();
|
||||
case ConfigurationRole:
|
||||
return d.hasConfiguration();
|
||||
return !d.configurationName().isEmpty();
|
||||
case KcmoduleNameRole:
|
||||
return d.configurationName();
|
||||
case RecommendedBorderSizeRole:
|
||||
return Utils::borderSizeToString(d.borderSize());
|
||||
}
|
||||
|
@ -63,6 +65,7 @@ QHash<int, QByteArray> DecorationsModel::roleNames() const
|
|||
{PluginNameRole, QByteArrayLiteral("plugin")},
|
||||
{ThemeNameRole, QByteArrayLiteral("theme")},
|
||||
{ConfigurationRole, QByteArrayLiteral("configureable")},
|
||||
{KcmoduleNameRole, QByteArrayLiteral("kcmoduleName")},
|
||||
{RecommendedBorderSizeRole, QByteArrayLiteral("recommendedbordersize")}});
|
||||
return roles;
|
||||
}
|
||||
|
@ -76,15 +79,6 @@ static bool isThemeEngine(const QVariantMap &decoSettingsMap)
|
|||
return it.value().toBool();
|
||||
}
|
||||
|
||||
static bool isConfigureable(const QVariantMap &decoSettingsMap)
|
||||
{
|
||||
auto it = decoSettingsMap.find(QStringLiteral("kcmodule"));
|
||||
if (it == decoSettingsMap.end()) {
|
||||
return false;
|
||||
}
|
||||
return it.value().toBool();
|
||||
}
|
||||
|
||||
static KDecoration2::BorderSize recommendedBorderSize(const QVariantMap &decoSettingsMap)
|
||||
{
|
||||
auto it = decoSettingsMap.find(QStringLiteral("recommendedBorderSize"));
|
||||
|
@ -142,7 +136,12 @@ void DecorationsModel::init()
|
|||
continue;
|
||||
}
|
||||
}
|
||||
data.setHasConfiguration(isConfigureable(decoSettingsMap));
|
||||
|
||||
if (decoSettingsMap.contains(QStringLiteral("kcmodule"))) {
|
||||
qWarning() << "The use of 'kcmodule' is deprecated in favor of 'kcmoduleName', please update" << info.name();
|
||||
}
|
||||
|
||||
data.setConfigurationName(info.value("X-KDE-ConfigModule"));
|
||||
data.setBorderSize(recommendedBorderSize(decoSettingsMap));
|
||||
data.setVisibleName(info.name().isEmpty() ? info.pluginId() : info.name());
|
||||
data.setPluginId(info.pluginId());
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
ThemeNameRole,
|
||||
ConfigurationRole,
|
||||
RecommendedBorderSizeRole,
|
||||
KcmoduleNameRole,
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
|
@ -42,6 +42,7 @@ KCM.GridView {
|
|||
id: bridgeItem
|
||||
plugin: model.plugin
|
||||
theme: model.theme
|
||||
kcmoduleName: model.kcmoduleName
|
||||
}
|
||||
KDecoration.Settings {
|
||||
id: settingsItem
|
||||
|
|
|
@ -617,7 +617,9 @@ void ThemeProvider::findAllQmlThemes()
|
|||
data.setPluginId(m_data.pluginId());
|
||||
data.setThemeName(offer.pluginId());
|
||||
data.setVisibleName(offer.name());
|
||||
data.setHasConfiguration(hasConfiguration(offer.pluginId()));
|
||||
if (hasConfiguration(offer.pluginId())) {
|
||||
data.setConfigurationName("kwin_aurorae_config");
|
||||
}
|
||||
m_themes.append(data);
|
||||
}
|
||||
}
|
||||
|
@ -654,7 +656,9 @@ void ThemeProvider::findAllSvgThemes()
|
|||
data.setPluginId(m_data.pluginId());
|
||||
data.setThemeName(QLatin1String("__aurorae__svg__") + packageName);
|
||||
data.setVisibleName(name);
|
||||
data.setHasConfiguration(hasConfiguration(data.themeName()));
|
||||
if (hasConfiguration(data.themeName())) {
|
||||
data.setConfigurationName("kwin_aurorae_config");
|
||||
}
|
||||
m_themes.append(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
{
|
||||
"org.kde.kdecoration2": {
|
||||
"KNewStuff": "aurorae.knsrc",
|
||||
"defaultTheme": "kwin4_decoration_qml_plastik",
|
||||
"themeListKeyword": "themes",
|
||||
"KNewStuff": "aurorae.knsrc",
|
||||
"defaultTheme": "kwin4_decoration_qml_plastik",
|
||||
"themeListKeyword": "themes",
|
||||
"themes": true
|
||||
}
|
||||
},
|
||||
"X-KDE-ConfigModule": "kwin4_decoration_qml_plastik"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue