]> spindle.queued.net Git - midori/commitdiff
Implement a few preferences with new settings API in WebKit
authorChristian Dywan <christian@twotoasts.de>
Wed, 23 Jan 2008 03:26:13 +0000 (04:26 +0100)
committerChristian Dywan <christian@twotoasts.de>
Wed, 23 Jan 2008 03:28:50 +0000 (04:28 +0100)
Allow changing a few preferences that WebKit now has API for
and clear the way for more to come.

src/browser.c
src/conf.c
src/conf.h
src/global.h
src/main.c
src/prefs.c

index e121c3fc48a8a169eb49472438fb50c269d50bcd..1f3eb83896a731bee9198afaa666eba032ecf74e 100644 (file)
@@ -1703,16 +1703,6 @@ CBrowser* browser_new(CBrowser* oldBrowser)
     DOC_CONNECT  ("hovering-over-link"          , on_webView_link_hover)
     DOC_CONNECT  ("console-message"             , on_webView_console_message)
 
-    // For now we check for "plugins-enabled", in case this build has no properties
-    if(g_object_class_find_property(G_OBJECT_GET_CLASS(browser->webView), "plugins-enabled"))
-        g_object_set(G_OBJECT(browser->webView)
-         , "loads-images-automatically"      , config->loadImagesAutomatically
-         , "shrinks-standalone-images-to-fit", config->shrinkImagesToFit
-         , "text-areas-are-resizable"        , config->resizableTextAreas
-         , "java-script-enabled"             , config->enableJavaScript
-         , "plugins-enabled"                 , config->enablePlugins
-         , NULL);
-
     DOC_CONNECT  ("button-press-event"          , on_webView_button_press)
     DOC_CONNECT  ("popup-menu"                  , on_webView_popup);
     DOC_CONNECT  ("scroll-event"                , on_webView_scroll);
@@ -1720,6 +1710,8 @@ CBrowser* browser_new(CBrowser* oldBrowser)
     DOC_CONNECT  ("destroy"                     , on_webView_destroy)
     #undef DOC_CONNECT
 
+    webkit_web_view_set_settings(WEBKIT_WEB_VIEW(browser->webView), webSettings);
+
     // Eventually pack and display everything
     sokoke_widget_set_visible(browser->navibar, config->toolbarNavigation);
     sokoke_widget_set_visible(browser->newTab, config->toolbarNewTab);
