options: remove double-semicolon
[ncmpc.git] / src / screen_client.c
blobf864f1998498e810ea182feddbf3183344220f14
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2010 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
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.
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.
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.
20 #include "screen_client.h"
21 #include "screen_utils.h"
22 #include "screen_message.h"
23 #include "mpdclient.h"
24 #include "i18n.h"
25 #include "charset.h"
27 static bool
28 _screen_auth(struct mpdclient *c, gint recursion)
30 struct mpd_connection *connection;
31 char *password;
33 connection = mpdclient_get_connection(c);
34 if (connection == NULL)
35 return false;
37 mpd_connection_clear_error(connection);
38 if (recursion > 2)
39 return false;
41 password = screen_read_password(NULL);
42 if (password == NULL)
43 return false;
45 mpd_send_password(connection, password);
46 g_free(password);
48 mpd_response_finish(connection);
49 mpdclient_update(c);
51 if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
52 mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_PASSWORD)
53 return _screen_auth(c, ++recursion);
55 return true;
58 bool
59 screen_auth(struct mpdclient *c)
61 return _screen_auth(c, 0);
64 void
65 mpdclient_ui_error(const char *message_utf8)
67 char *message_locale = utf8_to_locale(message_utf8);
68 screen_status_printf("%s", message_locale);
69 g_free(message_locale);
71 screen_bell();
72 doupdate();
75 void
76 screen_database_update(struct mpdclient *c, const char *path)
78 struct mpd_connection *connection;
79 unsigned id;
81 assert(c != NULL);
82 assert(mpdclient_is_connected(c));
84 connection = mpdclient_get_connection(c);
85 if (connection == NULL)
86 return;
88 id = mpd_run_update(connection, path);
89 if (id == 0) {
90 if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
91 mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_UPDATE_ALREADY &&
92 mpd_connection_clear_error(connection))
93 screen_status_printf(_("Database update running..."));
94 else
95 mpdclient_handle_error(c);
96 return;
99 /* set update_id to make sure the browse callback gets called
100 even if the update has finished before status is updated */
101 c->update_id = id;
103 if (path != NULL && *path != 0) {
104 char *path_locale = utf8_to_locale(path);
105 screen_status_printf(_("Database update of %s started"), path);
106 g_free(path_locale);
107 } else
108 screen_status_message(_("Database update started"));