[gthumb] template-selector: organize attributes in sub-categories



commit 03b27b44747d9650c2679219c060c9f6a11e81d7
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Apr 3 20:02:19 2011 +0200

    template-selector: organize attributes in sub-categories

 extensions/rename_series/data/ui/code-selector.ui |    6 ++-
 extensions/rename_series/gth-template-selector.c  |   50 ++++++++++++++++++---
 2 files changed, 47 insertions(+), 9 deletions(-)
---
diff --git a/extensions/rename_series/data/ui/code-selector.ui b/extensions/rename_series/data/ui/code-selector.ui
index a94ded8..4c2c726 100644
--- a/extensions/rename_series/data/ui/code-selector.ui
+++ b/extensions/rename_series/data/ui/code-selector.ui
@@ -160,7 +160,7 @@
         <child>
           <object class="GtkComboBox" id="attribute_combobox">
             <property name="visible">True</property>
-            <property name="model">attribute_liststore</property>
+            <property name="model">attribute_treestore</property>
             <child>
               <object class="GtkCellRendererText" id="cellrenderertext3"/>
               <attributes>
@@ -254,12 +254,14 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
-  <object class="GtkListStore" id="attribute_liststore">
+  <object class="GtkTreeStore" id="attribute_treestore">
     <columns>
       <!-- column-name id -->
       <column type="gchararray"/>
       <!-- column-name name -->
       <column type="gchararray"/>
+      <!-- column-name sort_order -->
+      <column type="gint"/>
     </columns>
   </object>
 </interface>
diff --git a/extensions/rename_series/gth-template-selector.c b/extensions/rename_series/gth-template-selector.c
index 7670f55..6596c2e 100644
--- a/extensions/rename_series/gth-template-selector.c
+++ b/extensions/rename_series/gth-template-selector.c
@@ -43,6 +43,7 @@ enum {
 enum {
 	ATTRIBUTE_ID_COLUMN,
 	ATTRIBUTE_NAME_COLUMN,
+	ATTRIBUTE_SORT_ORDER_COLUMN,
 	ATTRIBUTE_N_COLUMNS,
 };
 
@@ -208,6 +209,8 @@ gth_template_selector_construct (GthTemplateSelector *self,
 	GtkTreeIter    iter;
 	int            i;
 	GTimeVal       timeval;
+	GHashTable    *category_root;
+	GtkTreeStore  *tree_store;
 	char         **attributes_v;
 
 	gtk_box_set_spacing (GTK_BOX (self), 6);
@@ -261,11 +264,17 @@ gth_template_selector_construct (GthTemplateSelector *self,
 
 	/* attributes */
 
-	list_store = (GtkListStore *) GET_WIDGET ("attribute_liststore");
+	gtk_combo_box_set_model (GTK_COMBO_BOX (GET_WIDGET ("attribute_combobox")), NULL);
+	tree_store = (GtkTreeStore *) GET_WIDGET ("attribute_treestore");
+	category_root = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) gtk_tree_row_reference_free);
 	attributes_v = gth_main_get_metadata_attributes ("*");
 	for (i = 0; attributes_v[i] != NULL; i++) {
-		GthMetadataInfo *info;
-		const char      *name;
+		GthMetadataInfo     *info;
+		const char          *name;
+		GthMetadataCategory *category;
+		GtkTreeRowReference *parent_row;
+		GtkTreePath         *path;
+		GtkTreeIter          root_iter;
 
 		info = gth_main_get_metadata_info (attributes_v[i]);
 		if (info == NULL)
@@ -277,13 +286,40 @@ gth_template_selector_construct (GthTemplateSelector *self,
 		if (name == NULL)
 			name = info->id;
 
-		gtk_list_store_append (list_store, &iter);
-		gtk_list_store_set (list_store, &iter,
+		category = gth_main_get_metadata_category (info->category);
+		parent_row = g_hash_table_lookup (category_root, category->id);
+		if (parent_row == NULL) {
+			gtk_tree_store_append (tree_store, &iter, NULL);
+			gtk_tree_store_set (tree_store,
+					    &iter,
+					    ATTRIBUTE_ID_COLUMN, category->id,
+					    ATTRIBUTE_NAME_COLUMN, category->display_name,
+					    ATTRIBUTE_SORT_ORDER_COLUMN, category->sort_order,
+					    -1);
+
+			path = gtk_tree_model_get_path (GTK_TREE_MODEL (tree_store), &iter);
+			parent_row = gtk_tree_row_reference_new (GTK_TREE_MODEL (tree_store), path);
+			g_hash_table_insert (category_root, g_strdup (info->category), parent_row);
+
+			gtk_tree_path_free (path);
+		}
+
+		path = gtk_tree_row_reference_get_path (parent_row);
+		gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_store), &root_iter, path);
+		gtk_tree_path_free (path);
+
+		gtk_tree_store_append (tree_store, &iter, &root_iter);
+		gtk_tree_store_set (tree_store, &iter,
 				    ATTRIBUTE_ID_COLUMN, info->id,
 				    ATTRIBUTE_NAME_COLUMN, name,
+				    ATTRIBUTE_SORT_ORDER_COLUMN, info->sort_order,
 				    -1);
 	}
 	g_strfreev (attributes_v);
+	g_hash_table_destroy (category_root);
+
+	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (tree_store), ATTRIBUTE_SORT_ORDER_COLUMN, GTK_SORT_ASCENDING);
+	gtk_combo_box_set_model (GTK_COMBO_BOX (GET_WIDGET ("attribute_combobox")), GTK_TREE_MODEL (tree_store));
 
 	/* signals */
 
@@ -426,7 +462,7 @@ gth_template_selector_set_value (GthTemplateSelector *self,
 			GtkTreeModel *tree_model;
 			GtkTreeIter   iter;
 
-			tree_model = (GtkTreeModel *) GET_WIDGET ("attribute_liststore");
+			tree_model = (GtkTreeModel *) GET_WIDGET ("attribute_treestore");
 			if (gtk_tree_model_get_iter_first (tree_model, &iter)) {
 				do {
 					char *iter_id;
@@ -515,7 +551,7 @@ gth_template_selector_get_value (GthTemplateSelector  *self,
 		if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (GET_WIDGET ("attribute_combobox")), &iter)) {
 			char *attribute_id;
 
-			gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("attribute_liststore")),
+			gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("attribute_treestore")),
 					    &iter,
 					    ATTRIBUTE_ID_COLUMN, &attribute_id,
 					    -1);



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