From 0630993f0990cd86de803bebfba253bc681598ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 10 Dec 2024 10:25:27 -0800 Subject: [PATCH 1/2] InfoBox: add auto connect switch --- src/Widgets/InfoBox.vala | 66 ++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/src/Widgets/InfoBox.vala b/src/Widgets/InfoBox.vala index d38fdba3..63fed940 100644 --- a/src/Widgets/InfoBox.vala +++ b/src/Widgets/InfoBox.vala @@ -17,6 +17,7 @@ public class Network.Widgets.InfoBox : Gtk.Box { private Gtk.Label dns; private Gtk.Label sent; private Gtk.Label received; + private Gtk.Switch auto_connect_switch; private Gtk.Switch reduce_data_switch; private Granite.HeaderLabel ip6address_head; private NM.RemoteConnection connection; @@ -84,6 +85,7 @@ public class Network.Widgets.InfoBox : Gtk.Box { }; var reduce_data_header = new Granite.HeaderLabel (_("Reduce background data usage")) { + hexpand = true, mnemonic_widget = reduce_data_switch, secondary_text = _("While connected to this network, background tasks like automatic updates will be paused.") }; @@ -94,6 +96,22 @@ public class Network.Widgets.InfoBox : Gtk.Box { reduce_data_box.append (reduce_data_header); reduce_data_box.append (reduce_data_switch); + auto_connect_switch = new Gtk.Switch () { + valign = CENTER + }; + + var auto_connect_header = new Granite.HeaderLabel (_("Automatically connect")) { + hexpand = true, + mnemonic_widget = auto_connect_switch, + valign = CENTER + }; + + var auto_connect_box = new Gtk.Box (HORIZONTAL, 12) { + margin_top = 12 + }; + auto_connect_box.append (auto_connect_header); + auto_connect_box.append (auto_connect_switch); + orientation = VERTICAL; append (ip4address_head); append (ip4address); @@ -107,6 +125,7 @@ public class Network.Widgets.InfoBox : Gtk.Box { append (dns); append (send_receive_box); append (reduce_data_box); + append (auto_connect_box); connection = device.get_active_connection ().connection; connection.changed.connect (update_settings); @@ -119,6 +138,16 @@ public class Network.Widgets.InfoBox : Gtk.Box { update_settings (); update_status (); + auto_connect_switch.notify["active"].connect (() => { + var setting_connection = connection.get_setting_connection (); + if (setting_connection.autoconnect == auto_connect_switch.active) { + return; + } + + setting_connection.set_property (NM.SettingConnection.AUTOCONNECT, auto_connect_switch.active); + commit_changes (); + }); + reduce_data_switch.notify["active"].connect (() => { var setting_connection = connection.get_setting_connection (); var metered = setting_connection.metered; @@ -131,22 +160,7 @@ public class Network.Widgets.InfoBox : Gtk.Box { setting_connection.set_property (NM.SettingConnection.METERED, metered); - try { - connection.commit_changes_async.begin (true, null); - } catch (Error e) { - var message_dialog = new Granite.MessageDialog.with_image_from_icon_name ( - _("Failed To Configure Settings"), - _("Unable to save changes to the disk"), - "network-error", - Gtk.ButtonsType.CLOSE - ) { - modal = true, - transient_for = (Gtk.Window) get_root () - }; - message_dialog.show_error_details (e.message); - message_dialog.response.connect (message_dialog.destroy); - message_dialog.present (); - } + commit_changes (); }); } @@ -207,9 +221,29 @@ public class Network.Widgets.InfoBox : Gtk.Box { } } + private void commit_changes () { + try { + connection.commit_changes_async.begin (true, null); + } catch (Error e) { + var message_dialog = new Granite.MessageDialog.with_image_from_icon_name ( + _("Failed To Configure Settings"), + _("Unable to save changes to the disk"), + "network-error", + Gtk.ButtonsType.CLOSE + ) { + modal = true, + transient_for = (Gtk.Window) get_root () + }; + message_dialog.show_error_details (e.message); + message_dialog.response.connect (message_dialog.destroy); + message_dialog.present (); + } + } + private void update_settings () { var setting_connection = connection.get_setting_connection (); + auto_connect_switch.active = setting_connection.autoconnect; reduce_data_switch.active = setting_connection.metered == YES || setting_connection.metered == GUESS_YES; } } From 40cc44fd80ff8a6767dc01d921421b75af8e6404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 10 Dec 2024 10:33:50 -0800 Subject: [PATCH 2/2] add metainfo --- data/network.metainfo.xml.in | 1 + 1 file changed, 1 insertion(+) diff --git a/data/network.metainfo.xml.in b/data/network.metainfo.xml.in index 48267d2a..bff8e83f 100644 --- a/data/network.metainfo.xml.in +++ b/data/network.metainfo.xml.in @@ -37,6 +37,7 @@ Mark a network as metered + Disable Unsecured Network Auto Connect