Lines 37-42
Link Here
|
37 |
#include <kimageeffect.h> |
37 |
#include <kimageeffect.h> |
38 |
#include <kdialog.h> |
38 |
#include <kdialog.h> |
39 |
#include <kseparator.h> |
39 |
#include <kseparator.h> |
|
|
40 |
#include <kconfig.h> |
41 |
|
42 |
#include <dcopclient.h> |
43 |
#include <dcopref.h> |
40 |
|
44 |
|
41 |
#include <sys/types.h> |
45 |
#include <sys/types.h> |
42 |
#include <sys/utsname.h> |
46 |
#include <sys/utsname.h> |
Lines 130-135
Link Here
|
130 |
buttonlay->addWidget( btnLogout ); |
134 |
buttonlay->addWidget( btnLogout ); |
131 |
connect(btnLogout, SIGNAL(clicked()), SLOT(slotLogout())); |
135 |
connect(btnLogout, SIGNAL(clicked()), SLOT(slotLogout())); |
132 |
|
136 |
|
|
|
137 |
m_halCtx = NULL; |
138 |
|
133 |
if (maysd) { |
139 |
if (maysd) { |
134 |
|
140 |
|
135 |
// Shutdown |
141 |
// Shutdown |
Lines 167-172
Link Here
|
167 |
btnReboot->setPopup(targets); |
173 |
btnReboot->setPopup(targets); |
168 |
connect( targets, SIGNAL(activated(int)), SLOT(slotReboot(int)) ); |
174 |
connect( targets, SIGNAL(activated(int)), SLOT(slotReboot(int)) ); |
169 |
} |
175 |
} |
|
|
176 |
|
177 |
// respect lock on resume & disable suspend/hibernate settings |
178 |
// from power-manager |
179 |
KConfig config("power-managerrc"); |
180 |
bool disableSuspend = config.readBoolEntry("disableSuspend", false); |
181 |
bool disableHibernate = config.readBoolEntry("disableHibernate", false); |
182 |
m_lockOnResume = config.readBoolEntry("lockOnResume", true); |
183 |
|
184 |
bool canSuspend = false; |
185 |
bool canHibernate = false; |
186 |
|
187 |
// Query HAL for suspend/resume support |
188 |
m_halCtx = libhal_ctx_new(); |
189 |
|
190 |
DBusError error; |
191 |
dbus_error_init(&error); |
192 |
m_dbusConn = dbus_connection_open_private(DBUS_SYSTEM_BUS, &error); |
193 |
if (!m_dbusConn) |
194 |
{ |
195 |
dbus_error_free(&error); |
196 |
libhal_ctx_free(m_halCtx); |
197 |
m_halCtx = NULL; |
198 |
} |
199 |
else |
200 |
{ |
201 |
dbus_bus_register(m_dbusConn, &error); |
202 |
if (dbus_error_is_set(&error)) |
203 |
{ |
204 |
dbus_error_free(&error); |
205 |
libhal_ctx_free(m_halCtx); |
206 |
m_dbusConn = NULL; |
207 |
m_halCtx = NULL; |
208 |
} |
209 |
else |
210 |
{ |
211 |
libhal_ctx_set_dbus_connection(m_halCtx, m_dbusConn); |
212 |
if (!libhal_ctx_init(m_halCtx, &error)) |
213 |
{ |
214 |
if (dbus_error_is_set(&error)) |
215 |
dbus_error_free(&error); |
216 |
libhal_ctx_free(m_halCtx); |
217 |
m_dbusConn = NULL; |
218 |
m_halCtx = NULL; |
219 |
} |
220 |
} |
221 |
} |
222 |
|
223 |
if (m_halCtx) |
224 |
{ |
225 |
if (libhal_device_get_property_bool(m_halCtx, |
226 |
"/org/freedesktop/Hal/devices/computer", |
227 |
"power_management.can_suspend", |
228 |
NULL)) |
229 |
{ |
230 |
canSuspend = true; |
231 |
} |
232 |
|
233 |
if (libhal_device_get_property_bool(m_halCtx, |
234 |
"/org/freedesktop/Hal/devices/computer", |
235 |
"power_management.can_hibernate", |
236 |
NULL)) |
237 |
{ |
238 |
canHibernate = true; |
239 |
} |
240 |
} |
241 |
|
242 |
if (canSuspend && !disableSuspend) |
243 |
{ |
244 |
KPushButton* btnSuspend = new KPushButton( KGuiItem( i18n("&Suspend Computer"), "suspend"), frame ); |
245 |
btnSuspend->setFont( btnFont ); |
246 |
buttonlay->addWidget( btnSuspend ); |
247 |
connect(btnSuspend, SIGNAL(clicked()), SLOT(slotSuspend())); |
248 |
} |
249 |
|
250 |
if (canHibernate && !disableHibernate) |
251 |
{ |
252 |
KPushButton* btnHibernate = new KPushButton( KGuiItem( i18n("&Hibernate Computer"), "hibernate"), frame ); |
253 |
btnHibernate->setFont( btnFont ); |
254 |
buttonlay->addWidget( btnHibernate ); |
255 |
connect(btnHibernate, SIGNAL(clicked()), SLOT(slotHibernate())); |
256 |
} |
170 |
} |
257 |
} |
171 |
|
258 |
|
172 |
buttonlay->addStretch( 1 ); |
259 |
buttonlay->addStretch( 1 ); |
Lines 181-186
Link Here
|
181 |
|
268 |
|
182 |
} |
269 |
} |
183 |
|
270 |
|
|
|
271 |
KSMShutdownDlg::~KSMShutdownDlg() |
272 |
{ |
273 |
if (m_halCtx) |
274 |
{ |
275 |
DBusError error; |
276 |
dbus_error_init(&error); |
277 |
libhal_ctx_shutdown(m_halCtx, &error); |
278 |
libhal_ctx_free(m_halCtx); |
279 |
} |
280 |
} |
281 |
|
184 |
|
282 |
|
185 |
void KSMShutdownDlg::slotLogout() |
283 |
void KSMShutdownDlg::slotLogout() |
186 |
{ |
284 |
{ |
Lines 213-218
Link Here
|
213 |
accept(); |
311 |
accept(); |
214 |
} |
312 |
} |
215 |
|
313 |
|
|
|
314 |
void KSMShutdownDlg::slotSuspend() |
315 |
{ |
316 |
if (m_lockOnResume) { |
317 |
DCOPRef("kdesktop", "KScreensaverIface").send("lock"); |
318 |
} |
319 |
|
320 |
if (m_dbusConn) |
321 |
{ |
322 |
DBusMessage *msg = dbus_message_new_method_call( |
323 |
"org.freedesktop.Hal", |
324 |
"/org/freedesktop/Hal/devices/computer", |
325 |
"org.freedesktop.Hal.Device.SystemPowerManagement", |
326 |
"Suspend"); |
327 |
|
328 |
int wakeup=0; |
329 |
dbus_message_append_args(msg, DBUS_TYPE_INT32, &wakeup, DBUS_TYPE_INVALID); |
330 |
|
331 |
dbus_connection_send(m_dbusConn, msg, NULL); |
332 |
|
333 |
dbus_message_unref(msg); |
334 |
} |
335 |
|
336 |
reject(); // continue on resume |
337 |
} |
338 |
|
339 |
void KSMShutdownDlg::slotHibernate() |
340 |
{ |
341 |
if (m_lockOnResume) { |
342 |
DCOPRef("kdesktop", "KScreensaverIface").send("lock"); |
343 |
} |
344 |
|
345 |
if (m_dbusConn) |
346 |
{ |
347 |
DBusMessage *msg = dbus_message_new_method_call( |
348 |
"org.freedesktop.Hal", |
349 |
"/org/freedesktop/Hal/devices/computer", |
350 |
"org.freedesktop.Hal.Device.SystemPowerManagement", |
351 |
"Hibernate"); |
352 |
|
353 |
dbus_connection_send(m_dbusConn, msg, NULL); |
354 |
|
355 |
dbus_message_unref(msg); |
356 |
} |
357 |
|
358 |
reject(); // continue on resume |
359 |
} |
216 |
|
360 |
|
217 |
bool KSMShutdownDlg::confirmShutdown( bool maysd, KApplication::ShutdownType& sdtype, QString& bootOption ) |
361 |
bool KSMShutdownDlg::confirmShutdown( bool maysd, KApplication::ShutdownType& sdtype, QString& bootOption ) |
218 |
{ |
362 |
{ |