1
commit df577c699c5b4b6b74c57accc664db5a16fc9b09
2
Author: Marty Jack <martyj@linux.local>
3
Date: Thu Apr 8 10:06:06 2010 -0400
5
Convert DeviceKit/Power support to UPower support and remove conditional compilation
7
diff --git a/lxsession-logout/dbus-interface.c b/lxsession-logout/dbus-interface.c
8
index f05b752..940035b 100644
9
--- a/lxsession-logout/dbus-interface.c
10
+++ b/lxsession-logout/dbus-interface.c
11
@@ -54,7 +54,7 @@ static DBusConnection * dbus_connect(void)
15
-static DBusMessage * dbus_send_message(DBusMessage * message)
16
+static DBusMessage * dbus_send_message(DBusMessage * message, char * * error_text)
18
/* Get a connection handle. */
19
DBusConnection * connection = dbus_connect();
20
@@ -68,36 +68,25 @@ static DBusMessage * dbus_send_message(DBusMessage * message)
21
dbus_message_unref(message);
24
- g_warning(G_STRLOC ": DBUS: %s", error.message);
25
+ if ((error.name == NULL) || (strcmp(error.name, DBUS_ERROR_NO_REPLY) != 0))
27
+ if (error_text != NULL)
28
+ *error_text = g_strdup(error.message);
29
+ g_warning(G_STRLOC ": DBUS: %s", error.message);
31
dbus_error_free(&error);
36
-/* Send a message with no reply expected. */
37
-static gboolean dbus_send_message_without_reply(DBusMessage * message)
39
- /* Get a connection handle. */
40
- DBusConnection * connection = dbus_connect();
41
- if (connection == NULL)
44
- /* Send the message in the blind. */
45
- dbus_bool_t status = dbus_connection_send(connection, message, NULL);
46
- dbus_message_unref(message);
48
- g_warning(G_STRLOC ": DBUS: dbus_connection_send failed\n");
52
/* Read a result for a method that returns void. */
53
-static gboolean dbus_read_result_void(DBusMessage * reply)
54
+static char * dbus_read_result_void(DBusMessage * reply)
57
dbus_message_unref(reply);
59
/* No result. Assume success. */
64
/* Read a result for a method that returns boolean. */
65
@@ -144,19 +133,21 @@ static DBusMessage * dbus_ConsoleKit_formulate_message(const char * const query)
66
static gboolean dbus_ConsoleKit_query(const char * const query)
69
- return dbus_read_result_boolean(dbus_send_message(dbus_ConsoleKit_formulate_message(query)));
70
+ return dbus_read_result_boolean(dbus_send_message(dbus_ConsoleKit_formulate_message(query), NULL));
76
/* Send a specified message to the ConsoleKit interface and process a void result. */
77
-static gboolean dbus_ConsoleKit_command(const char * const command)
78
+static char * dbus_ConsoleKit_command(const char * const command)
81
- return dbus_read_result_void(dbus_send_message(dbus_ConsoleKit_formulate_message(command)));
82
+ char * error = NULL;
83
+ dbus_read_result_void(dbus_send_message(dbus_ConsoleKit_formulate_message(command), &error));
91
@@ -173,49 +164,49 @@ gboolean dbus_ConsoleKit_CanRestart(void)
94
/* Invoke the Stop method on ConsoleKit. */
95
-gboolean dbus_ConsoleKit_Stop(void)
96
+char * dbus_ConsoleKit_Stop(void)
98
return dbus_ConsoleKit_command("Stop");
101
/* Invoke the Restart method on ConsoleKit. */
102
-gboolean dbus_ConsoleKit_Restart(void)
103
+char * dbus_ConsoleKit_Restart(void)
105
return dbus_ConsoleKit_command("Restart");
108
-/*** DeviceKit Power mechanism ***/
109
+/*** UPower mechanism ***/
112
-/* Formulate a message to the DeviceKit Power interface. */
113
-static DBusMessage * dbus_DeviceKit_formulate_command(const char * const command)
114
+/* Formulate a message to the UPower interface. */
115
+static DBusMessage * dbus_UPower_formulate_command(const char * const command)
117
return dbus_message_new_method_call(
118
- "org.freedesktop.DeviceKit.Power",
119
- "/org/freedesktop/DeviceKit/Power",
120
- "org.freedesktop.DeviceKit.Power",
121
+ "org.freedesktop.UPower",
122
+ "/org/freedesktop/UPower",
123
+ "org.freedesktop.UPower",
128
-/* Send a specified message to the DeviceKit interface and process a boolean result. */
129
-static gboolean dbus_DeviceKit_query(const char * const query)
130
+/* Send a specified message to the UPower interface and process a boolean result. */
131
+static gboolean dbus_UPower_query(const char * const query)
134
/* Formulate a message to the Properties interface. */
135
DBusMessage * message = dbus_message_new_method_call(
136
- "org.freedesktop.DeviceKit.Power",
137
- "/org/freedesktop/DeviceKit/Power",
138
+ "org.freedesktop.UPower",
139
+ "/org/freedesktop/UPower",
140
"org.freedesktop.DBus.Properties",
142
- const char * const interface_name = "org.freedesktop.DeviceKit.Power";
143
+ const char * const interface_name = "org.freedesktop.UPower";
144
dbus_message_append_args(message,
145
DBUS_TYPE_STRING, &interface_name,
146
DBUS_TYPE_STRING, &query,
149
/* Send the message. */
150
- DBusMessage * reply = dbus_send_message(message);
151
+ DBusMessage * reply = dbus_send_message(message, NULL);
155
@@ -237,39 +228,40 @@ static gboolean dbus_DeviceKit_query(const char * const query)
159
-/* Send a specified message to the DeviceKit interface and process a void result. */
160
-static gboolean dbus_DeviceKit_command(const char * const command)
161
+/* Send a specified message to the UPower interface and process a void result. */
162
+static char * dbus_UPower_command(const char * const command)
165
- return dbus_read_result_void(dbus_send_message(dbus_DeviceKit_formulate_command(command)));
166
-// return dbus_send_message_without_reply(dbus_DeviceKit_formulate_command(command)); It seems they don't send a reply; to be checked out
167
+ char * error = NULL;
168
+ dbus_read_result_void(dbus_send_message(dbus_UPower_formulate_command(command), &error));
176
-/* Read the can-suspend property of DeviceKit/Power. */
177
-gboolean dbus_DeviceKit_CanSuspend(void)
178
+/* Read the can-suspend property of UPower. */
179
+gboolean dbus_UPower_CanSuspend(void)
181
- return dbus_DeviceKit_query("CanSuspend");
182
+ return dbus_UPower_query("CanSuspend");
185
-/* Read the can-hibernate property of DeviceKit/Power. */
186
-gboolean dbus_DeviceKit_CanHibernate(void)
187
+/* Read the can-hibernate property of UPower. */
188
+gboolean dbus_UPower_CanHibernate(void)
190
- return dbus_DeviceKit_query("CanHibernate");
191
+ return dbus_UPower_query("CanHibernate");
194
-/* Invoke the Suspend method on DeviceKit/Power. */
195
-gboolean dbus_DeviceKit_Suspend(void)
196
+/* Invoke the Suspend method on UPower. */
197
+char * dbus_UPower_Suspend(void)
199
- return dbus_DeviceKit_command("Suspend");
200
+ return dbus_UPower_command("Suspend");
203
-/* Invoke the Hibernate method on DeviceKit/Power. */
204
-gboolean dbus_DeviceKit_Hibernate(void)
205
+/* Invoke the Hibernate method on UPower. */
206
+char * dbus_UPower_Hibernate(void)
208
- return dbus_DeviceKit_command("Hibernate");
209
+ return dbus_UPower_command("Hibernate");
212
/*** HAL mechanism ***/
213
@@ -318,7 +310,7 @@ static gboolean dbus_HAL_string_exists_query(const char * const property)
214
DBusMessage * message = dbus_HAL_formulate_string_property_query(property);
217
- DBusMessage * reply = dbus_send_message(message);
218
+ DBusMessage * reply = dbus_send_message(message, NULL);
221
dbus_message_unref(reply);
222
@@ -332,20 +324,20 @@ static gboolean dbus_HAL_string_exists_query(const char * const property)
223
static gboolean dbus_HAL_boolean_query(const char * const property)
226
- return dbus_read_result_boolean(dbus_send_message(dbus_HAL_formulate_boolean_property_query(property)));
227
+ return dbus_read_result_boolean(dbus_send_message(dbus_HAL_formulate_boolean_property_query(property), NULL));
233
/* Send a specified message to the HAL interface and process a void result. */
234
-static gboolean dbus_HAL_command(const char * const command)
235
+static char * dbus_HAL_command(const char * const command)
238
/* Formulate the message. */
239
DBusMessage * message = dbus_HAL_formulate_message(command);
244
/* Suspend has an argument. */
245
if (strcmp(command, "Suspend") == 0)
246
@@ -355,9 +347,11 @@ static gboolean dbus_HAL_command(const char * const command)
249
/* Send the message and wait for a reply. */
250
- return dbus_read_result_void(dbus_send_message(message));
251
+ char * error = NULL;
252
+ dbus_read_result_void(dbus_send_message(message, &error));
260
@@ -386,25 +380,25 @@ gboolean dbus_HAL_CanHibernate(void)
263
/* Invoke the Shutdown method on HAL. */
264
-gboolean dbus_HAL_Shutdown(void)
265
+char * dbus_HAL_Shutdown(void)
267
return dbus_HAL_command("Shutdown");
270
/* Invoke the Reboot method on HAL. */
271
-gboolean dbus_HAL_Reboot(void)
272
+char * dbus_HAL_Reboot(void)
274
return dbus_HAL_command("Reboot");
277
/* Invoke the Suspend method on HAL. */
278
-gboolean dbus_HAL_Suspend(void)
279
+char * dbus_HAL_Suspend(void)
281
return dbus_HAL_command("Suspend");
284
/* Invoke the Hibernate method on HAL. */
285
-gboolean dbus_HAL_Hibernate(void)
286
+char * dbus_HAL_Hibernate(void)
288
return dbus_HAL_command("Hibernate");
290
diff --git a/lxsession-logout/dbus-interface.h b/lxsession-logout/dbus-interface.h
291
index 465d15a..4ea2d5b 100644
292
--- a/lxsession-logout/dbus-interface.h
293
+++ b/lxsession-logout/dbus-interface.h
295
/* Interface to ConsoleKit for shutdown and reboot. */
296
extern gboolean dbus_ConsoleKit_CanStop(void);
297
extern gboolean dbus_ConsoleKit_CanRestart(void);
298
-extern gboolean dbus_ConsoleKit_Stop(void);
299
-extern gboolean dbus_ConsoleKit_Restart(void);
300
+extern char * dbus_ConsoleKit_Stop(void);
301
+extern char * dbus_ConsoleKit_Restart(void);
303
-/* Interface to DeviceKit/Power for suspend and hibernate. */
304
-extern gboolean dbus_DeviceKit_CanSuspend(void);
305
-extern gboolean dbus_DeviceKit_CanHibernate(void);
306
-extern gboolean dbus_DeviceKit_Suspend(void);
307
-extern gboolean dbus_DeviceKit_Hibernate(void);
308
+/* Interface to UPower for suspend and hibernate. */
309
+extern gboolean dbus_UPower_CanSuspend(void);
310
+extern gboolean dbus_UPower_CanHibernate(void);
311
+extern char * dbus_UPower_Suspend(void);
312
+extern char * dbus_UPower_Hibernate(void);
314
/* Interface to HAL for shutdown, reboot, suspend, and hibernate.
315
* HAL is being replaced by the above two mechanisms; this support is legacy. */
316
@@ -39,9 +39,9 @@ extern gboolean dbus_HAL_CanShutdown(void);
317
extern gboolean dbus_HAL_CanReboot(void);
318
extern gboolean dbus_HAL_CanSuspend(void);
319
extern gboolean dbus_HAL_CanHibernate(void);
320
-gboolean dbus_HAL_Shutdown(void);
321
-gboolean dbus_HAL_Reboot(void);
322
-gboolean dbus_HAL_Suspend(void);
323
-gboolean dbus_HAL_Hibernate(void);
324
+extern char * dbus_HAL_Shutdown(void);
325
+extern char * dbus_HAL_Reboot(void);
326
+extern char * dbus_HAL_Suspend(void);
327
+extern char * dbus_HAL_Hibernate(void);
330
diff --git a/lxsession-logout/lxsession-logout.c b/lxsession-logout/lxsession-logout.c
331
index a4183fc..435216c 100644
332
--- a/lxsession-logout/lxsession-logout.c
333
+++ b/lxsession-logout/lxsession-logout.c
334
@@ -52,6 +52,7 @@ static GOptionEntry opt_entries[] =
337
GPid lxsession_pid; /* Process ID of lxsession */
338
+ GtkWidget * error_label; /* Text of an error, if we get one */
340
int shutdown_available : 1; /* Shutdown is available */
341
int reboot_available : 1; /* Reboot is available */
342
@@ -61,19 +62,20 @@ typedef struct {
344
int shutdown_ConsoleKit : 1; /* Shutdown is available via ConsoleKit */
345
int reboot_ConsoleKit : 1; /* Reboot is available via ConsoleKit */
346
- int suspend_DeviceKit : 1; /* Suspend is available via DeviceKit */
347
- int hibernate_DeviceKit : 1; /* Hibernate is available via DeviceKit */
348
+ int suspend_UPower : 1; /* Suspend is available via UPower */
349
+ int hibernate_UPower : 1; /* Hibernate is available via UPower */
350
int shutdown_HAL : 1; /* Shutdown is available via HAL */
351
int reboot_HAL : 1; /* Reboot is available via HAL */
352
int suspend_HAL : 1; /* Suspend is available via HAL */
353
int hibernate_HAL : 1; /* Hibernate is available via HAL */
354
int switch_user_GDM : 1; /* Switch User is available via GDM */
355
int switch_user_KDM : 1; /* Switch User is available via KDM */
356
- int ltsp : 1; /* under LTSP environment */
357
+ int ltsp : 1; /* Shutdown and reboot is accomplished via LTSP */
360
static gboolean verify_running(char * display_manager, char * executable);
361
static void logout_clicked(GtkButton * button, HandlerContext * handler_context);
362
+static void change_root_property(GtkWidget* w, const char* prop_name, const char* value);
363
static void shutdown_clicked(GtkButton * button, HandlerContext * handler_context);
364
static void reboot_clicked(GtkButton * button, HandlerContext * handler_context);
365
static void suspend_clicked(GtkButton * button, HandlerContext * handler_context);
366
@@ -145,6 +147,7 @@ static void logout_clicked(GtkButton * button, HandlerContext * handler_context)
370
+/* Replace a property on the root window. */
371
static void change_root_property(GtkWidget* w, const char* prop_name, const char* value)
373
GdkDisplay* dpy = gtk_widget_get_display(w);
374
@@ -157,56 +160,82 @@ static void change_root_property(GtkWidget* w, const char* prop_name, const char
375
/* Handler for "clicked" signal on Shutdown button. */
376
static void shutdown_clicked(GtkButton * button, HandlerContext * handler_context)
378
- if (G_UNLIKELY(handler_context->ltsp))
379
+ char * error_result = NULL;
380
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
382
+ if (handler_context->ltsp)
384
change_root_property(GTK_WIDGET(button), "LTSP_LOGOUT_ACTION", "HALT");
385
kill(handler_context->lxsession_pid, SIGTERM);
387
else if (handler_context->shutdown_ConsoleKit)
388
- dbus_ConsoleKit_Stop();
389
+ error_result = dbus_ConsoleKit_Stop();
390
else if (handler_context->shutdown_HAL)
391
- dbus_HAL_Shutdown();
393
+ error_result = dbus_HAL_Shutdown();
395
+ if (error_result != NULL)
396
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
397
+ else gtk_main_quit();
400
/* Handler for "clicked" signal on Reboot button. */
401
static void reboot_clicked(GtkButton * button, HandlerContext * handler_context)
403
- if (G_UNLIKELY(handler_context->ltsp))
404
+ char * error_result = NULL;
405
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
407
+ if (handler_context->ltsp)
409
change_root_property(GTK_WIDGET(button), "LTSP_LOGOUT_ACTION", "REBOOT");
410
kill(handler_context->lxsession_pid, SIGTERM);
412
else if (handler_context->reboot_ConsoleKit)
413
- dbus_ConsoleKit_Restart();
414
+ error_result = dbus_ConsoleKit_Restart();
415
else if (handler_context->reboot_HAL)
418
+ error_result = dbus_HAL_Reboot();
420
+ if (error_result != NULL)
421
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
422
+ else gtk_main_quit();
425
/* Handler for "clicked" signal on Suspend button. */
426
static void suspend_clicked(GtkButton * button, HandlerContext * handler_context)
428
- if (handler_context->suspend_DeviceKit)
429
- dbus_DeviceKit_Suspend();
430
+ char * error_result = NULL;
431
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
433
+ if (handler_context->suspend_UPower)
434
+ error_result = dbus_UPower_Suspend();
435
else if (handler_context->suspend_HAL)
436
- dbus_HAL_Suspend();
438
+ error_result = dbus_HAL_Suspend();
440
+ if (error_result != NULL)
441
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
442
+ else gtk_main_quit();
445
/* Handler for "clicked" signal on Hibernate button. */
446
static void hibernate_clicked(GtkButton * button, HandlerContext * handler_context)
448
- if (handler_context->hibernate_DeviceKit)
449
- dbus_DeviceKit_Hibernate();
450
+ char * error_result = NULL;
451
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
453
+ if (handler_context->hibernate_UPower)
454
+ error_result = dbus_UPower_Hibernate();
455
else if (handler_context->hibernate_HAL)
456
- dbus_HAL_Hibernate();
458
+ error_result = dbus_HAL_Hibernate();
460
+ if (error_result != NULL)
461
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
462
+ else gtk_main_quit();
465
/* Handler for "clicked" signal on Switch User button. */
466
static void switch_user_clicked(GtkButton * button, HandlerContext * handler_context)
468
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
470
if (handler_context->switch_user_GDM)
471
g_spawn_command_line_sync("gdmflexiserver --startnew", NULL, NULL, NULL, NULL);
472
else if (handler_context->switch_user_KDM)
473
@@ -341,19 +370,17 @@ int main(int argc, char * argv[])
474
handler_context.reboot_ConsoleKit = TRUE;
477
-#ifdef LATENT_DEVICEKIT_SUPPORT
478
- /* Initialize capabilities of the DeviceKit mechanism. */
479
- if (dbus_DeviceKit_CanSuspend())
480
+ /* Initialize capabilities of the UPower mechanism. */
481
+ if (dbus_UPower_CanSuspend())
483
handler_context.suspend_available = TRUE;
484
- handler_context.suspend_DeviceKit = TRUE;
485
+ handler_context.suspend_UPower = TRUE;
487
- if (dbus_DeviceKit_CanHibernate())
488
+ if (dbus_UPower_CanHibernate())
490
handler_context.hibernate_available = TRUE;
491
- handler_context.hibernate_DeviceKit = TRUE;
492
+ handler_context.hibernate_UPower = TRUE;
496
/* Initialize capabilities of the HAL mechanism. */
497
if (!handler_context.shutdown_available && dbus_HAL_CanShutdown())
498
@@ -552,6 +579,11 @@ int main(int argc, char * argv[])
499
g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(cancel_clicked), NULL);
500
gtk_box_pack_start(GTK_BOX(controls), cancel_button, FALSE, FALSE, 4);
502
+ /* Create the error text. */
503
+ handler_context.error_label = gtk_label_new("");
504
+ gtk_label_set_justify(GTK_LABEL(handler_context.error_label), GTK_JUSTIFY_CENTER);
505
+ gtk_box_pack_start(GTK_BOX(controls), handler_context.error_label, FALSE, FALSE, 4);
507
/* Show everything. */
508
gtk_widget_show_all(window);