Code

mpdclient: convert UTF-8 error message to locale charset
authorMax Kellermann <max.kellermann@gmail.com>
Fri, 17 Mar 2017 21:51:46 +0000 (22:51 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Fri, 17 Mar 2017 22:07:02 +0000 (23:07 +0100)
Provide a consistent, documented API.

src/callbacks.c
src/callbacks.h
src/mpdclient.c

index e12268227586640528e63cf7232913c2dea9bb55..90eb40923001281ba7eb3a1d9936b8eb175f335d 100644 (file)
@@ -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();
 }
index 610050895c346ab905bced0de0d268a5dc2fe6a1..4fa472fc406802e4168b7c717b1613a22bdf3b38 100644 (file)
@@ -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);
index c8351d14cb1526365975875ae10d2520179feeb8..4c480d781357a72d961a854514d4258cc78954f0 100644 (file)
 #include "filelist.h"
 #include "config.h"
 #include "gidle.h"
+#include "charset.h"
 
 #include <mpd/client.h>
 
 #include <assert.h>
 
 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);
 }
 
 /****************************************************************************/