Set CSS file from preferences dialog
authorP. F. Chimento <philip.chimento@gmail.com>
Sun, 13 Mar 2011 19:36:56 +0000 (20:36 +0100)
committerP. F. Chimento <philip.chimento@gmail.com>
Sun, 13 Mar 2011 19:36:56 +0000 (20:36 +0100)
Now you can set a custom CSS file from the preferences dialog and it
will be remembered across runs of the program.

player/chimara.ui
player/org.chimara-if.gschema.xml
player/preferences.c

index d8c2ea8b32df349d7690903103d1c3b189df8133..0a80104cb648c4494c3c7b95f801c4a6c884c67d 100644 (file)
@@ -394,6 +394,7 @@ Philip Chimento</property>
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="title" translatable="yes">Select A CSS File</property>
+                        <signal name="file-set" handler="on_css_filechooser_file_set" swapped="no"/>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
index 6c0e4d17520a2a920e06700b4e717db4c63f2f61..83c521ef5c448166f50f235157f31c70f9d9388a 100644 (file)
       </description>
     </key>
 
+    <key name="css-file" type="ms">
+      <default>nothing</default>
+      <summary>CSS style file</summary>
+      <description>
+        The CSS file containing the current theme for the text in the games.
+      </description>
+    </key>
+
     <key name="resource-path" type="ms">
       <default>nothing</default>
       <summary>Resource path</summary>
index ad77ee6b8b63b2810d21569d6159c3457c823208..88e88ff1aade52a8b6664c3ae78856079a14128e 100644 (file)
@@ -168,12 +168,24 @@ preferences_create(ChimaraGlk *glk)
        GObject *flep = G_OBJECT( load_object("flep") );
        g_settings_bind(prefs_settings, "flep", flep, "active", G_SETTINGS_BIND_DEFAULT);
        GtkFileChooser *blorb_chooser = GTK_FILE_CHOOSER( load_object("blorb_file_chooser") );
+       GtkFileChooser *css_chooser = GTK_FILE_CHOOSER( load_object("css-filechooser") );
        char *filename;
        g_settings_get(prefs_settings, "resource-path", "ms", &filename);
        if(filename) {
                gtk_file_chooser_set_filename(blorb_chooser, filename);
                g_free(filename);
        }
+       g_settings_get(prefs_settings, "css-file", "ms", &filename);
+       if(filename) {
+               if(!chimara_glk_set_css_from_file(glk, filename, NULL)) {
+                       /* If the setting didn't point to a CSS file, fail silently and
+                        null the setting */
+                       g_settings_set(prefs_settings, "css-file", "ms", NULL);
+               } else {
+                       gtk_file_chooser_set_filename(css_chooser, filename);
+               }
+               g_free(filename);
+       }
 
        /* Populate the list of available interpreters */
        GtkListStore *interp_list = GTK_LIST_STORE( load_object("available_interpreters") );
@@ -324,6 +336,21 @@ on_font_set(GtkFontButton *button, ChimaraGlk *glk)
        chimara_glk_update_style(glk);
 }
 
+void
+on_css_filechooser_file_set(GtkFileChooserButton *button, ChimaraGlk *glk)
+{
+       GError *error = NULL;
+       extern GSettings *prefs_settings;
+       char *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(button) );
+       if(!chimara_glk_set_css_from_file(glk, filename, &error)) {
+               error_dialog(NULL, error, "There was a problem reading the CSS file: ");
+               g_settings_set(prefs_settings, "css-file", "ms", NULL);
+       } else {
+               g_settings_set(prefs_settings, "css-file", "ms", filename);
+       }
+       g_free(filename);
+}
+
 void
 on_resource_file_set(GtkFileChooserButton *button, ChimaraGlk *glk)
 {