Code

filelist: filelist_find_song() returns position instead of pointer
authorMax Kellermann <max@duempel.org>
Tue, 18 Nov 2008 20:51:28 +0000 (21:51 +0100)
committerMax Kellermann <max@duempel.org>
Tue, 18 Nov 2008 20:51:28 +0000 (21:51 +0100)
Making the function return the index makes it more flexible: those who
want the pointer can use filelist_get(), and the others may use the
index for other purposes.

src/filelist.c
src/filelist.h
src/screen_browser.c

index 415eec4021a6038c5def9f96a1d05b6871e52f5f..2e078635ad230a54e04db2c33fe611307068294a 100644 (file)
@@ -118,7 +118,7 @@ filelist_sort(struct filelist *filelist, GCompareFunc compare_func)
                                   compare_func);
 }
 
-struct filelist_entry *
+int
 filelist_find_song(struct filelist *fl, const struct mpd_song *song)
 {
        guint i;
@@ -133,11 +133,11 @@ filelist_find_song(struct filelist *fl, const struct mpd_song *song)
                        struct mpd_song *song2 = entity->info.song;
 
                        if (strcmp(song->file, song2->file) == 0)
-                               return entry;
+                               return i;
                }
        }
 
-       return NULL;
+       return -1;
 }
 
 int
index d7d4dff888ba107bbbccb76506ab86d355b216db..bc467fb65bb45ad1746b10a44485e8c4e6e8fb19 100644 (file)
@@ -73,7 +73,7 @@ filelist_move(struct filelist *filelist, struct filelist *from);
 void
 filelist_sort(struct filelist *filelist, GCompareFunc compare_func);
 
-struct filelist_entry *
+int
 filelist_find_song(struct filelist *flist, const struct mpd_song *song);
 
 int
index b5ce64171721baec8d445eb660313eb5ea8a41cb..6a5bbd2331f549b57edb25b3e645e0bbc24a29b2 100644 (file)
@@ -56,11 +56,13 @@ clear_highlights(mpdclient_filelist_t *fl)
 static void
 set_highlight(mpdclient_filelist_t *fl, mpd_Song *song, int highlight)
 {
-       struct filelist_entry *entry = filelist_find_song(fl, song);
+       int i = filelist_find_song(fl, song);
+       struct filelist_entry *entry;
 
-       if (entry == NULL)
+       if (i < 0)
                return;
 
+       entry = filelist_get(fl, i);
        if (highlight)
                entry->flags |= HIGHLIGHT;
        else