index 8dccad03cefab9de914f9b75499e6361c5704286..53a14dfa60f86f563acef2fa84829c401c023bdf 100644 (file)
@@ -73,10 +73,12 @@ gboolean config_from_file(CConfig* config, const gchar* filename, GError** error
     #define GET_STR(var, key, default) \
      var = sokoke_key_file_get_string_default( \
      keyFile, "content", key, default, NULL)
-    GET_INT(config->loadImagesAutomatically, "LoadImagesAutomatically", TRUE);
-    GET_INT(config->shrinkImagesToFit, "ShrinkImagesTooFit", TRUE);
+    GET_INT(config->autoLoadImages, "AutoLoadImages", TRUE);
+    GET_INT(config->autoShrinkImages, "AutoShrinkImages", TRUE);
+    GET_INT(config->printBackgrounds, "PrintBackgrounds", FALSE);
     GET_INT(config->resizableTextAreas, "ResizableTextAreas", FALSE);
-    GET_INT(config->enableJavaScript, "EnableJavaScript", TRUE);
+    GET_STR(config->userStylesheetUri, "UserStylesheetUri", "");
+    GET_INT(config->enableScripts, "EnableScripts", TRUE);
     GET_INT(config->enablePlugins, "EnablePlugins", TRUE);
     #undef GET_INT
     #undef GET_STR
@@ -141,10 +143,12 @@ gboolean config_to_file(CConfig* config, const gchar* filename, GError** error)
     g_key_file_set_integer(keyFile, "browser", "OpenTabsInTheBackground", config->openTabsInTheBackground);
     g_key_file_set_integer(keyFile, "browser", "OpenPopupsInTabs", config->openPopupsInTabs);
 
-    g_key_file_set_integer(keyFile, "content", "LoadImagesAutomatically", config->loadImagesAutomatically);
-    g_key_file_set_integer(keyFile, "content", "ShrinkImagesToFit", config->shrinkImagesToFit);
+    g_key_file_set_integer(keyFile, "content", "AutoLoadImages", config->autoLoadImages);
+    g_key_file_set_integer(keyFile, "content", "AutoShrinkImages", config->autoShrinkImages);
+    g_key_file_set_integer(keyFile, "content", "PrintBackgrounds", config->printBackgrounds);
     g_key_file_set_integer(keyFile, "content", "ResizableTextAreas", config->resizableTextAreas);
-    g_key_file_set_integer(keyFile, "content", "EnableJavaScript", config->enableJavaScript);
+    g_key_file_set_string (keyFile, "content", "UserStylesheetUri", config->userStylesheetUri);
+    g_key_file_set_integer(keyFile, "content", "EnableScripts", config->enableScripts);
     g_key_file_set_integer(keyFile, "content", "EnablePlugins", config->enablePlugins);
 
     g_key_file_set_integer(keyFile, "session", "RememberWinSize", config->rememberWinSize);
index b43b03119526534762321aade738043008e20887..a36c6929347484a09dab4879d1b5e1d27253fd4d 100644 (file)
@@ -37,10 +37,13 @@ typedef struct _CConfig
     gboolean openTabsInTheBackground;
     gboolean openPopupsInTabs;
 
-    gboolean loadImagesAutomatically;
-    gboolean shrinkImagesToFit;
+    
+    gboolean autoLoadImages;
+    gboolean autoShrinkImages;
+    gboolean printBackgrounds;
     gboolean resizableTextAreas;
-    gboolean enableJavaScript;
+    gchar* userStylesheetUri;
+    gboolean enableScripts;
     gboolean enablePlugins;
 
     gboolean rememberWinSize; // Restore window size upon startup?
index 19139f3e674b949233067c235613ffd3454e0b2e..52f283e6703e609129d3ebdc1cb876fd66c0a507 100644 (file)
 #include "../katze/katze.h"
 
 #include <gtk/gtk.h>
+#include <webkit.h>
 
 // -- globals
 
 CConfig* config;
 GList* searchEngines; // Items of type 'SearchEngine'
 GList* browsers; // Items of type 'CBrowser'
+WebKitWebSettings* webSettings;
 GtkAccelGroup* accel_group;
 KatzeXbelItem* bookmarks;
 KatzeXbelItem* session;
index fb79eb97e118c6c6ebfa90776e1161ba5c68fb88..97951a30e0bdf139d364b1adc71efa73c349bf57 100755 (executable)
@@ -244,6 +244,17 @@ int main(int argc, char** argv)
     stock_items_init();
     browsers = NULL;
 
+    webSettings = webkit_web_settings_new();
+    g_object_set(webSettings
+     , "auto-load-images"    , config->autoLoadImages
+     , "auto-shrink-images"  , config->autoShrinkImages
+     , "print-backgrounds"   , config->printBackgrounds
+     , "resizable-text-areas", config->resizableTextAreas
+     , "user-stylesheet-uri" , config->userStylesheetUri
+     , "enable-scripts"      , config->enableScripts
+     , "enable-plugins"      , config->enablePlugins
+     , NULL);
+
     session = katze_xbel_folder_new();
     CBrowser* browser = NULL;
     guint n = katze_xbel_folder_get_n_items(_session);
index d77a90fcd3be1018c3d4a3f99b7362fa1d54fce6..eaf1d37b972040c7dae06ac40cd434d488a86d1b 100644 (file)
@@ -46,42 +46,38 @@ static void on_prefs_openPopupsInTabs_toggled(GtkWidget* widget, CPrefs* prefs)
 
 static void on_prefs_loadImagesAutomatically_toggled(GtkWidget* widget, CPrefs* prefs)
 {
-    config->loadImagesAutomatically = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-    // FIXME: Apply the change to all open webViews
-    g_object_set(get_nth_webView(-1, prefs->browser)
-     , "loads-images-automatically", config->loadImagesAutomatically, NULL);
+    config->autoLoadImages = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+    g_object_set(webSettings, "auto-load-images", config->autoLoadImages, NULL);
 }
 
 static void on_prefs_shrinkImagesToFit_toggled(GtkWidget* widget, CPrefs* prefs)
 {
-    config->shrinkImagesToFit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-    // FIXME: Apply the change to all open webViews
-    g_object_set(get_nth_webView(-1, prefs->browser)
-     , "shrinks-standalone-images-to-fit", config->shrinkImagesToFit, NULL);
+    config->autoShrinkImages = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+    g_object_set(webSettings, "auto-shrink-images", config->autoShrinkImages, NULL);
+}
+
+static void on_prefs_printBackgrounds_toggled(GtkWidget* widget, CPrefs* prefs)
+{
+    config->printBackgrounds = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+    g_object_set(webSettings, "print-backgrounds", config->printBackgrounds, NULL);
 }
 
 static void on_prefs_resizableTextAreas_toggled(GtkWidget* widget, CPrefs* prefs)
 {
     config->resizableTextAreas = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-    // FIXME: Apply the change to all open webViews
-    g_object_set(get_nth_webView(-1, prefs->browser)
-     , "text-areas-are-resizable", config->resizableTextAreas, NULL);
+    g_object_set(webSettings, "resizable-text-areas", config->resizableTextAreas, NULL);
 }
 
 static void on_prefs_enableJavaScript_toggled(GtkWidget* widget, CPrefs* prefs)
 {
-    config->enableJavaScript = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-    // FIXME: Apply the change to all open webViews
-    g_object_set(get_nth_webView(-1, prefs->browser)
-     , "java-script-enabled", config->enableJavaScript, NULL);
+    config->enableScripts = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+    g_object_set(webSettings, "enable-scripts", config->enableScripts, NULL);
 }
 
 static void on_prefs_enablePlugins_toggled(GtkWidget* widget, CPrefs* prefs)
 {
     config->enablePlugins = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-    // FIXME: Apply the change to all open webViews
-    g_object_set(get_nth_webView(-1, prefs->browser)
-     , "plugins-enabled", config->enablePlugins, NULL);
+    g_object_set(webSettings, "enable-plugins", config->enablePlugins, NULL);
 }
 
 static void on_prefs_toolbarstyle_changed(GtkWidget* widget, CPrefs* prefs)
@@ -435,33 +431,35 @@ GtkWidget* prefs_preferences_dialog_new(CBrowser* browser)
     FRAME_NEW("Features");
     TABLE_NEW(3, 2);
     checkbutton = gtk_check_button_new_with_mnemonic("Load _images automatically");
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->loadImagesAutomatically);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->autoLoadImages);
     g_signal_connect(checkbutton, "toggled"
      , G_CALLBACK(on_prefs_loadImagesAutomatically_toggled), prefs);
     SPANNED_ADD(checkbutton, 0, 1, 0, 1);
     checkbutton = gtk_check_button_new_with_mnemonic("_Shrink images to fit");
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->shrinkImagesToFit);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->autoShrinkImages);
     g_signal_connect(checkbutton, "toggled"
      , G_CALLBACK(on_prefs_shrinkImagesToFit_toggled), prefs);
     SPANNED_ADD(checkbutton, 1, 2, 0, 1);
