summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-08-05 13:23:29 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-08-05 13:23:29 +0200
commit1e8643259a915b05e010bebb6f28999e69e223d4 (patch)
tree38cc698042ba66b74a5fbcbf3dbd2684156989d2
parentd5e0af6abf7f9021094a55e00d885d05a209bef4 (diff)
downloadpianobar-1e8643259a915b05e010bebb6f28999e69e223d4.tar.gz
pianobar-1e8643259a915b05e010bebb6f28999e69e223d4.tar.bz2
pianobar-1e8643259a915b05e010bebb6f28999e69e223d4.zip
piano: Remember stations selected for quickmix
-rw-r--r--libpiano/src/xml.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index 55cb5fe..30f4c2e 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -292,6 +292,39 @@ PianoReturn_t PianoXmlParseUserinfo (PianoHandle_t *ph, const char *xml) {
return PIANO_RET_OK;
}
+void PianoXmlParseQuickMixStationsCb (const char *key, const xmlNode *value,
+ void *data) {
+ char ***retIds = data;
+ char **ids = NULL;
+ size_t idsN = 0;
+ xmlNode *curNode;
+
+ if (strcmp ("quickMixStationIds", key) == 0) {
+ for (curNode = value->children->children; curNode;
+ curNode = curNode->next) {
+ if (curNode->type == XML_ELEMENT_NODE &&
+ xmlStrEqual ((xmlChar *) "value", curNode->name)) {
+ idsN++;
+ if (ids == NULL) {
+ ids = calloc (idsN, sizeof (*ids));
+ } else {
+ ids = realloc (ids, idsN * sizeof (*ids));
+ }
+ ids[idsN-1] = strdup (PianoXmlGetNodeText (curNode));
+ }
+ }
+ /* append NULL: list ends here */
+ idsN++;
+ if (ids == NULL) {
+ ids = calloc (idsN, sizeof (*ids));
+ } else {
+ ids = realloc (ids, idsN * sizeof (*ids));
+ }
+ ids[idsN-1] = NULL;
+ }
+ *retIds = ids;
+}
+
/* parse stations returned by pandora
* @param piano handle
* @param xml returned by pandora
@@ -301,6 +334,7 @@ PianoReturn_t PianoXmlParseStations (PianoHandle_t *ph, const char *xml) {
xmlNode *docRoot, *curNode;
xmlDocPtr doc;
PianoReturn_t ret;
+ char **quickMixIds = NULL, **curQuickMixId = NULL;
if ((ret = PianoXmlInitDoc (xml, &doc, &docRoot)) != PIANO_RET_OK) {
return ret;
@@ -314,6 +348,11 @@ PianoReturn_t PianoXmlParseStations (PianoHandle_t *ph, const char *xml) {
PianoStation_t *tmpStation = calloc (1, sizeof (*tmpStation));
PianoXmlStructParser (curNode->children,
PianoXmlParseStationsCb, tmpStation);
+ /* get stations selected for quickmix */
+ if (tmpStation->isQuickMix) {
+ PianoXmlStructParser (curNode->children,
+ PianoXmlParseQuickMixStationsCb, &quickMixIds);
+ }
/* start new linked list or append */
if (ph->stations == NULL) {
ph->stations = tmpStation;
@@ -326,6 +365,18 @@ PianoReturn_t PianoXmlParseStations (PianoHandle_t *ph, const char *xml) {
}
}
}
+ /* set quickmix flags after all stations are read */
+ curQuickMixId = quickMixIds;
+ while (*curQuickMixId != NULL) {
+ PianoStation_t *curStation = PianoFindStationById (ph->stations,
+ *curQuickMixId);
+ if (curStation != NULL) {
+ curStation->useQuickMix = 1;
+ }
+ free (*curQuickMixId);
+ curQuickMixId++;
+ }
+ free (quickMixIds);
xmlFreeDoc (doc);
return PIANO_RET_OK;