Merge lp:~donadigo/switchboard-plug-networking/page-in-deviceitem into lp:~elementary-pantheon/switchboard-plug-networking/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
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.
Revision history for this message
xapantu (xapantu) wrote :

There are several minor bugs, but I'm going to report them and we can fix them later.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Plug.vala'
--- src/Plug.vala 2015-09-11 12:46:58 +0000
+++ src/Plug.vala 2015-10-20 20:37:51 +0000
@@ -47,20 +47,24 @@
4747
4848
49 protected override void add_interface (WidgetNMInterface widget_interface) {49 protected override void add_interface (WidgetNMInterface widget_interface) {
50 device_list.add_device_to_list (widget_interface.device);50 device_list.add_device_to_list (widget_interface);
51 content.add(widget_interface);51
52 select_first ();
53 show_all ();
54 }
55
56 protected override void remove_interface (WidgetNMInterface widget_interface) {
57 device_list.remove_device_from_list (widget_interface.device);
58 content.remove (widget_interface);
52 59
60 select_first ();
61 show_all ();
62 }
63
64 private void select_first () {
53 if (network_interface.length () <= 1) {65 if (network_interface.length () <= 1) {
54 device_list.select_first_item ();66 device_list.select_first_item ();
55 }67 }
56 show_all ();
57 }
58
59 protected override void remove_interface (WidgetNMInterface widget_interface) {
60 device_list.remove_device_from_list (widget_interface.device);
61 content.remove(widget_interface);
62
63 show_all ();
64 }68 }
6569
66 protected override void build_ui () {70 protected override void build_ui () {
@@ -70,7 +74,7 @@
70 content = new Gtk.Stack ();74 content = new Gtk.Stack ();
7175
72 var sidebar = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);76 var sidebar = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
73 device_list = new Widgets.DeviceList (client);77 device_list = new Widgets.DeviceList ();
7478
75 footer = new Widgets.Footer (client);79 footer = new Widgets.Footer (client);
76 footer.hexpand = false;80 footer.hexpand = false;
@@ -109,34 +113,14 @@
109113
110 /* Main function to connect all the signals */114 /* Main function to connect all the signals */
111 private void connect_signals () {115 private void connect_signals () {
112 device_list.create_proxy_entry ();116 device_list.row_activated.connect ((row) => {
113117 if (!Utils.list_contains (content.get_children (), ((Widgets.DeviceItem) row).page)) {
114 var proxy_page = new Widgets.ProxyPage ();118 content.add (((Widgets.DeviceItem) row).page);
115 proxy_page.stack.set_visible_child_name ("configuration");
116
117 proxy_page.update_status_label.connect ((mode) => {
118 device_list.proxy.switch_status (null, mode);
119 });
120
121 proxy_page.update_mode ();
122
123 content.add_named (proxy_page, "proxy-page");
124 device_list.proxy.activate.connect (() => {
125 if (content.get_visible_child_name () != "proxy-page")
126 content.set_visible_child (proxy_page);
127
128 current_device = null;
129 });
130
131 device_list.row_changed.connect ((row) => {
132 NM.Device device = (row as Widgets.DeviceItem).get_item_device ();
133 foreach(var w in network_interface) {
134 if(w.is_device(device)) {
135 content.set_visible_child(w);
136 }
137 }119 }
120
121 content.visible_child = ((Widgets.DeviceItem) row).page;
138 });122 });
139123
140 device_list.show_no_devices.connect ((show) => {124 device_list.show_no_devices.connect ((show) => {
141 if (show) {125 if (show) {
142 content.set_visible_child (no_devices);126 content.set_visible_child (no_devices);
143127
=== modified file 'src/Utils.vala'
--- src/Utils.vala 2015-10-09 19:12:42 +0000
+++ src/Utils.vala 2015-10-20 20:37:51 +0000
@@ -1,21 +1,11 @@
1namespace Network.Utils {1namespace Network.Utils {
2 public static Polkit.Permission? permission = null;2 public enum ItemType {
33 DEVICE = 0,
4 public static Polkit.Permission? get_permission () {4 PROXY,
5 if (permission != null)5 INVALID
6 return permission;
7 try {
8 var user = Polkit.UnixUser.new_for_name (Environment.get_user_name ()) as Polkit.UnixUser;
9 permission = new Polkit.Permission.sync ("org.freedesktop.NetworkManager.settings.modify.hostname",
10 Polkit.UnixProcess.new_for_owner (Posix.getpid (), 0, user.get_uid ()));
11 return permission;
12 } catch (Error e) {
13 critical (e.message);
14 return null;
15 }
16 }6 }
177
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…")) {
19 var details_btn = new Gtk.Button.with_label (title);9 var details_btn = new Gtk.Button.with_label (title);
20 details_btn.clicked.connect (() => {10 details_btn.clicked.connect (() => {
21 new Granite.Services.SimpleCommand ("/usr/bin",11 new Granite.Services.SimpleCommand ("/usr/bin",
@@ -25,6 +15,16 @@
25 return details_btn;15 return details_btn;
26 }16 }
27 17
18 public bool list_contains (List list, List.G data) {
19 foreach (var unit in list.copy ()) {
20 if (unit == data) {
21 return true;
22 }
23 }
24
25 return false;
26 }
27
28 public string state_to_string (NM.DeviceState state) {28 public string state_to_string (NM.DeviceState state) {
29 switch (state) {29 switch (state) {
30 case NM.DeviceState.ACTIVATED:30 case NM.DeviceState.ACTIVATED:
3131
=== modified file 'src/Widgets/Device/DeviceItem.vala'
--- src/Widgets/Device/DeviceItem.vala 2015-10-08 19:04:34 +0000
+++ src/Widgets/Device/DeviceItem.vala 2015-10-20 20:37:51 +0000
@@ -22,7 +22,10 @@
2222
23namespace Network.Widgets {23namespace Network.Widgets {
24 public class DeviceItem : Gtk.ListBoxRow {24 public class DeviceItem : Gtk.ListBoxRow {
25 public bool special = false;25 public NM.Device? device = null;
26 public Gtk.Box? page = null;
27 public Utils.ItemType type;
28
26 public Gtk.Label row_description;29 public Gtk.Label row_description;
27 private Gtk.Image row_image;30 private Gtk.Image row_image;
28 private Gtk.Image status_image;31 private Gtk.Image status_image;
@@ -33,24 +36,23 @@
3336
34 private Gtk.Grid row_grid;37 private Gtk.Grid row_grid;
35 private Gtk.Label row_title;38 private Gtk.Label row_title;
36 public NM.Device device = null;
3739
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") {
39 this.special = _special;
40 this.title = _title;41 this.title = _title;
41 this.subtitle = _subtitle;42 this.subtitle = _subtitle;
42 this.icon_name = _icon_name;43 this.icon_name = _icon_name;
44 this.type = Utils.ItemType.INVALID;
4345
44 create_ui (icon_name);46 create_ui (icon_name);
45 }47 }
4648
47 public DeviceItem.from_device (NM.Device _device,49 public DeviceItem.from_interface (WidgetNMInterface iface,
48 string _icon_name = "network-wired",50 string _icon_name = "network-wired",
49 bool _special = false,
50 string _title = "") {51 string _title = "") {
51 this.special = _special;52 this.page = iface;
52 this.device = _device;53 this.device = iface.device;
5354 this.type = Utils.ItemType.DEVICE;
55
54 if (_title != "") {56 if (_title != "") {
55 this.title = _title;57 this.title = _title;
56 } else {58 } else {
5759
=== modified file 'src/Widgets/DeviceList.vala'
--- src/Widgets/DeviceList.vala 2015-10-08 19:04:34 +0000
+++ src/Widgets/DeviceList.vala 2015-10-20 20:37:51 +0000
@@ -22,7 +22,6 @@
2222
23namespace Network.Widgets {23namespace Network.Widgets {
24 public class DeviceList : Gtk.ListBox {24 public class DeviceList : Gtk.ListBox {
25 public signal void row_changed (Gtk.ListBoxRow row);
26 public signal void show_no_devices (bool show);25 public signal void show_no_devices (bool show);
27 26
28 public NM.Client client;27 public NM.Client client;
@@ -37,12 +36,11 @@
3736
38 private int wireless_item = 0;37 private int wireless_item = 0;
3938
40 public DeviceList (NM.Client _client) {39 public DeviceList () {
41 this.selection_mode = Gtk.SelectionMode.SINGLE;40 this.selection_mode = Gtk.SelectionMode.SINGLE;
42 this.activate_on_single_click = true; 41 this.activate_on_single_click = true;
43 this.set_header_func (update_headers);42 this.set_header_func (update_headers);
4443
45 client = _client;
46 items = new List<DeviceItem> ();44 items = new List<DeviceItem> ();
4745
48 settings_l = new Gtk.Label (_("Virtual"));46 settings_l = new Gtk.Label (_("Virtual"));
@@ -53,54 +51,42 @@
53 devices_l.get_style_context ().add_class ("h4");51 devices_l.get_style_context ().add_class ("h4");
54 devices_l.halign = Gtk.Align.START;52 devices_l.halign = Gtk.Align.START;
5553
56 this.row_selected.connect ((row) => {
57 if (row != null) {
58 if (row == proxy) {
59 proxy.activate ();
60 return;
61 }
62
63 if (wifi == null || row != wifi) {
64 row_changed (row);
65 } else if (wifi != null && row == wifi) {
66 wifi.activate ();
67 }
68 }
69 });
70
71 bool show = (items.length () > 0);54 bool show = (items.length () > 0);
72 this.show_no_devices (!show);55 this.show_no_devices (!show);
56 this.add_proxy ();
73 }57 }
7458
75 public void add_device_to_list (NM.Device device) {59
76 if (device.get_device_type () == NM.DeviceType.WIFI) {60 public void add_device_to_list (WidgetNMInterface iface) {
61 if (iface.device.get_device_type () == NM.DeviceType.WIFI) {
77 string title = _("Wireless");62 string title = _("Wireless");
78 if (wireless_item > 0) {63 if (wireless_item > 0) {
79 title += " " + wireless_item.to_string ();64 title += SUFFIX + wireless_item.to_string ();
80 }65 }
8166
82 item = new DeviceItem.from_device (device, "network-wireless", false, title); 67 item = new DeviceItem.from_interface (iface, "network-wireless", title);
83 wireless_item++;68 wireless_item++;
84 } else {69 } else {
8570
86 if (!device.get_managed ()) {71 if (!iface.device.get_managed ()) {
87 warning("Unmanaged device? probably something that has just been added…");72 warning ("Unmanaged device, probably something that has just been added.");
88 }73 }
89 if (device.get_iface ().has_prefix ("usb")) {74
90 item = new DeviceItem.from_device (device, "drive-removable-media");75 if (iface.device.get_iface ().has_prefix ("usb")) {
76 item = new DeviceItem.from_interface (iface, "drive-removable-media");
91 } else {77 } else {
92 item = new DeviceItem.from_device (device);78 item = new DeviceItem.from_interface (iface);
93 }79 }
94 }80 }
9581
96 items.append (item);82 items.append (item);
97 insert (item, (int)(items.length() - 1));83 insert (item, (int) items.length () - 1);
98 show_all ();84 show_all ();
99 }85 }
10086
101 public void remove_device_from_list (NM.Device device) {87 public void remove_device_from_list (NM.Device device) {
102 foreach (var list_item in items) {88 foreach (var list_item in items) {
103 if(list_item.device == device) {89 if (list_item.device == device) {
104 remove_row_from_list (list_item);90 remove_row_from_list (list_item);
105 break;91 break;
106 }92 }
@@ -114,18 +100,18 @@
114 this.select_row (this.get_row_at_index (0));100 this.select_row (this.get_row_at_index (0));
115 }101 }
116102
117 public void create_proxy_entry () {103 private void add_proxy () {
118 proxy = new DeviceItem (_("Proxy"), "", "preferences-system-network", true);104 proxy = new DeviceItem (_("Proxy"), "", "preferences-system-network");
105 proxy.page = new Widgets.ProxyPage (proxy);
106 proxy.type = Utils.ItemType.PROXY;
119 this.add (proxy);107 this.add (proxy);
120 }108 }
121
122 public void select_first_item () {109 public void select_first_item () {
123 var first_row = this.get_row_at_index (0);110 this.get_row_at_index (0).activate ();
124 this.select_row (first_row);
125 } 111 }
126112
127 private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) {113 private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) {
128 if (row == proxy) {114 if (((DeviceItem) row).type != Utils.ItemType.DEVICE) {
129 row.set_header (settings_l);115 row.set_header (settings_l);
130 } else if (row == items.nth_data (0)) {116 } else if (row == items.nth_data (0)) {
131 row.set_header (devices_l);117 row.set_header (devices_l);
132118
=== modified file 'src/Widgets/InfoBox.vala'
--- src/Widgets/InfoBox.vala 2015-09-11 12:46:58 +0000
+++ src/Widgets/InfoBox.vala 2015-10-20 20:37:51 +0000
@@ -27,7 +27,6 @@
27 private NM.Device device;27 private NM.Device device;
28 private DeviceItem? owner;28 private DeviceItem? owner;
2929
30 private string status_l = (_("Status:") + SUFFIX);
31 private string ipaddress_l = (_("IP Address:") + SUFFIX);30 private string ipaddress_l = (_("IP Address:") + SUFFIX);
32 private string mask_l = (_("Subnet mask:") + SUFFIX);31 private string mask_l = (_("Subnet mask:") + SUFFIX);
33 private string router_l = (_("Router:") + SUFFIX);32 private string router_l = (_("Router:") + SUFFIX);
3433
=== modified file 'src/Widgets/Proxy/ProxyPage.vala'
--- src/Widgets/Proxy/ProxyPage.vala 2015-10-08 19:04:34 +0000
+++ src/Widgets/Proxy/ProxyPage.vala 2015-10-20 20:37:51 +0000
@@ -3,7 +3,10 @@
3 public Gtk.Stack stack;3 public Gtk.Stack stack;
4 public signal void update_status_label (string mode);4 public signal void update_status_label (string mode);
55
6 public ProxyPage () {6 private DeviceItem owner;
7
8 public ProxyPage (DeviceItem _owner) {
9 this.owner = _owner;
7 this.orientation = Gtk.Orientation.VERTICAL;10 this.orientation = Gtk.Orientation.VERTICAL;
8 this.baseline_position = Gtk.BaselinePosition.CENTER;11 this.baseline_position = Gtk.BaselinePosition.CENTER;
9 this.margin_top = 20;12 this.margin_top = 20;
@@ -19,17 +22,19 @@
19 stack.add_titled (exceptions_page, "exceptions", _("Exceptions"));22 stack.add_titled (exceptions_page, "exceptions", _("Exceptions"));
20 stackswitcher.stack = stack;23 stackswitcher.stack = stack;
2124
22 proxy_settings.changed.connect (() => {25 proxy_settings.changed.connect (update_mode);
23 update_mode ();26
24 });27 update_mode ();
2528
26 this.add (stackswitcher);29 this.add (stackswitcher);
27 this.add (stack);30 this.add (stack);
28 this.show_all ();31 this.show_all ();
32
33 stack.visible_child = configuration_page;
29 }34 }
3035
31 public void update_mode () {36 public void update_mode () {
32 this.update_status_label (proxy_settings.mode);37 owner.switch_status (null, proxy_settings.mode);
33 }38 }
34 }39 }
35}40}

Subscribers

People subscribed via source and target branches

to all changes: