~ivaldi/midori/tabby-title-changed

« back to all changes in this revision

Viewing changes to src/midori-preferences.c

  • Committer: Christian Dywan
  • Date: 2008-06-01 21:47:27 UTC
  • Revision ID: git-v1:b511f12b9b4b063610161f2229b94a24a86be0fc
Rename folder 'src' to 'midori'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 Copyright (C) 2007-2008 Christian Dywan <christian@twotoasts.de>
3
 
 
4
 
 This library is free software; you can redistribute it and/or
5
 
 modify it under the terms of the GNU Lesser General Public
6
 
 License as published by the Free Software Foundation; either
7
 
 version 2.1 of the License, or (at your option) any later version.
8
 
 
9
 
 See the file COPYING for the full license text.
10
 
*/
11
 
 
12
 
#include "midori-preferences.h"
13
 
 
14
 
#include "sokoke.h"
15
 
 
16
 
#include <glib/gi18n.h>
17
 
 
18
 
G_DEFINE_TYPE (MidoriPreferences, midori_preferences, GTK_TYPE_DIALOG)
19
 
 
20
 
struct _MidoriPreferencesPrivate
21
 
{
22
 
    GtkWidget* notebook;
23
 
};
24
 
 
25
 
#define MIDORI_PREFERENCES_GET_PRIVATE(obj) \
26
 
    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
27
 
     MIDORI_TYPE_PREFERENCES, MidoriPreferencesPrivate))
28
 
 
29
 
enum
30
 
{
31
 
    PROP_0,
32
 
 
33
 
    PROP_SETTINGS
34
 
};
35
 
 
36
 
static void
37
 
midori_preferences_finalize (GObject* object);
38
 
 
39
 
static void
40
 
midori_preferences_set_property (GObject*      object,
41
 
                                 guint         prop_id,
42
 
                                 const GValue* value,
43
 
                                 GParamSpec*   pspec);
44
 
 
45
 
static void
46
 
midori_preferences_get_property (GObject*    object,
47
 
                                 guint       prop_id,
48
 
                                 GValue*     value,
49
 
                                 GParamSpec* pspec);
50
 
 
51
 
static void
52
 
midori_preferences_class_init (MidoriPreferencesClass* class)
53
 
{
54
 
    GObjectClass* gobject_class = G_OBJECT_CLASS (class);
55
 
    gobject_class->finalize = midori_preferences_finalize;
56
 
    gobject_class->set_property = midori_preferences_set_property;
57
 
    gobject_class->get_property = midori_preferences_get_property;
58
 
 
59
 
    g_object_class_install_property (gobject_class,
60
 
                                     PROP_SETTINGS,
61
 
                                     g_param_spec_object (
62
 
                                     "settings",
63
 
                                     "Settings",
64
 
                                     _("Settings instance to provide properties"),
65
 
                                     MIDORI_TYPE_WEB_SETTINGS,
66
 
                                     G_PARAM_WRITABLE));
67
 
 
68
 
    g_type_class_add_private (class, sizeof (MidoriPreferencesPrivate));
69
 
}
70
 
 
71
 
static void
72
 
clear_button_clicked_cb (GtkWidget* button, GtkWidget* file_chooser)
73
 
{
74
 
    gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (file_chooser), "");
75
 
    // Emit "file-set" manually for Gtk doesn't emit it otherwise
76
 
    g_signal_emit_by_name (file_chooser, "file-set");
77
 
}
78
 
 
79
 
static void
80
 
midori_preferences_init (MidoriPreferences* preferences)
81
 
{
82
 
    preferences->priv = MIDORI_PREFERENCES_GET_PRIVATE (preferences);
83
 
    MidoriPreferencesPrivate* priv = preferences->priv;
84
 
 
85
 
    priv->notebook = NULL;
86
 
 
87
 
    gchar* dialog_title = g_strdup_printf (_("%s Preferences"),
88
 
                                           g_get_application_name ());
89
 
    g_object_set (preferences,
90
 
                  "icon-name", GTK_STOCK_PREFERENCES,
91
 
                  "title", dialog_title,
92
 
                  "has-separator", FALSE,
93
 
                  NULL);
94
 
    gtk_dialog_add_buttons (GTK_DIALOG (preferences),
95
 
        GTK_STOCK_HELP, GTK_RESPONSE_HELP,
96
 
        GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
97
 
        NULL);
98
 
    // TODO: Implement some kind of help function
99
 
    gtk_dialog_set_response_sensitive (GTK_DIALOG (preferences),
100
 
                                       GTK_RESPONSE_HELP, FALSE); //...
101
 
    g_signal_connect (preferences, "response",
102
 
                      G_CALLBACK (gtk_widget_destroy), preferences);
103
 
 
104
 
    // TODO: Do we want tooltips for explainations or can we omit that?
105
 
    g_free (dialog_title);
106
 
}
107
 
 
108
 
static void
109
 
midori_preferences_finalize (GObject* object)
110
 
{
111
 
    G_OBJECT_CLASS (midori_preferences_parent_class)->finalize (object);
112
 
}
113
 
 
114
 
static void
115
 
midori_preferences_set_property (GObject*      object,
116
 
                                 guint         prop_id,
117
 
                                 const GValue* value,
118
 
                                 GParamSpec*   pspec)
119
 
{
120
 
    MidoriPreferences* preferences = MIDORI_PREFERENCES (object);
121
 
 
122
 
    switch (prop_id)
123
 
    {
124
 
    case PROP_SETTINGS:
125
 
    {
126
 
        GtkWidget* xfce_heading;
127
 
        GtkWindow* parent;
128
 
        g_object_get (object, "transient-for", &parent, NULL);
129
 
        if ((xfce_heading = sokoke_xfce_header_new (
130
 
            gtk_window_get_icon_name (parent),
131
 
            gtk_window_get_title (GTK_WINDOW (object)))))
132
 
                gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox),
133
 
                                    xfce_heading, FALSE, FALSE, 0);
134
 
        midori_preferences_set_settings (preferences,
135
 
                                         g_value_get_object (value));
136
 
        break;
137
 
    }
138
 
    default:
139
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
140
 
        break;
141
 
    }
142
 
}
143
 
 
144
 
static void
145
 
midori_preferences_get_property (GObject*    object,
146
 
                                 guint       prop_id,
147
 
                                 GValue*     value,
148
 
                                 GParamSpec* pspec)
149
 
{
150
 
    switch (prop_id)
151
 
    {
152
 
    default:
153
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
154
 
        break;
155
 
    }
156
 
}
157
 
 
158
 
/**
159
 
 * midori_preferences_new:
160
 
 * @parent: the parent window
161
 
 * @settings: the settings
162
 
 *
163
 
 * Creates a new preferences dialog.
164
 
 *
165
 
 * Return value: a new #MidoriPreferences
166
 
 **/
167
 
GtkWidget*
168
 
midori_preferences_new (GtkWindow*         parent,
169
 
                        MidoriWebSettings* settings)
170
 
{
171
 
    g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
172
 
    g_return_val_if_fail (MIDORI_IS_WEB_SETTINGS (settings), NULL);
173
 
 
174
 
    MidoriPreferences* preferences = g_object_new (MIDORI_TYPE_PREFERENCES,
175
 
                                                   "transient-for", parent,
176
 
                                                   "settings", settings,
177
 
                                                   NULL);
178
 
 
179
 
    return GTK_WIDGET (preferences);
180
 
}
181
 
 
182
 
/**
183
 
 * midori_preferences_set_settings:
184
 
 * @settings: the settings
185
 
 *
186
 
 * Assigns a settings instance to a preferences dialog.
187
 
 *
188
 
 * Note: This must not be called more than once.
189
 
 **/
190
 
void
191
 
midori_preferences_set_settings (MidoriPreferences* preferences,
192
 
                                 MidoriWebSettings* settings)
193
 
{
194
 
    g_return_if_fail (MIDORI_IS_PREFERENCES (preferences));
195
 
    g_return_if_fail (MIDORI_IS_WEB_SETTINGS (settings));
196
 
 
197
 
    MidoriPreferencesPrivate* priv = preferences->priv;
198
 
 
199
 
    g_return_if_fail (!priv->notebook);
200
 
 
201
 
    priv->notebook = gtk_notebook_new ();
202
 
    gtk_container_set_border_width (GTK_CONTAINER (priv->notebook), 6);
203
 
    GtkSizeGroup* sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
204
 
    GtkWidget* page; GtkWidget* frame; GtkWidget* table; GtkWidget* align;
205
 
    GtkWidget* label; GtkWidget* button;
206
 
    GtkWidget* entry; GtkWidget* hbox;
207
 
    #define PAGE_NEW(__label) page = gtk_vbox_new (FALSE, 0); \
208
 
     gtk_container_set_border_width (GTK_CONTAINER (page), 5); \
209
 
     gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page, \
210
 
                               gtk_label_new (__label))
