Commit ec464bb9 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Port plasmasearch KCM to QML

parent 17154702
Pipeline #183675 passed with stage
in 3 minutes and 32 seconds
# SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
# SPDX-License-Identifier: BSD-3-Clause
# KI18N Translation Domain for this library
add_definitions(-DTRANSLATION_DOMAIN=\"kcm_search\")
......
# KRunner Settings Module
set(kcm_krunnersettings_SRCS
krunnersettings.cpp
krunnersettingsdata.cpp
)
kcmutils_generate_module_data(
kcm_krunnersettings_SRCS
MODULE_DATA_HEADER krunnersettingsdata.h
......@@ -16,16 +15,14 @@ kconfig_add_kcfg_files(kcm_krunnersettings_SRCS krunnersettingsbase.kcfgc GENERA
kcoreaddons_add_plugin(kcm_krunnersettings SOURCES ${kcm_krunnersettings_SRCS} INSTALL_NAMESPACE "plasma/kcms/desktop")
target_link_libraries(kcm_krunnersettings
Qt::DBus
KF5::Activities
KF5::ConfigCore
KF5::I18n
KF5::KCMUtils
KF5::QuickAddons
Qt::DBus
)
install(FILES krunnersettingsbase.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
kpackage_install_package(package kcm_krunnersettings kcms)
install(FILES kcm_krunnersettings.desktop DESTINATION ${KDE_INSTALL_APPDIR})
kpackage_install_package(package kcm_krunnersettings kcms)
add_library(kcm_plasmasearch MODULE kcm.cpp krunnerdata.cpp)
# SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
# SPDX-License-Identifier: BSD-3-Clause
add_library(kcm_plasmasearch MODULE kcm.cpp)
target_link_libraries(kcm_plasmasearch
KF5::CoreAddons
KF5::KCMUtilsCore
KF5::KCMUtils
KF5::QuickAddons
KF5::Runner
KF5::I18n
KF5::NewStuffWidgets
Qt::DBus
Qt::Widgets
)
install(TARGETS kcm_plasmasearch DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/kcms/systemsettings_qwidgets)
kpackage_install_package(package kcm_plasmasearch kcms)
install(TARGETS kcm_plasmasearch DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/kcms/systemsettings)
install(FILES kcm_plasmasearch.desktop DESTINATION ${KDE_INSTALL_APPDIR})
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
SPDX-FileCopyrightText: 2020 Alexander Lohnau <alexander.lohnau@gmx.de>
SPDX-FileCopyrightText: 2020, 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
SPDX-License-Identifier: LGPL-2.0-only
......@@ -9,123 +9,102 @@
#include "kcm.h"
#include <KAboutData>
#include <KCModuleData>
#include <KCMultiDialog>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KNSWidgets/Button>
#include <KPluginFactory>
#include <KPluginWidget>
#include <KRunner/RunnerManager>
#include <QDebug>
#include <QApplication>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusMetaType>
#include <QLabel>
#include <QVBoxLayout>
#include "krunnerdata.h"
class KRunnerData : public KCModuleData
{
Q_OBJECT
public:
using KCModuleData::KCModuleData;
bool isDefaults() const override
{
const QVector<KPluginMetaData> runnerData = Plasma::RunnerManager::runnerMetaDataList();
KConfigGroup cfgGroup(m_krunnerConfig, "Plugins");
return std::all_of(runnerData.begin(), runnerData.end(), [&cfgGroup](const KPluginMetaData &pluginData) {
return pluginData.isEnabled(cfgGroup) != pluginData.isEnabledByDefault();
});
}
private:
KSharedConfigPtr m_krunnerConfig = KSharedConfig::openConfig("krunnerrc");
};
K_PLUGIN_FACTORY_WITH_JSON(SearchConfigModuleFactory, "kcm_plasmasearch.json", registerPlugin<SearchConfigModule>(); registerPlugin<KRunnerData>();)
SearchConfigModule::SearchConfigModule(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
SearchConfigModule::SearchConfigModule(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, data, args)
, m_model(new KPluginModel(this))
, m_config(KSharedConfig::openConfig("krunnerrc"))
{
KAboutData *about = new KAboutData(QStringLiteral("kcm_search"),
i18nc("kcm name for About dialog", "Configure search settings"),
QStringLiteral("0.1"),
QString(),
KAboutLicense::LGPL);
about->addAuthor(i18n("Vishesh Handa"), QString(), QStringLiteral("vhanda@kde.org"));
setAboutData(about);
setButtons(Apply | Default);
if (!args.at(0).toString().isEmpty()) {
qDBusRegisterMetaType<QByteArrayList>();
qDBusRegisterMetaType<QHash<QString, QByteArrayList>>();
if (!args.isEmpty()) {
m_pluginID = args.at(0).toString();
}
qDBusRegisterMetaType<QByteArrayList>();
qDBusRegisterMetaType<QHash<QString, QByteArrayList>>();
QVBoxLayout *layout = new QVBoxLayout(this);
connect(m_model, &KPluginModel::defaulted, this, &SearchConfigModule::representsDefaults);
connect(m_model, &KPluginModel::isSaveNeededChanged, this, [this]() {
setNeedsSave(m_model->isSaveNeeded());
});
}
QHBoxLayout *headerLayout = new QHBoxLayout;
layout->addLayout(headerLayout);
void SearchConfigModule::load()
{
reloadPlugins();
QLabel *label = new QLabel(i18n("Enable or disable plugins (used in KRunner, Application Launcher, and the Overview effect)"));
if (!m_pluginID.isEmpty()) {
const KPluginMetaData data = m_model->findConfigForPluginId(m_pluginID);
if (data.isValid()) {
showKCM(data);
} else {
qWarning() << "Could not find plugin with id" << m_pluginID;
}
m_pluginID.clear(); // Clear this to avoid showing the plugin's config again if we reset the KCM
}
}
headerLayout->addWidget(label);
headerLayout->addStretch();
void SearchConfigModule::reloadPlugins()
{
m_model->clear();
m_pluginSelector = new KPluginWidget(this);
connect(m_pluginSelector, &KPluginWidget::changed, this, &SearchConfigModule::updateUnmanagedState);
m_model->addPlugins(Plasma::RunnerManager::runnerMetaDataList(), i18n("Available Plugins"));
m_model->setConfig(m_config->group("Plugins"));
}
qDBusRegisterMetaType<QByteArrayList>();
qDBusRegisterMetaType<QHash<QString, QByteArrayList>>();
// This will trigger the reloadConfiguration method for the runner
connect(m_pluginSelector, &KPluginWidget::pluginConfigSaved, this, [](const QString &componentName) {
void SearchConfigModule::showKCM(const KPluginMetaData &data, const QStringList args) const
{
auto dlg = new KCMultiDialog();
dlg->addModule(data, args);
dlg->show();
connect(dlg, qOverload<>(&KCMultiDialog::configCommitted), dlg, [data]() {
QDBusMessage message =
QDBusMessage::createSignal(QStringLiteral("/krunnerrc"), QStringLiteral("org.kde.kconfig.notify"), QStringLiteral("ConfigChanged"));
const QHash<QString, QByteArrayList> changes = {
{QStringLiteral("Runners"), {componentName.toLocal8Bit()}},
{QStringLiteral("Runners"), {data.pluginId().toLocal8Bit()}},
};
message.setArguments({QVariant::fromValue(changes)});
QDBusConnection::sessionBus().send(message);
});
layout->addWidget(m_pluginSelector);
QHBoxLayout *downloadLayout = new QHBoxLayout;
// Open KRunner settings
m_krunnerSettingsButton = new QPushButton(QIcon::fromTheme(QStringLiteral("krunner")), QStringLiteral("Configure KRunner…"), this);
connect(m_krunnerSettingsButton, &QPushButton::clicked, this, [this] {
if (!m_krunnerSettingsDialog) {
m_krunnerSettingsDialog = new KCMultiDialog(this);
m_krunnerSettingsDialog->addModule(KPluginMetaData(QStringLiteral("plasma/kcms/desktop/kcm_krunnersettings")),
{QStringLiteral("openedFromPluginSettings")});
}
m_krunnerSettingsDialog->show();
});
KNSWidgets::Button *downloadButton = new KNSWidgets::Button(i18n("Get New Plugins…"), QStringLiteral("krunner.knsrc"), this);
connect(downloadButton, &KNSWidgets::Button::dialogFinished, this, [this](const QList<KNSCore::Entry> &changedEntries) {
if (!changedEntries.isEmpty()) {
m_pluginSelector->clear();
m_pluginSelector->addPlugins(Plasma::RunnerManager::runnerMetaDataList(), i18n("Available Plugins"));
}
});
downloadLayout->addStretch();
downloadLayout->addWidget(m_krunnerSettingsButton);
downloadLayout->addWidget(downloadButton);
layout->addLayout(downloadLayout);
connect(this, &SearchConfigModule::defaultsIndicatorsVisibleChanged, this, &SearchConfigModule::updateUnmanagedState);
connect(this, &SearchConfigModule::defaultsIndicatorsVisibleChanged, m_pluginSelector, &KPluginWidget::setDefaultsIndicatorsVisible);
}
void SearchConfigModule::load()
{
m_pluginSelector->clear();
KCModule::load();
// Set focus on the pluginselector to pass focus to search bar.
m_pluginSelector->setFocus(Qt::OtherFocusReason);
m_pluginSelector->addPlugins(Plasma::RunnerManager::runnerMetaDataList(), i18n("Available Plugins"));
m_pluginSelector->setConfig(m_config->group("Plugins"));
if (!m_pluginID.isEmpty()) {
m_pluginSelector->showConfiguration(m_pluginID);
}
}
void SearchConfigModule::save()
{
KCModule::save();
KQuickAddons::ManagedConfigModule::save();
m_pluginSelector->save();
m_model->save();
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/krunnerrc"), QStringLiteral("org.kde.kconfig.notify"), QStringLiteral("ConfigChanged"));
const QHash<QString, QByteArrayList> changes = {{QStringLiteral("Plugins"), {}}};
......@@ -135,15 +114,9 @@ void SearchConfigModule::save()
void SearchConfigModule::defaults()
{
KCModule::defaults();
KQuickAddons::ManagedConfigModule::defaults();
m_pluginSelector->defaults();
}
void SearchConfigModule::updateUnmanagedState()
{
unmanagedWidgetChangeState(m_pluginSelector->isSaveNeeded());
unmanagedWidgetDefaultState(m_pluginSelector->isDefault());
m_model->defaults();
}
void SearchConfigModule::setDefaultIndicatorVisible(QWidget *widget, bool visible)
......
......@@ -2,6 +2,7 @@
SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
SPDX-FileCopyrightText: 2020 Alexander Lohnau <alexander.lohnau@gmx.de>
SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
......@@ -9,38 +10,43 @@
#ifndef _KCM_SEARCH_H
#define _KCM_SEARCH_H
#include <KCModule>
#include <KPluginModel>
#include <KQuickAddons/ManagedConfigModule>
#include <KSharedConfig>
#include <QPushButton>
class KPluginWidget;
class KCMultiDialog;
class SearchConfigModule : public KCModule
class SearchConfigModule : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT)
public:
enum Roles {
RunnersRole = Qt::UserRole + 1,
DescriptionRole,
};
explicit SearchConfigModule(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
SearchConfigModule(QWidget *parent, const QVariantList &args);
QAbstractItemModel *model() const
{
return m_model;
}
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
void updateUnmanagedState();
void reloadPlugins();
void showKCM(const KPluginMetaData &data, const QStringList args = {}) const;
void showKRunnerKCM() const
{
showKCM(KPluginMetaData(QStringLiteral("plasma/kcms/desktop/kcm_krunnersettings")), {QStringLiteral("openedFromPluginSettings")});
};
private:
void setDefaultIndicatorVisible(QWidget *widget, bool visible);
KPluginWidget *m_pluginSelector;
KPluginModel *m_model;
KSharedConfigPtr m_config;
QString m_pluginID;
QPushButton *m_krunnerSettingsButton = nullptr;
KCMultiDialog *m_krunnerSettingsDialog = nullptr;
};
......
/*
SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "krunnerdata.h"
#include <KPackage/Package>
#include <KPackage/PackageLoader>
#include <KPackage/PackageStructure>
#include <KPluginFactory>
#include <KPluginInfo>
#include <KRunner/RunnerManager>
KRunnerData::KRunnerData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_krunnerConfig(KSharedConfig::openConfig("krunnerrc"))
{
}
bool KRunnerData::isDefaults() const
{
const QVector<KPluginMetaData> runnerData = Plasma::RunnerManager::runnerMetaDataList();
KConfigGroup cfgGroup(m_krunnerConfig, "Plugins");
if (std::any_of(runnerData.cbegin(), runnerData.cend(), [&cfgGroup](const KPluginMetaData &pluginData) {
return pluginData.isEnabled(cfgGroup) != pluginData.isEnabledByDefault();
})) {
return false;
}
return true;
}
/*
SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
SPDX-License-Identifier: LGPL-2.0-only
*/
#ifndef KRUNNERDATA_H
#define KRUNNERDATA_H
#include <QObject>
#include <KCModuleData>
#include <KSharedConfig>
class KRunnerData : public KCModuleData
{
Q_OBJECT
public:
KRunnerData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
bool isDefaults() const override;
private:
KSharedConfigPtr m_krunnerConfig;
};
#endif // KRUNNERDATA_H
/*
SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.1
import org.kde.kconfig 1.0
import org.kde.kcm 1.3 as KCM
import org.kde.kirigami 2.19 as Kirigami
import org.kde.kcmutils 1.0 as KCMUtils
import org.kde.newstuff 1.91 as NewStuff
KCM.ScrollViewKCM {
id: root
implicitWidth: Kirigami.Units.gridUnit * 32
implicitHeight: Kirigami.Units.gridUnit * 18
header: ColumnLayout {
QQC2.Label {
text: i18n("Enable or disable plugins (used in KRunner, Application Launcher, and the Overview effect)")
}
Kirigami.SearchField {
Layout.fillWidth: true
id: searchField
wrapMode: Text.WordWrap
}
}
view: KCMUtils.KPluginSelector {
sourceModel: kcm.model
query: searchField.text
delegate: KCMUtils.KPluginDelegate {
onConfigTriggered: kcm.showKCM(model.config)
highlighted: false
hoverEnabled: false
}
}
footer: Kirigami.ActionToolBar {
flat: false
alignment: Qt.AlignRight
actions: [
Kirigami.Action {
text: i18n("Configure KRunner…")
onTriggered: kcm.showKRunnerKCM()
},
NewStuff.Action {
text: i18n("Get New Plugins…")
visible: KAuthorized.authorize(KAuthorized.GHNS)
configFile: "krunner.knsrc"
onEntryEvent: function (entry, event) {
if (event == NewStuff.Entry.StatusChangedEvent) {
kcm.reloadPlugin()
}
}
}
]
}
}
# SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
# SPDX-License-Identifier: BSD-3-Clause
add_executable(krunner-plugininstaller
main.cpp
AbstractJob.cpp
......
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