[gthumb: 7/20] added option to avoid to store metadata in files
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 7/20] added option to avoid to store metadata in files
- Date: Tue, 30 Mar 2010 19:32:43 +0000 (UTC)
commit 4d258f32df46b056c867b495e47bd741c2475456
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Mar 28 17:24:43 2010 +0200
added option to avoid to store metadata in files
[bug #533819]
data/gthumb.schemas.in | 13 +++++
extensions/comments/gth-comment.c | 47 ++++++++++++++++++
extensions/comments/gth-comment.h | 7 ++-
.../comments/gth-metadata-provider-comment.c | 51 +++++---------------
extensions/comments/main.c | 12 +++++
.../exiv2_tools/gth-metadata-provider-exiv2.c | 3 +
gthumb/dlg-preferences.c | 3 +
gthumb/gth-metadata.c | 19 +++++++
gthumb/gth-metadata.h | 8 ++-
gthumb/gth-preferences.h | 2 +-
10 files changed, 121 insertions(+), 44 deletions(-)
---
diff --git a/data/gthumb.schemas.in b/data/gthumb.schemas.in
index 06db504..4008859 100644
--- a/data/gthumb.schemas.in
+++ b/data/gthumb.schemas.in
@@ -56,6 +56,19 @@
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/gthumb/general/store_metadata_in_files</key>
+ <applyto>/apps/gthumb/general/store_metadata_in_files</applyto>
+ <owner>gthumb</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short></short>
+ <long>
+ </long>
+ </locale>
+ </schema>
+
<!-- Browser -->
<schema>
diff --git a/extensions/comments/gth-comment.c b/extensions/comments/gth-comment.c
index 5544bce..a5c0ca3 100644
--- a/extensions/comments/gth-comment.c
+++ b/extensions/comments/gth-comment.c
@@ -579,3 +579,50 @@ gth_comment_get_time_as_exif_format (GthComment *comment)
return s;
}
+
+
+void
+gth_comment_update_general_attributes (GthFileData *file_data)
+{
+ const char *value;
+
+ value = g_file_info_get_attribute_string (file_data->info, "comment::note");
+ if (value != NULL)
+ set_attribute_from_string (file_data->info,
+ "general::description",
+ value,
+ NULL);
+
+ value = g_file_info_get_attribute_string (file_data->info, "comment::caption");
+ if (value != NULL)
+ set_attribute_from_string (file_data->info,
+ "general::title",
+ value,
+ NULL);
+
+ value = g_file_info_get_attribute_string (file_data->info, "comment::place");
+ if (value != NULL)
+ set_attribute_from_string (file_data->info,
+ "general::location",
+ value,
+ NULL);
+
+ if (g_file_info_has_attribute (file_data->info, "comment::rating")) {
+ char *v;
+
+ v = g_strdup_printf ("%d", g_file_info_get_attribute_int32 (file_data->info, "comment::rating"));
+ set_attribute_from_string (file_data->info, "general::rating", v, NULL);
+
+ g_free (v);
+ }
+
+ if (g_file_info_has_attribute (file_data->info, "comment::categories"))
+ g_file_info_set_attribute_object (file_data->info,
+ "general::tags",
+ g_file_info_get_attribute_object (file_data->info, "comment::categories"));
+
+ if (g_file_info_has_attribute (file_data->info, "comment::time"))
+ g_file_info_set_attribute_object (file_data->info,
+ "general::datetime",
+ g_file_info_get_attribute_object (file_data->info, "comment::time"));
+}
diff --git a/extensions/comments/gth-comment.h b/extensions/comments/gth-comment.h
index 93ef828..30ffb89 100644
--- a/extensions/comments/gth-comment.h
+++ b/extensions/comments/gth-comment.h
@@ -65,14 +65,14 @@ void gth_comment_set_place (GthComment *comment,
const char *value);
void gth_comment_set_rating (GthComment *comment,
int value);
-void gth_comment_clear_categories (GthComment *comment);
+void gth_comment_clear_categories (GthComment *comment);
void gth_comment_add_category (GthComment *comment,
const char *value);
-void gth_comment_reset_time (GthComment *comment);
+void gth_comment_reset_time (GthComment *comment);
void gth_comment_set_time_from_exif_format (GthComment *comment,
const char *value);
void gth_comment_set_time_from_time_t (GthComment *comment,
- time_t value);
+ time_t value);
const char * gth_comment_get_caption (GthComment *comment);
const char * gth_comment_get_note (GthComment *comment);
const char * gth_comment_get_place (GthComment *comment);
@@ -81,5 +81,6 @@ GPtrArray * gth_comment_get_categories (GthComment *comment);
GDate * gth_comment_get_date (GthComment *comment);
GthTime * gth_comment_get_time_of_day (GthComment *comment);
char * gth_comment_get_time_as_exif_format (GthComment *comment);
+void gth_comment_update_general_attributes (GthFileData *file_data);
#endif /* GTH_COMMENT_H */
diff --git a/extensions/comments/gth-metadata-provider-comment.c b/extensions/comments/gth-metadata-provider-comment.c
index 8fe6893..a1109ea 100644
--- a/extensions/comments/gth-metadata-provider-comment.c
+++ b/extensions/comments/gth-metadata-provider-comment.c
@@ -63,25 +63,6 @@ gth_metadata_provider_comment_can_write (GthMetadataProvider *self,
static void
-set_attribute_from_string (GFileInfo *info,
- const char *key,
- const char *raw,
- const char *formatted)
-{
- GthMetadata *metadata;
-
- metadata = g_object_new (GTH_TYPE_METADATA,
- "id", key,
- "raw", raw,
- "formatted", (formatted != NULL ? formatted : raw),
- NULL);
- g_file_info_set_attribute_object (info, key, G_OBJECT (metadata));
-
- g_object_unref (metadata);
-}
-
-
-static void
gth_metadata_provider_comment_read (GthMetadataProvider *self,
GthFileData *file_data,
const char *attributes)
@@ -99,32 +80,21 @@ gth_metadata_provider_comment_read (GthMetadataProvider *self,
matcher = g_file_attribute_matcher_new (attributes);
value = gth_comment_get_note (comment);
- if (value != NULL) {
+ if (value != NULL)
g_file_info_set_attribute_string (file_data->info, "comment::note", value);
- set_attribute_from_string (file_data->info, "general::description", value, NULL);
- }
value = gth_comment_get_caption (comment);
- if (value != NULL) {
+ if (value != NULL)
g_file_info_set_attribute_string (file_data->info, "comment::caption", value);
- set_attribute_from_string (file_data->info, "general::title", value, NULL);
- }
value = gth_comment_get_place (comment);
- if (value != NULL) {
+ if (value != NULL)
g_file_info_set_attribute_string (file_data->info, "comment::place", value);
- set_attribute_from_string (file_data->info, "general::location", value, NULL);
- }
-
- if (gth_comment_get_rating (comment) > 0) {
- char *v;
+ if (gth_comment_get_rating (comment) > 0)
g_file_info_set_attribute_int32 (file_data->info, "comment::rating", gth_comment_get_rating (comment));
- v = g_strdup_printf ("%d", gth_comment_get_rating (comment));
- set_attribute_from_string (file_data->info, "general::rating", v, NULL);
-
- g_free (v);
- }
+ else
+ g_file_info_remove_attribute (file_data->info, "comment::rating");
categories = gth_comment_get_categories (comment);
if (categories->len > 0) {
@@ -132,9 +102,11 @@ gth_metadata_provider_comment_read (GthMetadataProvider *self,
value = (GObject *) gth_string_list_new_from_ptr_array (categories);
g_file_info_set_attribute_object (file_data->info, "comment::categories", value);
- g_file_info_set_attribute_object (file_data->info, "general::tags", value);
+
g_object_unref (value);
}
+ else
+ g_file_info_remove_attribute (file_data->info, "comment::categories");
comment_time = gth_comment_get_time_as_exif_format (comment);
if (comment_time != NULL) {
@@ -146,11 +118,14 @@ gth_metadata_provider_comment_read (GthMetadataProvider *self,
else
formatted = g_strdup (comment_time);
set_attribute_from_string (file_data->info, "comment::time", comment_time, formatted);
- set_attribute_from_string (file_data->info, "general::datetime", comment_time, formatted);
g_free (formatted);
g_free (comment_time);
}
+ else
+ g_file_info_remove_attribute (file_data->info, "comment::time");
+
+ gth_comment_update_general_attributes (file_data);
g_file_attribute_matcher_unref (matcher);
g_object_unref (comment);
diff --git a/extensions/comments/main.c b/extensions/comments/main.c
index dc0f3bf..2d83a23 100644
--- a/extensions/comments/main.c
+++ b/extensions/comments/main.c
@@ -88,6 +88,18 @@ comments__read_metadata_ready_cb (GthFileData *file_data,
GthComment *comment;
GthStringList *categories;
+ if (! eel_gconf_get_boolean (PREF_STORE_METADATA_IN_FILES, TRUE)) {
+ /* if PREF_STORE_METADATA_IN_FILES is false, avoid to
+ * synchronize the .comment metadata because the embedded
+ * metadata is likely to be out-of-date.
+ * Give priority to the .comment metadata which, if present,
+ * is the most up-to-date. */
+
+ gth_comment_update_general_attributes (file_data);
+
+ return;
+ }
+
if (! eel_gconf_get_boolean (PREF_COMMENTS_SYNCHRONIZE, TRUE))
return;
diff --git a/extensions/exiv2_tools/gth-metadata-provider-exiv2.c b/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
index 0e1c995..fe86fa7 100644
--- a/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
+++ b/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
@@ -123,6 +123,9 @@ gth_metadata_provider_exiv2_write (GthMetadataProvider *self,
GError *error = NULL;
GObject *metadata;
+ if (! eel_gconf_get_boolean (PREF_STORE_METADATA_IN_FILES, TRUE))
+ return;
+
if (! exiv2_supports_writes (gth_file_data_get_mime_type (file_data)))
return;
diff --git a/gthumb/dlg-preferences.c b/gthumb/dlg-preferences.c
index 1e66a2d..8740cdd 100644
--- a/gthumb/dlg-preferences.c
+++ b/gthumb/dlg-preferences.c
@@ -80,6 +80,7 @@ apply_changes (DialogData *data)
eel_gconf_set_boolean (PREF_GO_TO_LAST_LOCATION, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("go_to_last_location_radiobutton"))));
eel_gconf_set_boolean (PREF_USE_STARTUP_LOCATION, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("use_startup_location_radiobutton"))));
+ eel_gconf_set_boolean (PREF_STORE_METADATA_IN_FILES, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("embed_metadata_checkbutton"))));
if (eel_gconf_get_boolean (PREF_USE_STARTUP_LOCATION, FALSE)) {
char *location;
@@ -269,6 +270,8 @@ dlg_preferences (GthBrowser *browser)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("ask_to_save_checkbutton")), eel_gconf_get_boolean (PREF_MSG_SAVE_MODIFIED_IMAGE, DEFAULT_MSG_SAVE_MODIFIED_IMAGE));
gtk_combo_box_set_active (GTK_COMBO_BOX (data->toolbar_style_combobox), eel_gconf_get_enum (PREF_UI_TOOLBAR_STYLE, GTH_TYPE_TOOLBAR_STYLE, GTH_TOOLBAR_STYLE_SYSTEM));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("embed_metadata_checkbutton")), eel_gconf_get_boolean (PREF_STORE_METADATA_IN_FILES, TRUE));
+
/* * browser */
gtk_combo_box_set_active (GTK_COMBO_BOX (data->thumbnail_size_combobox), get_idx_from_size (eel_gconf_get_integer (PREF_THUMBNAIL_SIZE, DEFAULT_THUMBNAIL_SIZE)));
diff --git a/gthumb/gth-metadata.c b/gthumb/gth-metadata.c
index e965c08..4666ee4 100644
--- a/gthumb/gth-metadata.c
+++ b/gthumb/gth-metadata.c
@@ -233,3 +233,22 @@ gth_metadata_info_dup (GthMetadataInfo *info)
return new_info;
}
+
+
+void
+set_attribute_from_string (GFileInfo *info,
+ const char *key,
+ const char *raw,
+ const char *formatted)
+{
+ GthMetadata *metadata;
+
+ metadata = g_object_new (GTH_TYPE_METADATA,
+ "id", key,
+ "raw", raw,
+ "formatted", (formatted != NULL ? formatted : raw),
+ NULL);
+ g_file_info_set_attribute_object (info, key, G_OBJECT (metadata));
+
+ g_object_unref (metadata);
+}
diff --git a/gthumb/gth-metadata.h b/gthumb/gth-metadata.h
index ad2390c..2234792 100644
--- a/gthumb/gth-metadata.h
+++ b/gthumb/gth-metadata.h
@@ -74,9 +74,13 @@ struct _GthMetadataClass {
GType gth_metadata_get_type (void);
GthMetadata * gth_metadata_new (void);
-const char * gth_metadata_get_raw (GthMetadata *metadata);
-const char * gth_metadata_get_formatted (GthMetadata *metadata);
+const char * gth_metadata_get_raw (GthMetadata *metadata);
+const char * gth_metadata_get_formatted (GthMetadata *metadata);
GthMetadataInfo * gth_metadata_info_dup (GthMetadataInfo *info);
+void set_attribute_from_string (GFileInfo *info,
+ const char *key,
+ const char *raw,
+ const char *formatted);
G_END_DECLS
diff --git a/gthumb/gth-preferences.h b/gthumb/gth-preferences.h
index 7f82cbf..03639fa 100644
--- a/gthumb/gth-preferences.h
+++ b/gthumb/gth-preferences.h
@@ -35,7 +35,7 @@ G_BEGIN_DECLS
#define PREF_USE_STARTUP_LOCATION "/apps/gthumb/general/use_startup_location"
#define PREF_STARTUP_LOCATION "/apps/gthumb/general/startup_location"
#define PREF_ACTIVE_EXTENSIONS "/apps/gthumb/general/active_extensions"
-
+#define PREF_STORE_METADATA_IN_FILES "/apps/gthumb/general/store_metadata_in_files"
#define PREF_GENERAL_FILTER "/apps/gthumb/browser/general_filter"
#define PREF_SHOW_HIDDEN_FILES "/apps/gthumb/browser/show_hidden_files"
#define PREF_SHOW_THUMBNAILS "/apps/gthumb/browser/show_thumbnails"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]