summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 422c8a8)
raw | patch | inline | side by side (parent: 422c8a8)
author | Max Kellermann <max@duempel.org> | |
Wed, 30 Sep 2009 18:15:54 +0000 (20:15 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 30 Sep 2009 18:15:54 +0000 (20:15 +0200) |
Instead of having a GList of callback functions, call
mpdclient_ui_error(), which is exported by screen_client.c.
mpdclient_ui_error(), which is exported by screen_client.c.
src/main.c | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history | |
src/screen_client.c | patch | blob | history |
diff --git a/src/main.c b/src/main.c
index 0cbe184bca87554ce95c9a114df8820bacf40698..3874d112a1832136a2ce468113a7d659304a8866 100644 (file)
--- a/src/main.c
+++ b/src/main.c
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)
/* 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 2d6598518086d5cd080d13aa949207a33a77a7aa..152942e011b97ea79d3ffb48fad82e9a1f6d8202 100644 (file)
--- a/src/mpdclient.c
+++ b/src/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);
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);
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 4723acfea191a3e526d3a1472743c30c78bac48a..41890daca65a8ffdcb196cd7ce4be2ad2a2a8d26 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
struct mpdclient_playlist playlist;
/* Callbacks */
- GList *error_callbacks;
GList *playlist_callbacks;
GList *browse_callbacks;
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);
/*** 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 f94ada1c9038f6c7114f5dc9ddb780cd5b35558d..d442cabc2f860887c435b60d51dda642459e2bb7 100644 (file)
--- a/src/screen_client.c
+++ b/src/screen_client.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)
{