kcm-openrc/openrc_kcm.cpp
Juraj Oravec c95cef0bbd
Port to TreeView with custom model
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2025-05-30 22:58:09 +02:00

102 lines
3.2 KiB
C++

#include "openrc_kcm.h"
#include "openrc_service_model.h"
#include <KPluginFactory>
#include <KLocalizedString>
#include "openrckcmsettings.h"
#include <sys/queue.h>
#include <QString>
#include <KAuth/Action>
#include <KAuth/ExecuteJob>
#include <rc.h>
K_PLUGIN_CLASS_WITH_JSON(OpenRCKCM, "kcm_openrc.json");
OpenRCKCM::OpenRCKCM(QObject *parent, const KPluginMetaData &metaData)
: KQuickManagedConfigModule(parent, metaData)
{
constexpr const char *uri = "org.kde.plasma.kcm.openrc";
qmlRegisterType<OpenRCServiceModel>(uri, 1, 0, "OpenRCServiceModel");
setButtons(Help | Apply | Default);
}
const QStringList OpenRCKCM::getAllServiceTitles() {
QStringList list;
{
RC_STRINGLIST* listS = rc_services_in_runlevel("default");
RC_STRING* svc;
TAILQ_FOREACH(svc, listS, entries) {
std::string serviceStrStd(svc->value);
std::string serviceDescription(rc_service_description(svc->value,""));
QString serviceStr = QString::fromStdString(serviceStrStd) + QString::fromStdString(" (") + QString::fromStdString(serviceDescription) + QString::fromStdString(")");
list << serviceStr;
}
rc_stringlist_free(listS);
}
return list;
}
const QStringList OpenRCKCM::getAllServices() {
QStringList list;
{
RC_STRINGLIST* listS = rc_services_in_runlevel("default");
RC_STRING* svc;
TAILQ_FOREACH(svc, listS, entries) {
std::string serviceStrStd(svc->value);
QString serviceStr = QString::fromStdString(serviceStrStd);
list << serviceStr;
}
rc_stringlist_free(listS);
}
return list;
}
void OpenRCKCM::tryDisableService ( QString serviceName )
{
QVariantMap map;
map[QStringLiteral("serviceName")] = serviceName;
KAuth::Action removal_service(QStringLiteral("tridentu.auth.openrc.service.removeservice"));
removal_service.setHelperId(QStringLiteral("tridentu.auth.openrc.service"));
removal_service.setArguments(map);
KAuth::ExecuteJob* job = removal_service.execute();
qDebug() << "Running rc-update...";
if(!job->exec()){
qDebug() << QStringLiteral("OpenRC Suite failed: ") << job->errorString();
}
}
void OpenRCKCM::tryStopService( QString serviceName )
{
QVariantMap map;
map[QStringLiteral("serviceName")] = serviceName;
KAuth::Action stop_service(QStringLiteral("tridentu.auth.openrc.service.stopservice"));
stop_service.setHelperId(QStringLiteral("tridentu.auth.openrc.service"));
stop_service.setArguments(map);
KAuth::ExecuteJob* job = stop_service.execute();
qDebug() << "Running rc-update...";
if(!job->exec()){
qDebug() << QStringLiteral("OpenRC Suite failed: ") << job->errorString();
}
}
void OpenRCKCM::tryRestartService( QString serviceName )
{
QVariantMap map;
map[QStringLiteral("serviceName")] = serviceName;
KAuth::Action rs_service(QStringLiteral("tridentu.auth.openrc.service.restartservice"));
rs_service.setHelperId(QStringLiteral("tridentu.auth.openrc.service"));
rs_service.setArguments(map);
KAuth::ExecuteJob* job = rs_service.execute();
qDebug() << "Running rc-update...";
if(!job->exec()){
qDebug() << QStringLiteral("OpenRC Suite failed: ") << job->errorString();
}
}
#include "openrc_kcm.moc"