Changeset View
Changeset View
Standalone View
Standalone View
kcms/ksmserver/kcmsmserver.cpp
Show All 13 Lines | |||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. | ||
17 | * | 17 | * | ||
18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | 19 | * along with this program; if not, write to the Free Software | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include <QDBusConnection> | ||||
23 | #include <QDBusPendingCallWatcher> | ||||
24 | #include <QDBusPendingReply> | ||||
22 | #include <QCheckBox> | 25 | #include <QCheckBox> | ||
26 | #include <QFileInfo> | ||||
23 | //Added by qt3to4: | 27 | //Added by qt3to4: | ||
24 | #include <QVBoxLayout> | 28 | #include <QVBoxLayout> | ||
25 | 29 | | |||
26 | | ||||
27 | #include <kconfig.h> | 30 | #include <kconfig.h> | ||
28 | #include <kconfiggroup.h> | 31 | #include <kconfiggroup.h> | ||
29 | #include <ksharedconfig.h> | 32 | #include <ksharedconfig.h> | ||
30 | #include <kworkspace.h> | 33 | #include <kworkspace.h> | ||
31 | #include <qregexp.h> | 34 | #include <qregexp.h> | ||
32 | #include <kdesktopfile.h> | 35 | #include <kdesktopfile.h> | ||
33 | #include <kprocess.h> | 36 | #include <kprocess.h> | ||
34 | #include <kmessagebox.h> | 37 | #include <kmessagebox.h> | ||
35 | #include <QApplication> | 38 | #include <QApplication> | ||
36 | #include <QDBusInterface> | 39 | #include <QDBusInterface> | ||
37 | #include <QLineEdit> | 40 | #include <QLineEdit> | ||
38 | 41 | | |||
39 | #include "kcmsmserver.h" | 42 | #include "kcmsmserver.h" | ||
40 | #include "smserverconfigimpl.h" | 43 | #include "smserverconfigimpl.h" | ||
41 | #include <KPluginFactory> | 44 | #include <KPluginFactory> | ||
42 | #include <KPluginLoader> | 45 | #include <KPluginLoader> | ||
43 | #include <KLocalizedString> | 46 | #include <KLocalizedString> | ||
44 | 47 | | |||
45 | K_PLUGIN_FACTORY(SMSFactory, registerPlugin<SMServerConfig>();) | 48 | K_PLUGIN_FACTORY(SMSFactory, registerPlugin<SMServerConfig>();) | ||
46 | 49 | | |||
50 | static const QString s_login1Service = QStringLiteral("org.freedesktop.login1"); | ||||
51 | static const QString s_login1Path = QStringLiteral("/org/freedesktop/login1"); | ||||
52 | static const QString s_dbusPropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); | ||||
53 | static const QString s_login1ManagerInterface = QStringLiteral("org.freedesktop.login1.Manager"); | ||||
54 | static const QString s_login1RebootToFirmwareSetup = QStringLiteral("RebootToFirmwareSetup"); | ||||
55 | static const QString s_login1CanRebootToFirmwareSetup = QStringLiteral("CanRebootToFirmwareSetup"); | ||||
56 | static const QString s_login1SetRebootToFirmwareSetup = QStringLiteral("SetRebootToFirmwareSetup"); | ||||
57 | | ||||
47 | SMServerConfig::SMServerConfig(QWidget *parent, const QVariantList &args) | 58 | SMServerConfig::SMServerConfig(QWidget *parent, const QVariantList &args) | ||
48 | : KCModule(parent, args) | 59 | : KCModule(parent, args) | ||
49 | { | 60 | { | ||
50 | setQuickHelp( i18n("<h1>Session Manager</h1>" | 61 | setQuickHelp( i18n("<h1>Session Manager</h1>" | ||
51 | " You can configure the session manager here." | 62 | " You can configure the session manager here." | ||
52 | " This includes options such as whether or not the session exit (logout)" | 63 | " This includes options such as whether or not the session exit (logout)" | ||
53 | " should be confirmed, whether the session should be restored again when logging in" | 64 | " should be confirmed, whether the session should be restored again when logging in" | ||
54 | " and whether the computer should be automatically shut down after session" | 65 | " and whether the computer should be automatically shut down after session" | ||
55 | " exit by default.")); | 66 | " exit by default.")); | ||
56 | 67 | | |||
57 | QVBoxLayout *topLayout = new QVBoxLayout(this); | 68 | QVBoxLayout *topLayout = new QVBoxLayout(this); | ||
58 | topLayout->setContentsMargins(0, 0, 0, 0); | 69 | topLayout->setContentsMargins(0, 0, 0, 0); | ||
59 | dialog = new SMServerConfigImpl(this); | 70 | dialog = new SMServerConfigImpl(this); | ||
60 | connect(dialog, SIGNAL(changed()), SLOT(changed())); | 71 | connect(dialog, SIGNAL(changed()), SLOT(changed())); | ||
61 | 72 | | |||
73 | initFirmwareSetup(); | ||||
sitter: possibly should be up in the member initializer list? | |||||
74 | checkFirmwareSetupRequested(); | ||||
75 | | ||||
62 | topLayout->addWidget(dialog); | 76 | topLayout->addWidget(dialog); | ||
63 | } | 77 | } | ||
64 | 78 | | |||
79 | void SMServerConfig::initFirmwareSetup() | ||||
80 | { | ||||
81 | connect(dialog, &SMServerConfigImpl::firmwareSetupRequested, this, [this](bool enable) { | ||||
82 | dialog->hideFirmwareSetupMessage(); | ||||
83 | | ||||
84 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | ||||
85 | s_login1Path, | ||||
86 | s_login1ManagerInterface, | ||||
87 | s_login1SetRebootToFirmwareSetup); | ||||
88 | message.setArguments({enable}); | ||||
89 | message.setInteractiveAuthorizationAllowed(true); | ||||
90 | | ||||
91 | QDBusPendingReply<void> call = QDBusConnection::systemBus().asyncCall(message); | ||||
92 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(call, this); | ||||
93 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this, enable](QDBusPendingCallWatcher *watcher) { | ||||
94 | QDBusPendingReply<void> reply = *watcher; | ||||
95 | watcher->deleteLater(); | ||||
96 | | ||||
97 | checkFirmwareSetupRequested(); | ||||
98 | | ||||
99 | if (reply.isError()) { | ||||
100 | // User likely canceled the PolKit prompt, don't show an error in this case | ||||
101 | if (reply.error().type() != QDBusError::AccessDenied) { | ||||
102 | dialog->showFirmwareSetupMessage(KMessageWidget::Error, | ||||
103 | i18n("Failed to request restart to firmware setup: %1", reply.error().message())); | ||||
104 | } | ||||
105 | return; | ||||
106 | } | ||||
107 | | ||||
108 | if (enable) { | ||||
109 | if (m_isUefi) { | ||||
110 | dialog->showFirmwareSetupMessage(KMessageWidget::Information, | ||||
111 | i18n("Next time the computer is restarted, it will enter the UEFI setup screen.")); | ||||
112 | } else { | ||||
113 | dialog->showFirmwareSetupMessage(KMessageWidget::Information, | ||||
114 | i18n("Next time the computer is restarted, it will enter the firmware setup screen.")); | ||||
115 | } | ||||
sitter: Perhaps reduce the nesting by returning early `if (!enable) { return; }`? | |||||
116 | } | ||||
117 | }); | ||||
118 | }); | ||||
119 | | ||||
120 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | ||||
121 | s_login1Path, | ||||
122 | s_login1ManagerInterface, | ||||
123 | s_login1CanRebootToFirmwareSetup); | ||||
124 | QDBusPendingReply<QString> call = QDBusConnection::systemBus().asyncCall(message); | ||||
125 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(call, this); | ||||
126 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { | ||||
127 | QDBusPendingReply<QString> reply = *watcher; | ||||
128 | watcher->deleteLater(); | ||||
129 | | ||||
130 | const bool canFirmwareSetup = (reply.value() == QLatin1String("yes") | ||||
131 | || reply.value() == QLatin1String("challenge")); | ||||
132 | | ||||
133 | if (!canFirmwareSetup) { | ||||
134 | return; | ||||
135 | } | ||||
136 | | ||||
137 | // now check whether we're UEFI to provide a more descriptive button label | ||||
138 | if (QFileInfo(QStringLiteral("/sys/firmware/efi")).isDir()) { | ||||
139 | m_isUefi = true; | ||||
140 | dialog->setFirmwareSetupTitle(i18n("UEFI Setup")); | ||||
141 | dialog->setFirmwareSetupLabel(i18n("Enter UEFI setup on next restart")); | ||||
142 | } | ||||
143 | | ||||
144 | dialog->setFirmwareSetupSupported(canFirmwareSetup); | ||||
145 | }); | ||||
146 | } | ||||
147 | | ||||
148 | void SMServerConfig::checkFirmwareSetupRequested() | ||||
149 | { | ||||
150 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | ||||
151 | s_login1Path, | ||||
152 | s_dbusPropertiesInterface, | ||||
153 | QStringLiteral("Get")); | ||||
154 | message.setArguments({s_login1ManagerInterface, s_login1RebootToFirmwareSetup}); | ||||
155 | | ||||
156 | QDBusPendingReply<QVariant> call = QDBusConnection::systemBus().asyncCall(message); | ||||
157 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(call, this); | ||||
158 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { | ||||
159 | QDBusPendingReply<QVariant> reply = *watcher; | ||||
160 | watcher->deleteLater(); | ||||
161 | | ||||
162 | if (reply.value().isValid()) { | ||||
163 | dialog->setFirmwareSetupChecked(reply.value().toBool()); | ||||
164 | } | ||||
165 | }); | ||||
166 | } | ||||
167 | | ||||
65 | void SMServerConfig::load() | 168 | void SMServerConfig::load() | ||
66 | { | 169 | { | ||
67 | KConfigGroup c(KSharedConfig::openConfig(QStringLiteral("ksmserverrc"), KConfig::NoGlobals), | 170 | KConfigGroup c(KSharedConfig::openConfig(QStringLiteral("ksmserverrc"), KConfig::NoGlobals), | ||
68 | QStringLiteral("General")); | 171 | QStringLiteral("General")); | ||
69 | dialog->confirmLogoutCheck->setChecked(c.readEntry("confirmLogout", true)); | 172 | dialog->confirmLogoutCheck->setChecked(c.readEntry("confirmLogout", true)); | ||
70 | bool en = c.readEntry("offerShutdown", true); | 173 | bool en = c.readEntry("offerShutdown", true); | ||
71 | dialog->offerShutdownCheck->setChecked(en); | 174 | dialog->offerShutdownCheck->setChecked(en); | ||
72 | dialog->sdGroup->setEnabled(en); | 175 | dialog->sdGroup->setEnabled(en); | ||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |
possibly should be up in the member initializer list?