~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to capplets/network/gnome-network-properties.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* gnome-network-properties.c: network preferences capplet
2
 
 *
3
 
 * Copyright (C) 2002 Sun Microsystems Inc.
4
 
 *
5
 
 * Written by: Mark McLoughlin <mark@skynet.ie>
6
 
 *
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)
10
 
 * any later version.
11
 
 *
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.
16
 
 *
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
20
 
 * 02111-1307, USA.
21
 
 */
22
 
 
23
 
#ifdef HAVE_CONFIG_H
24
 
#  include <config.h>
25
 
#endif
26
 
 
27
 
#include <stdlib.h>
28
 
#include <string.h>
29
 
#include <gconf/gconf-client.h>
30
 
#include <glib/gi18n.h>
31
 
 
32
 
#include "capplet-util.h"
33
 
#include "gconf-property-editor.h"
34
 
 
35
 
enum ProxyMode
36
 
{
37
 
        PROXYMODE_NONE,
38
 
        PROXYMODE_MANUAL,
39
 
        PROXYMODE_AUTO
40
 
};
41
 
 
42
 
static GEnumValue proxytype_values[] = {
43
 
        { PROXYMODE_NONE, "PROXYMODE_NONE", "none"},
44
 
        { PROXYMODE_MANUAL, "PROXYMODE_MANUAL", "manual"},
45
 
        { PROXYMODE_AUTO, "PROXYMODE_AUTO", "auto"},
46
 
        { 0, NULL, NULL }
47
 
};
48
 
 
49
 
enum {
50
 
        COL_NAME,
51
 
        COL_STYLE
52
 
};
53
 
 
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"
76
 
 
77
 
#define LOCATION_DIR "/apps/control-center/network"
78
 
#define CURRENT_LOCATION "/apps/control-center/network/current_location"
79
 
 
80
 
#define GNOMECC_GNP_UI_FILE (GNOMECC_UI_DIR "/gnome-network-properties.ui")
81
 
 
82
 
static GtkWidget *details_dialog = NULL;
83
 
static GSList *ignore_hosts = NULL;
84
 
static GtkTreeModel *model = NULL;
85
 
 
86
 
static GtkTreeModel *
87
 
create_listmodel(void)
88
 
{
89
 
        GtkListStore *store;
90
 
 
91
 
        store = gtk_list_store_new(1, G_TYPE_STRING);
92
 
 
93
 
        return GTK_TREE_MODEL(store);
94
 
}
95
 
 
96
 
static GtkTreeModel *
97
 
populate_listmodel(GtkListStore *store, GSList *list)
98
 
{
99
 
        GtkTreeIter iter;
100
 
        GSList *pointer;
101
 
 
102
 
        gtk_list_store_clear(store);
103
 
 
104
 
        pointer = list;
105
 
        while(pointer)
106
 
        {
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);
110
 
        }
111
 
 
112
 
        return GTK_TREE_MODEL(store);
113
 
}
114
 
 
115
 
static GtkWidget *
116
 
config_treeview(GtkTreeView *tree, GtkTreeModel *model)
117
 
{
118
 
        GtkCellRenderer *renderer;
119
 
 
120
 
        renderer = gtk_cell_renderer_text_new();
121
 
        gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree),
122
 
                                                                                                -1, "Hosts", renderer,
123
 
                                                                                                "text", 0, NULL);
124
 
 
125
 
        gtk_tree_view_set_model(GTK_TREE_VIEW(tree), model);
126
 
 
127
 
        return GTK_WIDGET(tree);
128
 
}
129
 
 
130
 
static GtkWidget*
131
 
_gtk_builder_get_widget (GtkBuilder *builder, const gchar *name)
132
 
{
133
 
        return GTK_WIDGET (gtk_builder_get_object (builder, name));
134
 
}
135
 
 
136
 
 
137
 
static void
138
 
cb_add_url (GtkButton *button, gpointer data)
139
 
{
140
 
        GtkBuilder *builder = GTK_BUILDER (data);
141
 
        gchar *new_url = NULL;
142
 
        GConfClient *client;
143
 
 
144
 
        new_url = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, "entry_url"))));
145
 
        if (strlen (new_url) == 0)
146
 
                return;
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,
150
 
                                                             "entry_url")), "");
151
 
 
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);
155
 
}
156
 
 
157
 
static void
158
 
cb_remove_url (GtkButton *button, gpointer data)
159
 
{
160
 
        GtkBuilder *builder = GTK_BUILDER (data);
161
 
        GtkTreeSelection *selection;
162
 
        GtkTreeIter       iter;
163
 
        GConfClient *client;
164
 
 
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))
167
 
        {
168
 
                gchar *url;
169
 
                GSList *pointer;
170
 
 
171
 
                gtk_tree_model_get (model, &iter, 0, &url, -1);
172
 
 
173
 
                pointer = ignore_hosts;
174
 
                while(pointer)
175
 
                {
176
 
                        if(strcmp(url, (char *) pointer->data) == 0)
177
 
                        {
178
 
                                g_free (pointer->data);
179
 
                                ignore_hosts = g_slist_delete_link(ignore_hosts, pointer);
180
 
                                break;
181
 
                        }
182
 
                        pointer = g_slist_next(pointer);
183
 
                }
184
 
 
185
 
                g_free(url);
186
 
                populate_listmodel(GTK_LIST_STORE(model), ignore_hosts);
187
 
 
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);
191
 
        }
192
 
}
193
 
 
194
 
static void
195
 
cb_dialog_response (GtkDialog *dialog, gint response_id)
196
 
{
197
 
        if (response_id == GTK_RESPONSE_HELP)
198
 
                capplet_help (GTK_WINDOW (dialog),
199
 
                        "goscustdesk-50");
200
 
        else if (response_id == GTK_RESPONSE_CLOSE || response_id == GTK_RESPONSE_DELETE_EVENT)
201
 
        {
202
 
                if (ignore_hosts) {
203
 
                        g_slist_foreach (ignore_hosts, (GFunc) g_free, NULL);
204
 
                        g_slist_free (ignore_hosts);
205
 
                }
206
 
 
207
 
                gtk_main_quit ();
208
 
        }
209
 
}
210
 
 
211
 
static void
212
 
cb_details_dialog_response (GtkDialog *dialog, gint response_id)
213
 
{
214
 
        if (response_id == GTK_RESPONSE_HELP)
215
 
                capplet_help (GTK_WINDOW (dialog),
216
 
                              "goscustdesk-50");
217
 
        else {
218
 
                gtk_widget_destroy (GTK_WIDGET (dialog));
219
 
                details_dialog = NULL;
220
 
        }
221
 
}
222
 
 
223
 
static void
224
 
cb_use_auth_toggled (GtkToggleButton *toggle,
225
 
                     GtkWidget *table)
226
 
{
227
 
        gtk_widget_set_sensitive (table, gtk_toggle_button_get_active (toggle));
228
 
}
229
 
 
230
 
static void
231
 
cb_http_details_button_clicked (GtkWidget *button,
232
 
                                GtkWidget *parent)
233
 
{
234
 
        GtkBuilder *builder;
235
 
        gchar *builder_widgets[] = { "details_dialog", NULL };
236
 
        GError *error = NULL;
237
 
        GtkWidget *widget;
238
 
        GConfPropertyEditor *peditor;
239
 
 
240
 
        if (details_dialog != NULL) {
241
 
                gtk_window_present (GTK_WINDOW (details_dialog));
242
 
                gtk_widget_grab_focus (details_dialog);
243
 
                return;
244
 
        }
245
 
 
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);
252
 
                return;
253
 
        }
254
 
 
255
 
        details_dialog = widget = _gtk_builder_get_widget (builder,
256
 
                                                           "details_dialog");
257
 
 
258
 
        gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (parent));
259
 
 
260
 
        g_signal_connect (gtk_builder_get_object (builder, "use_auth_checkbutton"),
261
 
                          "toggled",
262
 
                          G_CALLBACK (cb_use_auth_toggled),
263
 
                          _gtk_builder_get_widget (builder, "auth_table"));
264
 
 
265
 
        peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_boolean (
266
 
                        NULL, HTTP_USE_AUTH_KEY,
267
 
                        _gtk_builder_get_widget (builder, "use_auth_checkbutton"),
268
 
                        NULL));
269
 
        peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
270
 
                        NULL, HTTP_AUTH_USER_KEY,
271
 
                        _gtk_builder_get_widget (builder, "username_entry"),
272
 
                        NULL));
273
 
        peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
274
 
                        NULL, HTTP_AUTH_PASSWD_KEY,
275
 
                        _gtk_builder_get_widget (builder, "password_entry"),
276
 
                        NULL));
277
 
 
278
 
        g_signal_connect (widget, "response",
279
 
                          G_CALLBACK (cb_details_dialog_response), NULL);
280
 
 
281
 
        capplet_set_icon (widget, "gnome-network-properties");
282
 
 
283
 
        gtk_widget_show_all (widget);
284
 
}
285
 
 
286
 
static gchar *
287
 
copy_location_create_key (const gchar *from, const gchar *what)
288
 
{
289
 
        if (from[0] == '\0') return g_strdup (what);
290
 
        else return g_strconcat (from, what + strlen ("/system"), NULL);
291
 
}
292
 
 
293
 
static void
294
 
copy_location (const gchar *from, const gchar *to, GConfClient *client)
295
 
{
296
 
        int ti;
297
 
        gboolean tb;
298
 
        GSList *tl;
299
 
        gchar *tstr, *dest, *src;
300
 
 
301
 
        if (from[0] != '\0' && !gconf_client_dir_exists (client, from, NULL))
302
 
                return;
303
 
 
304
 
        /* USE_PROXY */
305
 
        dest = copy_location_create_key (to, USE_PROXY_KEY);
306
 
        src = copy_location_create_key (from, USE_PROXY_KEY);
307
 
 
308
 
        tb = gconf_client_get_bool (client, src, NULL);
309
 
        gconf_client_set_bool (client, dest, tb, NULL);
310
 
 
311
 
        g_free (dest);
312
 
        g_free (src);
313
 
 
314
 
        /* USE_SAME_PROXY */
315
 
        dest = copy_location_create_key (to, USE_SAME_PROXY_KEY);
316
 
        src = copy_location_create_key (from, USE_SAME_PROXY_KEY);
317
 
 
318
 
        tb = gconf_client_get_bool (client, src, NULL);
319
 
        gconf_client_set_bool (client, dest, tb, NULL);
320
 
 
321
 
        g_free (dest);
322
 
        g_free (src);
323
 
 
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);
327
 
 
328
 
        tstr = gconf_client_get_string (client, src, NULL);
329
 
        if (tstr != NULL)
330
 
        {
331
 
                gconf_client_set_string (client, dest, tstr, NULL);
332
 
                g_free (tstr);
333
 
        }
334
 
 
335
 
        g_free (dest);
336
 
        g_free (src);
337
 
 
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);
341
 
 
342
 
        ti = gconf_client_get_int (client, src, NULL);
343
 
        gconf_client_set_int (client, dest, ti, NULL);
344
 
 
345
 
        g_free (dest);
346
 
        g_free (src);
347
 
 
348
 
        /* HTTP_USE_AUTH */
349
 
        dest = copy_location_create_key (to, HTTP_USE_AUTH_KEY);
350
 
        src = copy_location_create_key (from, HTTP_USE_AUTH_KEY);
351
 
 
352
 
        tb = gconf_client_get_bool (client, src, NULL);
353
 
        gconf_client_set_bool (client, dest, tb, NULL);
354
 
 
355
 
        g_free (dest);
356
 
        g_free (src);
357
 
 
358
 
        /* HTTP_AUTH_USER */
359
 
        dest = copy_location_create_key (to, HTTP_AUTH_USER_KEY);
360
 
        src = copy_location_create_key (from, HTTP_AUTH_USER_KEY);
361
 
 
362
 
        tstr = gconf_client_get_string (client, src, NULL);
363
 
        if (tstr != NULL)
364
 
        {
365
 
                gconf_client_set_string (client, dest, tstr, NULL);
366
 
                g_free (tstr);
367
 
        }
368
 
 
369
 
        g_free (dest);
370
 
        g_free (src);
371
 
 
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);
375
 
 
376
 
        tstr = gconf_client_get_string (client, src, NULL);
377
 
        if (tstr != NULL)
378
 
        {
379
 
                 gconf_client_set_string (client, dest, tstr, NULL);
380
 
                g_free (tstr);
381
 
        }
382
 
 
383
 
        g_free (dest);
384
 
        g_free (src);
385
 
 
386
 
        /* IGNORE_HOSTS */
387
 
        dest = copy_location_create_key (to, IGNORE_HOSTS_KEY);
388
 
        src = copy_location_create_key (from, IGNORE_HOSTS_KEY);
389
 
 
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);
393
 
        g_slist_free (tl);
394
 
 
395
 
        g_free (dest);
396
 
        g_free (src);
397
 
 
398
 
        /* PROXY_MODE */
399
 
        dest = copy_location_create_key (to, PROXY_MODE_KEY);
400
 
        src = copy_location_create_key (from, PROXY_MODE_KEY);
401
 
 
402
 
        tstr = gconf_client_get_string (client, src, NULL);
403
 
        if (tstr != NULL)
404
 
        {
405
 
                gconf_client_set_string (client, dest, tstr, NULL);
406
 
                g_free (tstr);
407
 
        }
408
 
 
409
 
        g_free (dest);
410
 
        g_free (src);
411
 
 
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);
415
 
 
416
 
        tstr = gconf_client_get_string (client, src, NULL);
417
 
        if (tstr != NULL)
418
 
        {
419
 
                gconf_client_set_string (client, dest, tstr, NULL);
420
 
                g_free (tstr);
421
 
        }
422
 
 
423
 
        g_free (dest);
424
 
        g_free (src);
425
 
 
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);
429
 
 
430
 
        tstr = gconf_client_get_string (client, src, NULL);
431
 
        if (tstr != NULL)
432
 
        {
433
 
                gconf_client_set_string (client, dest, tstr, NULL);
434
 
                g_free (tstr);
435
 
        }
436
 
 
437
 
        g_free (dest);
438
 
        g_free (src);
439
 
 
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);
443
 
 
444
 
        ti = gconf_client_get_int (client, src, NULL);
445
 
        gconf_client_set_int (client, dest, ti, NULL);
446
 
 
447
 
        g_free (dest);
448
 
        g_free (src);
449
 
 
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);
453
 
 
454
 
        ti = gconf_client_get_int (client, src, NULL);
455
 
        gconf_client_set_int (client, dest, ti, NULL);
456
 
 
457
 
        g_free (dest);
458
 
        g_free (src);
459
 
 
460
 
        /* FTP_PROXY_HOST */
461
 
        dest = copy_location_create_key (to, FTP_PROXY_HOST_KEY);
462
 
        src = copy_location_create_key (from, FTP_PROXY_HOST_KEY);
463
 
 
464
 
        tstr = gconf_client_get_string (client, src, NULL);
465
 
        if (tstr != NULL)
466
 
        {
467
 
                gconf_client_set_string (client, dest, tstr, NULL);
468
 
                g_free (tstr);
469
 
        }
470
 
 
471
 
        g_free (dest);
472
 
        g_free (src);
473
 
 
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);
477
 
 
478
 
        tstr = gconf_client_get_string (client, src, NULL);
479
 
        if (tstr != NULL)
480
 
        {
481
 
                gconf_client_set_string (client, dest, tstr, NULL);
482
 
                g_free (tstr);
483
 
        }
484
 
 
485
 
        g_free (dest);
486
 
        g_free (src);
487
 
 
488
 
        /* FTP_PROXY_PORT */
489
 
        dest = copy_location_create_key (to, FTP_PROXY_PORT_KEY);
490
 
        src = copy_location_create_key (from, FTP_PROXY_PORT_KEY);
491
 
 
492
 
        ti = gconf_client_get_int (client, src, NULL);
493
 
        gconf_client_set_int (client, dest, ti, NULL);
494
 
 
495
 
        g_free (dest);
496
 
        g_free (src);
497
 
 
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);
501
 
 
502
 
        ti = gconf_client_get_int (client, src, NULL);
503
 
        gconf_client_set_int (client, dest, ti, NULL);
504
 
 
505
 
        g_free (dest);
506
 
        g_free (src);
507
 
 
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);
511
 
 
512
 
        tstr = gconf_client_get_string (client, src, NULL);
513
 
        if (tstr != NULL)
514
 
        {
515
 
                gconf_client_set_string (client, dest, tstr, NULL);
516
 
                g_free (tstr);
517
 
        }
518
 
 
519
 
        g_free  (dest);
520
 
        g_free (src);
521
 
 
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);
525
 
 
526
 
        tstr = gconf_client_get_string (client, src, NULL);
527
 
        if (tstr != NULL)
528
 
        {
529
 
                gconf_client_set_string (client, dest, tstr, NULL);
530
 
                g_free (tstr);
531
 
        }
532
 
 
533
 
        g_free (dest);
534
 
        g_free (src);
535
 
 
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);
539
 
 
540
 
        ti = gconf_client_get_int (client, src, NULL);
541
 
        gconf_client_set_int (client, dest, ti, NULL);
542
 
 
543
 
        g_free (dest);
544
 
        g_free (src);
545
 
 
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);
549
 
 
550
 
        ti = gconf_client_get_int (client, src, NULL);
551
 
        gconf_client_set_int (client, dest, ti, NULL);
552
 
 
553
 
        g_free (dest);
554
 
        g_free (src);
555
 
 
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);
559
 
 
560
 
        tstr = gconf_client_get_string (client, src, NULL);
561
 
        if (tstr != NULL)
562
 
        {
563
 
                gconf_client_set_string (client, dest, tstr, NULL);
564
 
                g_free (tstr);
565
 
        }
566
 
 
567
 
        g_free (dest);
568
 
        g_free (src);
569
 
}
570
 
 
571
 
static gchar *
572
 
get_current_location (GConfClient *client)
573
 
{
574
 
        gchar *result;
575
 
 
576
 
        result = gconf_client_get_string (client, CURRENT_LOCATION, NULL);
577
 
 
578
 
        if (result == NULL || result[0] == '\0')
579
 
        {
580
 
                g_free (result);
581
 
                result = g_strdup (_("Default"));
582
 
        }
583
 
 
584
 
        return result;
585
 
}
586
 
 
587
 
static gboolean
588
 
location_combo_separator (GtkTreeModel *model,
589
 
                          GtkTreeIter *iter,
590
 
                          gpointer data)
591
 
{
592
 
        gchar *name;
593
 
        gboolean ret;
594
 
 
595
 
        gtk_tree_model_get (model, iter, COL_NAME, &name, -1);
596
 
 
597
 
        ret = name == NULL || name[0] == '\0';
598
 
 
599
 
        g_free (name);
600
 
 
601
 
        return ret;
602
 
}
603
 
 
604
 
static void
605
 
update_locations (GConfClient *client,
606
 
                  GtkBuilder *builder);
607
 
 
608
 
static void
609
 
cb_location_changed (GtkWidget *location,
610
 
                     GtkBuilder *builder);
611
 
 
612
 
static void
613
 
cb_current_location (GConfClient *client,
614
 
                     guint cnxn_id,
615
 
                     GConfEntry *entry,
616
 
                     GtkBuilder *builder)
617
 
{
618
 
        GConfValue *value;
619
 
        const gchar *newval;
620
 
 
621
 
        value = gconf_entry_get_value (entry);
622
 
        if (value == NULL)
623
 
                return;
624
 
 
625
 
        newval = gconf_value_get_string (value);
626
 
        if (newval == NULL)
627
 
                return;
628
 
 
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);
636
 
}
637
 
 
638
 
static void
639
 
update_locations (GConfClient *client,
640
 
                  GtkBuilder *builder)
641
 
{
642
 
        int i, select;
643
 
        gchar *current;
644
 
        GtkComboBox *location = GTK_COMBO_BOX (gtk_builder_get_object (builder, "location_combobox"));
645
 
        GSList *list = gconf_client_all_dirs (client, LOCATION_DIR, NULL);
646
 
        GtkTreeIter titer;
647
 
        GtkListStore *store;
648
 
        GSList *iter, *last;
649
 
 
650
 
        store = GTK_LIST_STORE (gtk_combo_box_get_model (location));
651
 
        gtk_list_store_clear (store);
652
 
 
653
 
        current = get_current_location (client);
654
 
 
655
 
        list = g_slist_append (list, g_strconcat (LOCATION_DIR"/", current, NULL));
656
 
        list = g_slist_sort (list, (GCompareFunc) strcmp);
657
 
 
658
 
        select = -1;
659
 
 
660
 
        for (i = 0, iter = list, last = NULL; iter != NULL; last = iter, iter = g_slist_next (iter), ++i)
661
 
        {
662
 
                if (last == NULL || strcmp (last->data, iter->data) != 0)
663
 
                {
664
 
                        gchar *locp, *key_name;
665
 
 
666
 
                        locp = iter->data + strlen (LOCATION_DIR) + 1;
667
 
                        key_name = gconf_unescape_key (locp, -1);
668
 
 
669
 
                        gtk_list_store_append (store, &titer);
670
 
                        gtk_list_store_set (store, &titer,
671
 
                                                COL_NAME, key_name,
672
 
                                                COL_STYLE, PANGO_STYLE_NORMAL, -1);
673
 
 
674
 
                        g_free (key_name);
675
 
 
676
 
                        if (strcmp (locp, current) == 0)
677
 
                                select = i;
678
 
                }
679
 
        }
680
 
        if (select == -1)
681
 
        {
682
 
                gtk_list_store_append (store, &titer);
683
 
                gtk_list_store_set (store, &titer,
684
 
                                    COL_NAME , current,
685
 
                                    COL_STYLE, PANGO_STYLE_NORMAL, -1);
686
 
                select = i++;
687
 
        }
688
 
        gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
689
 
                                                           "delete_button"),
