summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-12 16:43:28 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-12 16:44:25 +0200
commitc5819e14350678efc1e2415191848e87f0f21f85 (patch)
treef4296a3f2275f5aa695dd626aa13027cfe36ca47
parent6d199669a9276053ee709210539b75435e19fa3c (diff)
parent682cd6f7d4dbd3b2d18a7b8c9e375f4143559fcd (diff)
downloadpianobar-windows-c5819e14350678efc1e2415191848e87f0f21f85.tar.gz
pianobar-windows-c5819e14350678efc1e2415191848e87f0f21f85.tar.bz2
pianobar-windows-c5819e14350678efc1e2415191848e87f0f21f85.zip
Merge branch 'deletestation'
-rw-r--r--libpiano/main.c36
-rw-r--r--libpiano/piano.h2
-rw-r--r--src/main.c19
3 files changed, 52 insertions, 5 deletions
diff --git a/libpiano/main.c b/libpiano/main.c
index 52d7a1b..17bef4b 100644
--- a/libpiano/main.c
+++ b/libpiano/main.c
@@ -84,6 +84,18 @@ void PianoDestroySearchResult (PianoSearchResult_t *searchResult) {
}
}
+/* free single station
+ * @author PromyLOPh
+ * @added 2008-06-12
+ * @public yes
+ * @param station
+ */
+void PianoDestroyStation (PianoStation_t *station) {
+ free (station->name);
+ free (station->id);
+ memset (station, 0, sizeof (station));
+}
+
/* free complete station list
* @author PromyLOPh
* @added 2008-06-09
@@ -94,11 +106,9 @@ void PianoDestroyStations (PianoHandle_t *ph) {
curStation = ph->stations;
while (curStation != NULL) {
- free (curStation->name);
- free (curStation->id);
lastStation = curStation;
curStation = curStation->next;
- memset (lastStation, 0, sizeof (*lastStation));
+ PianoDestroyStation (lastStation);
free (lastStation);
}
ph->stations = NULL;
@@ -374,7 +384,25 @@ PianoReturn_t PianoDeleteStation (PianoHandle_t *ph, PianoStation_t *station) {
PianoHttpPost (ph->curlHandle, url, requestStr, &retStr);
ret = PianoXmlParseSimple (retStr);
- /* FIXME would be our job to delete station from global station list... */
+ if (ret == PIANO_RET_OK) {
+ /* delete station from local station list */
+ PianoStation_t *curStation = ph->stations, *lastStation = NULL;
+ while (curStation != NULL) {
+ if (curStation == station) {
+ printf ("deleting station\n");
+ if (lastStation != NULL) {
+ lastStation->next = curStation->next;
+ } else {
+ /* first station in list */
+ ph->stations = curStation->next;
+ }
+ PianoDestroyStation (curStation);
+ free (curStation);
+ }
+ lastStation = curStation;
+ curStation = curStation->next;
+ }
+ }
free (requestStr);
free (retStr);
diff --git a/libpiano/piano.h b/libpiano/piano.h
index bbe0a9e..9f2f7d7 100644
--- a/libpiano/piano.h
+++ b/libpiano/piano.h
@@ -145,6 +145,8 @@ void PianoInit (PianoHandle_t *);
void PianoDestroy (PianoHandle_t *);
void PianoDestroyPlaylist (PianoHandle_t *ph);
void PianoDestroySearchResult (PianoSearchResult_t *searchResult);
+void PianoDestroyStation (PianoStation_t *station);
+void PianoDestroyStations (PianoHandle_t *ph);
void PianoConnect (PianoHandle_t *, char *, char *);
void PianoGetStations (PianoHandle_t *ph);
diff --git a/src/main.c b/src/main.c
index 8b06ed6..a032be3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -274,7 +274,7 @@ int main (int argc, char **argv) {
/* in the meantime: wait for user actions */
while (!player.finishedPlayback) {
struct pollfd polls = {fileno (stdin), POLLIN, POLLIN};
- char buf;
+ char buf, yesnoBuf;
char *lineBuf;
if (poll (&polls, 1, 1000) > 0) {
@@ -296,6 +296,23 @@ int main (int argc, char **argv) {
PianoDestroyPlaylist (&ph);
break;
+ case 'd':
+ printf ("Really delete \"%s\"? [yn]\n",
+ curStation->name);
+ read (fileno (stdin), &yesnoBuf, sizeof (yesnoBuf));
+ if (yesnoBuf == 'y') {
+ if (PianoDeleteStation (&ph, curStation) ==
+ PIANO_RET_OK) {
+ player.doQuit = 1;
+ printf ("Deleted.\n");
+ PianoDestroyPlaylist (&ph);
+ curStation = selectStation (&ph);
+ } else {
+ printf ("Error while deleting station.\n");
+ }
+ }
+ break;
+
case 'l':
if (curSong->rating == PIANO_RATE_LOVE) {
printf ("Already loved. No need to do this twice.\n");