211
 
    #define FRAME_NEW(__label) frame = sokoke_hig_frame_new (__label); \
212
 
     gtk_container_set_border_width (GTK_CONTAINER (frame), 5); \
213
 
     gtk_box_pack_start (GTK_BOX (page), frame, FALSE, FALSE, 0);
214
 
    #define TABLE_NEW(__rows, __cols) table = gtk_table_new ( \
215
 
                                       __rows, __cols, FALSE); \
216
 
     gtk_container_set_border_width (GTK_CONTAINER (table), 5); \
217
 
     gtk_container_add (GTK_CONTAINER (frame), table);
218
 
    #define WIDGET_ADD(__widget, __left, __right, __top, __bottom) \
219
 
     gtk_table_attach (GTK_TABLE (table), __widget \
220
 
      , __left, __right, __top, __bottom \
221
 
      , GTK_FILL, GTK_FILL, 8, 2)
222
 
    #define FILLED_ADD(__widget, __left, __right, __top, __bottom) \
223
 
     gtk_table_attach (GTK_TABLE (table), __widget \
224
 
      , __left, __right, __top, __bottom\
225
 
      , GTK_EXPAND | GTK_FILL, GTK_FILL, 8, 2)
226
 
    #define INDENTED_ADD(__widget, __left, __right, __top, __bottom) \
227
 
     align = gtk_alignment_new (0, 0.5, 0, 0); \
228
 
     gtk_container_add (GTK_CONTAINER (align), __widget); \
229
 
     gtk_size_group_add_widget (sizegroup, align); \
230
 
     WIDGET_ADD (align, __left, __right, __top, __bottom)
231
 
    #define SPANNED_ADD(__widget, __left, __right, __top, __bottom) \
232
 
     align = gtk_alignment_new (0, 0.5, 0, 0); \
233
 
     gtk_container_add (GTK_CONTAINER (align), __widget); \
234
 
     FILLED_ADD (align, __left, __right, __top, __bottom)
235
 
    // Page "General"
236
 
    PAGE_NEW (_("General"));
237
 
    FRAME_NEW (_("Startup"));
238
 
    TABLE_NEW (2, 2);
239
 
    label = katze_property_label (settings, "load-on-startup");
240
 
    INDENTED_ADD (label, 0, 1, 0, 1);
241
 
    button = katze_property_proxy (settings, "load-on-startup", NULL);
242
 
    FILLED_ADD (button, 1, 2, 0, 1);
243
 
    label = katze_property_label (settings, "homepage");
244
 
    INDENTED_ADD (label, 0, 1, 1, 2);
245
 
    entry = katze_property_proxy (settings, "homepage", NULL);
246
 
    FILLED_ADD (entry, 1, 2, 1, 2);
247
 
    // TODO: We need something like "use current website"
248
 
    FRAME_NEW (_("Transfers"));
249
 
    TABLE_NEW (1, 2);
250
 
    label = katze_property_label (settings, "download-folder");
251
 
    INDENTED_ADD (label, 0, 1, 0, 1);
252
 
    button = katze_property_proxy (settings, "download-folder", "folder");
253
 
    FILLED_ADD (button, 1, 2, 0, 1);
254
 
    button = katze_property_proxy (settings, "show-download-notification", "blurb");
255
 
    SPANNED_ADD (button, 0, 2, 1, 2);
256
 
 
257
 
    // Page "Appearance"
258
 
    PAGE_NEW (_("Appearance"));
259
 
    FRAME_NEW (_("Font settings"));
260
 
    TABLE_NEW (5, 2);
261
 
    label = katze_property_label (settings, "default-font-family");
262
 
    INDENTED_ADD (label, 0, 1, 0, 1);
263
 
    hbox = gtk_hbox_new (FALSE, 4);
264
 
    button = katze_property_proxy (settings, "default-font-family", "font");
265
 
    gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
