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