Merge lp:~donadigo/switchboard-plug-networking/page-in-deviceitem into lp:~elementary-pantheon/switchboard-plug-networking/trunk
- page-in-deviceitem
- Merge into trunk
Proposed by
Adam Bieńkowski
Status: | Merged |
---|---|
Approved by: | xapantu |
Approved revision: | 169 |
Merged at revision: | 170 |
Proposed branch: | lp:~donadigo/switchboard-plug-networking/page-in-deviceitem |
Merge into: | lp:~elementary-pantheon/switchboard-plug-networking/trunk |
Diff against target: |
357 lines (+79/-103) 6 files modified
src/Plug.vala (+22/-38) src/Utils.vala (+15/-15) src/Widgets/Device/DeviceItem.vala (+11/-9) src/Widgets/DeviceList.vala (+21/-35) src/Widgets/InfoBox.vala (+0/-1) src/Widgets/Proxy/ProxyPage.vala (+10/-5) |
To merge this branch: | bzr merge lp:~donadigo/switchboard-plug-networking/page-in-deviceitem |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
xapantu (community) | Approve | ||
Review via email: mp+275099@code.launchpad.net |
Commit message
* Soft-code page switching.
* Page variable directly in DeviceItem.
* Do not hardcode proxy item.
* Removed unused methods.
* ProxyPage: changed tabs to spaces.
* Code clean.
Description of the change
This is the new version of page-in-deviceitem refreshed for new revision.
***
The goal here is to remove as much hard-coded functions as possible. Creating page variable directly in the DeviceItem allows us to easily add and manage switching pages just by getting the variable from the device item. In consequence proxy page is no longer a "special" item but normal item that has it's page.
To post a comment you must log in.
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 2015-09-11 12:46:58 +0000 | |||
3 | +++ src/Plug.vala 2015-10-20 20:37:51 +0000 | |||
4 | @@ -47,20 +47,24 @@ | |||
5 | 47 | 47 | ||
6 | 48 | 48 | ||
7 | 49 | protected override void add_interface (WidgetNMInterface widget_interface) { | 49 | protected override void add_interface (WidgetNMInterface widget_interface) { |
10 | 50 | device_list.add_device_to_list (widget_interface.device); | 50 | device_list.add_device_to_list (widget_interface); |
11 | 51 | content.add(widget_interface); | 51 | |
12 | 52 | select_first (); | ||
13 | 53 | show_all (); | ||
14 | 54 | } | ||
15 | 55 | |||
16 | 56 | protected override void remove_interface (WidgetNMInterface widget_interface) { | ||
17 | 57 | device_list.remove_device_from_list (widget_interface.device); | ||
18 | 58 | content.remove (widget_interface); | ||
19 | 52 | 59 | ||
20 | 60 | select_first (); | ||
21 | 61 | show_all (); | ||
22 | 62 | } | ||
23 | 63 | |||
24 | 64 | private void select_first () { | ||
25 | 53 | if (network_interface.length () <= 1) { | 65 | if (network_interface.length () <= 1) { |
26 | 54 | device_list.select_first_item (); | 66 | device_list.select_first_item (); |
36 | 55 | } | 67 | } |
28 | 56 | show_all (); | ||
29 | 57 | } | ||
30 | 58 | |||
31 | 59 | protected override void remove_interface (WidgetNMInterface widget_interface) { | ||
32 | 60 | device_list.remove_device_from_list (widget_interface.device); | ||
33 | 61 | content.remove(widget_interface); | ||
34 | 62 | |||
35 | 63 | show_all (); | ||
37 | 64 | } | 68 | } |
38 | 65 | 69 | ||
39 | 66 | protected override void build_ui () { | 70 | protected override void build_ui () { |
40 | @@ -70,7 +74,7 @@ | |||
41 | 70 | content = new Gtk.Stack (); | 74 | content = new Gtk.Stack (); |
42 | 71 | 75 | ||
43 | 72 | var sidebar = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); | 76 | var sidebar = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); |
45 | 73 | device_list = new Widgets.DeviceList (client); | 77 | device_list = new Widgets.DeviceList (); |
46 | 74 | 78 | ||
47 | 75 | footer = new Widgets.Footer (client); | 79 | footer = new Widgets.Footer (client); |
48 | 76 | footer.hexpand = false; | 80 | footer.hexpand = false; |
49 | @@ -109,34 +113,14 @@ | |||
50 | 109 | 113 | ||
51 | 110 | /* Main function to connect all the signals */ | 114 | /* Main function to connect all the signals */ |
52 | 111 | private void connect_signals () { | 115 | private void connect_signals () { |
78 | 112 | device_list.create_proxy_entry (); | 116 | device_list.row_activated.connect ((row) => { |
79 | 113 | 117 | if (!Utils.list_contains (content.get_children (), ((Widgets.DeviceItem) row).page)) { | |
80 | 114 | var proxy_page = new Widgets.ProxyPage (); | 118 | content.add (((Widgets.DeviceItem) row).page); |
56 | 115 | proxy_page.stack.set_visible_child_name ("configuration"); | ||
57 | 116 | |||
58 | 117 | proxy_page.update_status_label.connect ((mode) => { | ||
59 | 118 | device_list.proxy.switch_status (null, mode); | ||
60 | 119 | }); | ||
61 | 120 | |||
62 | 121 | proxy_page.update_mode (); | ||
63 | 122 | |||
64 | 123 | content.add_named (proxy_page, "proxy-page"); | ||
65 | 124 | device_list.proxy.activate.connect (() => { | ||
66 | 125 | if (content.get_visible_child_name () != "proxy-page") | ||
67 | 126 | content.set_visible_child (proxy_page); | ||
68 | 127 | |||
69 | 128 | current_device = null; | ||
70 | 129 | }); | ||
71 | 130 | |||
72 | 131 | device_list.row_changed.connect ((row) => { | ||
73 | 132 | NM.Device device = (row as Widgets.DeviceItem).get_item_device (); | ||
74 | 133 | foreach(var w in network_interface) { | ||
75 | 134 | if(w.is_device(device)) { | ||
76 | 135 | content.set_visible_child(w); | ||
77 | 136 | } | ||
81 | 137 | } | 119 | } |
82 | 120 | |||
83 | 121 | content.visible_child = ((Widgets.DeviceItem) row).page; | ||
84 | 138 | }); | 122 | }); |
86 | 139 | 123 | ||
87 | 140 | device_list.show_no_devices.connect ((show) => { | 124 | device_list.show_no_devices.connect ((show) => { |
88 | 141 | if (show) { | 125 | if (show) { |
89 | 142 | content.set_visible_child (no_devices); | 126 | content.set_visible_child (no_devices); |
90 | 143 | 127 | ||
91 | === modified file 'src/Utils.vala' | |||
92 | --- src/Utils.vala 2015-10-09 19:12:42 +0000 | |||
93 | +++ src/Utils.vala 2015-10-20 20:37:51 +0000 | |||
94 | @@ -1,21 +1,11 @@ | |||
95 | 1 | namespace Network.Utils { | 1 | namespace Network.Utils { |
110 | 2 | public static Polkit.Permission? permission = null; | 2 | public enum ItemType { |
111 | 3 | 3 | DEVICE = 0, | |
112 | 4 | public static Polkit.Permission? get_permission () { | 4 | PROXY, |
113 | 5 | if (permission != null) | 5 | INVALID |
100 | 6 | return permission; | ||
101 | 7 | try { | ||
102 | 8 | var user = Polkit.UnixUser.new_for_name (Environment.get_user_name ()) as Polkit.UnixUser; | ||
103 | 9 | permission = new Polkit.Permission.sync ("org.freedesktop.NetworkManager.settings.modify.hostname", | ||
104 | 10 | Polkit.UnixProcess.new_for_owner (Posix.getpid (), 0, user.get_uid ())); | ||
105 | 11 | return permission; | ||
106 | 12 | } catch (Error e) { | ||
107 | 13 | critical (e.message); | ||
108 | 14 | return null; | ||
109 | 15 | } | ||
114 | 16 | } | 6 | } |
115 | 17 | 7 | ||
117 | 18 | public new Gtk.Button get_advanced_button_from_device (NM.Device? device, string title = _("Advanced Settings…")) { | 8 | public Gtk.Button get_advanced_button_from_device (NM.Device? device, string title = _("Advanced Settings…")) { |
118 | 19 | var details_btn = new Gtk.Button.with_label (title); | 9 | var details_btn = new Gtk.Button.with_label (title); |
119 | 20 | details_btn.clicked.connect (() => { | 10 | details_btn.clicked.connect (() => { |
120 | 21 | new Granite.Services.SimpleCommand ("/usr/bin", | 11 | new Granite.Services.SimpleCommand ("/usr/bin", |
121 | @@ -25,6 +15,16 @@ | |||
122 | 25 | return details_btn; | 15 | return details_btn; |
123 | 26 | } | 16 | } |
124 | 27 | 17 | ||
125 | 18 | public bool list_contains (List list, List.G data) { | ||
126 | 19 | foreach (var unit in list.copy ()) { | ||
127 | 20 | if (unit == data) { | ||
128 | 21 | return true; | ||
129 | 22 | } | ||
130 | 23 | } | ||
131 | 24 | |||
132 | 25 | return false; | ||
133 | 26 | } | ||
134 | 27 | |||
135 | 28 | public string state_to_string (NM.DeviceState state) { | 28 | public string state_to_string (NM.DeviceState state) { |
136 | 29 | switch (state) { | 29 | switch (state) { |
137 | 30 | case NM.DeviceState.ACTIVATED: | 30 | case NM.DeviceState.ACTIVATED: |
138 | 31 | 31 | ||
139 | === modified file 'src/Widgets/Device/DeviceItem.vala' | |||
140 | --- src/Widgets/Device/DeviceItem.vala 2015-10-08 19:04:34 +0000 | |||
141 | +++ src/Widgets/Device/DeviceItem.vala 2015-10-20 20:37:51 +0000 | |||
142 | @@ -22,7 +22,10 @@ | |||
143 | 22 | 22 | ||
144 | 23 | namespace Network.Widgets { | 23 | namespace Network.Widgets { |
145 | 24 | public class DeviceItem : Gtk.ListBoxRow { | 24 | public class DeviceItem : Gtk.ListBoxRow { |
147 | 25 | public bool special = false; | 25 | public NM.Device? device = null; |
148 | 26 | public Gtk.Box? page = null; | ||
149 | 27 | public Utils.ItemType type; | ||
150 | 28 | |||
151 | 26 | public Gtk.Label row_description; | 29 | public Gtk.Label row_description; |
152 | 27 | private Gtk.Image row_image; | 30 | private Gtk.Image row_image; |
153 | 28 | private Gtk.Image status_image; | 31 | private Gtk.Image status_image; |
154 | @@ -33,24 +36,23 @@ | |||
155 | 33 | 36 | ||
156 | 34 | private Gtk.Grid row_grid; | 37 | private Gtk.Grid row_grid; |
157 | 35 | private Gtk.Label row_title; | 38 | private Gtk.Label row_title; |
158 | 36 | public NM.Device device = null; | ||
159 | 37 | 39 | ||
162 | 38 | public DeviceItem (string _title, string _subtitle, string _icon_name = "network-wired", bool _special = false) { | 40 | public DeviceItem (string _title, string _subtitle, string _icon_name = "network-wired") { |
161 | 39 | this.special = _special; | ||
163 | 40 | this.title = _title; | 41 | this.title = _title; |
164 | 41 | this.subtitle = _subtitle; | 42 | this.subtitle = _subtitle; |
165 | 42 | this.icon_name = _icon_name; | 43 | this.icon_name = _icon_name; |
166 | 44 | this.type = Utils.ItemType.INVALID; | ||
167 | 43 | 45 | ||
168 | 44 | create_ui (icon_name); | 46 | create_ui (icon_name); |
169 | 45 | } | 47 | } |
170 | 46 | 48 | ||
172 | 47 | public DeviceItem.from_device (NM.Device _device, | 49 | public DeviceItem.from_interface (WidgetNMInterface iface, |
173 | 48 | string _icon_name = "network-wired", | 50 | string _icon_name = "network-wired", |
174 | 49 | bool _special = false, | ||
175 | 50 | string _title = "") { | 51 | string _title = "") { |
179 | 51 | this.special = _special; | 52 | this.page = iface; |
180 | 52 | this.device = _device; | 53 | this.device = iface.device; |
181 | 53 | 54 | this.type = Utils.ItemType.DEVICE; | |
182 | 55 | |||
183 | 54 | if (_title != "") { | 56 | if (_title != "") { |
184 | 55 | this.title = _title; | 57 | this.title = _title; |
185 | 56 | } else { | 58 | } else { |
186 | 57 | 59 | ||
187 | === modified file 'src/Widgets/DeviceList.vala' | |||
188 | --- src/Widgets/DeviceList.vala 2015-10-08 19:04:34 +0000 | |||
189 | +++ src/Widgets/DeviceList.vala 2015-10-20 20:37:51 +0000 | |||
190 | @@ -22,7 +22,6 @@ | |||
191 | 22 | 22 | ||
192 | 23 | namespace Network.Widgets { | 23 | namespace Network.Widgets { |
193 | 24 | public class DeviceList : Gtk.ListBox { | 24 | public class DeviceList : Gtk.ListBox { |
194 | 25 | public signal void row_changed (Gtk.ListBoxRow row); | ||
195 | 26 | public signal void show_no_devices (bool show); | 25 | public signal void show_no_devices (bool show); |
196 | 27 | 26 | ||
197 | 28 | public NM.Client client; | 27 | public NM.Client client; |
198 | @@ -37,12 +36,11 @@ | |||
199 | 37 | 36 | ||
200 | 38 | private int wireless_item = 0; | 37 | private int wireless_item = 0; |
201 | 39 | 38 | ||
203 | 40 | public DeviceList (NM.Client _client) { | 39 | public DeviceList () { |
204 | 41 | this.selection_mode = Gtk.SelectionMode.SINGLE; | 40 | this.selection_mode = Gtk.SelectionMode.SINGLE; |
205 | 42 | this.activate_on_single_click = true; | 41 | this.activate_on_single_click = true; |
206 | 43 | this.set_header_func (update_headers); | 42 | this.set_header_func (update_headers); |
207 | 44 | 43 | ||
208 | 45 | client = _client; | ||
209 | 46 | items = new List<DeviceItem> (); | 44 | items = new List<DeviceItem> (); |
210 | 47 | 45 | ||
211 | 48 | settings_l = new Gtk.Label (_("Virtual")); | 46 | settings_l = new Gtk.Label (_("Virtual")); |
212 | @@ -53,54 +51,42 @@ | |||
213 | 53 | devices_l.get_style_context ().add_class ("h4"); | 51 | devices_l.get_style_context ().add_class ("h4"); |
214 | 54 | devices_l.halign = Gtk.Align.START; | 52 | devices_l.halign = Gtk.Align.START; |
215 | 55 | 53 | ||
216 | 56 | this.row_selected.connect ((row) => { | ||
217 | 57 | if (row != null) { | ||
218 | 58 | if (row == proxy) { | ||
219 | 59 | proxy.activate (); | ||
220 | 60 | return; | ||
221 | 61 | } | ||
222 | 62 | |||
223 | 63 | if (wifi == null || row != wifi) { | ||
224 | 64 | row_changed (row); | ||
225 | 65 | } else if (wifi != null && row == wifi) { | ||
226 | 66 | wifi.activate (); | ||
227 | 67 | } | ||
228 | 68 | } | ||
229 | 69 | }); | ||
230 | 70 | |||
231 | 71 | bool show = (items.length () > 0); | 54 | bool show = (items.length () > 0); |
232 | 72 | this.show_no_devices (!show); | 55 | this.show_no_devices (!show); |
233 | 56 | this.add_proxy (); | ||
234 | 73 | } | 57 | } |
235 | 74 | 58 | ||
238 | 75 | public void add_device_to_list (NM.Device device) { | 59 | |
239 | 76 | if (device.get_device_type () == NM.DeviceType.WIFI) { | 60 | public void add_device_to_list (WidgetNMInterface iface) { |
240 | 61 | if (iface.device.get_device_type () == NM.DeviceType.WIFI) { | ||
241 | 77 | string title = _("Wireless"); | 62 | string title = _("Wireless"); |
242 | 78 | if (wireless_item > 0) { | 63 | if (wireless_item > 0) { |
244 | 79 | title += " " + wireless_item.to_string (); | 64 | title += SUFFIX + wireless_item.to_string (); |
245 | 80 | } | 65 | } |
246 | 81 | 66 | ||
248 | 82 | item = new DeviceItem.from_device (device, "network-wireless", false, title); | 67 | item = new DeviceItem.from_interface (iface, "network-wireless", title); |
249 | 83 | wireless_item++; | 68 | wireless_item++; |
250 | 84 | } else { | 69 | } else { |
251 | 85 | 70 | ||
254 | 86 | if (!device.get_managed ()) { | 71 | if (!iface.device.get_managed ()) { |
255 | 87 | warning("Unmanaged device? probably something that has just been added…"); | 72 | warning ("Unmanaged device, probably something that has just been added."); |
256 | 88 | } | 73 | } |
259 | 89 | if (device.get_iface ().has_prefix ("usb")) { | 74 | |
260 | 90 | item = new DeviceItem.from_device (device, "drive-removable-media"); | 75 | if (iface.device.get_iface ().has_prefix ("usb")) { |
261 | 76 | item = new DeviceItem.from_interface (iface, "drive-removable-media"); | ||
262 | 91 | } else { | 77 | } else { |
264 | 92 | item = new DeviceItem.from_device (device); | 78 | item = new DeviceItem.from_interface (iface); |
265 | 93 | } | 79 | } |
266 | 94 | } | 80 | } |
267 | 95 | 81 | ||
268 | 96 | items.append (item); | 82 | items.append (item); |
270 | 97 | insert (item, (int)(items.length() - 1)); | 83 | insert (item, (int) items.length () - 1); |
271 | 98 | show_all (); | 84 | show_all (); |
272 | 99 | } | 85 | } |
273 | 100 | 86 | ||
274 | 101 | public void remove_device_from_list (NM.Device device) { | 87 | public void remove_device_from_list (NM.Device device) { |
275 | 102 | foreach (var list_item in items) { | 88 | foreach (var list_item in items) { |
277 | 103 | if(list_item.device == device) { | 89 | if (list_item.device == device) { |
278 | 104 | remove_row_from_list (list_item); | 90 | remove_row_from_list (list_item); |
279 | 105 | break; | 91 | break; |
280 | 106 | } | 92 | } |
281 | @@ -114,18 +100,18 @@ | |||
282 | 114 | this.select_row (this.get_row_at_index (0)); | 100 | this.select_row (this.get_row_at_index (0)); |
283 | 115 | } | 101 | } |
284 | 116 | 102 | ||
287 | 117 | public void create_proxy_entry () { | 103 | private void add_proxy () { |
288 | 118 | proxy = new DeviceItem (_("Proxy"), "", "preferences-system-network", true); | 104 | proxy = new DeviceItem (_("Proxy"), "", "preferences-system-network"); |
289 | 105 | proxy.page = new Widgets.ProxyPage (proxy); | ||
290 | 106 | proxy.type = Utils.ItemType.PROXY; | ||
291 | 119 | this.add (proxy); | 107 | this.add (proxy); |
292 | 120 | } | 108 | } |
293 | 121 | |||
294 | 122 | public void select_first_item () { | 109 | public void select_first_item () { |
297 | 123 | var first_row = this.get_row_at_index (0); | 110 | this.get_row_at_index (0).activate (); |
296 | 124 | this.select_row (first_row); | ||
298 | 125 | } | 111 | } |
299 | 126 | 112 | ||
300 | 127 | private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) { | 113 | private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) { |
302 | 128 | if (row == proxy) { | 114 | if (((DeviceItem) row).type != Utils.ItemType.DEVICE) { |
303 | 129 | row.set_header (settings_l); | 115 | row.set_header (settings_l); |
304 | 130 | } else if (row == items.nth_data (0)) { | 116 | } else if (row == items.nth_data (0)) { |
305 | 131 | row.set_header (devices_l); | 117 | row.set_header (devices_l); |
306 | 132 | 118 | ||
307 | === modified file 'src/Widgets/InfoBox.vala' | |||
308 | --- src/Widgets/InfoBox.vala 2015-09-11 12:46:58 +0000 | |||
309 | +++ src/Widgets/InfoBox.vala 2015-10-20 20:37:51 +0000 | |||
310 | @@ -27,7 +27,6 @@ | |||
311 | 27 | private NM.Device device; | 27 | private NM.Device device; |
312 | 28 | private DeviceItem? owner; | 28 | private DeviceItem? owner; |
313 | 29 | 29 | ||
314 | 30 | private string status_l = (_("Status:") + SUFFIX); | ||
315 | 31 | private string ipaddress_l = (_("IP Address:") + SUFFIX); | 30 | private string ipaddress_l = (_("IP Address:") + SUFFIX); |
316 | 32 | private string mask_l = (_("Subnet mask:") + SUFFIX); | 31 | private string mask_l = (_("Subnet mask:") + SUFFIX); |
317 | 33 | private string router_l = (_("Router:") + SUFFIX); | 32 | private string router_l = (_("Router:") + SUFFIX); |
318 | 34 | 33 | ||
319 | === modified file 'src/Widgets/Proxy/ProxyPage.vala' | |||
320 | --- src/Widgets/Proxy/ProxyPage.vala 2015-10-08 19:04:34 +0000 | |||
321 | +++ src/Widgets/Proxy/ProxyPage.vala 2015-10-20 20:37:51 +0000 | |||
322 | @@ -3,7 +3,10 @@ | |||
323 | 3 | public Gtk.Stack stack; | 3 | public Gtk.Stack stack; |
324 | 4 | public signal void update_status_label (string mode); | 4 | public signal void update_status_label (string mode); |
325 | 5 | 5 | ||
327 | 6 | public ProxyPage () { | 6 | private DeviceItem owner; |
328 | 7 | |||
329 | 8 | public ProxyPage (DeviceItem _owner) { | ||
330 | 9 | this.owner = _owner; | ||
331 | 7 | this.orientation = Gtk.Orientation.VERTICAL; | 10 | this.orientation = Gtk.Orientation.VERTICAL; |
332 | 8 | this.baseline_position = Gtk.BaselinePosition.CENTER; | 11 | this.baseline_position = Gtk.BaselinePosition.CENTER; |
333 | 9 | this.margin_top = 20; | 12 | this.margin_top = 20; |
334 | @@ -19,17 +22,19 @@ | |||
335 | 19 | stack.add_titled (exceptions_page, "exceptions", _("Exceptions")); | 22 | stack.add_titled (exceptions_page, "exceptions", _("Exceptions")); |
336 | 20 | stackswitcher.stack = stack; | 23 | stackswitcher.stack = stack; |
337 | 21 | 24 | ||
341 | 22 | proxy_settings.changed.connect (() => { | 25 | proxy_settings.changed.connect (update_mode); |
342 | 23 | update_mode (); | 26 | |
343 | 24 | }); | 27 | update_mode (); |
344 | 25 | 28 | ||
345 | 26 | this.add (stackswitcher); | 29 | this.add (stackswitcher); |
346 | 27 | this.add (stack); | 30 | this.add (stack); |
347 | 28 | this.show_all (); | 31 | this.show_all (); |
348 | 32 | |||
349 | 33 | stack.visible_child = configuration_page; | ||
350 | 29 | } | 34 | } |
351 | 30 | 35 | ||
352 | 31 | public void update_mode () { | 36 | public void update_mode () { |
354 | 32 | this.update_status_label (proxy_settings.mode); | 37 | owner.switch_status (null, proxy_settings.mode); |
355 | 33 | } | 38 | } |
356 | 34 | } | 39 | } |
357 | 35 | } | 40 | } |
There are several minor bugs, but I'm going to report them and we can fix them later.