266
 
    entry = katze_property_proxy (settings, "default-font-size", NULL);
267
 
    gtk_box_pack_end (GTK_BOX (hbox), entry, FALSE, FALSE, 4);
268
 
    FILLED_ADD (hbox, 1, 2, 0, 1);
269
 
    label = katze_property_label (settings, "minimum-font-size");
270
 
    INDENTED_ADD (label, 0, 1, 1, 2);
271
 
    hbox = gtk_hbox_new (FALSE, 4);
272
 
    entry = katze_property_proxy (settings, "minimum-font-size", NULL);
273
 
    INDENTED_ADD (entry, 1, 2, 1, 2);
274
 
    label = katze_property_label (settings, "preferred-encoding");
275
 
    INDENTED_ADD (label, 0, 1, 2, 3);
276
 
    button = katze_property_proxy (settings, "preferred-encoding", NULL);
277
 
    FILLED_ADD (button, 1, 2, 2, 3);
278
 
 
279
 
    // Page "Behavior"
280
 
    PAGE_NEW (_("Behavior"));
281
 
    FRAME_NEW (_("Features"));
282
 
    TABLE_NEW (5, 2);
283
 
    button = katze_property_proxy (settings, "auto-load-images", NULL);
284
 
    INDENTED_ADD (button, 0, 1, 0, 1);
285
 
    button = katze_property_proxy (settings, "auto-shrink-images", NULL);
286
 
    SPANNED_ADD (button, 1, 2, 0, 1);
287
 
    button = katze_property_proxy (settings, "print-backgrounds", NULL);
288
 
    INDENTED_ADD (button, 0, 1, 1, 2);
289
 
    button = katze_property_proxy (settings, "resizable-text-areas", NULL);
290
 
    SPANNED_ADD (button, 1, 2, 1, 2);
291
 
    button = katze_property_proxy (settings, "enable-scripts", NULL);
292
 
    INDENTED_ADD (button, 0, 1, 2, 3);
293
 
    button = katze_property_proxy (settings, "enable-plugins", NULL);
294
 
    SPANNED_ADD(button, 1, 2, 2, 3);
295
 
    label = katze_property_label (settings, "user-stylesheet-uri");
296
 
    INDENTED_ADD (label, 0, 1, 3, 4);
297
 
    hbox = gtk_hbox_new (FALSE, 4);
298
 
    entry = katze_property_proxy (settings, "user-stylesheet-uri", "uri");
299
 
    gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
300
 
    button = gtk_button_new ();
301
 
    gtk_container_add (GTK_CONTAINER (button),
302
 
        gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
303
 
    g_signal_connect (button, "clicked",
304
 
                      G_CALLBACK (clear_button_clicked_cb), entry);
305
 
    gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 4);
306
 
    FILLED_ADD (hbox, 1, 2, 3, 4);
307
 
    label = katze_property_label (settings, "location-entry-search");
308
 
    INDENTED_ADD (label, 0, 1, 4, 5);
309
 
    entry = katze_property_proxy (settings, "location-entry-search", NULL);
310
 
    FILLED_ADD (entry, 1, 2, 4, 5);
311
 
 
312
 
    // Page "Interface"
313
 
    PAGE_NEW (_("Interface"));
314
 
    FRAME_NEW (_("Navigationbar"));
315
 
    TABLE_NEW (3, 2);
316
 
    INDENTED_ADD (katze_property_label (settings, "toolbar-style"), 0, 1, 0, 1);
317
 
    button = katze_property_proxy (settings, "toolbar-style", NULL);
318
 
    FILLED_ADD(button, 1, 2, 0, 1);
319
 
    button = katze_property_proxy (settings, "show-new-tab", NULL);
320
 
    INDENTED_ADD (button, 0, 1, 1, 2);
321
 
    button = katze_property_proxy (settings, "show-web-search", NULL);
322
 
    SPANNED_ADD (button, 1, 2, 1, 2);
323
 
    button = katze_property_proxy (settings, "show-homepage", NULL);
324
 
    INDENTED_ADD (button, 0, 1, 2, 3);
325
 
    button = katze_property_proxy (settings, "show-trash", NULL);
326
 
    SPANNED_ADD (button, 1, 2, 2, 3);
327
 
    FRAME_NEW(_("Browsing"));
