[gthumb/ext: 8/20] [image_print] allow to print the image metadata



commit ca83f3a46dcd79955ac1609b181d12b20f469745
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Nov 21 20:54:41 2009 +0100

    [image_print] allow to print the image metadata
    
    added ability to choose the metadata to print; added the metadata
    in the page preview; print the selected metadata.

 extensions/image_print/data/ui/print-layout.ui |   26 ++--
 extensions/image_print/gth-image-info.c        |    1 +
 extensions/image_print/gth-image-info.h        |    8 +-
 extensions/image_print/gth-image-print-job.c   |  227 ++++++++++++++++++++++-
 gthumb/gth-browser.c                           |   66 +-------
 gthumb/gth-main.c                              |   70 ++++++++
 gthumb/gth-main.h                              |    5 +
 7 files changed, 315 insertions(+), 88 deletions(-)
---
diff --git a/extensions/image_print/data/ui/print-layout.ui b/extensions/image_print/data/ui/print-layout.ui
index 16e991c..e18d34f 100644
--- a/extensions/image_print/data/ui/print-layout.ui
+++ b/extensions/image_print/data/ui/print-layout.ui
@@ -155,20 +155,16 @@
                     <property name="orientation">vertical</property>
                     <property name="spacing">6</property>
                     <child>
-                      <object class="GtkScrolledWindow" id="scrolledwindow1">
-                        <property name="width_request">250</property>
-                        <property name="height_request">120</property>
+                      <object class="GtkScrolledWindow" id="caption_scrolledwindow">
+                        <property name="width_request">300</property>
+                        <property name="height_request">150</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="hscrollbar_policy">automatic</property>
                         <property name="vscrollbar_policy">automatic</property>
                         <property name="shadow_type">in</property>
                         <child>
-                          <object class="GtkTreeView" id="treeview1">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="model">caption_liststore</property>
-                          </object>
+                          <placeholder/>
                         </child>
                       </object>
                       <packing>
@@ -201,6 +197,7 @@
                         </child>
                       </object>
                       <packing>
+                        <property name="pack_type">end</property>
                         <property name="position">1</property>
                       </packing>
                     </child>
@@ -219,7 +216,6 @@
         </child>
         <child>
           <object class="GtkVBox" id="vbox2">
-            <property name="visible">True</property>
             <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
@@ -409,7 +405,6 @@
         </child>
         <child>
           <object class="GtkVBox" id="vbox1">
-            <property name="visible">True</property>
             <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
@@ -630,8 +625,17 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkDrawingArea" id="preview_drawingarea">
+                      <object class="GtkHBox" id="hbox2">
                         <property name="visible">True</property>
+                        <child>
+                          <object class="GtkDrawingArea" id="preview_drawingarea">
+                            <property name="visible">True</property>
+                          </object>
+                          <packing>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="position">1</property>
diff --git a/extensions/image_print/gth-image-info.c b/extensions/image_print/gth-image-info.c
index 179b219..4cd7375 100644
--- a/extensions/image_print/gth-image-info.c
+++ b/extensions/image_print/gth-image-info.c
@@ -78,6 +78,7 @@ gth_image_info_unref (GthImageInfo *image_info)
 	_g_object_unref (image_info->pixbuf);
 	_g_object_unref (image_info->thumbnail);
 	_g_object_unref (image_info->thumbnail_active);
+	g_free (image_info->comment_text);
 	g_free (image_info);
 }
 
diff --git a/extensions/image_print/gth-image-info.h b/extensions/image_print/gth-image-info.h
index 010c195..c6b3d34 100644
--- a/extensions/image_print/gth-image-info.h
+++ b/extensions/image_print/gth-image-info.h
@@ -46,17 +46,11 @@ typedef struct {
 	int           page;
 	int           row;
 	int           col;
-	/*double        width, height;
-	double        scale_x, scale_y;
-	double        trans_x, trans_y;*/
 	int           rotation;
 	GthTransform  transform;
 	double        zoom;
-	/*double        min_x, min_y;
-	double        max_x, max_y;
-	double        comment_height;*/
 	gboolean      print_comment;
-
+	char         *comment_text;
 	GthRectangle  boundary;
 	GthRectangle  maximized;
 	GthRectangle  image;
diff --git a/extensions/image_print/gth-image-print-job.c b/extensions/image_print/gth-image-print-job.c
index 17c960c..efc3e9c 100644
--- a/extensions/image_print/gth-image-print-job.c
+++ b/extensions/image_print/gth-image-print-job.c
@@ -53,6 +53,7 @@ struct _GthImagePrintJobPrivate {
 	GthBrowser         *browser;
 	GtkPrintOperation  *print_operation;
 	GtkBuilder         *builder;
+	GtkWidget          *caption_chooser;
 
 	/* settings */
 
@@ -63,6 +64,7 @@ struct _GthImagePrintJobPrivate {
 	int                 image_width;
 	int                 image_height;
 	GtkPageSetup       *page_setup;
+	char               *caption_attributes;
 
 	/* layout info */
 
@@ -92,6 +94,7 @@ gth_image_print_job_finalize (GObject *base)
 		gth_image_info_unref (self->priv->images[i]);
 	g_free (self->priv->images);
 	_g_object_unref (self->priv->page_setup);
+	g_free (self->priv->caption_attributes);
 
 	G_OBJECT_CLASS (parent_class)->finalize (base);
 }
@@ -118,6 +121,7 @@ gth_image_print_job_init (GthImagePrintJob *self)
 	self->priv->task = NULL;
 	self->priv->page_setup = NULL;
 	self->priv->current_page = 0;
+	self->priv->caption_attributes = g_strdup (""); /* FIXME: load from a gconf key */
 }
 
 
@@ -289,10 +293,21 @@ gth_image_print_job_update_page_layout (GthImagePrintJob   *self,
 					int                 page,
 					gdouble             page_width,
 					gdouble             page_height,
-					GtkPageOrientation  orientation)
+					GtkPageOrientation  orientation,
+					double              scale_factor)
 {
-	int i;
-
+	PangoLayout           *pango_layout;
+	PangoFontDescription  *font_desc;
+	char                 **attributes_v;
+	int                    i;
+
+	pango_layout = gtk_widget_create_pango_layout (GTK_WIDGET (self->priv->browser), NULL);
+	pango_layout_set_wrap (pango_layout, PANGO_WRAP_WORD_CHAR);
+	pango_layout_set_alignment (pango_layout, PANGO_ALIGN_CENTER);
+	font_desc = pango_font_description_from_string ("[sans serif] [normal] [10]");
+	pango_layout_set_font_description (pango_layout, font_desc);
+
+	attributes_v = g_strsplit(self->priv->caption_attributes, ",", -1);
 	for (i = 0; i < self->priv->n_images; i++) {
 		GthImageInfo *image_info = self->priv->images[i];
 		double        max_image_width;
@@ -320,7 +335,51 @@ gth_image_print_job_update_page_layout (GthImagePrintJob   *self,
 		max_image_width = image_info->boundary.width;
 		max_image_height = image_info->boundary.height;
 
-		/* FIXME: change max_image_width/max_image_height to make space to the comment */
+		image_info->print_comment = FALSE;
+		g_free (image_info->comment_text);
+		image_info->comment_text = NULL;
+
+		if (strcmp (self->priv->caption_attributes, "") != 0) {
+			gboolean  comment_present = FALSE;
+			GString  *text;
+			int       j;
+
+			text = g_string_new ("");
+			for (j = 0; attributes_v[j] != NULL; j++) {
+				char *value;
+
+				value = gth_file_data_get_attribute_as_string (image_info->file_data, attributes_v[j]);
+				if ((value != NULL) && (strcmp (value, "") != 0)) {
+					if (comment_present)
+						g_string_append (text, "\n");
+					g_string_append (text, value);
+					comment_present = TRUE;
+				}
+
+				g_free (value);
+			}
+
+			image_info->comment_text = g_string_free (text, FALSE);
+			if (comment_present) {
+				PangoRectangle logical_rect;
+
+				image_info->print_comment = TRUE;
+
+				pango_layout_set_text (pango_layout, image_info->comment_text, -1);
+				pango_layout_set_width (pango_layout, max_image_width * scale_factor * PANGO_SCALE);
+				pango_layout_get_pixel_extents (pango_layout, NULL, &logical_rect);
+
+				image_info->comment.x = 0;
+				image_info->comment.y = 0;
+				image_info->comment.width = image_info->boundary.width;
+				image_info->comment.height = logical_rect.height / scale_factor;
+				max_image_height -= image_info->comment.height;
+				if (max_image_height < 0) {
+					image_info->print_comment = FALSE;
+					max_image_height = image_info->boundary.height;
+				}
+			}
+		}
 
 		factor = MIN (max_image_width / image_info->pixbuf_width, max_image_height / image_info->pixbuf_height);
 		image_info->maximized.width = (double) image_info->pixbuf_width * factor;
@@ -331,10 +390,22 @@ gth_image_print_job_update_page_layout (GthImagePrintJob   *self,
 		image_info->image.y = image_info->maximized.y;
 		image_info->image.width = image_info->maximized.width * image_info->zoom;
 		image_info->image.height = image_info->maximized.height * image_info->zoom;
+
+		if (image_info->print_comment) {
+			image_info->comment.x += image_info->boundary.x;
+			image_info->comment.y += image_info->maximized.y + image_info->maximized.height;
+		}
 	}
+
+	g_strfreev (attributes_v);
+	pango_font_description_free (font_desc);
+	g_object_unref (pango_layout);
 }
 
 
+#define PREVIEW_SCALE_FACTOR 3.0 /* FIXME: why 3.0 ? */
+
+
 static void
 gth_image_print_job_update_layout (GthImagePrintJob   *self,
 			  	   gdouble             page_width,
@@ -342,20 +413,25 @@ gth_image_print_job_update_layout (GthImagePrintJob   *self,
 			  	   GtkPageOrientation  orientation)
 {
 	gth_image_print_job_update_layout_info (self, page_width, page_height, orientation);
-	gth_image_print_job_update_page_layout (self, self->priv->current_page, page_width, page_height, orientation);
+	gth_image_print_job_update_page_layout (self, self->priv->current_page, page_width, page_height, orientation, PREVIEW_SCALE_FACTOR);
 }
 
 
 static void
 gth_image_print_job_paint (GthImagePrintJob *self,
 			   cairo_t          *cr,
+			   PangoLayout      *pango_layout,
 			   double            dpi,
 			   double            x_offset,
 			   double            y_offset,
 			   int               page,
 			   gboolean          preview)
 {
-	int i;
+	PangoFontDescription *font_desc;
+	int                   i;
+
+	font_desc = pango_font_description_from_string ("[sans serif] [normal] [10]");
+	pango_layout_set_font_description (pango_layout, font_desc);
 
 	for (i = 0; i < self->priv->n_images; i++) {
 		GthImageInfo *image_info = self->priv->images[i];
@@ -366,8 +442,24 @@ gth_image_print_job_paint (GthImagePrintJob *self,
 		if (image_info->page != page)
 			continue;
 
+		if (preview) {
+			cairo_save (cr);
+
+			cairo_set_line_width (cr, 0.5);
+			cairo_set_source_rgb (cr, .5, .5, .5);
+			cairo_rectangle (cr,
+					 x_offset + image_info->boundary.x,
+					 y_offset + image_info->boundary.y,
+					 image_info->boundary.width,
+					 image_info->boundary.height);
+			cairo_stroke (cr);
+
+			cairo_restore (cr);
+		}
+
 #if 0
 		cairo_save (cr);
+
 		cairo_set_source_rgb (cr, 1.0, .0, .0);
 		cairo_rectangle (cr,
 				 x_offset + image_info->boundary.x,
@@ -383,7 +475,16 @@ gth_image_print_job_paint (GthImagePrintJob *self,
 				 image_info->image.width,
 				 image_info->image.height);
 		cairo_stroke (cr);
+
+		cairo_set_source_rgb (cr, .0, .0, 1.0);
+		cairo_rectangle (cr,
+				 x_offset + image_info->comment.x,
+				 y_offset + image_info->comment.y,
+				 image_info->comment.width,
+				 image_info->comment.height);
+		cairo_stroke (cr);
 		cairo_restore (cr);
+
 #endif
 
 		/* For higher-resolution images, cairo will render the bitmaps at a miserable
@@ -397,6 +498,7 @@ gth_image_print_job_paint (GthImagePrintJob *self,
 			scale_factor = image_info->pixbuf_width / image_info->image.width;
 		*/
 		scale_factor = 1.0;
+		/*scale_factor = MIN (image_info->pixbuf_width / image_info->image.width, image_info->pixbuf_height / image_info->image.height);*/
 
 		if (! preview) {
 			if (image_info->rotation != 0)
@@ -408,8 +510,8 @@ gth_image_print_job_paint (GthImagePrintJob *self,
 			fullsize_pixbuf = g_object_ref (image_info->thumbnail);
 
 		pixbuf = gdk_pixbuf_scale_simple (fullsize_pixbuf,
-						  image_info->image.width * scale_factor,
-						  image_info->image.height * scale_factor,
+						  image_info->image.width,
+						  image_info->image.height,
 						  preview ? GDK_INTERP_NEAREST : GDK_INTERP_BILINEAR);
 
 		cairo_save (cr);
@@ -426,10 +528,44 @@ gth_image_print_job_paint (GthImagePrintJob *self,
 		cairo_paint (cr);
 		cairo_restore (cr);
 
+		if (image_info->print_comment) {
+			cairo_save (cr);
+
+			pango_layout_set_wrap (pango_layout, PANGO_WRAP_WORD_CHAR);
+			pango_layout_set_alignment (pango_layout, PANGO_ALIGN_CENTER);
+			pango_layout_set_width (pango_layout, image_info->comment.width * (preview ? PREVIEW_SCALE_FACTOR : 1.0) * PANGO_SCALE);
+			pango_layout_set_text (pango_layout, image_info->comment_text, -1);
+
+			cairo_move_to (cr, x_offset + image_info->comment.x, y_offset + image_info->comment.y);
+			if (preview) {
+				cairo_font_options_t *options;
+
+				options = cairo_font_options_create ();
+				cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE);
+				cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
+				cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_NONE);
+				cairo_set_font_options (cr, options);
+				cairo_font_options_destroy (options);
+
+				cairo_scale (cr, 1.0 / PREVIEW_SCALE_FACTOR, 1.0 / PREVIEW_SCALE_FACTOR);
+				cairo_set_line_width (cr, 0.5);
+			}
+
+			pango_cairo_layout_path (cr, pango_layout);
+			cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+			/*cairo_set_line_width (cr, 0.5);
+			cairo_stroke_preserve (cr);*/
+			cairo_fill (cr);
+
+			cairo_restore (cr);
+		}
+
 		g_object_unref (fullsize_pixbuf);
 		g_object_unref (pixbuf);
 	}
 
+	pango_font_description_free (font_desc);
+
 #if 0
 	cairo_t        *cr;
 	PangoLayout    *layout;
@@ -533,6 +669,7 @@ preview_expose_event_cb (GtkWidget      *widget,
 {
 	GthImagePrintJob *self = user_data;
 	cairo_t          *cr;
+	PangoLayout      *pango_layout;
 
 	cr = gdk_cairo_create (widget->window);
 
@@ -546,13 +683,17 @@ preview_expose_event_cb (GtkWidget      *widget,
 
 	/* paint the current page */
 
-	gth_image_print_job_paint (self, cr,
+	pango_layout = gtk_widget_create_pango_layout (GTK_WIDGET (self->priv->browser), NULL);
+	gth_image_print_job_paint (self,
+			           cr,
+			           pango_layout,
 				   gdk_screen_get_resolution (gtk_widget_get_screen (widget)),
 				   gtk_page_setup_get_left_margin (self->priv->page_setup, GTK_UNIT_MM),
 				   gtk_page_setup_get_top_margin (self->priv->page_setup, GTK_UNIT_MM),
 				   self->priv->current_page,
 				   TRUE);
 
+	g_object_unref (pango_layout);
 	cairo_destroy (cr);
 }
 
@@ -588,6 +729,58 @@ prev_page_button_clicked_cb (GtkWidget *widget,
 }
 
 
+static void
+metadata_ready_cb (GList    *files,
+		   GError   *error,
+		   gpointer  user_data)
+{
+	GthImagePrintJob *self = user_data;
+
+	gth_image_print_job_update_preview (self);
+}
+
+
+static void
+gth_image_print_job_load_metadata (GthImagePrintJob *self)
+{
+	GList *files;
+	int    i;
+
+	files = NULL;
+	for (i = 0; i < self->priv->n_images; i++)
+		files = g_list_prepend (files, self->priv->images[i]->file_data);
+	files = g_list_reverse (files);
+
+	_g_query_metadata_async (files,
+				 self->priv->caption_attributes,
+				 NULL,
+				 metadata_ready_cb,
+				 self);
+
+	g_list_free (files);
+}
+
+
+static void
+caption_chooser_changed_cb (GthMetadataChooser *chooser,
+			    gpointer            user_data)
+{
+	GthImagePrintJob *self = user_data;
+	char             *new_caption_attributes;
+	gboolean          reload_required;
+
+	new_caption_attributes = gth_metadata_chooser_get_selection (chooser);
+	reload_required = attribute_list_reaload_required (self->priv->caption_attributes, new_caption_attributes);
+	g_free (self->priv->caption_attributes);
+	self->priv->caption_attributes = new_caption_attributes;
+
+	if (reload_required)
+		gth_image_print_job_load_metadata (self);
+	else
+		gth_image_print_job_update_preview (self);
+}
+
+
 static GObject *
 operation_create_custom_widget_cb (GtkPrintOperation *operation,
 			           gpointer           user_data)
@@ -595,6 +788,10 @@ operation_create_custom_widget_cb (GtkPrintOperation *operation,
 	GthImagePrintJob *self = user_data;
 
 	self->priv->builder = _gtk_builder_new_from_file ("print-layout.ui", "image_print");
+	self->priv->caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_PRINT);
+	gtk_widget_show (self->priv->caption_chooser);
+	gtk_container_add (GTK_CONTAINER (GET_WIDGET ("caption_scrolledwindow")), self->priv->caption_chooser);
+
 	g_signal_connect (GET_WIDGET ("preview_drawingarea"),
 			  "expose_event",
 	                  G_CALLBACK (preview_expose_event_cb),
@@ -611,6 +808,10 @@ operation_create_custom_widget_cb (GtkPrintOperation *operation,
 			  "clicked",
 			  G_CALLBACK (prev_page_button_clicked_cb),
 			  self);
+	g_signal_connect (self->priv->caption_chooser,
+			  "changed",
+	                  G_CALLBACK (caption_chooser_changed_cb),
+	                  self);
 
 	return gtk_builder_get_object (self->priv->builder, "print_layout");
 }
@@ -673,22 +874,28 @@ print_operation_draw_page_cb (GtkPrintOperation *operation,
 	GthImagePrintJob *self = user_data;
 	GtkPageSetup     *setup;
 	cairo_t          *cr;
+	PangoLayout      *pango_layout;
 
 	setup = gtk_print_context_get_page_setup (context);
 	gth_image_print_job_update_page_layout (self,
 						page_nr,
 						gtk_print_context_get_width (context),
 						gtk_print_context_get_height (context),
-						gtk_page_setup_get_orientation (setup));
+						gtk_page_setup_get_orientation (setup),
+						1.0);
 
 	cr = gtk_print_context_get_cairo_context (context);
+	pango_layout = gtk_print_context_create_pango_layout (context);
 	gth_image_print_job_paint (self,
 				   cr,
+				   pango_layout,
 				   gtk_print_context_get_dpi_x (context),
 				   0,
 				   0,
 				   page_nr,
 				   FALSE);
+
+	g_object_unref (pango_layout);
 }
 
 
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 9966945..834323d 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -1080,69 +1080,15 @@ static void _gth_browser_load_ready_cb (GthFileSource *file_source, GList *files
 static gboolean
 _gth_browser_reload_required (GthBrowser *browser)
 {
-	char        *old_list_attributes;
-	char       **old_list_attributes_v;
-	const char  *new_list_attributes;
-	char       **new_list_attributes_v;
-	int          new_list_attributes_len;
-	int          i;
+	char        *old_attributes;
+	const char  *new_attributes;
 	gboolean     reload_required;
 
-	old_list_attributes = g_strdup (_gth_browser_get_list_attributes (browser, FALSE));
-	old_list_attributes_v = g_strsplit (old_list_attributes, ",", -1);
+	old_attributes = g_strdup (_gth_browser_get_list_attributes (browser, FALSE));
+	new_attributes = _gth_browser_get_list_attributes (browser, TRUE);
+	reload_required = attribute_list_reaload_required (old_attributes, new_attributes);
 
-	new_list_attributes = _gth_browser_get_list_attributes (browser, TRUE);
-	new_list_attributes_v = g_strsplit (new_list_attributes, ",", -1);
-	new_list_attributes_len = g_strv_length (new_list_attributes_v);
-
-	for (i = 0; i < new_list_attributes_len; i++) {
-		if (_g_file_attributes_matches (new_list_attributes_v[i], "standard::*,etag::*,id::*,access::*,mountable::*,time::*,unix::*,dos::*,owner::*,thumbnail::*,filesystem::*,gvfs::*,xattr::*,xattr-sys::*,selinux::*")) {
-			g_free (new_list_attributes_v[i]);
-			new_list_attributes_v[i] = NULL;
-		}
-	}
-
-	for (i = 0; (old_list_attributes_v[i] != NULL); i++) {
-		GthMetadataProvider *provider;
-		int                  j;
-
-		provider = gth_main_get_metadata_reader (old_list_attributes_v[i]);
-		if (provider == NULL)
-			continue;
-
-		for (j = 0; j < new_list_attributes_len; j++)
-			if ((new_list_attributes_v[j] != NULL)
-			    && (new_list_attributes_v[j][0] != '\0')
-			    && (strcmp (new_list_attributes_v[j], "none") != 0))
-			{
-				char *attr_v[2];
-
-				attr_v[0] = new_list_attributes_v[j];
-				attr_v[1] = NULL;
-				if (gth_metadata_provider_can_read (provider, attr_v)) {
-					g_free (new_list_attributes_v[j]);
-					new_list_attributes_v[j] = NULL;
-				}
-			}
-
-		g_object_ref (provider);
-	}
-
-	/*g_print ("attributes to load: %s\n", new_list_attributes);
-	g_print ("attributes not available: \n");*/
-	reload_required = FALSE;
-	for (i = 0; ! reload_required && (i < new_list_attributes_len); i++)
-		if ((new_list_attributes_v[i] != NULL)
-		    && (new_list_attributes_v[i][0] != '\0')
-		    && (strcmp (new_list_attributes_v[i], "none") != 0))
-		{
-			reload_required = TRUE;
-			/*g_print ("\t%s\n", new_list_attributes_v[i]);*/
-		}
-
-	g_strfreev (new_list_attributes_v);
-	g_strfreev (old_list_attributes_v);
-	g_free (old_list_attributes);
+	g_free (old_attributes);
 
 	return reload_required;
 }
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index ab859c5..385d577 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -1242,3 +1242,73 @@ gth_main_activate_extensions (void)
 	g_slist_foreach (active_extensions, (GFunc) g_free, NULL);
 	g_slist_free (active_extensions);
 }
+
+
+/* utilities */
+
+
+gboolean
+attribute_list_reaload_required (const char *old_attributes,
+				 const char *new_attributes)
+{
+	char     **old_attributes_v;
+	char     **new_attributes_v;
+	int        new_attributes_len;
+	int        i;
+	gboolean   reload_required;
+
+	old_attributes_v = g_strsplit (old_attributes, ",", -1);
+	new_attributes_v = g_strsplit (new_attributes, ",", -1);
+	new_attributes_len = g_strv_length (new_attributes_v);
+
+	for (i = 0; i < new_attributes_len; i++) {
+		if (_g_file_attributes_matches (new_attributes_v[i], "standard::*,etag::*,id::*,access::*,mountable::*,time::*,unix::*,dos::*,owner::*,thumbnail::*,filesystem::*,gvfs::*,xattr::*,xattr-sys::*,selinux::*")) {
+			g_free (new_attributes_v[i]);
+			new_attributes_v[i] = NULL;
+		}
+	}
+
+	for (i = 0; (old_attributes_v[i] != NULL); i++) {
+		GthMetadataProvider *provider;
+		int                  j;
+
+		provider = gth_main_get_metadata_reader (old_attributes_v[i]);
+		if (provider == NULL)
+			continue;
+
+		for (j = 0; j < new_attributes_len; j++)
+			if ((new_attributes_v[j] != NULL)
+			    && (new_attributes_v[j][0] != '\0')
+			    && (strcmp (new_attributes_v[j], "none") != 0))
+			{
+				char *attr_v[2];
+
+				attr_v[0] = new_attributes_v[j];
+				attr_v[1] = NULL;
+				if (gth_metadata_provider_can_read (provider, attr_v)) {
+					g_free (new_attributes_v[j]);
+					new_attributes_v[j] = NULL;
+				}
+			}
+
+		g_object_ref (provider);
+	}
+
+	/*g_print ("attributes to load: %s\n", new_attributes);
+	g_print ("attributes not available: \n");*/
+
+	reload_required = FALSE;
+	for (i = 0; ! reload_required && (i < new_attributes_len); i++)
+		if ((new_attributes_v[i] != NULL)
+		    && (new_attributes_v[i][0] != '\0')
+		    && (strcmp (new_attributes_v[i], "none") != 0))
+		{
+			reload_required = TRUE;
+			/*g_print ("\t%s\n", new_attributes_v[i]);*/
+		}
+
+	g_strfreev (new_attributes_v);
+	g_strfreev (old_attributes_v);
+
+	return reload_required;
+}
diff --git a/gthumb/gth-main.h b/gthumb/gth-main.h
index 6c3592a..941030f 100644
--- a/gthumb/gth-main.h
+++ b/gthumb/gth-main.h
@@ -123,6 +123,11 @@ void                   gth_main_register_default_sort_types   (void);
 void                   gth_main_register_default_metadata     (void);
 void                   gth_main_activate_extensions           (void);
 
+/* utilities */
+
+gboolean               attribute_list_reaload_required        (const char *old_attributes,
+							       const char *new_attributes);
+
 G_END_DECLS
 
 #endif /* GTH_MAIN_H */



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