File indexing completed on 2024-05-19 15:09:24

0001 /*
0002     SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "kcmshell.h"
0008 
0009 #include <KAuthorized>
0010 #include <KService>
0011 
0012 #include <KIO/CommandLauncherJob>
0013 
0014 KCMShell::KCMShell(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 KCMShell::~KCMShell()
0020 {
0021 }
0022 
0023 void KCMShell::open(const QStringList &names) const
0024 {
0025     KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kcmshell5"), names);
0026     job->start();
0027 }
0028 
0029 void KCMShell::openSystemSettings(const QString &name, const QStringList &args) const
0030 {
0031     // The desktop filename is the same as the binary and icon
0032     const QString systemSettings = QStringLiteral("systemsettings");
0033     KIO::CommandLauncherJob *job = nullptr;
0034 
0035     QStringList cmdline{name};
0036     if (!args.isEmpty()) {
0037         cmdline.append(QStringLiteral("--args"));
0038         cmdline.append(args.join(QLatin1Char(' ')));
0039     }
0040 
0041     // Open in System Settings if it's available
0042     if (KService::serviceByDesktopName(systemSettings)) {
0043         job = new KIO::CommandLauncherJob(systemSettings, cmdline);
0044         job->setIcon(systemSettings);
0045         job->setDesktopName(systemSettings);
0046     } else {
0047         job = new KIO::CommandLauncherJob(QStringLiteral("kcmshell5"), cmdline);
0048     }
0049 
0050     job->start();
0051 }
0052 
0053 void KCMShell::openInfoCenter(const QString &name) const
0054 {
0055     const QString infoCenterDesktopFile = QStringLiteral("org.kde.kinfocenter");
0056     const QString infoCenterbinary = QStringLiteral("kinfocenter");
0057 
0058     KIO::CommandLauncherJob *job = nullptr;
0059 
0060     // Open in Info Center if it's available
0061     if (KService::serviceByDesktopName(infoCenterDesktopFile)) {
0062         job = new KIO::CommandLauncherJob(infoCenterbinary, QStringList(name));
0063         job->setIcon(infoCenterbinary);
0064         job->setDesktopName(infoCenterDesktopFile);
0065     } else {
0066         job = new KIO::CommandLauncherJob(QStringLiteral("kcmshell5"), QStringList(name));
0067     }
0068 
0069     job->start();
0070 }
0071 
0072 QStringList KCMShell::authorize(const QStringList &menuIds) const
0073 {
0074     return KAuthorized::authorizeControlModules(menuIds);
0075 }
0076 
0077 #include "moc_kcmshell.cpp"