Code

mpdclient: removed several functions
authorMax Kellermann <max@duempel.org>
Thu, 1 Oct 2009 21:05:27 +0000 (23:05 +0200)
committerMax Kellermann <max@duempel.org>
Thu, 1 Oct 2009 21:05:27 +0000 (23:05 +0200)
Make the code use libmpdclient directly.

src/mpdclient.c
src/mpdclient.h
src/screen_browser.c
src/screen_file.c
src/screen_play.c

index 9efb5b5a5fc81702c6a61b0b6bcec0e04fc5fe7c..de9f648e12ca3c48025f97009ef65d4610862146 100644 (file)
@@ -314,13 +314,6 @@ mpdclient_cmd_crop(struct mpdclient *c)
        return mpdclient_finish_command(c);
 }
 
-gint
-mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end)
-{
-       mpd_send_shuffle_range(c->connection, start, end);
-       return mpdclient_finish_command(c);
-}
-
 gint
 mpdclient_cmd_clear(struct mpdclient *c)
 {
@@ -639,47 +632,6 @@ mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index)
        return 0;
 }
 
-gint
-mpdclient_cmd_save_playlist(struct mpdclient *c, const gchar *filename_utf8)
-{
-       gint retval = 0;
-
-       if (MPD_ERROR(c))
-               return -1;
-
-       mpd_send_save(c->connection, filename_utf8);
-       if ((retval = mpdclient_finish_command(c)) == 0) {
-               c->events |= MPD_IDLE_STORED_PLAYLIST;
-       }
-
-       return retval;
-}
-
-gint
-mpdclient_cmd_load_playlist(struct mpdclient *c, const gchar *filename_utf8)
-{
-       if (MPD_ERROR(c))
-               return -1;
-
-       mpd_send_load(c->connection, filename_utf8);
-       return mpdclient_finish_command(c);
-}
-
-gint
-mpdclient_cmd_delete_playlist(struct mpdclient *c, const gchar *filename_utf8)
-{
-       gint retval = 0;
-
-       if (MPD_ERROR(c))
-               return -1;
-
-       mpd_send_rm(c->connection, filename_utf8);
-       if ((retval = mpdclient_finish_command(c)) == 0)
-               c->events |= MPD_IDLE_STORED_PLAYLIST;
-
-       return retval;
-}
-
 
 /****************************************************************************/
 /*** Playlist management functions ******************************************/
index b06c7a042679d97dde9e6e059057cfb8bb5b4c7f..8a1db5944dbc83ca16ceded0622bbde58558d8d8 100644 (file)
@@ -71,7 +71,6 @@ mpdclient_ui_error(const char *message);
 gint mpdclient_cmd_play(struct mpdclient *c, gint index);
 gint
 mpdclient_cmd_crop(struct mpdclient *c);
-gint mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end);
 gint mpdclient_cmd_clear(struct mpdclient *c);
 gint mpdclient_cmd_volume(struct mpdclient *c, gint value);
 gint mpdclient_cmd_volume_up(struct mpdclient *c);
@@ -86,19 +85,10 @@ mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
 
 gint mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
 
-gint mpdclient_cmd_save_playlist(struct mpdclient *c, const gchar *filename);
-gint mpdclient_cmd_load_playlist(struct mpdclient *c, const gchar *filename_utf8);
-gint mpdclient_cmd_delete_playlist(struct mpdclient *c, const gchar *filename_utf8);
-
 /* list functions */
 GList *mpdclient_get_artists(struct mpdclient *c);
 GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8);
 
-
-/*** error callbacks *****************************************************/
-
-#define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8)
-
 /*** playlist functions  **************************************************/
 
 /* update the complete playlist */
index deb9e48900d2086e3a9420043d0d68820353fad5..59769268170aa7907f544fffb02726349643fae8 100644 (file)
@@ -127,9 +127,13 @@ load_playlist(struct mpdclient *c, const struct mpd_playlist *playlist)
 {
        char *filename = utf8_to_locale(mpd_playlist_get_path(playlist));
 
-       if (mpdclient_cmd_load_playlist(c, mpd_playlist_get_path(playlist)) == 0)
+       if (mpd_run_load(c->connection, mpd_playlist_get_path(playlist))) {
                screen_status_printf(_("Loading playlist %s..."),
                                     g_basename(filename));
+               c->events |= MPD_IDLE_QUEUE;
+       } else
+               mpdclient_handle_error(c);
+
        g_free(filename);
        return true;
 }
index b4dc24d6d1a23a01231614fbc2c0e867221372bb..b36c265031ea35279f7b14c88293d2159b0eeca2 100644 (file)
@@ -224,8 +224,12 @@ handle_delete(struct mpdclient *c)
                        return 0;
                }
 
-               if (mpdclient_cmd_delete_playlist(c, mpd_playlist_get_path(playlist)))
-                       continue;
+               if (!mpd_run_rm(c->connection, mpd_playlist_get_path(playlist))) {
+                       mpdclient_handle_error(c);
+                       break;
+               }
+
+               c->events |= MPD_IDLE_STORED_PLAYLIST;
 
                /* translators: MPD deleted the playlist, as requested by the
                   user */
index 39fdf032d6fe1d8ba3a7056be571d4fa9c8f4042..aee7e600482806f63d65ad9698e0910a7e43eb7d 100644 (file)
@@ -277,7 +277,6 @@ int
 playlist_save(struct mpdclient *c, char *name, char *defaultname)
 {
        gchar *filename, *filename_utf8;
-       gint error;
 #ifndef NCMPC_MINI
        GCompletion *gcmp;
        GList *list = NULL;
@@ -325,15 +324,15 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
        /* send save command to mpd */
 
        filename_utf8 = locale_to_utf8(filename);
-       error = mpdclient_cmd_save_playlist(c, filename_utf8);
 
-       if (error) {
-               gint code = GET_ACK_ERROR_CODE(error);
-
-               if (code == MPD_SERVER_ERROR_EXIST) {
+       if (!mpd_run_save(c->connection, filename_utf8)) {
+               if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
+                   mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_EXIST) {
                        char *buf;
                        int key;
 
+                       mpd_connection_clear_error(c->connection);
+
                        buf = g_strdup_printf(_("Replace %s [%s/%s] ? "),
                                              filename, YES, NO);
                        key = tolower(screen_getch(buf));
@@ -346,26 +345,23 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
                                return -1;
                        }
 
-                       error = mpdclient_cmd_delete_playlist(c, filename_utf8);
-                       if (error) {
+                       if (!mpd_run_rm(c->connection, filename_utf8) ||
+                           !mpd_run_save(c->connection, filename_utf8)) {
+                               mpdclient_handle_error(c);
                                g_free(filename_utf8);
                                g_free(filename);
                                return -1;
                        }
-
-                       error = mpdclient_cmd_save_playlist(c, filename_utf8);
-                       if (error) {
-                               g_free(filename_utf8);
-                               g_free(filename);
-                               return error;
-                       }
                } else {
+                       mpdclient_handle_error(c);
                        g_free(filename_utf8);
                        g_free(filename);
                        return -1;
                }
        }
 
+       c->events |= MPD_IDLE_STORED_PLAYLIST;
+
        g_free(filename_utf8);
 
        /* success */
@@ -696,9 +692,11 @@ play_cmd(struct mpdclient *c, command_t cmd)
                        /* No range selection, shuffle all list. */
                        break;
 
-               if (mpdclient_cmd_shuffle_range(c, lw->selected_start, lw->selected_end+1) == 0)
+               if (mpd_run_shuffle_range(c->connection, lw->selected_start,
+                                         lw->selected_end + 1))
                        screen_status_message(_("Shuffled playlist"));
-
+               else
+                       mpdclient_handle_error(c);
                return true;
        }
        case CMD_LIST_MOVE_UP: