From b2c0363cb4c254602ee5438d3b6582c01c061116 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 23 Jan 2008 04:26:13 +0100 Subject: [PATCH] Implement a few preferences with new settings API in WebKit Allow changing a few preferences that WebKit now has API for and clear the way for more to come. --- src/browser.c | 12 ++---------- src/conf.c | 16 +++++++++------ src/conf.h | 9 ++++++--- src/global.h | 2 ++ src/main.c | 11 +++++++++++ src/prefs.c | 54 +++++++++++++++++++++++++-------------------------- 6 files changed, 57 insertions(+), 47 deletions(-) diff --git a/src/browser.c b/src/browser.c index e121c3fc..1f3eb838 100644 --- a/src/browser.c +++ b/src/browser.c @@ -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); diff --git a/src/conf.c b/src/conf.c index 8dccad03..53a14dfa 100644 --- a/src/conf.c +++ b/src/conf.c @@ -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); diff --git a/src/conf.h b/src/conf.h index b43b0311..a36c6929 100644 --- a/src/conf.h +++ b/src/conf.h @@ -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? diff --git a/src/global.h b/src/global.h index 19139f3e..52f283e6 100644 --- a/src/global.h +++ b/src/global.h @@ -16,12 +16,14 @@ #include "../katze/katze.h" #include +#include // -- globals CConfig* config; GList* searchEngines; // Items of type 'SearchEngine' GList* browsers; // Items of type 'CBrowser' +WebKitWebSettings* webSettings; GtkAccelGroup* accel_group; KatzeXbelItem* bookmarks; KatzeXbelItem* session; diff --git a/src/main.c b/src/main.c index fb79eb97..97951a30 100755 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/prefs.c b/src/prefs.c index d77a90fc..eaf1d37b 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -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");