X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fscreen_client.c;h=b8e936fdbc0fe6147edd4bbd961f2c590551368d;hb=refs%2Ftags%2Frelease-0.21;hp=e4cc7cd600d06a6921bf1d784ab3e8f74ae248dd;hpb=34ca92e9ed28234b506a158ef53b46eea6ccb78c;p=ncmpc.git diff --git a/src/screen_client.c b/src/screen_client.c index e4cc7cd..b8e936f 100644 --- a/src/screen_client.c +++ b/src/screen_client.c @@ -1,5 +1,5 @@ /* ncmpc (Ncurses MPD Client) - * (c) 2004-2009 The Music Player Daemon Project + * (c) 2004-2010 The Music Player Daemon Project * Project homepage: http://musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,38 +19,91 @@ #include "screen_client.h" #include "screen_utils.h" +#include "screen_status.h" #include "mpdclient.h" +#include "i18n.h" +#include "charset.h" -static gint +static bool _screen_auth(struct mpdclient *c, gint recursion) { + struct mpd_connection *connection; char *password; - mpd_connection_clear_error(c->connection); + connection = mpdclient_get_connection(c); + if (connection == NULL) + return false; + + mpd_connection_clear_error(connection); if (recursion > 2) - return 1; + return false; - password = screen_read_password(NULL, NULL); + password = screen_read_password(NULL); if (password == NULL) - return 1; + return false; - mpd_send_password(c->connection, password); + mpd_send_password(connection, password); g_free(password); - mpd_response_finish(c->connection); + mpd_response_finish(connection); mpdclient_update(c); - if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER && - mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PASSWORD) + if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER && + mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_PASSWORD) return _screen_auth(c, ++recursion); - return 0; + + return true; } -gint +bool screen_auth(struct mpdclient *c) { - gint ret = _screen_auth(c, 0); - mpdclient_update(c); - curs_set(0); - return ret; + return _screen_auth(c, 0); +} + +void +mpdclient_ui_error(const char *message_utf8) +{ + char *message_locale = utf8_to_locale(message_utf8); + screen_status_printf("%s", message_locale); + g_free(message_locale); + + screen_bell(); + doupdate(); +} + +void +screen_database_update(struct mpdclient *c, const char *path) +{ + struct mpd_connection *connection; + unsigned id; + + assert(c != NULL); + assert(mpdclient_is_connected(c)); + + connection = mpdclient_get_connection(c); + if (connection == NULL) + return; + + id = mpd_run_update(connection, path); + if (id == 0) { + if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER && + mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_UPDATE_ALREADY && + mpd_connection_clear_error(connection)) + screen_status_printf(_("Database update running...")); + else + mpdclient_handle_error(c); + return; + } + + /* set update_id to make sure the browse callback gets called + even if the update has finished before status is updated */ + c->update_id = id; + + 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")); }