Skip to content

Commit

Permalink
Granite.Services.Settings → GLib.Settings (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Nov 4, 2019
1 parent ea952c2 commit ece3277
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 148 deletions.
1 change: 0 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 0 additions & 13 deletions src/NetworkManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/Plug.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string?> (null, null);
settings.set ("network", null);
Expand All @@ -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 ();
Expand Down
70 changes: 0 additions & 70 deletions src/Settings/ProxySettings.vala

This file was deleted.

9 changes: 3 additions & 6 deletions src/Views/ProxyPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
}

Expand All @@ -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;
Expand Down
92 changes: 48 additions & 44 deletions src/Widgets/Proxy/ProxyConfigurationPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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 &&
Expand All @@ -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;
Expand All @@ -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");
}
}

Expand All @@ -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 ();
Expand Down
17 changes: 5 additions & 12 deletions src/Widgets/Proxy/ProxyExceptionsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 ();
}

Expand Down
3 changes: 1 addition & 2 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit ece3277

Please sign in to comment.