Code

playlist: make functions const
authorMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 20:14:20 +0000 (22:14 +0200)
committerMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 20:14:20 +0000 (22:14 +0200)
And return const mpd_song objects.

src/main.c
src/mpdclient.c
src/mpdclient.h
src/playlist.c
src/playlist.h
src/screen_lyrics.c

index 10706a55456b5e4dfc914d7c1dca3bbfcbe2b57d..fb5de59652f7eaed0ec40888ebbaffd37f0d7897 100644 (file)
@@ -85,7 +85,7 @@ update_xterm_title(void)
        static char title[BUFSIZE];
        char tmp[BUFSIZE];
        struct mpd_status *status = NULL;
-       struct mpd_song *song = NULL;
+       const struct mpd_song *song = NULL;
 
        if (mpd) {
                status = mpd->status;
index ac7fce93d045b16540a6b8f309b88f30cc18994c..cbc6a91fb0cc77d991aafd3858a4d329b1404588 100644 (file)
@@ -269,7 +269,7 @@ mpdclient_update(struct mpdclient *c)
 gint
 mpdclient_cmd_play(struct mpdclient *c, gint idx)
 {
-       struct mpd_song *song = playlist_get_song(&c->playlist, idx);
+       const struct mpd_song *song = playlist_get_song(&c->playlist, idx);
 
        if (MPD_ERROR(c))
                return -1;
index 52fcdb45eb9be8030abbb5e0300ecadc412f649f..e2b81c8212b9cb7d8789893b8003fd16320862ef 100644 (file)
@@ -18,7 +18,7 @@ struct mpdclient {
 
        struct mpd_connection *connection;
        struct mpd_status *status;
-       struct mpd_song *song;
+       const struct mpd_song *song;
 
        int volume;
        unsigned updatingdb;
index 562fde69e7b40932b8a1d98740578e9ff30e1886..5fced75f0c7c1041eb7d7280fb5a1e8f34676c62 100644 (file)
@@ -60,8 +60,8 @@ mpdclient_playlist_free(struct mpdclient_playlist *playlist)
        return 0;
 }
 
-struct mpd_song *
-playlist_get_song(struct mpdclient_playlist *playlist, gint idx)
+const struct mpd_song *
+playlist_get_song(const struct mpdclient_playlist *playlist, gint idx)
 {
        if (idx < 0 || (guint)idx >= playlist_length(playlist))
                return NULL;
@@ -69,8 +69,8 @@ playlist_get_song(struct mpdclient_playlist *playlist, gint idx)
        return playlist_get(playlist, idx);
 }
 
-struct mpd_song *
-playlist_lookup_song(struct mpdclient_playlist *playlist, unsigned id)
+const struct mpd_song *
+playlist_lookup_song(const struct mpdclient_playlist *playlist, unsigned id)
 {
        for (guint i = 0; i < playlist_length(playlist); ++i) {
                struct mpd_song *song = playlist_get(playlist, i);
index 580b1c98069d8fca9809c6cc5da1a35daf0a4644..cee91002f840f288d92602888958896fa7b549de 100644 (file)
@@ -119,11 +119,11 @@ playlist_swap(struct mpdclient_playlist *playlist, guint idx1, guint idx2)
        g_ptr_array_index(playlist->list, idx2) = song1;
 }
 
-struct mpd_song *
-playlist_lookup_song(struct mpdclient_playlist *playlist, unsigned id);
+const struct mpd_song *
+playlist_lookup_song(const struct mpdclient_playlist *playlist, unsigned id);
 
-struct mpd_song *
-playlist_get_song(struct mpdclient_playlist *playlist, gint index);
+const struct mpd_song *
+playlist_get_song(const struct mpdclient_playlist *playlist, gint index);
 
 gint
 playlist_get_index(const struct mpdclient_playlist *playlist,
index f9fdb81b643f76cab222c7a4d72b4005d9e483cc..abf1055661e827c8577c66bd65f2a9141873e97d 100644 (file)
@@ -202,16 +202,16 @@ lyrics_exit(void)
 static void
 lyrics_open(struct mpdclient *c)
 {
-       if (next_song == NULL)
-               next_song = c->song;
+       const struct mpd_song *next_song_c =
+               next_song != NULL ? next_song : c->song;
 
-       if (next_song != NULL &&
+       if (next_song_c != NULL &&
            (current.song == NULL ||
-            strcmp(mpd_song_get_uri(next_song),
+            strcmp(mpd_song_get_uri(next_song_c),
                    mpd_song_get_uri(current.song)) != 0))
-               screen_lyrics_load(next_song);
+               screen_lyrics_load(next_song_c);
 
-       if (next_song != c->song)
+       if (next_song != NULL)
                mpd_song_free(next_song);
        next_song = NULL;
 }
@@ -222,15 +222,11 @@ lyrics_update(struct mpdclient *c)
        if (!follow)
                return;
 
-       next_song = c->song;
-
-       if (next_song != NULL &&
+       if (c->song != NULL &&
            (current.song == NULL ||
-            strcmp(mpd_song_get_uri(next_song),
+            strcmp(mpd_song_get_uri(c->song),
                    mpd_song_get_uri(current.song)) != 0))
-               screen_lyrics_load(next_song);
-
-       next_song = NULL;
+               screen_lyrics_load(c->song);
 }
 
 static const char *