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
=== modified file 'configure.ac'
--- configure.ac 2012-11-16 18:13:45 +0000
+++ configure.ac 2012-11-29 22:15:26 +0000
@@ -46,7 +46,6 @@
46PKG_CHECK_MODULES(SESSIONSERVICE, glib-2.0 >= $GLIB_REQUIRED_VERSION46PKG_CHECK_MODULES(SESSIONSERVICE, glib-2.0 >= $GLIB_REQUIRED_VERSION
47 dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION47 dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
48 dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION48 dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION
49 dbus-glib-1
50 gio-unix-2.049 gio-unix-2.0
51 indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION50 indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION
52 packagekit-glib2)51 packagekit-glib2)
5352
=== modified file 'src/gtk-logout-helper.c'
--- src/gtk-logout-helper.c 2012-06-20 19:33:06 +0000
+++ src/gtk-logout-helper.c 2012-11-29 22:15:26 +0000
@@ -26,109 +26,123 @@
26#include <locale.h>26#include <locale.h>
27#include <glib.h>27#include <glib.h>
28#include <glib/gi18n.h> /* textdomain(), bindtextdomain() */28#include <glib/gi18n.h> /* textdomain(), bindtextdomain() */
29#include <dbus/dbus-glib.h>
30#include <gtk/gtk.h>29#include <gtk/gtk.h>
31#include "dialog.h"30#include "dialog.h"
32#include "shared-names.h"31#include "shared-names.h"
3332
33static GVariant *
34call_console_kit (const gchar *method, GVariant *parameters, GError **error)
35{
36 GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
37 if (!bus)
38 {
39 g_variant_unref (parameters);
40 return NULL;
41 }
42
43 GVariant *result = g_dbus_connection_call_sync(bus,
44 "org.freedesktop.ConsoleKit",
45 "/org/freedesktop/ConsoleKit/Manager",
46 "org.freedesktop.ConsoleKit.Manager",
47 method,
48 parameters,
49 NULL,
50 G_DBUS_CALL_FLAGS_NONE,
51 -1,
52 NULL,
53 error);
54 g_object_unref (bus);
55
56 return result;
57}
58
34static void59static void
35consolekit_fallback (LogoutDialogType action)60consolekit_fallback (LogoutDialogType action)
36{61{
62 GError * error = NULL;
63 GVariant *result = NULL;
64
37 g_debug("Falling back to using ConsoleKit for action");65 g_debug("Falling back to using ConsoleKit for action");
3866
39 DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
40 g_return_if_fail(sbus != NULL); /* worst case */
41 DBusGProxy * proxy = dbus_g_proxy_new_for_name(sbus, "org.freedesktop.ConsoleKit",
42 "/org/freedesktop/ConsoleKit/Manager",
43 "org.freedesktop.ConsoleKit.Manager");
44
45 if (proxy == NULL) {
46 g_warning("Unable to get consolekit proxy");
47 return;
48 }
49
50 GError * error = NULL;
51
52 switch (action) {67 switch (action) {
53 case LOGOUT_DIALOG_TYPE_LOG_OUT:68 case LOGOUT_DIALOG_TYPE_LOG_OUT:
54 g_warning("Unable to fallback to ConsoleKit for logout as it's a session issue. We need some sort of session handler.");69 g_warning("Unable to fallback to ConsoleKit for logout as it's a session issue. We need some sort of session handler.");
55 break;70 break;
56 case LOGOUT_DIALOG_TYPE_SHUTDOWN:71 case LOGOUT_DIALOG_TYPE_SHUTDOWN:
57 g_debug("Telling ConsoleKit to 'Stop'");72 g_debug("Telling ConsoleKit to 'Stop'");
58 dbus_g_proxy_call(proxy,73 result = call_console_kit ("Stop", g_variant_new ("()"), &error);
59 "Stop",
60 &error,
61 G_TYPE_INVALID,
62 G_TYPE_INVALID);
63 break;74 break;
64 case LOGOUT_DIALOG_TYPE_RESTART:75 case LOGOUT_DIALOG_TYPE_RESTART:
65 g_debug("Telling ConsoleKit to 'Restart'");76 g_debug("Telling ConsoleKit to 'Restart'");
66 dbus_g_proxy_call(proxy,77 result = call_console_kit ("Restart", g_variant_new ("()"), &error);
67 "Restart",
68 &error,
69 G_TYPE_INVALID,
70 G_TYPE_INVALID);
71 break;78 break;
72 default:79 default:
73 g_warning("Unknown action");80 g_warning("Unknown action");
74 break;81 break;
75 }82 }
7683
77 g_object_unref(proxy);84 if (!result) {
85 if (error != NULL) {
86 g_warning ("ConsoleKit action failed: %s", error->message);
87 } else {
88 g_warning ("ConsoleKit action failed: unknown error");
89 }
7890
79 if (error != NULL) {91 consolekit_fallback(action);
80 g_warning("Unable to signal ConsoleKit");
81 g_error_free(error);
82 }92 }
93 else
94 g_variant_unref (result);
95 g_clear_error (&error);
8396
84 return;97 return;
85}98}
8699
100static GVariant *
101call_gnome_session (const gchar *method, GVariant *parameters, GError **error)
102{
103 GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error);
104 if (!bus)
105 {
106 g_variant_unref (parameters);
107 return NULL;
108 }
109
110 GVariant *result = g_dbus_connection_call_sync(bus,
111 "org.gnome.SessionManager",
112 "/org/gnome/SessionManager",
113 "org.gnome.SessionManager",
114 method,
115 parameters,
116 NULL,
117 G_DBUS_CALL_FLAGS_NONE,
118 G_MAXINT,
119 NULL,
120 error);
121 g_object_unref (bus);
122
123 return result;
124}
125
87static void126static void
88session_action (LogoutDialogType action)127session_action (LogoutDialogType action)
89{128{
90 DBusGConnection * sbus;
91 DBusGProxy * sm_proxy;
92 GError * error = NULL;129 GError * error = NULL;
93 gboolean res = FALSE;130 GVariant *result = NULL;
94
95 sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
96 if (sbus == NULL) {
97 g_warning("Unable to get DBus session bus.");
98 return;
99 }
100 sm_proxy = dbus_g_proxy_new_for_name_owner (sbus,
101 "org.gnome.SessionManager",
102 "/org/gnome/SessionManager",
103 "org.gnome.SessionManager",
104 &error);
105 if (sm_proxy == NULL) {
106 g_warning("Unable to get DBus proxy to SessionManager interface: %s", error->message);
107 g_error_free(error);
108131
109 consolekit_fallback(action);
110 return;
111 }
112
113 g_clear_error (&error);
114
115 if (action == LOGOUT_DIALOG_TYPE_LOG_OUT) {132 if (action == LOGOUT_DIALOG_TYPE_LOG_OUT) {
116 g_debug("Asking Session manager to 'Logout'");133 g_debug("Asking Session manager to 'Logout'");
117 res = dbus_g_proxy_call_with_timeout (sm_proxy, "Logout", INT_MAX, &error,134 result = call_gnome_session ("Logout", g_variant_new ("(u)", 1), &error);
118 G_TYPE_UINT, 1, G_TYPE_INVALID, G_TYPE_INVALID);
119 } else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) {135 } else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) {
120 g_debug("Asking Session manager to 'RequestShutdown'");136 g_debug("Asking Session manager to 'RequestShutdown'");
121 res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestShutdown", INT_MAX, &error,137 result = call_gnome_session ("RequestShutdown", g_variant_new ("()"), &error);
122 G_TYPE_INVALID, G_TYPE_INVALID);
123 } else if (action == LOGOUT_DIALOG_TYPE_RESTART) {138 } else if (action == LOGOUT_DIALOG_TYPE_RESTART) {
124 g_debug("Asking Session manager to 'RequestReboot'");139 g_debug("Asking Session manager to 'RequestReboot'");
125 res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestReboot", INT_MAX, &error,140 result = call_gnome_session ("RequestReboot", g_variant_new ("()"), &error);
126 G_TYPE_INVALID, G_TYPE_INVALID);
127 } else {141 } else {
128 g_warning ("Unknown session action");142 g_warning ("Unknown session action");
129 }143 }
130 144
131 if (!res) {145 if (!result) {
132 if (error != NULL) {146 if (error != NULL) {
133 g_warning ("SessionManager action failed: %s", error->message);147 g_warning ("SessionManager action failed: %s", error->message);
134 } else {148 } else {
@@ -137,8 +151,8 @@
137151
138 consolekit_fallback(action);152 consolekit_fallback(action);
139 }153 }
140 154 else
141 g_object_unref(sm_proxy);155 g_variant_unref (result);
142 g_clear_error (&error);156 g_clear_error (&error);
143 157
144 return;158 return;

Subscribers

People subscribed via source and target branches