Merge lp:~3v1n0/indicator-session/shell-mode into lp:indicator-session/13.04

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Charles Kerr
Approved revision: 391
Merged at revision: 386
Proposed branch: lp:~3v1n0/indicator-session/shell-mode
Merge into: lp:indicator-session/13.04
Diff against target: 239 lines (+149/-4)
1 file modified
src/session-menu-mgr.c (+149/-4)
To merge this branch: bzr merge lp:~3v1n0/indicator-session/shell-mode
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+151976@code.launchpad.net

Commit message

SessionMenuMgr: use unity shutdown dialogs if they're available, hiding Reboot action

Description of the change

To impelment the shutdown dialogs in Unity we're implementing the org.gnome.Shell's org.gnome.SessionManager.EndSessionDialog interface, this will allow us to react to gnome-session events with a nice UI flawlessly.

In that case, as the spec says, the indicator-session should not show the "Reboot" actions since both it and the "Shut Down" one are now pointing to the same screen.

So, when the org.gnome.Shell name appears now we hide the unneeded Reboot menu action and we call the GnomeSessionManager methods instead of opening the legacy dialog.

JohnLea has approved this change.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
391. By Marco Trevisan (Treviño)

SessionMenuMgr: show the reboot menu item in shell-mode with no confirmation

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

This merge needs a change to here:

https://wiki.ubuntu.com/SystemMenu

Before it should be applied so that they stay in sync.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> This merge needs a change to here:
>
> https://wiki.ubuntu.com/SystemMenu
>
> Before it should be applied so that they stay in sync.

Fine, can I do that, or should I wait for design?

Revision history for this message
Charles Kerr (charlesk) wrote :

Since we're up on FF and the design's been approved for some time now, IMO on balance it's better to approve this.

