diff --git a/src/Views/WifiPage.vala b/src/Views/WifiPage.vala index 950eceac..1c2c5e44 100644 --- a/src/Views/WifiPage.vala +++ b/src/Views/WifiPage.vala @@ -25,8 +25,6 @@ public class Network.WifiInterface : Network.Widgets.Page { protected Gtk.ScrolledWindow scrolled; protected Gtk.Box hotspot_mode_alert; protected Gtk.Revealer top_revealer; - protected Gtk.Button? disconnect_btn; - protected Gtk.Button? settings_btn; protected Gtk.Button? hidden_btn; public WifiInterface (NM.Device device) { @@ -181,9 +179,7 @@ public class Network.WifiInterface : Network.Widgets.Page { /* Sometimes network manager sends a (fake?) AP without a valid ssid. */ if (!found && ap.ssid != null) { - var item = new WifiMenuItem (ap) { - visible = true - }; + var item = new WifiMenuItem (ap); item.user_action.connect (wifi_activate_cb); wifi_list.append (item); @@ -263,14 +259,6 @@ public class Network.WifiInterface : Network.Widgets.Page { public override void update () { bool sensitive = (device.get_state () == NM.DeviceState.ACTIVATED); - if (disconnect_btn != null) { - disconnect_btn.sensitive = sensitive; - } - - if (settings_btn != null) { - settings_btn.sensitive = sensitive; - } - if (hidden_btn != null) { hidden_btn.sensitive = (state != NM.DeviceState.UNAVAILABLE); } @@ -342,8 +330,6 @@ public class Network.WifiInterface : Network.Widgets.Page { if (connected_frame != null && connected_frame.get_child () != null) { connected_frame.get_child ().destroy (); } - - disconnect_btn = settings_btn = null; } else if (active_access_point != null && active_wifi_item != old_active) { if (old_active != null) { @@ -357,43 +343,17 @@ public class Network.WifiInterface : Network.Widgets.Page { active_wifi_item.visible = false; var top_item = new WifiMenuItem (active_access_point) { - hexpand = true, state = NM.DeviceState.ACTIVATED }; - disconnect_btn = new Gtk.Button.with_label (_("Disconnect")) { - sensitive = (device.get_state () == NM.DeviceState.ACTIVATED) - }; - disconnect_btn.add_css_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION); - disconnect_btn.clicked.connect (() => { - try { - device.disconnect (null); - } catch (Error e) { - warning (e.message); - } - }); - - settings_btn = new Gtk.Button.with_label (_("Settings…")) { - sensitive = (device.get_state () == NM.DeviceState.ACTIVATED) - }; - - var button_box = new Gtk.Box (HORIZONTAL, 6) { - homogeneous = true, - valign = CENTER - }; - button_box.append (settings_btn); - button_box.append (disconnect_btn); - var connected_box = new Gtk.Box (HORIZONTAL, 12); - connected_box.append (top_item); - connected_box.append (button_box); // Create a single item listbox to match styles with main listbox var connected_listbox = new Gtk.ListBox () { selection_mode = NONE }; connected_listbox.add_css_class (Granite.STYLE_CLASS_RICH_LIST); - connected_listbox.append (connected_box); + connected_listbox.append (top_item); connected_listbox.get_first_child ().focusable = false; connected_frame.child = connected_listbox; @@ -412,9 +372,8 @@ public class Network.WifiInterface : Network.Widgets.Page { settings_dialog.add_button (_("Close"), Gtk.ResponseType.CLOSE); settings_dialog.custom_bin.append (info_box); - settings_btn.clicked.connect (() => { - settings_dialog.present (); - }); + top_item.user_action.connect (wifi_activate_cb); + top_item.settings_request.connect (settings_dialog.present); settings_dialog.response.connect ((response) => { if (response == 0) { @@ -477,6 +436,11 @@ public class Network.WifiInterface : Network.Widgets.Page { /* Do not activate connection if it is already activated */ if (wifi_device.get_active_access_point () == row.ap) { + try { + device.disconnect (null); + } catch (Error e) { + warning (e.message); + } return; } diff --git a/src/Widgets/WifiMenuItem.vala b/src/Widgets/WifiMenuItem.vala index 73d828bb..e91e359d 100644 --- a/src/Widgets/WifiMenuItem.vala +++ b/src/Widgets/WifiMenuItem.vala @@ -17,6 +17,7 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow { public signal void user_action (); + public signal void settings_request (); public bool is_secured { get; private set; } public bool active { get; set; } @@ -50,11 +51,19 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow { public Gtk.Label ssid_label { get; private set; } public Gtk.Label status_label { get; private set; } + private static Gtk.SizeGroup button_sizegroup; + + private Gtk.Box button_box; + private Gtk.Button connect_button; private Gtk.Image lock_img; private Gtk.Image error_img; - private Gtk.Revealer connect_button_revealer; + private Gtk.Revealer settings_button_revealer; private Gtk.Spinner spinner; + static construct { + button_sizegroup = new Gtk.SizeGroup (HORIZONTAL); + } + public WifiMenuItem (NM.AccessPoint ap) { img_strength = new Gtk.Image () { icon_size = LARGE @@ -77,16 +86,25 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow { spinner = new Gtk.Spinner (); - var connect_button = new Gtk.Button.with_label (_("Connect")) { - halign = Gtk.Align.END, - hexpand = true, - valign = Gtk.Align.CENTER + var settings_button = new Gtk.Button.with_label (_("Settings…")); + + connect_button = new Gtk.Button (); + + button_sizegroup.add_widget (connect_button); + + settings_button_revealer = new Gtk.Revealer () { + child = settings_button, + overflow = VISIBLE }; - connect_button_revealer = new Gtk.Revealer () { - reveal_child = true, - child = connect_button + button_box = new Gtk.Box (HORIZONTAL, 6) { + hexpand = true, + halign = END, + homogeneous = true, + valign = CENTER }; + button_box.append (settings_button_revealer); + button_box.append (connect_button); var grid = new Gtk.Grid () { valign = Gtk.Align.CENTER, @@ -98,7 +116,7 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow { grid.attach (lock_img, 2, 0); grid.attach (error_img, 3, 0, 1, 2); grid.attach (spinner, 4, 0, 1, 2); - grid.attach (connect_button_revealer, 5, 0, 1, 2); + grid.attach (button_box, 5, 0, 1, 2); _ap = new Gee.LinkedList (); @@ -110,9 +128,8 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow { notify["state"].connect (update); notify["active"].connect (update); - connect_button.clicked.connect (() => { - user_action (); - }); + connect_button.clicked.connect (() => user_action ()); + settings_button.clicked.connect (() => settings_request ()); update (); } @@ -159,8 +176,9 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow { hide_item (error_img); spinner.spinning = false; - - connect_button_revealer.reveal_child = true; + button_box.sensitive = true; + settings_button_revealer.reveal_child = false; + connect_button.label = _("Connect"); switch (state) { case NM.DeviceState.FAILED: @@ -169,10 +187,12 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow { break; case NM.DeviceState.PREPARE: spinner.spinning = true; + button_box.sensitive = false; state_string = _("Connecting"); break; case NM.DeviceState.ACTIVATED: - connect_button_revealer.reveal_child = false; + settings_button_revealer.reveal_child = true; + connect_button.label = _("Disconnect"); break; }