summaryrefslogtreecommitdiffabout
path: root/src/idop.c
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-11 09:42:16 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-07-11 10:00:48 (GMT)
commit892d9b1f21b131c2d7fad21c441e4aa47e8e15d6 (patch) (side-by-side diff)
treea40926451727b0ef64bf5a8bfd67663a64b56667 /src/idop.c
parentc3052454045484d22ba4d94722016162c222fb17 (diff)
downloadidest-892d9b1f21b131c2d7fad21c441e4aa47e8e15d6.tar.gz
idest-892d9b1f21b131c2d7fad21c441e4aa47e8e15d6.tar.bz2
Accept language and class specs when setting comment fields.
* src/idest.h (set_frame_value): Change signature. * src/idop.c (set_frame_value): Change signature. Set lang and class for comment fields, if supplied. (update_frame): New function. Introduces special handling for comment fields. (set_tags): Call update_frame. * src/main.c (ed_list_add_assignment): Accept language and class specs for comment fields (--set comment:lang:class=value). * NEWS: Update.
Diffstat (limited to 'src/idop.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/idop.c74
1 files changed, 55 insertions, 19 deletions
diff --git a/src/idop.c b/src/idop.c
index 5eb2609..96e196d 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -19,13 +19,15 @@
#include <signal.h>
void
-set_frame_value(struct id3_frame *frame, const char *value)
+set_frame_value(struct id3_frame *frame, const struct ed_item *item)
{
+ const char *value = item->v.value;
union id3_field *field;
enum id3_field_textencoding encoding =
(latin1_option ? ID3_FIELD_TEXTENCODING_ISO_8859_1
: ID3_FIELD_TEXTENCODING_UTF_8);
id3_ucs4_t *ucs4;
+ const char *class;
switch (frame_id(frame->id)) {
case item_title:
@@ -53,8 +55,19 @@ set_frame_value(struct id3_frame *frame, const char *value)
/* Field 0: Encoding */
field = id3_frame_field(frame, 0);
id3_field_settextencoding(field, encoding);
- /* FIXME: Field 1: Language */
- /* FIXME: Field 2: Short descr */
+ /* Field 1: Language */
+ field = id3_frame_field(frame, 1);
+ id3_field_setlanguage(field, item->lang ? item->lang : "eng");
+ /* Field 2: Short descr */
+ field = id3_frame_field(frame, 2);
+ class = item->class ? item->class : "";
+ if (latin1_option)
+ ucs4 = id3_latin1_ucs4duplicate(
+ (const id3_latin1_t *)class);
+ else
+ ucs4 = id3_utf8_ucs4duplicate(
+ (const id3_utf8_t *)class);
+ id3_field_setstring(field, ucs4);
/* Field 3: Comment */
field = id3_frame_field(frame, 3);
if (latin1_option)
@@ -87,6 +100,44 @@ safe_id3_file_update_and_close(struct id3_file *file)
sigprocmask(SIG_SETMASK, &oldset, NULL);
}
+static void
+update_frame(struct id3_tag *tag, const struct ed_item *item)
+{
+ struct id3_frame *frame = id3_tag_findframe(tag, item->id, 0);
+ if (!frame) {
+ frame = id3_frame_new(item->id);
+ if (id3_tag_attachframe(tag, frame))
+ error(1, 0, "cannot attach new frame");
+ } else if (strcmp(item->id, ID3_FRAME_COMMENT) == 0
+ && item->class) {
+ /* Special handling for comments */
+ int i = 0;
+ union id3_field *field;
+
+ do {
+ union id3_field *field = id3_frame_field(frame, 2);
+ char *s;
+
+ if (field && (s = field_to_string(field, 0))
+ && strcmp(s, item->class) == 0)
+ break;
+ } while (frame = id3_tag_findframe(tag, item->id, ++i));
+ if (!frame) {
+ frame = id3_frame_new(item->id);
+ if (id3_tag_attachframe(tag, frame))
+ error(1, 0, "cannot attach new frame");
+ }
+ } else {
+ struct id3_frame *fp;
+
+ while (fp = id3_tag_findframe(tag, item->id, 1)) {
+ id3_tag_detachframe(tag, fp);
+ id3_frame_delete(fp);
+ }
+ }
+ set_frame_value(frame, item);
+}
+
void
set_tags(const char *name)
{
@@ -108,22 +159,7 @@ set_tags(const char *name)
itr = gl_list_iterator(ed_list);
while (gl_list_iterator_next(&itr, &p, NULL)) {
const struct ed_item *item = p;
- struct id3_frame *frame
- = id3_tag_findframe(tag, item->id, 0);
- if (!frame) {
- frame = id3_frame_new(item->id);
- if (id3_tag_attachframe(tag, frame))
- error(1, 0, "cannot attach new frame");
- } else {
- struct id3_frame *fp;
-
- while (fp = id3_tag_findframe(tag, item->id,
- 1)) {
- id3_tag_detachframe(tag, fp);
- id3_frame_delete(fp);
- }
- }
- set_frame_value(frame, item->v.value);
+ update_frame(tag, item);
modified |= 1;
}
gl_list_iterator_free(&itr);

Return to:

Send suggestions and report system problems to the System administrator.