[goffice] Add a button to save an embedded theme



commit 19d2daa0202c8838b7bae0809c7e1225397f43e7
Author: Jean Brefort <jean brefort normalesup org>
Date:   Wed Nov 7 18:19:40 2012 +0100

    Add a button to save an embedded theme

 ChangeLog                                |   11 +++
 docs/reference/goffice-0.10-sections.txt |    1 +
 goffice/graph/gog-graph-prefs.ui         |  117 +++++++++++++++++++-----------
 goffice/graph/gog-graph.c                |   17 ++++-
 goffice/graph/gog-theme.c                |   19 +++++-
 goffice/graph/gog-theme.h                |    1 +
 6 files changed, 118 insertions(+), 48 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 27aea3f..0b1efc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-11-07  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/graph/gog-graph-prefs.ui: add a button to save an embedded
+	theme.
+	* goffice/graph/gog-graph.c (cb_theme_changed), (save_theme_cb),
+	(gog_graph_populate_editor): ditto.
+	* goffice/graph/gog-theme.c (gog_theme_save_to_home_dir): new function,
+	(gog_theme_registry_get_theme_names), (theme_load_from_uri): fix a
+	locale related issue.
+	* goffice/graph/gog-theme.h: ditto.
+
 2012-11-06  Jean Brefort  <jean brefort normalesup org>
 
 	* goffice/app/go-doc.c (go_doc_write), (load_color_map),
diff --git a/docs/reference/goffice-0.10-sections.txt b/docs/reference/goffice-0.10-sections.txt
index 8f49ddb..d6be7b6 100644
--- a/docs/reference/goffice-0.10-sections.txt
+++ b/docs/reference/goffice-0.10-sections.txt
@@ -3413,6 +3413,7 @@ gog_theme_get_name
 gog_theme_get_resource_type
 gog_theme_registry_get_theme_names
 gog_theme_registry_lookup
+gog_theme_save_to_home_dir
 <SUBSECTION Standard>
 GOG_IS_THEME
 GOG_THEME
diff --git a/goffice/graph/gog-graph-prefs.ui b/goffice/graph/gog-graph-prefs.ui
index d4ef3bc..20f1372 100644
--- a/goffice/graph/gog-graph-prefs.ui
+++ b/goffice/graph/gog-graph-prefs.ui
@@ -1,28 +1,30 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <!-- interface-naming-policy toplevel-contextual -->
-  <object class="GtkTable" id="gog_graph_prefs">
+  <object class="GtkGrid" id="gog-graph-prefs">
     <property name="visible">True</property>
+    <property name="can_focus">False</property>
     <property name="border_width">12</property>
-    <property name="n_rows">2</property>
-    <property name="n_columns">2</property>
-    <property name="column_spacing">6</property>
     <property name="row_spacing">6</property>
+    <property name="column_spacing">12</property>
     <child>
       <object class="GtkLabel" id="label51">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="xalign">0</property>
         <property name="label" translatable="yes">Theme:</property>
       </object>
       <packing>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options"></property>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
       </packing>
     </child>
     <child>
       <object class="GtkComboBox" id="theme_combo">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="model">model1</property>
         <child>
           <object class="GtkCellRendererText" id="renderer1"/>
@@ -33,59 +35,86 @@
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="right_attach">2</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options">GTK_FILL</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
       </packing>
     </child>
     <child>
-      <object class="GtkButton" id="force_theme_button">
+      <object class="GtkButton" id="force-theme-button">
+        <property name="use_action_appearance">False</property>
         <property name="visible">True</property>
         <property name="can_focus">True</property>
         <property name="receives_default">True</property>
+        <property name="use_action_appearance">False</property>
         <child>
-          <object class="GtkAlignment" id="alignment1">
+          <object class="GtkGrid" id="grid3">
             <property name="visible">True</property>
-            <property name="xscale">0</property>
-            <property name="yscale">0</property>
+            <property name="can_focus">False</property>
             <child>
-              <object class="GtkBox" id="hbox1">
+              <object class="GtkImage" id="image1">
                 <property name="visible">True</property>
-                <property name="spacing">2</property>
-                <child>
-                  <object class="GtkImage" id="image1">
-                    <property name="visible">True</property>
-                    <property name="stock">gtk-clear</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label52">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Forget user styles</property>
-                    <property name="use_underline">True</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
+                <property name="can_focus">False</property>
+                <property name="stock">gtk-clear</property>
               </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label52">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Forget user styles</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
             </child>
           </object>
         </child>
       </object>
       <packing>
-        <property name="right_attach">2</property>
+        <property name="left_attach">0</property>
         <property name="top_attach">1</property>
-        <property name="bottom_attach">2</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options"></property>
+        <property name="width">2</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <placeholder/>
+    </child>
+    <child>
+      <placeholder/>
+    </child>
+    <child>
+      <placeholder/>
+    </child>
+    <child>
+      <placeholder/>
+    </child>
+    <child>
+      <object class="GtkButton" id="save-theme">
+        <property name="label" translatable="yes">Save</property>
+        <property name="use_action_appearance">False</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="tooltip_text" translatable="yes">Save the theme as a standalone file in the user home directory.</property>
+        <property name="use_action_appearance">False</property>
+      </object>
+      <packing>
+        <property name="left_attach">2</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
       </packing>
     </child>
   </object>
diff --git a/goffice/graph/gog-graph.c b/goffice/graph/gog-graph.c
index 97a2fe6..50516fb 100644
--- a/goffice/graph/gog-graph.c
+++ b/goffice/graph/gog-graph.c
@@ -259,6 +259,7 @@ static void
 cb_theme_changed (GtkComboBox *combo, GogGraph *graph)
 {
 	GtkTreeIter iter;
+	GtkWidget *w = g_object_get_data (G_OBJECT (combo), "save-button");
 
 	if (gtk_combo_box_get_active_iter (combo, &iter)) {
 		GtkTreeModel *model = GTK_TREE_MODEL (gtk_combo_box_get_model (GTK_COMBO_BOX (combo)));
@@ -269,6 +270,7 @@ cb_theme_changed (GtkComboBox *combo, GogGraph *graph)
 			g_object_unref (theme);
 		}
 	}
+	gtk_widget_set_visible (w, graph->theme && gog_theme_get_resource_type (graph->theme) == GO_RESOURCE_EXTERNAL);
 }
 
 static void
@@ -290,6 +292,13 @@ unset_model (GtkComboBox *cb)
 }
 
 static void
+save_theme_cb (GtkWidget *w, GogGraph *graph)
+{
+	gog_theme_save_to_home_dir (graph->theme);
+	gtk_widget_hide (w);
+}
+
+static void
 gog_graph_populate_editor (GogObject *gobj,
 			   GOEditor *editor,
 			   G_GNUC_UNUSED GogDataAllocator *dalloc,
@@ -326,6 +335,9 @@ gog_graph_populate_editor (GogObject *gobj,
 				  G_CALLBACK (unset_model), NULL);
 
 		count = 0;
+		box = go_gtk_builder_get_widget (gui, "save-theme");
+		g_signal_connect (G_OBJECT (box), "clicked", G_CALLBACK (save_theme_cb), graph);
+		g_object_set_data (G_OBJECT (combo), "save-button", box);
 		for (ptr = theme_names; ptr != NULL; ptr = ptr->next) {
 			theme = gog_theme_registry_lookup (ptr->data);
 			gtk_list_store_append (model, &iter);
@@ -338,12 +350,13 @@ gog_graph_populate_editor (GogObject *gobj,
 			count++;
 		}
 		gtk_combo_box_set_active (GTK_COMBO_BOX (combo), index);
+		gtk_widget_set_visible (box, graph->theme && gog_theme_get_resource_type (graph->theme) == GO_RESOURCE_EXTERNAL);
 
 		g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (cb_theme_changed), graph);
-		g_signal_connect (gtk_builder_get_object (gui, "force_theme_button"), "clicked",
+		g_signal_connect (gtk_builder_get_object (gui, "force-theme-button"), "clicked",
 				  G_CALLBACK (cb_force_theme), graph);
 
-		box = go_gtk_builder_get_widget (gui, "gog_graph_prefs");
+		box = go_gtk_builder_get_widget (gui, "gog-graph-prefs");
 		go_editor_add_page (editor, box, _("Theme"));
 
 		g_slist_free (theme_names);
diff --git a/goffice/graph/gog-theme.c b/goffice/graph/gog-theme.c
index a26e6b5..f204ab5 100644
--- a/goffice/graph/gog-theme.c
+++ b/goffice/graph/gog-theme.c
@@ -450,6 +450,22 @@ gog_theme_save (GogTheme const *theme)
 	g_object_unref (output);
 }
 
+/**
+ * gog_theme_save_to_home_dir:
+ * @theme: the #GogTheme to save
+ *
+ * Writes the theme to the user directory so that it becomes permanently
+ * available.
+ **/
+void
+gog_theme_save_to_home_dir (GogTheme *theme)
+{
+	g_return_if_fail (GOG_IS_THEME (theme) && theme->type == GO_RESOURCE_EXTERNAL && theme->uri == NULL);
+	gog_theme_build_uri (theme);
+	gog_theme_save (theme);
+	theme->type = GO_RESOURCE_RW;
+}
+
 /**************
  * Input code *
  **************/
@@ -1159,7 +1175,7 @@ gog_theme_registry_get_theme_names (void)
 
 	for (ptr = themes; ptr != NULL; ptr = ptr->next) {
 		theme = ptr->data;
-		names = g_slist_append (names, theme->name);
+		names = g_slist_append (names, theme->id);
 	}
 
 	return names;
@@ -1543,7 +1559,6 @@ theme_load_from_uri (char const *uri)
 		}
 		theme_loaded (&state);
 		gog_theme_registry_add (state.theme, FALSE);
-printf("theme is %p with id %s\n",state.theme,state.theme->id);
 	} else {
 		g_free (state.name);
 		g_free (state.desc);
diff --git a/goffice/graph/gog-theme.h b/goffice/graph/gog-theme.h
index 5d9e2c5..7db765a 100644
--- a/goffice/graph/gog-theme.h
+++ b/goffice/graph/gog-theme.h
@@ -42,6 +42,7 @@ GogAxisColorMap const *gog_theme_get_color_map (GogTheme const *theme, gboolean
 
 GogTheme   *gog_theme_registry_lookup 		(char const *name);
 GSList	   *gog_theme_registry_get_theme_names	(void);
+void		gog_theme_save_to_home_dir (GogTheme *theme);
 
 /* private */
 void _gog_themes_init	 (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]