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.
This commit is contained in:
Christian Dywan 2008-01-23 04:26:13 +01:00
parent 22b277d94b
commit b2c0363cb4
6 changed files with 57 additions and 47 deletions

View file

@ -1703,16 +1703,6 @@ CBrowser* browser_new(CBrowser* oldBrowser)
DOC_CONNECT ("hovering-over-link" , on_webView_link_hover) DOC_CONNECT ("hovering-over-link" , on_webView_link_hover)
DOC_CONNECT ("console-message" , on_webView_console_message) 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 ("button-press-event" , on_webView_button_press)
DOC_CONNECT ("popup-menu" , on_webView_popup); DOC_CONNECT ("popup-menu" , on_webView_popup);
DOC_CONNECT ("scroll-event" , on_webView_scroll); DOC_CONNECT ("scroll-event" , on_webView_scroll);
@ -1720,6 +1710,8 @@ CBrowser* browser_new(CBrowser* oldBrowser)
DOC_CONNECT ("destroy" , on_webView_destroy) DOC_CONNECT ("destroy" , on_webView_destroy)
#undef DOC_CONNECT #undef DOC_CONNECT
webkit_web_view_set_settings(WEBKIT_WEB_VIEW(browser->webView), webSettings);
// Eventually pack and display everything // Eventually pack and display everything
sokoke_widget_set_visible(browser->navibar, config->toolbarNavigation); sokoke_widget_set_visible(browser->navibar, config->toolbarNavigation);
sokoke_widget_set_visible(browser->newTab, config->toolbarNewTab); sokoke_widget_set_visible(browser->newTab, config->toolbarNewTab);

View file

@ -73,10 +73,12 @@ gboolean config_from_file(CConfig* config, const gchar* filename, GError** error
#define GET_STR(var, key, default) \ #define GET_STR(var, key, default) \
var = sokoke_key_file_get_string_default( \ var = sokoke_key_file_get_string_default( \
keyFile, "content", key, default, NULL) keyFile, "content", key, default, NULL)
GET_INT(config->loadImagesAutomatically, "LoadImagesAutomatically", TRUE); GET_INT(config->autoLoadImages, "AutoLoadImages", TRUE);
GET_INT(config->shrinkImagesToFit, "ShrinkImagesTooFit", TRUE); GET_INT(config->autoShrinkImages, "AutoShrinkImages", TRUE);
GET_INT(config->printBackgrounds, "PrintBackgrounds", FALSE);
GET_INT(config->resizableTextAreas, "ResizableTextAreas", 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); GET_INT(config->enablePlugins, "EnablePlugins", TRUE);
#undef GET_INT #undef GET_INT
#undef GET_STR #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", "OpenTabsInTheBackground", config->openTabsInTheBackground);
g_key_file_set_integer(keyFile, "browser", "OpenPopupsInTabs", config->openPopupsInTabs); 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", "AutoLoadImages", config->autoLoadImages);
g_key_file_set_integer(keyFile, "content", "ShrinkImagesToFit", config->shrinkImagesToFit); 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", "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, "content", "EnablePlugins", config->enablePlugins);
g_key_file_set_integer(keyFile, "session", "RememberWinSize", config->rememberWinSize); g_key_file_set_integer(keyFile, "session", "RememberWinSize", config->rememberWinSize);

View file

@ -37,10 +37,13 @@ typedef struct _CConfig
gboolean openTabsInTheBackground; gboolean openTabsInTheBackground;
gboolean openPopupsInTabs; gboolean openPopupsInTabs;
gboolean loadImagesAutomatically;
gboolean shrinkImagesToFit; gboolean autoLoadImages;
gboolean autoShrinkImages;
gboolean printBackgrounds;
gboolean resizableTextAreas; gboolean resizableTextAreas;
gboolean enableJavaScript; gchar* userStylesheetUri;
gboolean enableScripts;
gboolean enablePlugins; gboolean enablePlugins;
gboolean rememberWinSize; // Restore window size upon startup? gboolean rememberWinSize; // Restore window size upon startup?

View file

@ -16,12 +16,14 @@
#include "../katze/katze.h" #include "../katze/katze.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <webkit.h>
// -- globals // -- globals
CConfig* config; CConfig* config;
GList* searchEngines; // Items of type 'SearchEngine' GList* searchEngines; // Items of type 'SearchEngine'
GList* browsers; // Items of type 'CBrowser' GList* browsers; // Items of type 'CBrowser'
WebKitWebSettings* webSettings;
GtkAccelGroup* accel_group; GtkAccelGroup* accel_group;
KatzeXbelItem* bookmarks; KatzeXbelItem* bookmarks;
KatzeXbelItem* session; KatzeXbelItem* session;

View file

@ -244,6 +244,17 @@ int main(int argc, char** argv)
stock_items_init(); stock_items_init();
browsers = NULL; 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(); session = katze_xbel_folder_new();
CBrowser* browser = NULL; CBrowser* browser = NULL;
guint n = katze_xbel_folder_get_n_items(_session); guint n = katze_xbel_folder_get_n_items(_session);

View 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) static void on_prefs_loadImagesAutomatically_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->loadImagesAutomatically = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->autoLoadImages = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
// FIXME: Apply the change to all open webViews g_object_set(webSettings, "auto-load-images", config->autoLoadImages, NULL);
g_object_set(get_nth_webView(-1, prefs->browser)
, "loads-images-automatically", config->loadImagesAutomatically, NULL);
} }
static void on_prefs_shrinkImagesToFit_toggled(GtkWidget* widget, CPrefs* prefs) static void on_prefs_shrinkImagesToFit_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->shrinkImagesToFit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->autoShrinkImages = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
// FIXME: Apply the change to all open webViews g_object_set(webSettings, "auto-shrink-images", config->autoShrinkImages, NULL);
g_object_set(get_nth_webView(-1, prefs->browser) }
, "shrinks-standalone-images-to-fit", config->shrinkImagesToFit, 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) static void on_prefs_resizableTextAreas_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->resizableTextAreas = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->resizableTextAreas = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
// FIXME: Apply the change to all open webViews g_object_set(webSettings, "resizable-text-areas", config->resizableTextAreas, NULL);
g_object_set(get_nth_webView(-1, prefs->browser)
, "text-areas-are-resizable", config->resizableTextAreas, NULL);
} }
static void on_prefs_enableJavaScript_toggled(GtkWidget* widget, CPrefs* prefs) static void on_prefs_enableJavaScript_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->enableJavaScript = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->enableScripts = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
// FIXME: Apply the change to all open webViews g_object_set(webSettings, "enable-scripts", config->enableScripts, NULL);
g_object_set(get_nth_webView(-1, prefs->browser)
, "java-script-enabled", config->enableJavaScript, NULL);
} }
static void on_prefs_enablePlugins_toggled(GtkWidget* widget, CPrefs* prefs) static void on_prefs_enablePlugins_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->enablePlugins = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->enablePlugins = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
// FIXME: Apply the change to all open webViews g_object_set(webSettings, "enable-plugins", config->enablePlugins, NULL);
g_object_set(get_nth_webView(-1, prefs->browser)
, "plugins-enabled", config->enablePlugins, NULL);
} }
static void on_prefs_toolbarstyle_changed(GtkWidget* widget, CPrefs* prefs) static void on_prefs_toolbarstyle_changed(GtkWidget* widget, CPrefs* prefs)
@ -435,33 +431,35 @@ GtkWidget* prefs_preferences_dialog_new(CBrowser* browser)
FRAME_NEW("Features"); FRAME_NEW("Features");
TABLE_NEW(3, 2); TABLE_NEW(3, 2);
checkbutton = gtk_check_button_new_with_mnemonic("Load _images automatically"); 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_signal_connect(checkbutton, "toggled"
, G_CALLBACK(on_prefs_loadImagesAutomatically_toggled), prefs); , G_CALLBACK(on_prefs_loadImagesAutomatically_toggled), prefs);
SPANNED_ADD(checkbutton, 0, 1, 0, 1); SPANNED_ADD(checkbutton, 0, 1, 0, 1);
checkbutton = gtk_check_button_new_with_mnemonic("_Shrink images to fit"); 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_signal_connect(checkbutton, "toggled"
, G_CALLBACK(on_prefs_shrinkImagesToFit_toggled), prefs); , G_CALLBACK(on_prefs_shrinkImagesToFit_toggled), prefs);
SPANNED_ADD(checkbutton, 1, 2, 0, 1); 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"); checkbutton = gtk_check_button_new_with_mnemonic("_Resizable textareas");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->resizableTextAreas); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->resizableTextAreas);
g_signal_connect(checkbutton, "toggled" g_signal_connect(checkbutton, "toggled"
, G_CALLBACK(on_prefs_resizableTextAreas_toggled), prefs); , G_CALLBACK(on_prefs_resizableTextAreas_toggled), prefs);
SPANNED_ADD(checkbutton, 0, 1, 1, 2); SPANNED_ADD(checkbutton, 1, 2, 1, 2);
checkbutton = gtk_check_button_new_with_mnemonic("Enable java_script"); checkbutton = gtk_check_button_new_with_mnemonic("Enable _scripts");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->enableJavaScript); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->enableScripts);
g_signal_connect(checkbutton, "toggled" g_signal_connect(checkbutton, "toggled"
, G_CALLBACK(on_prefs_enableJavaScript_toggled), prefs); , 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"); checkbutton = gtk_check_button_new_with_mnemonic("Enable _plugins");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->enablePlugins); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->enablePlugins);
g_signal_connect(checkbutton, "toggled" g_signal_connect(checkbutton, "toggled"
, G_CALLBACK(on_prefs_enablePlugins_toggled), prefs); , G_CALLBACK(on_prefs_enablePlugins_toggled), prefs);
SPANNED_ADD(checkbutton, 0, 1, 2, 3); SPANNED_ADD(checkbutton, 1, 2, 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);
// Page "Interface" // Page "Interface"
PAGE_NEW("Interface"); PAGE_NEW("Interface");