diff --git a/kgreeter/kcm/CMakeLists.txt b/kgreeter/kcm/CMakeLists.txt index fbc76f37..7051266e 100644 --- a/kgreeter/kcm/CMakeLists.txt +++ b/kgreeter/kcm/CMakeLists.txt @@ -22,3 +22,15 @@ install( FILES kcm_kgreeterconfig.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR} ) + +########### next target ############### + +add_executable(kcmkgreeterhelper kgreeterhelper.cpp) +target_link_libraries(kcmkgreeterhelper ${KDE4_KDECORE_LIBS}) + +install( + TARGETS kcmkgreeterhelper + DESTINATION ${KDE4_LIBEXEC_INSTALL_DIR} +) + +kde4_install_auth_helper_files(kcmkgreeterhelper org.kde.kcontrol.kcmkgreeter root) diff --git a/kgreeter/kcm/kgreeterconfig.cpp b/kgreeter/kcm/kgreeterconfig.cpp index f791dd90..3206fe9f 100644 --- a/kgreeter/kcm/kgreeterconfig.cpp +++ b/kgreeter/kcm/kgreeterconfig.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -119,6 +120,19 @@ void KCMGreeter::load() void KCMGreeter::save() { + KAuth::Action kgreeteraction("org.kde.kcontrol.kcmkgreeter.save"); + kgreeteraction.setHelperID("org.kde.kcontrol.kcmkgreeter"); + kgreeteraction.addArgument("style", stylesbox->currentText()); + kgreeteraction.addArgument("colorscheme", colorsbox->currentText()); + kgreeteraction.addArgument("background", backgroundrequester->url().path()); + kgreeteraction.addArgument("rectangle", rectanglerequester->url().path()); + KAuth::ActionReply kgreeterreply = kgreeteraction.execute(); + + // qDebug() << kgreeter.errorCode() << kgreeter.errorDescription(); + + if (kgreeterreply != KAuth::ActionReply::SuccessReply) { + KMessageBox::error(this, kgreeterreply.errorDescription()); + } emit changed(false); } diff --git a/kgreeter/kcm/kgreeterhelper.cpp b/kgreeter/kcm/kgreeterhelper.cpp new file mode 100644 index 00000000..4364ba46 --- /dev/null +++ b/kgreeter/kcm/kgreeterhelper.cpp @@ -0,0 +1,48 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kgreeterhelper.h" + +#include +#include + +#include "config-kgreeter.h" + +ActionReply KGreeterHelper::save(const QVariantMap ¶meters) +{ + if (!parameters.contains("style") || !parameters.contains("colorscheme") + || !parameters.contains("background") || !parameters.contains("rectangle")) { + return KAuth::ActionReply::HelperErrorReply; + } + + QSettings kgreetersettings(SYSCONF_INSTALL_DIR "/lightdm/lightdm-kgreeter-greeter.conf", QSettings::IniFormat); + kgreetersettings.setValue("greeter/style", parameters.value("style")); + kgreetersettings.setValue("greeter/colorscheme", parameters.value("colorscheme")); + kgreetersettings.setValue("greeter/background", parameters.value("background")); + kgreetersettings.setValue("greeter/rectangle", parameters.value("rectangle")); + if (kgreetersettings.status() != QSettings::NoError) { + KAuth::ActionReply errorreply(KAuth::ActionReply::HelperError); + errorreply.setErrorDescription("Could not save settings"); + errorreply.setErrorCode(1); + return errorreply; + } + + return KAuth::ActionReply::SuccessReply; +} + +KDE4_AUTH_HELPER_MAIN("org.kde.kcontrol.kcmkgreeter", KGreeterHelper) diff --git a/kgreeter/kcm/kgreeterhelper.h b/kgreeter/kcm/kgreeterhelper.h new file mode 100644 index 00000000..2b9c0ee9 --- /dev/null +++ b/kgreeter/kcm/kgreeterhelper.h @@ -0,0 +1,34 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KGREETERHELPER_H +#define KGREETERHELPER_H + +#include + +// methods return type must be ActionReply otherwise QMetaObject::invokeMethod() fails +using namespace KAuth; + +class KGreeterHelper : public QObject +{ + Q_OBJECT +public slots: + ActionReply save(const QVariantMap ¶meters); +}; + +#endif // KGREETERHELPER_H