Merge lp:~diegoprovinciani/switchboard-plug-power/1383209 into lp:~elementary-apps/switchboard-plug-power/trunk

Proposed by Diego Provinciani
Status: Merged
Approved by: Danielle Foré
Approved revision: 330
Merged at revision: 329
Proposed branch: lp:~diegoprovinciani/switchboard-plug-power/1383209
Merge into: lp:~elementary-apps/switchboard-plug-power/trunk
Diff against target: 133 lines (+48/-32)
2 files modified
src/Interfaces.vala (+25/-25)
src/Plug.vala (+23/-7)
To merge this branch: bzr merge lp:~diegoprovinciani/switchboard-plug-power/1383209
Reviewer Review Type Date Requested Status
Adam Bieńkowski (community) code Needs Fixing
Danielle Foré Needs Fixing
Review via email: mp+299001@code.launchpad.net

Commit message

Brightness slider update when changing brightness via keyboard shortcut

Description of the change

Added a mechanism to conect to signal emited when the brightness property on dbus is changed.

To test it, build and install the project, open the switchboard and then power plug. Press the brightness keyboard shortcut.
You can also try change the brightness changing the slider position with the pointer and with the direction keys on keyboard.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Please revert all the file permissions changes

review: Needs Fixing
326. By Diego Provinciani

Reverted all the file permissions

327. By Diego Provinciani

Reverted all the file permissions

Revision history for this message
Diego Provinciani (diegoprovinciani) wrote :

All file permissions were restored.

On dom, jul 3, 2016 at 10:53 , Daniel Fore <email address hidden> wrote:
> Review: Needs Fixing
>
> Please revert all the file permissions changes
> --
> https://code.launchpad.net/~diegoprovinciani/switchboard-plug-power/1383209/+merge/299001
> You are the owner of
> lp:~diegoprovinciani/switchboard-plug-power/1383209.

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Some minor things about the code:
- Some lines aren't correctly idented (look diff).

- code style: "string []" should be strip down to just: "string[]"

- I do not like how the UpowerProperties variable is named: "screen_signal". It suggests it's a signal, but it's not. I would suggest maybe to change it to just "upower_properties"?

- code style: we do not use upper case in methods: change "on_screen_signal_PropertiesChanged" to "on_screen_signal_properties_changed".

- Connecting the PropertiesChanged signal could be simplified: just replace it like this:
screen_signal.PropertiesChanged.connect (on_screen_signal_properties_changed);

- In method on_screen_signal_PropertiesChanged: there's no guarantee that "Brightness" property changed and it can be null, perhaps you could use this on the beggining of the method:

if (!changed_properties.contains ("Brightness")) {
   return;
}

review: Needs Fixing (code)
328. By Diego Provinciani

Fixed all code style suggestions

329. By Diego Provinciani

Fixed all code style suggestions

Revision history for this message
Diego Provinciani (diegoprovinciani) wrote :

All the suggestions has been fixed and the project has been tested again, checking the correct behavior.

Revision history for this message
Corentin Noël (tintou) wrote :

You never need to implement org.freedesktop.DBus.Properties
See here for an example about how to handle invalidated properties the better way:
http://bazaar.launchpad.net/~wingpanel-devs/wingpanel-indicator-bluetooth/trunk/view/head:/src/Services/Manager.vala#L64

330. By Diego Provinciani

Refactorized property signal to detect brightness changes

Revision history for this message
Diego Provinciani (diegoprovinciani) wrote :

