Merge lp:~robert-ancell/indicator-session/lp-1084756 into lp:indicator-session/13.04

Proposed by Robert Ancell
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 377
Merged at revision: 377
Proposed branch: lp:~robert-ancell/indicator-session/lp-1084756
Merge into: lp:indicator-session/13.04
Diff against target: 208 lines (+74/-61)
2 files modified
configure.ac (+0/-1)
src/gtk-logout-helper.c (+74/-60)
To merge this branch: bzr merge lp:~robert-ancell/indicator-session/lp-1084756
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Charles Kerr (community) Approve
Review via email: mp+137068@code.launchpad.net

Commit message

Use GDbus

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Nice work Robert!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Autolanding.
No commit message was specified.

review: Needs Fixing (continuous-integration)
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Hey Robert, can you please also remove the now uneeded build-dep in debian/control?

Revision history for this message
Sebastien Bacher (seb128) wrote :

I'm approving this one and will do a follow up merge request for the build-depends

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2012-11-16 18:13:45 +0000
3+++ configure.ac 2012-11-29 22:15:26 +0000
4@@ -46,7 +46,6 @@
5 PKG_CHECK_MODULES(SESSIONSERVICE, glib-2.0 >= $GLIB_REQUIRED_VERSION
6 dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
7 dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION
8- dbus-glib-1
9 gio-unix-2.0
10 indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION
11 packagekit-glib2)
12
13=== modified file 'src/gtk-logout-helper.c'
14--- src/gtk-logout-helper.c 2012-06-20 19:33:06 +0000
15+++ src/gtk-logout-helper.c 2012-11-29 22:15:26 +0000
16@@ -26,109 +26,123 @@
17 #include <locale.h>
18 #include <glib.h>
19 #include <glib/gi18n.h> /* textdomain(), bindtextdomain() */
20-#include <dbus/dbus-glib.h>
21 #include <gtk/gtk.h>
22 #include "dialog.h"
23 #include "shared-names.h"
24
25+static GVariant *
26+call_console_kit (const gchar *method, GVariant *parameters, GError **error)
27+{
28+ GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
29+ if (!bus)
30+ {
31+ g_variant_unref (parameters);
32+ return NULL;
33+ }
34+
35+ GVariant *result = g_dbus_connection_call_sync(bus,
36+ "org.freedesktop.ConsoleKit",
37+ "/org/freedesktop/ConsoleKit/Manager",
38+ "org.freedesktop.ConsoleKit.Manager",
39+ method,
40+ parameters,
41+ NULL,
42+ G_DBUS_CALL_FLAGS_NONE,
43+ -1,
44+ NULL,
45+ error);
46+ g_object_unref (bus);
47+
48+ return result;
49+}
50+
51 static void
52 consolekit_fallback (LogoutDialogType action)
53 {
54+ GError * error = NULL;
55+ GVariant *result = NULL;
56+
57 g_debug("Falling back to using ConsoleKit for action");
58
59- DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
60- g_return_if_fail(sbus != NULL); /* worst case */
61- DBusGProxy * proxy = dbus_g_proxy_new_for_name(sbus, "org.freedesktop.ConsoleKit",
62- "/org/freedesktop/ConsoleKit/Manager",
63- "org.freedesktop.ConsoleKit.Manager");
64-
65- if (proxy == NULL) {
66- g_warning("Unable to get consolekit proxy");
67- return;
68- }
69-
70- GError * error = NULL;
71-
72 switch (action) {
73 case LOGOUT_DIALOG_TYPE_LOG_OUT:
74 g_warning("Unable to fallback to ConsoleKit for logout as it's a session issue. We need some sort of session handler.");
75 break;
76 case LOGOUT_DIALOG_TYPE_SHUTDOWN:
77 g_debug("Telling ConsoleKit to 'Stop'");
78- dbus_g_proxy_call(proxy,
79- "Stop",
80- &error,
81- G_TYPE_INVALID,
82- G_TYPE_INVALID);
83+ result = call_console_kit ("Stop", g_variant_new ("()"), &error);
84 break;
85 case LOGOUT_DIALOG_TYPE_RESTART:
86 g_debug("Telling ConsoleKit to 'Restart'");
87- dbus_g_proxy_call(proxy,
88- "Restart",
89- &error,
90- G_TYPE_INVALID,
91- G_TYPE_INVALID);
92+ result = call_console_kit ("Restart", g_variant_new ("()"), &error);
93 break;
94 default:
95 g_warning("Unknown action");
96 break;
97 }
98
99- g_object_unref(proxy);
100+ if (!result) {
101+ if (error != NULL) {
102+ g_warning ("ConsoleKit action failed: %s", error->message);
103+ } else {
104+ g_warning ("ConsoleKit action failed: unknown error");
105+ }
106
107- if (error != NULL) {
108- g_warning("Unable to signal ConsoleKit");
109- g_error_free(error);
110+ consolekit_fallback(action);
111 }
112+ else
113+ g_variant_unref (result);
114+ g_clear_error (&error);
115
116 return;
117 }
118
119+static GVariant *
120+call_gnome_session (const gchar *method, GVariant *parameters, GError **error)
121+{
122+ GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error);
123+ if (!bus)
124+ {
125+ g_variant_unref (parameters);
126+ return NULL;
127+ }
128+
129+ GVariant *result = g_dbus_connection_call_sync(bus,
130+ "org.gnome.SessionManager",
131+ "/org/gnome/SessionManager",
132+ "org.gnome.SessionManager",
133+ method,
134+ parameters,
135+ NULL,
136+ G_DBUS_CALL_FLAGS_NONE,
137+ G_MAXINT,
138+ NULL,
139+ error);
140+ g_object_unref (bus);
141+
142+ return result;
143+}
144+
145 static void
146 session_action (LogoutDialogType action)
147 {
148- DBusGConnection * sbus;
149- DBusGProxy * sm_proxy;
150 GError * error = NULL;
151- gboolean res = FALSE;
152-
153- sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
154- if (sbus == NULL) {
155- g_warning("Unable to get DBus session bus.");
156- return;
157- }
158- sm_proxy = dbus_g_proxy_new_for_name_owner (sbus,
159- "org.gnome.SessionManager",
160- "/org/gnome/SessionManager",
161- "org.gnome.SessionManager",
162- &error);
163- if (sm_proxy == NULL) {
164- g_warning("Unable to get DBus proxy to SessionManager interface: %s", error->message);
165- g_error_free(error);
166+ GVariant *result = NULL;
167
168- consolekit_fallback(action);
169- return;
170- }
171-
172- g_clear_error (&error);
173-
174 if (action == LOGOUT_DIALOG_TYPE_LOG_OUT) {
175 g_debug("Asking Session manager to 'Logout'");
176- res = dbus_g_proxy_call_with_timeout (sm_proxy, "Logout", INT_MAX, &error,
177- G_TYPE_UINT, 1, G_TYPE_INVALID, G_TYPE_INVALID);
178+ result = call_gnome_session ("Logout", g_variant_new ("(u)", 1), &error);
179 } else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) {
180 g_debug("Asking Session manager to 'RequestShutdown'");
181- res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestShutdown", INT_MAX, &error,
182- G_TYPE_INVALID, G_TYPE_INVALID);
183+ result = call_gnome_session ("RequestShutdown", g_variant_new ("()"), &error);
184 } else if (action == LOGOUT_DIALOG_TYPE_RESTART) {
185 g_debug("Asking Session manager to 'RequestReboot'");
186- res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestReboot", INT_MAX, &error,
187- G_TYPE_INVALID, G_TYPE_INVALID);
188+ result = call_gnome_session ("RequestReboot", g_variant_new ("()"), &error);
189 } else {
190 g_warning ("Unknown session action");
191 }
192
193- if (!res) {
194+ if (!result) {
195 if (error != NULL) {
196 g_warning ("SessionManager action failed: %s", error->message);
197 } else {
198@@ -137,8 +151,8 @@
199
200 consolekit_fallback(action);
201 }
202-
203- g_object_unref(sm_proxy);
204+ else
205+ g_variant_unref (result);
206 g_clear_error (&error);
207
208 return;

Subscribers

People subscribed via source and target branches