Changeset View
Changeset View
Standalone View
Standalone View
kcms/ksmserver/kcmsmserver.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * kcmsmserver.cpp | 2 | * kcmsmserver.cpp | ||
3 | * Copyright (c) 2000,2002 Oswald Buddenhagen <ossi@kde.org> | 3 | * Copyright (c) 2000,2002 Oswald Buddenhagen <ossi@kde.org> | ||
4 | * | 4 | * | ||
5 | * based on kcmtaskbar.cpp | 5 | * based on kcmtaskbar.cpp | ||
6 | * Copyright (c) 2000 Kurt Granroth <granroth@kde.org> | 6 | * Copyright (c) 2000 Kurt Granroth <granroth@kde.org> | ||
7 | * | 7 | * | ||
8 | * Copyright (c) 2019 Kevin Ottens <kevin.ottens@enioka.com> | ||||
9 | * | ||||
8 | * This program is free software; you can redistribute it and/or modify | 10 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | 13 | * (at your option) any later version. | ||
12 | * | 14 | * | ||
13 | * This program is distributed in the hope that it will be useful, | 15 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | 18 | * GNU General Public License for more details. | ||
17 | * | 19 | * | ||
18 | * You should have received a copy of the GNU General Public License | 20 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | 21 | * along with this program; if not, write to the Free Software | ||
20 | */ | 22 | */ | ||
21 | 23 | | |||
22 | #include <QAction> | 24 | #include <QAction> | ||
23 | #include <QDBusConnection> | 25 | #include <QDBusConnection> | ||
24 | #include <QDBusPendingCallWatcher> | 26 | #include <QDBusPendingCallWatcher> | ||
25 | #include <QDBusPendingReply> | 27 | #include <QDBusPendingReply> | ||
26 | #include <QCheckBox> | 28 | #include <QCheckBox> | ||
27 | #include <QFileInfo> | 29 | #include <QFileInfo> | ||
28 | 30 | | |||
29 | #include <QVBoxLayout> | 31 | #include <QVBoxLayout> | ||
30 | 32 | | |||
31 | #include <kconfig.h> | | |||
32 | #include <kconfiggroup.h> | | |||
33 | #include <ksharedconfig.h> | | |||
34 | #include <kworkspace.h> | 33 | #include <kworkspace.h> | ||
35 | #include <qregexp.h> | 34 | #include <qregexp.h> | ||
36 | #include <kdesktopfile.h> | 35 | #include <kdesktopfile.h> | ||
37 | #include <kprocess.h> | 36 | #include <kprocess.h> | ||
38 | #include <kmessagebox.h> | 37 | #include <kmessagebox.h> | ||
39 | #include <QApplication> | 38 | #include <QApplication> | ||
40 | #include <QDBusInterface> | 39 | #include <QDBusInterface> | ||
41 | #include <QLineEdit> | 40 | #include <QLineEdit> | ||
42 | 41 | | |||
43 | #include "kcmsmserver.h" | 42 | #include "kcmsmserver.h" | ||
44 | #include "smserverconfigimpl.h" | 43 | #include "smserversettings.h" | ||
44 | #include "ui_smserverconfigdlg.h" | ||||
45 | | ||||
45 | #include <KPluginFactory> | 46 | #include <KPluginFactory> | ||
46 | #include <KPluginLoader> | 47 | #include <KPluginLoader> | ||
47 | #include <KLocalizedString> | 48 | #include <KLocalizedString> | ||
48 | 49 | | |||
49 | #include <sessionmanagement.h> | 50 | #include <sessionmanagement.h> | ||
50 | 51 | | |||
51 | #include "login1_manager.h" | 52 | #include "login1_manager.h" | ||
52 | 53 | | |||
53 | K_PLUGIN_FACTORY(SMSFactory, registerPlugin<SMServerConfig>();) | 54 | K_PLUGIN_FACTORY(SMSFactory, registerPlugin<SMServerConfig>();) | ||
54 | 55 | | |||
55 | SMServerConfig::SMServerConfig(QWidget *parent, const QVariantList &args) | 56 | SMServerConfig::SMServerConfig(QWidget *parent, const QVariantList &args) | ||
56 | : KCModule(parent, args) | 57 | : KCModule(parent, args) | ||
58 | , ui(new Ui::SMServerConfigDlg) | ||||
59 | , m_settings(new SMServerSettings(this)) | ||||
57 | , m_login1Manager(new OrgFreedesktopLogin1ManagerInterface(QStringLiteral("org.freedesktop.login1"), | 60 | , m_login1Manager(new OrgFreedesktopLogin1ManagerInterface(QStringLiteral("org.freedesktop.login1"), | ||
58 | QStringLiteral("/org/freedesktop/login1"), | 61 | QStringLiteral("/org/freedesktop/login1"), | ||
59 | QDBusConnection::systemBus(), | 62 | QDBusConnection::systemBus(), | ||
60 | this)) | 63 | this)) | ||
61 | { | 64 | { | ||
65 | ui->setupUi(this); | ||||
66 | | ||||
62 | setQuickHelp( i18n("<h1>Session Manager</h1>" | 67 | setQuickHelp( i18n("<h1>Session Manager</h1>" | ||
63 | " You can configure the session manager here." | 68 | " You can configure the session manager here." | ||
64 | " This includes options such as whether or not the session exit (logout)" | 69 | " This includes options such as whether or not the session exit (logout)" | ||
65 | " should be confirmed, whether the session should be restored again when logging in" | 70 | " should be confirmed, whether the session should be restored again when logging in" | ||
66 | " and whether the computer should be automatically shut down after session" | 71 | " and whether the computer should be automatically shut down after session" | ||
67 | " exit by default.")); | 72 | " exit by default.")); | ||
68 | 73 | | |||
69 | QVBoxLayout *topLayout = new QVBoxLayout(this); | | |||
70 | topLayout->setContentsMargins(0, 0, 0, 0); | | |||
71 | dialog = new SMServerConfigImpl(this); | | |||
72 | connect(dialog, SIGNAL(changed()), SLOT(changed())); | | |||
73 | | ||||
74 | initFirmwareSetup(); | 74 | initFirmwareSetup(); | ||
75 | checkFirmwareSetupRequested(); | 75 | checkFirmwareSetupRequested(); | ||
76 | 76 | | |||
77 | topLayout->addWidget(dialog); | 77 | ui->firmwareSetupBox->hide(); | ||
78 | ui->firmwareSetupMessageWidget->hide(); | ||||
79 | | ||||
80 | addConfig(m_settings, this); | ||||
78 | } | 81 | } | ||
79 | 82 | | |||
83 | SMServerConfig::~SMServerConfig() = default; | ||||
84 | | ||||
80 | void SMServerConfig::initFirmwareSetup() | 85 | void SMServerConfig::initFirmwareSetup() | ||
81 | { | 86 | { | ||
82 | m_rebootNowAction = new QAction(QIcon::fromTheme(QStringLiteral("system-reboot")), i18n("Restart Now")); | 87 | m_rebootNowAction = new QAction(QIcon::fromTheme(QStringLiteral("system-reboot")), i18n("Restart Now")); | ||
83 | connect(m_rebootNowAction, &QAction::triggered, this, [this] { | 88 | connect(m_rebootNowAction, &QAction::triggered, this, [this] { | ||
84 | auto sm = new SessionManagement(this); | 89 | auto sm = new SessionManagement(this); | ||
85 | auto doShutdown=[sm]() { | 90 | auto doShutdown=[sm]() { | ||
86 | sm->requestReboot(); | 91 | sm->requestReboot(); | ||
87 | delete sm; | 92 | delete sm; | ||
88 | }; | 93 | }; | ||
89 | if (sm->state() == SessionManagement::State::Loading) { | 94 | if (sm->state() == SessionManagement::State::Loading) { | ||
90 | connect(sm, &SessionManagement::stateChanged, this, doShutdown); | 95 | connect(sm, &SessionManagement::stateChanged, this, doShutdown); | ||
91 | } else { | 96 | } else { | ||
92 | doShutdown(); | 97 | doShutdown(); | ||
93 | } | 98 | } | ||
94 | }); | 99 | }); | ||
95 | 100 | | |||
96 | connect(dialog->firmwareSetupCheck, &QCheckBox::clicked, this, [this](bool enable) { | 101 | connect(ui->firmwareSetupCheck, &QCheckBox::clicked, this, [this](bool enable) { | ||
97 | dialog->firmwareSetupMessageWidget->removeAction(m_rebootNowAction); | 102 | ui->firmwareSetupMessageWidget->removeAction(m_rebootNowAction); | ||
98 | dialog->firmwareSetupMessageWidget->animatedHide(); | 103 | ui->firmwareSetupMessageWidget->animatedHide(); | ||
99 | 104 | | |||
100 | QDBusMessage message = QDBusMessage::createMethodCall(m_login1Manager->service(), | 105 | QDBusMessage message = QDBusMessage::createMethodCall(m_login1Manager->service(), | ||
101 | m_login1Manager->path(), | 106 | m_login1Manager->path(), | ||
102 | m_login1Manager->interface(), | 107 | m_login1Manager->interface(), | ||
103 | QStringLiteral("SetRebootToFirmwareSetup")); | 108 | QStringLiteral("SetRebootToFirmwareSetup")); | ||
104 | 109 | | |||
105 | message.setArguments({enable}); | 110 | message.setArguments({enable}); | ||
106 | // This cannot be set through a generated DBus interface, so we have to create the message ourself. | 111 | // This cannot be set through a generated DBus interface, so we have to create the message ourself. | ||
107 | message.setInteractiveAuthorizationAllowed(true); | 112 | message.setInteractiveAuthorizationAllowed(true); | ||
108 | 113 | | |||
109 | QDBusPendingReply<void> call = m_login1Manager->connection().asyncCall(message); | 114 | QDBusPendingReply<void> call = m_login1Manager->connection().asyncCall(message); | ||
110 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(call, this); | 115 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(call, this); | ||
111 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this, enable](QDBusPendingCallWatcher *watcher) { | 116 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this, enable](QDBusPendingCallWatcher *watcher) { | ||
112 | QDBusPendingReply<void> reply = *watcher; | 117 | QDBusPendingReply<void> reply = *watcher; | ||
113 | watcher->deleteLater(); | 118 | watcher->deleteLater(); | ||
114 | 119 | | |||
115 | checkFirmwareSetupRequested(); | 120 | checkFirmwareSetupRequested(); | ||
116 | 121 | | |||
117 | KMessageWidget *message = dialog->firmwareSetupMessageWidget; | 122 | KMessageWidget *message = ui->firmwareSetupMessageWidget; | ||
118 | 123 | | |||
119 | if (reply.isError()) { | 124 | if (reply.isError()) { | ||
120 | // User likely canceled the PolKit prompt, don't show an error in this case | 125 | // User likely canceled the PolKit prompt, don't show an error in this case | ||
121 | if (reply.error().type() != QDBusError::AccessDenied) { | 126 | if (reply.error().type() != QDBusError::AccessDenied) { | ||
122 | message->setMessageType(KMessageWidget::Error); | 127 | message->setMessageType(KMessageWidget::Error); | ||
123 | message->setText(i18n("Failed to request restart to firmware setup: %1", reply.error().message())); | 128 | message->setText(i18n("Failed to request restart to firmware setup: %1", reply.error().message())); | ||
124 | message->animatedShow(); | 129 | message->animatedShow(); | ||
125 | } | 130 | } | ||
Show All 15 Lines | |||||
141 | }); | 146 | }); | ||
142 | }); | 147 | }); | ||
143 | 148 | | |||
144 | const QString canFirmareSetup = m_login1Manager->CanRebootToFirmwareSetup().value(); | 149 | const QString canFirmareSetup = m_login1Manager->CanRebootToFirmwareSetup().value(); | ||
145 | if (canFirmareSetup == QLatin1String("yes") || canFirmareSetup == QLatin1String("challenge")) { | 150 | if (canFirmareSetup == QLatin1String("yes") || canFirmareSetup == QLatin1String("challenge")) { | ||
146 | // now check whether we're UEFI to provide a more descriptive button label | 151 | // now check whether we're UEFI to provide a more descriptive button label | ||
147 | if (QFileInfo(QStringLiteral("/sys/firmware/efi")).isDir()) { | 152 | if (QFileInfo(QStringLiteral("/sys/firmware/efi")).isDir()) { | ||
148 | m_isUefi = true; | 153 | m_isUefi = true; | ||
149 | dialog->firmwareSetupBox->setTitle(i18n("UEFI Setup")); | 154 | ui->firmwareSetupBox->setTitle(i18n("UEFI Setup")); | ||
150 | dialog->firmwareSetupCheck->setText(i18n("Enter UEFI setup on next restart")); | 155 | ui->firmwareSetupCheck->setText(i18n("Enter UEFI setup on next restart")); | ||
151 | } | 156 | } | ||
152 | 157 | | |||
153 | dialog->firmwareSetupBox->setVisible(true); | 158 | ui->firmwareSetupBox->setVisible(true); | ||
154 | } | 159 | } | ||
155 | } | 160 | } | ||
156 | 161 | | |||
157 | void SMServerConfig::checkFirmwareSetupRequested() | 162 | void SMServerConfig::checkFirmwareSetupRequested() | ||
158 | { | 163 | { | ||
159 | dialog->firmwareSetupCheck->setChecked(m_login1Manager->property("RebootToFirmwareSetup").toBool()); | 164 | ui->firmwareSetupCheck->setChecked(m_login1Manager->property("RebootToFirmwareSetup").toBool()); | ||
160 | } | | |||
161 | | ||||
162 | void SMServerConfig::load() | | |||
163 | { | | |||
164 | KConfigGroup c(KSharedConfig::openConfig(QStringLiteral("ksmserverrc"), KConfig::NoGlobals), | | |||
165 | QStringLiteral("General")); | | |||
166 | dialog->confirmLogoutCheck->setChecked(c.readEntry("confirmLogout", true)); | | |||
167 | bool en = c.readEntry("offerShutdown", true); | | |||
168 | dialog->offerShutdownCheck->setChecked(en); | | |||
169 | dialog->sdGroup->setEnabled(en); | | |||
170 | | ||||
171 | QString s = c.readEntry( "loginMode" ); | | |||
172 | if ( s == QLatin1String("default") ) | | |||
173 | dialog->emptySessionRadio->setChecked(true); | | |||
174 | else if ( s == QLatin1String("restoreSavedSession") ) | | |||
175 | dialog->savedSessionRadio->setChecked(true); | | |||
176 | else // "restorePreviousLogout" | | |||
177 | dialog->previousSessionRadio->setChecked(true); | | |||
178 | | ||||
179 | switch (c.readEntry("shutdownType", int(KWorkSpace::ShutdownTypeNone))) { | | |||
180 | case int(KWorkSpace::ShutdownTypeHalt): | | |||
181 | dialog->haltRadio->setChecked(true); | | |||
182 | break; | | |||
183 | case int(KWorkSpace::ShutdownTypeReboot): | | |||
184 | dialog->rebootRadio->setChecked(true); | | |||
185 | break; | | |||
186 | default: | | |||
187 | dialog->logoutRadio->setChecked(true); | | |||
188 | break; | | |||
189 | } | | |||
190 | dialog->excludeLineedit->setText( c.readEntry("excludeApps")); | | |||
191 | | ||||
192 | emit changed(false); | | |||
193 | } | | |||
194 | | ||||
195 | void SMServerConfig::save() | | |||
196 | { | | |||
197 | KConfig c(QStringLiteral("ksmserverrc"), KConfig::NoGlobals); | | |||
198 | KConfigGroup group = c.group(QStringLiteral("General")); | | |||
199 | group.writeEntry( "confirmLogout", dialog->confirmLogoutCheck->isChecked()); | | |||
200 | group.writeEntry( "offerShutdown", dialog->offerShutdownCheck->isChecked()); | | |||
201 | QString s = QStringLiteral("restorePreviousLogout"); | | |||
202 | if ( dialog->emptySessionRadio->isChecked() ) | | |||
203 | s = QStringLiteral("default"); | | |||
davidedmundson: This patch renames this entry "default" to "emptySession"
From what I can tell it won't matter… | |||||
Yes, several reasons for that change: default doesn't play well as an enum value, also it wasn't the default at all... since restoring the previous session is. ervin: Yes, several reasons for that change: default doesn't play well as an enum value, also it… | |||||
204 | else if ( dialog->savedSessionRadio->isChecked() ) | | |||
205 | s = QStringLiteral("restoreSavedSession"); | | |||
206 | group.writeEntry( "loginMode", s ); | | |||
207 | | ||||
208 | group.writeEntry( "shutdownType", | | |||
209 | dialog->haltRadio->isChecked() ? | | |||
210 | int(KWorkSpace::ShutdownTypeHalt) : | | |||
211 | dialog->rebootRadio->isChecked() ? | | |||
212 | int(KWorkSpace::ShutdownTypeReboot) : | | |||
213 | int(KWorkSpace::ShutdownTypeNone)); | | |||
214 | group.writeEntry("excludeApps", dialog->excludeLineedit->text()); | | |||
215 | c.sync(); | | |||
216 | } | | |||
217 | | ||||
218 | void SMServerConfig::defaults() | | |||
219 | { | | |||
220 | dialog->previousSessionRadio->setChecked(true); | | |||
221 | dialog->confirmLogoutCheck->setChecked(true); | | |||
222 | dialog->offerShutdownCheck->setChecked(true); | | |||
223 | dialog->sdGroup->setEnabled(true); | | |||
224 | dialog->logoutRadio->setChecked(true); | | |||
225 | dialog->excludeLineedit->clear(); | | |||
226 | } | 165 | } | ||
227 | 166 | | |||
228 | #include "kcmsmserver.moc" | 167 | #include "kcmsmserver.moc" |
This patch renames this entry "default" to "emptySession"
From what I can tell it won't matter for ksmserver itself as that only compares against the other two strings.
But if a user had this value set currently then opens the KCM afterwards, which value gets loaded?