PageRenderTime 38ms CodeModel.GetById 14ms app.highlight 21ms RepoModel.GetById 0ms app.codeStats 0ms

/midori/midori-preferences.c

https://bitbucket.org/edgimar/midori
C | 520 lines | 433 code | 45 blank | 42 comment | 17 complexity | 033624e241c8600bff22c6f8cd328191 MD5 | raw file
Possible License(s): LGPL-2.1
  1/*
  2 Copyright (C) 2007-2009 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 "midori-app.h"
 15#include "midori-core.h"
 16#include "midori-platform.h"
 17
 18#include <string.h>
 19#include <glib/gi18n.h>
 20#include <libsoup/soup.h>
 21
 22#if WEBKIT_CHECK_VERSION (1, 3, 11)
 23    #define LIBSOUP_USE_UNSTABLE_REQUEST_API
 24    #include <libsoup/soup-cache.h>
 25#endif
 26
 27#include <config.h>
 28#if HAVE_LIBNOTIFY
 29    #include <libnotify/notify.h>
 30#endif
 31
 32struct _MidoriPreferences
 33{
 34    KatzePreferences parent_instance;
 35
 36    gpointer settings;
 37};
 38
 39G_DEFINE_TYPE (MidoriPreferences, midori_preferences, KATZE_TYPE_PREFERENCES);
 40
 41enum
 42{
 43    PROP_0,
 44
 45    PROP_SETTINGS
 46};
 47
 48static void
 49midori_preferences_finalize (GObject* object);
 50
 51static void
 52midori_preferences_set_property (GObject*      object,
 53                                 guint         prop_id,
 54                                 const GValue* value,
 55                                 GParamSpec*   pspec);
 56
 57static void
 58midori_preferences_get_property (GObject*    object,
 59                                 guint       prop_id,
 60                                 GValue*     value,
 61                                 GParamSpec* pspec);
 62
 63static void
 64midori_preferences_class_init (MidoriPreferencesClass* class)
 65{
 66    GObjectClass* gobject_class = G_OBJECT_CLASS (class);
 67    gobject_class->finalize = midori_preferences_finalize;
 68    gobject_class->set_property = midori_preferences_set_property;
 69    gobject_class->get_property = midori_preferences_get_property;
 70
 71    /**
 72     * MidoriPreferences:settings:
 73     *
 74     * The settings to proxy properties from.
 75     */
 76    g_object_class_install_property (gobject_class,
 77                                     PROP_SETTINGS,
 78                                     g_param_spec_object (
 79                                     "settings",
 80                                     "Settings",
 81                                     "Settings instance to provide properties",
 82                                     MIDORI_TYPE_WEB_SETTINGS,
 83                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 84}
 85
 86static void
 87midori_preferences_init (MidoriPreferences* preferences)
 88{
 89    preferences->settings = NULL;
 90}
 91
 92static void
 93midori_preferences_finalize (GObject* object)
 94{
 95    G_OBJECT_CLASS (midori_preferences_parent_class)->finalize (object);
 96}
 97
 98static void
 99midori_preferences_set_property (GObject*      object,
100                                 guint         prop_id,
101                                 const GValue* value,
102                                 GParamSpec*   pspec)
103{
104    MidoriPreferences* preferences = MIDORI_PREFERENCES (object);
105
106    switch (prop_id)
107    {
108    case PROP_SETTINGS:
109        midori_preferences_set_settings (preferences,
110                                         g_value_get_object (value));
111        break;
112    default:
113        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
114        break;
115    }
116}
117
118static void
119midori_preferences_get_property (GObject*    object,
120                                 guint       prop_id,
121                                 GValue*     value,
122                                 GParamSpec* pspec)
123{
124    MidoriPreferences* preferences = MIDORI_PREFERENCES (object);
125
126    switch (prop_id)
127    {
128    case PROP_SETTINGS:
129        g_value_set_object (value, preferences->settings);
130        break;
131    default:
132        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
133        break;
134    }
135}
136
137/**
138 * midori_preferences_new:
139 * @parent: the parent window
140 * @settings: the settings
141 *
142 * Creates a new preferences dialog.
143 *
144 * Since 0.1.2 @parent may be %NULL.
145 *
146 * Return value: a new #MidoriPreferences
147 **/
148GtkWidget*
149midori_preferences_new (GtkWindow*         parent,
150                        MidoriWebSettings* settings)
151{
152    MidoriPreferences* preferences;
153
154    g_return_val_if_fail (!parent || GTK_IS_WINDOW (parent), NULL);
155    g_return_val_if_fail (MIDORI_IS_WEB_SETTINGS (settings), NULL);
156
157    preferences = g_object_new (MIDORI_TYPE_PREFERENCES,
158                                "transient-for", parent,
159                                "settings", settings,
160                                NULL);
161
162    return GTK_WIDGET (preferences);
163}
164
165static void
166midori_preferences_homepage_current_clicked_cb (GtkWidget*         button,
167                                                MidoriWebSettings* settings)
168{
169    GtkWidget* preferences = gtk_widget_get_toplevel (button);
170    GtkWidget* browser = katze_object_get_object (preferences, "transient-for");
171
172    if (GTK_IS_WINDOW (browser))
173    {
174        gchar* uri = katze_object_get_string (browser, "uri");
175        if (uri && *uri)
176            g_object_set (settings, "homepage", uri, NULL);
177        else
178            g_object_set (settings, "homepage", "about:blank", NULL);
179        g_free (uri);
180    }
181}
182
183#if !HAVE_HILDON
184static void
185midori_preferences_notify_proxy_type_cb (MidoriWebSettings* settings,
186                                         GParamSpec*        pspec,
187                                         GtkWidget*         entry)
188{
189    MidoriProxy proxy_type = katze_object_get_enum (settings, "proxy-type");
190
191    gtk_widget_set_sensitive (entry, proxy_type == MIDORI_PROXY_HTTP);
192}
193#endif
194
195#if HAVE_OSX
196static void
197midori_preferences_toolbutton_clicked_cb (GtkWidget* toolbutton,
198                                          GtkWidget* page)
199{
200    gpointer notebook = g_object_get_data (G_OBJECT (toolbutton), "notebook");
201    guint n = gtk_notebook_page_num (notebook, page);
202    gtk_notebook_set_current_page (notebook, n);
203}
204#endif
205
206static inline void
207midori_preferences_add_toolbutton (GtkWidget*   toolbar,
208                                   GtkWidget**  toolbutton,
209                                   const gchar* icon,
210                                   const gchar* label,
211                                   GtkWidget*   page)
212{
213#if HAVE_OSX
214    *toolbutton = GTK_WIDGET (*toolbutton ? gtk_radio_tool_button_new_from_widget (
215        GTK_RADIO_TOOL_BUTTON (*toolbutton)) : gtk_radio_tool_button_new (NULL));
216    gtk_tool_button_set_label (GTK_TOOL_BUTTON (*toolbutton), label);
217    gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (*toolbutton), icon);
218    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (*toolbutton), -1);
219    g_signal_connect (*toolbutton, "clicked",
220        G_CALLBACK (midori_preferences_toolbutton_clicked_cb), page);
221#endif
222}
223
224#if 0
225static void
226midori_preferences_list_dicts_cb (const gchar* lang_tag,
227                                  const gchar* provider_name,
228                                  const gchar* provider_desc,
229                                  const gchar* provider_file,
230                                  GList**      dicts)
231{
232    *dicts = g_list_prepend (*dicts, (gchar*)lang_tag);
233}
234
235static GList*
236midori_preferences_get_spell_languages (void)
237{
238    GList* dicts = NULL;
239    gpointer broker = enchant_broker_init ();
240    enchant_broker_list_dicts (broker, (GCallback)midori_preferences_list_dicts_cb, &dicts);
241    enchant_broker_free (broker);
242    return dicts;
243}
244#endif
245
246/**
247 * midori_preferences_set_settings:
248 * @settings: the settings
249 *
250 * Assigns a settings instance to a preferences dialog.
251 *
252 * Note: This must not be called more than once.
253 *
254 * Since 0.1.2 this is equal to setting #MidoriPreferences:settings:.
255 **/
256void
257midori_preferences_set_settings (MidoriPreferences* preferences,
258                                 MidoriWebSettings* settings)
259{
260    GtkWidget* header;
261    GtkWindow* parent;
262    const gchar* icon_name;
263    KatzePreferences* _preferences;
264    GtkWidget* label;
265    GtkWidget* button;
266    GtkWidget* entry;
267
268    g_return_if_fail (MIDORI_IS_PREFERENCES (preferences));
269    g_return_if_fail (MIDORI_IS_WEB_SETTINGS (settings));
270
271    g_return_if_fail (!preferences->settings);
272
273    preferences->settings = settings;
274
275    g_object_get (preferences, "transient-for", &parent, NULL);
276    icon_name = parent ? gtk_window_get_icon_name (parent) : NULL;
277    if ((header = sokoke_xfce_header_new (icon_name,
278        gtk_window_get_title (GTK_WINDOW (preferences)))))
279    {
280        GtkWidget* vbox = gtk_dialog_get_content_area (GTK_DIALOG (preferences));
281        gtk_box_pack_start (GTK_BOX (vbox), header, FALSE, FALSE, 0);
282        gtk_widget_show_all (header);
283    }
284    _preferences = KATZE_PREFERENCES (preferences);
285
286    #define PAGE_NEW(__icon, __label) \
287     katze_preferences_add_category (_preferences, __label, __icon)
288    #define FRAME_NEW(__label) \
289     katze_preferences_add_group (_preferences, __label)
290    #define FILLED_ADD(__widget) \
291     katze_preferences_add_widget (_preferences, __widget, "filled")
292    #define INDENTED_ADD(__widget) \
293     katze_preferences_add_widget (_preferences, __widget, "indented")
294    #define SPANNED_ADD(__widget) \
295     katze_preferences_add_widget (_preferences, __widget, "spanned")
296    /* Page "General" */
297    if (!midori_paths_is_readonly ())
298    {
299    PAGE_NEW (GTK_STOCK_HOME, _("Startup"));
300    FRAME_NEW (NULL);
301    label = katze_property_label (settings, "load-on-startup");
302    INDENTED_ADD (label);
303    button = katze_property_proxy (settings, "load-on-startup", NULL);
304    SPANNED_ADD (button);
305    label = gtk_label_new (_("Homepage:"));
306    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
307    INDENTED_ADD (label);
308    entry = katze_property_proxy (settings, "homepage", "address");
309    SPANNED_ADD (entry);
310    if (parent && katze_object_has_property (parent, "uri"))
311    {
312        #if 0
313        button = gtk_button_new_with_mnemonic (_("Use _current page"));
314        #else
315        label = gtk_label_new (NULL);
316        INDENTED_ADD (label);
317        button = gtk_button_new_with_label (_("Use current page as homepage"));
318        #endif
319        g_signal_connect (button, "clicked",
320            G_CALLBACK (midori_preferences_homepage_current_clicked_cb), settings);
321        SPANNED_ADD (button);
322    }
323    }
324
325    /* Page "Appearance" */
326    PAGE_NEW (GTK_STOCK_SELECT_FONT, _("Fonts"));
327    FRAME_NEW (NULL);
328    #if !HAVE_HILDON
329    label = gtk_label_new (_("Proportional Font Family"));
330    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
331    INDENTED_ADD (label);
332    button = katze_property_proxy (settings, "default-font-family", "font");
333    gtk_widget_set_tooltip_text (button, _("The default font family used to display text"));
334    SPANNED_ADD (button);
335    entry = katze_property_proxy (settings, "default-font-size", NULL);
336    gtk_widget_set_tooltip_text (entry, _("The default font size used to display text"));
337    SPANNED_ADD (entry);
338    label = gtk_label_new (_("Fixed-width Font Family"));
339    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
340    INDENTED_ADD (label);
341    button = katze_property_proxy (settings, "monospace-font-family", "font-monospace");
342    gtk_widget_set_tooltip_text (button, _("The font family used to display fixed-width text"));
343    SPANNED_ADD (button);
344    entry = katze_property_proxy (settings, "default-monospace-font-size", NULL);
345    gtk_widget_set_tooltip_text (entry, _("The font size used to display fixed-width text"));
346    SPANNED_ADD (entry);
347    label = gtk_label_new (_("Minimum Font Size"));
348    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
349    INDENTED_ADD (label);
350    entry = katze_property_proxy (settings, "minimum-font-size", NULL);
351    gtk_widget_set_tooltip_text (entry, _("The minimum font size used to display text"));
352    SPANNED_ADD (entry);
353    button = katze_property_proxy (settings, "enforce-font-family", NULL);
354    INDENTED_ADD (button);
355    #endif
356    label = katze_property_label (settings, "preferred-encoding");
357    INDENTED_ADD (label);
358    button = katze_property_proxy (settings, "preferred-encoding", "custom-default-encoding");
359    SPANNED_ADD (button);
360
361    /* Page "Behavior" */
362    PAGE_NEW (GTK_STOCK_SELECT_COLOR, _("Behavior"));
363    FRAME_NEW (NULL);
364    #if !HAVE_HILDON
365    button = katze_property_proxy (settings, "auto-load-images", NULL);
366    gtk_button_set_label (GTK_BUTTON (button), _("Load images automatically"));
367    INDENTED_ADD (button);
368    button = katze_property_proxy (settings, "enable-spell-checking", NULL);
369    gtk_button_set_label (GTK_BUTTON (button), _("Enable Spell Checking"));
370    SPANNED_ADD (button);
371    /* Disable spell check option if there are no enchant modules */
372    {
373        gchar* enchant_path = midori_paths_get_lib_path ("enchant");
374        if (enchant_path == NULL)
375        {
376            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
377            gtk_widget_set_sensitive (button, FALSE);
378        }
379        else
380            g_free (enchant_path);
381    }
382    button = katze_property_proxy (settings, "enable-scripts", NULL);
383    gtk_button_set_label (GTK_BUTTON (button), _("Enable scripts"));
384    INDENTED_ADD (button);
385    button = katze_property_proxy (settings, "enable-plugins", NULL);
386    gtk_button_set_label (GTK_BUTTON (button), _("Enable Netscape plugins"));
387    gtk_widget_set_sensitive (button, midori_web_settings_has_plugin_support ());
388    SPANNED_ADD (button);
389    #endif
390    button = katze_property_proxy (settings, "zoom-text-and-images", NULL);
391    gtk_button_set_label (GTK_BUTTON (button), _("Zoom Text and Images"));
392    INDENTED_ADD (button);
393    button = katze_property_proxy (settings, "javascript-can-open-windows-automatically", NULL);
394    gtk_button_set_label (GTK_BUTTON (button), _("Allow scripts to open popups"));
395    gtk_widget_set_tooltip_text (button, _("Whether scripts are allowed to open popup windows automatically"));
396    SPANNED_ADD (button);
397    if (katze_widget_has_touchscreen_mode (parent ?
398        GTK_WIDGET (parent) : GTK_WIDGET (preferences)))
399    {
400        button = katze_property_proxy (settings, "kinetic-scrolling", NULL);
401        gtk_button_set_label (GTK_BUTTON (button), _("Kinetic scrolling"));
402        gtk_widget_set_tooltip_text (button, _("Whether scrolling should kinetically move according to speed"));
403    }
404    else
405    {
406        button = katze_property_proxy (settings, "middle-click-opens-selection", NULL);
407        gtk_button_set_label (GTK_BUTTON (button), _("Middle click opens Selection"));
408        gtk_widget_set_tooltip_text (button, _("Load an address from the selection via middle click"));
409    }
410    INDENTED_ADD (button);
411    if (katze_object_has_property (settings, "enable-webgl"))
412    {
413        button = katze_property_proxy (settings, "enable-webgl", NULL);
414        gtk_button_set_label (GTK_BUTTON (button), _("Enable WebGL support"));
415        SPANNED_ADD (button);
416    }
417    #ifndef G_OS_WIN32
418    button = katze_property_proxy (settings, "flash-window-on-new-bg-tabs", NULL);
419    gtk_button_set_label (GTK_BUTTON (button), _("Flash window on background tabs"));
420    INDENTED_ADD (button);
421    #endif
422
423    FRAME_NEW (NULL);
424    button = katze_property_label (settings, "preferred-languages");
425    INDENTED_ADD (button);
426    entry = katze_property_proxy (settings, "preferred-languages", "languages");
427    SPANNED_ADD (entry);
428    label = gtk_label_new (_("Save downloaded files to:"));
429    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
430    INDENTED_ADD (label);
431    button = katze_property_proxy (settings, "download-folder", "folder");
432    SPANNED_ADD (button);
433
434    /* Page "Interface" */
435    PAGE_NEW (GTK_STOCK_CONVERT, _("Browsing"));
436    #if !HAVE_HILDON
437    if (!g_getenv ("DESKTOP_SESSION"))
438    {
439        FRAME_NEW (NULL);
440        INDENTED_ADD (katze_property_label (settings, "toolbar-style"));
441        button = katze_property_proxy (settings, "toolbar-style", NULL);
442        SPANNED_ADD (button);
443    }
444    #endif
445    FRAME_NEW (NULL);
446    label = katze_property_label (settings, "open-new-pages-in");
447    INDENTED_ADD (label);
448    button = katze_property_proxy (settings, "open-new-pages-in", NULL);
449    SPANNED_ADD (button);
450    button = katze_property_proxy (settings, "close-buttons-on-tabs", NULL);
451    gtk_button_set_label (GTK_BUTTON (button), _("Close Buttons on Tabs"));
452    INDENTED_ADD (button);
453    #ifndef HAVE_GRANITE
454    button = katze_property_proxy (settings, "always-show-tabbar", NULL);
455    gtk_button_set_label (GTK_BUTTON (button), _("Always Show Tabbar"));
456    SPANNED_ADD (button);
457    #endif
458    button = katze_property_proxy (settings, "open-tabs-next-to-current", NULL);
459    gtk_button_set_label (GTK_BUTTON (button), _("Open Tabs next to Current"));
460    gtk_widget_set_tooltip_text (button, _("Whether to open new tabs next to the current tab or after the last one"));
461    INDENTED_ADD (button);
462    button = katze_property_proxy (settings, "open-tabs-in-the-background", NULL);
463    gtk_button_set_label (GTK_BUTTON (button), _("Open tabs in the background"));
464    SPANNED_ADD (button);
465
466    INDENTED_ADD (gtk_label_new (NULL));
467    label = gtk_label_new (_("Text Editor"));
468    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
469    INDENTED_ADD (label);
470    entry = katze_property_proxy (settings, "text-editor", "application-text/plain");
471    SPANNED_ADD (entry);
472    label = gtk_label_new (_("News Aggregator"));
473    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
474    INDENTED_ADD (label);
475    entry = katze_property_proxy (settings, "news-aggregator", "application-News");
476    SPANNED_ADD (entry);
477
478    /* Page "Network" */
479    PAGE_NEW (GTK_STOCK_NETWORK, _("Network"));
480    FRAME_NEW (NULL);
481    label = gtk_label_new (_("Proxy server"));
482    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
483    INDENTED_ADD (label);
484    button = katze_property_proxy (settings, "proxy-type", NULL);
485    SPANNED_ADD (button);
486    label = gtk_label_new (_("Hostname"));
487    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
488    INDENTED_ADD (label);
489    entry = katze_property_proxy (settings, "http-proxy", "address");
490    SPANNED_ADD (entry);
491    g_signal_connect (settings, "notify::proxy-type",
492        G_CALLBACK (midori_preferences_notify_proxy_type_cb), entry);
493    midori_preferences_notify_proxy_type_cb (settings, NULL, entry);
494    label = gtk_label_new (_("Port"));
495    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
496    INDENTED_ADD (label);
497    entry = katze_property_proxy (settings, "http-proxy-port", NULL);
498    SPANNED_ADD (entry);
499    g_signal_connect (settings, "notify::proxy-type",
500        G_CALLBACK (midori_preferences_notify_proxy_type_cb), entry);
501    midori_preferences_notify_proxy_type_cb (settings, NULL, entry);
502    #if WEBKIT_CHECK_VERSION (1, 3, 11)
503    if (soup_session_get_feature (webkit_get_default_session (), SOUP_TYPE_CACHE))
504    {
505        label = gtk_label_new (_("Web Cache"));
506        gtk_widget_set_tooltip_text (label, _("The maximum size of cached pages on disk"));
507        INDENTED_ADD (label);
508        button = katze_property_proxy (settings, "maximum-cache-size", NULL);
509        gtk_widget_set_tooltip_text (button, _("The maximum size of cached pages on disk"));
510        SPANNED_ADD (button);
511        label = gtk_label_new (_("MB"));
512        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
513        SPANNED_ADD (label);
514    }
515    #endif
516    label = katze_property_label (settings, "identify-as");
517    INDENTED_ADD (label);
518    button = katze_property_proxy (settings, "identify-as", "custom-user-agent");
519    SPANNED_ADD (button);
520}