From 6477032a6d2d73aec2485220f108a9246d60513c Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 23 Jan 2008 05:27:54 +0100 Subject: [PATCH] Add a preference to choose a user stylesheet. --- src/conf.c | 2 ++ src/conf.h | 1 + src/main.c | 2 +- src/prefs.c | 33 ++++++++++++++++++++++++++++++--- src/prefs.h | 1 + 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/conf.c b/src/conf.c index 53a14dfa..9a1e9ae8 100644 --- a/src/conf.c +++ b/src/conf.c @@ -77,6 +77,7 @@ gboolean config_from_file(CConfig* config, const gchar* filename, GError** error GET_INT(config->autoShrinkImages, "AutoShrinkImages", TRUE); GET_INT(config->printBackgrounds, "PrintBackgrounds", FALSE); GET_INT(config->resizableTextAreas, "ResizableTextAreas", FALSE); + GET_INT(config->userStylesheet, "UserStylesheet", FALSE); GET_STR(config->userStylesheetUri, "UserStylesheetUri", ""); GET_INT(config->enableScripts, "EnableScripts", TRUE); GET_INT(config->enablePlugins, "EnablePlugins", TRUE); @@ -147,6 +148,7 @@ gboolean config_to_file(CConfig* config, const gchar* filename, GError** error) 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", "UserStylesheet", config->userStylesheet); 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); diff --git a/src/conf.h b/src/conf.h index a36c6929..0cf12d6b 100644 --- a/src/conf.h +++ b/src/conf.h @@ -42,6 +42,7 @@ typedef struct _CConfig gboolean autoShrinkImages; gboolean printBackgrounds; gboolean resizableTextAreas; + gboolean userStylesheet; gchar* userStylesheetUri; gboolean enableScripts; gboolean enablePlugins; diff --git a/src/main.c b/src/main.c index 97951a30..6c100df0 100755 --- a/src/main.c +++ b/src/main.c @@ -250,7 +250,7 @@ int main(int argc, char** argv) , "auto-shrink-images" , config->autoShrinkImages , "print-backgrounds" , config->printBackgrounds , "resizable-text-areas", config->resizableTextAreas - , "user-stylesheet-uri" , config->userStylesheetUri + , "user-stylesheet-uri" , config->userStylesheet ? config->userStylesheetUri : NULL , "enable-scripts" , config->enableScripts , "enable-plugins" , config->enablePlugins , NULL); diff --git a/src/prefs.c b/src/prefs.c index eaf1d37b..f828ff9f 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -80,6 +80,20 @@ static void on_prefs_enablePlugins_toggled(GtkWidget* widget, CPrefs* prefs) g_object_set(webSettings, "enable-plugins", config->enablePlugins, NULL); } +static void on_prefs_userStylesheet_toggled(GtkWidget* widget, CPrefs* prefs) +{ + config->userStylesheet = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + gtk_widget_set_sensitive(prefs->userStylesheetUri, config->userStylesheet); + const gchar* uri = config->userStylesheet ? config->userStylesheetUri : ""; + g_object_set(webSettings, "user-stylesheet-uri", uri, NULL); +} + +static void on_prefs_userStylesheetUri_file_set(GtkWidget* widget, CPrefs* prefs) +{ + katze_assign(config->userStylesheetUri, g_strdup(gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(widget)))); + g_object_set(webSettings, "user-stylesheet-uri", config->userStylesheetUri, NULL); +} + static void on_prefs_toolbarstyle_changed(GtkWidget* widget, CPrefs* prefs) { config->toolbarStyle = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); @@ -422,15 +436,15 @@ GtkWidget* prefs_preferences_dialog_new(CBrowser* browser) g_signal_connect(checkbutton, "toggled" , G_CALLBACK(on_prefs_openTabsInTheBackground_toggled), prefs); SPANNED_ADD(checkbutton, 0, 2, 1, 2); - checkbutton = gtk_check_button_new_with_mnemonic("Open _popups in tabs"); + checkbutton = gtk_check_button_new_with_mnemonic("Open popups in _tabs"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->openPopupsInTabs); g_signal_connect(checkbutton, "toggled" , G_CALLBACK(on_prefs_openPopupsInTabs_toggled), prefs); gtk_widget_set_sensitive(checkbutton, FALSE); //... SPANNED_ADD(checkbutton, 0, 2, 2, 3); FRAME_NEW("Features"); - TABLE_NEW(3, 2); - checkbutton = gtk_check_button_new_with_mnemonic("Load _images automatically"); + TABLE_NEW(4, 2); + checkbutton = gtk_check_button_new_with_mnemonic("Load _images"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->autoLoadImages); g_signal_connect(checkbutton, "toggled" , G_CALLBACK(on_prefs_loadImagesAutomatically_toggled), prefs); @@ -460,6 +474,19 @@ GtkWidget* prefs_preferences_dialog_new(CBrowser* browser) g_signal_connect(checkbutton, "toggled" , G_CALLBACK(on_prefs_enablePlugins_toggled), prefs); SPANNED_ADD(checkbutton, 1, 2, 2, 3); + checkbutton = gtk_check_button_new_with_mnemonic("_User Stylesheet"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), config->userStylesheet); + g_signal_connect(checkbutton, "toggled" + , G_CALLBACK(on_prefs_userStylesheet_toggled), prefs); + INDENTED_ADD(checkbutton, 0, 1, 3, 4); + filebutton = gtk_file_chooser_button_new( + "Choose user stylesheet", GTK_FILE_CHOOSER_ACTION_OPEN); + prefs->userStylesheetUri = filebutton; + gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(filebutton), config->userStylesheetUri); + g_signal_connect(filebutton, "file-set" + , G_CALLBACK(on_prefs_userStylesheetUri_file_set), prefs); + gtk_widget_set_sensitive(filebutton, config->userStylesheet); + FILLED_ADD(filebutton, 1, 2, 3, 4); // Page "Interface" PAGE_NEW("Interface"); diff --git a/src/prefs.h b/src/prefs.h index 7a452742..7576095e 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -22,6 +22,7 @@ typedef struct { CBrowser* browser; //GtkWidget* window; + GtkWidget* userStylesheetUri; GtkWidget* treeview; GtkWidget* combobox; GtkWidget* add;