gthumb r2264 - in trunk: . libgthumb
- From: mjc svn gnome org
- To: svn-commits-list gnome org
- Subject: gthumb r2264 - in trunk: . libgthumb
- Date: Thu, 7 Feb 2008 01:02:31 +0000 (GMT)
Author: mjc
Date: Thu Feb 7 01:02:31 2008
New Revision: 2264
URL: http://svn.gnome.org/viewvc/gthumb?rev=2264&view=rev
Log:
2008-02-06 Michael J. Chudobiak <mjc svn gnome org>
* libgthumb/comments.c: (has_non_whitespace_comment),
(load_comment_from_metadata), (save_comment_to_metadata):
* libgthumb/gth-exif-utils.c:
* libgthumb/gth-exiv2-utils.cpp:
Made comment metadata reading/writing a bit more robust.
Modified:
trunk/ChangeLog
trunk/libgthumb/comments.c
trunk/libgthumb/gth-exif-utils.c
trunk/libgthumb/gth-exiv2-utils.cpp
Modified: trunk/libgthumb/comments.c
==============================================================================
--- trunk/libgthumb/comments.c (original)
+++ trunk/libgthumb/comments.c Thu Feb 7 01:02:31 2008
@@ -362,6 +362,24 @@
}
+static gboolean
+has_non_whitespace_comment (const char *text_in)
+{
+ gchar *pos;
+
+ if (text_in == NULL)
+ return FALSE;
+
+ for (pos = (char *) text_in; *pos != 0; pos = g_utf8_next_char (pos)) {
+ gunichar ch = g_utf8_get_char (pos);
+ if (!g_unichar_isspace (ch))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
static CommentData *
load_comment_from_metadata (const char *uri)
{
@@ -376,47 +394,54 @@
data = comment_data_new ();
metadata_string = get_metadata_tagset_string (file, TAG_NAME_SETS[COMMENT_TAG_NAMES]);
- if ((metadata_string != NULL) && (metadata_string[0] != 0)) {
+ if (has_non_whitespace_comment (metadata_string))
data->comment = g_strdup (metadata_string);
- g_free (metadata_string);
- }
+ g_free (metadata_string);
metadata_string = get_metadata_tagset_string (file, TAG_NAME_SETS[LOCATION_TAG_NAMES]);
- if ((metadata_string != NULL) && (metadata_string[0] != 0)) {
+ if (has_non_whitespace_comment (metadata_string))
data->place = g_strdup (metadata_string);
- g_free (metadata_string);
- }
+ g_free (metadata_string);
metadata_time = get_metadata_time_from_fd (file, TAG_NAME_SETS[COMMENT_DATE_TAG_NAMES]);
if (metadata_time > (time_t) 0)
data->time = metadata_time;
metadata_string = get_metadata_tagset_string (file, TAG_NAME_SETS[KEYWORD_TAG_NAMES]);
- if ((metadata_string != NULL) && (metadata_string[0] != 0)) {
+ if (has_non_whitespace_comment (metadata_string)) {
char **keywords_v;
int i = 0;
+ int j = 0;
comment_data_free_keywords (data);
- /* TODO - FIXME - check for all-whitespace keywords */
-
keywords_v = g_strsplit (metadata_string, ",", 0);
- while (keywords_v[i] != NULL) {
- i++;
+ while (keywords_v[j] != NULL) {
+ if (has_non_whitespace_comment (keywords_v[j])) {
+ i++;
+ }
+ j++;
}
data->keywords_n = i;
data->keywords = g_new0 (char*, data->keywords_n + 1);
- for (i = 0; i < data->keywords_n; i++)
- data->keywords[i] = g_strdup (keywords_v[i]);
+ i = 0;
+ j = 0;
+ while (keywords_v[j] != NULL) {
+ if (has_non_whitespace_comment (keywords_v[j])) {
+ data->keywords[i] = g_strdup (keywords_v[j]);
+ i++;
+ }
+ j++;
+ }
data->keywords[i] = NULL;
g_strfreev (keywords_v);
- g_free (metadata_string);
}
+ g_free (metadata_string);
file_data_unref (file);
return data;
@@ -449,7 +474,6 @@
tm.tm_sec );
add_metadata = simple_add_metadata (add_metadata, TAG_NAME_SETS[COMMENT_DATE_TAG_NAMES][0], buf);
- /* TODO - FIXME - check for all-whitespace keywords */
if (data->keywords_n > 0) {
if (data->keywords_n == 1)
keywords_str = g_strdup (data->keywords[0]);
Modified: trunk/libgthumb/gth-exif-utils.c
==============================================================================
--- trunk/libgthumb/gth-exif-utils.c (original)
+++ trunk/libgthumb/gth-exif-utils.c Thu Feb 7 01:02:31 2008
@@ -135,7 +135,7 @@
NULL };
const char *_KEYWORD_TAG_NAMES[] = {
- "Xmp.dc.subject",
+ "Xmp.iptc.Keywords",
"Iptc.Application2.Keywords",
NULL };
Modified: trunk/libgthumb/gth-exiv2-utils.cpp
==============================================================================
--- trunk/libgthumb/gth-exiv2-utils.cpp (original)
+++ trunk/libgthumb/gth-exiv2-utils.cpp Thu Feb 7 01:02:31 2008
@@ -589,22 +589,25 @@
// Load existing metadata
image1->readMetadata();
+ Exiv2::ExifData &ed = image1->exifData();
+ Exiv2::IptcData &id = image1->iptcData();
+#ifdef HAVE_EXIV2_XMP_HPP
+ Exiv2::XmpData &xd = image1->xmpData();
+#endif
+
for (scan = metadata_in; scan; scan = scan->next) {
// Update the requested tag
GthMetadata *metadatum = (GthMetadata *) scan->data;
if (metadatum->full_name != NULL) {
if (g_str_has_prefix (metadatum->full_name, "Exif")) {
- Exiv2::ExifData &md = image1->exifData();
- md[metadatum->full_name] = metadatum->raw_value;
+ ed[metadatum->full_name] = metadatum->raw_value;
}
else if (g_str_has_prefix (metadatum->full_name, "Iptc")) {
- Exiv2::IptcData &md = image1->iptcData();
- md[metadatum->full_name] = metadatum->raw_value;
+ id[metadatum->full_name] = metadatum->raw_value;
}
#ifdef HAVE_EXIV2_XMP_HPP
else if (g_str_has_prefix (metadatum->full_name, "Xmp")) {
- Exiv2::XmpData &md = image1->xmpData();
- md[metadatum->full_name] = metadatum->raw_value;
+ xd[metadatum->full_name] = metadatum->raw_value;
}
#endif
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]