Code

mpdclient: move code to mpdclient_invoke_error_callback()
[ncmpc.git] / src / mpdclient.c
index 164a08dd927e40b121072929610ef875125c9c1d..c8351d14cb1526365975875ae10d2520179feeb8 100644 (file)
  */
 
 #include "mpdclient.h"
+#include "callbacks.h"
 #include "filelist.h"
-#include "screen_client.h"
 #include "config.h"
-#include "options.h"
-#include "strfsong.h"
-#include "utils.h"
 #include "gidle.h"
 
 #include <mpd/client.h>
 
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <string.h>
+#include <assert.h>
 
-#define BUFSIZE 1024
-
-/* sort by song format */
-gint
-compare_filelistentry_format(gconstpointer filelist_entry1,
-                            gconstpointer filelist_entry2,
-                            const char *song_format)
+static void
+mpdclient_invoke_error_callback(gcc_unused enum mpd_error error,
+                               const char *message)
 {
-       const struct mpd_entity *e1 =
-               ((const struct filelist_entry *)filelist_entry1)->entity;
-       const struct mpd_entity *e2 =
-               ((const struct filelist_entry *)filelist_entry2)->entity;
-
-       int n = 0;
-       if (e1 && e2 &&
-           mpd_entity_get_type(e1) == MPD_ENTITY_TYPE_SONG &&
-           mpd_entity_get_type(e2) == MPD_ENTITY_TYPE_SONG) {
-               char key1[BUFSIZE], key2[BUFSIZE];
-               strfsong(key1, BUFSIZE, song_format, mpd_entity_get_song(e1));
-               strfsong(key2, BUFSIZE, song_format, mpd_entity_get_song(e2));
-               n = strcmp(key1,key2);
-       }
-
-       return n;
+       mpdclient_error_callback(message);
 }
 
-
 /****************************************************************************/
 /*** mpdclient functions ****************************************************/
 /****************************************************************************/
@@ -73,10 +47,11 @@ mpdclient_handle_error(struct mpdclient *c)
 
        if (error == MPD_ERROR_SERVER &&
            mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PERMISSION &&
-           screen_auth(c))
+           mpdclient_auth_callback(c))
                return true;
 
-       mpdclient_ui_error(mpd_connection_get_error_message(c->connection));
+       mpdclient_invoke_error_callback(error,
+                                       mpd_connection_get_error_message(c->connection));
 
        if (!mpd_connection_clear_error(c->connection))
                mpdclient_disconnect(c);
@@ -162,6 +137,9 @@ mpdclient_connect(struct mpdclient *c,
                return false;
        }
 
+       c->source = mpd_glib_new(c->connection,
+                                mpdclient_idle_callback, c);
+
        ++c->connection_id;
 
        return true;