Mercurial > geeqie
annotate src/metadata.c @ 1203:43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
metadata immediately before writting is now possible
modified metadata are stored in fd->modified_xmp
author | nadvornik |
---|---|
date | Mon, 15 Dec 2008 22:47:31 +0000 |
parents | ef7530186597 |
children | fa91098e4949 |
rev | line source |
---|---|
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
1 /* |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
2 * Geeqie |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
3 * (C) 2004 John Ellis |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
4 * Copyright (C) 2008 The Geeqie Team |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
5 * |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
6 * Author: John Ellis, Laurent Monin |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
7 * |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
8 * This software is released under the GNU General Public License (GNU GPL). |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
9 * Please read the included file COPYING for more information. |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
10 * This software comes with no warranty of any kind, use at your own risk! |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
11 */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
12 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
13 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
14 #include "main.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
15 #include "metadata.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
16 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
17 #include "cache.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
18 #include "exif.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
19 #include "filedata.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
20 #include "misc.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
21 #include "secure_save.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
22 #include "ui_fileops.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
23 #include "ui_misc.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
24 #include "utilops.h" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
25 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
26 typedef enum { |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
27 MK_NONE, |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
28 MK_KEYWORDS, |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
29 MK_COMMENT |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
30 } MetadataKey; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
31 |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
32 |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
33 gint metadata_write_list(FileData *fd, const gchar *key, GList *values) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
34 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
35 if (!fd->modified_xmp) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
36 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
37 fd->modified_xmp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)string_list_free); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
38 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
39 g_hash_table_insert(fd->modified_xmp, g_strdup(key), values); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
40 if (fd->exif) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
41 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
42 exif_update_metadata(fd->exif, key, values); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
43 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
44 return TRUE; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
45 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
46 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
47 gint metadata_write_string(FileData *fd, const gchar *key, const char *value) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
48 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
49 return metadata_write_list(fd, key, g_list_append(NULL, g_strdup(value))); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
50 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
51 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
52 |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
53 /* |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
54 *------------------------------------------------------------------- |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
55 * keyword / comment read/write |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
56 *------------------------------------------------------------------- |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
57 */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
58 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
59 static gint metadata_file_write(gchar *path, GList *keywords, const gchar *comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
60 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
61 SecureSaveInfo *ssi; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
62 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
63 ssi = secure_open(path); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
64 if (!ssi) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
65 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
66 secure_fprintf(ssi, "#%s comment (%s)\n\n", GQ_APPNAME, VERSION); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
67 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
68 secure_fprintf(ssi, "[keywords]\n"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
69 while (keywords && secsave_errno == SS_ERR_NONE) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
70 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
71 const gchar *word = keywords->data; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
72 keywords = keywords->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
73 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
74 secure_fprintf(ssi, "%s\n", word); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
75 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
76 secure_fputc(ssi, '\n'); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
77 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
78 secure_fprintf(ssi, "[comment]\n"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
79 secure_fprintf(ssi, "%s\n", (comment) ? comment : ""); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
80 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
81 secure_fprintf(ssi, "#end\n"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
82 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
83 return (secure_close(ssi) == 0); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
84 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
85 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
86 static gint metadata_legacy_write(FileData *fd, GList *keywords, const gchar *comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
87 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
88 gchar *metadata_path; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
89 gint success = FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
90 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
91 /* If an existing metadata file exists, we will try writing to |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
92 * it's location regardless of the user's preference. |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
93 */ |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
94 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
95 if (metadata_path && !access_file(metadata_path, W_OK)) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
96 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
97 g_free(metadata_path); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
98 metadata_path = NULL; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
99 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
100 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
101 if (!metadata_path) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
102 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
103 gchar *metadata_dir; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
104 mode_t mode = 0755; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
105 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
106 metadata_dir = cache_get_location(CACHE_TYPE_METADATA, fd->path, FALSE, &mode); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
107 if (recursive_mkdir_if_not_exists(metadata_dir, mode)) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
108 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
109 gchar *filename = g_strconcat(fd->name, GQ_CACHE_EXT_METADATA, NULL); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
110 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
111 metadata_path = g_build_filename(metadata_dir, filename, NULL); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
112 g_free(filename); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
113 } |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
114 g_free(metadata_dir); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
115 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
116 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
117 if (metadata_path) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
118 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
119 gchar *metadata_pathl; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
120 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
121 DEBUG_1("Saving comment: %s", metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
122 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
123 metadata_pathl = path_from_utf8(metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
124 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
125 success = metadata_file_write(metadata_pathl, keywords, comment); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
126 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
127 g_free(metadata_pathl); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
128 g_free(metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
129 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
130 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
131 return success; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
132 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
133 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
134 static gint metadata_file_read(gchar *path, GList **keywords, gchar **comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
135 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
136 FILE *f; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
137 gchar s_buf[1024]; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
138 MetadataKey key = MK_NONE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
139 GList *list = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
140 GString *comment_build = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
141 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
142 f = fopen(path, "r"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
143 if (!f) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
144 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
145 while (fgets(s_buf, sizeof(s_buf), f)) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
146 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
147 gchar *ptr = s_buf; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
148 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
149 if (*ptr == '#') continue; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
150 if (*ptr == '[' && key != MK_COMMENT) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
151 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
152 gchar *keystr = ++ptr; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
153 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
154 key = MK_NONE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
155 while (*ptr != ']' && *ptr != '\n' && *ptr != '\0') ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
156 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
157 if (*ptr == ']') |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
158 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
159 *ptr = '\0'; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
160 if (g_ascii_strcasecmp(keystr, "keywords") == 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
161 key = MK_KEYWORDS; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
162 else if (g_ascii_strcasecmp(keystr, "comment") == 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
163 key = MK_COMMENT; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
164 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
165 continue; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
166 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
167 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
168 switch(key) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
169 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
170 case MK_NONE: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
171 break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
172 case MK_KEYWORDS: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
173 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
174 while (*ptr != '\n' && *ptr != '\0') ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
175 *ptr = '\0'; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
176 if (strlen(s_buf) > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
177 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
178 gchar *kw = utf8_validate_or_convert(s_buf); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
179 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
180 list = g_list_prepend(list, kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
181 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
182 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
183 break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
184 case MK_COMMENT: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
185 if (!comment_build) comment_build = g_string_new(""); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
186 g_string_append(comment_build, s_buf); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
187 break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
188 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
189 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
190 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
191 fclose(f); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
192 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
193 *keywords = g_list_reverse(list); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
194 if (comment_build) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
195 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
196 if (comment) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
197 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
198 gint len; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
199 gchar *ptr = comment_build->str; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
200 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
201 /* strip leading and trailing newlines */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
202 while (*ptr == '\n') ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
203 len = strlen(ptr); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
204 while (len > 0 && ptr[len - 1] == '\n') len--; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
205 if (ptr[len] == '\n') len++; /* keep the last one */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
206 if (len > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
207 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
208 gchar *text = g_strndup(ptr, len); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
209 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
210 *comment = utf8_validate_or_convert(text); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
211 g_free(text); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
212 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
213 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
214 g_string_free(comment_build, TRUE); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
215 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
216 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
217 return TRUE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
218 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
219 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
220 static gint metadata_legacy_delete(FileData *fd) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
221 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
222 gchar *metadata_path; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
223 gchar *metadata_pathl; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
224 gint success = FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
225 if (!fd) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
226 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
227 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
228 if (!metadata_path) return FALSE; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
229 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
230 metadata_pathl = path_from_utf8(metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
231 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
232 success = !unlink(metadata_pathl); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
233 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
234 g_free(metadata_pathl); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
235 g_free(metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
236 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
237 return success; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
238 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
239 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
240 static gint metadata_legacy_read(FileData *fd, GList **keywords, gchar **comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
241 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
242 gchar *metadata_path; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
243 gchar *metadata_pathl; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
244 gint success = FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
245 if (!fd) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
246 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
247 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
248 if (!metadata_path) return FALSE; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
249 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
250 metadata_pathl = path_from_utf8(metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
251 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
252 success = metadata_file_read(metadata_pathl, keywords, comment); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
253 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
254 g_free(metadata_pathl); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
255 g_free(metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
256 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
257 return success; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
258 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
259 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
260 static GList *remove_duplicate_strings_from_list(GList *list) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
261 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
262 GList *work = list; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
263 GHashTable *hashtable = g_hash_table_new(g_str_hash, g_str_equal); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
264 GList *newlist = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
265 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
266 while (work) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
267 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
268 gchar *key = work->data; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
269 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
270 if (g_hash_table_lookup(hashtable, key) == NULL) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
271 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
272 g_hash_table_insert(hashtable, (gpointer) key, GINT_TO_POINTER(1)); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
273 newlist = g_list_prepend(newlist, key); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
274 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
275 work = work->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
276 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
277 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
278 g_hash_table_destroy(hashtable); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
279 g_list_free(list); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
280 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
281 return g_list_reverse(newlist); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
282 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
283 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
284 #define COMMENT_KEY "Xmp.dc.description" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
285 #define KEYWORD_KEY "Xmp.dc.subject" |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
286 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
287 static gint metadata_xmp_read(FileData *fd, GList **keywords, gchar **comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
288 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
289 ExifData *exif; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
290 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
291 exif = exif_read_fd(fd); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
292 if (!exif) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
293 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
294 if (comment) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
295 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
296 gchar *text; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
297 ExifItem *item = exif_get_item(exif, COMMENT_KEY); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
298 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
299 text = exif_item_get_string(item, 0); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
300 *comment = utf8_validate_or_convert(text); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
301 g_free(text); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
302 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
303 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
304 if (keywords) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
305 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
306 ExifItem *item; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
307 guint i; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
308 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
309 *keywords = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
310 item = exif_get_item(exif, KEYWORD_KEY); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
311 for (i = 0; i < exif_item_get_elements(item); i++) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
312 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
313 gchar *kw = exif_item_get_string(item, i); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
314 gchar *utf8_kw; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
315 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
316 if (!kw) break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
317 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
318 utf8_kw = utf8_validate_or_convert(kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
319 *keywords = g_list_append(*keywords, (gpointer) utf8_kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
320 g_free(kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
321 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
322 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
323 /* FIXME: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
324 * Exiv2 handles Iptc keywords as multiple entries with the |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
325 * same key, thus exif_get_item returns only the first keyword |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
326 * and the only way to get all keywords is to iterate through |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
327 * the item list. |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
328 */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
329 for (item = exif_get_first_item(exif); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
330 item; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
331 item = exif_get_next_item(exif)) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
332 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
333 guint tag; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
334 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
335 tag = exif_item_get_tag_id(item); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
336 if (tag == 0x0019) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
337 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
338 gchar *tag_name = exif_item_get_tag_name(item); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
339 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
340 if (strcmp(tag_name, "Iptc.Application2.Keywords") == 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
341 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
342 gchar *kw; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
343 gchar *utf8_kw; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
344 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
345 kw = exif_item_get_data_as_text(item); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
346 if (!kw) continue; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
347 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
348 utf8_kw = utf8_validate_or_convert(kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
349 *keywords = g_list_append(*keywords, (gpointer) utf8_kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
350 g_free(kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
351 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
352 g_free(tag_name); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
353 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
354 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
355 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
356 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
357 exif_free_fd(fd, exif); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
358 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
359 return (comment && *comment) || (keywords && *keywords); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
360 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
361 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
362 static gint metadata_xmp_write(FileData *fd, GList *keywords, const gchar *comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
363 { |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
364 gint success = TRUE; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
365 gint write_comment = (comment && comment[0]); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
366 |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
367 if (write_comment) success = success && metadata_write_string(fd, COMMENT_KEY, comment); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
368 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
369 if (keywords) success = success && metadata_write_list(fd, KEYWORD_KEY, string_list_copy(keywords)); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
370 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
371 |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
372 /* FIXME - actual writting should be triggered in metadata_write_list and should be delayed */ |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
373 success = exif_write_fd(fd); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
374 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
375 return success; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
376 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
377 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
378 gint metadata_write(FileData *fd, GList *keywords, const gchar *comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
379 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
380 if (!fd) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
381 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
382 if (options->save_metadata_in_image_file && |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
383 metadata_xmp_write(fd, keywords, comment)) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
384 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
385 metadata_legacy_delete(fd); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
386 return TRUE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
387 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
388 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
389 return metadata_legacy_write(fd, keywords, comment); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
390 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
391 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
392 gint metadata_read(FileData *fd, GList **keywords, gchar **comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
393 { |
1194 | 394 GList *keywords_xmp = NULL; |
395 GList *keywords_legacy = NULL; | |
396 gchar *comment_xmp = NULL; | |
397 gchar *comment_legacy = NULL; | |
398 gint result_xmp, result_legacy; | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
399 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
400 if (!fd) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
401 |
1194 | 402 result_xmp = metadata_xmp_read(fd, &keywords_xmp, &comment_xmp); |
403 result_legacy = metadata_legacy_read(fd, &keywords_legacy, &comment_legacy); | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
404 |
1194 | 405 if (!result_xmp && !result_legacy) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
406 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
407 return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
408 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
409 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
410 if (keywords) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
411 { |
1194 | 412 if (result_xmp && result_legacy) |
413 *keywords = g_list_concat(keywords_xmp, keywords_legacy); | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
414 else |
1194 | 415 *keywords = result_xmp ? keywords_xmp : keywords_legacy; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
416 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
417 *keywords = remove_duplicate_strings_from_list(*keywords); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
418 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
419 else |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
420 { |
1194 | 421 if (result_xmp) string_list_free(keywords_xmp); |
422 if (result_legacy) string_list_free(keywords_legacy); | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
423 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
424 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
425 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
426 if (comment) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
427 { |
1194 | 428 if (result_xmp && result_legacy && comment_xmp && comment_legacy && *comment_xmp && *comment_legacy) |
429 *comment = g_strdup_printf("%s\n%s", comment_xmp, comment_legacy); | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
430 else |
1194 | 431 *comment = result_xmp ? comment_xmp : comment_legacy; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
432 } |
1194 | 433 |
434 if (result_xmp && (!comment || *comment != comment_xmp)) g_free(comment_xmp); | |
435 if (result_legacy && (!comment || *comment != comment_legacy)) g_free(comment_legacy); | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
436 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
437 // return FALSE in the following cases: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
438 // - only looking for a comment and didn't find one |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
439 // - only looking for keywords and didn't find any |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
440 // - looking for either a comment or keywords, but found nothing |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
441 if ((!keywords && comment && !*comment) || |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
442 (!comment && keywords && !*keywords) || |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
443 ( comment && !*comment && keywords && !*keywords)) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
444 return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
445 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
446 return TRUE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
447 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
448 |
1194 | 449 void metadata_set(FileData *fd, GList *new_keywords, gchar *new_comment, gboolean append) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
450 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
451 gchar *comment = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
452 GList *keywords = NULL; |
1194 | 453 GList *keywords_list = NULL; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
454 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
455 metadata_read(fd, &keywords, &comment); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
456 |
1194 | 457 if (new_comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
458 { |
1192
48d62a7e3c33
metadata_set_keywords() -> metadata_set(). Use gboolean type for boolean parameters.
zas_
parents:
1191
diff
changeset
|
459 if (append && comment && *comment) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
460 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
461 gchar *tmp = comment; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
462 |
1194 | 463 comment = g_strconcat(tmp, new_comment, NULL); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
464 g_free(tmp); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
465 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
466 else |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
467 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
468 g_free(comment); |
1194 | 469 comment = g_strdup(new_comment); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
470 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
471 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
472 |
1194 | 473 if (new_keywords) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
474 { |
1192
48d62a7e3c33
metadata_set_keywords() -> metadata_set(). Use gboolean type for boolean parameters.
zas_
parents:
1191
diff
changeset
|
475 if (append && keywords && g_list_length(keywords) > 0) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
476 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
477 GList *work; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
478 |
1194 | 479 work = new_keywords; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
480 while (work) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
481 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
482 gchar *key; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
483 GList *p; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
484 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
485 key = work->data; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
486 work = work->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
487 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
488 p = keywords; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
489 while (p && key) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
490 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
491 gchar *needle = p->data; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
492 p = p->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
493 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
494 if (strcmp(needle, key) == 0) key = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
495 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
496 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
497 if (key) keywords = g_list_append(keywords, g_strdup(key)); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
498 } |
1194 | 499 keywords_list = keywords; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
500 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
501 else |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
502 { |
1194 | 503 keywords_list = new_keywords; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
504 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
505 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
506 |
1194 | 507 metadata_write(fd, keywords_list, comment); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
508 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
509 string_list_free(keywords); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
510 g_free(comment); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
511 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
512 |
1193
aed0e28b2744
keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents:
1192
diff
changeset
|
513 gboolean find_string_in_list(GList *list, const gchar *string) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
514 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
515 while (list) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
516 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
517 gchar *haystack = list->data; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
518 |
1193
aed0e28b2744
keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents:
1192
diff
changeset
|
519 if (haystack && string && strcmp(haystack, string) == 0) return TRUE; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
520 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
521 list = list->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
522 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
523 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
524 return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
525 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
526 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
527 #define KEYWORDS_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '\n' || (c) == '\r' || (c) == '\b') |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
528 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
529 GList *string_to_keywords_list(const gchar *text) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
530 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
531 GList *list = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
532 const gchar *ptr = text; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
533 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
534 while (*ptr != '\0') |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
535 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
536 const gchar *begin; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
537 gint l = 0; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
538 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
539 while (KEYWORDS_SEPARATOR(*ptr)) ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
540 begin = ptr; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
541 while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr)) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
542 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
543 ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
544 l++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
545 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
546 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
547 /* trim starting and ending whitespaces */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
548 while (l > 0 && g_ascii_isspace(*begin)) begin++, l--; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
549 while (l > 0 && g_ascii_isspace(begin[l-1])) l--; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
550 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
551 if (l > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
552 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
553 gchar *keyword = g_strndup(begin, l); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
554 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
555 /* only add if not already in the list */ |
1193
aed0e28b2744
keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents:
1192
diff
changeset
|
556 if (find_string_in_list(list, keyword) == FALSE) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
557 list = g_list_append(list, keyword); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
558 else |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
559 g_free(keyword); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
560 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
561 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
562 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
563 return list; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
564 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
565 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
566 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |