┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/settings/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/services')
-rw-r--r--src/settings/services/servicemenuinstaller/CMakeLists.txt5
-rw-r--r--src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp147
-rw-r--r--src/settings/services/servicessettingspage.cpp53
-rw-r--r--src/settings/services/servicessettingspage.h14
4 files changed, 173 insertions, 46 deletions
diff --git a/src/settings/services/servicemenuinstaller/CMakeLists.txt b/src/settings/services/servicemenuinstaller/CMakeLists.txt
index 988899936..46b159079 100644
--- a/src/settings/services/servicemenuinstaller/CMakeLists.txt
+++ b/src/settings/services/servicemenuinstaller/CMakeLists.txt
@@ -6,5 +6,10 @@ target_link_libraries(servicemenuinstaller PRIVATE
Qt5::Core
Qt5::Gui
KF5::I18n
+ KF5::CoreAddons
)
+
+if(HAVE_PACKAGEKIT)
+ target_link_libraries(servicemenuinstaller PRIVATE PK::packagekitqt5)
+endif()
install(TARGETS servicemenuinstaller ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp b/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp
index 06f34c6b9..89f2545f8 100644
--- a/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp
+++ b/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp
@@ -20,28 +20,42 @@
#include <QDebug>
#include <QProcess>
+#include <QTimer>
#include <QStandardPaths>
#include <QDir>
#include <QDirIterator>
#include <QCommandLineParser>
#include <QMimeDatabase>
#include <QUrl>
-#include <QDesktopServices>
#include <QGuiApplication>
-
#include <KLocalizedString>
+#include <KShell>
+
+#include "../../../config-packagekit.h"
+
+const static QStringList binaryPackages = {QStringLiteral("application/vnd.debian.binary-package"),
+ QStringLiteral("application/x-rpm"),
+ QStringLiteral("application/x-xz"),
+ QStringLiteral("application/zstd")};
+enum PackageOperation {
+ Install,
+ Uninstall
+};
+
+#ifdef HAVE_PACKAGEKIT
+#include <PackageKit/Daemon>
+#include <PackageKit/Details>
+#include <PackageKit/Transaction>
+#else
+#include <QDesktopServices>
+#endif
// @param msg Error that gets logged to CLI
Q_NORETURN void fail(const QString &str)
{
qCritical() << str;
-
- QProcess process;
- const QStringList args = {"--passivepopup", i18n("Dolphin service menu installation failed"), "15"};
- process.start("kdialog", args, QIODevice::ReadOnly);
- if (!process.waitForStarted()) {
- qFatal("Failed to run kdialog");
- }
+ const QStringList args = {"--detailederror" ,i18n("Dolphin service menu installation failed"), str};
+ QProcess::startDetached("kdialog", args);
exit(1);
}
@@ -52,6 +66,84 @@ QString getServiceMenusDir()
return QDir(dataLocation).absoluteFilePath("kservices5/ServiceMenus");
}
+#ifdef HAVE_PACKAGEKIT
+void packageKitInstall(const QString &fileName)
+{
+ PackageKit::Transaction *transaction = PackageKit::Daemon::installFile(fileName);
+
+ const auto exitWithError = [=](PackageKit::Transaction::Error, const QString &details) {
+ fail(details);
+ };
+
+ QObject::connect(transaction, &PackageKit::Transaction::finished,
+ [=](PackageKit::Transaction::Exit status, uint) {
+ if (status == PackageKit::Transaction::ExitSuccess) {
+ exit(0);
+ }
+ // Fallback error handling
+ QTimer::singleShot(500, [=](){
+ fail(i18n("Failed to install \"%1\", exited with status \"%2\"",
+ fileName, QVariant::fromValue(status).toString()));
+ });
+ });
+ QObject::connect(transaction, &PackageKit::Transaction::errorCode, exitWithError);
+}
+
+void packageKitUninstall(const QString &fileName)
+{
+ const auto exitWithError = [=](PackageKit::Transaction::Error, const QString &details) {
+ fail(details);
+ };
+ const auto uninstallLambda = [=](PackageKit::Transaction::Exit status, uint) {
+ if (status == PackageKit::Transaction::ExitSuccess) {
+ exit(0);
+ }
+ };
+
+ PackageKit::Transaction *transaction = PackageKit::Daemon::getDetailsLocal(fileName);
+ QObject::connect(transaction, &PackageKit::Transaction::details,
+ [=](const PackageKit::Details &details) {
+ PackageKit::Transaction *transaction = PackageKit::Daemon::removePackage(details.packageId());
+ QObject::connect(transaction, &PackageKit::Transaction::finished, uninstallLambda);
+ QObject::connect(transaction, &PackageKit::Transaction::errorCode, exitWithError);
+ });
+
+ QObject::connect(transaction, &PackageKit::Transaction::errorCode, exitWithError);
+ // Fallback error handling
+ QObject::connect(transaction, &PackageKit::Transaction::finished,
+ [=](PackageKit::Transaction::Exit status, uint) {
+ if (status != PackageKit::Transaction::ExitSuccess) {
+ QTimer::singleShot(500, [=]() {
+ fail(i18n("Failed to uninstall \"%1\", exited with status \"%2\"",
+ fileName, QVariant::fromValue(status).toString()));
+ });
+ }
+ });
+ }
+#endif
+
+Q_NORETURN void packageKit(PackageOperation operation, const QString &fileName)
+{
+#ifdef HAVE_PACKAGEKIT
+ QFileInfo fileInfo(fileName);
+ if (!fileInfo.exists()) {
+ fail(i18n("The file does not exist!"));
+ }
+ const QString absPath = fileInfo.absoluteFilePath();
+ if (operation == PackageOperation::Install) {
+ packageKitInstall(absPath);
+ } else {
+ packageKitUninstall(absPath);
+ }
+ QGuiApplication::exec(); // For event handling, no return after signals finish
+ fail(i18n("Unknown error when installing package"));
+#else
+ Q_UNUSED(operation)
+ QDesktopServices::openUrl(QUrl(fileName));
+ exit(0);
+#endif
+}
+
struct UncompressCommand
{
QString command;
@@ -59,6 +151,11 @@ struct UncompressCommand
QStringList args2;
};
+enum ScriptExecution{
+ Process,
+ Konsole
+};
+
void runUncompress(const QString &inputPath, const QString &outputPath)
{
QVector<QPair<QStringList, UncompressCommand>> mimeTypeToCommand;
@@ -126,12 +223,24 @@ QString findRecursive(const QString &dir, const QString &basename)
return QString();
}
-bool runScriptOnce(const QString &path, const QStringList &args)
+bool runScriptOnce(const QString &path, const QStringList &args, ScriptExecution execution)
{
QProcess process;
process.setWorkingDirectory(QFileInfo(path).absolutePath());
- process.start(path, args, QIODevice::NotOpen);
+ const static bool konsoleAvailable = !QStandardPaths::findExecutable("konsole").isEmpty();
+ if (konsoleAvailable && execution == ScriptExecution::Konsole) {
+ QString bashCommand = KShell::quoteArg(path) + ' ';
+ if (!args.isEmpty()) {
+ bashCommand.append(args.join(' '));
+ }
+ bashCommand.append("|| $SHELL");
+ // If the install script fails a shell opens and the user can fix the problem
+ // without an error konsole closes
+ process.start("konsole", QStringList() << "-e" << "bash" << "-c" << bashCommand, QIODevice::NotOpen);
+ } else {
+ process.start(path, args, QIODevice::NotOpen);
+ }
if (!process.waitForStarted()) {
fail(i18n("Failed to run installer script %1", path));
}
@@ -163,11 +272,11 @@ bool runScriptVariants(const QString &path, bool hasArgVariants, const QStringLi
qInfo() << "[servicemenuinstaller]: Trying to run installer/uninstaller" << path;
if (hasArgVariants) {
for (const auto &arg : argVariants) {
- if (runScriptOnce(path, {arg})) {
+ if (runScriptOnce(path, {arg}, ScriptExecution::Process)) {
return true;
}
}
- } else if (runScriptOnce(path, {})) {
+ } else if (runScriptOnce(path, {}, ScriptExecution::Konsole)) {
return true;
}
@@ -202,9 +311,8 @@ bool cmdInstall(const QString &archive, QString &errorText)
return false;
}
} else {
- const QStringList binaryPackages = {"application/vnd.debian.binary-package", "application/x-rpm"};
if (binaryPackages.contains(QMimeDatabase().mimeTypeForFile(archive).name())) {
- return QDesktopServices::openUrl(QUrl(archive));
+ packageKit(PackageOperation::Install, archive);
}
const QString dir = generateDirPath(archive);
if (QFile::exists(dir)) {
@@ -247,7 +355,11 @@ bool cmdInstall(const QString &archive, QString &errorText)
}
if (!installerPath.isEmpty()) {
- return runScriptVariants(installerPath, true, {"--local", "--local-install", "--install"}, errorText);
+ // Try to run script without variants first
+ if (!runScriptVariants(installerPath, false, {}, errorText)) {
+ return runScriptVariants(installerPath, true, {"--local", "--local-install", "--install"}, errorText);
+ }
+ return true;
}
fail(i18n("Failed to find an installation script in %1", dir));
@@ -268,6 +380,9 @@ bool cmdUninstall(const QString &archive, QString &errorText)
return false;
}
} else {
+ if (binaryPackages.contains(QMimeDatabase().mimeTypeForFile(archive).name())) {
+ packageKit(PackageOperation::Uninstall, archive);
+ }
const QString dir = generateDirPath(archive);
// Try "deinstall" first
diff --git a/src/settings/services/servicessettingspage.cpp b/src/settings/services/servicessettingspage.cpp
index fe900bc5c..e18bfb09e 100644
--- a/src/settings/services/servicessettingspage.cpp
+++ b/src/settings/services/servicessettingspage.cpp
@@ -38,6 +38,7 @@
#include <QListWidget>
#include <QShowEvent>
#include <QSortFilterProxyModel>
+#include <QLineEdit>
namespace
{
@@ -61,25 +62,33 @@ ServicesSettingsPage::ServicesSettingsPage(QWidget* parent) :
"Select which services should "
"be shown in the context menu:"), this);
label->setWordWrap(true);
+ m_searchLineEdit = new QLineEdit(this);
+ m_searchLineEdit->setPlaceholderText(i18nc("@label:textbox", "Search..."));
+ connect(m_searchLineEdit, &QLineEdit::textChanged, this, [this](const QString &filter){
+ m_sortModel->setFilterFixedString(filter);
+ });
m_listView = new QListView(this);
- ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView);
+ auto *delegate = new ServiceItemDelegate(m_listView, m_listView);
m_serviceModel = new ServiceModel(this);
m_sortModel = new QSortFilterProxyModel(this);
m_sortModel->setSourceModel(m_serviceModel);
m_sortModel->setSortRole(Qt::DisplayRole);
m_sortModel->setSortLocaleAware(true);
+ m_sortModel->setFilterRole(Qt::DisplayRole);
+ m_sortModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
m_listView->setModel(m_sortModel);
m_listView->setItemDelegate(delegate);
m_listView->setVerticalScrollMode(QListView::ScrollPerPixel);
connect(m_listView, &QListView::clicked, this, &ServicesSettingsPage::changed);
- KNS3::Button* downloadButton = new KNS3::Button(i18nc("@action:button", "Download New Services..."),
- QStringLiteral("servicemenu.knsrc"),
- this);
+ auto *downloadButton = new KNS3::Button(i18nc("@action:button", "Download New Services..."),
+ QStringLiteral("servicemenu.knsrc"),
+ this);
connect(downloadButton, &KNS3::Button::dialogFinished, this, &ServicesSettingsPage::loadServices);
topLayout->addWidget(label);
+ topLayout->addWidget(m_searchLineEdit);
topLayout->addWidget(m_listView);
topLayout->addWidget(downloadButton);
@@ -87,9 +96,7 @@ ServicesSettingsPage::ServicesSettingsPage(QWidget* parent) :
std::sort(m_enabledVcsPlugins.begin(), m_enabledVcsPlugins.end());
}
-ServicesSettingsPage::~ServicesSettingsPage()
-{
-}
+ServicesSettingsPage::~ServicesSettingsPage() = default;
void ServicesSettingsPage::applySettings()
{
@@ -102,7 +109,7 @@ void ServicesSettingsPage::applySettings()
QStringList enabledPlugins;
- const QAbstractItemModel* model = m_listView->model();
+ const QAbstractItemModel *model = m_listView->model();
for (int i = 0; i < model->rowCount(); ++i) {
const QModelIndex index = model->index(i, 0);
const QString service = model->data(index, ServiceModel::DesktopEntryNameRole).toString();
@@ -188,19 +195,16 @@ void ServicesSettingsPage::loadServices()
// Load generic services
const KService::List entries = KServiceTypeTrader::self()->query(QStringLiteral("KonqPopupMenu/Plugin"));
- foreach (const KService::Ptr& service, entries) {
+ for (const KService::Ptr &service : entries) {
const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kservices5/" % service->entryPath());
- const QList<KServiceAction> serviceActions =
- KDesktopFileActions::userDefinedServices(file, true);
+ const QList<KServiceAction> serviceActions = KDesktopFileActions::userDefinedServices(file, true);
- KDesktopFile desktopFile(file);
+ const KDesktopFile desktopFile(file);
const QString subMenuName = desktopFile.desktopGroup().readEntry("X-KDE-Submenu");
- foreach (const KServiceAction& action, serviceActions) {
+ for (const KServiceAction &action : serviceActions) {
const QString serviceName = action.name();
- const bool addService = !action.noDisplay()
- && !action.isSeparator()
- && !isInServicesList(serviceName);
+ const bool addService = !action.noDisplay() && !action.isSeparator() && !isInServicesList(serviceName);
if (addService) {
const QString itemName = subMenuName.isEmpty()
@@ -214,7 +218,7 @@ void ServicesSettingsPage::loadServices()
// Load service plugins that implement the KFileItemActionPlugin interface
const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("KFileItemAction/Plugin"));
- foreach (const KService::Ptr& service, pluginServices) {
+ for (const KService::Ptr &service : pluginServices) {
const QString desktopEntryName = service->desktopEntryName();
if (!isInServicesList(desktopEntryName)) {
const bool checked = showGroup.readEntry(desktopEntryName, true);
@@ -227,7 +231,7 @@ void ServicesSettingsPage::loadServices()
return metaData.serviceTypes().contains(QLatin1String("KFileItemAction/Plugin"));
});
- foreach (const auto& jsonMetadata, jsonPlugins) {
+ for (const auto &jsonMetadata : jsonPlugins) {
const QString desktopEntryName = jsonMetadata.pluginId();
if (!isInServicesList(desktopEntryName)) {
const bool checked = showGroup.readEntry(desktopEntryName, true);
@@ -236,6 +240,7 @@ void ServicesSettingsPage::loadServices()
}
m_sortModel->sort(Qt::DisplayRole);
+ m_searchLineEdit->setFocus(Qt::OtherFocusReason);
}
void ServicesSettingsPage::loadVersionControlSystems()
@@ -244,8 +249,8 @@ void ServicesSettingsPage::loadVersionControlSystems()
// Create a checkbox for each available version control plugin
const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin"));
- for (KService::List::ConstIterator it = pluginServices.constBegin(); it != pluginServices.constEnd(); ++it) {
- const QString pluginName = (*it)->name();
+ for (const auto &plugin : pluginServices) {
+ const QString pluginName = plugin->name();
addRow(QStringLiteral("code-class"),
pluginName,
VersionControlServicePrefix + pluginName,
@@ -255,7 +260,7 @@ void ServicesSettingsPage::loadVersionControlSystems()
m_sortModel->sort(Qt::DisplayRole);
}
-bool ServicesSettingsPage::isInServicesList(const QString& service) const
+bool ServicesSettingsPage::isInServicesList(const QString &service) const
{
for (int i = 0; i < m_serviceModel->rowCount(); ++i) {
const QModelIndex index = m_serviceModel->index(i, 0);
@@ -266,9 +271,9 @@ bool ServicesSettingsPage::isInServicesList(const QString& service) const
return false;
}
-void ServicesSettingsPage::addRow(const QString& icon,
- const QString& text,
- const QString& value,
+void ServicesSettingsPage::addRow(const QString &icon,
+ const QString &text,
+ const QString &value,
bool checked)
{
m_serviceModel->insertRow(0);
diff --git a/src/settings/services/servicessettingspage.h b/src/settings/services/servicessettingspage.h
index cd4cbe52f..8f507407b 100644
--- a/src/settings/services/servicessettingspage.h
+++ b/src/settings/services/servicessettingspage.h
@@ -26,6 +26,7 @@
class QListView;
class QSortFilterProxyModel;
class ServiceModel;
+class QLineEdit;
/**
* @brief Page for the 'Services' settings of the Dolphin settings dialog.
@@ -59,21 +60,22 @@ private:
*/
void loadVersionControlSystems();
- bool isInServicesList(const QString& service) const;
+ bool isInServicesList(const QString &service) const;
/**
* Adds a row to the model of m_listView.
*/
- void addRow(const QString& icon,
- const QString& text,
- const QString& value,
+ void addRow(const QString &icon,
+ const QString &text,
+ const QString &value,
bool checked);
private:
bool m_initialized;
- ServiceModel* m_serviceModel;
- QSortFilterProxyModel* m_sortModel;
+ ServiceModel *m_serviceModel;
+ QSortFilterProxyModel *m_sortModel;
QListView* m_listView;
+ QLineEdit *m_searchLineEdit;
QStringList m_enabledVcsPlugins;
};