diff --git a/po/POTFILES b/po/POTFILES index 1e221353..b6f10a75 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -20,4 +20,3 @@ src/Widgets/VPN/VPNInfoDialog.vala src/Widgets/VPN/VPNMenuItem.vala src/Widgets/Proxy/ProxyExceptionsPage.vala src/Widgets/Proxy/ProxyConfigurationPage.vala -src/Settings/ProxySettings.vala diff --git a/src/NetworkManager.vala b/src/NetworkManager.vala index d0faba4e..70299066 100644 --- a/src/NetworkManager.vala +++ b/src/NetworkManager.vala @@ -30,25 +30,12 @@ public class Network.NetworkManager : GLib.Object { /* Main client instance */ public NM.Client client { get; construct; } - /* Proxy settings */ - public Network.ProxySettings proxy_settings { get; construct; } - public Network.ProxyFTPSettings ftp_settings { get; construct; } - public Network.ProxyHTTPSettings http_settings { get; construct; } - public Network.ProxyHTTPSSettings https_settings { get; construct; } - public Network.ProxySocksSettings socks_settings { get; construct; } - construct { try { client = new NM.Client (); } catch (Error e) { critical (e.message); } - - proxy_settings = new Network.ProxySettings (); - ftp_settings = new Network.ProxyFTPSettings (); - http_settings = new Network.ProxyHTTPSettings (); - https_settings = new Network.ProxyHTTPSSettings (); - socks_settings = new Network.ProxySocksSettings (); } public async void activate_hotspot (NM.DeviceWifi wifi_device, string ssid, string key, NM.Connection? selected) { diff --git a/src/Plug.vala b/src/Plug.vala index 42a57b1e..5e4dd680 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -24,6 +24,8 @@ namespace Network { public class Plug : Switchboard.Plug { private MainView? main_view = null; + public static GLib.Settings proxy_settings; + public Plug () { var settings = new Gee.TreeMap (null, null); settings.set ("network", null); @@ -35,6 +37,10 @@ namespace Network { supported_settings: settings); } + static construct { + proxy_settings = new GLib.Settings ("org.gnome.system.proxy"); + } + public override Gtk.Widget get_widget () { if (main_view == null) { main_view = new MainView (); diff --git a/src/Settings/ProxySettings.vala b/src/Settings/ProxySettings.vala deleted file mode 100644 index e6349e3d..00000000 --- a/src/Settings/ProxySettings.vala +++ /dev/null @@ -1,70 +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 ProxySettings : Granite.Services.Settings { - public string autoconfig_url { get; set; } - public string[] ignore_hosts { get; set; } - public string mode { get; set; } - - public static ProxySettings () { - base ("org.gnome.system.proxy"); - } - - public string[] get_ignored_hosts () { - return ignore_hosts; - } - } - - public class ProxyFTPSettings : Granite.Services.Settings { - public string host { get; set; } - public int port { get; set; } - - public static ProxyFTPSettings () { - base ("org.gnome.system.proxy.ftp"); - } - } - - public class ProxyHTTPSettings : Granite.Services.Settings { - public string host { get; set; } - public int port { get; set; } - - public static ProxyHTTPSettings () { - base ("org.gnome.system.proxy.http"); - } - } - - public class ProxyHTTPSSettings : Granite.Services.Settings { - public string host { get; set; } - public int port { get; set; } - - public static ProxyHTTPSSettings () { - base ("org.gnome.system.proxy.https"); - } - } - - public class ProxySocksSettings : Granite.Services.Settings { - public string host { get; set; } - public int port { get; set; } - - public static ProxySocksSettings () { - base ("org.gnome.system.proxy.socks"); - } - } -} diff --git a/src/Views/ProxyPage.vala b/src/Views/ProxyPage.vala index e9afdcfc..8a595b23 100644 --- a/src/Views/ProxyPage.vala +++ b/src/Views/ProxyPage.vala @@ -50,8 +50,7 @@ namespace Network.Widgets { stackswitcher.halign = Gtk.Align.CENTER; stackswitcher.stack = stack; - unowned NetworkManager network_manager = NetworkManager.get_default (); - network_manager.proxy_settings.changed.connect (update_mode); + Network.Plug.proxy_settings.changed.connect (update_mode); update_mode (); content_area.column_spacing = 12; @@ -66,8 +65,7 @@ namespace Network.Widgets { protected override void control_switch_activated () { if (!status_switch.active) { - unowned NetworkManager network_manager = NetworkManager.get_default (); - network_manager.proxy_settings.mode = "none"; + Network.Plug.proxy_settings.set_string ("mode", "none"); } } @@ -77,8 +75,7 @@ namespace Network.Widgets { private void update_mode () { var mode = Utils.CustomMode.INVALID; - unowned NetworkManager network_manager = NetworkManager.get_default (); - switch (network_manager.proxy_settings.mode) { + switch (Network.Plug.proxy_settings.get_string ("mode")) { case "none": mode = Utils.CustomMode.PROXY_NONE; status_switch.active = false; diff --git a/src/Widgets/Proxy/ProxyConfigurationPage.vala b/src/Widgets/Proxy/ProxyConfigurationPage.vala index 87ebd239..faeb0966 100644 --- a/src/Widgets/Proxy/ProxyConfigurationPage.vala +++ b/src/Widgets/Proxy/ProxyConfigurationPage.vala @@ -36,24 +36,21 @@ namespace Network.Widgets { private Gtk.Button apply_button; - private unowned Network.ProxySettings proxy_settings; - private unowned Network.ProxyFTPSettings ftp_settings; - private unowned Network.ProxyHTTPSettings http_settings; - private unowned Network.ProxyHTTPSSettings https_settings; - private unowned Network.ProxySocksSettings socks_settings; + private GLib.Settings ftp_settings; + private GLib.Settings http_settings; + private GLib.Settings https_settings; + private GLib.Settings socks_settings; - public ConfigurationPage () { + construct { margin_top = 12; halign = Gtk.Align.CENTER; orientation = Gtk.Orientation.VERTICAL; row_spacing = 12; - unowned NetworkManager network_manager = NetworkManager.get_default (); - proxy_settings = network_manager.proxy_settings; - ftp_settings = network_manager.ftp_settings; - http_settings = network_manager.http_settings; - https_settings = network_manager.https_settings; - socks_settings = network_manager.socks_settings; + ftp_settings = new GLib.Settings ("org.gnome.system.proxy.ftp"); + http_settings = new GLib.Settings ("org.gnome.system.proxy.http"); + https_settings = new GLib.Settings ("org.gnome.system.proxy.https"); + socks_settings = new GLib.Settings ("org.gnome.system.proxy.socks"); auto_button = new Gtk.RadioButton.with_label (null, _("Automatic proxy configuration")); manual_button = new Gtk.RadioButton.with_label_from_widget (auto_button, _("Manual proxy configuration")); @@ -196,15 +193,15 @@ namespace Network.Widgets { auto_button.notify["active"].connect (() => verify_applicable ()); manual_button.notify["active"].connect (() => verify_applicable ()); - auto_entry.text = proxy_settings.autoconfig_url; - http_entry.text = http_settings.host; - http_spin.value = http_settings.port; - https_entry.text = https_settings.host; - https_spin.value = https_settings.port; - ftp_entry.text = ftp_settings.host; - ftp_spin.value = ftp_settings.port; - socks_entry.text = socks_settings.host; - socks_spin.value = socks_settings.port; + auto_entry.text = Network.Plug.proxy_settings.get_string ("autoconfig-url"); + http_entry.text = http_settings.get_string ("host"); + http_spin.value = http_settings.get_int ("port"); + https_entry.text = https_settings.get_string ("host"); + https_spin.value = https_settings.get_int ("port"); + ftp_entry.text = ftp_settings.get_string ("host"); + ftp_spin.value = ftp_settings.get_int ("port"); + socks_entry.text = socks_settings.get_string ("host"); + socks_spin.value = socks_settings.get_int ("port"); if (http_entry.text == https_entry.text && http_entry.text == ftp_entry.text && http_entry.text == socks_entry.text && @@ -214,7 +211,7 @@ namespace Network.Widgets { use_all_check.active = true; } - if (proxy_settings.mode == "auto") { + if (Network.Plug.proxy_settings.get_string ("mode") == "auto") { auto_button.active = true; } else { manual_button.active = true; @@ -236,19 +233,22 @@ namespace Network.Widgets { private void apply_settings () { if (auto_button.active) { - proxy_settings.autoconfig_url = auto_entry.text; - proxy_settings.mode = "auto"; - + Network.Plug.proxy_settings.set_string ("autoconfig-url", auto_entry.text); + Network.Plug.proxy_settings.set_string ("mode", "auto"); } else { - http_settings.host = http_entry.text; - http_settings.port = (int)http_spin.value; - https_settings.host = https_entry.text; - https_settings.port = (int)https_spin.value; - ftp_settings.host = ftp_entry.text; - ftp_settings.port = (int)ftp_spin.value; - socks_settings.host = socks_entry.text; - socks_settings.port = (int)socks_spin.value; - proxy_settings.mode = "manual"; + http_settings.set_string ("host", http_entry.text); + http_settings.set_int ("port", (int)http_spin.value); + + https_settings.set_string ("host", https_entry.text); + https_settings.set_int ("port", (int)https_spin.value); + + ftp_settings.set_string ("host", ftp_entry.text); + ftp_settings.set_int ("port", (int)ftp_spin.value); + + socks_settings.set_string ("host", socks_entry.text); + socks_settings.set_int ("port", (int)socks_spin.value); + + Network.Plug.proxy_settings.set_string ("mode", "manual"); } } @@ -265,16 +265,20 @@ namespace Network.Widgets { reset_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION); if (reset_dialog.run () == Gtk.ResponseType.APPLY) { - proxy_settings.mode = "none"; - proxy_settings.autoconfig_url = ""; - http_settings.host = ""; - http_settings.port = 0; - https_settings.host = ""; - https_settings.port = 0; - ftp_settings.host = ""; - ftp_settings.port = 0; - socks_settings.host = ""; - socks_settings.port = 0; + Network.Plug.proxy_settings.set_string ("mode", "none"); + Network.Plug.proxy_settings.set_string ("autoconfig-url", ""); + + http_settings.set_string ("host", ""); + http_settings.set_int ("port", 0); + + https_settings.set_string ("host", ""); + https_settings.set_int ("port", 0); + + ftp_settings.set_string ("host", ""); + ftp_settings.set_int ("port", 0); + + socks_settings.set_string ("host", ""); + socks_settings.set_int ("port", 0); } reset_dialog.destroy (); diff --git a/src/Widgets/Proxy/ProxyExceptionsPage.vala b/src/Widgets/Proxy/ProxyExceptionsPage.vala index 1b4634f4..ba998a3a 100644 --- a/src/Widgets/Proxy/ProxyExceptionsPage.vala +++ b/src/Widgets/Proxy/ProxyExceptionsPage.vala @@ -22,8 +22,6 @@ namespace Network.Widgets { private Gtk.ListBox ignored_list; private Gtk.ListBoxRow[] items = {}; - public ExecepionsPage () {} - construct { margin_top = 10; orientation = Gtk.Orientation.VERTICAL; @@ -83,23 +81,20 @@ namespace Network.Widgets { } private void add_exception (Gtk.Entry entry) { - unowned NetworkManager network_manager = NetworkManager.get_default (); - unowned Network.ProxySettings proxy_settings = network_manager.proxy_settings; - string[] new_hosts = proxy_settings.ignore_hosts; + 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 (); } } - proxy_settings.ignore_hosts = new_hosts; + Network.Plug.proxy_settings.set_strv ("ignore-hosts", new_hosts); entry.text = ""; update_list (); } private void list_exceptions () { - unowned NetworkManager network_manager = NetworkManager.get_default (); - foreach (string e in network_manager.proxy_settings.ignore_hosts) { + 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); @@ -124,14 +119,12 @@ namespace Network.Widgets { private void remove_exception (string exception) { string[] new_hosts = {}; - unowned NetworkManager network_manager = NetworkManager.get_default (); - unowned Network.ProxySettings proxy_settings = network_manager.proxy_settings; - foreach (string host in proxy_settings.ignore_hosts) { + foreach (string host in Network.Plug.proxy_settings.get_strv ("ignore-hosts")) { if (host != exception) new_hosts += host; } - proxy_settings.ignore_hosts = new_hosts; + Network.Plug.proxy_settings.set_strv ("ignore-hosts", new_hosts); update_list (); } diff --git a/src/meson.build b/src/meson.build index 52d7a354..1a5c2748 100644 --- a/src/meson.build +++ b/src/meson.build @@ -20,8 +20,7 @@ plug_files = files( 'Widgets/Proxy/ProxyExceptionsPage.vala', 'Widgets/Proxy/ProxyConfigurationPage.vala', 'Widgets/VPN/VPNInfoDialog.vala', - 'Widgets/VPN/VPNMenuItem.vala', - 'Settings/ProxySettings.vala' + 'Widgets/VPN/VPNMenuItem.vala' ) switchboard_dep = dependency('switchboard-2.0')