From e5be3d5c5377b1c3b0e1666fbbef455e0bf441a1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 1 Oct 2009 23:05:27 +0200 Subject: [PATCH] mpdclient: removed several functions Make the code use libmpdclient directly. --- src/mpdclient.c | 48 -------------------------------------------- src/mpdclient.h | 10 --------- src/screen_browser.c | 6 +++++- src/screen_file.c | 8 ++++++-- src/screen_play.c | 32 ++++++++++++++--------------- 5 files changed, 26 insertions(+), 78 deletions(-) diff --git a/src/mpdclient.c b/src/mpdclient.c index 9efb5b5..de9f648 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -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 ******************************************/ diff --git a/src/mpdclient.h b/src/mpdclient.h index b06c7a0..8a1db59 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -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 */ diff --git a/src/screen_browser.c b/src/screen_browser.c index deb9e48..5976926 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -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; } diff --git a/src/screen_file.c b/src/screen_file.c index b4dc24d..b36c265 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -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 */ diff --git a/src/screen_play.c b/src/screen_play.c index 39fdf03..aee7e60 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -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: -- 2.30.2