Skip to content

Commit 26581d8

Browse files
danirabbitzeebok
andauthored
Pages set status (#398)
* Page: set status_type * get status from page * Deviceitems can only be constructed from page * fix VPN * Fix hotspot * simpler --------- Co-authored-by: Ryan Kornheisl <ryan@skarva.tech>
1 parent 16ea3e8 commit 26581d8

7 files changed

Lines changed: 82 additions & 80 deletions

File tree

src/MainView.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public class Network.MainView : Gtk.Box {
3535
virtual_header = new Granite.HeaderLabel (_("Virtual"));
3636
devices_header = new Granite.HeaderLabel (_("Devices"));
3737

38-
var proxy = new Widgets.DeviceItem (_("Proxy"), "preferences-system-network") {
38+
var proxy_page = new Widgets.ProxyPage ();
39+
var proxy = new Widgets.DeviceItem.from_page (proxy_page) {
3940
item_type = VIRTUAL
4041
};
41-
proxy.page = new Widgets.ProxyPage (proxy);
4242

4343
vpn_page = new VPNPage ();
4444
var vpn = new Widgets.DeviceItem.from_page (vpn_page) {

src/Utils.vala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ namespace Network {
8181
return true;
8282
}
8383

84-
public enum CustomMode {
85-
PROXY_NONE = 0,
86-
PROXY_MANUAL,
87-
PROXY_AUTO,
88-
HOTSPOT_ENABLED,
89-
HOTSPOT_DISABLED,
90-
INVALID
91-
}
92-
9384
public enum ItemType {
9485
DEVICE = 0,
9586
VIRTUAL,

src/Views/HotspotPage.vala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,13 @@
203203
var root_iface_is_hotspot = Utils.get_device_is_hotspot (root_iface.wifi_device);
204204
if (root_iface_is_hotspot) {
205205
state = NM.DeviceState.ACTIVATED;
206+
status_type = SUCCESS;
206207
} else {
207208
state = NM.DeviceState.DISCONNECTED;
209+
status_type = OFFLINE;
208210
}
211+
212+
status = Utils.state_to_string (state);
209213
}
210214

211215
protected override void update_switch () {

src/Views/ProxyPage.vala

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ namespace Network.Widgets {
2222
public Gtk.Stack stack;
2323
public signal void update_status_label (string mode);
2424

25-
public DeviceItem owner { get; construct; }
2625

27-
public ProxyPage (DeviceItem _owner) {
26+
public ProxyPage () {
2827
Object (
2928
activatable: true,
3029
title: _("Proxy"),
31-
icon: new ThemedIcon ("preferences-system-network"),
32-
owner: _owner
30+
icon: new ThemedIcon ("preferences-system-network")
3331
);
3432

3533
}
@@ -82,26 +80,23 @@ namespace Network.Widgets {
8280
}
8381

8482
private void update_mode () {
85-
var mode = Utils.CustomMode.INVALID;
8683
switch (Network.Plug.proxy_settings.get_string ("mode")) {
8784
case "none":
88-
mode = Utils.CustomMode.PROXY_NONE;
85+
status = _("Disabled");
8986
status_switch.active = false;
87+
status_type = OFFLINE;
9088
break;
9189
case "manual":
92-
mode = Utils.CustomMode.PROXY_MANUAL;
90+
status = _("Enabled (manual mode)");
9391
status_switch.active = true;
92+
status_type = SUCCESS;
9493
break;
9594
case "auto":
96-
mode = Utils.CustomMode.PROXY_AUTO;
95+
status = _("Enabled (auto mode)");
9796
status_switch.active = true;
98-
break;
99-
default:
100-
mode = Utils.CustomMode.INVALID;
97+
status_type = SUCCESS;
10198
break;
10299
}
103-
104-
owner.switch_status (mode);
105100
}
106101
}
107102
}

src/Views/VPNPage.vala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,22 @@ public class Network.VPNPage : Network.Widgets.Page {
164164
}
165165
}
166166

167-
update_switch ();
167+
switch (state) {
168+
case ACTIVATED:
169+
status_type = SUCCESS;
170+
break;
171+
case DISCONNECTED:
172+
status_type = OFFLINE;
173+
break;
174+
case FAILED:
175+
status_type = ERROR;
176+
break;
177+
default:
178+
status_type = WARNING;
179+
break;
180+
}
181+
182+
status = Utils.state_to_string (state);
168183
}
169184

170185
protected override void update_switch () {

src/Widgets/DeviceItem.vala

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@
1919

2020
namespace Network.Widgets {
2121
public class DeviceItem : Gtk.ListBoxRow {
22+
public Switchboard.SettingsPage.StatusType status_type {
23+
set {
24+
switch (value) {
25+
case ERROR:
26+
status_image.icon_name = "emblem-error";
27+
break;
28+
case OFFLINE:
29+
status_image.icon_name = "emblem-disabled";
30+
break;
31+
case SUCCESS:
32+
status_image.icon_name = "emblem-enabled";
33+
break;
34+
case WARNING:
35+
status_image.icon_name = "emblem-warning";
36+
break;
37+
case NONE:
38+
status_image.clear ();
39+
break;
40+
}
41+
}
42+
}
43+
2244
public NM.Device? device { get; construct; default = null; }
2345
public Widgets.Page? page { get; set; default = null; }
2446
public string title { get; set; default = ""; }
@@ -28,13 +50,6 @@ namespace Network.Widgets {
2850

2951
private Gtk.Image status_image;
3052

31-
public DeviceItem (string title, string icon_name) {
32-
Object (
33-
title: title,
34-
icon: new ThemedIcon (icon_name)
35-
);
36-
}
37-
3853
public DeviceItem.from_page (Widgets.Page page, string icon_name = "network-wired") {
3954
Object (
4055
device: page.device,
@@ -45,11 +60,8 @@ namespace Network.Widgets {
4560

4661
page.bind_property ("title", this, "title", SYNC_CREATE);
4762
page.bind_property ("icon", this, "icon", SYNC_CREATE);
48-
49-
switch_status (Utils.CustomMode.INVALID, page.state);
50-
page.notify["state"].connect (() => {
51-
switch_status (Utils.CustomMode.INVALID, page.state);
52-
});
63+
page.bind_property ("status-type", this, "status-type", SYNC_CREATE);
64+
page.bind_property ("status", this, "subtitle", SYNC_CREATE);
5365
}
5466

5567
construct {
@@ -70,8 +82,9 @@ namespace Network.Widgets {
7082
halign = Gtk.Align.START,
7183
valign = Gtk.Align.START
7284
};
85+
row_description.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);
7386

74-
status_image = new Gtk.Image.from_icon_name ("user-available") {
87+
status_image = new Gtk.Image () {
7588
halign = Gtk.Align.END,
7689
valign = Gtk.Align.END
7790
};
@@ -92,47 +105,5 @@ namespace Network.Widgets {
92105
bind_property ("subtitle", row_description, "label");
93106
bind_property ("icon", row_image, "gicon");
94107
}
95-
96-
public void switch_status (Utils.CustomMode custom_mode, NM.DeviceState? state = null) {
97-
if (state != null) {
98-
switch (state) {
99-
case NM.DeviceState.ACTIVATED:
100-
status_image.icon_name = "user-available";
101-
break;
102-
case NM.DeviceState.DISCONNECTED:
103-
status_image.icon_name = "user-offline";
104-
break;
105-
case NM.DeviceState.FAILED:
106-
status_image.icon_name = "user-busy";
107-
break;
108-
default:
109-
status_image.icon_name = "user-away";
110-
break;
111-
}
112-
113-
if (device is NM.DeviceWifi && state == NM.DeviceState.UNAVAILABLE) {
114-
subtitle = _("Disabled");
115-
} else {
116-
subtitle = Utils.state_to_string (state);
117-
}
118-
} else if (custom_mode != Utils.CustomMode.INVALID) {
119-
switch (custom_mode) {
120-
case Utils.CustomMode.PROXY_NONE:
121-
subtitle = _("Disabled");
122-
status_image.icon_name = "user-offline";
123-
break;
124-
case Utils.CustomMode.PROXY_MANUAL:
125-
subtitle = _("Enabled (manual mode)");
126-
status_image.icon_name = "user-available";
127-
break;
128-
case Utils.CustomMode.PROXY_AUTO:
129-
subtitle = _("Enabled (auto mode)");
130-
status_image.icon_name = "user-available";
131-
break;
132-
}
133-
}
134-
135-
subtitle = "<span font_size='small'>" + subtitle + "</span>";
136-
}
137108
}
138109
}

src/Widgets/Page.vala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,39 @@ namespace Network.Widgets {
4949

5050
get_uuid ();
5151
device.state_changed.connect_after (() => {
52+
update_status ();
5253
get_uuid ();
5354
});
55+
56+
update_status ();
5457
}
5558

5659
show_end_title_buttons = true;
5760
}
5861

62+
private void update_status () {
63+
switch (device.state) {
64+
case ACTIVATED:
65+
status_type = SUCCESS;
66+
break;
67+
case DISCONNECTED:
68+
status_type = OFFLINE;
69+
break;
70+
case FAILED:
71+
status_type = ERROR;
72+
break;
73+
default:
74+
status_type = WARNING;
75+
break;
76+
}
77+
78+
if (device is NM.DeviceWifi && state == UNAVAILABLE) {
79+
status = _("Disabled");
80+
} else {
81+
status = Utils.state_to_string (device.state);
82+
}
83+
}
84+
5985
public virtual void update () {
6086
if (info_box != null) {
6187
string sent_bytes, received_bytes;

0 commit comments

Comments
 (0)