Skip to content

Commit 9c4de5a

Browse files
committed
EtherInterface: use SettingsToggle
Remove extra whitespace
1 parent 3cdf0ee commit 9c4de5a

1 file changed

Lines changed: 32 additions & 34 deletions

File tree

src/Widgets/EtherInterface.vala

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,26 @@
1717
*/
1818

1919
public class Network.EtherInterface : Network.WidgetNMInterface {
20-
private Gtk.ToggleButton ethernet_item;
20+
private SettingsToggle ethernet_item;
21+
private SimpleAction toggle_ethernet_action;
2122

2223
public EtherInterface (NM.Client nm_client, NM.Device? _device) {
2324
device = _device;
2425

25-
ethernet_item = new Gtk.ToggleButton () {
26-
halign = Gtk.Align.CENTER,
27-
image = new Gtk.Image.from_icon_name ("panel-network-wired-connected-symbolic", Gtk.IconSize.MENU)
26+
ethernet_item = new SettingsToggle () {
27+
action_name = "ethernet.toggle",
28+
icon_name = "panel-network-wired-connected-symbolic",
29+
settings_uri = "settings://network",
30+
text = display_title
2831
};
2932

30-
var label = new Gtk.Label (display_title) {
31-
ellipsize = Pango.EllipsizeMode.MIDDLE,
32-
max_width_chars = 16
33-
};
34-
label.get_style_context ().add_class (Granite.STYLE_CLASS_SMALL_LABEL);
35-
36-
hexpand = true;
37-
orientation = Gtk.Orientation.VERTICAL;
38-
spacing = 3;
3933
add (ethernet_item);
40-
add (label);
4134

42-
bind_property ("display-title", label, "label");
35+
bind_property ("display-title", ethernet_item, "text");
4336

44-
ethernet_item.toggled.connect (() => {
45-
debug ("update");
46-
if (ethernet_item.active && device.get_state () == NM.DeviceState.DISCONNECTED) {
37+
toggle_ethernet_action = new SimpleAction.stateful ("toggle", null, new Variant.boolean (true));
38+
toggle_ethernet_action.activate.connect (() => {
39+
if (device.get_state () == NM.DeviceState.DISCONNECTED) {
4740
var connection = NM.SimpleConnection.new ();
4841
var remote_array = device.get_available_connections ();
4942
if (remote_array == null) {
@@ -52,13 +45,18 @@ public class Network.EtherInterface : Network.WidgetNMInterface {
5245
connection.set_path (remote_array.get (0).get_path ());
5346
nm_client.activate_connection_async.begin (connection, device, null, null, null);
5447
}
55-
} else if (!ethernet_item.active && device.get_state () == NM.DeviceState.ACTIVATED) {
48+
} else if (device.get_state () == NM.DeviceState.ACTIVATED) {
5649
device.disconnect_async.begin (null, () => { debug ("Successfully disconnected."); });
5750
}
5851
});
5952

6053
update ();
6154
device.state_changed.connect (update);
55+
56+
var action_group = new SimpleActionGroup ();
57+
action_group.add_action (toggle_ethernet_action);
58+
59+
insert_action_group ("ethernet", action_group);
6260
}
6361

6462
private void update () {
@@ -67,23 +65,23 @@ public class Network.EtherInterface : Network.WidgetNMInterface {
6765
case NM.DeviceState.UNMANAGED:
6866
case NM.DeviceState.DEACTIVATING:
6967
case NM.DeviceState.FAILED:
70-
sensitive = false;
71-
ethernet_item.active = false;
68+
toggle_ethernet_action.set_state (new Variant.boolean (false));
69+
toggle_ethernet_action.set_enabled (false);
7270
state = State.FAILED;
73-
((Gtk.Image ) ethernet_item.image).icon_name = "panel-network-wired-error-symbolic";
71+
ethernet_item.icon_name = "panel-network-wired-error-symbolic";
7472
break;
7573

7674
case NM.DeviceState.UNAVAILABLE:
77-
sensitive = false;
78-
ethernet_item.active = false;
75+
toggle_ethernet_action.set_state (new Variant.boolean (false));
76+
toggle_ethernet_action.set_enabled (false);
7977
state = State.WIRED_UNPLUGGED;
80-
((Gtk.Image ) ethernet_item.image).icon_name = "panel-network-wired-no-route-symbolic";
78+
ethernet_item.icon_name = "panel-network-wired-no-route-symbolic";
8179
break;
8280
case NM.DeviceState.DISCONNECTED:
83-
sensitive = true;
84-
ethernet_item.active = false;
81+
toggle_ethernet_action.set_state (new Variant.boolean (false));
82+
toggle_ethernet_action.set_enabled (true);
8583
state = State.WIRED_UNPLUGGED;
86-
((Gtk.Image ) ethernet_item.image).icon_name = "panel-network-wired-offline-symbolic";
84+
ethernet_item.icon_name = "panel-network-wired-offline-symbolic";
8785
break;
8886

8987
case NM.DeviceState.PREPARE:
@@ -92,17 +90,17 @@ public class Network.EtherInterface : Network.WidgetNMInterface {
9290
case NM.DeviceState.IP_CONFIG:
9391
case NM.DeviceState.IP_CHECK:
9492
case NM.DeviceState.SECONDARIES:
95-
sensitive = true;
96-
ethernet_item.active = true;
93+
toggle_ethernet_action.set_enabled (true);
94+
toggle_ethernet_action.set_state (new Variant.boolean (true));
9795
state = State.CONNECTING_WIRED;
98-
((Gtk.Image ) ethernet_item.image).icon_name = "panel-network-wired-acquiring-symbolic";
96+
ethernet_item.icon_name = "panel-network-wired-acquiring-symbolic";
9997
break;
10098

10199
case NM.DeviceState.ACTIVATED:
102-
sensitive = true;
103-
ethernet_item.active = true;
100+
toggle_ethernet_action.set_enabled (true);
101+
toggle_ethernet_action.set_state (new Variant.boolean (true));
104102
state = State.CONNECTED_WIRED;
105-
((Gtk.Image ) ethernet_item.image).icon_name = "panel-network-wired-connected-symbolic-symbolic";
103+
ethernet_item.icon_name = "panel-network-wired-connected-symbolic-symbolic";
106104
break;
107105
}
108106
}

0 commit comments

Comments
 (0)