kgreeter: implement settings save

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-03-31 20:12:08 +03:00
parent 654bf3ba95
commit 517de9cc22
4 changed files with 108 additions and 0 deletions

View file

@ -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)

View file

@ -23,6 +23,7 @@
#include <QProcess>
#include <kdebug.h>
#include <klocale.h>
#include <kauthaction.h>
#include <kimageio.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>
@ -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);
}

View file

@ -0,0 +1,48 @@
/* This file is part of the KDE project
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
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 <QSettings>
#include <kauthhelpersupport.h>
#include "config-kgreeter.h"
ActionReply KGreeterHelper::save(const QVariantMap &parameters)
{
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)

View file

@ -0,0 +1,34 @@
/* This file is part of the KDE project
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
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 <kauthactionreply.h>
// 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 &parameters);
};
#endif // KGREETERHELPER_H