+    checkbutton = gtk_check_button_new_with_mnemonic("Print _backgrounds");
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->printBackgrounds);
+    g_signal_connect(checkbutton, "toggled"
+     , G_CALLBACK(on_prefs_printBackgrounds_toggled), prefs);
+    SPANNED_ADD(checkbutton, 0, 1, 1, 2);
     checkbutton = gtk_check_button_new_with_mnemonic("_Resizable textareas");
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->resizableTextAreas);
     g_signal_connect(checkbutton, "toggled"
      , G_CALLBACK(on_prefs_resizableTextAreas_toggled), prefs);
-    SPANNED_ADD(checkbutton, 0, 1, 1, 2);
-    checkbutton = gtk_check_button_new_with_mnemonic("Enable java_script");
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->enableJavaScript);
+    SPANNED_ADD(checkbutton, 1, 2, 1, 2);
+    checkbutton = gtk_check_button_new_with_mnemonic("Enable _scripts");
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->enableScripts);
     g_signal_connect(checkbutton, "toggled"
      , G_CALLBACK(on_prefs_enableJavaScript_toggled), prefs);
-    SPANNED_ADD(checkbutton, 1, 2, 1, 2);
+    SPANNED_ADD(checkbutton, 0, 1, 2, 3);
     checkbutton = gtk_check_button_new_with_mnemonic("Enable _plugins");
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->enablePlugins);
     g_signal_connect(checkbutton, "toggled"
      , G_CALLBACK(on_prefs_enablePlugins_toggled), prefs);
-    SPANNED_ADD(checkbutton, 0, 1, 2, 3);
-    // For now we check for "plugins-enabled", in case this build has no properties
-    if(!g_object_class_find_property(G_OBJECT_GET_CLASS(browser->webView), "plugins-enabled"))
-        gtk_widget_set_sensitive(frame, FALSE);
+    SPANNED_ADD(checkbutton, 1, 2, 2, 3);
 
     // Page "Interface"
     PAGE_NEW("Interface");