Commit 506d1807 authored by Kevin Ottens's avatar Kevin Ottens
Browse files

Port KSMServer's KCM to KConfigXT

Reviewers: #plasma, mart, davidedmundson, crossi, bport, mlaurent

Subscribers: mlaurent, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25609
parent c95d7fad
# KI18N Translation Domain for this library
add_definitions(-DTRANSLATION_DOMAIN=\"kcmsmserver\")
set(kcm_smserver_PART_SRCS kcmsmserver.cpp smserverconfigimpl.cpp )
set(kcm_smserver_PART_SRCS kcmsmserver.cpp)
qt5_add_dbus_interface(kcm_smserver_PART_SRCS org.freedesktop.login1.Manager.xml login1_manager)
kconfig_add_kcfg_files(kcm_smserver_PART_SRCS smserversettings.kcfgc GENERATE_MOC)
ki18n_wrap_ui(kcm_smserver_PART_SRCS smserverconfigdlg.ui )
add_library(kcm_smserver MODULE ${kcm_smserver_PART_SRCS})
......
......@@ -5,6 +5,8 @@
* based on kcmtaskbar.cpp
* Copyright (c) 2000 Kurt Granroth <granroth@kde.org>
*
* Copyright (c) 2019 Kevin Ottens <kevin.ottens@enioka.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
......@@ -28,9 +30,6 @@
#include <QVBoxLayout>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <ksharedconfig.h>
#include <kworkspace.h>
#include <qregexp.h>
#include <kdesktopfile.h>
......@@ -41,7 +40,9 @@
#include <QLineEdit>
#include "kcmsmserver.h"
#include "smserverconfigimpl.h"
#include "smserversettings.h"
#include "ui_smserverconfigdlg.h"
#include <KPluginFactory>
#include <KPluginLoader>
#include <KLocalizedString>
......@@ -54,11 +55,15 @@ K_PLUGIN_FACTORY(SMSFactory, registerPlugin<SMServerConfig>();)
SMServerConfig::SMServerConfig(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
, ui(new Ui::SMServerConfigDlg)
, m_settings(new SMServerSettings(this))
, m_login1Manager(new OrgFreedesktopLogin1ManagerInterface(QStringLiteral("org.freedesktop.login1"),
QStringLiteral("/org/freedesktop/login1"),
QDBusConnection::systemBus(),
this))
{
ui->setupUi(this);
setQuickHelp( i18n("<h1>Session Manager</h1>"
" You can configure the session manager here."
" This includes options such as whether or not the session exit (logout)"
......@@ -66,17 +71,17 @@ SMServerConfig::SMServerConfig(QWidget *parent, const QVariantList &args)
" and whether the computer should be automatically shut down after session"
" exit by default."));
QVBoxLayout *topLayout = new QVBoxLayout(this);
topLayout->setContentsMargins(0, 0, 0, 0);
dialog = new SMServerConfigImpl(this);
connect(dialog, SIGNAL(changed()), SLOT(changed()));
initFirmwareSetup();
checkFirmwareSetupRequested();
topLayout->addWidget(dialog);
ui->firmwareSetupBox->hide();
ui->firmwareSetupMessageWidget->hide();
addConfig(m_settings, this);
}
SMServerConfig::~SMServerConfig() = default;
void SMServerConfig::initFirmwareSetup()
{
m_rebootNowAction = new QAction(QIcon::fromTheme(QStringLiteral("system-reboot")), i18n("Restart Now"));
......@@ -93,9 +98,9 @@ void SMServerConfig::initFirmwareSetup()
}
});
connect(dialog->firmwareSetupCheck, &QCheckBox::clicked, this, [this](bool enable) {
dialog->firmwareSetupMessageWidget->removeAction(m_rebootNowAction);
dialog->firmwareSetupMessageWidget->animatedHide();
connect(ui->firmwareSetupCheck, &QCheckBox::clicked, this, [this](bool enable) {
ui->firmwareSetupMessageWidget->removeAction(m_rebootNowAction);
ui->firmwareSetupMessageWidget->animatedHide();
QDBusMessage message = QDBusMessage::createMethodCall(m_login1Manager->service(),
m_login1Manager->path(),
......@@ -114,7 +119,7 @@ void SMServerConfig::initFirmwareSetup()
checkFirmwareSetupRequested();
KMessageWidget *message = dialog->firmwareSetupMessageWidget;
KMessageWidget *message = ui->firmwareSetupMessageWidget;
if (reply.isError()) {
// User likely canceled the PolKit prompt, don't show an error in this case
......@@ -146,83 +151,17 @@ void SMServerConfig::initFirmwareSetup()
// now check whether we're UEFI to provide a more descriptive button label
if (QFileInfo(QStringLiteral("/sys/firmware/efi")).isDir()) {
m_isUefi = true;
dialog->firmwareSetupBox->setTitle(i18n("UEFI Setup"));
dialog->firmwareSetupCheck->setText(i18n("Enter UEFI setup on next restart"));
ui->firmwareSetupBox->setTitle(i18n("UEFI Setup"));
ui->firmwareSetupCheck->setText(i18n("Enter UEFI setup on next restart"));
}
dialog->firmwareSetupBox->setVisible(true);
ui->firmwareSetupBox->setVisible(true);
}
}
void SMServerConfig::checkFirmwareSetupRequested()
{
dialog->firmwareSetupCheck->setChecked(m_login1Manager->property("RebootToFirmwareSetup").toBool());
}
void SMServerConfig::load()
{
KConfigGroup c(KSharedConfig::openConfig(QStringLiteral("ksmserverrc"), KConfig::NoGlobals),
QStringLiteral("General"));
dialog->confirmLogoutCheck->setChecked(c.readEntry("confirmLogout", true));
bool en = c.readEntry("offerShutdown", true);
dialog->offerShutdownCheck->setChecked(en);
dialog->sdGroup->setEnabled(en);
QString s = c.readEntry( "loginMode" );
if ( s == QLatin1String("default") )
dialog->emptySessionRadio->setChecked(true);
else if ( s == QLatin1String("restoreSavedSession") )
dialog->savedSessionRadio->setChecked(true);
else // "restorePreviousLogout"
dialog->previousSessionRadio->setChecked(true);
switch (c.readEntry("shutdownType", int(KWorkSpace::ShutdownTypeNone))) {
case int(KWorkSpace::ShutdownTypeHalt):
dialog->haltRadio->setChecked(true);
break;
case int(KWorkSpace::ShutdownTypeReboot):
dialog->rebootRadio->setChecked(true);
break;
default:
dialog->logoutRadio->setChecked(true);
break;
}
dialog->excludeLineedit->setText( c.readEntry("excludeApps"));
emit changed(false);
}
void SMServerConfig::save()
{
KConfig c(QStringLiteral("ksmserverrc"), KConfig::NoGlobals);
KConfigGroup group = c.group(QStringLiteral("General"));
group.writeEntry( "confirmLogout", dialog->confirmLogoutCheck->isChecked());
group.writeEntry( "offerShutdown", dialog->offerShutdownCheck->isChecked());
QString s = QStringLiteral("restorePreviousLogout");
if ( dialog->emptySessionRadio->isChecked() )
s = QStringLiteral("default");
else if ( dialog->savedSessionRadio->isChecked() )
s = QStringLiteral("restoreSavedSession");
group.writeEntry( "loginMode", s );
group.writeEntry( "shutdownType",
dialog->haltRadio->isChecked() ?
int(KWorkSpace::ShutdownTypeHalt) :
dialog->rebootRadio->isChecked() ?
int(KWorkSpace::ShutdownTypeReboot) :
int(KWorkSpace::ShutdownTypeNone));
group.writeEntry("excludeApps", dialog->excludeLineedit->text());
c.sync();
}
void SMServerConfig::defaults()
{
dialog->previousSessionRadio->setChecked(true);
dialog->confirmLogoutCheck->setChecked(true);
dialog->offerShutdownCheck->setChecked(true);
dialog->sdGroup->setEnabled(true);
dialog->logoutRadio->setChecked(true);
dialog->excludeLineedit->clear();
ui->firmwareSetupCheck->setChecked(m_login1Manager->property("RebootToFirmwareSetup").toBool());
}
#include "kcmsmserver.moc"
......@@ -5,6 +5,8 @@
* based on kcmtaskbar.h
* Copyright (c) 2000 Kurt Granroth <granroth@kde.org>
*
* Copyright (c) 2019 Kevin Ottens <kevin.ottens@enioka.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
......@@ -25,26 +27,29 @@
class QAction;
class SMServerSettings;
class SMServerConfigImpl;
class OrgFreedesktopLogin1ManagerInterface;
namespace Ui {
class SMServerConfigDlg;
}
class SMServerConfig : public KCModule
{
Q_OBJECT
public:
explicit SMServerConfig( QWidget *parent=nullptr, const QVariantList &list=QVariantList() );
void load() override;
void save() override;
void defaults() override;
~SMServerConfig();
private:
void initFirmwareSetup();
void checkFirmwareSetupRequested();
SMServerConfigImpl* dialog;
QScopedPointer<Ui::SMServerConfigDlg> ui;
SMServerSettings *m_settings;
OrgFreedesktopLogin1ManagerInterface *m_login1Manager = nullptr;
QAction *m_rebootNowAction = nullptr;
bool m_isUefi = false;
......
......@@ -18,7 +18,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="confirmLogoutCheck">
<widget class="QCheckBox" name="kcfg_confirmLogout">
<property name="whatsThis">
<string>Check this option if you want the session manager to display a logout confirmation dialog box.</string>
</property>
......@@ -28,7 +28,7 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="offerShutdownCheck">
<widget class="QCheckBox" name="kcfg_offerShutdown">
<property name="text">
<string>O&amp;ffer shutdown options</string>
</property>
......@@ -38,7 +38,10 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="sdGroup">
<widget class="QGroupBox" name="kcfg_shutdownType">
<property name="enabled">
<bool>false</bool>
</property>
<property name="whatsThis">
<string>Here you can choose what should happen by default when you log out. This only has meaning, if you logged in through KDM.</string>
</property>
......@@ -71,7 +74,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="loginGroup">
<widget class="QGroupBox" name="kcfg_loginMode">
<property name="whatsThis">
<string>&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Restore previous session:&lt;/b&gt; Will save all applications running on exit and restore them when they next start up&lt;/li&gt;
......@@ -113,12 +116,12 @@
<bool>false</bool>
</property>
<property name="buddy">
<cstring>excludeLineedit</cstring>
<cstring>kcfg_excludeApps</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="excludeLineedit">
<widget class="QLineEdit" name="kcfg_excludeApps">
<property name="whatsThis">
<string>Here you can enter a colon or comma separated list of applications that should not be saved in sessions, and therefore will not be started when restoring a session. For example 'xterm:konsole' or 'xterm,konsole'.</string>
</property>
......@@ -179,9 +182,9 @@
<resources/>
<connections>
<connection>
<sender>offerShutdownCheck</sender>
<sender>kcfg_offerShutdown</sender>
<signal>toggled(bool)</signal>
<receiver>sdGroup</receiver>
<receiver>kcfg_shutdownType</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
......
/***************************************************************************
smserverconfigimpl.cpp - description
-------------------
begin : Thu May 17 2001
copyright : (C) 2001 by stulle
email : stulle@tux
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "smserverconfigimpl.h"
SMServerConfigImpl::SMServerConfigImpl(QWidget *parent ) : SMServerConfigDlg(parent) {
connect(confirmLogoutCheck,&QAbstractButton::toggled, this, &SMServerConfigImpl::configChanged);
connect(previousSessionRadio,&QAbstractButton::toggled, this, &SMServerConfigImpl::configChanged);
connect(savedSessionRadio,&QAbstractButton::toggled, this, &SMServerConfigImpl::configChanged);
connect(emptySessionRadio,&QAbstractButton::toggled, this, &SMServerConfigImpl::configChanged);
connect(logoutRadio,&QAbstractButton::toggled, this, &SMServerConfigImpl::configChanged);
connect(haltRadio,&QAbstractButton::toggled, this, &SMServerConfigImpl::configChanged);
connect(rebootRadio,&QAbstractButton::toggled, this, &SMServerConfigImpl::configChanged);
connect(excludeLineedit,&QLineEdit::textChanged,this, &SMServerConfigImpl::configChanged);
connect(offerShutdownCheck,&QAbstractButton::toggled,this, &SMServerConfigImpl::configChanged);
firmwareSetupBox->hide();
firmwareSetupMessageWidget->hide();
}
SMServerConfigImpl::~SMServerConfigImpl(){
}
/** No descriptions */
void SMServerConfigImpl::configChanged(){
emit changed();
}
/***************************************************************************
smserverconfigimpl.h - description
-------------------
begin : Thu May 17 2001
copyright : (C) 2001 by stulle
email : stulle@tux
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef SMSERVERCONFIGIMPL_H
#define SMSERVERCONFIGIMPL_H
#include <QWidget>
#include "ui_smserverconfigdlg.h"
/**
*@author stulle
*/
class SMServerConfigDlg : public QWidget, public Ui::SMServerConfigDlg
{
public:
SMServerConfigDlg( QWidget *parent ) : QWidget( parent ) {
setupUi( this );
}
};
class SMServerConfigImpl : public SMServerConfigDlg {
Q_OBJECT
public:
SMServerConfigImpl(QWidget *parent=nullptr);
~SMServerConfigImpl() override;
public Q_SLOTS: // Public slots
/** No descriptions */
void configChanged();
Q_SIGNALS: // Signals
/** No descriptions */
void changed();
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="ksmserverrc" />
<group name="General">
<entry name="confirmLogout" type="Bool">
<label>Confirm logout</label>
<default>true</default>
</entry>
<entry name="offerShutdown" type="Bool">
<label>Offer shutdown options</label>
<default>true</default>
</entry>
<entry name="shutdownType" type="Int">
<label>Default leave option</label>
<default>0</default>
</entry>
<entry name="loginMode" type="Enum">
<choices name="LoginModeType">
<choice name="restorePreviousLogout"/>
<choice name="restoreSavedSession"/>
<choice name="emptySession"/>
</choices>
<label>On login</label>
<default>restorePreviousLogout</default>
</entry>
<entry name="excludeApps" type="String">
<label>Applications to be excluded from session</label>
<default></default>
</entry>
</group>
</kcfg>
File=smserversettings.kcfg
ClassName=SMServerSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment