aboutsummaryrefslogtreecommitdiffstats
path: root/src/prefs-dialog.c
blob: 17ca94cd88e942f84a7d24c6f2176df35bfa08b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/*
 *  Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "prefs-dialog.h"
#include "general-prefs.h"
#include "appearance-prefs.h"
#include "ephy-dialog.h"
#include "ephy-prefs.h"
#include "ephy-embed-prefs.h"
#include "ephy-shell.h"
#include "ephy-state.h"

#include <bonobo/bonobo-i18n.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtkradiobutton.h>
#include <gtk/gtktogglebutton.h>
#include <gtk/gtkimage.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkstock.h>
#include <gtk/gtkmessagedialog.h>
#include <libgnome/gnome-help.h>

static void
prefs_dialog_class_init (PrefsDialogClass *klass);
static void
prefs_dialog_init (PrefsDialog *pd);
static void
prefs_dialog_finalize (GObject *object);

/* Glade callbacks */
void
prefs_proxy_auto_url_reload_cb (GtkWidget *button,
                    EphyDialog *dialog);
void
prefs_clear_memory_cache_button_clicked_cb (GtkWidget *button,
                        gpointer data);
void
prefs_clear_disk_cache_button_clicked_cb (GtkWidget *button,
                      gpointer data);


/* Proxy page */

enum
{
    CACHE_COMPARE_PROP,
    DISK_CACHE_PROP,
    MEMORY_CACHE_PROP
};

static const
EphyDialogProperty network_properties [] =
{
    { CACHE_COMPARE_PROP, "cache_compare_radiobutton", CONF_NETWORK_CACHE_COMPARE, PT_AUTOAPPLY, NULL },
    { DISK_CACHE_PROP, "disk_cache_spin", CONF_NETWORK_DISK_CACHE, PT_AUTOAPPLY, NULL },
    { MEMORY_CACHE_PROP, "memory_cache_spin", CONF_NETWORK_MEMORY_CACHE, PT_AUTOAPPLY, NULL },

    { -1, NULL, NULL }
};

enum
{
    OPEN_IN_TABS_PROP,
    JUMP_TO_PROP,
    POPUPS_PROP
};

static const
EphyDialogProperty ui_properties [] =
{
    { OPEN_IN_TABS_PROP, "open_in_tabs_checkbutton", CONF_TABS_TABBED, PT_AUTOAPPLY, NULL },
    { JUMP_TO_PROP, "jump_to_checkbutton", CONF_TABS_TABBED_AUTOJUMP, PT_AUTOAPPLY, NULL },
    { POPUPS_PROP, "popups_checkbutton", CONF_TABS_TABBED_POPUPS, PT_AUTOAPPLY, NULL },

    { -1, NULL, NULL }
};

struct PrefsDialogPrivate
{
    GtkWidget *notebook;
};

static GObjectClass *parent_class = NULL;

GType
prefs_dialog_get_type (void)
{
        static GType prefs_dialog_type = 0;

        if (prefs_dialog_type == 0)
        {
                static const GTypeInfo our_info =
                {
                        sizeof (PrefsDialogClass),
                        NULL, /* base_init */
                        NULL, /* base_finalize */
                        (GClassInitFunc) prefs_dialog_class_init,
                        NULL,
                        NULL, /* class_data */
                        sizeof (PrefsDialog),
                        0, /* n_preallocs */
                        (GInstanceInitFunc) prefs_dialog_init
                };

                prefs_dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
                                "PrefsDialog",
                                &our_info, 0);
        }

        return prefs_dialog_type;

}

GtkDialog *
prefs_dialog_new (void)
{
        GtkDialog *dialog;

        dialog = GTK_DIALOG (g_object_new (PREFS_DIALOG_TYPE, NULL));

        return dialog;
}

static void
prefs_dialog_class_init (PrefsDialogClass *klass)
{
        GObjectClass *object_class = G_OBJECT_CLASS (klass);

        parent_class = g_type_class_peek_parent (klass);

        object_class->finalize = prefs_dialog_finalize;
}

static void
prefs_dialog_finalize (GObject *object)
{
        PrefsDialog *pd;

        g_return_if_fail (object != NULL);
        g_return_if_fail (IS_PREFS_DIALOG (object));

    pd = PREFS_DIALOG (object);

        g_return_if_fail (pd->priv != NULL);

        g_free (pd->priv);

        G_OBJECT_CLASS (parent_class)->finalize (object);
}

static EphyDialog *
create_page (PrefsPageID id,
         const char *page_widget,
         const EphyDialogProperty *prop)
{
    EphyDialog *page = NULL;

    switch (id)
    {
    case PREFS_PAGE_GENERAL:
        page = general_prefs_new ();
        break;
    case PREFS_PAGE_APPEARANCE:
        page = appearance_prefs_new ();
        break;
    case PREFS_PAGE_UI:
    case PREFS_PAGE_ADVANCED:
        page = ephy_dialog_new ();
        ephy_dialog_construct (EPHY_DIALOG(page),
                       prop,
                       "prefs-dialog.glade",
                       page_widget);
        break;
    }

    return page;
}

static EphyDialog *
prefs_dialog_get_page (PrefsDialog *pd,
               PrefsPageID id)
{
    const char *page_widget = NULL;
    EphyDialog *page;
    const EphyDialogProperty *prop = NULL;

    switch (id)
    {
    case PREFS_PAGE_APPEARANCE:
        page_widget = "appearance_page_box";
        break;
    case PREFS_PAGE_GENERAL:
        page_widget = "general_page_box";
        break;
    case PREFS_PAGE_UI:
        page_widget = "ui_page_box";
        prop = ui_properties;
        break;
    case PREFS_PAGE_ADVANCED:
        page_widget = "network_page_box";
        prop = network_properties;
        break;
    }

    g_assert (page_widget != NULL);

    page = create_page (id, page_widget, prop);
    g_assert (page != NULL);

    return page;
}

void
prefs_dialog_show_page (PrefsDialog *pd,
                PrefsPageID id)
{
    gtk_notebook_set_current_page (GTK_NOTEBOOK (pd->priv->notebook), id);
}

static void
prefs_dialog_show_help (PrefsDialog *pd)
{
    GError *err = NULL;
    gint id;
    gchar *help_preferences[] = {
        "ephy-preferences-appearance",
        "ephy-preferences-general",
        "ephy-preferences-ui",
        "ephy-preferences-advanced"
    };

    id = gtk_notebook_get_current_page (GTK_NOTEBOOK (pd->priv->notebook));

    gnome_help_display ("epiphany", help_preferences [id], &err);
    if (err != NULL) 
    {
        GtkWidget *err_dialog;
        err_dialog = gtk_message_dialog_new (
                GTK_WINDOW (pd),
                GTK_DIALOG_DESTROY_WITH_PARENT,
                GTK_MESSAGE_ERROR,
                GTK_BUTTONS_CLOSE,
                _("Could not display help: %s"),
                  err->message);

        g_signal_connect (G_OBJECT (err_dialog), "response",
                G_CALLBACK (gtk_widget_destroy),
                NULL);
        gtk_window_set_resizable (GTK_WINDOW (err_dialog),
                FALSE);
        gtk_widget_show (err_dialog);
        g_error_free (err);
    }
}

static void
prefs_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer data)
{
    if (response_id == GTK_RESPONSE_CLOSE)
    {
        gtk_widget_destroy (GTK_WIDGET(dialog));
    }
    else if (response_id == GTK_RESPONSE_HELP)
    {
        PrefsDialog *pd = (PrefsDialog *)data;
        prefs_dialog_show_help (pd);
    }
}

static void
prefs_build_notebook (PrefsDialog *pd)
{
    int i;
    GtkWidget *nb;

    struct
    {
        char *name;
        int id;
    }
    pages[] =
    {
        { _("General"), PREFS_PAGE_GENERAL },
        { _("Appearance"), PREFS_PAGE_APPEARANCE },
        { _("User Interface"), PREFS_PAGE_UI },
        { _("Advanced"), PREFS_PAGE_ADVANCED },

        { NULL, 0 }
    };

    gtk_dialog_add_button (GTK_DIALOG (pd), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);

    gtk_dialog_add_button (GTK_DIALOG (pd), GTK_STOCK_HELP, GTK_RESPONSE_HELP);
    g_signal_connect (pd, "response",
              G_CALLBACK (prefs_dialog_response_cb),
              pd);

    gtk_container_set_border_width (GTK_CONTAINER (pd), 5);

    nb = gtk_notebook_new ();
    gtk_container_set_border_width (GTK_CONTAINER (nb), 5);
    gtk_widget_show (nb);
    gtk_container_add (GTK_CONTAINER (GTK_DIALOG (pd)->vbox), nb);
    gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), TRUE);
    pd->priv->notebook = nb;

    for (i = 0; pages[i].name != NULL; i++)
    {
        GtkWidget *label, *child;
        EphyDialog *page;

        page = prefs_dialog_get_page (pd, pages[i].id);

        child = gtk_hbox_new (FALSE, 0);
        gtk_widget_show (child);
        label = gtk_label_new (pages[i].name);
        gtk_notebook_append_page (GTK_NOTEBOOK (nb),
                      child, label);

        ephy_dialog_show_embedded (page, child);
    }
}

static void
prefs_dialog_init (PrefsDialog *pd)
{
    GdkPixbuf *icon;
    pd->priv = g_new0 (PrefsDialogPrivate, 1);

    gtk_window_set_title (GTK_WINDOW(pd), _("Preferences"));
    gtk_dialog_set_has_separator (GTK_DIALOG(pd), FALSE);

    ephy_state_add_window (GTK_WIDGET(pd),
                   "prefs_dialog", -1, -1);
    
    icon = gtk_widget_render_icon (GTK_WIDGET(pd),
                              GTK_STOCK_PREFERENCES,
                              GTK_ICON_SIZE_MENU,
                              "prefs_dialog");
    gtk_window_set_icon (GTK_WINDOW(pd), icon);
    g_object_unref(icon);

    prefs_build_notebook (pd);
}

/* Network page callbacks */

void
prefs_clear_memory_cache_button_clicked_cb (GtkWidget *button,
                        gpointer data)
{
    EphyEmbedSingle *single;

    single = ephy_embed_shell_get_embed_single
        (EPHY_EMBED_SHELL (ephy_shell));

    ephy_embed_single_clear_cache (single, MEMORY_CACHE);
}

void
prefs_clear_disk_cache_button_clicked_cb (GtkWidget *button,
                      gpointer data)
{
    EphyEmbedSingle *single;

    single = ephy_embed_shell_get_embed_single
        (EPHY_EMBED_SHELL (ephy_shell));

    ephy_embed_single_clear_cache (single, DISK_CACHE);
}