[gthumb/ext: 11/15] [organize_task] added the catalog icon, made the list sortable



commit 3c219720b32bd0df07ee3fe91e8597ecb41ede78
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Dec 14 22:37:15 2009 +0100

    [organize_task] added the catalog icon, made the list sortable

 extensions/catalogs/data/ui/organize-files-task.ui |   59 +++++++-
 extensions/catalogs/gth-organize-task.c            |  146 ++++++++++++++++++--
 2 files changed, 185 insertions(+), 20 deletions(-)
---
diff --git a/extensions/catalogs/data/ui/organize-files-task.ui b/extensions/catalogs/data/ui/organize-files-task.ui
index e961f5a..2189c98 100644
--- a/extensions/catalogs/data/ui/organize-files-task.ui
+++ b/extensions/catalogs/data/ui/organize-files-task.ui
@@ -10,6 +10,10 @@
       <column type="gint"/>
       <!-- column-name create -->
       <column type="gboolean"/>
+      <!-- column-name key -->
+      <column type="gchararray"/>
+      <!-- column-name icon -->
+      <column type="GdkPixbuf"/>
     </columns>
   </object>
   <object class="GtkDialog" id="organize_files_dialog">
@@ -80,7 +84,7 @@
                           <object class="GtkLabel" id="progress_label">
                             <property name="visible">True</property>
                             <property name="xalign">0</property>
-                            <property name="label" translatable="yes">Searching in...</property>
+                            <property name="ellipsize">middle</property>
                           </object>
                           <packing>
                             <property name="position">0</property>
@@ -141,16 +145,26 @@
                                 <property name="vscrollbar_policy">automatic</property>
                                 <property name="shadow_type">in</property>
                                 <child>
-                                  <object class="GtkTreeView" id="treeview1">
+                                  <object class="GtkTreeView" id="organization_treeview">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="model">results_liststore</property>
                                     <property name="headers_clickable">False</property>
+                                    <property name="rules_hint">True</property>
                                     <property name="search_column">0</property>
                                     <child>
                                       <object class="GtkTreeViewColumn" id="treeviewcolumn1">
-                                        <property name="title">Date</property>
+                                        <property name="title">Catalog</property>
                                         <property name="expand">True</property>
+                                        <property name="reorderable">True</property>
+                                        <property name="sort_indicator">True</property>
+                                        <property name="sort_column_id">3</property>
+                                        <child>
+                                          <object class="GtkCellRendererPixbuf" id="icon_cellrendererpixbuf"/>
+                                          <attributes>
+                                            <attribute name="pixbuf">4</attribute>
+                                          </attributes>
+                                        </child>
                                         <child>
                                           <object class="GtkCellRendererText" id="cellrenderertext1"/>
                                           <attributes>
@@ -163,6 +177,9 @@
                                       <object class="GtkTreeViewColumn" id="treeviewcolumn2">
                                         <property name="title">Files</property>
                                         <property name="expand">True</property>
+                                        <property name="reorderable">True</property>
+                                        <property name="sort_indicator">True</property>
+                                        <property name="sort_column_id">1</property>
                                         <child>
                                           <object class="GtkCellRendererText" id="cellrenderertext2"/>
                                           <attributes>
@@ -173,9 +190,9 @@
                                     </child>
                                     <child>
                                       <object class="GtkTreeViewColumn" id="treeviewcolumn3">
-                                        <property name="title">Create Catalog</property>
+                                        <property name="title">Create</property>
                                         <child>
-                                          <object class="GtkCellRendererToggle" id="cellrenderertoggle2"/>
+                                          <object class="GtkCellRendererToggle" id="create_cellrenderertoggle"/>
                                           <attributes>
                                             <attribute name="active">2</attribute>
                                           </attributes>
@@ -232,6 +249,34 @@
                 <property name="position">0</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkButton" id="close_button">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="ok_button">
+                <property name="label">gtk-save</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -242,7 +287,9 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="0">cancel_button</action-widget>
+      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="-7">close_button</action-widget>
+      <action-widget response="-5">ok_button</action-widget>
     </action-widgets>
   </object>
 </interface>
diff --git a/extensions/catalogs/gth-organize-task.c b/extensions/catalogs/gth-organize-task.c
index 3adc531..753a8f7 100644
--- a/extensions/catalogs/gth-organize-task.c
+++ b/extensions/catalogs/gth-organize-task.c
@@ -34,7 +34,9 @@
 enum {
 	NAME_COLUMN = 0,
 	CARDINALITY_COLUMN,
-	CREATE_CATALOG_COLUMN
+	CREATE_CATALOG_COLUMN,
+	KEY_COLUMN,
+	ICON_COLUMN
 };
 
 
@@ -49,6 +51,7 @@ struct _GthOrganizeTaskPrivate
 	GtkBuilder     *builder;
 	GtkListStore   *results_liststore;
 	GHashTable     *catalogs;
+	GdkPixbuf      *icon_pixbuf;
 };
 
 
@@ -62,10 +65,12 @@ gth_organize_task_finalize (GObject *object)
 
 	self = GTH_ORGANIZE_TASK (object);
 
+	gtk_widget_destroy (GET_WIDGET ("organize_files_dialog"));
 	g_object_unref (self->priv->folder);
 	_g_object_unref (self->priv->singletons_catalog);
 	g_object_unref (self->priv->builder);
 	g_hash_table_destroy (self->priv->catalogs);
+	g_object_unref (self->priv->icon_pixbuf);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -128,16 +133,8 @@ create_singletons_catalog (gpointer key,
 
 
 static void
-done_func (GError   *error,
-	   gpointer  user_data)
+save_catalogs (GthOrganizeTask *self)
 {
-	GthOrganizeTask *self = user_data;
-
-	if (error != NULL) {
-		gth_task_completed (GTH_TASK (self), error);
-		return;
-	}
-
 	g_hash_table_foreach (self->priv->catalogs, save_catalog, self);
 
 	if (! self->priv->create_singletons && (self->priv->singletons_catalog != NULL)) {
@@ -161,11 +158,29 @@ done_func (GError   *error,
 		g_object_unref (gio_file);
 	}
 
-	gtk_widget_destroy (GET_WIDGET ("organize_files_dialog"));
 	gth_task_completed (GTH_TASK (self), NULL);
 }
 
 
+static void
+done_func (GError   *error,
+	   gpointer  user_data)
+{
+	GthOrganizeTask *self = user_data;
+
+	if (error != NULL) {
+		gth_task_completed (GTH_TASK (self), error);
+		return;
+	}
+
+	gtk_label_set_text (GTK_LABEL (GET_WIDGET ("progress_label")), _("Operation completed."));
+
+	gtk_widget_hide (GET_WIDGET ("cancel_button"));
+	gtk_widget_show (GET_WIDGET ("close_button"));
+	gtk_widget_show (GET_WIDGET ("ok_button"));
+}
+
+
 static GFile *
 get_catalog_file (const char *base_uri,
 		  const char *display_name)
@@ -255,6 +270,7 @@ for_each_file_func (GFile     *file,
 		GthDateTime *date_time;
 		char        *exif_date;
 		GFile       *catalog_file;
+		char        *name;
 		GtkTreeIter  iter;
 
 		catalog = gth_catalog_new ();
@@ -266,20 +282,50 @@ for_each_file_func (GFile     *file,
 		gth_catalog_set_file (catalog, catalog_file);
 		g_hash_table_insert (self->priv->catalogs, g_strdup (key), catalog);
 
+		name = gth_datetime_strftime (date_time, "%x");
 		gtk_list_store_append (self->priv->results_liststore, &iter);
 		gtk_list_store_set (self->priv->results_liststore, &iter,
-				    NAME_COLUMN, key,
+				    KEY_COLUMN, key,
+				    NAME_COLUMN, name,
 				    CARDINALITY_COLUMN, 0,
 				    CREATE_CATALOG_COLUMN, TRUE,
+				    ICON_COLUMN, self->priv->icon_pixbuf,
 				    -1);
 
+		g_free (name);
 		g_object_unref (catalog_file);
 		g_free (exif_date);
 		gth_datetime_free (date_time);
 	}
 
-	if (catalog != NULL)
+	if (catalog != NULL) {
+		GtkTreeIter iter;
+		int         n = 0;
+
+		if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->results_liststore), &iter)) {
+			do {
+				char *k;
+
+				gtk_tree_model_get (GTK_TREE_MODEL (self->priv->results_liststore),
+						    &iter,
+						    KEY_COLUMN, &k,
+						    CARDINALITY_COLUMN, &n,
+						    -1);
+				if (g_strcmp0 (k, key) == 0) {
+					gtk_list_store_set (self->priv->results_liststore, &iter,
+							    CARDINALITY_COLUMN, n + 1,
+							    -1);
+					g_free (k);
+					break;
+				}
+
+				g_free (k);
+			}
+			while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->results_liststore), &iter));
+		}
+
 		gth_catalog_append_file (catalog, file_data->file);
+	}
 
 	g_object_unref (file_data);
 	g_free (key);
@@ -335,10 +381,14 @@ gth_organize_task_exec (GthTask *base)
 				   done_func,
 				   self);
 
-	gth_task_dialog (base, TRUE);
+	gtk_widget_show (GET_WIDGET ("cancel_button"));
+	gtk_widget_hide (GET_WIDGET ("close_button"));
+	gtk_widget_hide (GET_WIDGET ("ok_button"));
 	gtk_window_set_transient_for (GTK_WINDOW (GET_WIDGET ("organize_files_dialog")), GTK_WINDOW (self->priv->browser));
 	gtk_window_set_modal (GTK_WINDOW (GET_WIDGET ("organize_files_dialog")), TRUE);
 	gtk_widget_show (GET_WIDGET ("organize_files_dialog"));
+
+	gth_task_dialog (base, TRUE); /* FIXME */
 }
 
 
@@ -350,6 +400,27 @@ gth_organize_task_cancelled (GthTask *base)
 
 
 static void
+organize_files_dialog_response_cb (GtkDialog *dialog,
+				   int        response_id,
+				   gpointer   user_data)
+{
+	GthOrganizeTask *self = user_data;
+
+	switch (response_id) {
+	case GTK_RESPONSE_CANCEL:
+		gth_task_cancel (GTH_TASK (self));
+		break;
+	case GTK_RESPONSE_CLOSE:
+		gth_task_completed (GTH_TASK (self), NULL);
+		break;
+	case GTK_RESPONSE_OK:
+		save_catalogs (self);
+		break;
+	}
+}
+
+
+static void
 gth_organize_task_class_init (GthOrganizeTaskClass *klass)
 {
 	GObjectClass *object_class;
@@ -368,12 +439,59 @@ gth_organize_task_class_init (GthOrganizeTaskClass *klass)
 
 
 static void
+create_cellrenderertoggle_toggled_cb (GtkCellRendererToggle *cell_renderer,
+				      char                  *path,
+				      gpointer               user_data)
+{
+	GthOrganizeTask *self = user_data;
+	GtkTreePath     *tpath;
+	GtkTreeIter      iter;
+
+	tpath = gtk_tree_path_new_from_string (path);
+	if (tpath == NULL)
+		return;
+
+	if (gtk_tree_model_get_iter (GTK_TREE_MODEL (self->priv->results_liststore), &iter, tpath)) {
+		gboolean create;
+
+		gtk_tree_model_get (GTK_TREE_MODEL (self->priv->results_liststore), &iter,
+				    CREATE_CATALOG_COLUMN, &create,
+				    -1);
+		gtk_list_store_set (self->priv->results_liststore, &iter,
+				    CREATE_CATALOG_COLUMN, ! create,
+				    -1);
+	}
+
+	gtk_tree_path_free (tpath);
+}
+
+
+static void
 gth_organize_task_init (GthOrganizeTask *self)
 {
+	GIcon *icon;
+
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_ORGANIZE_TASK, GthOrganizeTaskPrivate);
 	self->priv->builder = _gtk_builder_new_from_file ("organize-files-task.ui", "catalogs");
 	self->priv->results_liststore = (GtkListStore *) gtk_builder_get_object (self->priv->builder, "results_liststore");
 	self->priv->catalogs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
+	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->priv->results_liststore), KEY_COLUMN, GTK_SORT_ASCENDING);
+
+	icon = g_themed_icon_new ("image-catalog");
+	self->priv->icon_pixbuf = _g_icon_get_pixbuf (icon,
+						      _gtk_icon_get_pixel_size (GET_WIDGET ("organization_treeview"), GTK_ICON_SIZE_MENU),
+						      gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GET_WIDGET ("organization_treeview"))));
+	g_object_unref (icon);
+
+	g_signal_connect (GET_WIDGET ("create_cellrenderertoggle"),
+			  "toggled",
+			  G_CALLBACK (create_cellrenderertoggle_toggled_cb),
+			  self);
+	g_signal_connect (GET_WIDGET ("organize_files_dialog"),
+			  "response",
+			  G_CALLBACK (organize_files_dialog_response_cb),
+			  self);
 }
 
 



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