Commit 0dbc4dac authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Styles KCM] Port away from QDBusInterface

Check GTK module being loaded asynchronously and load the page
and its associated model only when entering the GTK subpage.
parent ff595625
......@@ -13,6 +13,8 @@ set(kcm_style_PART_SRCS
previewitem.cpp
styledata.cpp
)
qt5_add_dbus_interface(kcm_style_PART_SRCS ${KDED_DBUS_INTERFACE} kded_interface)
qt5_add_dbus_interface(kcm_style_PART_SRCS org.kde.GtkConfig.xml kdegtkconfig_interface)
kcmutils_generate_module_data(
kcm_style_PART_SRCS
......
......@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDBusReply>
#include <QDBusPendingCall>
#include <QDir>
#include <QStandardPaths>
#include <QUrl>
......@@ -32,24 +32,23 @@
GtkPage::GtkPage(QObject *parent)
: QObject(parent)
, m_gtkThemesModel(new GtkThemesModel(this))
, gtkConfigInterface(QStringLiteral("org.kde.GtkConfig"), QStringLiteral("/GtkConfig"), QStringLiteral("org.kde.GtkConfig"))
, m_gtkConfigInterface(QStringLiteral("org.kde.GtkConfig"), QStringLiteral("/GtkConfig"), QDBusConnection::sessionBus())
{
connect(m_gtkThemesModel, &GtkThemesModel::themeRemoved, this, &GtkPage::onThemeRemoved);
connect(m_gtkThemesModel, &GtkThemesModel::selectedThemeChanged, this, [this]() {
Q_EMIT gtkThemeSettingsChanged();
});
}
GtkPage::~GtkPage()
{
delete m_gtkThemesModel;
load();
}
GtkPage::~GtkPage() = default;
QString GtkPage::gtkThemeFromConfig()
{
QDBusReply<QString> dbusReply = gtkConfigInterface.call(QStringLiteral("gtkTheme"));
return dbusReply.value();
// FIXME make aysnc but that requires some refactoring on the UI side
return m_gtkConfigInterface.gtkTheme().value();
}
bool GtkPage::gtkPreviewAvailable()
......@@ -59,7 +58,7 @@ bool GtkPage::gtkPreviewAvailable()
void GtkPage::showGtkPreview()
{
gtkConfigInterface.call(QStringLiteral("showGtkThemePreview"), m_gtkThemesModel->selectedTheme());
m_gtkConfigInterface.showGtkThemePreview(m_gtkThemesModel->selectedTheme());
}
void GtkPage::onThemeRemoved()
......@@ -111,7 +110,9 @@ void GtkPage::installGtkThemeFromFile(const QUrl &fileUrl)
void GtkPage::save()
{
gtkConfigInterface.call(QStringLiteral("setGtkTheme"), m_gtkThemesModel->selectedTheme());
auto call = m_gtkConfigInterface.setGtkTheme(m_gtkThemesModel->selectedTheme());
// needs to block so "OK" button closing kcmshell still saves properly
call.waitForFinished();
}
void GtkPage::defaults()
......
......@@ -20,12 +20,13 @@
#pragma once
#include <QDBusInterface>
#include <QObject>
#include <QQmlListReference>
#include "gtkthemesmodel.h"
#include "kdegtkconfig_interface.h"
class GtkPage : public QObject
{
Q_OBJECT
......@@ -63,5 +64,5 @@ Q_SIGNALS:
private:
GtkThemesModel *m_gtkThemesModel;
QDBusInterface gtkConfigInterface;
OrgKdeGtkConfigInterface m_gtkConfigInterface;
};
......@@ -37,7 +37,8 @@
#include <KPluginFactory>
#include <KPluginLoader>
#include <QDBusReply>
#include <QDBusPendingReply>
#include <QDBusPendingCallWatcher>
#include <QLibrary>
#include <QMetaEnum>
#include <QQuickItem>
......@@ -53,6 +54,8 @@
#include "../krdb/krdb.h"
#include "kded_interface.h"
#include "previewitem.h"
#include "styledata.h"
#include "stylesettings.h"
......@@ -80,7 +83,6 @@ KCMStyle::KCMStyle(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_data(new StyleData(this))
, m_model(new StylesModel(this))
, m_gtkPage()
{
qmlRegisterUncreatableType<KCMStyle>("org.kde.private.kcms.style", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM"));
qmlRegisterType<StyleSettings>();
......@@ -99,12 +101,6 @@ KCMStyle::KCMStyle(QObject *parent, const QVariantList &args)
about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@broulik.de"));
setAboutData(about);
if (gtkConfigKdedModuleLoaded()) {
m_gtkPage = new GtkPage(this);
connect(m_gtkPage, &GtkPage::gtkThemeSettingsChanged, this, [this]() {
setNeedsSave(true);
});
}
connect(m_model, &StylesModel::selectedStyleChanged, this, [this](const QString &style) {
styleSettings()->setWidgetStyle(style);
});
......@@ -121,6 +117,18 @@ KCMStyle::KCMStyle(QObject *parent, const QVariantList &args)
KCMStyle::~KCMStyle() = default;
GtkPage *KCMStyle::gtkPage()
{
if (!m_gtkPage) {
m_gtkPage = new GtkPage(this);
connect(m_gtkPage, &GtkPage::gtkThemeSettingsChanged, this, [this]() {
setNeedsSave(true);
});
}
return m_gtkPage;
}
StylesModel *KCMStyle::model() const
{
return m_model;
......@@ -239,15 +247,39 @@ void KCMStyle::configure(const QString &title, const QString &styleName, QQuickI
m_styleConfigDialog->show();
}
bool KCMStyle::gtkConfigKdedModuleLoaded()
bool KCMStyle::gtkConfigKdedModuleLoaded() const
{
return m_gtkConfigKdedModuleLoaded;
}
void KCMStyle::checkGtkConfigKdedModuleLoaded()
{
QDBusInterface kdedInterface(QStringLiteral("org.kde.kded5"), QStringLiteral("/kded"), QStringLiteral("org.kde.kded5"));
QDBusReply<QStringList> loadedKdedModules = kdedInterface.call(QStringLiteral("loadedModules"));
return loadedKdedModules.value().contains(QStringLiteral("gtkconfig"));
org::kde::kded5 kdedInterface(QStringLiteral("org.kde.kded5"),
QStringLiteral("/kded"),
QDBusConnection::sessionBus());
auto call = kdedInterface.loadedModules();
auto *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<QStringList> reply = *watcher;
watcher->deleteLater();
if (reply.isError()) {
qWarning() << "Failed to check whether GTK Config KDED module is loaded" << reply.error().message();
return;
}
const bool isLoaded = reply.value().contains(QLatin1String("gtkconfig"));
if (m_gtkConfigKdedModuleLoaded != isLoaded) {
m_gtkConfigKdedModuleLoaded = isLoaded;
Q_EMIT gtkConfigKdedModuleLoadedChanged();
}
});
}
void KCMStyle::load()
{
checkGtkConfigKdedModuleLoaded();
if (m_gtkPage) {
m_gtkPage->load();
}
......
......@@ -47,11 +47,12 @@ class KCMStyle : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(GtkPage *gtkPage MEMBER m_gtkPage CONSTANT)
Q_PROPERTY(GtkPage *gtkPage READ gtkPage CONSTANT)
Q_PROPERTY(StylesModel *model READ model CONSTANT)
Q_PROPERTY(StyleSettings *styleSettings READ styleSettings CONSTANT)
Q_PROPERTY(ToolBarStyle mainToolBarStyle READ mainToolBarStyle WRITE setMainToolBarStyle NOTIFY mainToolBarStyleChanged)
Q_PROPERTY(ToolBarStyle otherToolBarStyle READ otherToolBarStyle WRITE setOtherToolBarStyle NOTIFY otherToolBarStyleChanged)
Q_PROPERTY(bool gtkConfigKdedModuleLoaded READ gtkConfigKdedModuleLoaded NOTIFY gtkConfigKdedModuleLoadedChanged)
public:
KCMStyle(QObject *parent, const QVariantList &args);
......@@ -65,6 +66,8 @@ public:
};
Q_ENUM(ToolBarStyle)
GtkPage *gtkPage();
StylesModel *model() const;
StyleSettings *styleSettings() const;
......@@ -77,8 +80,10 @@ public:
void setOtherToolBarStyle(ToolBarStyle style);
Q_SIGNAL void otherToolBarStyleChanged();
bool gtkConfigKdedModuleLoaded() const;
Q_SIGNAL void gtkConfigKdedModuleLoadedChanged();
Q_INVOKABLE void configure(const QString &title, const QString &styleName, QQuickItem *ctx = nullptr);
Q_INVOKABLE bool gtkConfigKdedModuleLoaded();
void load() override;
void save() override;
......@@ -90,6 +95,7 @@ Q_SIGNALS:
private:
void loadSettingsToModel();
void checkGtkConfigKdedModuleLoaded();
StyleData *m_data;
StylesModel *m_model;
......@@ -101,7 +107,10 @@ private:
ToolBarStyle m_otherToolBarStyle = NoText;
QPointer<StyleConfigDialog> m_styleConfigDialog;
GtkPage *m_gtkPage;
bool m_gtkConfigKdedModuleLoaded = false;
GtkPage *m_gtkPage = nullptr;
};
#endif // __KCMSTYLE_H
<?xml version="1.0"?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.GtkConfig">
<method name="setGtkTheme">
<arg name="themeName" type="s" direction="in"/>
</method>
<method name="gtkTheme">
<arg type="s" direction="out"/>
</method>
<method name="showGtkThemePreview">
<arg name="themeName" type="s" direction="in"/>
</method>
</interface>
</node>
......@@ -136,7 +136,7 @@ KCM.GridViewKCM {
QtControls.Button {
id: gtkSettingsButton
visible: kcm.gtkConfigKdedModuleLoaded()
visible: kcm.gtkConfigKdedModuleLoaded
text: i18n("Configure GNOME/GTK Application Style...")
icon.name: "configure"
onClicked: root.openGtkStyleSettings()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment