Merge lp:~evfool/switchboard-plug-power/lp1312470 into lp:~elementary-apps/switchboard-plug-power/trunk

Proposed by Robert Roth
Status: Merged
Approved by: Robert Roth
Approved revision: 127
Merged at revision: 119
Proposed branch: lp:~evfool/switchboard-plug-power/lp1312470
Merge into: lp:~elementary-apps/switchboard-plug-power/trunk
Diff against target: 187 lines (+98/-18)
1 file modified
src/Plug.vala (+98/-18)
To merge this branch: bzr merge lp:~evfool/switchboard-plug-power/lp1312470
Reviewer Review Type Date Requested Status
David Gomes (community) Approve
Danielle Foré Approve
Review via email: mp+224034@code.launchpad.net

Commit message

Added brightness slider and dim switch (lp:1312470)

Description of the change

The branch has the following changes to fix lp:1312470:
* added brightness slider (from Brightness and Lock panel)
* added dim screen when idle switch (from Brightness and Lock panel)
* moved the comboboxes appearing in both panels of the stack (Battery and Plugged in) out of the stack, to have only one instance of each

To post a comment you must log in.
Revision history for this message
Cody Garver (codygarver) wrote :

Adjusting the brightness does not affect my laptop even though the functions keys for it do. And if I leave the plug it resets the scale.

Revision history for this message
Robert Roth (evfool) wrote :

@Cody Garver: Could you please check the Screen interface on the /org/gnome/SettingsDaemon/Power object path on the org.gnome.SettingsDaemon.Power session bus? (I have used D-Feet to check this) Does it have a Brightness property? Strangely it works on my laptop, but will try with a fresh Freya install too.

Revision history for this message
Robert Roth (evfool) wrote :

@Cody: nevermind, I have found that the Brightness property was introduced with G-S-D 3.10, so will have to add an ifdef G-S-D<3.10 for the "current" gnome-settings-daemon in Freya (I'm running elementary dailies + gnome3-staging).

Revision history for this message
Danielle Foré (danrabbit) wrote :

Robert can we left align that switch? It feels a little weird all the way on the other side of the screen ;p

Also can we right align all those labels? (brightness, dim, sleep, suspend, etc)

review: Needs Fixing
Revision history for this message
Robert Roth (evfool) wrote :

@danrabbit: fixed as requested.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Oh yeah!

review: Approve
125. By Robert Roth

More tabs instead of spaces

126. By Robert Roth

Correct tabs indentation

Revision history for this message
David Gomes (davidgomes) :
127. By Robert Roth

Fixed last indentation issue

Revision history for this message
Robert Roth (evfool) wrote :

Updated branch indentation based on comments.

Revision history for this message
David Gomes (davidgomes) wrote :

Approving the code, I can't really build this to test it. Getting a ton of Gee errors.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Plug.vala'
2--- src/Plug.vala 2014-03-06 20:46:00 +0000
3+++ src/Plug.vala 2014-06-23 20:26:16 +0000
4@@ -3,6 +3,15 @@
5 GLib.Settings settings;
6 Gtk.Box stack_container;
7
8+ [DBus (name = "org.gnome.SettingsDaemon.Power.Screen")]
9+
10+ interface PowerSettings : GLib.Object {
11+ public abstract uint GetPercentage () throws IOError;
12+ public abstract uint SetPercentage (uint percentage) throws IOError;
13+ // use the Brightness property after updateing g-s-d to 3.10 or above
14+ // public abstract int Brightness {get; set; }
15+ }
16+
17 class ComboBox : Gtk.ComboBoxText {
18
19 public Gtk.Label label;
20@@ -17,6 +26,7 @@
21 this.key = key;
22 this.label = new Gtk.Label (label);
23 this.label.halign = Gtk.Align.END;
24+ this.label.xalign = 1.0f;
25
26 this.append_text (_("Suspend"));
27 this.append_text (_("Shutdown"));
28@@ -44,6 +54,9 @@
29
30 public class Plug : Switchboard.Plug {
31
32+ private PowerSettings screen;
33+ private Gtk.SizeGroup label_size;
34+
35 public Plug () {
36 Object (category: Category.HARDWARE,
37 code_name: "system-pantheon-power",
38@@ -52,7 +65,13 @@
39 icon: "preferences-system-power");
40
41 settings = new GLib.Settings ("org.gnome.settings-daemon.plugins.power");
42-
43+ try {
44+ screen = Bus.get_proxy_sync (BusType.SESSION,
45+ "org.gnome.SettingsDaemon",
46+ "/org/gnome/SettingsDaemon/Power");
47+ } catch (IOError e) {
48+ warning ("Failed to get settings daemon for brightness setting");
49+ }
50 }
51
52 public override Gtk.Widget get_widget () {
53@@ -82,8 +101,11 @@
54
55 void setup_ui () {
56 stack_container = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
57+ label_size = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
58+
59 var plug_grid = create_notebook_pages ("ac");
60 var battery_grid = create_notebook_pages ("battery");
61+ var common_settings = create_common_settings ();
62 var stack = new Gtk.Stack ();
63 var stack_switcher = new Gtk.StackSwitcher ();
64 stack_switcher.halign = Gtk.Align.CENTER;
65@@ -92,9 +114,78 @@
66 stack.add_titled (battery_grid, "battery", _("Battery Power"));
67 stack_container.pack_start(stack_switcher, false, false, 0);
68 stack_container.pack_start(stack, true, true, 0);
69+ stack_container.pack_end (common_settings);
70 stack_container.margin = 12;
71 stack_container.show_all ();
72 }
73+
74+ private Gtk.Grid create_common_settings () {
75+ var grid = new Gtk.Grid ();
76+ grid.margin = 12;
77+ grid.column_spacing = 12;
78+ grid.row_spacing = 12;
79+
80+ var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
81+ separator.vexpand = true;
82+ separator.valign = Gtk.Align.END;
83+ grid.attach (separator, 0, 0, 2, 1);
84+
85+ var brightness_label = new Gtk.Label (_("Screen brightness:"));
86+ brightness_label.xalign = 1.0f;
87+ label_size.add_widget (brightness_label);
88+ brightness_label.halign = Gtk.Align.END;
89+
90+ var scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0, 100, 10);
91+ scale.set_draw_value (false);
92+ scale.hexpand = true;
93+ scale.width_request = 480;
94+
95+ var dim_label = new Gtk.Label (_("Dim screen when inactive:"));
96+ dim_label.xalign = 1.0f;
97+ var dim_switch = new Gtk.Switch ();
98+ dim_switch.halign = Gtk.Align.START;
99+
100+ settings.bind ("idle-dim", dim_switch, "active", SettingsBindFlags.DEFAULT);
101+
102+ try {
103+ // scale.set_value (screen.Brightness);
104+ scale.set_value (screen.GetPercentage ());
105+ } catch (Error e) {
106+ warning ("Brightness setter not available, hiding brightness settings");
107+ brightness_label.no_show_all = true;
108+ scale.no_show_all = true;
109+ dim_label.no_show_all = true;
110+ dim_switch.no_show_all = true;
111+ }
112+ scale.value_changed.connect (() => {
113+ var val = (int) scale.get_value ();
114+ try {
115+ // screen.Brightness = val;
116+ screen.SetPercentage (val);
117+ } catch (IOError ioe) {
118+ // ignore, because if we have GetPercentage, we have SetPercentage
119+ // otherwise the scale won't be visible to change
120+ }
121+ });
122+
123+ grid.attach (brightness_label, 0, 1, 1, 1);
124+ grid.attach (scale, 1, 1, 1, 1);
125+
126+ grid.attach (dim_label, 0, 2, 1, 1);
127+ grid.attach (dim_switch, 1, 2, 1, 1);
128+
129+ string[] labels = {_("Sleep button:"), _("Suspend button:"), _("Hibernate button:"), _("Power button:")};
130+ string[] keys = {"button-sleep", "button-suspend", "button-hibernate", "button-power"};
131+
132+ for (int i = 0; i < labels.length; i++) {
133+ var box = new Power.ComboBox (labels[i], keys[i]);
134+ grid.attach (box.label, 0, i+3, 1, 1);
135+ label_size.add_widget (box.label);
136+ grid.attach (box, 1, i+3, 1, 1);
137+ }
138+
139+ return grid;
140+ }
141
142 private Gtk.Grid create_notebook_pages (string type) {
143 var grid = new Gtk.Grid ();
144@@ -103,6 +194,8 @@
145 grid.row_spacing = 12;
146
147 var scale_label = new Gtk.Label (_("Put the computer to sleep when inactive:"));
148+ scale_label.xalign = 1.0f;
149+ label_size.add_widget (scale_label);
150 var scale_settings = @"sleep-inactive-$type-timeout";
151
152 var scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0, 4000, 300);
153@@ -136,30 +229,17 @@
154 if (type != "ac") {
155 var critical_box = new ComboBox (_("When battery power is critically low:"), "critical-battery-action");
156 grid.attach (critical_box.label, 0, 2, 1, 1);
157+ label_size.add_widget (critical_box.label);
158 grid.attach (critical_box, 1, 2, 1, 1);
159 }
160
161- var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
162- separator.vexpand = true;
163- separator.valign = Gtk.Align.END;
164- grid.attach (separator, 0, 3, 2, 1);
165-
166- string[] labels = {_("Sleep button:"), _("Suspend button:"), _("Hibernate button:"), _("Power button:")};
167- string[] keys = {"button-sleep", "button-suspend", "button-hibernate", "button-power"};
168-
169- for (int i = 0; i < labels.length; i++) {
170- var box = new Power.ComboBox (labels[i], keys[i]);
171- grid.attach (box.label, 0, i+4, 1, 1);
172- grid.attach (box, 1, i+4, 1, 1);
173- }
174-
175 return grid;
176 }
177 }
178 }
179
180 public Switchboard.Plug get_plug (Module module) {
181- debug ("Activating Power plug");
182- var plug = new Power.Plug ();
183- return plug;
184+ debug ("Activating Power plug");
185+ var plug = new Power.Plug ();
186+ return plug;
187 }

Subscribers

People subscribed via source and target branches

to all changes: