1
/* gnome-network-properties.c: network preferences capplet
3
* Copyright (C) 2002 Sun Microsystems Inc.
5
* Written by: Mark McLoughlin <mark@skynet.ie>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2, or (at your option)
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29
#include <gconf/gconf-client.h>
30
#include <glib/gi18n.h>
32
#include "capplet-util.h"
33
#include "gconf-property-editor.h"
42
static GEnumValue proxytype_values[] = {
43
{ PROXYMODE_NONE, "PROXYMODE_NONE", "none"},
44
{ PROXYMODE_MANUAL, "PROXYMODE_MANUAL", "manual"},
45
{ PROXYMODE_AUTO, "PROXYMODE_AUTO", "auto"},
54
#define USE_PROXY_KEY "/system/http_proxy/use_http_proxy"
55
#define USE_SAME_PROXY_KEY "/system/http_proxy/use_same_proxy"
56
#define HTTP_PROXY_HOST_KEY "/system/http_proxy/host"
57
#define HTTP_PROXY_PORT_KEY "/system/http_proxy/port"
58
#define HTTP_USE_AUTH_KEY "/system/http_proxy/use_authentication"
59
#define HTTP_AUTH_USER_KEY "/system/http_proxy/authentication_user"
60
#define HTTP_AUTH_PASSWD_KEY "/system/http_proxy/authentication_password"
61
#define IGNORE_HOSTS_KEY "/system/http_proxy/ignore_hosts"
62
#define PROXY_MODE_KEY "/system/proxy/mode"
63
#define SECURE_PROXY_HOST_KEY "/system/proxy/secure_host"
64
#define OLD_SECURE_PROXY_HOST_KEY "/system/proxy/old_secure_host"
65
#define SECURE_PROXY_PORT_KEY "/system/proxy/secure_port"
66
#define OLD_SECURE_PROXY_PORT_KEY "/system/proxy/old_secure_port"
67
#define FTP_PROXY_HOST_KEY "/system/proxy/ftp_host"
68
#define OLD_FTP_PROXY_HOST_KEY "/system/proxy/old_ftp_host"
69
#define FTP_PROXY_PORT_KEY "/system/proxy/ftp_port"
70
#define OLD_FTP_PROXY_PORT_KEY "/system/proxy/old_ftp_port"
71
#define SOCKS_PROXY_HOST_KEY "/system/proxy/socks_host"
72
#define OLD_SOCKS_PROXY_HOST_KEY "/system/proxy/old_socks_host"
73
#define SOCKS_PROXY_PORT_KEY "/system/proxy/socks_port"
74
#define OLD_SOCKS_PROXY_PORT_KEY "/system/proxy/old_socks_port"
75
#define PROXY_AUTOCONFIG_URL_KEY "/system/proxy/autoconfig_url"
77
#define LOCATION_DIR "/apps/control-center/network"
78
#define CURRENT_LOCATION "/apps/control-center/network/current_location"
80
#define GNOMECC_GNP_UI_FILE (GNOMECC_UI_DIR "/gnome-network-properties.ui")
82
static GtkWidget *details_dialog = NULL;
83
static GSList *ignore_hosts = NULL;
84
static GtkTreeModel *model = NULL;
87
create_listmodel(void)
91
store = gtk_list_store_new(1, G_TYPE_STRING);
93
return GTK_TREE_MODEL(store);
97
populate_listmodel(GtkListStore *store, GSList *list)
102
gtk_list_store_clear(store);
107
gtk_list_store_append(store, &iter);
108
gtk_list_store_set(store, &iter, 0, (char *) pointer->data, -1);
109
pointer = g_slist_next(pointer);
112
return GTK_TREE_MODEL(store);
116
config_treeview(GtkTreeView *tree, GtkTreeModel *model)
118
GtkCellRenderer *renderer;
120
renderer = gtk_cell_renderer_text_new();
121
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree),
122
-1, "Hosts", renderer,
125
gtk_tree_view_set_model(GTK_TREE_VIEW(tree), model);
127
return GTK_WIDGET(tree);
131
_gtk_builder_get_widget (GtkBuilder *builder, const gchar *name)
133
return GTK_WIDGET (gtk_builder_get_object (builder, name));
138
cb_add_url (GtkButton *button, gpointer data)
140
GtkBuilder *builder = GTK_BUILDER (data);
141
gchar *new_url = NULL;
144
new_url = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, "entry_url"))));
145
if (strlen (new_url) == 0)
147
ignore_hosts = g_slist_append(ignore_hosts, new_url);
148
populate_listmodel(GTK_LIST_STORE(model), ignore_hosts);
149
gtk_entry_set_text(GTK_ENTRY (gtk_builder_get_object (builder,
152
client = gconf_client_get_default ();
153
gconf_client_set_list (client, IGNORE_HOSTS_KEY, GCONF_VALUE_STRING, ignore_hosts, NULL);
154
g_object_unref (client);
158
cb_remove_url (GtkButton *button, gpointer data)
160
GtkBuilder *builder = GTK_BUILDER (data);
161
GtkTreeSelection *selection;
165
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview_ignore_host")));
166
if (gtk_tree_selection_get_selected(selection, &model, &iter))
171
gtk_tree_model_get (model, &iter, 0, &url, -1);
173
pointer = ignore_hosts;
176
if(strcmp(url, (char *) pointer->data) == 0)
178
g_free (pointer->data);
179
ignore_hosts = g_slist_delete_link(ignore_hosts, pointer);
182
pointer = g_slist_next(pointer);
186
populate_listmodel(GTK_LIST_STORE(model), ignore_hosts);
188
client = gconf_client_get_default ();
189
gconf_client_set_list(client, IGNORE_HOSTS_KEY, GCONF_VALUE_STRING, ignore_hosts, NULL);
190
g_object_unref (client);
195
cb_dialog_response (GtkDialog *dialog, gint response_id)
197
if (response_id == GTK_RESPONSE_HELP)
198
capplet_help (GTK_WINDOW (dialog),
200
else if (response_id == GTK_RESPONSE_CLOSE || response_id == GTK_RESPONSE_DELETE_EVENT)
203
g_slist_foreach (ignore_hosts, (GFunc) g_free, NULL);
204
g_slist_free (ignore_hosts);
212
cb_details_dialog_response (GtkDialog *dialog, gint response_id)
214
if (response_id == GTK_RESPONSE_HELP)
215
capplet_help (GTK_WINDOW (dialog),
218
gtk_widget_destroy (GTK_WIDGET (dialog));
219
details_dialog = NULL;
224
cb_use_auth_toggled (GtkToggleButton *toggle,
227
gtk_widget_set_sensitive (table, gtk_toggle_button_get_active (toggle));
231
cb_http_details_button_clicked (GtkWidget *button,
235
gchar *builder_widgets[] = { "details_dialog", NULL };
236
GError *error = NULL;
238
GConfPropertyEditor *peditor;
240
if (details_dialog != NULL) {
241
gtk_window_present (GTK_WINDOW (details_dialog));
242
gtk_widget_grab_focus (details_dialog);
246
builder = gtk_builder_new ();
247
if (gtk_builder_add_objects_from_file (builder, GNOMECC_GNP_UI_FILE,
248
builder_widgets, &error) == 0) {
249
g_warning ("Could not load details dialog: %s", error->message);
250
g_error_free (error);
251
g_object_unref (builder);
255
details_dialog = widget = _gtk_builder_get_widget (builder,
258
gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (parent));
260
g_signal_connect (gtk_builder_get_object (builder, "use_auth_checkbutton"),
262
G_CALLBACK (cb_use_auth_toggled),
263
_gtk_builder_get_widget (builder, "auth_table"));
265
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_boolean (
266
NULL, HTTP_USE_AUTH_KEY,
267
_gtk_builder_get_widget (builder, "use_auth_checkbutton"),
269
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
270
NULL, HTTP_AUTH_USER_KEY,
271
_gtk_builder_get_widget (builder, "username_entry"),
273
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
274
NULL, HTTP_AUTH_PASSWD_KEY,
275
_gtk_builder_get_widget (builder, "password_entry"),
278
g_signal_connect (widget, "response",
279
G_CALLBACK (cb_details_dialog_response), NULL);
281
capplet_set_icon (widget, "gnome-network-properties");
283
gtk_widget_show_all (widget);
287
copy_location_create_key (const gchar *from, const gchar *what)
289
if (from[0] == '\0') return g_strdup (what);
290
else return g_strconcat (from, what + strlen ("/system"), NULL);
294
copy_location (const gchar *from, const gchar *to, GConfClient *client)
299
gchar *tstr, *dest, *src;
301
if (from[0] != '\0' && !gconf_client_dir_exists (client, from, NULL))
305
dest = copy_location_create_key (to, USE_PROXY_KEY);
306
src = copy_location_create_key (from, USE_PROXY_KEY);
308
tb = gconf_client_get_bool (client, src, NULL);
309
gconf_client_set_bool (client, dest, tb, NULL);
315
dest = copy_location_create_key (to, USE_SAME_PROXY_KEY);
316
src = copy_location_create_key (from, USE_SAME_PROXY_KEY);
318
tb = gconf_client_get_bool (client, src, NULL);
319
gconf_client_set_bool (client, dest, tb, NULL);
324
/* HTTP_PROXY_HOST */
325
dest = copy_location_create_key (to, HTTP_PROXY_HOST_KEY);
326
src = copy_location_create_key (from, HTTP_PROXY_HOST_KEY);
328
tstr = gconf_client_get_string (client, src, NULL);
331
gconf_client_set_string (client, dest, tstr, NULL);
338
/* HTTP_PROXY_PORT */
339
dest = copy_location_create_key (to, HTTP_PROXY_PORT_KEY);
340
src = copy_location_create_key (from, HTTP_PROXY_PORT_KEY);
342
ti = gconf_client_get_int (client, src, NULL);
343
gconf_client_set_int (client, dest, ti, NULL);
349
dest = copy_location_create_key (to, HTTP_USE_AUTH_KEY);
350
src = copy_location_create_key (from, HTTP_USE_AUTH_KEY);
352
tb = gconf_client_get_bool (client, src, NULL);
353
gconf_client_set_bool (client, dest, tb, NULL);
359
dest = copy_location_create_key (to, HTTP_AUTH_USER_KEY);
360
src = copy_location_create_key (from, HTTP_AUTH_USER_KEY);
362
tstr = gconf_client_get_string (client, src, NULL);
365
gconf_client_set_string (client, dest, tstr, NULL);
372
/* HTTP_AUTH_PASSWD */
373
dest = copy_location_create_key (to, HTTP_AUTH_PASSWD_KEY);
374
src = copy_location_create_key (from, HTTP_AUTH_PASSWD_KEY);
376
tstr = gconf_client_get_string (client, src, NULL);
379
gconf_client_set_string (client, dest, tstr, NULL);
387
dest = copy_location_create_key (to, IGNORE_HOSTS_KEY);
388
src = copy_location_create_key (from, IGNORE_HOSTS_KEY);
390
tl = gconf_client_get_list (client, src, GCONF_VALUE_STRING, NULL);
391
gconf_client_set_list (client, dest, GCONF_VALUE_STRING, tl, NULL);
392
g_slist_foreach (tl, (GFunc) g_free, NULL);
399
dest = copy_location_create_key (to, PROXY_MODE_KEY);
400
src = copy_location_create_key (from, PROXY_MODE_KEY);
402
tstr = gconf_client_get_string (client, src, NULL);
405
gconf_client_set_string (client, dest, tstr, NULL);
412
/* SECURE_PROXY_HOST */
413
dest = copy_location_create_key (to, SECURE_PROXY_HOST_KEY);
414
src = copy_location_create_key (from, SECURE_PROXY_HOST_KEY);
416
tstr = gconf_client_get_string (client, src, NULL);
419
gconf_client_set_string (client, dest, tstr, NULL);
426
/* OLD_SECURE_PROXY_HOST */
427
dest = copy_location_create_key (to, OLD_SECURE_PROXY_HOST_KEY);
428
src = copy_location_create_key (from, OLD_SECURE_PROXY_HOST_KEY);
430
tstr = gconf_client_get_string (client, src, NULL);
433
gconf_client_set_string (client, dest, tstr, NULL);
440
/* SECURE_PROXY_PORT */
441
dest = copy_location_create_key (to, SECURE_PROXY_PORT_KEY);
442
src = copy_location_create_key (from, SECURE_PROXY_PORT_KEY);
444
ti = gconf_client_get_int (client, src, NULL);
445
gconf_client_set_int (client, dest, ti, NULL);
450
/* OLD_SECURE_PROXY_PORT */
451
dest = copy_location_create_key (to, OLD_SECURE_PROXY_PORT_KEY);
452
src = copy_location_create_key (from, OLD_SECURE_PROXY_PORT_KEY);
454
ti = gconf_client_get_int (client, src, NULL);
455
gconf_client_set_int (client, dest, ti, NULL);
461
dest = copy_location_create_key (to, FTP_PROXY_HOST_KEY);
462
src = copy_location_create_key (from, FTP_PROXY_HOST_KEY);
464
tstr = gconf_client_get_string (client, src, NULL);
467
gconf_client_set_string (client, dest, tstr, NULL);
474
/* OLD_FTP_PROXY_HOST */
475
dest = copy_location_create_key (to, OLD_FTP_PROXY_HOST_KEY);
476
src = copy_location_create_key (from, OLD_FTP_PROXY_HOST_KEY);
478
tstr = gconf_client_get_string (client, src, NULL);
481
gconf_client_set_string (client, dest, tstr, NULL);
489
dest = copy_location_create_key (to, FTP_PROXY_PORT_KEY);
490
src = copy_location_create_key (from, FTP_PROXY_PORT_KEY);
492
ti = gconf_client_get_int (client, src, NULL);
493
gconf_client_set_int (client, dest, ti, NULL);
498
/* OLD_FTP_PROXY_PORT */
499
dest = copy_location_create_key (to, OLD_FTP_PROXY_PORT_KEY);
500
src = copy_location_create_key (from, OLD_FTP_PROXY_PORT_KEY);
502
ti = gconf_client_get_int (client, src, NULL);
503
gconf_client_set_int (client, dest, ti, NULL);
508
/* SOCKS_PROXY_HOST */
509
dest = copy_location_create_key (to, SOCKS_PROXY_HOST_KEY);
510
src = copy_location_create_key (from, SOCKS_PROXY_HOST_KEY);
512
tstr = gconf_client_get_string (client, src, NULL);
515
gconf_client_set_string (client, dest, tstr, NULL);
522
/* OLD_SOCKS_PROXY_HOST */
523
dest = copy_location_create_key (to, OLD_SOCKS_PROXY_HOST_KEY);
524
src = copy_location_create_key (from, OLD_SOCKS_PROXY_HOST_KEY);
526
tstr = gconf_client_get_string (client, src, NULL);
529
gconf_client_set_string (client, dest, tstr, NULL);
536
/* SOCKS_PROXY_PORT */
537
dest = copy_location_create_key (to, SOCKS_PROXY_PORT_KEY);
538
src = copy_location_create_key (from, SOCKS_PROXY_PORT_KEY);
540
ti = gconf_client_get_int (client, src, NULL);
541
gconf_client_set_int (client, dest, ti, NULL);
546
/* OLD_SOCKS_PROXY_PORT */
547
dest = copy_location_create_key (to, OLD_SOCKS_PROXY_PORT_KEY);
548
src = copy_location_create_key (from, OLD_SOCKS_PROXY_PORT_KEY);
550
ti = gconf_client_get_int (client, src, NULL);
551
gconf_client_set_int (client, dest, ti, NULL);
556
/* PROXY_AUTOCONFIG_URL */
557
dest = copy_location_create_key (to, PROXY_AUTOCONFIG_URL_KEY);
558
src = copy_location_create_key (from, PROXY_AUTOCONFIG_URL_KEY);
560
tstr = gconf_client_get_string (client, src, NULL);
563
gconf_client_set_string (client, dest, tstr, NULL);
572
get_current_location (GConfClient *client)
576
result = gconf_client_get_string (client, CURRENT_LOCATION, NULL);
578
if (result == NULL || result[0] == '\0')
581
result = g_strdup (_("Default"));
588
location_combo_separator (GtkTreeModel *model,
595
gtk_tree_model_get (model, iter, COL_NAME, &name, -1);
597
ret = name == NULL || name[0] == '\0';
605
update_locations (GConfClient *client,
606
GtkBuilder *builder);
609
cb_location_changed (GtkWidget *location,
610
GtkBuilder *builder);
613
cb_current_location (GConfClient *client,
621
value = gconf_entry_get_value (entry);
625
newval = gconf_value_get_string (value);
629
/* prevent the current settings from being saved by blocking
630
* the signal handler */
631
g_signal_handlers_block_by_func (gtk_builder_get_object (builder, "location_combobox"),
632
cb_location_changed, builder);
633
update_locations (client, builder);
634
g_signal_handlers_unblock_by_func (gtk_builder_get_object (builder, "location_combobox"),
635
cb_location_changed, builder);
639
update_locations (GConfClient *client,
644
GtkComboBox *location = GTK_COMBO_BOX (gtk_builder_get_object (builder, "location_combobox"));
645
GSList *list = gconf_client_all_dirs (client, LOCATION_DIR, NULL);
650
store = GTK_LIST_STORE (gtk_combo_box_get_model (location));
651
gtk_list_store_clear (store);
653
current = get_current_location (client);
655
list = g_slist_append (list, g_strconcat (LOCATION_DIR"/", current, NULL));
656
list = g_slist_sort (list, (GCompareFunc) strcmp);
660
for (i = 0, iter = list, last = NULL; iter != NULL; last = iter, iter = g_slist_next (iter), ++i)
662
if (last == NULL || strcmp (last->data, iter->data) != 0)
664
gchar *locp, *key_name;
666
locp = iter->data + strlen (LOCATION_DIR) + 1;
667
key_name = gconf_unescape_key (locp, -1);
669
gtk_list_store_append (store, &titer);
670
gtk_list_store_set (store, &titer,
672
COL_STYLE, PANGO_STYLE_NORMAL, -1);
676
if (strcmp (locp, current) == 0)
682
gtk_list_store_append (store, &titer);
683
gtk_list_store_set (store, &titer,
685
COL_STYLE, PANGO_STYLE_NORMAL, -1);
688
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
692
gtk_list_store_append (store, &titer);
693
gtk_list_store_set (store, &titer,
695
COL_STYLE, PANGO_STYLE_NORMAL, -1);
697
gtk_list_store_append (store, &titer);
698
gtk_list_store_set (store, &titer,
699
COL_NAME, _("New Location..."),
700
COL_STYLE, PANGO_STYLE_ITALIC, -1);
702
gtk_combo_box_set_row_separator_func (location, location_combo_separator, NULL, NULL);
703
gtk_combo_box_set_active (location, select);
705
g_slist_foreach (list, (GFunc) gconf_entry_free, NULL);
710
cb_location_new_text_changed (GtkEntry *entry, GtkBuilder *builder)
713
gchar *current, *esc, *key;
717
client = gconf_client_get_default ();
719
name = gtk_entry_get_text (entry);
720
if (name != NULL && name[0] != '\0')
722
esc = gconf_escape_key (name, -1);
724
key = g_strconcat (LOCATION_DIR "/", esc, NULL);
727
current = get_current_location (client);
729
exists = (strcmp (current, name) == 0) ||
730
gconf_client_dir_exists (client, key, NULL);
732
} else exists = FALSE;
734
g_object_unref (client);
737
gtk_widget_show (_gtk_builder_get_widget (builder,
740
gtk_widget_hide (_gtk_builder_get_widget (builder,
743
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
749
location_new (GtkBuilder *capplet_builder, GtkWidget *parent)
752
GError *error = NULL;
753
gchar *builder_widgets[] = { "location_new_dialog",
754
"new_location_btn_img", NULL };
755
GtkWidget *askdialog;
760
client = gconf_client_get_default ();
762
builder = gtk_builder_new ();
763
if (gtk_builder_add_objects_from_file (builder, GNOMECC_GNP_UI_FILE,
764
builder_widgets, &error) == 0) {
765
g_warning ("Could not load location dialog: %s",
767
g_error_free (error);
768
g_object_unref (builder);
772
askdialog = _gtk_builder_get_widget (builder, "location_new_dialog");
773
gtk_window_set_transient_for (GTK_WINDOW (askdialog), GTK_WINDOW (parent));
774
g_signal_connect (askdialog, "response",
775
G_CALLBACK (gtk_widget_hide), NULL);
776
g_signal_connect (gtk_builder_get_object (builder, "text"), "changed",
777
G_CALLBACK (cb_location_new_text_changed), builder);
778
response = gtk_dialog_run (GTK_DIALOG (askdialog));
779
name = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, "text")));
780
g_object_unref (builder);
782
if (response == GTK_RESPONSE_OK && name[0] != '\0')
785
gchar *current, *esc, *key;
786
esc = gconf_escape_key (name, -1);
787
key = g_strconcat (LOCATION_DIR "/", esc, NULL);
790
current = get_current_location (client);
792
exists = (strcmp (current, name) == 0) ||
793
gconf_client_dir_exists (client, key, NULL);
799
esc = gconf_escape_key (current, -1);
801
key = g_strconcat (LOCATION_DIR "/", esc, NULL);
804
copy_location ("", key, client);
807
gconf_client_set_string (client, CURRENT_LOCATION, name, NULL);
808
update_locations (client, capplet_builder);
812
GtkWidget *err = gtk_message_dialog_new (GTK_WINDOW (askdialog),
813
GTK_DIALOG_DESTROY_WITH_PARENT,
816
_("Location already exists"));
817
gtk_dialog_run (GTK_DIALOG (err));
818
gtk_widget_destroy (err);
820
/* switch back to the currently selected location */
821
gconf_client_notify (client, CURRENT_LOCATION);
826
/* switch back to the currently selected location */
827
gconf_client_notify (client, CURRENT_LOCATION);
829
gtk_widget_destroy (askdialog);
830
g_object_unref (client);
834
cb_location_changed (GtkWidget *location,
838
gchar *name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (location));
844
client = gconf_client_get_default ();
846
current = get_current_location (client);
848
if (strcmp (current, name) != 0)
850
if (strcmp (name, _("New Location...")) == 0)
852
location_new (builder, _gtk_builder_get_widget (builder, "network_dialog"));
858
/* save current settings */
859
esc = gconf_escape_key (current, -1);
860
key = g_strconcat (LOCATION_DIR "/", esc, NULL);
863
copy_location ("", key, client);
867
esc = gconf_escape_key (name, -1);
868
key = g_strconcat (LOCATION_DIR "/", esc, NULL);
871
copy_location (key, "", client);
872
gconf_client_recursive_unset (client, key,
873
GCONF_UNSET_INCLUDING_SCHEMA_NAMES, NULL);
876
gconf_client_set_string (client, CURRENT_LOCATION, name, NULL);
882
g_object_unref (client);
886
cb_delete_button_clicked (GtkWidget *button,
890
GtkComboBox *box = GTK_COMBO_BOX (gtk_builder_get_object (builder,
891
"location_combobox"));
892
int active = gtk_combo_box_get_active (box);
893
gchar *current, *key, *esc;
895
/* prevent the current settings from being saved by blocking
896
* the signal handler */
897
g_signal_handlers_block_by_func (box, cb_location_changed, builder);
898
gtk_combo_box_set_active (box, (active == 0) ? 1 : 0);
899
gtk_combo_box_remove_text (box, active);
900
g_signal_handlers_unblock_by_func (box, cb_location_changed, builder);
902
/* set the new location */
903
client = gconf_client_get_default ();
904
current = gtk_combo_box_get_active_text (box);
906
esc = gconf_escape_key (current, -1);
907
key = g_strconcat (LOCATION_DIR "/", esc, NULL);
910
copy_location (key, "", client);
911
gconf_client_recursive_unset (client, key,
912
GCONF_UNSET_INCLUDING_SCHEMA_NAMES, NULL);
913
gconf_client_suggest_sync (client, NULL);
916
gconf_client_set_string (client, CURRENT_LOCATION, current, NULL);
920
g_object_unref (client);
923
/* When using the same proxy for all protocols, updates every host_entry
924
* as the user types along */
926
synchronize_hosts (GtkEntry *widget,
929
const gchar *hosts[] = {
934
const gchar **host, *http_host;
936
http_host = gtk_entry_get_text (widget);
938
for (host = hosts; *host != NULL; ++host)
940
widget = GTK_ENTRY (gtk_builder_get_object (builder, *host));
941
gtk_entry_set_text (widget, http_host);
945
/* When using the same proxy for all protocols, copies the value of the
946
* http port to the other spinbuttons */
948
synchronize_ports (GtkSpinButton *widget,
951
const gchar *ports[] = {
952
"secure_port_spinbutton",
953
"ftp_port_spinbutton",
954
"socks_port_spinbutton",
959
http_port = gtk_spin_button_get_value (widget);
961
for (port = ports; *port != NULL; ++port)
963
widget = GTK_SPIN_BUTTON (
964
gtk_builder_get_object (builder, *port));
965
gtk_spin_button_set_value (widget, http_port);
969
/* Synchronizes all hosts and ports */
971
synchronize_entries (GtkBuilder *builder)
974
gtk_builder_get_object (builder, "http_host_entry"),
976
G_CALLBACK (synchronize_hosts),
979
gtk_builder_get_object (builder, "http_port_spinbutton"),
981
G_CALLBACK (synchronize_ports),
985
/* Unsynchronize hosts and ports */
987
unsynchronize_entries (GtkBuilder *builder)
989
g_signal_handlers_disconnect_by_func (
990
gtk_builder_get_object (builder, "http_host_entry"),
993
g_signal_handlers_disconnect_by_func (
994
gtk_builder_get_object (builder, "http_port_spinbutton"),
1000
cb_use_same_proxy_checkbutton_clicked (GtkWidget *checkbutton,
1001
GtkBuilder *builder)
1003
GConfClient *client;
1004
gboolean same_proxy;
1009
client = gconf_client_get_default ();
1010
same_proxy = gconf_client_get_bool (client, USE_SAME_PROXY_KEY, NULL);
1012
http_proxy = gconf_client_get_string (client, HTTP_PROXY_HOST_KEY, NULL);
1013
http_port = gconf_client_get_int (client, HTTP_PROXY_PORT_KEY, NULL);
1017
/* Save the old values */
1018
host = gconf_client_get_string (client, SECURE_PROXY_HOST_KEY, NULL);
1019
gconf_client_set_string (client, OLD_SECURE_PROXY_HOST_KEY, host, NULL);
1020
gconf_client_set_int (client, OLD_SECURE_PROXY_PORT_KEY,
1021
gconf_client_get_int (client, SECURE_PROXY_PORT_KEY, NULL), NULL);
1024
host = gconf_client_get_string (client, FTP_PROXY_HOST_KEY, NULL);
1025
gconf_client_set_string (client, OLD_FTP_PROXY_HOST_KEY, host, NULL);
1026
gconf_client_set_int (client, OLD_FTP_PROXY_PORT_KEY,
1027
gconf_client_get_int (client, FTP_PROXY_PORT_KEY, NULL), NULL);
1030
host = gconf_client_get_string (client, SOCKS_PROXY_HOST_KEY, NULL);
1031
gconf_client_set_string (client, OLD_SOCKS_PROXY_HOST_KEY, host, NULL);
1032
gconf_client_set_int (client, OLD_SOCKS_PROXY_PORT_KEY,
1033
gconf_client_get_int (client, SOCKS_PROXY_PORT_KEY, NULL), NULL);
1036
/* Set the new values */
1037
gconf_client_set_string (client, SECURE_PROXY_HOST_KEY, http_proxy, NULL);
1038
gconf_client_set_int (client, SECURE_PROXY_PORT_KEY, http_port, NULL);
1040
gconf_client_set_string (client, FTP_PROXY_HOST_KEY, http_proxy, NULL);
1041
gconf_client_set_int (client, FTP_PROXY_PORT_KEY, http_port, NULL);
1043
gconf_client_set_string (client, SOCKS_PROXY_HOST_KEY, http_proxy, NULL);
1044
gconf_client_set_int (client, SOCKS_PROXY_PORT_KEY, http_port, NULL);
1046
/* Synchronize entries */
1047
synchronize_entries (builder);
1051
host = gconf_client_get_string (client, OLD_SECURE_PROXY_HOST_KEY, NULL);
1052
gconf_client_set_string (client, SECURE_PROXY_HOST_KEY, host, NULL);
1053
gconf_client_set_int (client, SECURE_PROXY_PORT_KEY,
1054
gconf_client_get_int (client, OLD_SECURE_PROXY_PORT_KEY, NULL), NULL);
1057
host = gconf_client_get_string (client, OLD_FTP_PROXY_HOST_KEY, NULL);
1058
gconf_client_set_string (client, FTP_PROXY_HOST_KEY, host, NULL);
1059
gconf_client_set_int (client, FTP_PROXY_PORT_KEY,
1060
gconf_client_get_int (client, OLD_FTP_PROXY_PORT_KEY, NULL), NULL);
1063
host = gconf_client_get_string (client, OLD_SOCKS_PROXY_HOST_KEY, NULL);
1064
gconf_client_set_string (client, SOCKS_PROXY_HOST_KEY, host, NULL);
1065
gconf_client_set_int (client, SOCKS_PROXY_PORT_KEY,
1066
gconf_client_get_int (client, OLD_SOCKS_PROXY_PORT_KEY, NULL), NULL);
1069
/* Hosts and ports should not be synchronized any more */
1070
unsynchronize_entries (builder);
1073
/* Set the proxy entries insensitive if we are using the same proxy for all */
1074
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1075
"secure_host_entry"),
1077
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1078
"secure_port_spinbutton"),
1080
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1083
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1084
"ftp_port_spinbutton"),
1086
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1087
"socks_host_entry"),
1089
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1090
"socks_port_spinbutton"),
1093
g_object_unref (client);
1097
get_hostname_from_uri (const gchar *uri)
1099
const gchar *start, *end;
1105
/* skip the scheme part */
1106
start = strchr (uri, ':');
1110
/* forward until after the last '/' */
1113
} while (*start == '/');
1118
/* maybe we have a port? */
1119
end = strchr (start, ':');
1121
end = strchr (start, '/');
1124
host = g_strndup (start, end - start);
1126
host = g_strdup (start);
1132
extract_proxy_host (GConfPropertyEditor *peditor, const GConfValue *orig)
1134
char const *entered_text = gconf_value_get_string (orig);
1135
GConfValue *res = NULL;
1137
if (entered_text != NULL) {
1138
gchar *host = get_hostname_from_uri (entered_text);
1141
res = gconf_value_new (GCONF_VALUE_STRING);
1142
gconf_value_set_string (res, host);
1147
return (res != NULL) ? res : gconf_value_copy (orig);
1151
proxy_mode_radiobutton_clicked_cb (GtkWidget *widget,
1152
GtkBuilder *builder)
1156
GConfClient *client;
1158
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
1161
mode_group = g_slist_copy (gtk_radio_button_get_group
1162
(GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "none_radiobutton"))));
1163
mode_group = g_slist_reverse (mode_group);
1164
mode = g_slist_index (mode_group, widget);
1165
g_slist_free (mode_group);
1167
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "manual_box"),
1168
mode == PROXYMODE_MANUAL);
1169
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "same_proxy_checkbutton"),
1170
mode == PROXYMODE_MANUAL);
1171
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "auto_box"),
1172
mode == PROXYMODE_AUTO);
1173
client = gconf_client_get_default ();
1174
gconf_client_set_bool (client, USE_PROXY_KEY,
1175
mode == PROXYMODE_AUTO || mode == PROXYMODE_MANUAL, NULL);
1176
g_object_unref (client);
1180
connect_sensitivity_signals (GtkBuilder *builder, GSList *mode_group)
1182
for (; mode_group != NULL; mode_group = mode_group->next)
1184
g_signal_connect (G_OBJECT (mode_group->data), "clicked",
1185
G_CALLBACK(proxy_mode_radiobutton_clicked_cb),
1191
cb_ignore_hosts_gconf_changed (GConfClient *client, guint cnxn_id,
1192
GConfEntry *entry, gpointer user_data)
1194
g_slist_foreach (ignore_hosts, (GFunc) g_free, NULL);
1195
g_slist_free (ignore_hosts);
1197
ignore_hosts = gconf_client_get_list (client, IGNORE_HOSTS_KEY,
1198
GCONF_VALUE_STRING, NULL);
1200
populate_listmodel (GTK_LIST_STORE (model), ignore_hosts);
1204
setup_dialog (GtkBuilder *builder)
1206
GConfPropertyEditor *peditor;
1208
GType mode_type = 0;
1209
GConfClient *client;
1211
GtkWidget *location_box, *same_proxy_toggle;
1212
GtkCellRenderer *location_renderer;
1213
GtkListStore *store;
1215
mode_type = g_enum_register_static ("NetworkPreferencesProxyType",
1218
client = gconf_client_get_default ();
1221
location_box = _gtk_builder_get_widget (builder, "location_combobox");
1222
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
1223
gtk_combo_box_set_model (GTK_COMBO_BOX (location_box), GTK_TREE_MODEL (store));
1225
update_locations (client, builder);
1226
gconf_client_add_dir (client, LOCATION_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
1227
gconf_client_notify_add (client, CURRENT_LOCATION, (GConfClientNotifyFunc) cb_current_location, builder, NULL, NULL);
1229
gconf_client_notify_add (client, IGNORE_HOSTS_KEY, cb_ignore_hosts_gconf_changed, NULL, NULL, NULL);
1231
g_signal_connect (location_box, "changed", G_CALLBACK (cb_location_changed), builder);
1232
g_signal_connect (gtk_builder_get_object (builder, "delete_button"), "clicked", G_CALLBACK (cb_delete_button_clicked), builder);
1234
location_renderer = gtk_cell_renderer_text_new ();
1235
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (location_box), location_renderer, TRUE);
1236
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (location_box),
1239
"style", COL_STYLE, NULL);
1242
mode_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "none_radiobutton")));
1243
connect_sensitivity_signals (builder, mode_group);
1245
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_select_radio_with_enum (NULL,
1246
PROXY_MODE_KEY, mode_group, mode_type,
1249
/* Use same proxy for all protocols */
1250
same_proxy_toggle = _gtk_builder_get_widget (builder, "same_proxy_checkbutton");
1251
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_boolean (NULL,
1252
USE_SAME_PROXY_KEY, same_proxy_toggle, NULL));
1254
g_signal_connect (same_proxy_toggle,
1256
G_CALLBACK (cb_use_same_proxy_checkbutton_clicked),
1260
port_value = gconf_client_get_int (client, HTTP_PROXY_PORT_KEY, NULL);
1261
gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "http_port_spinbutton")), (gdouble) port_value);
1262
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
1263
NULL, HTTP_PROXY_HOST_KEY, _gtk_builder_get_widget (builder, "http_host_entry"),
1264
"conv-from-widget-cb", extract_proxy_host,
1266
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
1267
NULL, HTTP_PROXY_PORT_KEY,
1268
_gtk_builder_get_widget (builder, "http_port_spinbutton"),
1270
g_signal_connect (gtk_builder_get_object (builder, "details_button"),
1272
G_CALLBACK (cb_http_details_button_clicked),
1273
_gtk_builder_get_widget (builder, "network_dialog"));
1276
port_value = gconf_client_get_int (client, SECURE_PROXY_PORT_KEY, NULL);
1277
gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "secure_port_spinbutton")), (gdouble) port_value);
1278
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
1279
NULL, SECURE_PROXY_HOST_KEY,
1280
_gtk_builder_get_widget (builder, "secure_host_entry"),
1281
"conv-from-widget-cb", extract_proxy_host,
1283
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
1284
NULL, SECURE_PROXY_PORT_KEY,
1285
_gtk_builder_get_widget (builder, "secure_port_spinbutton"),
1289
port_value = gconf_client_get_int (client, FTP_PROXY_PORT_KEY, NULL);
1290
gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "ftp_port_spinbutton")), (gdouble) port_value);
1291
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
1292
NULL, FTP_PROXY_HOST_KEY,
1293
_gtk_builder_get_widget (builder, "ftp_host_entry"),
1294
"conv-from-widget-cb", extract_proxy_host,
1296
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
1297
NULL, FTP_PROXY_PORT_KEY,
1298
_gtk_builder_get_widget (builder, "ftp_port_spinbutton"),
1302
port_value = gconf_client_get_int (client, SOCKS_PROXY_PORT_KEY, NULL);
1303
gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "socks_port_spinbutton")), (gdouble) port_value);
1304
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
1305
NULL, SOCKS_PROXY_HOST_KEY,
1306
_gtk_builder_get_widget (builder, "socks_host_entry"),
1307
"conv-from-widget-cb", extract_proxy_host,
1309
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
1310
NULL, SOCKS_PROXY_PORT_KEY,
1311
_gtk_builder_get_widget (builder, "socks_port_spinbutton"),
1314
/* Set the proxy entries insensitive if we are using the same proxy for all,
1315
and make sure they are all synchronized */
1316
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (same_proxy_toggle)))
1318
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "secure_host_entry"), FALSE);
1319
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "secure_port_spinbutton"), FALSE);
1320
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "ftp_host_entry"), FALSE);
1321
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "ftp_port_spinbutton"), FALSE);
1322
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "socks_host_entry"), FALSE);
1323
gtk_widget_set_sensitive (_gtk_builder_get_widget (builder, "socks_port_spinbutton"), FALSE);
1325
synchronize_entries (builder);
1328
/* Autoconfiguration */
1329
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
1330
NULL, PROXY_AUTOCONFIG_URL_KEY,
1331
_gtk_builder_get_widget (builder, "autoconfig_entry"),
1334
g_signal_connect (gtk_builder_get_object (builder, "network_dialog"),
1335
"response", G_CALLBACK (cb_dialog_response), NULL);
1338
ignore_hosts = gconf_client_get_list(client, IGNORE_HOSTS_KEY, GCONF_VALUE_STRING, NULL);
1339
g_object_unref (client);
1341
model = create_listmodel();
1342
populate_listmodel(GTK_LIST_STORE(model), ignore_hosts);
1343
config_treeview(GTK_TREE_VIEW(gtk_builder_get_object (builder, "treeview_ignore_host")), model);
1345
g_signal_connect (gtk_builder_get_object (builder, "button_add_url"),
1346
"clicked", G_CALLBACK (cb_add_url), builder);
1347
g_signal_connect (gtk_builder_get_object (builder, "entry_url"),
1348
"activate", G_CALLBACK (cb_add_url), builder);
1349
g_signal_connect (gtk_builder_get_object (builder, "button_remove_url"),
1350
"clicked", G_CALLBACK (cb_remove_url), builder);
1354
main (int argc, char **argv)
1356
GtkBuilder *builder;
1357
GError *error = NULL;
1358
gchar *builder_widgets[] = {"network_dialog", "adjustment1",
1359
"adjustment2", "adjustment3", "adjustment4",
1360
"delete_button_img", NULL};
1361
GConfClient *client;
1364
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
1365
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1366
textdomain (GETTEXT_PACKAGE);
1368
gtk_init (&argc, &argv);
1370
client = gconf_client_get_default ();
1371
gconf_client_add_dir (client, "/system/http_proxy",
1372
GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
1373
gconf_client_add_dir (client, "/system/proxy",
1374
GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
1376
builder = gtk_builder_new ();
1377
if (gtk_builder_add_objects_from_file (builder, GNOMECC_GNP_UI_FILE,
1378
builder_widgets, &error) == 0) {
1379
g_warning ("Could not load main dialog: %s",
1381
g_error_free (error);
1382
g_object_unref (builder);
1383
g_object_unref (client);
1384
return (EXIT_FAILURE);
1387
setup_dialog (builder);
1388
widget = _gtk_builder_get_widget (builder, "network_dialog");
1389
capplet_set_icon (widget, "gnome-network-properties");
1390
gtk_widget_show_all (widget);
1393
g_object_unref (builder);
1394
g_object_unref (client);