diff --git a/src/Views/VPNPage.vala b/src/Views/VPNPage.vala index b19c2257..44eebaef 100644 --- a/src/Views/VPNPage.vala +++ b/src/Views/VPNPage.vala @@ -69,13 +69,7 @@ public class Network.VPNPage : Network.Widgets.Page { add_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); add_button_label.mnemonic_widget = add_button; - var remove_button = new Gtk.Button.from_icon_name ("list-remove-symbolic") { - tooltip_text = _("Forget selected VPNā€¦"), - sensitive = false - }; - actionbar.pack_start (add_button); - actionbar.pack_start (remove_button); var scrolled = new Gtk.ScrolledWindow (null, null) { child = vpn_list @@ -103,8 +97,6 @@ public class Network.VPNPage : Network.Widgets.Page { try_connection_editor ("--create --type=vpn"); }); - remove_button.clicked.connect (remove_button_cb); - remove_vpn_toast.default_action.connect (() => { GLib.Source.remove (timeout_id); timeout_id = 0; @@ -119,10 +111,6 @@ public class Network.VPNPage : Network.Widgets.Page { } }); - vpn_list.row_selected.connect (row => { - remove_button.sensitive = row != null; - }); - active_connections = new Gee.ArrayList (); update (); @@ -195,6 +183,15 @@ public class Network.VPNPage : Network.Widgets.Page { public void add_connection (NM.RemoteConnection connection) { var item = new VPNMenuItem (connection); + item.remove_request.connect (() => { + sel_row = item; + remove_vpn_toast.send_notification (); + timeout_id = GLib.Timeout.add (3600, () => { + timeout_id = 0; + delete_connection (item); + return GLib.Source.REMOVE; + }); + }); vpn_list.add (item); update (); @@ -280,36 +277,6 @@ public class Network.VPNPage : Network.Widgets.Page { } } - private void remove_button_cb () { - sel_row = vpn_list.get_selected_row () as VPNMenuItem; - if (sel_row != null) { - if (sel_row.state == NM.DeviceState.ACTIVATED || - sel_row.state == NM.DeviceState.PREPARE) { - var dialog = new Granite.MessageDialog ( - _("Failed to remove VPN connection"), - _("Cannot remove an active VPN connection."), - new ThemedIcon ("network-vpn"), - Gtk.ButtonsType.CLOSE - ) { - badge_icon = new ThemedIcon ("dialog-error"), - modal = true, - transient_for = (Gtk.Window) get_toplevel () - }; - dialog.present (); - dialog.response.connect (dialog.destroy); - return; - } else { - remove_vpn_toast.send_notification (); - sel_row.hide (); - timeout_id = GLib.Timeout.add (3600, () => { - timeout_id = 0; - delete_connection (); - return GLib.Source.REMOVE; - }); - } - } - } - private void try_connection_editor (string args) { try { var appinfo = AppInfo.create_from_commandline ( @@ -335,34 +302,31 @@ public class Network.VPNPage : Network.Widgets.Page { } } - private void delete_connection () { - var selected_row = vpn_list.get_selected_row () as VPNMenuItem; - if (selected_row != null && sel_row != null) { - if (sel_row == selected_row) { - try { - selected_row.connection.delete (null); - } catch (Error e) { - warning (e.message); - var dialog = new Granite.MessageDialog ( - _("Failed to remove VPN connection"), - "", - new ThemedIcon ("network-vpn"), - Gtk.ButtonsType.CLOSE - ) { - badge_icon = new ThemedIcon ("dialog-error"), - modal = true, - transient_for = (Gtk.Window) get_toplevel () - }; - dialog.show_error_details (e.message); - dialog.present (); - dialog.response.connect (dialog.destroy); - } - } else { - warning ("Row selection changed between operations. Cancelling removal of VPN."); - GLib.Source.remove (timeout_id); - timeout_id = 0; - sel_row.show (); + private void delete_connection (VPNMenuItem item) { + if (sel_row != null && sel_row == item) { + try { + item.connection.delete (null); + } catch (Error e) { + warning (e.message); + var dialog = new Granite.MessageDialog ( + _("Failed to remove VPN connection"), + "", + new ThemedIcon ("network-vpn"), + Gtk.ButtonsType.CLOSE + ) { + badge_icon = new ThemedIcon ("dialog-error"), + modal = true, + transient_for = (Gtk.Window) get_toplevel () + }; + dialog.show_error_details (e.message); + dialog.present (); + dialog.response.connect (dialog.destroy); } + } else { + warning ("Row selection changed between operations. Cancelling removal of VPN."); + GLib.Source.remove (timeout_id); + timeout_id = 0; + sel_row.show (); } } diff --git a/src/Widgets/VPN/VPNMenuItem.vala b/src/Widgets/VPN/VPNMenuItem.vala index 0c4fdaee..4ebf25db 100644 --- a/src/Widgets/VPN/VPNMenuItem.vala +++ b/src/Widgets/VPN/VPNMenuItem.vala @@ -16,6 +16,7 @@ */ public class Network.VPNMenuItem : Gtk.ListBoxRow { + public signal void remove_request (); public NM.RemoteConnection? connection { get; construct; } public NM.DeviceState state { get; set; default = NM.DeviceState.DISCONNECTED; } @@ -60,9 +61,15 @@ public class Network.VPNMenuItem : Gtk.ListBoxRow { xalign = 0 }; - var vpn_info_button = new Gtk.Button () { - image = new Gtk.Image.from_icon_name ("view-more-horizontal-symbolic", Gtk.IconSize.MENU), + var remove_button = new Gtk.Button.from_icon_name ("edit-delete-symbolic") { margin_end = 3, + tooltip_text = _("Forget connection"), + valign = CENTER + }; + + var vpn_info_button = new Gtk.Button.from_icon_name ("view-more-horizontal-symbolic") { + margin_end = 3, + tooltip_text = _("Connection info"), valign = Gtk.Align.CENTER }; vpn_info_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); @@ -82,7 +89,8 @@ public class Network.VPNMenuItem : Gtk.ListBoxRow { grid.attach (vpn_label, 1, 0); grid.attach (state_label, 1, 1); grid.attach (vpn_info_button, 2, 0, 1, 2); - grid.attach (connect_button, 3, 0, 1, 2); + grid.attach (remove_button, 3, 0, 1, 2); + grid.attach (connect_button, 4, 0, 1, 2); add (grid); show_all (); @@ -92,6 +100,7 @@ public class Network.VPNMenuItem : Gtk.ListBoxRow { update (); connect_button.clicked.connect (() => activate ()); + remove_button.clicked.connect (remove_row); vpn_info_button.clicked.connect (() => { var vpn_info_dialog = new Widgets.VPNInfoDialog (connection) { @@ -104,6 +113,26 @@ public class Network.VPNMenuItem : Gtk.ListBoxRow { }); } + private void remove_row () { + if (state == ACTIVATED || state == PREPARE) { + var dialog = new Granite.MessageDialog ( + _("Failed to remove VPN connection"), + _("Cannot remove an active VPN connection."), + new ThemedIcon ("network-vpn"), + Gtk.ButtonsType.CLOSE + ) { + badge_icon = new ThemedIcon ("dialog-error"), + modal = true, + transient_for = (Gtk.Window) get_toplevel () + }; + dialog.present (); + dialog.response.connect (dialog.destroy); + } else { + remove_request (); + hide (); + } + } + private void update () { vpn_label.label = connection.get_id ();