From 67fb8e7843c729fd84ce3be4f55eb8be67012960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Jan 2024 16:46:51 -0800 Subject: [PATCH 1/3] ProxyExceptionsPage: GTK4 prep (#383) * ProxyExceptionsPage: GTK4 prep * Set mnemonic widget --- src/Widgets/Proxy/ProxyExceptionsPage.vala | 226 ++++++++++----------- 1 file changed, 105 insertions(+), 121 deletions(-) diff --git a/src/Widgets/Proxy/ProxyExceptionsPage.vala b/src/Widgets/Proxy/ProxyExceptionsPage.vala index e000fcf8..b2643284 100644 --- a/src/Widgets/Proxy/ProxyExceptionsPage.vala +++ b/src/Widgets/Proxy/ProxyExceptionsPage.vala @@ -1,147 +1,131 @@ -/*- - * Copyright (c) 2015-2016 elementary LLC. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * SPDX-FileCopyrightText: 2015-2024 elementary, Inc. (https://elementary.io) * Authored by: Adam Bieńkowski */ -namespace Network.Widgets { - public class ExecepionsPage : Gtk.Box { - private Gtk.ListBox ignored_list; - private Gtk.ListBoxRow[] items = {}; - - construct { - margin_top = 10; - orientation = Gtk.Orientation.VERTICAL; - - ignored_list = new Gtk.ListBox () { - vexpand = true, - selection_mode = Gtk.SelectionMode.SINGLE, - activate_on_single_click = false - }; - - var frame = new Gtk.Frame (null); - frame.add (ignored_list); - - var control_row = new Gtk.ListBoxRow () { - selectable = false - }; +public class Network.Widgets.ExecepionsPage : Gtk.Box { + private Gtk.ListBox ignored_list; + private Gtk.ListBoxRow[] items = {}; + + construct { + ignored_list = new Gtk.ListBox () { + vexpand = true, + selection_mode = SINGLE, + activate_on_single_click = false + }; + + var frame = new Gtk.Frame (null) { + child = ignored_list + }; + + var ign_label = new Granite.HeaderLabel (_("Ignored hosts")) { + mnemonic_widget = ignored_list + }; + + var entry = new Gtk.Entry () { + hexpand = true, + placeholder_text = _("Exception to add (separate with commas to add multiple)") + }; + + var add_btn = new Gtk.Button.with_label (_("Add Exception")) { + sensitive = false + }; + add_btn.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); + + var box_btn = new Gtk.Box (HORIZONTAL, 12) { + margin_top = 12 + }; + box_btn.add (entry); + box_btn.add (add_btn); + + list_exceptions (); + + orientation = VERTICAL; + add (ign_label); + add (frame); + add (box_btn); + + add_btn.clicked.connect (() => { + add_exception (entry); + }); + + entry.activate.connect (() => { + add_btn.clicked (); + }); + + entry.changed.connect (() => { + add_btn.sensitive = entry.text != ""; + }); + } - var ign_label = new Gtk.Label (_("Ignored hosts")); - ign_label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); + private void add_exception (Gtk.Entry entry) { + string[] new_hosts = Network.Plug.proxy_settings.get_strv ("ignore-hosts"); + foreach (string host in entry.get_text ().split (",")) { + if (host.strip () != "") { + new_hosts += host.strip (); + } + } - var ign_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - ign_box.pack_start (ign_label, false, false, 0); + Network.Plug.proxy_settings.set_strv ("ignore-hosts", new_hosts); + entry.text = ""; + update_list (); + } - var entry = new Gtk.Entry () { - placeholder_text = _("Exception to add (separate with commas to add multiple)") + private void list_exceptions () { + foreach (string e in Network.Plug.proxy_settings.get_strv ("ignore-hosts")) { + var e_label = new Gtk.Label (e) { + halign = START, + hexpand = true }; - var add_btn = new Gtk.Button.with_label (_("Add Exception")) { - sensitive = false + var remove_btn = new Gtk.Button.from_icon_name ("edit-delete-symbolic") { + tooltip_text = _("Remove exception") }; - add_btn.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); - add_btn.clicked.connect (() => { - add_exception (entry); - }); - - entry.activate.connect (() => { - add_btn.clicked (); - }); + remove_btn.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); - entry.changed.connect (() => { - if (entry.get_text () != "") - add_btn.sensitive = true; - else - add_btn.sensitive = false; + remove_btn.clicked.connect (() => { + remove_exception (e); }); - var box_btn = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12) { - margin_top = 12 + var e_box = new Gtk.Box (HORIZONTAL, 0) { + margin_top = 3, + margin_end = 6, + margin_bottom = 3, + margin_start = 6 }; - box_btn.pack_end (add_btn, false, false, 0); - box_btn.pack_end (entry, true, true, 0); - - control_row.add (ign_box); - ignored_list.add (control_row); - - list_exceptions (); + e_box.add (e_label); + e_box.add (remove_btn); - this.add (frame); - this.add (box_btn); - this.show_all (); - } - - private void add_exception (Gtk.Entry entry) { - string[] new_hosts = Network.Plug.proxy_settings.get_strv ("ignore-hosts"); - foreach (string host in entry.get_text ().split (",")) { - if (host.strip () != "") { - new_hosts += host.strip (); - } - } + var row = new Gtk.ListBoxRow () { + child = e_box + }; - Network.Plug.proxy_settings.set_strv ("ignore-hosts", new_hosts); - entry.text = ""; - update_list (); + ignored_list.add (row); + items += row; } + } - private void list_exceptions () { - foreach (string e in Network.Plug.proxy_settings.get_strv ("ignore-hosts")) { - var row = new Gtk.ListBoxRow (); - var e_label = new Gtk.Label (e); - e_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); - - var remove_btn = new Gtk.Button.from_icon_name ("user-trash-symbolic", Gtk.IconSize.SMALL_TOOLBAR); - remove_btn.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); - - remove_btn.clicked.connect (() => { - remove_exception (e); - }); - - var e_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { - margin_end = 6, - margin_start = 6 - }; - e_box.pack_start (e_label, false, true, 0); - e_box.pack_end (remove_btn, false, false, 0); - - row.add (e_box); - ignored_list.add (row); - items += row; + private void remove_exception (string exception) { + string[] new_hosts = {}; + foreach (string host in Network.Plug.proxy_settings.get_strv ("ignore-hosts")) { + if (host != exception) { + new_hosts += host; } } - private void remove_exception (string exception) { - string[] new_hosts = {}; - foreach (string host in Network.Plug.proxy_settings.get_strv ("ignore-hosts")) { - if (host != exception) - new_hosts += host; - } + Network.Plug.proxy_settings.set_strv ("ignore-hosts", new_hosts); + update_list (); + } - Network.Plug.proxy_settings.set_strv ("ignore-hosts", new_hosts); - update_list (); + private void update_list () { + foreach (var item in items) { + ignored_list.remove (item); } - private void update_list () { - foreach (var item in items) - ignored_list.remove (item); - - items = {}; + items = {}; - list_exceptions (); - this.show_all (); - } + list_exceptions (); + this.show_all (); } } From c3ddbac84f052bdffb497ad613584f40e78b3074 Mon Sep 17 00:00:00 2001 From: elementaryBot Date: Fri, 12 Jan 2024 00:49:01 +0000 Subject: [PATCH 2/3] Update translation template --- po/extra/extra.pot | 2 +- po/networking-plug.pot | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/po/extra/extra.pot b/po/extra/extra.pot index fa0b4c17..82e6253d 100644 --- a/po/extra/extra.pot +++ b/po/extra/extra.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: extra\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-01-10 16:32+0000\n" +"POT-Creation-Date: 2024-01-12 00:49+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/po/networking-plug.pot b/po/networking-plug.pot index 78aee580..306e7ce5 100644 --- a/po/networking-plug.pot +++ b/po/networking-plug.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: networking-plug\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-01-10 16:32+0000\n" +"POT-Creation-Date: 2024-01-12 00:49+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -477,18 +477,22 @@ msgstr "" msgid "Gateway: " msgstr "" -#: src/Widgets/Proxy/ProxyExceptionsPage.vala:42 +#: src/Widgets/Proxy/ProxyExceptionsPage.vala:22 msgid "Ignored hosts" msgstr "" -#: src/Widgets/Proxy/ProxyExceptionsPage.vala:49 +#: src/Widgets/Proxy/ProxyExceptionsPage.vala:28 msgid "Exception to add (separate with commas to add multiple)" msgstr "" -#: src/Widgets/Proxy/ProxyExceptionsPage.vala:52 +#: src/Widgets/Proxy/ProxyExceptionsPage.vala:31 msgid "Add Exception" msgstr "" +#: src/Widgets/Proxy/ProxyExceptionsPage.vala:83 +msgid "Remove exception" +msgstr "" + #: src/Widgets/Proxy/ProxyConfigurationPage.vala:55 msgid "Automatic proxy configuration" msgstr "" From 073ac7433acb567f2c2025d5e04de1a03b89d407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Jan 2024 17:22:32 -0800 Subject: [PATCH 3/3] MainView: absorb footer (#382) --- po/POTFILES | 1 - src/MainView.vala | 49 ++++++++++++++++++++++++++++------- src/Widgets/Footer.vala | 57 ----------------------------------------- src/meson.build | 1 - 4 files changed, 40 insertions(+), 68 deletions(-) delete mode 100644 src/Widgets/Footer.vala diff --git a/po/POTFILES b/po/POTFILES index 9bdc9dd2..ef0e3046 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -12,7 +12,6 @@ src/Views/WifiPage.vala src/Widgets/SettingsButton.vala src/Widgets/Page.vala src/Widgets/InfoBox.vala -src/Widgets/Footer.vala src/Widgets/DeviceItem.vala src/Widgets/WifiMenuItem.vala src/Widgets/VPN/VPNInfoDialog.vala diff --git a/src/MainView.vala b/src/MainView.vala index 87d4f421..17904c09 100644 --- a/src/MainView.vala +++ b/src/MainView.vala @@ -57,7 +57,22 @@ public class Network.MainView : Gtk.Box { device_list.add (proxy); device_list.add (vpn); - var footer = new Widgets.Footer (); + var label = new Gtk.Label (_("Airplane Mode")) { + margin_start = 3 + }; + label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); + + var airplane_switch = new Gtk.Switch () { + margin_start = 6, + margin_top = 6, + margin_bottom = 6, + margin_end = 3 + }; + + var footer = new Gtk.ActionBar (); + footer.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); + footer.pack_start (label); + footer.pack_end (airplane_switch); var airplane_mode = new Granite.Widgets.AlertView ( _("Airplane Mode Is Enabled"), @@ -101,14 +116,8 @@ public class Network.MainView : Gtk.Box { content.visible_child = page; }); - unowned NetworkManager network_manager = NetworkManager.get_default (); - network_manager.client.notify["networking-enabled"].connect (update_networking_state); - - update_networking_state (); - - /* Monitor network manager */ - unowned NetworkManager nm_manager = NetworkManager.get_default (); - unowned NM.Client nm_client = nm_manager.client; + unowned var network_manager = NetworkManager.get_default (); + unowned var nm_client = network_manager.client; nm_client.connection_added.connect (connection_added_cb); nm_client.connection_removed.connect (connection_removed_cb); @@ -118,6 +127,28 @@ public class Network.MainView : Gtk.Box { nm_client.get_devices ().foreach ((device) => device_added_cb (device)); nm_client.get_connections ().foreach ((connection) => connection_added_cb (connection)); + update_networking_state (); + nm_client.notify["networking-enabled"].connect (update_networking_state); + + airplane_switch.notify["active"].connect (() => { + nm_client.dbus_call.begin ( + NM.DBUS_PATH, NM.DBUS_INTERFACE, "Enable", + new GLib.Variant.tuple ({!airplane_switch.active}), + null, -1, null, + (obj, res) => { + try { + nm_client.dbus_call.end (res); + } catch (Error e) { + warning (e.message); + } + } + ); + }); + + if (!airplane_switch.active && !nm_client.networking_enabled) { + airplane_switch.activate (); + } + show_all (); } diff --git a/src/Widgets/Footer.vala b/src/Widgets/Footer.vala deleted file mode 100644 index 6af75bb8..00000000 --- a/src/Widgets/Footer.vala +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 2015-2016 elementary LLC. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Authored by: Adam Bieńkowski - */ - -namespace Network { - public class Widgets.Footer : Gtk.ActionBar { - construct { - hexpand = false; - get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR); - - var label = new Gtk.Label (_("Airplane Mode")) { - margin_start = 3 - }; - label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); - - - var airplane_switch = new Gtk.Switch () { - margin_start = 6, - margin_top = 6, - margin_bottom = 6, - margin_end = 3 - }; - - this.pack_start (label); - this.pack_end (airplane_switch); - - unowned NetworkManager network_manager = NetworkManager.get_default (); - unowned NM.Client client = network_manager.client; - airplane_switch.notify["active"].connect (() => { - try { - client.networking_set_enabled (!airplane_switch.active); - } catch (Error e) { - warning (e.message); - } - }); - - if (!airplane_switch.get_active () && !client.networking_get_enabled ()) { - airplane_switch.activate (); - } - } - } -} diff --git a/src/meson.build b/src/meson.build index 5f29dacb..6710199e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -13,7 +13,6 @@ plug_files = files( 'Widgets/SettingsButton.vala', 'Widgets/Page.vala', 'Widgets/InfoBox.vala', - 'Widgets/Footer.vala', 'Widgets/DeviceItem.vala', 'Widgets/WifiMenuItem.vala', 'Widgets/Proxy/ProxyExceptionsPage.vala',