690
 
                                  i > 1);
691
 
 
692
 
        gtk_list_store_append (store, &titer);
693
 
        gtk_list_store_set (store, &titer,
694
 
                            COL_NAME, NULL,
695
 
                            COL_STYLE, PANGO_STYLE_NORMAL, -1);
696
 
 
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);
701
 
 
702
 
        gtk_combo_box_set_row_separator_func (location, location_combo_separator, NULL, NULL);
703
 
        gtk_combo_box_set_active (location, select);
704
 
        g_free (current);
705
 
        g_slist_foreach (list, (GFunc) gconf_entry_free, NULL);
706
 
        g_slist_free (list);
707
 
}
708
 
 
709
 
static void
710
 
cb_location_new_text_changed (GtkEntry *entry, GtkBuilder *builder)
711
 
{
712
 
        gboolean exists;
713
 
        gchar *current, *esc, *key;
714
 
        const gchar *name;
715
 
        GConfClient *client;
716
 
 
717
 
        client = gconf_client_get_default ();
718
 
 
719
 
        name = gtk_entry_get_text (entry);
720
 
        if (name != NULL && name[0] != '\0')
721
 
        {
722
 
                esc = gconf_escape_key (name, -1);
723
 
 
724
 
                key = g_strconcat (LOCATION_DIR "/", esc, NULL);
725
 
                g_free (esc);
726
 
 
727
 
                current = get_current_location (client);
728
 
 
729
 
                exists = (strcmp (current, name) == 0) ||
730
 
                          gconf_client_dir_exists (client, key, NULL);
731
 
                g_free (key);
732
 
        } else exists = FALSE;
733
 
 
734
 
        g_object_unref (client);
735
 
 
736
 
        if (exists)
737
 
                gtk_widget_show (_gtk_builder_get_widget (builder,
738
 
                                                          "error_label"));
739
 
        else
740
 
                gtk_widget_hide (_gtk_builder_get_widget (builder,
741
 
                                                          "error_label"));
742
 
 
743
 
        gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
744
 
                                                           "new_location"),
745
 
                                  !exists);
746
 
}
747
 
 
748
 
static void
749
 
location_new (GtkBuilder *capplet_builder, GtkWidget *parent)
750
 
{
751
 
        GtkBuilder *builder;
752
 
        GError *error = NULL;
753
 
        gchar *builder_widgets[] = { "location_new_dialog",
754
 
                                     "new_location_btn_img", NULL };
755
 
        GtkWidget *askdialog;
756
 
        const gchar *name;
757
 
        int response;
758
 
        GConfClient *client;
759
 
 
760
 
        client = gconf_client_get_default ();
761
 
 
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",
766
 
                           error->message);
767
 
                g_error_free (error);
768
 
                g_object_unref (builder);
769
 
                return;
770
 
        }
771
 
 
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);
781
 
 
782
 
        if (response == GTK_RESPONSE_OK && name[0] != '\0')
783
 
        {
784
 
                gboolean exists;
785
 
                gchar *current, *esc, *key;
786
 
                esc = gconf_escape_key (name, -1);
787
 
                key = g_strconcat (LOCATION_DIR "/", esc, NULL);
788
 
                g_free (esc);
789
 
 
790
 
                current = get_current_location (client);
791
 
 
792
 
                exists = (strcmp (current, name) == 0) ||
793
 
                         gconf_client_dir_exists (client, key, NULL);
794
 
 
795
 
                g_free (key);
796
 
 
797
 
                if (!exists)
798
 
                {
799
 
                        esc = gconf_escape_key (current, -1);
800
 
                        g_free (current);
801
 
                        key = g_strconcat (LOCATION_DIR "/", esc, NULL);
802
 
                        g_free (esc);
803
 
 
804
 
                        copy_location ("", key, client);
805
 
                        g_free (key);
806
 
 
807
 
                        gconf_client_set_string (client, CURRENT_LOCATION, name, NULL);
808
 
                        update_locations (client, capplet_builder);
809
 
                }
810
 
                else
811
 
                {
812
 
                        GtkWidget *err = gtk_message_dialog_new (GTK_WINDOW (askdialog),
813
 
                                                          GTK_DIALOG_DESTROY_WITH_PARENT,
814
 
                                                          GTK_MESSAGE_ERROR,
815
 
                                                          GTK_BUTTONS_CLOSE,
816
 
                                                          _("Location already exists"));
817
 
                        gtk_dialog_run (GTK_DIALOG (err));
818
 
                        gtk_widget_destroy (err);
819
 
 
820
 
                        /* switch back to the currently selected location */
821
 
                        gconf_client_notify (client, CURRENT_LOCATION);
822
 
                }
823
 
        }
824
 
        else
825
 
        {
826
 
                /* switch back to the currently selected location */
827
 
                gconf_client_notify (client, CURRENT_LOCATION);
828
 
        }
829
 
        gtk_widget_destroy (askdialog);
830
 
        g_object_unref (client);
831
 
}
832
 
 
833
 
static void
834
 
cb_location_changed (GtkWidget *location,
835
 
                     GtkBuilder *builder)
836
 
{
837
 
        gchar *current;
838
 
        gchar *name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (location));
839
 
        GConfClient *client;
840
 
 
841
 
        if (name == NULL)
842
 
                return;
843
 
 
844
 
        client = gconf_client_get_default ();
845
 
 
846
 
        current = get_current_location (client);
847
 
 
848
 
        if (strcmp (current, name) != 0)
849
 
        {
850
 
                if (strcmp (name, _("New Location...")) == 0)
851
 
                {
852
 
                        location_new (builder, _gtk_builder_get_widget (builder, "network_dialog"));
853
 
                }
854
 
                else
855
 
                {
856
 
                        gchar *key, *esc;
857
 
 
858
 
                        /* save current settings */
859
 
                        esc = gconf_escape_key (current, -1);
860
 
                        key = g_strconcat (LOCATION_DIR "/", esc, NULL);
861
 
                        g_free (esc);
862
 
 
863
 
                        copy_location ("", key, client);
864
 
                        g_free (key);
865
 
 
866
 
                        /* load settings */
867
 
                        esc = gconf_escape_key (name, -1);
868
 
                        key = g_strconcat (LOCATION_DIR "/", esc, NULL);
869
 
                        g_free (esc);
870
 
 
871
 
                        copy_location (key, "", client);
872
 
                        gconf_client_recursive_unset (client, key,
873
 
                                                      GCONF_UNSET_INCLUDING_SCHEMA_NAMES, NULL);
874
 
                        g_free (key);
875
 
 
876
 
                        gconf_client_set_string (client, CURRENT_LOCATION, name, NULL);
877
 
                }
878
 
        }
879
 
 
880
 
        g_free (current);
881
 
        g_free (name);
882
 
        g_object_unref (client);
883
 
}
884
 
 
885
 
static void
886
 
cb_delete_button_clicked (GtkWidget *button,
887
 
                          GtkBuilder *builder)
888
 
{
889
 
        GConfClient *client;
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;
894
 
 
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);
901
 
 
902
 
        /* set the new location */
903
 
        client = gconf_client_get_default ();
904
 
        current = gtk_combo_box_get_active_text (box);
905
 
 
906
 
        esc = gconf_escape_key (current, -1);
907
 
        key = g_strconcat (LOCATION_DIR "/", esc, NULL);
908
 
        g_free (esc);
909
 
 
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);
914
 
        g_free (key);
915
 
 
916
 
        gconf_client_set_string (client, CURRENT_LOCATION, current, NULL);
917
 
 
918
 
        g_free (current);
919
 
 
920
 
        g_object_unref (client);
921
 
}
922
 
 
923
 
/* When using the same proxy for all protocols, updates every host_entry
924
 
 * as the user types along */
925
 
static void
926
 
synchronize_hosts (GtkEntry *widget,
927
 
                   GtkBuilder *builder)
928
 
{
929
 
        const gchar *hosts[] = {
930
 
                "secure_host_entry",
931
 
                "ftp_host_entry",
932
 
                "socks_host_entry",
933
 
                NULL };
934
 
        const gchar **host, *http_host;
935
 
 
936
 
        http_host = gtk_entry_get_text (widget);
937
 
 
938
 
        for (host = hosts; *host != NULL; ++host)
939
 
        {
940
 
                widget = GTK_ENTRY (gtk_builder_get_object (builder, *host));
941
 
                gtk_entry_set_text (widget, http_host);
942
 
        }
943
 
}
944
 
 
945
 
/* When using the same proxy for all protocols, copies the value of the
946
 
 * http port to the other spinbuttons */
947
 
static void
948
 
synchronize_ports (GtkSpinButton *widget,
949
 
                   GtkBuilder *builder)
950
 
{
951
 
        const gchar *ports[] = {
952
 
                "secure_port_spinbutton",
953
 
                "ftp_port_spinbutton",
954
 
                "socks_port_spinbutton",
955
 
                NULL };
956
 
        gdouble http_port;
957
 
        const gchar **port;
958
 
 
959
 
        http_port = gtk_spin_button_get_value (widget);
960
 
 
961
 
        for (port = ports; *port != NULL; ++port)
962
 
        {
963
 
                widget = GTK_SPIN_BUTTON (
964
 
                        gtk_builder_get_object (builder, *port));
965
 
                gtk_spin_button_set_value (widget, http_port);
966
 
        }
967
 
}
968
 
 
969
 
/* Synchronizes all hosts and ports */
970
 
static void
971
 
synchronize_entries (GtkBuilder *builder)
972
 
{
973
 
        g_signal_connect (
974
 
                gtk_builder_get_object (builder, "http_host_entry"),
975
 
                "changed",
976
 
                G_CALLBACK (synchronize_hosts),
977
 
                builder);
978
 
        g_signal_connect (
979
 
                gtk_builder_get_object (builder, "http_port_spinbutton"),
980
 
                "value-changed",
981
 
                G_CALLBACK (synchronize_ports),
982
 
                builder);
983
 
}
984
 
 
985
 
/* Unsynchronize hosts and ports */
986
 
static void
987
 
unsynchronize_entries (GtkBuilder *builder)
988
 
{
989
 
        g_signal_handlers_disconnect_by_func (
990
 
                gtk_builder_get_object (builder, "http_host_entry"),
991
 
                synchronize_hosts,
992
 
                builder);
993
 
        g_signal_handlers_disconnect_by_func (
994
 
                gtk_builder_get_object (builder, "http_port_spinbutton"),
995
 
                synchronize_ports,
996
 
                builder);
997
 
}
998
 
 
999
 
static void
1000
 
cb_use_same_proxy_checkbutton_clicked (GtkWidget *checkbutton,
1001
 
                                       GtkBuilder *builder)
1002
 
{
1003
 
        GConfClient *client;
1004
 
        gboolean same_proxy;
1005
 
        gchar *http_proxy;
1006
 
        gint http_port;
1007
 
        gchar *host;
1008
 
 
1009
 
        client = gconf_client_get_default ();
1010
 
        same_proxy = gconf_client_get_bool (client, USE_SAME_PROXY_KEY, NULL);
1011
 
 
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);
1014
 
 
1015
 
        if (same_proxy)
1016
 
        {
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);
1022
 
                g_free (host);
1023
 
 
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);
1028
 
                g_free (host);
1029
 
 
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);
1034
 
                g_free (host);
1035
 
 
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);
1039
 
 
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);
1042
 
 
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);
1045
 
 
1046
 
                /* Synchronize entries */
1047
 
                synchronize_entries (builder);
1048
 
        }
1049
 
        else
1050
 
        {
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);
1055
 
                g_free (host);
1056
 
 
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);
1061
 
                g_free (host);
1062
 
 
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);
1067
 
                g_free (host);
1068
 
 
1069
 
                /* Hosts and ports should not be synchronized any more */
1070
 
                unsynchronize_entries (builder);
1071
 
        }
1072
 
 
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"),
1076
 
                                  !same_proxy);
1077
 
        gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1078
 
                                                           "secure_port_spinbutton"),
1079
 
                                  !same_proxy);
1080
 
        gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1081
 
                                                           "ftp_host_entry"),
1082
 
                                  !same_proxy);
1083
 
        gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1084
 
                                                           "ftp_port_spinbutton"),
1085
 
                                  !same_proxy);
1086
 
        gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1087
 
                                                           "socks_host_entry"),
1088
 
                                  !same_proxy);
1089
 
        gtk_widget_set_sensitive (_gtk_builder_get_widget (builder,
1090
 
                                                           "socks_port_spinbutton"),
1091
 
                                  !same_proxy);
1092
 
 
1093
 
        g_object_unref (client);
1094
 
}
1095
 
 
1096
 
static gchar *
1097
 
get_hostname_from_uri (const gchar *uri)
1098
 
{
1099
 
        const gchar *start, *end;
1100
 
        gchar *host;
1101
 
 
1102
 
        if (uri == NULL)
1103
 
                return NULL;
1104
 
 
1105
 
        /* skip the scheme part */
1106
 
        start = strchr (uri, ':');
1107
 
        if (start == NULL)
1108
 
                return NULL;
1109
 
 
1110
 
        /* forward until after the last '/' */
1111
 
        do {
1112
 
                ++start;
1113
 
        } while (*start == '/');
1114
 
 
1115
 
        if (*start == '\0')
1116
 
          return NULL;
1117
 
 
1118
 
        /* maybe we have a port? */
1119
 
        end = strchr (start, ':');
1120
 
        if (end == NULL)
1121
 
                end = strchr (start, '/');
1122
 
 
1123
 
        if (end != NULL)
1124
 
                host = g_strndup (start, end - start);
1125
 
        else
1126
 
                host = g_strdup (start);
1127
 
 
1128
 
        return host;
1129
 
}
1130
 
 
1131
 
static GConfValue *
1132
 
extract_proxy_host (GConfPropertyEditor *peditor, const GConfValue *orig)
1133
 
{
1134
 
        char const *entered_text = gconf_value_get_string (orig);
1135
 
        GConfValue *res = NULL;
1136
 
 
1137
 
        if (entered_text != NULL) {
1138
 
                gchar *host = get_hostname_from_uri (entered_text);
1139
 
 
1140
 
                if (host != NULL) {
1141
 
                        res = gconf_value_new (GCONF_VALUE_STRING);
1142
 
                        gconf_value_set_string (res, host);
1143
 
                        g_free (host);
1144
 
                }
1145
 
        }
1146
 
 
1147
 
        return (res != NULL) ? res : gconf_value_copy (orig);
1148
 
}
1149
 
 
1150
 
static void
1151
 
proxy_mode_radiobutton_clicked_cb (GtkWidget *widget,
1152
 
                                   GtkBuilder *builder)
1153
 
{
1154
 
        GSList *mode_group;
1155
 
        int mode;
1156
 
        GConfClient *client;
1157
 
 
1158
 
        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
1159
 
                return;
1160
 
 
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);
1166
 
 
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);
1177
 
}
1178
 
 
1179
 
static void
1180
 
connect_sensitivity_signals (GtkBuilder *builder, GSList *mode_group)
1181
 
{
1182
 
        for (; mode_group != NULL; mode_group = mode_group->next)
1183
 
        {
1184
 
                g_signal_connect (G_OBJECT (mode_group->data), "clicked",
1185
 
                                  G_CALLBACK(proxy_mode_radiobutton_clicked_cb),
1186
 
                                  builder);
1187
 
        }
1188
 
}
1189
 
 
1190
 
static void
1191
 
cb_ignore_hosts_gconf_changed (GConfClient *client, guint cnxn_id,
1192
 
                                GConfEntry *entry, gpointer user_data)
1193
 
{
1194
 
        g_slist_foreach (ignore_hosts, (GFunc) g_free, NULL);
1195
 
        g_slist_free (ignore_hosts);
1196
 
 
1197
 
        ignore_hosts = gconf_client_get_list (client, IGNORE_HOSTS_KEY,
1198
 
                                              GCONF_VALUE_STRING, NULL);
1199
 
 
1200
 
        populate_listmodel (GTK_LIST_STORE (model), ignore_hosts);
1201
 
}
1202
 
 
1203
 
static void
1204
 
setup_dialog (GtkBuilder *builder)
1205
 
{
1206
 
        GConfPropertyEditor *peditor;
1207
 
        GSList *mode_group;
1208
 
        GType mode_type = 0;
1209
 
        GConfClient *client;
1210
 
        gint port_value;
1211
 
        GtkWidget *location_box, *same_proxy_toggle;
1212
 
        GtkCellRenderer *location_renderer;
1213
 
        GtkListStore *store;
1214
 
 
1215
 
        mode_type = g_enum_register_static ("NetworkPreferencesProxyType",
1216
 
                                            proxytype_values);
1217
 
 
1218
 
        client = gconf_client_get_default ();
1219
 
 
1220
 
        /* Locations */
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));
1224
 
 
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);
1228
 
 
1229
 
        gconf_client_notify_add (client, IGNORE_HOSTS_KEY, cb_ignore_hosts_gconf_changed, NULL, NULL, NULL);
1230
 
 
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);
1233
 
 
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),
1237
 
                                        location_renderer,
1238
 
                                        "text", COL_NAME,
1239
 
                                        "style", COL_STYLE, NULL);
1240
 
 
1241
 
        /* Mode */
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);
1244
 
 
1245
 
        peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_select_radio_with_enum (NULL,
1246
 
                        PROXY_MODE_KEY, mode_group, mode_type,
1247
 
                        TRUE, NULL));
1248
 
 
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));
1253
 
 
1254
 
        g_signal_connect (same_proxy_toggle,
1255
 
                        "toggled",
1256
 
                        G_CALLBACK (cb_use_same_proxy_checkbutton_clicked),
1257
 
                        builder);
1258
 
 
1259
 
        /* Http */
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,
1265
 
                        NULL));
1266
 
        peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
1267
 
                        NULL, HTTP_PROXY_PORT_KEY,
1268
 
                        _gtk_builder_get_widget (builder, "http_port_spinbutton"),
1269
 
                        NULL));
1270
 
        g_signal_connect (gtk_builder_get_object (builder, "details_button"),
1271
 
                          "clicked",
1272
 
                          G_CALLBACK (cb_http_details_button_clicked),
1273
 
                          _gtk_builder_get_widget (builder, "network_dialog"));
1274
 
 
1275
 
        /* Secure */
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,
1282
 
                        NULL));
1283
 
        peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
1284
 
                        NULL, SECURE_PROXY_PORT_KEY,
1285
 
                        _gtk_builder_get_widget (builder, "secure_port_spinbutton"),
1286
 
                        NULL));
1287
 
 
1288
 
        /* Ftp */
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,
1295
 
                        NULL));
1296
 
        peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
1297
 
                        NULL, FTP_PROXY_PORT_KEY,
1298
 
                        _gtk_builder_get_widget (builder, "ftp_port_spinbutton"),
1299
 
                        NULL));
1300
 
 
1301
 
        /* Socks */
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,
1308
 
                        NULL));
1309
 
        peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
1310
 
                        NULL, SOCKS_PROXY_PORT_KEY,
1311
 
                        _gtk_builder_get_widget (builder, "socks_port_spinbutton"),
1312
 
                        NULL));
1313
 
 
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)))
1317
 
        {
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);
1324
 
 
1325
 
                synchronize_entries (builder);
1326
 
        }
1327
 
 
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"),
1332
 
                        NULL));
1333
 
 
1334
 
        g_signal_connect (gtk_builder_get_object (builder, "network_dialog"),
1335
 
                          "response", G_CALLBACK (cb_dialog_response), NULL);
1336
 
 
1337
 
 
1338
 
        ignore_hosts = gconf_client_get_list(client, IGNORE_HOSTS_KEY, GCONF_VALUE_STRING, NULL);
1339
 
        g_object_unref (client);
1340
 
 
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);
1344
 
 
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);
1351
 
}
1352
 
 
1353
 
int
1354
 
main (int argc, char **argv)
1355
 
{
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;
1362
 
        GtkWidget   *widget;
1363
 
 
1364
 
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
1365
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1366
 
        textdomain (GETTEXT_PACKAGE);
1367
 
 
1368
 
        gtk_init (&argc, &argv);
1369
 
 
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);
1375
 
 
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",
1380
 
                           error->message);
1381
 
                g_error_free (error);
1382
 
                g_object_unref (builder);
1383
 
                g_object_unref (client);
1384
 
                return (EXIT_FAILURE);
1385
 
        }
1386
 
 
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);
1391
 
        gtk_main ();
1392
 
 
1393
 
        g_object_unref (builder);
1394
 
        g_object_unref (client);
1395
 
 
1396
 
        return 0;
1397
 
}