328
 
    TABLE_NEW (3, 2);
329
 
    label = katze_property_label (settings, "open-new-pages-in");
330
 
    INDENTED_ADD (label, 0, 1, 0, 1);
331
 
    button = katze_property_proxy (settings, "open-new-pages-in", NULL);
332
 
    FILLED_ADD (button, 1, 2, 0, 1);
333
 
    button = katze_property_proxy (settings, "middle-click-opens-selection", NULL);
334
 
    INDENTED_ADD (button, 0, 1, 1, 2);
335
 
    button = katze_property_proxy (settings, "open-tabs-in-the-background", NULL);
336
 
    SPANNED_ADD (button, 1, 2, 1, 2);
337
 
    button = katze_property_proxy (settings, "open-popups-in-tabs", NULL);
338
 
    SPANNED_ADD (button, 0, 1, 2, 3);
339
 
    button = katze_property_proxy (settings, "close-buttons-on-tabs", NULL);
340
 
    SPANNED_ADD (button, 1, 2, 2, 3);
341
 
 
342
 
    // Page "Network"
343
 
    PAGE_NEW (_("Network"));
344
 
    FRAME_NEW (_("Network"));
345
 
    TABLE_NEW (2, 2);
346
 
    label = katze_property_label (settings, "http-proxy");
347
 
    INDENTED_ADD (label, 0, 1, 0, 1);
348
 
    button = katze_property_proxy (settings, "http-proxy", NULL);
349
 
    FILLED_ADD (button, 1, 2, 0, 1);
350
 
    label = katze_property_label (settings, "cache-size");
351
 
    INDENTED_ADD (label, 0, 1, 1, 2);
352
 
    hbox = gtk_hbox_new (FALSE, 4);
353
 
    entry = katze_property_proxy (settings, "cache-size", NULL);
354
 
    gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
355
 
    gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("MB")),
356
 
                        FALSE, FALSE, 0);
357
 
    FILLED_ADD (hbox, 1, 2, 1, 2);
358
 
 
359
 
    // Page "Privacy"
360
 
    PAGE_NEW (_("Privacy"));
361
 
    FRAME_NEW (_("Web Cookies"));
362
 
    TABLE_NEW (3, 2);
363
 
    label = katze_property_label (settings, "accept-cookies");
364
 
    INDENTED_ADD (label, 0, 1, 0, 1);
365
 
    button = katze_property_proxy (settings, "accept-cookies", NULL);
366
 
    FILLED_ADD (button, 1, 2, 0, 1);
367
 
    button = katze_property_proxy (settings, "original-cookies-only", "blurb");
368
 
    SPANNED_ADD (button, 0, 2, 1, 2);
369
 
    label = katze_property_label (settings, "maximum-cookie-age");
370
 
    INDENTED_ADD (label, 0, 1, 2, 3);
371
 
    hbox = gtk_hbox_new (FALSE, 4);
372
 
    entry = katze_property_proxy (settings, "maximum-cookie-age", NULL);
373
 
    gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
374
 
    gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("days")),
375
 
                        FALSE, FALSE, 0);
376
 
    FILLED_ADD (hbox, 1, 2, 2, 3);
377
 
    FRAME_NEW (_("History"));
378
 
    TABLE_NEW (3, 2);
379
 
    button = katze_property_proxy (settings, "remember-last-visited-pages", NULL);
380
 
    SPANNED_ADD (button, 0, 1, 0, 1);
381
 
    hbox = gtk_hbox_new (FALSE, 4);
382
 
    button = katze_property_proxy (settings, "maximum-history-age", NULL);
383
 
    gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
384
 
    gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("days")),
385
 
                        FALSE, FALSE, 0);
386
 
    SPANNED_ADD (hbox, 1, 2, 0, 1);
387
 
    button = katze_property_proxy (settings, "remember-last-form-inputs", NULL);
388
 
    SPANNED_ADD (button, 0, 2, 1, 2);
389
 
    button = katze_property_proxy (settings, "remember-last-downloaded-files", NULL);
390
 
    SPANNED_ADD (button, 0, 2, 2, 3);
391
 
 
392
 
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox),
393
 
                        priv->notebook, FALSE, FALSE, 4);
394
 
    gtk_widget_show_all (GTK_DIALOG (preferences)->vbox);
395
 
}