Merge lp:~ted/indicator-session/being-a-better-house-guest into lp:indicator-session/0.1

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ted/indicator-session/being-a-better-house-guest
Merge into: lp:indicator-session/0.1
Diff against target: 1030 lines (+638/-90)
8 files modified
.bzrignore (+2/-0)
src/Makefile.am (+18/-0)
src/consolekit-session.xml (+435/-0)
src/gdm-local-display-factory.xml (+20/-0)
src/indicator-session.c (+15/-0)
src/session-service.c (+12/-0)
src/users-service-dbus.c (+129/-90)
src/users-service-dbus.h (+7/-0)
To merge this branch: bzr merge lp:~ted/indicator-session/being-a-better-house-guest
Reviewer Review Type Date Requested Status
Cody Russell (community) Approve
Review via email: mp+21593@code.launchpad.net

Description of the change

Wow, basically the goal of this branch is to get it so that we can see
when the guest user is logged in and goto the running guest session. It
ended up being a lot more than that. Turns out you couldn't update
logged in icons and detecting the guest session as more than a little
trickey. Turned into a pretty big patch.

To post a comment you must log in.
124. By Ted Gould

Linking to 436030

Revision history for this message
Cody Russell (bratsche) wrote :

Awesome!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2010-03-15 22:02:31 +0000
3+++ .bzrignore 2010-03-18 03:33:27 +0000
4@@ -58,3 +58,5 @@
5 src/session-dbus-client.h
6 src/session-dbus-server.h
7 src/upower-client.h
8+src/gdm-local-display-factory-client.h
9+src/consolekit-session-client.h
10
11=== modified file 'src/Makefile.am'
12--- src/Makefile.am 2010-03-15 22:02:31 +0000
13+++ src/Makefile.am 2010-03-18 03:33:27 +0000
14@@ -26,6 +26,20 @@
15 --output=consolekit-manager-client.h \
16 $(srcdir)/consolekit-manager.xml
17
18+consolekit-session-client.h: $(srcdir)/consolekit-session.xml
19+ dbus-binding-tool \
20+ --prefix=_consolekit_session_client \
21+ --mode=glib-client \
22+ --output=consolekit-session-client.h \
23+ $(srcdir)/consolekit-session.xml
24+
25+gdm-local-display-factory-client.h: $(srcdir)/gdm-local-display-factory.xml
26+ dbus-binding-tool \
27+ --prefix=_gdm_local_display_factory_client \
28+ --mode=glib-client \
29+ --output=gdm-local-display-factory-client.h \
30+ $(srcdir)/gdm-local-display-factory.xml
31+
32 users-service-client.h: $(srcdir)/users-service.xml
33 dbus-binding-tool \
34 --prefix=_users_service_client \
35@@ -113,6 +127,8 @@
36
37 BUILT_SOURCES = \
38 consolekit-manager-client.h \
39+ consolekit-session-client.h \
40+ gdm-local-display-factory-client.h \
41 session-dbus-client.h \
42 session-dbus-server.h \
43 upower-client.h \
44@@ -122,6 +138,8 @@
45
46 EXTRA_DIST = \
47 consolekit-manager.xml \
48+ consolekit-session.xml \
49+ gdm-local-display-factory.xml \
50 session-dbus.xml \
51 upower.xml \
52 users-service.xml \
53
54=== added file 'src/consolekit-session.xml'
55--- src/consolekit-session.xml 1970-01-01 00:00:00 +0000
56+++ src/consolekit-session.xml 2010-03-18 03:33:27 +0000
57@@ -0,0 +1,435 @@
58+<?xml version="1.0" encoding="UTF-8"?>
59+<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
60+
61+ <interface name="org.freedesktop.ConsoleKit.Session">
62+ <doc:doc>
63+ <doc:description>
64+ <doc:para>Session objects represent and store information
65+ related to a user session.
66+ </doc:para>
67+ <doc:para>The properties associated with the Session
68+ specifically refer to the properties of the "session leader".
69+ </doc:para>
70+ </doc:description>
71+ </doc:doc>
72+ <method name="GetId">
73+ <arg name="ssid" direction="out" type="o">
74+ <doc:doc>
75+ <doc:summary>Session ID</doc:summary>
76+ </doc:doc>
77+ </arg>
78+ <doc:doc>
79+ <doc:description><doc:para>Returns the ID for Session.</doc:para>
80+ </doc:description>
81+ </doc:doc>
82+ </method>
83+ <method name="GetSeatId">
84+ <arg name="sid" direction="out" type="o">
85+ <doc:doc>
86+ <doc:summary>Seat ID</doc:summary>
87+ </doc:doc>
88+ </arg>
89+ <doc:doc>
90+ <doc:description><doc:para>Returns the ID for the Seat the Session is
91+ attached to.</doc:para>
92+ </doc:description>
93+ <doc:seealso><doc:ref type="interface" to="Seat">org.freedesktop.ConsoleKit.Seat</doc:ref></doc:seealso>
94+ </doc:doc>
95+ </method>
96+ <method name="GetSessionType">
97+ <arg name="type" direction="out" type="s">
98+ <doc:doc>
99+ <doc:summary>Session type</doc:summary>
100+ </doc:doc>
101+ </arg>
102+ <doc:doc>
103+ <doc:description>
104+ <doc:para>Returns the type of the session.</doc:para>
105+ <doc:para>Warning: we haven't yet defined the allowed values for this property.
106+ It is probably best to avoid this until we do.
107+ </doc:para>
108+ </doc:description>
109+ <doc:seealso><doc:ref type="property" to="Session:session-type">session-type</doc:ref></doc:seealso>
110+ </doc:doc>
111+ </method>
112+ <method name="GetUser">
113+ <arg name="uid" direction="out" type="u">
114+ <doc:doc>
115+ <doc:summary>User ID</doc:summary>
116+ </doc:doc>
117+ </arg>
118+ <doc:doc>
119+ <doc:description><doc:para>Returns the user that the session belongs to.</doc:para>
120+ </doc:description>
121+ <doc:deprecated version="0.1.3" instead="GetUnixUser"/>
122+ <doc:seealso><doc:ref type="property" to="Session:user">user</doc:ref></doc:seealso>
123+ </doc:doc>
124+ </method>
125+ <method name="GetUnixUser">
126+ <arg name="uid" direction="out" type="u">
127+ <doc:doc>
128+ <doc:summary>POSIX User ID</doc:summary>
129+ </doc:doc>
130+ </arg>
131+ <doc:doc>
132+ <doc:description><doc:para>Returns the POSIX user ID that the session belongs to.</doc:para>
133+ </doc:description>
134+ <doc:seealso><doc:ref type="property" to="Session:unix-user">unix-user</doc:ref></doc:seealso>
135+ </doc:doc>
136+ </method>
137+ <method name="GetX11Display">
138+ <arg name="display" direction="out" type="s">
139+ <doc:doc>
140+ <doc:summary>The value of the X11 display</doc:summary>
141+ </doc:doc>
142+ </arg>
143+ <doc:doc>
144+ <doc:description><doc:para>Returns the value of the X11 DISPLAY for this session
145+ if one is present.</doc:para>
146+ </doc:description>
147+ <doc:seealso><doc:ref type="property" to="Session:x11-display">x11-display</doc:ref></doc:seealso>
148+ </doc:doc>
149+ </method>
150+ <method name="GetX11DisplayDevice">
151+ <arg name="x11_display_device" direction="out" type="s">
152+ <doc:doc>
153+ <doc:summary>The value of the X11 display device</doc:summary>
154+ </doc:doc>
155+ </arg>
156+ <doc:doc>
157+ <doc:description><doc:para>Returns the value of the display device (aka TTY) that the
158+ X11 display for the session is connected to. If there is no x11-display set then this value
159+ is undefined.</doc:para>
160+ </doc:description>
161+ <doc:seealso><doc:ref type="property" to="Session:x11-display-device">x11-display-device</doc:ref></doc:seealso>
162+ </doc:doc>
163+ </method>
164+ <method name="GetDisplayDevice">
165+ <arg name="display_device" direction="out" type="s">
166+ <doc:doc>
167+ <doc:summary>The value of the display device</doc:summary>
168+ </doc:doc>
169+ </arg>
170+ <doc:doc>
171+ <doc:description><doc:para>Returns the value of the display device (aka TTY) that the
172+ session is connected to.</doc:para>
173+ </doc:description>
174+ <doc:seealso><doc:ref type="property" to="Session:display-device">display-device</doc:ref></doc:seealso>
175+ </doc:doc>
176+ </method>
177+ <method name="GetRemoteHostName">
178+ <arg name="remote_host_name" direction="out" type="s">
179+ <doc:doc>
180+ <doc:summary>The remote host name</doc:summary>
181+ </doc:doc>
182+ </arg>
183+ <doc:doc>
184+ <doc:description><doc:para>Returns the value of the remote host name for the session.
185+ </doc:para>
186+ </doc:description>
187+ <doc:seealso><doc:ref type="property" to="Session:remote-host-name">remote-host-name</doc:ref></doc:seealso>
188+ </doc:doc>
189+ </method>
190+ <method name="GetLoginSessionId">
191+ <arg name="login_session_id" direction="out" type="s">
192+ <doc:doc>
193+ <doc:summary>The value of the native system login session ID</doc:summary>
194+ </doc:doc>
195+ </arg>
196+ <doc:doc>
197+ <doc:description><doc:para>Returns the value of the login session ID that the
198+ underlying system uses to enforce session boundaries. If there is no login session ID
199+ set then this value is an empty string.</doc:para>
200+ </doc:description>
201+ </doc:doc>
202+ </method>
203+ <method name="IsActive">
204+ <arg name="active" direction="out" type="b">
205+ <doc:doc>
206+ <doc:summary>TRUE if the session is active, otherwise FALSE</doc:summary>
207+ </doc:doc>
208+ </arg>
209+ <doc:doc>
210+ <doc:description><doc:para>Returns whether the session is active on the Seat that
211+ it is attached to.</doc:para>
212+ <doc:para>If the session is not attached to a seat this value is undefined.
213+ </doc:para>
214+ </doc:description>
215+ <doc:seealso><doc:ref type="property" to="Session:active">active</doc:ref></doc:seealso>
216+ </doc:doc>
217+ </method>
218+ <method name="IsLocal">
219+ <arg name="local" direction="out" type="b">
220+ <doc:doc>
221+ <doc:summary>TRUE if the session is local, otherwise FALSE</doc:summary>
222+ </doc:doc>
223+ </arg>
224+ <doc:doc>
225+ <doc:description><doc:para>Returns whether the session is local</doc:para>
226+ <doc:para>FIXME: we need to come up with a concrete definition for this value.
227+ It was originally used as a way to identify XDMCP sessions that originate
228+ from a remote system.
229+ </doc:para>
230+ </doc:description>
231+ <doc:seealso><doc:ref type="property" to="Session:is-local">is-local</doc:ref></doc:seealso>
232+ </doc:doc>
233+ </method>
234+ <method name="GetCreationTime">
235+ <arg name="iso8601_datetime" type="s" direction="out">
236+ <doc:doc>
237+ <doc:summary>An ISO 8601 format date-type string</doc:summary>
238+ </doc:doc>
239+ </arg>
240+ <doc:doc>
241+ <doc:description>
242+ <doc:para>Returns an ISO 8601 date-time string that corresponds to
243+ the time that the session was opened.
244+ </doc:para>
245+ </doc:description>
246+ </doc:doc>
247+ </method>
248+
249+ <method name="Activate">
250+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
251+ <doc:doc>
252+ <doc:description>
253+ <doc:para>Attempt to activate the this session. In most
254+ cases, if successful, this will cause the session to
255+ become visible and become active on the seat that it
256+ is attached to.</doc:para>
257+ </doc:description>
258+ <doc:seealso><doc:ref type="method" to="Seat.ActivateSession">Seat.ActivateSession()</doc:ref></doc:seealso>
259+ </doc:doc>
260+ </method>
261+ <method name="Lock">
262+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
263+ <doc:doc>
264+ <doc:description>
265+ <doc:para>This will cause a <doc:ref type="signal" to="Session::Lock">Lock</doc:ref>
266+ signal to be emitted for this session.
267+ </doc:para>
268+ </doc:description>
269+ <doc:permission>This method is restricted to privileged users by D-Bus policy.</doc:permission>
270+ <doc:seealso><doc:ref type="signal" to="Session::Lock">Lock signal</doc:ref></doc:seealso>
271+ </doc:doc>
272+ </method>
273+ <method name="Unlock">
274+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
275+ <doc:doc>
276+ <doc:description>
277+ <doc:para>This will cause an <doc:ref type="signal" to="Session::Unlock">Unlock</doc:ref>
278+ signal to be emitted for this session.
279+ </doc:para>
280+ <doc:para>This can be used by login managers to unlock a session before it is
281+ re-activated during fast-user-switching.
282+ </doc:para>
283+ </doc:description>
284+ <doc:permission>This method is restricted to privileged users by D-Bus policy.</doc:permission>
285+ <doc:seealso><doc:ref type="signal" to="Session::Unlock">Unlock signal</doc:ref></doc:seealso>
286+ </doc:doc>
287+ </method>
288+
289+ <method name="GetIdleHint">
290+ <arg name="idle_hint" type="b" direction="out">
291+ <doc:doc>
292+ <doc:summary>The value of the idle-hint</doc:summary>
293+ </doc:doc>
294+ </arg>
295+ <doc:doc>
296+ <doc:description>
297+ <doc:para>Gets the value of the <doc:ref type="property" to="Session:idle-hint">idle-hint</doc:ref>
298+ property.
299+ </doc:para>
300+ </doc:description>
301+ <doc:seealso><doc:ref type="property" to="Session:idle-hint">idle-hint</doc:ref></doc:seealso>
302+ </doc:doc>
303+ </method>
304+ <method name="GetIdleSinceHint">
305+ <arg name="iso8601_datetime" type="s" direction="out">
306+ <doc:doc>
307+ <doc:summary>An ISO 8601 format date-type string</doc:summary>
308+ </doc:doc>
309+ </arg>
310+ <doc:doc>
311+ <doc:description>
312+ <doc:para>Returns an ISO 8601 date-time string that corresponds to
313+ the time of the last change of the idle-hint.
314+ </doc:para>
315+ </doc:description>
316+ </doc:doc>
317+ </method>
318+ <method name="SetIdleHint">
319+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
320+ <arg name="idle_hint" type="b" direction="in">
321+ <doc:doc>
322+ <doc:summary>boolean value to set the idle-hint to</doc:summary>
323+ </doc:doc>
324+ </arg>
325+ <doc:doc>
326+ <doc:description>
327+ <doc:para>This may be used by the session to indicate that
328+ it is idle.
329+ </doc:para>
330+ <doc:para>Use of this method is restricted to the user
331+ that owns the session.</doc:para>
332+ </doc:description>
333+ </doc:doc>
334+ </method>
335+
336+ <signal name="ActiveChanged">
337+ <arg name="is_active" type="b">
338+ <doc:doc>
339+ <doc:summary>TRUE if the session is active, otherwise FALSE</doc:summary>
340+ </doc:doc>
341+ </arg>
342+ <doc:doc>
343+ <doc:description>
344+ <doc:para>Emitted when the active property has changed.</doc:para>
345+ </doc:description>
346+ </doc:doc>
347+ </signal>
348+ <signal name="IdleHintChanged">
349+ <arg name="hint" type="b">
350+ <doc:doc>
351+ <doc:summary>the new value of idle-hint</doc:summary>
352+ </doc:doc>
353+ </arg>
354+ <doc:doc>
355+ <doc:description>
356+ <doc:para>Emitted when the idle-hint property has changed.</doc:para>
357+ </doc:description>
358+ </doc:doc>
359+ </signal>
360+ <signal name="Lock">
361+ <doc:doc>
362+ <doc:description>
363+ <doc:para>Emitted in response to a call to the <doc:ref type="method" to="Session.Lock">Lock()</doc:ref> method.</doc:para>
364+ <doc:para>It is intended that the screensaver for the session should lock the screen in response to this signal.</doc:para>
365+ </doc:description>
366+ </doc:doc>
367+ </signal>
368+ <signal name="Unlock">
369+ <doc:doc>
370+ <doc:description>
371+ <doc:para>Emitted in response to a call to the <doc:ref type="method" to="Session.Unlock">Unlock()</doc:ref> method.</doc:para>
372+ <doc:para>It is intended that the screensaver for the session should unlock the screen in response to this signal.</doc:para>
373+ </doc:description>
374+ </doc:doc>
375+ </signal>
376+
377+ <property name="unix-user" type="u" access="readwrite">
378+ <doc:doc>
379+ <doc:description>
380+ <doc:para>The user assigned to the session.</doc:para>
381+ </doc:description>
382+ </doc:doc>
383+ </property>
384+ <property name="user" type="u" access="readwrite">
385+ <doc:doc>
386+ <doc:description>
387+ <doc:para>The user assigned to the session.</doc:para>
388+ </doc:description>
389+ <doc:deprecated version="0.1.3" instead="unix-user"/>
390+ </doc:doc>
391+ </property>
392+ <property name="session-type" type="s" access="readwrite">
393+ <doc:doc>
394+ <doc:description>
395+ <doc:para>The type of the session.</doc:para>
396+ <doc:para>Warning: we haven't yet defined the allowed values for this property.
397+ It is probably best to avoid this until we do.
398+ </doc:para>
399+ </doc:description>
400+ </doc:doc>
401+ </property>
402+ <property name="remote-host-name" type="s" access="readwrite">
403+ <doc:doc>
404+ <doc:description>
405+ <doc:para>The remote host name for the session.
406+ </doc:para>
407+ <doc:para>This will be set in situations where the session is
408+ opened and controlled from a remote system.
409+ </doc:para>
410+ <doc:para>For example, this value will be set when the
411+ session is created from an SSH or XDMCP connection.
412+ </doc:para>
413+ </doc:description>
414+ </doc:doc>
415+ </property>
416+ <property name="display-device" type="s" access="readwrite">
417+ <doc:doc>
418+ <doc:description>
419+ <doc:para>The display device (aka TTY) that the
420+ session is connected to.
421+ </doc:para>
422+ </doc:description>
423+ </doc:doc>
424+ </property>
425+ <property name="x11-display" type="s" access="readwrite">
426+ <doc:doc>
427+ <doc:description>
428+ <doc:para>Value of the X11 DISPLAY for this session
429+ if one is present.
430+ </doc:para>
431+ </doc:description>
432+ </doc:doc>
433+ </property>
434+ <property name="x11-display-device" type="s" access="readwrite">
435+ <doc:doc>
436+ <doc:description>
437+ <doc:para>
438+ The display device (aka TTY) that the X11 display for the
439+ session is connected to. If there is no x11-display set then
440+ this value is undefined.
441+ </doc:para>
442+ </doc:description>
443+ </doc:doc>
444+ </property>
445+ <property name="active" type="b" access="readwrite">
446+ <doc:doc>
447+ <doc:description>
448+ <doc:para>
449+ Whether the session is active on the Seat that
450+ it is attached to.</doc:para>
451+ <doc:para>If the session is not attached to a seat this value is undefined.
452+ </doc:para>
453+ </doc:description>
454+ </doc:doc>
455+ </property>
456+ <property name="is-local" type="b" access="readwrite">
457+ <doc:doc>
458+ <doc:description>
459+ <doc:para>
460+ Whether the session is local</doc:para>
461+ <doc:para>FIXME: we need to come up with a concrete definition for this value.
462+ It was originally used as a way to identify XDMCP sessions that originate
463+ from a remote system.
464+ </doc:para>
465+ </doc:description>
466+ </doc:doc>
467+ </property>
468+ <property name="idle-hint" type="b" access="readwrite">
469+ <doc:doc>
470+ <doc:description>
471+ <doc:para>
472+ This is a hint used to indicate that the session may be idle.
473+ </doc:para>
474+ <doc:para>
475+ For sessions with a <doc:ref type="property" to="Session:x11-display">x11-display</doc:ref> set (ie. graphical
476+ sessions), it is up to each session to delegate the
477+ responsibility for updating this value. Typically, the
478+ screensaver will set this.
479+ </doc:para>
480+ <doc:para>However, for non-graphical sessions with a <doc:ref type="property" to="Session:display-device">display-device</doc:ref> set
481+ the Session object itself will periodically update this value based
482+ on the activity detected on the display-device itself.
483+ </doc:para>
484+ <doc:para>
485+ This should not be considered authoritative.
486+ </doc:para>
487+ </doc:description>
488+ </doc:doc>
489+ </property>
490+
491+ </interface>
492+</node>
493
494=== added file 'src/gdm-local-display-factory.xml'
495--- src/gdm-local-display-factory.xml 1970-01-01 00:00:00 +0000
496+++ src/gdm-local-display-factory.xml 2010-03-18 03:33:27 +0000
497@@ -0,0 +1,20 @@
498+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
499+<node name="/org/gnome/DisplayManager/LocalDisplayFactory">
500+ <interface name="org.gnome.DisplayManager.LocalDisplayFactory">
501+ <method name="CreateProductDisplay">
502+ <arg name="parent_display_id" direction="in" type="o"/>
503+ <arg name="relay_address" direction="in" type="s"/>
504+ <arg name="id" direction="out" type="o"/>
505+ </method>
506+ <method name="CreateTransientDisplay">
507+ <arg name="id" direction="out" type="o"/>
508+ </method>
509+ <method name="StartGuestSession">
510+ <arg name="id" direction="out" type="o"/>
511+ </method>
512+ <method name="SwitchToUser">
513+ <arg name="username" direction="in" type="s"/>
514+ <arg name="id" direction="out" type="o"/>
515+ </method>
516+ </interface>
517+</node>
518
519=== modified file 'src/indicator-session.c'
520--- src/indicator-session.c 2010-03-17 15:47:09 +0000
521+++ src/indicator-session.c 2010-03-18 03:33:27 +0000
522@@ -216,6 +216,19 @@
523 return INDICATOR_SESSION(io)->status_image;
524 }
525
526+static void
527+user_property_change (DbusmenuMenuitem * item, const gchar * property, const GValue * value, gpointer user_data)
528+{
529+ if (g_strcmp0(property, USER_ITEM_PROP_LOGGED_IN) == 0) {
530+ if (g_value_get_boolean(value)) {
531+ gtk_widget_show(GTK_WIDGET(user_data));
532+ } else {
533+ gtk_widget_hide(GTK_WIDGET(user_data));
534+ }
535+ }
536+ return;
537+}
538+
539 /* Builds an item with a hip little logged in icon. */
540 static gboolean
541 new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
542@@ -242,6 +255,8 @@
543
544 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent);
545
546+ g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(user_property_change), icon);
547+
548 return TRUE;
549 }
550
551
552=== modified file 'src/session-service.c'
553--- src/session-service.c 2010-03-16 15:06:31 +0000
554+++ src/session-service.c 2010-03-18 03:33:27 +0000
555@@ -386,6 +386,13 @@
556
557 lock_if_possible();
558
559+ if (dbusmenu_menuitem_property_get_bool(mi, USER_ITEM_PROP_LOGGED_IN)) {
560+ if (users_service_dbus_activate_guest_session(USERS_SERVICE_DBUS(user_data))) {
561+ return;
562+ }
563+ g_warning("Unable to activate guest session, falling back to command line activation.");
564+ }
565+
566 if (!g_spawn_command_line_async(GUEST_SESSION_LAUNCHER, &error)) {
567 g_warning("Unable to start guest session: %s", error->message);
568 g_error_free(error);
569@@ -519,6 +526,9 @@
570 }
571 }
572
573+ /* Set to NULL just incase we don't end up building one */
574+ users_service_dbus_set_guest_item(service, NULL);
575+
576 /* Build all of the user switching items */
577 if (can_activate == TRUE)
578 {
579@@ -536,6 +546,7 @@
580 dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, FALSE);
581 dbusmenu_menuitem_child_append (root, guest_mi);
582 g_signal_connect (G_OBJECT (guest_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), NULL);
583+ users_service_dbus_set_guest_item(service, guest_mi);
584 }
585
586 if (check_new_session ())
587@@ -592,6 +603,7 @@
588 dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_LOGGED_IN, user->sessions != NULL);
589 dbusmenu_menuitem_child_append (root, mi);
590 g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user);
591+ user->menuitem = mi;
592 }
593 }
594
595
596=== modified file 'src/users-service-dbus.c'
597--- src/users-service-dbus.c 2010-03-04 02:54:37 +0000
598+++ src/users-service-dbus.c 2010-03-18 03:33:27 +0000
599@@ -31,10 +31,16 @@
600 #include <dbus/dbus-glib-lowlevel.h>
601
602 #include "dbus-shared-names.h"
603+#include "gdm-local-display-factory-client.h"
604 #include "users-service-dbus.h"
605 #include "users-service-client.h"
606 #include "users-service-marshal.h"
607 #include "consolekit-manager-client.h"
608+#include "consolekit-session-client.h"
609+
610+#define CK_ADDR "org.freedesktop.ConsoleKit"
611+#define CK_SESSION_IFACE "org.freedesktop.ConsoleKit.Session"
612+
613
614 static void users_service_dbus_class_init (UsersServiceDbusClass *klass);
615 static void users_service_dbus_init (UsersServiceDbus *self);
616@@ -65,7 +71,7 @@
617 static gboolean do_add_session (UsersServiceDbus *service,
618 UserData *user,
619 const gchar *ssid);
620-static gchar * get_seat_internal (UsersServiceDbus *self);
621+static gchar * get_seat_internal (DBusGProxy *proxy);
622
623 /* Private */
624 typedef struct _UsersServiceDbusPrivate UsersServiceDbusPrivate;
625@@ -80,12 +86,16 @@
626 DBusGConnection *system_bus;
627
628 DBusGProxy *gdm_proxy;
629+ DBusGProxy *gdm_local_proxy;
630 DBusGProxy *ck_proxy;
631 DBusGProxy *seat_proxy;
632 DBusGProxy *session_proxy;
633
634 GHashTable *exclusions;
635 GHashTable *sessions;
636+
637+ DbusmenuMenuitem * guest_item;
638+ gchar * guest_session_id;
639 };
640
641 #define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate))
642@@ -155,6 +165,8 @@
643
644 priv->users = NULL;
645 priv->count = 0;
646+ priv->guest_item = NULL;
647+ priv->guest_session_id = NULL;
648
649 /* Get the system bus */
650 priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
651@@ -198,6 +210,13 @@
652 static void
653 users_service_dbus_finalize (GObject *object)
654 {
655+ UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (object);
656+
657+ if (priv->guest_session_id != NULL) {
658+ g_free(priv->guest_session_id);
659+ priv->guest_session_id = NULL;
660+ }
661+
662 G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object);
663 }
664
665@@ -266,6 +285,11 @@
666 G_CALLBACK (user_updated),
667 self,
668 NULL);
669+
670+ priv->gdm_local_proxy = dbus_g_proxy_new_for_name (priv->system_bus,
671+ "org.gnome.DisplayManager",
672+ "/org/gnome/DisplayManager/LocalDisplayFactory",
673+ "org.gnome.DisplayManager.LocalDisplayFactory");
674 }
675
676 static void
677@@ -341,9 +365,9 @@
678 UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service);
679
680 priv->session_proxy = dbus_g_proxy_new_for_name (priv->system_bus,
681- "org.freedesktop.ConsoleKit",
682+ CK_ADDR,
683 priv->ssid,
684- "org.freedesktop.ConsoleKit.Session");
685+ CK_SESSION_IFACE);
686
687 if (!priv->session_proxy)
688 {
689@@ -383,24 +407,18 @@
690 priv->ssid = ssid;
691 create_cksession_proxy (service);
692
693- seat = get_seat_internal (service);
694+ seat = get_seat_internal (priv->session_proxy);
695
696 return seat;
697 }
698
699 static gchar *
700-get_seat_internal (UsersServiceDbus *self)
701+get_seat_internal (DBusGProxy *proxy)
702 {
703- UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self);
704 GError *error = NULL;
705 gchar *seat = NULL;
706
707- if (!dbus_g_proxy_call (priv->session_proxy,
708- "GetSeatId",
709- &error,
710- G_TYPE_INVALID,
711- DBUS_TYPE_G_OBJECT_PATH, &seat,
712- G_TYPE_INVALID))
713+ if (!org_freedesktop_ConsoleKit_Session_get_seat_id (proxy, &seat, &error))
714 {
715 if (error)
716 {
717@@ -421,13 +439,22 @@
718 UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service);
719 GError *error = NULL;
720 guint uid;
721-
722- if (dbus_g_proxy_call (priv->session_proxy,
723- "GetUnixUser",
724- &error,
725- G_TYPE_INVALID,
726- G_TYPE_UINT, &uid,
727- G_TYPE_INVALID))
728+ DBusGProxy *session_proxy;
729+
730+ g_debug("Building session proxy for: %s", session_id);
731+ session_proxy = dbus_g_proxy_new_for_name_owner(priv->system_bus,
732+ CK_ADDR,
733+ session_id,
734+ CK_SESSION_IFACE,
735+ &error);
736+
737+ if (error != NULL) {
738+ g_warning("Unable to get CK Session proxy: %s", error->message);
739+ g_error_free(error);
740+ return FALSE;
741+ }
742+
743+ if (!org_freedesktop_ConsoleKit_Session_get_unix_user(session_proxy, &uid, &error))
744 {
745 if (error)
746 {
747@@ -435,6 +462,7 @@
748 g_error_free (error);
749 }
750
751+ g_object_unref(session_proxy);
752 return FALSE;
753 }
754
755@@ -443,6 +471,7 @@
756 *uidp = (uid_t)uid;
757 }
758
759+ g_object_unref(session_proxy);
760 return TRUE;
761 }
762
763@@ -455,19 +484,29 @@
764 GError *error = NULL;
765 gchar *seat = NULL;
766 gchar *xdisplay = NULL;
767+ DBusGProxy * session_proxy;
768 GList *l;
769
770- seat = get_seat_internal (service);
771-
772- if (!seat || !priv->seat || strcmp (seat, priv->seat) != 0)
773- return FALSE;
774-
775- if (!dbus_g_proxy_call (priv->session_proxy,
776- "GetX11Display",
777- &error,
778- G_TYPE_INVALID,
779- G_TYPE_STRING, &xdisplay,
780- G_TYPE_INVALID))
781+ session_proxy = dbus_g_proxy_new_for_name_owner(priv->system_bus,
782+ CK_ADDR,
783+ ssid,
784+ CK_SESSION_IFACE,
785+ &error);
786+
787+ if (error != NULL) {
788+ g_warning("Unable to get CK Session proxy: %s", error->message);
789+ g_error_free(error);
790+ return FALSE;
791+ }
792+
793+ seat = get_seat_internal (session_proxy);
794+
795+ if (!seat || !priv->seat || strcmp (seat, priv->seat) != 0) {
796+ g_object_unref(session_proxy);
797+ return FALSE;
798+ }
799+
800+ if (!org_freedesktop_ConsoleKit_Session_get_x11_display (session_proxy, &xdisplay, &error))
801 {
802 if (error)
803 {
804@@ -475,9 +514,12 @@
805 g_error_free (error);
806 }
807
808+ g_object_unref(session_proxy);
809 return FALSE;
810 }
811
812+ g_object_unref(session_proxy);
813+
814 if (!xdisplay || xdisplay[0] == '\0')
815 return FALSE;
816
817@@ -491,6 +533,10 @@
818 g_debug ("Adding session %s", ssid);
819
820 user->sessions = g_list_prepend (user->sessions, g_strdup (ssid));
821+
822+ if (user->menuitem != NULL) {
823+ dbusmenu_menuitem_property_set_bool(user->menuitem, USER_ITEM_PROP_LOGGED_IN, TRUE);
824+ }
825 }
826 else
827 {
828@@ -556,6 +602,17 @@
829 return;
830 }
831
832+ /* We need to special case guest here because it doesn't
833+ show up in the GDM user tables. */
834+ if (g_strcmp0("guest", pwent->pw_name) == 0) {
835+ if (priv->guest_item != NULL) {
836+ dbusmenu_menuitem_property_set_bool(priv->guest_item, USER_ITEM_PROP_LOGGED_IN, TRUE);
837+ }
838+ priv->guest_session_id = g_strdup(session_id);
839+ g_debug("Found guest session: %s", priv->guest_session_id);
840+ return;
841+ }
842+
843 user = g_hash_table_lookup (priv->users, pwent->pw_name);
844 if (!user)
845 {
846@@ -576,8 +633,17 @@
847 GList *l;
848
849 username = g_hash_table_lookup (priv->sessions, session_id);
850- if (!username)
851+ if (!username) {
852+ if (g_strcmp0(session_id, priv->guest_session_id) == 0) {
853+ g_debug("Removing guest session: %s", priv->guest_session_id);
854+ if (priv->guest_item != NULL) {
855+ dbusmenu_menuitem_property_set_bool(priv->guest_item, USER_ITEM_PROP_LOGGED_IN, FALSE);
856+ }
857+ g_free(priv->guest_session_id);
858+ priv->guest_session_id = NULL;
859+ }
860 return;
861+ }
862
863 user = g_hash_table_lookup (priv->users, username);
864 if (!user)
865@@ -592,6 +658,9 @@
866
867 g_free (l->data);
868 user->sessions = g_list_delete_link (user->sessions, l);
869+ if (user->menuitem != NULL && user->sessions == NULL) {
870+ dbusmenu_menuitem_property_set_bool(user->menuitem, USER_ITEM_PROP_LOGGED_IN, FALSE);
871+ }
872 }
873 else
874 {
875@@ -657,6 +726,7 @@
876 user->login_count = g_value_get_int (g_value_array_get_nth (values, 4));
877 user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5)));
878 user->real_name_conflict = FALSE;
879+ user->menuitem = NULL;
880
881 g_hash_table_insert (priv->users,
882 g_strdup (user->user_name),
883@@ -706,21 +776,16 @@
884 char *type = NULL;
885
886 if (!(proxy = dbus_g_proxy_new_for_name (priv->system_bus,
887- "org.freedesktop.ConsoleKit",
888+ CK_ADDR,
889 ssid,
890- "org.freedesktop.ConsoleKit.Session")))
891+ CK_SESSION_IFACE)))
892 {
893 g_warning ("Failed to get ConsoleKit proxy");
894
895 return FALSE;
896 }
897
898- if (!dbus_g_proxy_call (proxy,
899- "GetSessionType",
900- &error,
901- G_TYPE_INVALID,
902- G_TYPE_STRING, &type,
903- G_TYPE_INVALID))
904+ if (!org_freedesktop_ConsoleKit_Session_get_session_type (proxy, &type, &error))
905 {
906 g_warning ("Can't call GetSessionType: %s", error->message);
907 g_error_free (error);
908@@ -1005,61 +1070,21 @@
909 return g_hash_table_get_values (priv->users);
910 }
911
912+/* Activates the guest account if it can. */
913+gboolean
914+users_service_dbus_activate_guest_session (UsersServiceDbus *self)
915+{
916+ UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self);
917+ return org_gnome_DisplayManager_LocalDisplayFactory_switch_to_user(priv->gdm_local_proxy, "guest", NULL, NULL);
918+}
919+
920+/* Activates a specific user */
921 gboolean
922 users_service_dbus_activate_user_session (UsersServiceDbus *self,
923 UserData *user)
924 {
925- UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self);
926- DBusMessage *message = NULL;
927- DBusMessage *reply = NULL;
928- DBusError error;
929-
930- dbus_error_init (&error);
931-
932- if (!(message = dbus_message_new_method_call ("org.gnome.DisplayManager",
933- "/org/gnome/DisplayManager/LocalDisplayFactory",
934- "org.gnome.DisplayManager.LocalDisplayFactory",
935- "SwitchToUser")))
936- {
937- g_warning ("failed to create new message");
938- return FALSE;
939- }
940-
941- if (!dbus_message_append_args (message,
942- DBUS_TYPE_STRING, &user->user_name,
943- DBUS_TYPE_INVALID))
944- {
945- g_warning ("failed to append args");
946- return FALSE;
947- }
948-
949- if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus),
950- message,
951- -1,
952- &error)))
953- {
954- if (dbus_error_is_set (&error))
955- {
956- g_warning ("Failed to send message: %s", error.message);
957- dbus_error_free (&error);
958-
959- return FALSE;
960- }
961- }
962-
963- if (message)
964- {
965- dbus_message_unref (message);
966- }
967-
968- if (reply)
969- {
970- dbus_message_unref (reply);
971- }
972-
973- dbus_error_free (&error);
974-
975- return TRUE;
976+ UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self);
977+ return org_gnome_DisplayManager_LocalDisplayFactory_switch_to_user(priv->gdm_local_proxy, user->user_name, NULL, NULL);
978 }
979
980 gboolean
981@@ -1094,3 +1119,17 @@
982
983 return can_activate;
984 }
985+
986+/* Sets the menu item that represents the guest account */
987+void
988+users_service_dbus_set_guest_item (UsersServiceDbus * self, DbusmenuMenuitem * mi)
989+{
990+ UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self);
991+ priv->guest_item = mi;
992+
993+ if (priv->guest_session_id != NULL) {
994+ dbusmenu_menuitem_property_set_bool(priv->guest_item, USER_ITEM_PROP_LOGGED_IN, TRUE);
995+ }
996+
997+ return;
998+}
999
1000=== modified file 'src/users-service-dbus.h'
1001--- src/users-service-dbus.h 2010-03-02 22:13:22 +0000
1002+++ src/users-service-dbus.h 2010-03-18 03:33:27 +0000
1003@@ -22,6 +22,7 @@
1004
1005 #include <glib.h>
1006 #include <glib-object.h>
1007+#include <libdbusmenu-glib/menuitem.h>
1008
1009 G_BEGIN_DECLS
1010
1011@@ -47,7 +48,10 @@
1012
1013 GList *sessions;
1014
1015+ /* Whether the real name here conflicts with another in the system */
1016 gboolean real_name_conflict;
1017+ /* The menuitem representing this user if there is one. */
1018+ DbusmenuMenuitem * menuitem;
1019
1020 UsersServiceDbus *service;
1021 };
1022@@ -80,6 +84,9 @@
1023 gboolean users_service_dbus_can_activate_session (UsersServiceDbus *self);
1024 gboolean users_service_dbus_activate_user_session (UsersServiceDbus *self,
1025 UserData *user);
1026+gboolean users_service_dbus_activate_guest_session (UsersServiceDbus *self);
1027+void users_service_dbus_set_guest_item (UsersServiceDbus * self,
1028+ DbusmenuMenuitem * mi);
1029
1030 G_END_DECLS
1031

Subscribers

People subscribed via source and target branches