diff options
author | Max Kellermann <max@duempel.org> | 2008-09-18 01:13:02 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-18 01:13:02 +0200 |
commit | b3e35ee16d6e5cb8e0f53c318c47b55c2dc9ba62 (patch) | |
tree | eead11fe48df1707cfc81fa98de9bca995e1c575 /src/main.c | |
parent | 53c53f17643a73d899fcffa02577602300d17282 (diff) | |
download | mpd-b3e35ee16d6e5cb8e0f53c318c47b55c2dc9ba62.tar.gz mpd-b3e35ee16d6e5cb8e0f53c318c47b55c2dc9ba62.tar.xz mpd-b3e35ee16d6e5cb8e0f53c318c47b55c2dc9ba62.zip |
main: connect while UI is displayed
Display the UI always, and show connection errors there. This fixes a
lot of consistency problems: error messages used to be printed to
stderr, but afterwards, the atexit() handlers deinitialized ncurses
and the screen was cleared. This patch is still problematic, but
constitutes a good step forward.
Diffstat (limited to '')
-rw-r--r-- | src/main.c | 60 |
1 files changed, 21 insertions, 39 deletions
diff --git a/src/main.c b/src/main.c index a0ff34461..cbb4735b9 100644 --- a/src/main.c +++ b/src/main.c @@ -254,51 +254,17 @@ main(int argc, const char *argv[]) lyrics_init(); - /* connect to our music player daemon */ + /* create mpdclient instance */ mpd = mpdclient_new(); - - if (mpdclient_connect(mpd, - options.host, - options.port, - 10.0, - options.password)) - exit(EXIT_FAILURE); - - /* if no password is used, but the mpd wants one, the connection - might be established but no status information is avaiable */ - mpdclient_update(mpd); - if (!mpd->status) - screen_auth(mpd); - - if (!mpd->status) - exit(EXIT_FAILURE); - - connected = TRUE; - D("Connected to MPD version %d.%d.%d\n", - mpd->connection->version[0], - mpd->connection->version[1], - mpd->connection->version[2]); - - /* quit if mpd is pre 0.11.0 - song id not supported by mpd */ - if( MPD_VERSION_LT(mpd, 0,11,0) ) { - fprintf(stderr, - _("Error: MPD version %d.%d.%d is to old (0.11.0 needed).\n"), - mpd->connection->version[0], - mpd->connection->version[1], - mpd->connection->version[2]); - exit(EXIT_FAILURE); - } + mpdclient_install_error_callback(mpd, error_callback); /* initialize curses */ screen_init(mpd); - /* install error callback function */ - mpdclient_install_error_callback(mpd, error_callback); /* initialize timer */ timer = g_timer_new(); - connected = TRUE; - while (connected || options.reconnect) { + while (1) { static gdouble t = G_MAXDOUBLE; if (key_error) { @@ -324,19 +290,35 @@ main(int argc, const char *argv[]) g_timer_start(timer); } else screen_idle(mpd); - } else if (options.reconnect) { + } else { screen_status_printf(_("Connecting to %s... [Press %s to abort]"), options.host, get_key_names(CMD_QUIT,0) ); + /* if (get_keyboard_command_with_timeout(MPD_RECONNECT_TIME) == CMD_QUIT) exit(EXIT_SUCCESS); + */ if (mpdclient_connect(mpd, options.host, options.port, 1.5, options.password) == 0) { screen_status_printf(_("Connected to %s!"), options.host); - connected = TRUE; + + /* quit if mpd is pre 0.11.0 - song id not supported by mpd */ + if (MPD_VERSION_LT(mpd, 0, 11, 0)) { + screen_status_printf(_("Error: MPD version %d.%d.%d is to old (0.11.0 needed).\n"), + mpd->connection->version[0], + mpd->connection->version[1], + mpd->connection->version[2]); + mpdclient_disconnect(mpd); + } else { + mpdclient_update(mpd); + if (!mpd->status) + screen_auth(mpd); + + connected = TRUE; + } } doupdate(); |