The mechanism to detect the signal generated when the brightness property change has been refactored as Corentin Noël has been suggested.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Interfaces.vala'
2--- src/Interfaces.vala 2016-06-03 22:30:14 +0000
3+++ src/Interfaces.vala 2016-07-07 04:28:03 +0000
4@@ -21,7 +21,7 @@
5 public const string DBUS_UPOWER_NAME = "org.freedesktop.UPower";
6 public const string DBUS_UPOWER_PATH = "/org/freedesktop/UPower";
7
8- [DBus (name = "org.gnome.SettingsDaemon.Power.Screen")]
9+ [DBus (name = "org.gnome.SettingsDaemon.Power.Screen")]
10 interface PowerSettings : GLib.Object {
11 #if OLD_GSD
12 public abstract uint GetPercentage () throws IOError;
13@@ -32,28 +32,28 @@
14 #endif
15 }
16
17- [DBus (name = "org.freedesktop.UPower.Device")]
18- interface UpowerDevice : Object {
19- public signal void Changed ();
20- public abstract void Refresh () throws IOError;
21- public abstract bool Online { owned get; private set; }
22- public abstract bool PowerSupply { owned get; private set; }
23- public abstract bool IsPresent { owned get; private set; }
24- public abstract uint Type { owned get; private set; }
25- }
26-
27-
28- [DBus (name = "org.freedesktop.UPower")]
29- interface Upower : Object {
30- public signal void Changed ();
31- public abstract bool OnBattery { owned get; private set; }
32- public abstract bool LowOnBattery { owned get; private set; }
33- public abstract ObjectPath[] EnumerateDevices () throws IOError;
34- }
35-
36- [DBus (name = "org.freedesktop.DBus.Properties")]
37- public interface UpowerProperties : Object {
38- public abstract Variant Get (string interface, string propname) throws IOError;
39- public abstract void Set (string interface, string propname, Variant value) throws IOError;
40- }
41+ [DBus (name = "org.freedesktop.UPower.Device")]
42+ interface UpowerDevice : Object {
43+ public signal void Changed ();
44+ public abstract void Refresh () throws IOError;
45+ public abstract bool Online { owned get; private set; }
46+ public abstract bool PowerSupply { owned get; private set; }
47+ public abstract bool IsPresent { owned get; private set; }
48+ public abstract uint Type { owned get; private set; }
49+ }
50+
51+
52+ [DBus (name = "org.freedesktop.UPower")]
53+ interface Upower : Object {
54+ public signal void Changed ();
55+ public abstract bool OnBattery { owned get; private set; }
56+ public abstract bool LowOnBattery { owned get; private set; }
57+ public abstract ObjectPath[] EnumerateDevices () throws IOError;
58+ }
59+
60+ [DBus (name = "org.freedesktop.DBus.Properties")]
61+ public interface UpowerProperties : Object {
62+ public abstract Variant Get (string interface, string propname) throws IOError;
63+ public abstract void Set (string interface, string propname, Variant value) throws IOError;
64+ }
65 }
66
67=== modified file 'src/Plug.vala'
68--- src/Plug.vala 2016-06-05 12:08:06 +0000
69+++ src/Plug.vala 2016-07-07 04:28:03 +0000
70@@ -34,6 +34,7 @@
71 private CliCommunicator cli_communicator;
72 private Gtk.Image lock_image;
73 private Gtk.Image lock_image2;
74+ private Gtk.Scale scale;
75
76 private const string NO_PERMISSION_STRING = _("You do not have permission to change this");
77 private const string LAPTOP_DETECT_BINARY = "/usr/sbin/laptop-detect";
78@@ -139,8 +140,8 @@
79
80 private void connect_dbus () {
81 try {
82- screen = Bus.get_proxy_sync (BusType.SESSION,
83- "org.gnome.SettingsDaemon", "/org/gnome/SettingsDaemon/Power");
84+ screen = Bus.get_proxy_sync (BusType.SESSION, "org.gnome.SettingsDaemon",
85+ "/org/gnome/SettingsDaemon/Power", DBusProxyFlags.GET_INVALIDATED_PROPERTIES);
86 } catch (IOError e) {
87 warning ("Failed to get settings daemon for brightness setting");
88 }
89@@ -218,17 +219,15 @@
90
91 settings.bind ("ambient-enabled", als_switch, "active", SettingsBindFlags.DEFAULT);
92
93- var scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0, 100, 10);
94+ scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0, 100, 10);
95 scale.draw_value = false;
96 scale.hexpand = true;
97 scale.width_request = 480;
98
99 scale.set_value (screen.Brightness);
100
101- scale.value_changed.connect (() => {
102- var val = (int) scale.get_value ();
103- screen.Brightness = val;
104- });
105+ scale.value_changed.connect (on_scale_value_changed);
106+ (screen as DBusProxy).g_properties_changed.connect (on_screen_properties_changed);
107
108 main_grid.attach (brightness_label, 0, 0, 1, 1);
109 main_grid.attach (scale, 1, 0, 1, 1);
110@@ -258,6 +257,23 @@
111
112 return main_grid;
113 }
114+
115+ private void on_scale_value_changed () {
116+ var val = (int) scale.get_value ();
117+ (screen as DBusProxy).g_properties_changed.disconnect (on_screen_properties_changed);
118+ screen.Brightness = val;
119+ (screen as DBusProxy).g_properties_changed.connect (on_screen_properties_changed);
120+ }
121+
122+ private void on_screen_properties_changed (Variant changed_properties, string[] invalidated_properties) {
123+ var changed_brightness = changed_properties.lookup_value("Brightness", new VariantType("i"));
124+ if (changed_brightness != null) {
125+ var val = screen.Brightness;
126+ scale.value_changed.disconnect (on_scale_value_changed);
127+ scale.set_value (val);
128+ scale.value_changed.connect (on_scale_value_changed);
129+ }
130+ }
131
132 private Gtk.Grid create_notebook_pages (bool ac) {
133 var grid = new Gtk.Grid ();

Subscribers

People subscribed via source and target branches

to all changes: