Mercurial > audlegacy-plugins
comparison src/xspf/xspf.c @ 1669:e1985da23d28
And yet more cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 08 Sep 2007 04:39:38 +0300 |
parents | 4c088a45f839 |
children | ae9b0327b620 62e89e392227 |
comparison
equal
deleted
inserted
replaced
1668:4c088a45f839 | 1669:e1985da23d28 |
---|---|
155 } else { | 155 } else { |
156 isMeta = FALSE; | 156 isMeta = FALSE; |
157 findName = xmlStrdup(nptr->name); | 157 findName = xmlStrdup(nptr->name); |
158 } | 158 } |
159 | 159 |
160 for (i = 0; i < xspf_nentries; i++) { | 160 for (i = 0; i < xspf_nentries; i++) |
161 if ((xspf_entries[i].isMeta == isMeta) && | 161 if ((xspf_entries[i].isMeta == isMeta) && |
162 !xmlStrcmp(findName, (xmlChar *)xspf_entries[i].xspfName)) { | 162 !xmlStrcmp(findName, (xmlChar *)xspf_entries[i].xspfName)) { |
163 xmlChar *str = xmlNodeGetContent(nptr); | 163 xmlChar *str = xmlNodeGetContent(nptr); |
164 switch (xspf_entries[i].type) { | 164 switch (xspf_entries[i].type) { |
165 case TUPLE_STRING: | 165 case TUPLE_STRING: |
166 tuple_associate_string(tuple, xspf_entries[i].tupleName, (gchar *)str); | 166 tuple_associate_string(tuple, xspf_entries[i].tupleName, (gchar *)str); |
167 break; | 167 break; |
168 | 168 |
169 case TUPLE_INT: | 169 case TUPLE_INT: |
170 tuple_associate_int(tuple, xspf_entries[i].tupleName, atol((char *)str)); | 170 tuple_associate_int(tuple, xspf_entries[i].tupleName, atol((char *)str)); |
171 break; | 171 break; |
172 | 172 |
173 default: | 173 default: |
174 /* FIXME! error! */ | 174 break; |
175 break; | |
176 } | |
177 xmlFree(str); | |
178 break; | |
179 } | 175 } |
176 xmlFree(str); | |
177 break; | |
180 } | 178 } |
181 | 179 |
182 xmlFree(findName); | 180 xmlFree(findName); |
183 } | 181 } |
184 } | 182 } |
353 | 351 |
354 | 352 |
355 static void xspf_playlist_save(const gchar *filename, gint pos) | 353 static void xspf_playlist_save(const gchar *filename, gint pos) |
356 { | 354 { |
357 xmlDocPtr doc; | 355 xmlDocPtr doc; |
358 xmlNodePtr rootnode, tmp, tracklist; | 356 xmlNodePtr rootnode, tracklist; |
359 GList *node; | 357 GList *node; |
360 gint baselen = 0; | 358 gint baselen = 0; |
361 gchar *base = NULL; | 359 gchar *base = NULL; |
362 Playlist *playlist = playlist_get_active(); | 360 Playlist *playlist = playlist_get_active(); |
363 | 361 |
386 | 384 |
387 if (!is_uri(entry->filename)) { //obsolete | 385 if (!is_uri(entry->filename)) { //obsolete |
388 gchar *tmp2; | 386 gchar *tmp2; |
389 tmp2 = g_path_get_dirname(entry->filename); | 387 tmp2 = g_path_get_dirname(entry->filename); |
390 tmp = g_strdup_printf("%s/", tmp2); | 388 tmp = g_strdup_printf("%s/", tmp2); |
391 g_free(tmp2); tmp2 = NULL; | 389 g_free(tmp2); |
392 } | 390 } else { |
393 else { //uri | |
394 tmp = g_strdup(entry->filename); | 391 tmp = g_strdup(entry->filename); |
395 } | 392 } |
396 | 393 |
397 if(!base) { | 394 if(!base) { |
398 base = strdup(tmp); | 395 base = strdup(tmp); |
440 printf("base is not uri. something is wrong.\n"); | 437 printf("base is not uri. something is wrong.\n"); |
441 #endif | 438 #endif |
442 tmp = g_strdup_printf("file://%s", base); | 439 tmp = g_strdup_printf("file://%s", base); |
443 xmlSetProp(rootnode, (xmlChar *)"xml:base", (xmlChar *)tmp); | 440 xmlSetProp(rootnode, (xmlChar *)"xml:base", (xmlChar *)tmp); |
444 g_free(tmp); | 441 g_free(tmp); |
445 tmp = NULL; | |
446 } | 442 } |
447 else | 443 else |
448 xmlSetProp(rootnode, (xmlChar *)"xml:base", (xmlChar *)base); | 444 xmlSetProp(rootnode, (xmlChar *)"xml:base", (xmlChar *)base); |
449 } | 445 } |
450 } /* USE_RELATIVE */ | 446 } /* USE_RELATIVE */ |
451 | 447 |
452 /* common */ | 448 /* common */ |
453 xmlDocSetRootElement(doc, rootnode); | 449 xmlDocSetRootElement(doc, rootnode); |
454 | 450 |
455 tmp = xmlNewNode(NULL, (xmlChar *)"creator"); | 451 xspf_add_node(rootnode, TUPLE_STRING, FALSE, "creator", PACKAGE "-" VERSION, 0); |
456 xmlAddChild(tmp, xmlNewText((xmlChar *)PACKAGE "-" VERSION)); | |
457 xmlAddChild(rootnode, tmp); | |
458 | 452 |
459 /* add staticlist marker */ | 453 /* add staticlist marker */ |
460 if (playlist->attribute & PLAYLIST_STATIC) { | 454 if (playlist->attribute & PLAYLIST_STATIC) { |
461 xmlNodePtr extension, options; | 455 xmlNodePtr extension, options; |
462 | 456 |
470 xmlAddChild(rootnode, extension); | 464 xmlAddChild(rootnode, extension); |
471 } | 465 } |
472 | 466 |
473 /* save playlist title */ | 467 /* save playlist title */ |
474 if (playlist->title && playlist->title[0] && | 468 if (playlist->title && playlist->title[0] && |
475 g_utf8_validate(playlist->title, -1, NULL)) { | 469 g_utf8_validate(playlist->title, -1, NULL)) |
476 xmlNodePtr title; | 470 xspf_add_node(rootnode, TUPLE_STRING, FALSE, "title", playlist->title, 0); |
477 title = xmlNewNode(NULL, (xmlChar *)"title"); | 471 |
478 xmlAddChild(title, xmlNewText((xmlChar *)playlist->title)); | |
479 xmlAddChild(rootnode, title); | |
480 } | |
481 | 472 |
482 tracklist = xmlNewNode(NULL, (xmlChar *)"trackList"); | 473 tracklist = xmlNewNode(NULL, (xmlChar *)"trackList"); |
483 xmlAddChild(rootnode, tracklist); | 474 xmlAddChild(rootnode, tracklist); |
484 | 475 |
485 for(node = playlist->entries; node != NULL; node = g_list_next(node)) { | 476 for(node = playlist->entries; node != NULL; node = g_list_next(node)) { |
516 | 507 |
517 xmlAddChild(location, xmlNewText((xmlChar *)filename)); | 508 xmlAddChild(location, xmlNewText((xmlChar *)filename)); |
518 xmlAddChild(track, location); | 509 xmlAddChild(track, location); |
519 xmlAddChild(tracklist, track); | 510 xmlAddChild(tracklist, track); |
520 | 511 |
521 /* do we have a tuple? */ | 512 /* Do we have a tuple? */ |
522 if (entry->tuple != NULL) { | 513 if (entry->tuple != NULL) { |
523 gint i; | 514 gint i; |
524 for (i = 0; i < xspf_nentries; i++) { | 515 for (i = 0; i < xspf_nentries; i++) { |
525 const xspf_entry_t *xs = &xspf_entries[i]; | 516 const xspf_entry_t *xs = &xspf_entries[i]; |
526 gboolean isOK = FALSE; | 517 gboolean isOK = FALSE; |
550 | 541 |
551 if (isOK) | 542 if (isOK) |
552 xspf_add_node(track, xs->type, xs->isMeta, xs->xspfName, scratch, scratchi); | 543 xspf_add_node(track, xs->type, xs->isMeta, xs->xspfName, scratch, scratchi); |
553 } | 544 } |
554 | 545 |
555 // mtime: write mtime unconditionally to support staticlist. | 546 /* Write mtime unconditionally to support staticlist */ |
556 xspf_add_node(track, TUPLE_INT, TRUE, "mtime", NULL, tuple_get_int(entry->tuple, "mtime")); | 547 xspf_add_node(track, TUPLE_INT, TRUE, "mtime", NULL, tuple_get_int(entry->tuple, "mtime")); |
557 } else { | 548 } else { |
558 | 549 |
559 if (entry->title != NULL && g_utf8_validate(entry->title, -1, NULL)) | 550 if (entry->title != NULL && g_utf8_validate(entry->title, -1, NULL)) |
560 xspf_add_node(track, TUPLE_STRING, FALSE, "title", entry->title, 0); | 551 xspf_add_node(track, TUPLE_STRING, FALSE, "title", entry->title, 0); |
561 | 552 |
562 if (entry->length > 0) | 553 if (entry->length > 0) |
563 xspf_add_node(track, TUPLE_INT, FALSE, "duration", NULL, entry->length); | 554 xspf_add_node(track, TUPLE_INT, FALSE, "duration", NULL, entry->length); |
564 | 555 |
565 /* add mtime of -1 */ | 556 /* Add mtime of -1 */ |
566 xspf_add_node(track, TUPLE_INT, TRUE, "mtime", NULL, -1); | 557 xspf_add_node(track, TUPLE_INT, TRUE, "mtime", NULL, -1); |
567 } | 558 } |
568 | 559 |
569 g_free(filename); | 560 g_free(filename); |
570 filename = NULL; | 561 filename = NULL; |