From 92cf0efffffeb95fbefc57505d778e6fdbd772d4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 18 Sep 2008 23:35:12 +0200 Subject: [PATCH] screen_browser: moved code to browser_playlist_changed() Merge code from all 3 browser screens into one generic browser function. --- src/screen_artist.c | 15 ++------------- src/screen_browser.c | 31 +++++++++++++++++++++++++++++-- src/screen_browser.h | 10 +++++----- src/screen_file.c | 18 +----------------- src/screen_search.c | 14 ++------------ 5 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/screen_artist.c b/src/screen_artist.c index a839003..c5d5a26 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -84,20 +84,9 @@ artist_lw_callback(unsigned idx, mpd_unused int *highlight, mpd_unused void *dat /* the playlist have been updated -> fix highlights */ static void -playlist_changed_callback(mpdclient_t *c, int event, mpd_unused gpointer data) +playlist_changed_callback(mpdclient_t *c, int event, gpointer data) { - if (browser.filelist == NULL) - return; - - D("screen_artist.c> playlist_callback() [%d]\n", event); - switch(event) { - case PLAYLIST_EVENT_CLEAR: - clear_highlights(browser.filelist); - break; - default: - sync_highlights(c, browser.filelist); - break; - } + browser_playlist_changed(&browser, c, event, data); } /* fetch artists/albums/songs from mpd */ diff --git a/src/screen_browser.c b/src/screen_browser.c index 737b138..406d205 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -37,7 +37,7 @@ #define HIGHLIGHT (0x01) /* clear the highlight flag for all items in the filelist */ -void +static void clear_highlights(mpdclient_filelist_t *fl) { GList *list = g_list_first(fl->list); @@ -51,7 +51,7 @@ clear_highlights(mpdclient_filelist_t *fl) } /* change the highlight flag for a song */ -void +static void set_highlight(mpdclient_filelist_t *fl, mpd_Song *song, int highlight) { GList *list = g_list_first(fl->list); @@ -99,6 +99,33 @@ sync_highlights(mpdclient_t *c, mpdclient_filelist_t *fl) } } +/* the playlist have been updated -> fix highlights */ +void +browser_playlist_changed(struct screen_browser *browser, mpdclient_t *c, + int event, gpointer data) +{ + if (browser->filelist == NULL) + return; + + D("screen_file.c> playlist_callback() [%d]\n", event); + switch(event) { + case PLAYLIST_EVENT_CLEAR: + clear_highlights(browser->filelist); + break; + case PLAYLIST_EVENT_ADD: + set_highlight(browser->filelist, (mpd_Song *) data, 1); + break; + case PLAYLIST_EVENT_DELETE: + set_highlight(browser->filelist, (mpd_Song *) data, 0); + break; + case PLAYLIST_EVENT_MOVE: + break; + default: + sync_highlights(c, browser->filelist); + break; + } +} + /* list_window callback */ const char * browser_lw_callback(unsigned idx, int *highlight, void *data) diff --git a/src/screen_browser.h b/src/screen_browser.h index fbe131c..a867eda 100644 --- a/src/screen_browser.h +++ b/src/screen_browser.h @@ -36,12 +36,12 @@ struct screen_browser { mpdclient_filelist_t *filelist; }; -void clear_highlights(mpdclient_filelist_t *filelist); -void sync_highlights(mpdclient_t *c, mpdclient_filelist_t *filelist); -void set_highlight(mpdclient_filelist_t *filelist, - mpd_Song *song, - int highlight); +void +sync_highlights(mpdclient_t *c, mpdclient_filelist_t *fl); +void +browser_playlist_changed(struct screen_browser *browser, mpdclient_t *c, + int event, gpointer data); const char *browser_lw_callback(unsigned index, int *highlight, void *filelist); diff --git a/src/screen_file.c b/src/screen_file.c index 801c61f..ea20f95 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -53,23 +53,7 @@ file_changed_callback(mpdclient_t *c, mpd_unused int event, static void playlist_changed_callback(mpdclient_t *c, int event, gpointer data) { - D("screen_file.c> playlist_callback() [%d]\n", event); - switch(event) { - case PLAYLIST_EVENT_CLEAR: - clear_highlights(browser.filelist); - break; - case PLAYLIST_EVENT_ADD: - set_highlight(browser.filelist, (mpd_Song *) data, 1); - break; - case PLAYLIST_EVENT_DELETE: - set_highlight(browser.filelist, (mpd_Song *) data, 0); - break; - case PLAYLIST_EVENT_MOVE: - break; - default: - sync_highlights(c, browser.filelist); - break; - } + browser_playlist_changed(&browser, c, event, data); } static int diff --git a/src/screen_search.c b/src/screen_search.c index 365a23c..549221e 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -142,19 +142,9 @@ lw_search_help_callback(unsigned idx, mpd_unused int *highlight, /* the playlist have been updated -> fix highlights */ static void -playlist_changed_callback(mpdclient_t *c, int event, mpd_unused gpointer data) +playlist_changed_callback(mpdclient_t *c, int event, gpointer data) { - if (browser.filelist == NULL) - return; - D("screen_search.c> playlist_callback() [%d]\n", event); - switch(event) { - case PLAYLIST_EVENT_CLEAR: - clear_highlights(browser.filelist); - break; - default: - sync_highlights(c, browser.filelist); - break; - } + browser_playlist_changed(&browser, c, event, data); } /* sanity check search mode value */ -- 2.30.2