[gthumb] fixed the "save only modified fields" option in the comment dialog



commit d06283ce49b4c3b56b115639da03301b74307332
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Aug 24 13:38:29 2010 +0200

    fixed the "save only modified fields" option in the comment dialog
    
    [bug #627439]

 extensions/edit_metadata/gth-edit-comment-page.c |    2 +-
 extensions/exiv2_tools/gth-edit-exiv2-page.c     |    2 +-
 gthumb/gth-file-data.c                           |   37 ++++++++++++++++++++++
 gthumb/gth-file-data.h                           |    3 ++
 4 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/extensions/edit_metadata/gth-edit-comment-page.c b/extensions/edit_metadata/gth-edit-comment-page.c
index 5b91fd9..02caa63 100644
--- a/extensions/edit_metadata/gth-edit-comment-page.c
+++ b/extensions/edit_metadata/gth-edit-comment-page.c
@@ -281,7 +281,7 @@ gth_edit_comment_page_real_update_info (GthEditMetadataPage *base,
 	/* rating */
 
 	s = g_strdup_printf ("%d", gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("rating_spinbutton"))));
-	if (! only_modified_fields || ! gth_file_data_attribute_equal (file_data, "general::rating", s)) {
+	if (! only_modified_fields || ! gth_file_data_attribute_equal_int (file_data, "general::rating", s)) {
 		if (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("rating_spinbutton"))) > 0) {
 			metadata = g_object_new (GTH_TYPE_METADATA,
 						 "id", "general::rating",
diff --git a/extensions/exiv2_tools/gth-edit-exiv2-page.c b/extensions/exiv2_tools/gth-edit-exiv2-page.c
index c6cc8c0..bc7158d 100644
--- a/extensions/exiv2_tools/gth-edit-exiv2-page.c
+++ b/extensions/exiv2_tools/gth-edit-exiv2-page.c
@@ -167,7 +167,7 @@ gth_edit_exiv2_page_real_update_info (GthEditMetadataPage *base,
 
 	v = gtk_adjustment_get_value (GTK_ADJUSTMENT (GET_WIDGET ("urgency_adjustment")));
 	s = g_strdup_printf ("%1.g", v);
-	if (! only_modified_fields || ! gth_file_data_attribute_equal (file_data, "Iptc::Application2::Urgency", s)) {
+	if (! only_modified_fields || ! gth_file_data_attribute_equal_int (file_data, "Iptc::Application2::Urgency", s)) {
 		GthMetadata *metadata;
 
 		metadata = g_object_new (GTH_TYPE_METADATA,
diff --git a/gthumb/gth-file-data.c b/gthumb/gth-file-data.c
index 75fdbf7..9071e11 100644
--- a/gthumb/gth-file-data.c
+++ b/gthumb/gth-file-data.c
@@ -577,7 +577,44 @@ gth_file_data_attribute_equal (GthFileData *file_data,
 	char     *v;
 	gboolean  result;
 
+	/* a NULL pointer is equal to an empty string. */
+
+	if (g_strcmp0 (value, "") == 0)
+		value = NULL;
+
+	v = gth_file_data_get_attribute_as_string (file_data, attribute);
+	if (g_strcmp0 (v, "") == 0) {
+		g_free (v);
+		v = NULL;
+	}
+
+	result = g_strcmp0 (v, value) == 0;
+
+	g_free (v);
+
+	return result;
+}
+
+
+gboolean
+gth_file_data_attribute_equal_int (GthFileData *file_data,
+				   const char  *attribute,
+				   const char  *value)
+{
+	char     *v;
+	gboolean  result;
+
+	/* a NULL pointer or an empty string is equal to 0. */
+
+	if ((g_strcmp0 (value, "") == 0) || (value == NULL))
+		value = "0";
+
 	v = gth_file_data_get_attribute_as_string (file_data, attribute);
+	if ((g_strcmp0 (v, "") == 0) || (v == NULL)) {
+		g_free (v);
+		v = g_strdup ("0");
+	}
+
 	result = g_strcmp0 (v, value) == 0;
 
 	g_free (v);
diff --git a/gthumb/gth-file-data.h b/gthumb/gth-file-data.h
index 349f517..8b23006 100644
--- a/gthumb/gth-file-data.h
+++ b/gthumb/gth-file-data.h
@@ -108,6 +108,9 @@ GFileInfo *   gth_file_data_list_get_common_info    (GList          *file_data_l
 gboolean      gth_file_data_attribute_equal         (GthFileData    *file_data,
 						     const char     *attribute,
 						     const char     *value);
+gboolean      gth_file_data_attribute_equal_int     (GthFileData    *file_data,
+				   	   	     const char     *attribute,
+				   	   	     const char     *value);
 gboolean      gth_file_data_attribute_equal_string_list
 						    (GthFileData    *file_data,
 						     const char     *attribute,



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