diff --git a/kcms/style/CMakeLists.txt b/kcms/style/CMakeLists.txt --- a/kcms/style/CMakeLists.txt +++ b/kcms/style/CMakeLists.txt @@ -10,6 +10,8 @@ stylesmodel.cpp gtkthemesmodel.cpp gtkpage.cpp + gtkconfigdbusinterface.cpp + kdeddbusinterface.cpp previewitem.cpp ) set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml) diff --git a/kcms/style/gtkconfigdbusinterface.h b/kcms/style/gtkconfigdbusinterface.h new file mode 100644 --- /dev/null +++ b/kcms/style/gtkconfigdbusinterface.h @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Mikhail Zolotukhin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +class GtkConfigDBusInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + GtkConfigDBusInterface(QObject* parent); + + void setGtk2Theme(const QString &themeName); + void setGtk3Theme(const QString &themeName); + + QString gtk2Theme(); + QString gtk3Theme(); + + void showGtk2Preview(const QString &themeName); + void showGtk3Preview(const QString &themeName); +}; diff --git a/kcms/style/gtkconfigdbusinterface.cpp b/kcms/style/gtkconfigdbusinterface.cpp new file mode 100644 --- /dev/null +++ b/kcms/style/gtkconfigdbusinterface.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2020 Mikhail Zolotukhin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "gtkconfigdbusinterface.h" + +GtkConfigDBusInterface::GtkConfigDBusInterface(QObject* parent) + : QDBusAbstractInterface("org.kde.GtkConfig", "/GtkConfig", "org.kde.GtkConfig", QDBusConnection::sessionBus(), parent) +{ + +} + +void GtkConfigDBusInterface::setGtk2Theme(const QString& themeName) +{ + asyncCall(QStringLiteral("setGtk2Theme"), themeName); +} + +void GtkConfigDBusInterface::setGtk3Theme(const QString& themeName) +{ + asyncCall(QStringLiteral("setGtk3Theme"), themeName); +} + +QString GtkConfigDBusInterface::gtk2Theme() +{ + QDBusReply reply = call(QStringLiteral("gtk2Theme")); + return reply.value(); +} + +QString GtkConfigDBusInterface::gtk3Theme() +{ + QDBusReply reply = call(QStringLiteral("gtk3Theme")); + return reply.value(); +} + +void GtkConfigDBusInterface::showGtk2Preview(const QString &themeName) +{ + asyncCall(QStringLiteral("showGtk2ThemePreview"), themeName); +} + +void GtkConfigDBusInterface::showGtk3Preview(const QString &themeName) +{ + asyncCall(QStringLiteral("showGtk3ThemePreview"), themeName); +} + +#include "gtkconfigdbusinterface.moc" diff --git a/kcms/style/gtkpage.h b/kcms/style/gtkpage.h --- a/kcms/style/gtkpage.h +++ b/kcms/style/gtkpage.h @@ -21,9 +21,9 @@ #pragma once #include -#include #include "gtkthemesmodel.h" +#include "gtkconfigdbusinterface.h" class GtkPage : public QObject { @@ -67,5 +67,5 @@ GtkThemesModel *m_gtk2ThemesModel; GtkThemesModel *m_gtk3ThemesModel; - QDBusInterface gtkConfigInterface; + GtkConfigDBusInterface gtkConfigInterface; }; diff --git a/kcms/style/gtkpage.cpp b/kcms/style/gtkpage.cpp --- a/kcms/style/gtkpage.cpp +++ b/kcms/style/gtkpage.cpp @@ -20,8 +20,6 @@ #include #include -#include -#include #include #include @@ -34,11 +32,7 @@ : QObject(parent) , m_gtk2ThemesModel(new GtkThemesModel(this)) , m_gtk3ThemesModel(new GtkThemesModel(this)) - , gtkConfigInterface( - QStringLiteral("org.kde.GtkConfig"), - QStringLiteral("/GtkConfig"), - QStringLiteral("org.kde.GtkConfig") - ) + , gtkConfigInterface(this) { connect(m_gtk2ThemesModel, &GtkThemesModel::themeRemoved, this, &GtkPage::onThemeRemoved); connect(m_gtk3ThemesModel, &GtkThemesModel::themeRemoved, this, &GtkPage::onThemeRemoved); @@ -59,27 +53,24 @@ QString GtkPage::gtk2ThemeFromConfig() { - QDBusReply dbusReply = gtkConfigInterface.call(QStringLiteral("gtk2Theme")); - return dbusReply.value(); + return gtkConfigInterface.gtk2Theme(); } QString GtkPage::gtk3ThemeFromConfig() { - QDBusReply dbusReply = gtkConfigInterface.call(QStringLiteral("gtk3Theme")); - return dbusReply.value(); + return gtkConfigInterface.gtk3Theme(); } void GtkPage::showGtk2Preview() { - gtkConfigInterface.call(QStringLiteral("showGtk2ThemePreview"), m_gtk2ThemesModel->selectedTheme()); + gtkConfigInterface.showGtk2Preview(m_gtk2ThemesModel->selectedTheme()); } void GtkPage::showGtk3Preview() { - gtkConfigInterface.call(QStringLiteral("showGtk3ThemePreview"), m_gtk3ThemesModel->selectedTheme()); + gtkConfigInterface.showGtk3Preview(m_gtk3ThemesModel->selectedTheme()); } - void GtkPage::installGtk2ThemeFromGHNS() { KNS3::DownloadDialog downloadDialog(QStringLiteral("cgctheme.knsrc")); @@ -140,8 +131,8 @@ void GtkPage::save() { - gtkConfigInterface.call(QStringLiteral("setGtk2Theme"), m_gtk2ThemesModel->selectedTheme()); - gtkConfigInterface.call(QStringLiteral("setGtk3Theme"), m_gtk3ThemesModel->selectedTheme()); + gtkConfigInterface.setGtk2Theme(m_gtk2ThemesModel->selectedTheme()); + gtkConfigInterface.setGtk3Theme(m_gtk3ThemesModel->selectedTheme()); } void GtkPage::defaults() diff --git a/kcms/style/kcmstyle.cpp b/kcms/style/kcmstyle.cpp --- a/kcms/style/kcmstyle.cpp +++ b/kcms/style/kcmstyle.cpp @@ -37,7 +37,6 @@ #include #include -#include #include #include #include @@ -57,6 +56,7 @@ #include "previewitem.h" #include "stylesettings.h" #include "gtkpage.h" +#include "kdeddbusinterface.h" K_PLUGIN_FACTORY_WITH_JSON(KCMStyleFactory, "kcm_style.json", registerPlugin();) @@ -240,13 +240,9 @@ bool KCMStyle::gtkConfigKdedModuleLoaded() { - QDBusInterface kdedInterface( - QStringLiteral("org.kde.kded5"), - QStringLiteral("/kded"), - QStringLiteral("org.kde.kded5") - ); - QDBusReply loadedKdedModules = kdedInterface.call(QStringLiteral("loadedModules")); - return loadedKdedModules.value().contains(QStringLiteral("gtkconfig")); + KdedDBusInterface kdedInterface(this); + QStringList loadedKdedModules = kdedInterface.loadedModules(); + return loadedKdedModules.contains(QStringLiteral("gtkconfig")); } void KCMStyle::load() diff --git a/kcms/style/kdeddbusinterface.h b/kcms/style/kdeddbusinterface.h new file mode 100644 --- /dev/null +++ b/kcms/style/kdeddbusinterface.h @@ -0,0 +1,34 @@ +/* + * Copyright 2020 Mikhail Zolotukhin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +class QStringList; + +class KdedDBusInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + KdedDBusInterface(QObject* parent); + + QStringList loadedModules(); +}; diff --git a/kcms/style/kdeddbusinterface.cpp b/kcms/style/kdeddbusinterface.cpp new file mode 100644 --- /dev/null +++ b/kcms/style/kdeddbusinterface.cpp @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Mikhail Zolotukhin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "kdeddbusinterface.h" + +KdedDBusInterface::KdedDBusInterface(QObject* parent) + : QDBusAbstractInterface("org.kde.kded5", "/kded", "org.kde.kded5", QDBusConnection::sessionBus(), parent) +{ + +} + +QStringList KdedDBusInterface::loadedModules() +{ + QDBusReply reply = call(QStringLiteral("loadedModules")); + return reply.value(); +} + + +#include "kdeddbusinterface.moc"