Merge lp:~charlesk/gnome-control-center/icon-policy into lp:~ubuntu-desktop/gnome-control-center/ubuntu

Proposed by Charles Kerr
Status: Merged
Merged at revision: 348
Proposed branch: lp:~charlesk/gnome-control-center/icon-policy
Merge into: lp:~ubuntu-desktop/gnome-control-center/ubuntu
Diff against target: 178 lines (+165/-0)
2 files modified
debian/patches/97_power_icon_policy.patch (+164/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~charlesk/gnome-control-center/icon-policy
Reviewer Review Type Date Requested Status
Sebastien Bacher Needs Fixing
Review via email: mp+93064@code.launchpad.net

Description of the change

add a combobox to let user choose when the power indicator will be visible.

spec: https://wiki.ubuntu.com/Power#Power_settings
ticket: https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/811769

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thank you for your work there, could you handle the case where the schemas is missing there? it's different from gnome-bluetooth where the schemas was coming from the same source, the issue is that we patch gnome-control-center at the moment but the same gnome-control-center might be used under gnome-shell by users who have no indicators installed. Ideally the new ui wouldn't be displayed under non unity session but I think we can resolve that case later, the other indicators have the same issue

We will also need an indicator-power release out before uploading the gnome-control-center patch because of the schemas depends

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

Seb, the missing-schema case (and hiding the new UI if it's missing) is handled now in revision 348.

348. By Charles Kerr

handle missing schema case as requested by seb128

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'debian/patches/97_power_icon_policy.patch'
--- debian/patches/97_power_icon_policy.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/97_power_icon_policy.patch 2012-02-14 22:27:17 +0000
@@ -0,0 +1,164 @@
1--- a/panels/power/cc-power-panel.c
2+++ b/panels/power/cc-power-panel.c
3@@ -39,6 +39,7 @@
4 {
5 GSettings *lock_settings;
6 GSettings *gsd_settings;
7+ GSettings *indicator_settings;
8 GCancellable *cancellable;
9 GtkBuilder *builder;
10 GDBusProxy *proxy;
11@@ -83,6 +84,8 @@
12 {
13 CcPowerPanelPrivate *priv = CC_POWER_PANEL (object)->priv;
14
15+ g_clear_object (&priv->indicator_settings);
16+
17 if (priv->gsd_settings)
18 {
19 g_object_unref (priv->gsd_settings);
20@@ -566,6 +569,80 @@
21 gtk_widget_set_visible (widget, has_batteries && has_lid);
22 }
23
24+/* these keys are from com.canonical.indicator.power */
25+static const char * icon_policy_keys[] = { "present", "charge", "never" };
26+static const int icon_policy_key_count = G_N_ELEMENTS(icon_policy_keys);
27+
28+static gboolean
29+icon_policy_map_settings_to_value (GValue * value,
30+ GVariant * variant,
31+ gpointer user_data G_GNUC_UNUSED)
32+{
33+ int i;
34+ int index;
35+ const char * needle;
36+
37+ index = -1;
38+ needle = g_variant_get_string (variant, NULL);
39+ for (i=0; i<icon_policy_key_count; ++i)
40+ if (!g_strcmp0 (needle, icon_policy_keys[i]))
41+ index = i;
42+
43+ g_value_set_int (value, index);
44+ return TRUE;
45+}
46+
47+static GVariant*
48+icon_policy_map_value_to_settings (const GValue * value,
49+ const GVariantType * expected_type,
50+ gpointer user_data G_GNUC_UNUSED)
51+{
52+ GVariant * ret;
53+
54+ const int i = g_value_get_int (value);
55+ if (0<=i && i<icon_policy_key_count)
56+ ret = g_variant_new_string (icon_policy_keys[i]);
57+ else
58+ ret = NULL;
59+
60+ return ret;
61+}
62+
63+static gboolean
64+schema_exists (const char * name)
65+{
66+ int i;
67+ const char * const * schemas = g_settings_list_schemas ();
68+
69+ for (i=0; schemas && schemas[i]; i++)
70+ if (!g_strcmp0 (name, schemas[i]))
71+ return TRUE;
72+
73+ return FALSE;
74+}
75+
76+static void
77+icon_policy_init (CcPowerPanel *self)
78+{
79+ const char * schema = "com.canonical.indicator.power";
80+
81+ if (schema_exists (schema))
82+ {
83+ GtkWidget * widget = WID (self->priv->builder, "combobox_icon_policy");
84+ self->priv->indicator_settings = g_settings_new (schema);
85+ g_settings_bind_with_mapping (self->priv->indicator_settings, "icon-policy",
86+ widget, "active",
87+ G_SETTINGS_BIND_DEFAULT,
88+ icon_policy_map_settings_to_value,
89+ icon_policy_map_value_to_settings,
90+ NULL, NULL);
91+ }
92+ else
93+ {
94+ gtk_widget_hide (WID (self->priv->builder, "row_icon_policy"));
95+ }
96+}
97+
98 static void
99 cc_power_panel_init (CcPowerPanel *self)
100 {
101@@ -664,6 +741,8 @@
102
103 widget = WID (self->priv->builder, "vbox_power");
104 gtk_widget_reparent (widget, (GtkWidget *) self);
105+
106+ icon_policy_init (self);
107 }
108
109 void
110--- a/panels/power/power.ui
111+++ b/panels/power/power.ui
112@@ -432,6 +432,52 @@
113 <property name="position">1</property>
114 </packing>
115 </child>
116+ <child>
117+ <object class="GtkBox" id="row_icon_policy">
118+ <property name="visible">True</property>
119+ <property name="can_focus">False</property>
120+ <property name="spacing">9</property>
121+ <child>
122+ <object class="GtkLabel" id="label_icon_policy">
123+ <property name="visible">True</property>
124+ <property name="can_focus">False</property>
125+ <property name="xalign">1</property>
126+ <property name="label" translatable="yes">Show battery status in the _menu bar:</property>
127+ <property name="mnemonic_widget">combobox_icon_policy</property>
128+ <property name="use_underline">True</property>
129+ <property name="track_visited_links">False</property>
130+ </object>
131+ <packing>
132+ <property name="expand">False</property>
133+ <property name="fill">False</property>
134+ <property name="position">0</property>
135+ </packing>
136+ </child>
137+ <child>
138+ <object class="GtkComboBoxText" id="combobox_icon_policy">
139+ <property name="visible">True</property>
140+ <property name="can_focus">False</property>
141+ <property name="entry_text_column">0</property>
142+ <property name="id_column">1</property>
143+ <items>
144+ <item translatable="yes">When a battery is present</item>
145+ <item translatable="yes">When a battery is charging / in use</item>
146+ <item translatable="yes">Never</item>
147+ </items>
148+ </object>
149+ <packing>
150+ <property name="expand">False</property>
151+ <property name="fill">True</property>
152+ <property name="position">1</property>
153+ </packing>
154+ </child>
155+ </object>
156+ <packing>
157+ <property name="expand">False</property>
158+ <property name="fill">True</property>
159+ <property name="position">2</property>
160+ </packing>
161+ </child>
162 </object>
163 </child>
164 </object>
0165
=== modified file 'debian/patches/series'
--- debian/patches/series 2012-02-10 16:04:48 +0000
+++ debian/patches/series 2012-02-14 22:27:17 +0000
@@ -28,4 +28,5 @@
2894_git_adding_shortcuts.patch2894_git_adding_shortcuts.patch
2995_git_ctrlw_shortcut.patch2995_git_ctrlw_shortcut.patch
3096_sound_nua_panel.patch3096_sound_nua_panel.patch
3197_power_icon_policy.patch
31git_extra_keywords.patch32git_extra_keywords.patch

Subscribers

People subscribed via source and target branches