2
Copyright (C) 2007-2008 Christian Dywan <christian@twotoasts.de>
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.
9
See the file COPYING for the full license text.
12
#include "midori-preferences.h"
16
#include <glib/gi18n.h>
18
G_DEFINE_TYPE (MidoriPreferences, midori_preferences, GTK_TYPE_DIALOG)
20
struct _MidoriPreferencesPrivate
25
#define MIDORI_PREFERENCES_GET_PRIVATE(obj) \
26
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
27
MIDORI_TYPE_PREFERENCES, MidoriPreferencesPrivate))
37
midori_preferences_finalize (GObject* object);
40
midori_preferences_set_property (GObject* object,
46
midori_preferences_get_property (GObject* object,
52
midori_preferences_class_init (MidoriPreferencesClass* class)
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;
59
g_object_class_install_property (gobject_class,
64
_("Settings instance to provide properties"),
65
MIDORI_TYPE_WEB_SETTINGS,
68
g_type_class_add_private (class, sizeof (MidoriPreferencesPrivate));
72
clear_button_clicked_cb (GtkWidget* button, GtkWidget* file_chooser)
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");
80
midori_preferences_init (MidoriPreferences* preferences)
82
preferences->priv = MIDORI_PREFERENCES_GET_PRIVATE (preferences);
83
MidoriPreferencesPrivate* priv = preferences->priv;
85
priv->notebook = NULL;
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,
94
gtk_dialog_add_buttons (GTK_DIALOG (preferences),
95
GTK_STOCK_HELP, GTK_RESPONSE_HELP,
96
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
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);
104
// TODO: Do we want tooltips for explainations or can we omit that?
105
g_free (dialog_title);
109
midori_preferences_finalize (GObject* object)
111
G_OBJECT_CLASS (midori_preferences_parent_class)->finalize (object);
115
midori_preferences_set_property (GObject* object,
120
MidoriPreferences* preferences = MIDORI_PREFERENCES (object);
126
GtkWidget* xfce_heading;
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));
139
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145
midori_preferences_get_property (GObject* object,
153
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
159
* midori_preferences_new:
160
* @parent: the parent window
161
* @settings: the settings
163
* Creates a new preferences dialog.
165
* Return value: a new #MidoriPreferences
168
midori_preferences_new (GtkWindow* parent,
169
MidoriWebSettings* settings)
171
g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
172
g_return_val_if_fail (MIDORI_IS_WEB_SETTINGS (settings), NULL);
174
MidoriPreferences* preferences = g_object_new (MIDORI_TYPE_PREFERENCES,
175
"transient-for", parent,
176
"settings", settings,
179
return GTK_WIDGET (preferences);
183
* midori_preferences_set_settings:
184
* @settings: the settings
186
* Assigns a settings instance to a preferences dialog.
188
* Note: This must not be called more than once.
191
midori_preferences_set_settings (MidoriPreferences* preferences,
192
MidoriWebSettings* settings)
194
g_return_if_fail (MIDORI_IS_PREFERENCES (preferences));
195
g_return_if_fail (MIDORI_IS_WEB_SETTINGS (settings));
197
MidoriPreferencesPrivate* priv = preferences->priv;
199
g_return_if_fail (!priv->notebook);
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)
236
PAGE_NEW (_("General"));
237
FRAME_NEW (_("Startup"));
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"));
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);
258
PAGE_NEW (_("Appearance"));
259
FRAME_NEW (_("Font settings"));
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);
280
PAGE_NEW (_("Behavior"));
281
FRAME_NEW (_("Features"));
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);
313
PAGE_NEW (_("Interface"));
314
FRAME_NEW (_("Navigationbar"));
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"));
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);
343
PAGE_NEW (_("Network"));
344
FRAME_NEW (_("Network"));
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")),
357
FILLED_ADD (hbox, 1, 2, 1, 2);
360
PAGE_NEW (_("Privacy"));
361
FRAME_NEW (_("Web Cookies"));
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")),
376
FILLED_ADD (hbox, 1, 2, 2, 3);
377
FRAME_NEW (_("History"));
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")),
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);
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);