From 541ffa3a791a6ba615fbca3b5dff39de2674009e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 29 Sep 2009 20:57:27 +0200 Subject: [PATCH] screen_file: moved update code to screen_client.c Moved code from screen_file.c and player_command.c. --- src/player_command.c | 7 ++----- src/screen_client.c | 26 ++++++++++++++++++++++++++ src/screen_client.h | 7 +++++++ src/screen_file.c | 15 ++------------- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/player_command.c b/src/player_command.c index dab3d52..678d13a 100644 --- a/src/player_command.c +++ b/src/player_command.c @@ -22,6 +22,7 @@ #include "options.h" #include "screen.h" #include "i18n.h" +#include "screen_client.h" #define IS_PLAYING(s) (s==MPD_STATE_PLAY) #define IS_PAUSED(s) (s==MPD_STATE_PAUSE) @@ -159,11 +160,7 @@ handle_player_command(struct mpdclient *c, command_t cmd) mpdclient_cmd_crossfade(c, options.crossfade_time); break; case CMD_DB_UPDATE: - if (!mpd_status_get_update_id(c->status)) { - if( mpdclient_cmd_db_update(c,NULL)==0 ) - screen_status_printf(_("Database update started")); - } else - screen_status_printf(_("Database update running...")); + screen_database_update(c, NULL); break; case CMD_VOLUME_UP: mpdclient_cmd_volume_up(c); diff --git a/src/screen_client.c b/src/screen_client.c index 7583e8a..b5b31b5 100644 --- a/src/screen_client.c +++ b/src/screen_client.c @@ -19,7 +19,10 @@ #include "screen_client.h" #include "screen_utils.h" +#include "screen.h" #include "mpdclient.h" +#include "i18n.h" +#include "charset.h" static bool _screen_auth(struct mpdclient *c, gint recursion) @@ -52,3 +55,26 @@ screen_auth(struct mpdclient *c) { return _screen_auth(c, 0); } + +void +screen_database_update(struct mpdclient *c, const char *path) +{ + assert(c != NULL); + assert(c->connection != NULL); + assert(c->status != NULL); + + if (mpd_status_get_update_id(c->status) != 0) { + screen_status_printf(_("Database update running...")); + return; + } + + if (mpdclient_cmd_db_update(c, path) != 0) + return; + + if (path != NULL && *path != 0) { + char *path_locale = utf8_to_locale(path); + screen_status_printf(_("Database update of %s started"), path); + g_free(path_locale); + } else + screen_status_message(_("Database update started")); +} diff --git a/src/screen_client.h b/src/screen_client.h index 9b419d1..e98f772 100644 --- a/src/screen_client.h +++ b/src/screen_client.h @@ -27,4 +27,11 @@ struct mpdclient; bool screen_auth(struct mpdclient *c); +/** + * Starts a (server-side) database update and displays a status + * message. + */ +void +screen_database_update(struct mpdclient *c, const char *path); + #endif diff --git a/src/screen_file.c b/src/screen_file.c index ed3d26a..a9d5e6a 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -28,6 +28,7 @@ #include "screen_utils.h" #include "screen_browser.h" #include "screen_play.h" +#include "screen_client.h" #include @@ -374,19 +375,7 @@ browse_cmd(struct mpdclient *c, command_t cmd) if (c->status == NULL) return true; - if (mpd_status_get_update_id(c->status) == 0) { - if (mpdclient_cmd_db_update(c, current_path) == 0) { - if (strcmp(current_path, "")) { - char *path_locale = - utf8_to_locale(current_path); - screen_status_printf(_("Database update of %s started"), - path_locale); - g_free(path_locale); - } else - screen_status_printf(_("Database update started")); - } - } else - screen_status_printf(_("Database update running...")); + screen_database_update(c, current_path); return true; default: -- 2.30.2