Skip to content

Commit

Permalink
VPN: move edit connection button to info dialog (#390)
Browse files Browse the repository at this point in the history
* VPN: move edit connection button to info dialog

* Update VPNInfoDialog.vala

---------

Co-authored-by: Jeremy Wootten <jeremywootten@gmail.com>
  • Loading branch information
danirabbit and jeremypw authored Jan 19, 2024
1 parent db25955 commit 5697b4d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
12 changes: 0 additions & 12 deletions src/Views/VPNPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ public class Network.VPNPage : Network.Widgets.Page {
sensitive = false
};

var edit_connection_button = new Gtk.Button.from_icon_name ("preferences-system-symbolic") {
tooltip_text = _("Edit VPN connection…"),
sensitive = false
};

actionbar.pack_start (add_button);
actionbar.pack_start (remove_button);
actionbar.pack_start (edit_connection_button);

var scrolled = new Gtk.ScrolledWindow (null, null) {
child = vpn_list
Expand Down Expand Up @@ -109,11 +103,6 @@ public class Network.VPNPage : Network.Widgets.Page {
try_connection_editor ("--create --type=vpn");
});

edit_connection_button.clicked.connect (() => {
var selected_row = (VPNMenuItem) vpn_list.get_selected_row ();
try_connection_editor ("--edit=" + selected_row.connection.get_uuid ());
});

remove_button.clicked.connect (remove_button_cb);

remove_vpn_toast.default_action.connect (() => {
Expand All @@ -132,7 +121,6 @@ public class Network.VPNPage : Network.Widgets.Page {

vpn_list.row_selected.connect (row => {
remove_button.sensitive = row != null;
edit_connection_button.sensitive = row != null;
});

active_connections = new Gee.ArrayList<NM.ActiveConnection> ();
Expand Down
33 changes: 32 additions & 1 deletion src/Widgets/VPN/VPNInfoDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class Network.Widgets.VPNInfoDialog : Granite.MessageDialog {

public VPNInfoDialog (NM.RemoteConnection? connection) {
Object (
buttons: Gtk.ButtonsType.CLOSE,
image_icon: new ThemedIcon ("network-vpn"),
connection: connection
);
Expand All @@ -50,6 +49,9 @@ public class Network.Widgets.VPNInfoDialog : Granite.MessageDialog {
xalign = 0
};

add_button (_("Edit Connection…"), 1);
add_button (_("Close"), Gtk.ResponseType.CLOSE);

var box = new Gtk.Box (VERTICAL, 0);
box.add (new Granite.HeaderLabel (("VPN Type")));
box.add (vpn_type);
Expand All @@ -64,6 +66,35 @@ public class Network.Widgets.VPNInfoDialog : Granite.MessageDialog {

connection.changed.connect (update_status);
update_status ();

response.connect ((response) => {
if (response == 1) {
try {
var appinfo = AppInfo.create_from_commandline (
"nm-connection-editor --edit=%s".printf (connection.get_uuid ()),
null,
GLib.AppInfoCreateFlags.NONE
);
appinfo.launch (null, null);
} catch (Error error) {
var dialog = new Granite.MessageDialog (
_("Failed to run Connection Editor"),
_("The program \"nm-connection-editor\" may not be installed."),
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 (error.message);
dialog.present ();
dialog.response.connect (dialog.destroy);
}
}

destroy ();
});
}

private string get_key_group_username () {
Expand Down
1 change: 0 additions & 1 deletion src/Widgets/VPN/VPNMenuItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public class Network.VPNMenuItem : Gtk.ListBoxRow {
};

vpn_info_dialog.present ();
vpn_info_dialog.response.connect (vpn_info_dialog.destroy);
});
}

Expand Down

0 comments on commit 5697b4d

Please sign in to comment.