b5b31b5256b475e058d99b70e496be9d106e8183
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2009 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #include "screen_client.h"
21 #include "screen_utils.h"
22 #include "screen.h"
23 #include "mpdclient.h"
24 #include "i18n.h"
25 #include "charset.h"
27 static bool
28 _screen_auth(struct mpdclient *c, gint recursion)
29 {
30 char *password;
32 mpd_connection_clear_error(c->connection);
33 if (recursion > 2)
34 return false;
36 password = screen_read_password(NULL, NULL);
37 if (password == NULL)
38 return false;
40 mpd_send_password(c->connection, password);
41 g_free(password);
43 mpd_response_finish(c->connection);
44 mpdclient_update(c);
46 if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
47 mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PASSWORD)
48 return _screen_auth(c, ++recursion);
50 return true;
51 }
53 bool
54 screen_auth(struct mpdclient *c)
55 {
56 return _screen_auth(c, 0);
57 }
59 void
60 screen_database_update(struct mpdclient *c, const char *path)
61 {
62 assert(c != NULL);
63 assert(c->connection != NULL);
64 assert(c->status != NULL);
66 if (mpd_status_get_update_id(c->status) != 0) {
67 screen_status_printf(_("Database update running..."));
68 return;
69 }
71 if (mpdclient_cmd_db_update(c, path) != 0)
72 return;
74 if (path != NULL && *path != 0) {
75 char *path_locale = utf8_to_locale(path);
76 screen_status_printf(_("Database update of %s started"), path);
77 g_free(path_locale);
78 } else
79 screen_status_message(_("Database update started"));
80 }