Merge lp:~jconti/unity-greeter/hide-hidden-indicators into lp:~robert-ancell/unity-greeter/trunk

Proposed by Jason Conti
Status: Merged
Approved by: Robert Ancell
Approved revision: 138
Merged at revision: 152
Proposed branch: lp:~jconti/unity-greeter/hide-hidden-indicators
Merge into: lp:~robert-ancell/unity-greeter/trunk
Diff against target: 97 lines (+67/-12)
1 file modified
src/user-list.vala (+67/-12)
To merge this branch: bzr merge lp:~jconti/unity-greeter/hide-hidden-indicators
Reviewer Review Type Date Requested Status
Robert Ancell Pending
Review via email: mp+73455@code.launchpad.net

Description of the change

indicator-power hides its entry image if no battery information is available. This branch adds support to show/hide an indicator menuitem based on the visibility of its entry image/label. Uses a method similar to the indicator-applet.

This is related to lp:830175

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Hi Jason,

Thanks very much for that!

Unity greeter requires contributions to be give under the Canonical contributor agreement [1]. Could you please have a look at that and sign it if you agree?

Thanks again,
--Robert

[1] http://www.canonical.com/contributors

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/user-list.vala'
2--- src/user-list.vala 2011-08-30 04:41:21 +0000
3+++ src/user-list.vala 2011-08-30 22:08:24 +0000
4@@ -39,6 +39,64 @@
5 }
6 }
7
8+private class IndicatorMenuItem : Gtk.MenuItem
9+{
10+ private Gtk.HBox _hbox;
11+ private Gtk.Image _image = null;
12+ private Gtk.Label _label = null;
13+
14+ public IndicatorMenuItem ()
15+ {
16+ this._hbox = new Gtk.HBox (false, 3);
17+ this.add (this._hbox);
18+ this._hbox.show ();
19+ }
20+
21+ public Gtk.Image entry_image
22+ {
23+ get { return this._image; }
24+ set
25+ {
26+ if (value != null && this._image == null)
27+ {
28+ this._image = value;
29+ this._image.show.connect (this.visibility_changed_cb);
30+ this._image.hide.connect (this.visibility_changed_cb);
31+ this._hbox.pack_start (this._image, false, false, 0);
32+ }
33+ }
34+ }
35+
36+ public Gtk.Label entry_label
37+ {
38+ get { return this._label; }
39+ set
40+ {
41+ if (value != null && this._label == null)
42+ {
43+ this._label = value;
44+ this._label.show.connect (this.visibility_changed_cb);
45+ this._label.hide.connect (this.visibility_changed_cb);
46+ this._hbox.pack_start (this._label, false, false, 0);
47+ }
48+ }
49+ }
50+
51+ public bool has_visible_child ()
52+ {
53+ return (this._image != null && this._image.get_visible ()) ||
54+ (this._label != null && this._label.get_visible ());
55+ }
56+
57+ public void visibility_changed_cb (Gtk.Widget widget)
58+ {
59+ if (this.has_visible_child ())
60+ this.show ();
61+ else
62+ this.hide ();
63+ }
64+}
65+
66 private class SessionMenuItem : Gtk.RadioMenuItem
67 {
68 public string session_name;
69@@ -403,20 +461,17 @@
70
71 private void indicator_added_cb (Indicator.ObjectEntry entry)
72 {
73- var menuitem = new Gtk.MenuItem ();
74- menuitem.show ();
75-
76- var hbox = new Gtk.HBox (false, 3);
77- menuitem.add (hbox);
78- hbox.show ();
79-
80- if (entry.image != null)
81- hbox.pack_start (entry.image, false, false, 0);
82- if (entry.label != null)
83- hbox.pack_start (entry.label, false, false, 0);
84+ var menuitem = new IndicatorMenuItem ();
85+
86+ menuitem.entry_image = entry.image;
87+ menuitem.entry_label = entry.label;
88+
89 if (entry.menu != null)
90 menuitem.submenu = entry.menu;
91-
92+
93+ if (menuitem.has_visible_child ())
94+ menuitem.show();
95+
96 menubar.insert (menuitem, (int) menubar.get_children ().length () - 2);
97 }
98

Subscribers

People subscribed via source and target branches

to all changes: