From a4d68831c9dbd3a060775170459cd040066d352d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Mar 2017 22:51:46 +0100 Subject: [PATCH] mpdclient: convert UTF-8 error message to locale charset Provide a consistent, documented API. --- src/callbacks.c | 8 ++------ src/callbacks.h | 2 ++ src/mpdclient.c | 11 ++++++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/callbacks.c b/src/callbacks.c index e122682..90eb409 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -21,7 +21,6 @@ #include "screen_utils.h" #include "screen_status.h" #include "mpdclient.h" -#include "charset.h" static bool _mpdclient_auth_callback(struct mpdclient *c, gint recursion) @@ -58,12 +57,9 @@ mpdclient_auth_callback(struct mpdclient *c) } void -mpdclient_error_callback(const char *message_utf8) +mpdclient_error_callback(const char *message) { - char *message_locale = utf8_to_locale(message_utf8); - screen_status_printf("%s", message_locale); - g_free(message_locale); - + screen_status_message(message); screen_bell(); doupdate(); } diff --git a/src/callbacks.h b/src/callbacks.h index 6100508..4fa472f 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -29,6 +29,8 @@ struct mpdclient; /** * To be implemented by the application: mpdclient.c calls this to * display an error message. + * + * @param message a human-readable error message in the locale charset */ void mpdclient_error_callback(const char *message); diff --git a/src/mpdclient.c b/src/mpdclient.c index c8351d1..4c480d7 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -22,16 +22,25 @@ #include "filelist.h" #include "config.h" #include "gidle.h" +#include "charset.h" #include #include static void -mpdclient_invoke_error_callback(gcc_unused enum mpd_error error, +mpdclient_invoke_error_callback(enum mpd_error error, const char *message) { + char *allocated; + if (error == MPD_ERROR_SERVER) + /* server errors are UTF-8, the others are locale */ + message = allocated = utf8_to_locale(message); + else + allocated = NULL; + mpdclient_error_callback(message); + g_free(allocated); } /****************************************************************************/ -- 2.30.2