Skip to content

Commit

Permalink
VPNPage: Gtk4 prep and code style (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Jan 9, 2024
1 parent a69570a commit 7957edf
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions src/Views/VPNPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,70 +48,81 @@ public class Network.VPNPage : Network.Widgets.Page {

vpn_list = new Gtk.ListBox () {
activate_on_single_click = false,
visible = true,
selection_mode = Gtk.SelectionMode.BROWSE
hexpand = true,
vexpand = true,
selection_mode = BROWSE
};
vpn_list.set_placeholder (placeholder);
vpn_list.set_sort_func ((Gtk.ListBoxSortFunc) compare_rows);

var actionbar = new Gtk.ActionBar ();
actionbar.get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR);
actionbar.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

var add_button = new Gtk.Button.from_icon_name ("list-add-symbolic", Gtk.IconSize.BUTTON) {
tooltip_text = _("Add VPN Connection…")
var add_button_label = new Gtk.Label (_("Add Connection…"));

var add_button_box = new Gtk.Box (HORIZONTAL, 0);
add_button_box.add (new Gtk.Image.from_icon_name ("list-add-symbolic", BUTTON));
add_button_box.add (add_button_label);

var add_button = new Gtk.Button () {
child = add_button_box
};
add_button.clicked.connect (() => {
try_connection_editor ("--create --type=vpn");
});
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", Gtk.IconSize.BUTTON) {
var remove_button = new Gtk.Button.from_icon_name ("list-remove-symbolic") {
tooltip_text = _("Forget selected VPN…"),
sensitive = false
};
remove_button.clicked.connect (remove_button_cb);

remove_vpn_toast.default_action.connect (() => {
GLib.Source.remove (timeout_id);
timeout_id = 0;
sel_row.show ();
});

var edit_connection_button = new Gtk.Button.from_icon_name ("preferences-system-symbolic", Gtk.IconSize.BUTTON) {
var edit_connection_button = new Gtk.Button.from_icon_name ("preferences-system-symbolic") {
tooltip_text = _("Edit VPN connection…"),
sensitive = false
};
edit_connection_button.clicked.connect (() => {
var selected_row = (VPNMenuItem) vpn_list.get_selected_row ();
try_connection_editor ("--edit=" + selected_row.connection.get_uuid ());
});

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

var scrolled = new Gtk.ScrolledWindow (null, null) {
expand = true
child = vpn_list
};
scrolled.add (vpn_list);

var list_root = new Gtk.Grid ();
list_root.attach (scrolled, 0, 0, 1, 1);
list_root.attach (actionbar, 0, 1, 1, 1);
var vpn_box = new Gtk.Box (VERTICAL, 0);
vpn_box.add (scrolled);
vpn_box.add (actionbar);

var frame = new Gtk.Frame (null) {
child = vpn_box,
vexpand = true
};
frame.get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);
frame.add (list_root);

var main_overlay = new Gtk.Overlay ();
main_overlay.add (frame);
var main_overlay = new Gtk.Overlay () {
child = frame
};
main_overlay.add_overlay (remove_vpn_toast);

content_area.add (main_overlay);

show_all ();

add_button.clicked.connect (() => {
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 (() => {
GLib.Source.remove (timeout_id);
timeout_id = 0;
sel_row.show ();
});

vpn_list.row_activated.connect (row => {
if (((VPNMenuItem) row).state == NM.DeviceState.ACTIVATED) {
disconnect_vpn_cb ((VPNMenuItem) row);
Expand Down

0 comments on commit 7957edf

Please sign in to comment.