diff options
author | Stefano Karapetsas <[email protected]> | 2012-10-23 19:03:27 +0200 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2012-10-23 19:03:27 +0200 |
commit | 46787e474859801435542191480e2851f7fd870c (patch) | |
tree | 77da2f344c4f14daa3151aaab7b0118dea221ec0 /capplets/network/mate-network-properties.c | |
parent | d2d6d2944d6e725cd6bd2fce1c6f979649e77ed8 (diff) | |
download | mate-control-center-46787e474859801435542191480e2851f7fd870c.tar.bz2 mate-control-center-46787e474859801435542191480e2851f7fd870c.tar.xz |
migrate network capplet to gsettings
Diffstat (limited to 'capplets/network/mate-network-properties.c')
-rw-r--r-- | capplets/network/mate-network-properties.c | 1203 |
1 files changed, 153 insertions, 1050 deletions
diff --git a/capplets/network/mate-network-properties.c b/capplets/network/mate-network-properties.c index 2d704ca8..848a2565 100644 --- a/capplets/network/mate-network-properties.c +++ b/capplets/network/mate-network-properties.c @@ -1,8 +1,10 @@ /* mate-network-properties.c: network preferences capplet * * Copyright (C) 2002 Sun Microsystems Inc. + * 2012 Stefano Karapetsas * * Written by: Mark McLoughlin <[email protected]> + * Stefano Karapetsas <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,12 +28,22 @@ #include <stdlib.h> #include <string.h> -#include <mateconf/mateconf-client.h> +#include <gio/gio.h> #include <glib/gi18n.h> #include "capplet-util.h" -#include "mateconf-property-editor.h" +/* With GSettings migration, MATE is going to share proxy settings with + * GNOME3 (in gsettings-desktop-schemas package). + * GSettings schemas is http://git.gnome.org/browse/gsettings-desktop-schemas/tree/ + * schemas/org.gnome.system.proxy.gschema.xml.in.in + * Sharing the same schema, we lose the locations feature. + */ + +/* + * FIXME use enum from gsettings-desktop-schema + * http://git.gnome.org/browse/gsettings-desktop-schemas/tree/headers/gdesktop-enums.h#n26 + */ enum ProxyMode { PROXYMODE_NONE, @@ -39,43 +51,34 @@ enum ProxyMode PROXYMODE_AUTO }; -static GEnumValue proxytype_values[] = { - { PROXYMODE_NONE, "PROXYMODE_NONE", "none"}, - { PROXYMODE_MANUAL, "PROXYMODE_MANUAL", "manual"}, - { PROXYMODE_AUTO, "PROXYMODE_AUTO", "auto"}, - { 0, NULL, NULL } -}; - enum { COL_NAME, COL_STYLE }; -#define USE_PROXY_KEY "/system/http_proxy/use_http_proxy" -#define USE_SAME_PROXY_KEY "/system/http_proxy/use_same_proxy" -#define HTTP_PROXY_HOST_KEY "/system/http_proxy/host" -#define HTTP_PROXY_PORT_KEY "/system/http_proxy/port" -#define HTTP_USE_AUTH_KEY "/system/http_proxy/use_authentication" -#define HTTP_AUTH_USER_KEY "/system/http_proxy/authentication_user" -#define HTTP_AUTH_PASSWD_KEY "/system/http_proxy/authentication_password" -#define IGNORE_HOSTS_KEY "/system/http_proxy/ignore_hosts" -#define PROXY_MODE_KEY "/system/proxy/mode" -#define SECURE_PROXY_HOST_KEY "/system/proxy/secure_host" -#define OLD_SECURE_PROXY_HOST_KEY "/system/proxy/old_secure_host" -#define SECURE_PROXY_PORT_KEY "/system/proxy/secure_port" -#define OLD_SECURE_PROXY_PORT_KEY "/system/proxy/old_secure_port" -#define FTP_PROXY_HOST_KEY "/system/proxy/ftp_host" -#define OLD_FTP_PROXY_HOST_KEY "/system/proxy/old_ftp_host" -#define FTP_PROXY_PORT_KEY "/system/proxy/ftp_port" -#define OLD_FTP_PROXY_PORT_KEY "/system/proxy/old_ftp_port" -#define SOCKS_PROXY_HOST_KEY "/system/proxy/socks_host" -#define OLD_SOCKS_PROXY_HOST_KEY "/system/proxy/old_socks_host" -#define SOCKS_PROXY_PORT_KEY "/system/proxy/socks_port" -#define OLD_SOCKS_PROXY_PORT_KEY "/system/proxy/old_socks_port" -#define PROXY_AUTOCONFIG_URL_KEY "/system/proxy/autoconfig_url" - -#define LOCATION_DIR "/apps/control-center/network" -#define CURRENT_LOCATION "/apps/control-center/network/current_location" +#define PROXY_SCHEMA "org.gnome.system.proxy" +#define PROXY_MODE_KEY "mode" +#define PROXY_AUTOCONFIG_URL_KEY "autoconfig-url" +#define IGNORE_HOSTS_KEY "ignore-hosts" + +#define HTTP_PROXY_SCHEMA "org.gnome.system.proxy.http" +#define HTTP_PROXY_HOST_KEY "host" +#define HTTP_PROXY_PORT_KEY "port" +#define HTTP_USE_AUTH_KEY "use-authentication" +#define HTTP_AUTH_USER_KEY "authentication-user" +#define HTTP_AUTH_PASSWD_KEY "authentication-password" + +#define HTTPS_PROXY_SCHEMA "org.gnome.system.proxy.https" +#define SECURE_PROXY_HOST_KEY "host" +#define SECURE_PROXY_PORT_KEY "port" + +#define FTP_PROXY_SCHEMA "org.gnome.system.proxy.ftp" +#define FTP_PROXY_HOST_KEY "host" +#define FTP_PROXY_PORT_KEY "port" + +#define SOCKS_PROXY_SCHEMA "org.gnome.system.proxy.socks" +#define SOCKS_PROXY_HOST_KEY "host" +#define SOCKS_PROXY_PORT_KEY "port" #define MATECC_GNP_UI_FILE (MATECC_UI_DIR "/mate-network-properties.ui") @@ -83,6 +86,12 @@ static GtkWidget *details_dialog = NULL; static GSList *ignore_hosts = NULL; static GtkTreeModel *model = NULL; +static GSettings *proxy_settings = NULL; +static GSettings *http_proxy_settings = NULL; +static GSettings *https_proxy_settings = NULL; +static GSettings *ftp_proxy_settings = NULL; +static GSettings *socks_proxy_settings = NULL; + static GtkTreeModel * create_listmodel(void) { @@ -133,13 +142,41 @@ _gtk_builder_get_widget (GtkBuilder *builder, const gchar *name) return GTK_WIDGET (gtk_builder_get_object (builder, name)); } +static void +read_ignore_hosts_from_gsettings (void) +{ + gchar **array; + ignore_hosts = NULL; + gint i; + array = g_settings_get_strv (proxy_settings, IGNORE_HOSTS_KEY); + if (array != NULL) + { + for (i = 0; array[i]; i++) + { + ignore_hosts = g_slist_append (ignore_hosts, g_strdup (array[i])); + } + } + g_strfreev (array); +} + +static void +save_ignore_hosts_to_gsettings (void) +{ + GArray *array; + GSList *l; + array = g_array_new (TRUE, TRUE, sizeof (gchar *)); + for (l = ignore_hosts; l; l = l->next) { + array = g_array_append_val (array, l->data); + } + g_settings_set_strv (proxy_settings, IGNORE_HOSTS_KEY, (const gchar **) array->data); + g_array_free (array, TRUE); +} static void cb_add_url (GtkButton *button, gpointer data) { GtkBuilder *builder = GTK_BUILDER (data); gchar *new_url = NULL; - MateConfClient *client; new_url = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, "entry_url")))); if (strlen (new_url) == 0) @@ -149,9 +186,7 @@ cb_add_url (GtkButton *button, gpointer data) gtk_entry_set_text(GTK_ENTRY (gtk_builder_get_object (builder, "entry_url")), ""); - client = mateconf_client_get_default (); - mateconf_client_set_list (client, IGNORE_HOSTS_KEY, MATECONF_VALUE_STRING, ignore_hosts, NULL); - g_object_unref (client); + save_ignore_hosts_to_gsettings (); } static void @@ -160,7 +195,6 @@ cb_remove_url (GtkButton *button, gpointer data) GtkBuilder *builder = GTK_BUILDER (data); GtkTreeSelection *selection; GtkTreeIter iter; - MateConfClient *client; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview_ignore_host"))); if (gtk_tree_selection_get_selected(selection, &model, &iter)) @@ -185,9 +219,7 @@ cb_remove_url (GtkButton *button, gpointer data) g_free(url); populate_listmodel(GTK_LIST_STORE(model), ignore_hosts); - client = mateconf_client_get_default (); - mateconf_client_set_list(client, IGNORE_HOSTS_KEY, MATECONF_VALUE_STRING, ignore_hosts, NULL); - g_object_unref (client); + save_ignore_hosts_to_gsettings (); } } @@ -235,7 +267,6 @@ cb_http_details_button_clicked (GtkWidget *button, gchar *builder_widgets[] = { "details_dialog", NULL }; GError *error = NULL; GtkWidget *widget; - MateConfPropertyEditor *peditor; if (details_dialog != NULL) { gtk_window_present (GTK_WINDOW (details_dialog)); @@ -262,18 +293,15 @@ cb_http_details_button_clicked (GtkWidget *button, G_CALLBACK (cb_use_auth_toggled), _gtk_builder_get_widget (builder, "auth_table")); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_boolean ( - NULL, HTTP_USE_AUTH_KEY, - _gtk_builder_get_widget (builder, "use_auth_checkbutton"), - NULL)); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_string ( - NULL, HTTP_AUTH_USER_KEY, - _gtk_builder_get_widget (builder, "username_entry"), - NULL)); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_string ( - NULL, HTTP_AUTH_PASSWD_KEY, - _gtk_builder_get_widget (builder, "password_entry"), - NULL)); + g_settings_bind (http_proxy_settings, HTTP_USE_AUTH_KEY, + gtk_builder_get_object (builder, "use_auth_checkbutton"), "active", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind (http_proxy_settings, HTTP_AUTH_USER_KEY, + gtk_builder_get_object (builder, "username_entry"), "text", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind (http_proxy_settings, HTTP_AUTH_PASSWD_KEY, + gtk_builder_get_object (builder, "password_entry"), "text", + G_SETTINGS_BIND_DEFAULT); g_signal_connect (widget, "response", G_CALLBACK (cb_details_dialog_response), NULL); @@ -283,868 +311,22 @@ cb_http_details_button_clicked (GtkWidget *button, gtk_widget_show_all (widget); } -static gchar * -copy_location_create_key (const gchar *from, const gchar *what) -{ - if (from[0] == '\0') return g_strdup (what); - else return g_strconcat (from, what + strlen ("/system"), NULL); -} - -static void -copy_location (const gchar *from, const gchar *to, MateConfClient *client) -{ - int ti; - gboolean tb; - GSList *tl; - gchar *tstr, *dest, *src; - - if (from[0] != '\0' && !mateconf_client_dir_exists (client, from, NULL)) - return; - - /* USE_PROXY */ - dest = copy_location_create_key (to, USE_PROXY_KEY); - src = copy_location_create_key (from, USE_PROXY_KEY); - - tb = mateconf_client_get_bool (client, src, NULL); - mateconf_client_set_bool (client, dest, tb, NULL); - - g_free (dest); - g_free (src); - - /* USE_SAME_PROXY */ - dest = copy_location_create_key (to, USE_SAME_PROXY_KEY); - src = copy_location_create_key (from, USE_SAME_PROXY_KEY); - - tb = mateconf_client_get_bool (client, src, NULL); - mateconf_client_set_bool (client, dest, tb, NULL); - - g_free (dest); - g_free (src); - - /* HTTP_PROXY_HOST */ - dest = copy_location_create_key (to, HTTP_PROXY_HOST_KEY); - src = copy_location_create_key (from, HTTP_PROXY_HOST_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* HTTP_PROXY_PORT */ - dest = copy_location_create_key (to, HTTP_PROXY_PORT_KEY); - src = copy_location_create_key (from, HTTP_PROXY_PORT_KEY); - - ti = mateconf_client_get_int (client, src, NULL); - mateconf_client_set_int (client, dest, ti, NULL); - - g_free (dest); - g_free (src); - - /* HTTP_USE_AUTH */ - dest = copy_location_create_key (to, HTTP_USE_AUTH_KEY); - src = copy_location_create_key (from, HTTP_USE_AUTH_KEY); - - tb = mateconf_client_get_bool (client, src, NULL); - mateconf_client_set_bool (client, dest, tb, NULL); - - g_free (dest); - g_free (src); - - /* HTTP_AUTH_USER */ - dest = copy_location_create_key (to, HTTP_AUTH_USER_KEY); - src = copy_location_create_key (from, HTTP_AUTH_USER_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* HTTP_AUTH_PASSWD */ - dest = copy_location_create_key (to, HTTP_AUTH_PASSWD_KEY); - src = copy_location_create_key (from, HTTP_AUTH_PASSWD_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* IGNORE_HOSTS */ - dest = copy_location_create_key (to, IGNORE_HOSTS_KEY); - src = copy_location_create_key (from, IGNORE_HOSTS_KEY); - - tl = mateconf_client_get_list (client, src, MATECONF_VALUE_STRING, NULL); - mateconf_client_set_list (client, dest, MATECONF_VALUE_STRING, tl, NULL); - g_slist_foreach (tl, (GFunc) g_free, NULL); - g_slist_free (tl); - - g_free (dest); - g_free (src); - - /* PROXY_MODE */ - dest = copy_location_create_key (to, PROXY_MODE_KEY); - src = copy_location_create_key (from, PROXY_MODE_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* SECURE_PROXY_HOST */ - dest = copy_location_create_key (to, SECURE_PROXY_HOST_KEY); - src = copy_location_create_key (from, SECURE_PROXY_HOST_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* OLD_SECURE_PROXY_HOST */ - dest = copy_location_create_key (to, OLD_SECURE_PROXY_HOST_KEY); - src = copy_location_create_key (from, OLD_SECURE_PROXY_HOST_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* SECURE_PROXY_PORT */ - dest = copy_location_create_key (to, SECURE_PROXY_PORT_KEY); - src = copy_location_create_key (from, SECURE_PROXY_PORT_KEY); - - ti = mateconf_client_get_int (client, src, NULL); - mateconf_client_set_int (client, dest, ti, NULL); - - g_free (dest); - g_free (src); - - /* OLD_SECURE_PROXY_PORT */ - dest = copy_location_create_key (to, OLD_SECURE_PROXY_PORT_KEY); - src = copy_location_create_key (from, OLD_SECURE_PROXY_PORT_KEY); - - ti = mateconf_client_get_int (client, src, NULL); - mateconf_client_set_int (client, dest, ti, NULL); - - g_free (dest); - g_free (src); - - /* FTP_PROXY_HOST */ - dest = copy_location_create_key (to, FTP_PROXY_HOST_KEY); - src = copy_location_create_key (from, FTP_PROXY_HOST_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* OLD_FTP_PROXY_HOST */ - dest = copy_location_create_key (to, OLD_FTP_PROXY_HOST_KEY); - src = copy_location_create_key (from, OLD_FTP_PROXY_HOST_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* FTP_PROXY_PORT */ - dest = copy_location_create_key (to, FTP_PROXY_PORT_KEY); - src = copy_location_create_key (from, FTP_PROXY_PORT_KEY); - - ti = mateconf_client_get_int (client, src, NULL); - mateconf_client_set_int (client, dest, ti, NULL); - - g_free (dest); - g_free (src); - - /* OLD_FTP_PROXY_PORT */ - dest = copy_location_create_key (to, OLD_FTP_PROXY_PORT_KEY); - src = copy_location_create_key (from, OLD_FTP_PROXY_PORT_KEY); - - ti = mateconf_client_get_int (client, src, NULL); - mateconf_client_set_int (client, dest, ti, NULL); - - g_free (dest); - g_free (src); - - /* SOCKS_PROXY_HOST */ - dest = copy_location_create_key (to, SOCKS_PROXY_HOST_KEY); - src = copy_location_create_key (from, SOCKS_PROXY_HOST_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* OLD_SOCKS_PROXY_HOST */ - dest = copy_location_create_key (to, OLD_SOCKS_PROXY_HOST_KEY); - src = copy_location_create_key (from, OLD_SOCKS_PROXY_HOST_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); - - /* SOCKS_PROXY_PORT */ - dest = copy_location_create_key (to, SOCKS_PROXY_PORT_KEY); - src = copy_location_create_key (from, SOCKS_PROXY_PORT_KEY); - - ti = mateconf_client_get_int (client, src, NULL); - mateconf_client_set_int (client, dest, ti, NULL); - - g_free (dest); - g_free (src); - - /* OLD_SOCKS_PROXY_PORT */ - dest = copy_location_create_key (to, OLD_SOCKS_PROXY_PORT_KEY); - src = copy_location_create_key (from, OLD_SOCKS_PROXY_PORT_KEY); - - ti = mateconf_client_get_int (client, src, NULL); - mateconf_client_set_int (client, dest, ti, NULL); - - g_free (dest); - g_free (src); - - /* PROXY_AUTOCONFIG_URL */ - dest = copy_location_create_key (to, PROXY_AUTOCONFIG_URL_KEY); - src = copy_location_create_key (from, PROXY_AUTOCONFIG_URL_KEY); - - tstr = mateconf_client_get_string (client, src, NULL); - if (tstr != NULL) - { - mateconf_client_set_string (client, dest, tstr, NULL); - g_free (tstr); - } - - g_free (dest); - g_free (src); -} - -static gchar * -get_current_location (MateConfClient *client) -{ - gchar *result; - - result = mateconf_client_get_string (client, CURRENT_LOCATION, NULL); - - if (result == NULL || result[0] == '\0') - { - g_free (result); - result = g_strdup (_("Default")); - } - - return result; -} - -static gboolean -location_combo_separator (GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - gchar *name; - gboolean ret; - - gtk_tree_model_get (model, iter, COL_NAME, &name, -1); - - ret = name == NULL || name[0] == '\0'; - - g_free (name); - - return ret; -} - -static void -update_locations (MateConfClient *client, - GtkBuilder *builder); - -static void -cb_location_changed (GtkWidget *location, - GtkBuilder *builder); - -static void -cb_current_location (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - GtkBuilder *builder) -{ - MateConfValue *value; - const gchar *newval; - - value = mateconf_entry_get_value (entry); - if (value == NULL) - return; - - newval = mateconf_value_get_string (value); - if (newval == NULL) - return; - - /* prevent the current settings from being saved by blocking - * the signal handler */ - g_signal_handlers_block_by_func (gtk_builder_get_object (builder, "location_combobox"), - cb_location_changed, builder); - update_locations (client, builder); - g_signal_handlers_unblock_by_func (gtk_builder_get_object (builder, "location_combobox"), - cb_location_changed, builder); -} - -static void -update_locations (MateConfClient *client, - GtkBuilder *builder) -{ - int i, select; - gchar *current; - GtkComboBox *location = GTK_COMBO_BOX (gtk_builder_get_object (builder, "location_combobox")); - GSList *list = mateconf_client_all_dirs (client, LOCATION_DIR, NULL); - GtkTreeIter titer; - GtkListStore *store; - GSList *iter, *last; - - store = GTK_LIST_STORE (gtk_combo_box_get_model (location)); - gtk_list_store_clear (store); - - current = get_current_location (client); - - list = g_slist_append (list, g_strconcat (LOCATION_DIR"/", current, NULL)); - list = g_slist_sort (list, (GCompareFunc) strcmp); - - select = -1; - - for (i = 0, iter = list, last = NULL; iter != NULL; last = iter, iter = g_slist_next (iter), ++i) - { - if (last == NULL || strcmp (last->data, iter->data) != 0) - { - gchar *locp, *key_name; - - locp = iter->data + strlen (LOCATION_DIR) + 1; - key_name = mateconf_unescape_key (locp, -1); - - gtk_list_store_append (store, &titer); - gtk_list_store_set (store, &titer, - COL_NAME, key_name, - COL_STYLE, PANGO_STYLE_NORMAL, -1); - - g_free (key_name); - - if (strcmp (locp, current) == 0) - select = i; - } - } - if (select == -1) - { - gtk_list_store_append (store, &titer); - gtk_list_store_set (store, &titer, - COL_NAME , current, - COL_STYLE, PANGO_STYLE_NORMAL, -1); - select = i++; - } - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, - "delete_button"), - i > 1); - - gtk_list_store_append (store, &titer); - gtk_list_store_set (store, &titer, - COL_NAME, NULL, - COL_STYLE, PANGO_STYLE_NORMAL, -1); - - gtk_list_store_append (store, &titer); - gtk_list_store_set (store, &titer, - COL_NAME, _("New Location..."), - COL_STYLE, PANGO_STYLE_ITALIC, -1); - - gtk_combo_box_set_row_separator_func (location, location_combo_separator, NULL, NULL); - gtk_combo_box_set_active (location, select); - g_free (current); - g_slist_foreach (list, (GFunc) mateconf_entry_free, NULL); - g_slist_free (list); -} - -static void -cb_location_new_text_changed (GtkEntry *entry, GtkBuilder *builder) -{ - gboolean exists; - gchar *current, *esc, *key; - const gchar *name; - MateConfClient *client; - - client = mateconf_client_get_default (); - - name = gtk_entry_get_text (entry); - if (name != NULL && name[0] != '\0') - { - esc = mateconf_escape_key (name, -1); - - key = g_strconcat (LOCATION_DIR "/", esc, NULL); - g_free (esc); - - current = get_current_location (client); - - exists = (strcmp (current, name) == 0) || - mateconf_client_dir_exists (client, key, NULL); - g_free (key); - } else exists = FALSE; - - g_object_unref (client); - - if (exists) - gtk_widget_show (_gtk_builder_get_widget (builder, - "error_label")); - else - gtk_widget_hide (_gtk_builder_get_widget (builder, - "error_label")); - - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, - "new_location"), - !exists); -} - -static void -location_new (GtkBuilder *capplet_builder, GtkWidget *parent) -{ - GtkBuilder *builder; - GError *error = NULL; - gchar *builder_widgets[] = { "location_new_dialog", - "new_location_btn_img", NULL }; - GtkWidget *askdialog; - const gchar *name; - int response; - MateConfClient *client; - - client = mateconf_client_get_default (); - - builder = gtk_builder_new (); - if (gtk_builder_add_objects_from_file (builder, MATECC_GNP_UI_FILE, - builder_widgets, &error) == 0) { - g_warning ("Could not load location dialog: %s", - error->message); - g_error_free (error); - g_object_unref (builder); - return; - } - - askdialog = _gtk_builder_get_widget (builder, "location_new_dialog"); - gtk_window_set_transient_for (GTK_WINDOW (askdialog), GTK_WINDOW (parent)); - g_signal_connect (askdialog, "response", - G_CALLBACK (gtk_widget_hide), NULL); - g_signal_connect (gtk_builder_get_object (builder, "text"), "changed", - G_CALLBACK (cb_location_new_text_changed), builder); - response = gtk_dialog_run (GTK_DIALOG (askdialog)); - name = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, "text"))); - g_object_unref (builder); - - if (response == GTK_RESPONSE_OK && name[0] != '\0') - { - gboolean exists; - gchar *current, *esc, *key; - esc = mateconf_escape_key (name, -1); - key = g_strconcat (LOCATION_DIR "/", esc, NULL); - g_free (esc); - - current = get_current_location (client); - - exists = (strcmp (current, name) == 0) || - mateconf_client_dir_exists (client, key, NULL); - - g_free (key); - - if (!exists) - { - esc = mateconf_escape_key (current, -1); - g_free (current); - key = g_strconcat (LOCATION_DIR "/", esc, NULL); - g_free (esc); - - copy_location ("", key, client); - g_free (key); - - mateconf_client_set_string (client, CURRENT_LOCATION, name, NULL); - update_locations (client, capplet_builder); - } - else - { - GtkWidget *err = gtk_message_dialog_new (GTK_WINDOW (askdialog), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - _("Location already exists")); - gtk_dialog_run (GTK_DIALOG (err)); - gtk_widget_destroy (err); - - /* switch back to the currently selected location */ - mateconf_client_notify (client, CURRENT_LOCATION); - } - } - else - { - /* switch back to the currently selected location */ - mateconf_client_notify (client, CURRENT_LOCATION); - } - gtk_widget_destroy (askdialog); - g_object_unref (client); -} - -static void -cb_location_changed (GtkWidget *location, - GtkBuilder *builder) -{ - gchar *current; - gchar *name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (location)); - MateConfClient *client; - - if (name == NULL) - return; - - client = mateconf_client_get_default (); - - current = get_current_location (client); - - if (strcmp (current, name) != 0) - { - if (strcmp (name, _("New Location...")) == 0) - { - location_new (builder, _gtk_builder_get_widget (builder, "network_dialog")); - } - else - { - gchar *key, *esc; - - /* save current settings */ - esc = mateconf_escape_key (current, -1); - key = g_strconcat (LOCATION_DIR "/", esc, NULL); - g_free (esc); - - copy_location ("", key, client); - g_free (key); - - /* load settings */ - esc = mateconf_escape_key (name, -1); - key = g_strconcat (LOCATION_DIR "/", esc, NULL); - g_free (esc); - - copy_location (key, "", client); - mateconf_client_recursive_unset (client, key, - MATECONF_UNSET_INCLUDING_SCHEMA_NAMES, NULL); - g_free (key); - - mateconf_client_set_string (client, CURRENT_LOCATION, name, NULL); - } - } - - g_free (current); - g_free (name); - g_object_unref (client); -} - -static void -cb_delete_button_clicked (GtkWidget *button, - GtkBuilder *builder) -{ - MateConfClient *client; - GtkComboBox *box = GTK_COMBO_BOX (gtk_builder_get_object (builder, - "location_combobox")); - int active = gtk_combo_box_get_active (box); - gchar *current, *key, *esc; - - /* prevent the current settings from being saved by blocking - * the signal handler */ - g_signal_handlers_block_by_func (box, cb_location_changed, builder); - gtk_combo_box_set_active (box, (active == 0) ? 1 : 0); - gtk_combo_box_remove_text (box, active); - g_signal_handlers_unblock_by_func (box, cb_location_changed, builder); - - /* set the new location */ - client = mateconf_client_get_default (); - current = gtk_combo_box_get_active_text (box); - - esc = mateconf_escape_key (current, -1); - key = g_strconcat (LOCATION_DIR "/", esc, NULL); - g_free (esc); - - copy_location (key, "", client); - mateconf_client_recursive_unset (client, key, - MATECONF_UNSET_INCLUDING_SCHEMA_NAMES, NULL); - mateconf_client_suggest_sync (client, NULL); - g_free (key); - - mateconf_client_set_string (client, CURRENT_LOCATION, current, NULL); - - g_free (current); - - g_object_unref (client); -} - -/* When using the same proxy for all protocols, updates every host_entry - * as the user types along */ -static void -synchronize_hosts (GtkEntry *widget, - GtkBuilder *builder) -{ - const gchar *hosts[] = { - "secure_host_entry", - "ftp_host_entry", - "socks_host_entry", - NULL }; - const gchar **host, *http_host; - - http_host = gtk_entry_get_text (widget); - - for (host = hosts; *host != NULL; ++host) - { - widget = GTK_ENTRY (gtk_builder_get_object (builder, *host)); - gtk_entry_set_text (widget, http_host); - } -} - -/* When using the same proxy for all protocols, copies the value of the - * http port to the other spinbuttons */ -static void -synchronize_ports (GtkSpinButton *widget, - GtkBuilder *builder) -{ - const gchar *ports[] = { - "secure_port_spinbutton", - "ftp_port_spinbutton", - "socks_port_spinbutton", - NULL }; - gdouble http_port; - const gchar **port; - - http_port = gtk_spin_button_get_value (widget); - - for (port = ports; *port != NULL; ++port) - { - widget = GTK_SPIN_BUTTON ( - gtk_builder_get_object (builder, *port)); - gtk_spin_button_set_value (widget, http_port); - } -} - -/* Synchronizes all hosts and ports */ -static void -synchronize_entries (GtkBuilder *builder) -{ - g_signal_connect ( - gtk_builder_get_object (builder, "http_host_entry"), - "changed", - G_CALLBACK (synchronize_hosts), - builder); - g_signal_connect ( - gtk_builder_get_object (builder, "http_port_spinbutton"), - "value-changed", - G_CALLBACK (synchronize_ports), - builder); -} - -/* Unsynchronize hosts and ports */ -static void -unsynchronize_entries (GtkBuilder *builder) -{ - g_signal_handlers_disconnect_by_func ( - gtk_builder_get_object (builder, "http_host_entry"), - synchronize_hosts, - builder); - g_signal_handlers_disconnect_by_func ( - gtk_builder_get_object (builder, "http_port_spinbutton"), - synchronize_ports, - builder); -} - -static void -cb_use_same_proxy_checkbutton_clicked (GtkWidget *checkbutton, - GtkBuilder *builder) -{ - MateConfClient *client; - gboolean same_proxy; - gchar *http_proxy; - gint http_port; - gchar *host; - - client = mateconf_client_get_default (); - same_proxy = mateconf_client_get_bool (client, USE_SAME_PROXY_KEY, NULL); - - http_proxy = mateconf_client_get_string (client, HTTP_PROXY_HOST_KEY, NULL); - http_port = mateconf_client_get_int (client, HTTP_PROXY_PORT_KEY, NULL); - - if (same_proxy) - { - /* Save the old values */ - host = mateconf_client_get_string (client, SECURE_PROXY_HOST_KEY, NULL); - mateconf_client_set_string (client, OLD_SECURE_PROXY_HOST_KEY, host, NULL); - mateconf_client_set_int (client, OLD_SECURE_PROXY_PORT_KEY, - mateconf_client_get_int (client, SECURE_PROXY_PORT_KEY, NULL), NULL); - g_free (host); - - host = mateconf_client_get_string (client, FTP_PROXY_HOST_KEY, NULL); - mateconf_client_set_string (client, OLD_FTP_PROXY_HOST_KEY, host, NULL); - mateconf_client_set_int (client, OLD_FTP_PROXY_PORT_KEY, - mateconf_client_get_int (client, FTP_PROXY_PORT_KEY, NULL), NULL); - g_free (host); - - host = mateconf_client_get_string (client, SOCKS_PROXY_HOST_KEY, NULL); - mateconf_client_set_string (client, OLD_SOCKS_PROXY_HOST_KEY, host, NULL); - mateconf_client_set_int (client, OLD_SOCKS_PROXY_PORT_KEY, - mateconf_client_get_int (client, SOCKS_PROXY_PORT_KEY, NULL), NULL); - g_free (host); - - /* Set the new values */ - mateconf_client_set_string (client, SECURE_PROXY_HOST_KEY, http_proxy, NULL); - mateconf_client_set_int (client, SECURE_PROXY_PORT_KEY, http_port, NULL); - - mateconf_client_set_string (client, FTP_PROXY_HOST_KEY, http_proxy, NULL); - mateconf_client_set_int (client, FTP_PROXY_PORT_KEY, http_port, NULL); - - mateconf_client_set_string (client, SOCKS_PROXY_HOST_KEY, http_proxy, NULL); - mateconf_client_set_int (client, SOCKS_PROXY_PORT_KEY, http_port, NULL); - - /* Synchronize entries */ - synchronize_entries (builder); - } - else - { - host = mateconf_client_get_string (client, OLD_SECURE_PROXY_HOST_KEY, NULL); - mateconf_client_set_string (client, SECURE_PROXY_HOST_KEY, host, NULL); - mateconf_client_set_int (client, SECURE_PROXY_PORT_KEY, - mateconf_client_get_int (client, OLD_SECURE_PROXY_PORT_KEY, NULL), NULL); - g_free (host); - - host = mateconf_client_get_string (client, OLD_FTP_PROXY_HOST_KEY, NULL); - mateconf_client_set_string (client, FTP_PROXY_HOST_KEY, host, NULL); - mateconf_client_set_int (client, FTP_PROXY_PORT_KEY, - mateconf_client_get_int (client, OLD_FTP_PROXY_PORT_KEY, NULL), NULL); - g_free (host); - - host = mateconf_client_get_string (client, OLD_SOCKS_PROXY_HOST_KEY, NULL); - mateconf_client_set_string (client, SOCKS_PROXY_HOST_KEY, host, NULL); - mateconf_client_set_int (client, SOCKS_PROXY_PORT_KEY, - mateconf_client_get_int (client, OLD_SOCKS_PROXY_PORT_KEY, NULL), NULL); - g_free (host); - - /* Hosts and ports should not be synchronized any more */ - unsynchronize_entries (builder); - } - - /* Set the proxy entries insensitive if we are using the same proxy for all */ - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, - "secure_host_entry"), - !same_proxy); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, - "secure_port_spinbutton"), - !same_proxy); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, - "ftp_host_entry"), - !same_proxy); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, - "ftp_port_spinbutton"), - !same_proxy); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, - "socks_host_entry"), - !same_proxy); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, - "socks_port_spinbutton"), - !same_proxy); - - g_object_unref (client); -} - -static gchar * -get_hostname_from_uri (const gchar *uri) -{ - const gchar *start, *end; - gchar *host; - - if (uri == NULL) - return NULL; - - /* skip the scheme part */ - start = strchr (uri, ':'); - if (start == NULL) - return NULL; - - /* forward until after the last '/' */ - do { - ++start; - } while (*start == '/'); - - if (*start == '\0') - return NULL; - - /* maybe we have a port? */ - end = strchr (start, ':'); - if (end == NULL) - end = strchr (start, '/'); - - if (end != NULL) - host = g_strndup (start, end - start); - else - host = g_strdup (start); - - return host; -} - -static MateConfValue * -extract_proxy_host (MateConfPropertyEditor *peditor, const MateConfValue *orig) +proxy_mode_gsettings_changed (GSettings *settings, + gchar *key, + GtkBuilder *builder) { - char const *entered_text = mateconf_value_get_string (orig); - MateConfValue *res = NULL; - - if (entered_text != NULL) { - gchar *host = get_hostname_from_uri (entered_text); - - if (host != NULL) { - res = mateconf_value_new (MATECONF_VALUE_STRING); - mateconf_value_set_string (res, host); - g_free (host); - } - } - - return (res != NULL) ? res : mateconf_value_copy (orig); + int mode; + mode = g_settings_get_enum (settings, PROXY_MODE_KEY); + if (mode == PROXYMODE_NONE) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object(builder, "none_radiobutton")), TRUE); + else if (mode == PROXYMODE_AUTO) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object(builder, "auto_radiobutton")), TRUE); + else if (mode == PROXYMODE_MANUAL) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object(builder, "manual_radiobutton")), TRUE); + gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "manual_box"), + mode == PROXYMODE_MANUAL); + gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "auto_box"), + mode == PROXYMODE_AUTO); } static void @@ -1153,7 +335,7 @@ proxy_mode_radiobutton_clicked_cb (GtkWidget *widget, { GSList *mode_group; int mode; - MateConfClient *client; + int old_mode; if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget))) return; @@ -1164,16 +346,12 @@ proxy_mode_radiobutton_clicked_cb (GtkWidget *widget, mode = g_slist_index (mode_group, widget); g_slist_free (mode_group); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "manual_box"), - mode == PROXYMODE_MANUAL); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "same_proxy_checkbutton"), - mode == PROXYMODE_MANUAL); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "auto_box"), - mode == PROXYMODE_AUTO); - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, USE_PROXY_KEY, - mode == PROXYMODE_AUTO || mode == PROXYMODE_MANUAL, NULL); - g_object_unref (client); + old_mode = g_settings_get_enum (proxy_settings, PROXY_MODE_KEY); + + if (mode == old_mode) + return; + + g_settings_set_enum (proxy_settings, PROXY_MODE_KEY, mode); } static void @@ -1188,14 +366,12 @@ connect_sensitivity_signals (GtkBuilder *builder, GSList *mode_group) } static void -cb_ignore_hosts_mateconf_changed (MateConfClient *client, guint cnxn_id, - MateConfEntry *entry, gpointer user_data) +cb_ignore_hosts_gsettings_changed (GSettings *settings, gchar *key, gpointer user_data) { g_slist_foreach (ignore_hosts, (GFunc) g_free, NULL); g_slist_free (ignore_hosts); - ignore_hosts = mateconf_client_get_list (client, IGNORE_HOSTS_KEY, - MATECONF_VALUE_STRING, NULL); + read_ignore_hosts_from_gsettings (); populate_listmodel (GTK_LIST_STORE (model), ignore_hosts); } @@ -1203,140 +379,65 @@ cb_ignore_hosts_mateconf_changed (MateConfClient *client, guint cnxn_id, static void setup_dialog (GtkBuilder *builder) { - MateConfPropertyEditor *peditor; + gint mode; GSList *mode_group; - GType mode_type = 0; - MateConfClient *client; - gint port_value; - GtkWidget *location_box, *same_proxy_toggle; - GtkCellRenderer *location_renderer; GtkListStore *store; - mode_type = g_enum_register_static ("NetworkPreferencesProxyType", - proxytype_values); - - client = mateconf_client_get_default (); - - /* Locations */ - location_box = _gtk_builder_get_widget (builder, "location_combobox"); - store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT); - gtk_combo_box_set_model (GTK_COMBO_BOX (location_box), GTK_TREE_MODEL (store)); - - update_locations (client, builder); - mateconf_client_add_dir (client, LOCATION_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - mateconf_client_notify_add (client, CURRENT_LOCATION, (MateConfClientNotifyFunc) cb_current_location, builder, NULL, NULL); - - mateconf_client_notify_add (client, IGNORE_HOSTS_KEY, cb_ignore_hosts_mateconf_changed, NULL, NULL, NULL); - - g_signal_connect (location_box, "changed", G_CALLBACK (cb_location_changed), builder); - g_signal_connect (gtk_builder_get_object (builder, "delete_button"), "clicked", G_CALLBACK (cb_delete_button_clicked), builder); - - location_renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (location_box), location_renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (location_box), - location_renderer, - "text", COL_NAME, - "style", COL_STYLE, NULL); + g_signal_connect (proxy_settings, "changed::" IGNORE_HOSTS_KEY, + G_CALLBACK (cb_ignore_hosts_gsettings_changed), NULL); /* Mode */ + proxy_mode_gsettings_changed (proxy_settings, PROXY_MODE_KEY, builder); mode_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "none_radiobutton"))); connect_sensitivity_signals (builder, mode_group); - - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_select_radio_with_enum (NULL, - PROXY_MODE_KEY, mode_group, mode_type, - TRUE, NULL)); - - /* Use same proxy for all protocols */ - same_proxy_toggle = _gtk_builder_get_widget (builder, "same_proxy_checkbutton"); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_boolean (NULL, - USE_SAME_PROXY_KEY, same_proxy_toggle, NULL)); - - g_signal_connect (same_proxy_toggle, - "toggled", - G_CALLBACK (cb_use_same_proxy_checkbutton_clicked), - builder); + g_signal_connect (proxy_settings, "changed::" PROXY_MODE_KEY, + G_CALLBACK (proxy_mode_gsettings_changed), builder); /* Http */ - port_value = mateconf_client_get_int (client, HTTP_PROXY_PORT_KEY, NULL); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "http_port_spinbutton")), (gdouble) port_value); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_string ( - NULL, HTTP_PROXY_HOST_KEY, _gtk_builder_get_widget (builder, "http_host_entry"), - "conv-from-widget-cb", extract_proxy_host, - NULL)); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_integer ( - NULL, HTTP_PROXY_PORT_KEY, - _gtk_builder_get_widget (builder, "http_port_spinbutton"), - NULL)); + g_settings_bind (http_proxy_settings, HTTP_PROXY_PORT_KEY, + gtk_builder_get_object (builder, "http_port_spinbutton"), "value", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind (http_proxy_settings, HTTP_PROXY_HOST_KEY, + gtk_builder_get_object (builder, "http_host_entry"), "text", + G_SETTINGS_BIND_DEFAULT); g_signal_connect (gtk_builder_get_object (builder, "details_button"), "clicked", G_CALLBACK (cb_http_details_button_clicked), _gtk_builder_get_widget (builder, "network_dialog")); /* Secure */ - port_value = mateconf_client_get_int (client, SECURE_PROXY_PORT_KEY, NULL); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "secure_port_spinbutton")), (gdouble) port_value); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_string ( - NULL, SECURE_PROXY_HOST_KEY, - _gtk_builder_get_widget (builder, "secure_host_entry"), - "conv-from-widget-cb", extract_proxy_host, - NULL)); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_integer ( - NULL, SECURE_PROXY_PORT_KEY, - _gtk_builder_get_widget (builder, "secure_port_spinbutton"), - NULL)); + g_settings_bind (https_proxy_settings, SECURE_PROXY_PORT_KEY, + gtk_builder_get_object (builder, "secure_port_spinbutton"), "value", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind (https_proxy_settings, SECURE_PROXY_HOST_KEY, + gtk_builder_get_object (builder, "secure_host_entry"), "text", + G_SETTINGS_BIND_DEFAULT); /* Ftp */ - port_value = mateconf_client_get_int (client, FTP_PROXY_PORT_KEY, NULL); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "ftp_port_spinbutton")), (gdouble) port_value); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_string ( - NULL, FTP_PROXY_HOST_KEY, - _gtk_builder_get_widget (builder, "ftp_host_entry"), - "conv-from-widget-cb", extract_proxy_host, - NULL)); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_integer ( - NULL, FTP_PROXY_PORT_KEY, - _gtk_builder_get_widget (builder, "ftp_port_spinbutton"), - NULL)); + g_settings_bind (ftp_proxy_settings, FTP_PROXY_PORT_KEY, + gtk_builder_get_object (builder, "ftp_port_spinbutton"), "value", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind (ftp_proxy_settings, FTP_PROXY_HOST_KEY, + gtk_builder_get_object (builder, "ftp_host_entry"), "text", + G_SETTINGS_BIND_DEFAULT); /* Socks */ - port_value = mateconf_client_get_int (client, SOCKS_PROXY_PORT_KEY, NULL); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "socks_port_spinbutton")), (gdouble) port_value); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_string ( - NULL, SOCKS_PROXY_HOST_KEY, - _gtk_builder_get_widget (builder, "socks_host_entry"), - "conv-from-widget-cb", extract_proxy_host, - NULL)); - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_integer ( - NULL, SOCKS_PROXY_PORT_KEY, - _gtk_builder_get_widget (builder, "socks_port_spinbutton"), - NULL)); - - /* Set the proxy entries insensitive if we are using the same proxy for all, - and make sure they are all synchronized */ - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (same_proxy_toggle))) - { - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "secure_host_entry"), FALSE); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "secure_port_spinbutton"), FALSE); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "ftp_host_entry"), FALSE); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "ftp_port_spinbutton"), FALSE); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "socks_host_entry"), FALSE); - gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "socks_port_spinbutton"), FALSE); - - synchronize_entries (builder); - } + g_settings_bind (socks_proxy_settings, SOCKS_PROXY_PORT_KEY, + gtk_builder_get_object (builder, "socks_port_spinbutton"), "value", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind (socks_proxy_settings, SOCKS_PROXY_HOST_KEY, + gtk_builder_get_object (builder, "socks_host_entry"), "text", + G_SETTINGS_BIND_DEFAULT); /* Autoconfiguration */ - peditor = MATECONF_PROPERTY_EDITOR (mateconf_peditor_new_string ( - NULL, PROXY_AUTOCONFIG_URL_KEY, - _gtk_builder_get_widget (builder, "autoconfig_entry"), - NULL)); + g_settings_bind (proxy_settings, PROXY_AUTOCONFIG_URL_KEY, + gtk_builder_get_object (builder, "autoconfig_entry"), "text", + G_SETTINGS_BIND_DEFAULT); g_signal_connect (gtk_builder_get_object (builder, "network_dialog"), - "response", G_CALLBACK (cb_dialog_response), NULL); - + "response", G_CALLBACK (cb_dialog_response), NULL); - ignore_hosts = mateconf_client_get_list(client, IGNORE_HOSTS_KEY, MATECONF_VALUE_STRING, NULL); - g_object_unref (client); + read_ignore_hosts_from_gsettings (); model = create_listmodel(); populate_listmodel(GTK_LIST_STORE(model), ignore_hosts); @@ -1358,7 +459,6 @@ main (int argc, char **argv) gchar *builder_widgets[] = {"network_dialog", "adjustment1", "adjustment2", "adjustment3", "adjustment4", "delete_button_img", NULL}; - MateConfClient *client; GtkWidget *widget; bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR); @@ -1367,12 +467,6 @@ main (int argc, char **argv) gtk_init (&argc, &argv); - client = mateconf_client_get_default (); - mateconf_client_add_dir (client, "/system/http_proxy", - MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - mateconf_client_add_dir (client, "/system/proxy", - MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - builder = gtk_builder_new (); if (gtk_builder_add_objects_from_file (builder, MATECC_GNP_UI_FILE, builder_widgets, &error) == 0) { @@ -1380,10 +474,15 @@ main (int argc, char **argv) error->message); g_error_free (error); g_object_unref (builder); - g_object_unref (client); return (EXIT_FAILURE); } + proxy_settings = g_settings_new (PROXY_SCHEMA); + http_proxy_settings = g_settings_new (HTTP_PROXY_SCHEMA); + https_proxy_settings = g_settings_new (HTTPS_PROXY_SCHEMA); + ftp_proxy_settings = g_settings_new (FTP_PROXY_SCHEMA); + socks_proxy_settings = g_settings_new (SOCKS_PROXY_SCHEMA); + setup_dialog (builder); widget = _gtk_builder_get_widget (builder, "network_dialog"); capplet_set_icon (widget, "mate-network-properties"); @@ -1391,7 +490,11 @@ main (int argc, char **argv) gtk_main (); g_object_unref (builder); - g_object_unref (client); + g_object_unref (proxy_settings); + g_object_unref (http_proxy_settings); + g_object_unref (https_proxy_settings); + g_object_unref (ftp_proxy_settings); + g_object_unref (socks_proxy_settings); return 0; } |