However let's make sure mpt's aware of this change and see if he has any concerns/issues that we can address during bugfixing.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/session-menu-mgr.c'
2--- src/session-menu-mgr.c 2012-11-16 09:30:53 +0000
3+++ src/session-menu-mgr.c 2013-03-06 15:31:21 +0000
4@@ -110,8 +110,10 @@
5 gboolean allow_hibernate;
6 gboolean allow_suspend;
7
8+ gboolean shell_mode;
9 gboolean greeter_mode;
10
11+ guint shell_name_watcher;
12 GCancellable * cancellable;
13 DBusUPower * upower_proxy;
14 SessionDbus * session_dbus;
15@@ -122,6 +124,7 @@
16 static SwitcherMode get_switcher_mode (SessionMenuMgr *);
17
18 static void init_upower_proxy (SessionMenuMgr *);
19+static void init_shell_watcher (SessionMenuMgr *);
20
21 static void update_screensaver_shortcut (SessionMenuMgr *);
22 static void update_user_menuitems (SessionMenuMgr *);
23@@ -131,6 +134,9 @@
24 static void action_func_lock (SessionMenuMgr *);
25 static void action_func_suspend (SessionMenuMgr *);
26 static void action_func_hibernate (SessionMenuMgr *);
27+static void action_func_shutdown (SessionMenuMgr *);
28+static void action_func_reboot (SessionMenuMgr *);
29+static void action_func_logout (SessionMenuMgr *);
30 static void action_func_switch_to_lockscreen (SessionMenuMgr *);
31 static void action_func_switch_to_greeter (SessionMenuMgr *);
32 static void action_func_switch_to_guest (SessionMenuMgr *);
33@@ -172,6 +178,8 @@
34 s = g_settings_new ("com.canonical.indicator.session");
35 g_signal_connect_swapped (s, "changed::suppress-logout-restart-shutdown",
36 G_CALLBACK(update_confirmation_labels), mgr);
37+ g_signal_connect_swapped (s, "changed::suppress-logout-restart-shutdown",
38+ G_CALLBACK(update_session_menuitems), mgr);
39 g_signal_connect_swapped (s, "changed::suppress-logout-menuitem",
40 G_CALLBACK(update_session_menuitems), mgr);
41 g_signal_connect_swapped (s, "changed::suppress-restart-menuitem",
42@@ -196,6 +204,7 @@
43 G_CALLBACK(on_guest_logged_in_changed), mgr);
44
45 init_upower_proxy (mgr);
46+ init_shell_watcher (mgr);
47
48 /* Online accounts menu item */
49 mgr->online_accounts_mgr = online_accounts_mgr_new ();
50@@ -224,6 +233,11 @@
51 g_slist_free (mgr->user_menuitems);
52 mgr->user_menuitems = NULL;
53
54+ if (mgr->shell_name_watcher)
55+ {
56+ g_bus_unwatch_name (mgr->shell_name_watcher);
57+ }
58+
59 G_OBJECT_CLASS (session_menu_mgr_parent_class)->dispose (object);
60 }
61
62@@ -328,6 +342,37 @@
63 }
64 }
65
66+static void
67+on_shell_name_appeared (GDBusConnection *connection, const gchar *name,
68+ const gchar *name_owner, gpointer user_data)
69+{
70+ SessionMenuMgr * mgr = SESSION_MENU_MGR(user_data);
71+
72+ g_debug("Shell appeared");
73+ mgr->shell_mode = TRUE;
74+ update_session_menuitems (mgr);
75+}
76+
77+static void
78+on_shell_name_vanished (GDBusConnection *connection, const gchar *name, gpointer user_data)
79+{
80+ SessionMenuMgr * mgr = SESSION_MENU_MGR(user_data);
81+
82+ g_debug("Shell vanished");
83+ mgr->shell_mode = FALSE;
84+ update_session_menuitems (mgr);
85+}
86+
87+static void
88+init_shell_watcher (SessionMenuMgr * mgr)
89+{
90+ mgr->shell_name_watcher = g_bus_watch_name (G_BUS_TYPE_SESSION, "org.gnome.Shell",
91+ G_BUS_NAME_WATCHER_FLAGS_NONE,
92+ on_shell_name_appeared,
93+ on_shell_name_vanished,
94+ mgr, NULL);
95+}
96+
97 /***
98 **** Menuitem Helpers
99 ***/
100@@ -468,7 +513,8 @@
101 && mgr->allow_hibernate;
102 mi_set_visible (mgr->hibernate_mi, v);
103
104- v = HAVE_RESTART_CMD
105+ v = (!mgr->shell_mode || g_settings_get_boolean (s, "suppress-logout-restart-shutdown"))
106+ && (HAVE_RESTART_CMD || mgr->shell_mode)
107 && !g_settings_get_boolean (s, "suppress-restart-menuitem");
108 mi_set_visible (mgr->restart_mi, v);
109
110@@ -507,7 +553,7 @@
111 mi = mgr->logout_mi = mi_new (_("Log Out\342\200\246"));
112 dbusmenu_menuitem_child_append (mgr->top_mi, mi);
113 g_signal_connect_swapped (mi, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
114- G_CALLBACK(action_func_spawn_async), CMD_LOGOUT);
115+ G_CALLBACK(action_func_logout), mgr);
116
117 mi = mgr->suspend_mi = mi_new (_("Suspend"));
118 dbusmenu_menuitem_child_append (mgr->top_mi, mi);
119@@ -522,12 +568,12 @@
120 mi = mgr->restart_mi = mi_new (_("Restart\342\200\246"));
121 dbusmenu_menuitem_child_append (mgr->top_mi, mi);
122 g_signal_connect_swapped (mi, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
123- G_CALLBACK(action_func_spawn_async), CMD_RESTART);
124+ G_CALLBACK(action_func_reboot), mgr);
125
126 mi = mgr->shutdown_mi = mi_new (_("Shut Down\342\200\246"));
127 dbusmenu_menuitem_child_append (mgr->top_mi, mi);
128 g_signal_connect_swapped (mi, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
129- G_CALLBACK(action_func_spawn_async), CMD_SHUTDOWN);
130+ G_CALLBACK(action_func_shutdown), mgr);
131
132 update_confirmation_labels (mgr);
133 update_session_menuitems (mgr);
134@@ -1128,6 +1174,105 @@
135 }
136 }
137
138+static gboolean
139+call_session_manager_method (const gchar * method_name, GVariant * parameters)
140+{
141+ gboolean result = TRUE;
142+ GError * error = NULL;
143+ GDBusProxy * proxy = g_dbus_proxy_new_for_bus_sync (
144+ G_BUS_TYPE_SESSION,
145+ G_DBUS_PROXY_FLAGS_NONE,
146+ NULL,
147+ "org.gnome.SessionManager",
148+ "/org/gnome/SessionManager",
149+ "org.gnome.SessionManager",
150+ NULL,
151+ &error);
152+
153+ if (error == NULL)
154+ {
155+ g_dbus_proxy_call_sync (proxy, method_name, parameters,
156+ G_DBUS_CALL_FLAGS_NONE, -1, NULL,
157+ &error);
158+ }
159+ else if (parameters != NULL)
160+ {
161+ g_variant_unref (parameters);
162+ }
163+
164+ if (error != NULL)
165+ {
166+ result = FALSE;
167+ g_warning ("Error shutting down: %s", error->message);
168+ g_clear_error (&error);
169+ }
170+
171+ g_clear_object (&proxy);
172+
173+ return result;
174+}
175+
176+static void
177+action_func_shutdown (SessionMenuMgr * mgr)
178+{
179+ gboolean result = FALSE;
180+
181+ if (mgr->shell_mode)
182+ {
183+ if (g_settings_get_boolean (mgr->indicator_settings,
184+ "suppress-logout-restart-shutdown"))
185+ {
186+ result = call_session_manager_method ("Shutdown", NULL);
187+ }
188+ else
189+ {
190+ /* We call 'Reboot' method instead of 'Shutdown' because
191+ * Unity SessionManager handles the Shutdown request as a more
192+ * general request as the default SessionManager dialog would do */
193+ result = call_session_manager_method ("Reboot", NULL);
194+ }
195+ }
196+
197+ if (!result)
198+ {
199+ action_func_spawn_async (CMD_SHUTDOWN);
200+ }
201+}
202+
203+static void
204+action_func_logout (SessionMenuMgr * mgr)
205+{
206+ gboolean result = FALSE;
207+
208+ if (mgr->shell_mode)
209+ {
210+ guint interactive_mode = 0;
211+ result = call_session_manager_method ("Logout",
212+ g_variant_new ("(u)", interactive_mode));
213+ }
214+
215+ if (!result)
216+ {
217+ action_func_spawn_async (CMD_LOGOUT);
218+ }
219+}
220+
221+static void
222+action_func_reboot (SessionMenuMgr * mgr)
223+{
224+ gboolean result = FALSE;
225+
226+ if (mgr->shell_mode)
227+ {
228+ result = call_session_manager_method ("Reboot", NULL);
229+ }
230+
231+ if (!result)
232+ {
233+ action_func_spawn_async (CMD_RESTART);
234+ }
235+}
236+
237 /***
238 ****
239 ***/

Subscribers

People subscribed via source and target branches