From e0cf6984b61a936e36f5c683f5cac8b1c092b9da Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Sep 2009 20:15:54 +0200 Subject: [PATCH] mpdclient: replaced error_callback with imported function Instead of having a GList of callback functions, call mpdclient_ui_error(), which is exported by screen_client.c. --- src/main.c | 13 ------------- src/mpdclient.c | 19 +------------------ src/mpdclient.h | 13 ++++++------- src/screen_client.c | 11 +++++++++++ 4 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/main.c b/src/main.c index 0cbe184..3874d11 100644 --- a/src/main.c +++ b/src/main.c @@ -66,18 +66,6 @@ static guint reconnect_source_id, update_source_id; static guint check_key_bindings_source_id; #endif -static void -error_callback(G_GNUC_UNUSED struct mpdclient *c, G_GNUC_UNUSED gint error, - const gchar *_msg) -{ - char *msg = utf8_to_locale(_msg); - screen_status_printf("%s", msg); - g_free(msg); - - screen_bell(); - doupdate(); -} - #ifndef NCMPC_MINI static void update_xterm_title(void) @@ -441,7 +429,6 @@ main(int argc, const char *argv[]) /* create mpdclient instance */ mpd = mpdclient_new(); - mpdclient_install_error_callback(mpd, error_callback); /* initialize curses */ screen_init(mpd); diff --git a/src/mpdclient.c b/src/mpdclient.c index 2d65985..152942e 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -118,11 +118,7 @@ mpdclient_handle_error(struct mpdclient *c) if (error == MPD_ERROR_SERVER) error = error | (mpd_connection_get_server_error(c->connection) << 8); - for (GList *list = c->error_callbacks; list != NULL; - list = list->next) { - mpdc_error_cb_t cb = list->data; - cb(c, error, mpd_connection_get_error_message(c->connection)); - } + mpdclient_ui_error(mpd_connection_get_error_message(c->connection)); if (!mpd_connection_clear_error(c->connection)) mpdclient_disconnect(c); @@ -156,7 +152,6 @@ mpdclient_free(struct mpdclient *c) mpdclient_playlist_free(&c->playlist); - g_list_free(c->error_callbacks); g_list_free(c->playlist_callbacks); g_list_free(c->browse_callbacks); g_free(c); @@ -584,18 +579,6 @@ mpdclient_remove_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb) c->browse_callbacks = g_list_remove(c->browse_callbacks, cb); } -void -mpdclient_install_error_callback(struct mpdclient *c, mpdc_error_cb_t cb) -{ - c->error_callbacks = g_list_append(c->error_callbacks, cb); -} - -void -mpdclient_remove_error_callback(struct mpdclient *c, mpdc_error_cb_t cb) -{ - c->error_callbacks = g_list_remove(c->error_callbacks, cb); -} - /****************************************************************************/ /*** Playlist management functions ******************************************/ diff --git a/src/mpdclient.h b/src/mpdclient.h index 4723acf..41890da 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -12,7 +12,6 @@ struct mpdclient { struct mpdclient_playlist playlist; /* Callbacks */ - GList *error_callbacks; GList *playlist_callbacks; GList *browse_callbacks; @@ -50,6 +49,12 @@ mpdclient_disconnect(struct mpdclient *c); bool mpdclient_update(struct mpdclient *c); +/** + * To be implemented by the application: mpdclient.c calls this to + * display an error message. + */ +void +mpdclient_ui_error(const char *message); /*** MPD Commands **********************************************************/ gint mpdclient_cmd_play(struct mpdclient *c, gint index); @@ -77,14 +82,8 @@ GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8); /*** error callbacks *****************************************************/ -#define IS_ACK_ERROR(n) (n & MPD_ERROR_ACK) #define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8) -typedef void (*mpdc_error_cb_t) (struct mpdclient *c, gint error, const gchar *msg); - -void mpdclient_install_error_callback(struct mpdclient *c, mpdc_error_cb_t cb); -void mpdclient_remove_error_callback(struct mpdclient *c, mpdc_error_cb_t cb); - /*** playlist functions **************************************************/ /* update the complete playlist */ diff --git a/src/screen_client.c b/src/screen_client.c index f94ada1..d442cab 100644 --- a/src/screen_client.c +++ b/src/screen_client.c @@ -56,6 +56,17 @@ screen_auth(struct mpdclient *c) return _screen_auth(c, 0); } +void +mpdclient_ui_error(const char *message_utf8) +{ + char *message_locale = utf8_to_locale(message_utf8); + screen_status_printf("%s", message_locale); + g_free(message_locale); + + screen_bell(); + doupdate(); +} + void screen_database_update(struct mpdclient *c, const char *path) { -- 2.30.2