summaryrefslogtreecommitdiff
path: root/src/ui_act.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2013-08-04 18:53:43 +0200
committerLars-Dominik Braun <lars@6xq.net>2013-08-07 17:37:33 +0200
commitee2e73cd7b5a1de68c8316e916c4ef3a88302bed (patch)
treee952d75d075598123d5ecbe92f14838ce75f6db5 /src/ui_act.c
parent36ea2f13f87b9310219790c3cee498201d54f8e0 (diff)
downloadpianobar-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.tar.gz
pianobar-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.tar.bz2
pianobar-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.zip
piano: Generic linked lists
Introduces generic linked list structure and functions (like append, delete, …). Removes a lot of copy&pasted code and improves code readability/reusability. Heads up: This change breaks libpiano’s ABI.
Diffstat (limited to 'src/ui_act.c')
-rw-r--r--src/ui_act.c37
1 files changed, 13 insertions, 24 deletions
diff --git a/src/ui_act.c b/src/ui_act.c
index 270c1f5..8cf6c2b 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -232,7 +232,8 @@ BarUiActCallback(BarUiActDeleteStation) {
if (BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_STATION,
selStation) && selStation == app->curStation) {
BarUiDoSkipSong (&app->player);
- PianoDestroyPlaylist (app->playlist->next);
+ PianoDestroyPlaylist (PianoListNextP (app->playlist));
+ app->playlist->head.next = NULL;
BarUiHistoryPrepend (app, app->playlist);
app->playlist = NULL;
app->curStation = NULL;
@@ -283,10 +284,9 @@ BarUiActCallback(BarUiActStationFromGenre) {
/* print all available categories */
curCat = app->ph.genreStations;
i = 0;
- while (curCat != NULL) {
+ PianoListForeachP (curCat) {
BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curCat->name);
i++;
- curCat = curCat->next;
}
do {
@@ -295,20 +295,15 @@ BarUiActCallback(BarUiActStationFromGenre) {
if (BarReadlineInt (&i, &app->input) == 0) {
return;
}
- curCat = app->ph.genreStations;
- while (curCat != NULL && i > 0) {
- curCat = curCat->next;
- i--;
- }
+ curCat = PianoListGetP (app->ph.genreStations, i);
} while (curCat == NULL);
/* print all available stations */
- curGenre = curCat->genres;
i = 0;
- while (curGenre != NULL) {
+ curGenre = curCat->genres;
+ PianoListForeachP (curGenre) {
BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curGenre->name);
i++;
- curGenre = curGenre->next;
}
do {
@@ -316,11 +311,7 @@ BarUiActCallback(BarUiActStationFromGenre) {
if (BarReadlineInt (&i, &app->input) == 0) {
return;
}
- curGenre = curCat->genres;
- while (curGenre != NULL && i > 0) {
- curGenre = curGenre->next;
- i--;
- }
+ curGenre = PianoListGetP (curCat->genres, i);
} while (curGenre == NULL);
/* create station */
@@ -477,7 +468,8 @@ BarUiActCallback(BarUiActSelectStation) {
BarUiPrintStation (&app->settings, app->curStation);
BarUiDoSkipSong (&app->player);
if (app->playlist != NULL) {
- PianoDestroyPlaylist (app->playlist->next);
+ PianoDestroyPlaylist (PianoListNextP (app->playlist));
+ app->playlist->head.next = NULL;
BarUiHistoryPrepend (app, app->playlist);
app->playlist = NULL;
}
@@ -505,7 +497,7 @@ BarUiActCallback(BarUiActTempBanSong) {
BarUiActCallback(BarUiActPrintUpcoming) {
assert (selSong != NULL);
- PianoSong_t *nextSong = selSong->next;
+ PianoSong_t *nextSong = PianoListNextP (selSong);
if (nextSong != NULL) {
BarUiListSongs (&app->settings, nextSong, NULL);
} else {
@@ -527,27 +519,24 @@ static void BarUiActQuickmixCallback (BarApp_t *app, char *buf) {
switch (*buf) {
case 't':
/* toggle */
- while (curStation != NULL) {
+ PianoListForeachP (curStation) {
curStation->useQuickMix = !curStation->useQuickMix;
- curStation = curStation->next;
}
*buf = '\0';
break;
case 'a':
/* enable all */
- while (curStation != NULL) {
+ PianoListForeachP (curStation) {
curStation->useQuickMix = true;
- curStation = curStation->next;
}
*buf = '\0';
break;
case 'n':
/* enable none */
- while (curStation != NULL) {
+ PianoListForeachP (curStation) {
curStation->useQuickMix = false;
- curStation = curStation->next;
}
*buf = '\0';
break;