diff --git a/kcms/ksmserver/CMakeLists.txt b/kcms/ksmserver/CMakeLists.txt index e1c83c9b6..48a93b952 100644 --- a/kcms/ksmserver/CMakeLists.txt +++ b/kcms/ksmserver/CMakeLists.txt @@ -1,21 +1,22 @@ # 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}) target_link_libraries(kcm_smserver Qt5::Core Qt5::DBus Qt5::Widgets KF5::I18n KF5::ConfigCore KF5::KCMUtils PW::KWorkspace) install(TARGETS kcm_smserver DESTINATION ${KDE_INSTALL_PLUGINDIR} ) ########### install files ############### install( FILES kcmsmserver.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) diff --git a/kcms/ksmserver/kcmsmserver.cpp b/kcms/ksmserver/kcmsmserver.cpp index 8d93f0462..f1338e1d7 100644 --- a/kcms/ksmserver/kcmsmserver.cpp +++ b/kcms/ksmserver/kcmsmserver.cpp @@ -1,228 +1,167 @@ /* * kcmsmserver.cpp * Copyright (c) 2000,2002 Oswald Buddenhagen * * based on kcmtaskbar.cpp * Copyright (c) 2000 Kurt Granroth * + * Copyright (c) 2019 Kevin Ottens + * * 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. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software */ #include #include #include #include #include #include #include -#include -#include -#include #include #include #include #include #include #include #include #include #include "kcmsmserver.h" -#include "smserverconfigimpl.h" +#include "smserversettings.h" +#include "ui_smserverconfigdlg.h" + #include #include #include #include #include "login1_manager.h" K_PLUGIN_FACTORY(SMSFactory, registerPlugin();) 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("

Session Manager

" " You can configure the session manager here." " This includes options such as whether or not the session exit (logout)" " should be confirmed, whether the session should be restored again when logging in" " 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")); connect(m_rebootNowAction, &QAction::triggered, this, [this] { auto sm = new SessionManagement(this); auto doShutdown=[sm]() { sm->requestReboot(); delete sm; }; if (sm->state() == SessionManagement::State::Loading) { connect(sm, &SessionManagement::stateChanged, this, doShutdown); } else { doShutdown(); } }); - 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(), m_login1Manager->interface(), QStringLiteral("SetRebootToFirmwareSetup")); message.setArguments({enable}); // This cannot be set through a generated DBus interface, so we have to create the message ourself. message.setInteractiveAuthorizationAllowed(true); QDBusPendingReply call = m_login1Manager->connection().asyncCall(message); QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(call, this); connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this, enable](QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; watcher->deleteLater(); 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 if (reply.error().type() != QDBusError::AccessDenied) { message->setMessageType(KMessageWidget::Error); message->setText(i18n("Failed to request restart to firmware setup: %1", reply.error().message())); message->animatedShow(); } return; } if (!enable) { return; } message->setMessageType(KMessageWidget::Information); if (m_isUefi) { message->setText(i18n("Next time the computer is restarted, it will enter the UEFI setup screen.")); } else { message->setText(i18n("Next time the computer is restarted, it will enter the firmware setup screen.")); } message->addAction(m_rebootNowAction); message->animatedShow(); }); }); const QString canFirmareSetup = m_login1Manager->CanRebootToFirmwareSetup().value(); if (canFirmareSetup == QLatin1String("yes") || canFirmareSetup == QLatin1String("challenge")) { // 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" diff --git a/kcms/ksmserver/kcmsmserver.h b/kcms/ksmserver/kcmsmserver.h index babf32ef0..32651cdb2 100644 --- a/kcms/ksmserver/kcmsmserver.h +++ b/kcms/ksmserver/kcmsmserver.h @@ -1,53 +1,58 @@ /* * kcmsmserver.h * Copyright (c) 2000 Oswald Buddenhagen * * based on kcmtaskbar.h * Copyright (c) 2000 Kurt Granroth * + * Copyright (c) 2019 Kevin Ottens + * * 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. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software */ #ifndef __kcmsmserver_h__ #define __kcmsmserver_h__ #include 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; + SMServerSettings *m_settings; OrgFreedesktopLogin1ManagerInterface *m_login1Manager = nullptr; QAction *m_rebootNowAction = nullptr; bool m_isUefi = false; }; #endif diff --git a/kcms/ksmserver/smserverconfigdlg.ui b/kcms/ksmserver/smserverconfigdlg.ui index 2455e05c4..bb084bcdd 100644 --- a/kcms/ksmserver/smserverconfigdlg.ui +++ b/kcms/ksmserver/smserverconfigdlg.ui @@ -1,198 +1,201 @@ SMServerConfigDlg 0 0 477 398 General - + Check this option if you want the session manager to display a logout confirmation dialog box. Conf&irm logout - + O&ffer shutdown options - + + + false + Here you can choose what should happen by default when you log out. This only has meaning, if you logged in through KDM. Default Leave Option &End current session &Turn off computer &Restart computer - + <ul> <li><b>Restore previous session:</b> Will save all applications running on exit and restore them when they next start up</li> <li><b>Restore manually saved session: </b> Allows the session to be saved at any time via "Save Session" in the K-Menu. This means the currently started applications will reappear when they next start up.</li> <li><b>Start with an empty session:</b> Do not save anything. Will come up with an empty desktop on next start.</li> </ul> On Login Restore &previous session Restore &manually saved session Start with an empty &session Applications to be e&xcluded from sessions: false - excludeLineedit + kcfg_excludeApps - + 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'. Firmware Setup true When the computer is restarted the next time, enter firmware setup screen (e.g. UEFI or BIOS setup) Enter firmware setup on next restart Qt::Vertical 20 1 KMessageWidget QFrame
kmessagewidget.h
1
- offerShutdownCheck + kcfg_offerShutdown toggled(bool) - sdGroup + kcfg_shutdownType setEnabled(bool) 20 20 20 20
diff --git a/kcms/ksmserver/smserverconfigimpl.cpp b/kcms/ksmserver/smserverconfigimpl.cpp deleted file mode 100644 index ab20cd03a..000000000 --- a/kcms/ksmserver/smserverconfigimpl.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - 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(); - -} diff --git a/kcms/ksmserver/smserverconfigimpl.h b/kcms/ksmserver/smserverconfigimpl.h deleted file mode 100644 index 00a53cd9a..000000000 --- a/kcms/ksmserver/smserverconfigimpl.h +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - 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 -#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 diff --git a/kcms/ksmserver/smserversettings.kcfg b/kcms/ksmserver/smserversettings.kcfg new file mode 100644 index 000000000..1c2de4920 --- /dev/null +++ b/kcms/ksmserver/smserversettings.kcfg @@ -0,0 +1,34 @@ + + + + + + + true + + + + true + + + + 0 + + + + + + + + + restorePreviousLogout + + + + + + + diff --git a/kcms/ksmserver/smserversettings.kcfgc b/kcms/ksmserver/smserversettings.kcfgc new file mode 100644 index 000000000..2b1882cd3 --- /dev/null +++ b/kcms/ksmserver/smserversettings.kcfgc @@ -0,0 +1,6 @@ +File=smserversettings.kcfg +ClassName=SMServerSettings +Mutators=true +DefaultValueGetters=true +GenerateProperties=true +ParentInConstructor=true