Discover external tool settings and refresh cached settings UI

This commit is contained in:
ajp_anton committed 2026-09-07 19:47:28 +00:00
1 parent 93607d749f
commit ed2bb7f92c
11 files changed
+202 -3

No files matched your search

@@ -51,6 +51,19 @@ QAbstractItemModel *FedoraToolsKcm::tools()
return &m_tools;
}
void FedoraToolsKcm::configureExternalTool(const QString &packageName)
{
QStringList command = m_tools.configurationCommand(packageName);
if (command.isEmpty()) {
setMessage(i18n("No configuration application is registered for %1.", packageName), true);
return;
}
const QString executable = command.takeFirst();
if (!QProcess::startDetached(executable, command)) {
setMessage(i18n("Could not open settings for %1.", packageName), true);
}
}
bool FedoraToolsKcm::busy() const
{
return m_busy;
@@ -53,6 +53,7 @@ public:
Q_INVOKABLE void refresh(bool refreshMetadata = false);
Q_INVOKABLE void clearMessage();
Q_INVOKABLE void configureExternalTool(const QString &packageName);
Q_INVOKABLE void installTool(const QString &packageName);
Q_INVOKABLE void removeTool(const QString &packageName);
Q_INVOKABLE void saveShortcutSettings(bool startWithFirst, bool initialShiftOpensNew, bool shiftCyclesBackward);
+11
View File
@@ -10,13 +10,23 @@
#include <QProcess>
#include <QRegularExpression>
#include <sys/stat.h>
namespace
{
constexpr int commandTimeoutMs = 10 * 60 * 1000;
void setChildUmask(QProcess &process)
{
process.setChildProcessModifier([]() {
umask(0022);
});
}
KAuth::ActionReply commandReply(const QString &program, const QStringList &arguments)
{
QProcess process;
setChildUmask(process);
process.setProcessChannelMode(QProcess::MergedChannels);
process.start(program, arguments);
if (!process.waitForStarted()) {
@@ -52,6 +62,7 @@ KAuth::ActionReply commandReply(const QString &program, const QStringList &argum
bool isPublishedTool(const QString &packageName)
{
QProcess process;
setChildUmask(process);
process.start(QStringLiteral("/usr/bin/dnf5"),
{QStringLiteral("--repo=fedora-tools"),
QStringLiteral("-q"),
+61 -1
View File
@@ -3,10 +3,55 @@
#include "toolmodel.h"
#include <QMap>
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStandardPaths>
#include <algorithm>
#include <utility>
namespace
{
QStringList readConfigurationCommand(const QString &packageName)
{
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral("fedora-tools/settings/") + packageName + QStringLiteral(".json"));
if (path.isEmpty()) {
return {};
}
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Cannot read tool configuration registration:" << path << file.errorString();
return {};
}
QJsonParseError error;
const auto document = QJsonDocument::fromJson(file.readAll(), &error);
const auto command = document.object().value(QStringLiteral("command")).toArray();
if (error.error != QJsonParseError::NoError || command.isEmpty()) {
qWarning() << "Invalid tool configuration registration:" << path;
return {};
}
QStringList result;
for (const auto &argument : command) {
if (!argument.isString()) {
qWarning() << "Invalid tool configuration argument:" << path;
return {};
}
result.append(argument.toString());
}
const QFileInfo executable(result.first());
if (!executable.isAbsolute() || !executable.isExecutable() || !executable.isFile()) {
qWarning() << "Tool configuration executable is unavailable:" << result.first();
return {};
}
return result;
}
}
ToolModel::ToolModel(QObject *parent)
: QAbstractListModel(parent)
{
@@ -43,9 +88,12 @@ QVariant ToolModel::data(const QModelIndex &index, int role) const
return tool.updateAvailable;
case ConfigurableRole:
return tool.installed
&& (tool.packageName == QStringLiteral("plasma-fingerprint-workaround")
&& (!tool.configurationCommand.isEmpty()
|| tool.packageName == QStringLiteral("plasma-fingerprint-workaround")
|| tool.packageName == QStringLiteral("plasma-task-group-shortcuts")
|| tool.packageName == QStringLiteral("touchpad-hold-tap"));
case ExternalConfigurationRole:
return tool.installed && !tool.configurationCommand.isEmpty();
default:
return {};
}
@@ -63,6 +111,7 @@ QHash<int, QByteArray> ToolModel::roleNames() const
{AvailableRole, "available"},
{UpdateAvailableRole, "updateAvailable"},
{ConfigurableRole, "configurable"},
{ExternalConfigurationRole, "externalConfiguration"},
};
}
@@ -79,6 +128,7 @@ void ToolModel::setPackages(const QList<PackageRecord> &installed,
tool.architecture = package.architecture;
tool.summary = package.summary;
tool.installed = true;
tool.configurationCommand = readConfigurationCommand(package.name);
}
for (const PackageRecord &package : available) {
@@ -116,3 +166,13 @@ bool ToolModel::mayRemove(const QString &packageName) const
return tool.packageName == packageName && tool.installed;
});
}
QStringList ToolModel::configurationCommand(const QString &packageName) const
{
for (const Tool &tool : m_tools) {
if (tool.packageName == packageName && tool.installed) {
return tool.configurationCommand;
}
}
return {};
}
+4
View File
@@ -6,6 +6,7 @@
#include <QAbstractListModel>
#include <QSet>
#include <QStringList>
struct Tool
{
@@ -14,6 +15,7 @@ struct Tool
QString availableVersion;
QString architecture;
QString summary;
QStringList configurationCommand;
bool installed = false;
bool available = false;
bool updateAvailable = false;
@@ -34,6 +36,7 @@ public:
AvailableRole,
UpdateAvailableRole,
ConfigurableRole,
ExternalConfigurationRole,
};
explicit ToolModel(QObject *parent = nullptr);
@@ -47,6 +50,7 @@ public:
const QSet<QString> &updates = {});
bool mayInstall(const QString &packageName) const;
bool mayRemove(const QString &packageName) const;
QStringList configurationCommand(const QString &packageName) const;
private:
QList<Tool> m_tools;
+5
View File
@@ -86,6 +86,7 @@ KCM.SimpleKCM {
required property bool available
required property bool updateAvailable
required property bool configurable
required property bool externalConfiguration
width: toolList.width
@@ -138,6 +139,10 @@ KCM.SimpleKCM {
enabled: !kcm.busy
onClicked: {
kcm.clearMessage()
if (toolCard.externalConfiguration) {
kcm.configureExternalTool(toolCard.packageName)
return
}
root.settingsPage = toolCard.packageName
if (root.settingsPage === "plasma-task-group-shortcuts") {
shortcutPage.loadSettings()