From: Max Kellermann Date: Thu, 23 Dec 2010 19:28:42 +0000 (+0100) Subject: main: show real server address in status message X-Git-Tag: release-0.19~33 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=572f9c39c5e0947a95d126f7feedcf2d7d770503;p=ncmpc.git main: show real server address in status message Use the new mpd_settings object to determine the real server host (libmpdclient 2.4). --- diff --git a/NEWS b/NEWS index 013de66..49693f2 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ ncmpc 0.19 - not yet released * require libmpdclient 2.2 +* show real server address in status message ncmpc 0.18 - (09/22/2010) diff --git a/src/main.c b/src/main.c index bc2a8c7..8536cb6 100644 --- a/src/main.c +++ b/src/main.c @@ -231,6 +231,62 @@ do_mpd_update(void) check_reconnect(); } +#if LIBMPDCLIENT_CHECK_VERSION(2,4,0) + +static char * +settings_name(const struct mpd_settings *settings) +{ + const char *host = mpd_settings_get_host(settings); + if (host == NULL) + host = "unknown"; + + if (host[0] == '/') + return g_strdup(host); + + unsigned port = mpd_settings_get_port(settings); + if (port == 0 || port == 6600) + return g_strdup(host); + + return g_strdup_printf("%s:%u", host, port); +} + +#endif + +static char * +default_settings_name(void) +{ +#if LIBMPDCLIENT_CHECK_VERSION(2,4,0) + struct mpd_settings *settings = + mpd_settings_new(options.host, options.port, 0, + NULL, options.password); + if (settings == NULL) + return g_strdup("unknown"); + + char *name = settings_name(settings); + mpd_settings_free(settings); + + return name; +#else + return g_strdup(options.host); +#endif +} + +static char * +connection_settings_name(const struct mpd_connection *connection) +{ +#if LIBMPDCLIENT_CHECK_VERSION(2,4,0) + const struct mpd_settings *settings = + mpd_connection_get_settings(connection); + if (settings == NULL) + return g_strdup("unknown"); + + return settings_name(settings); +#else + (void)connection; + return g_strdup(options.host); +#endif +} + /** * This timer is installed when the connection to the MPD server is * broken. It tries to recover by reconnecting periodically. @@ -245,8 +301,10 @@ timer_reconnect(G_GNUC_UNUSED gpointer data) reconnect_source_id = 0; + char *name = default_settings_name(); screen_status_printf(_("Connecting to %s... [Press %s to abort]"), - options.host, get_key_names(CMD_QUIT,0) ); + name, get_key_names(CMD_QUIT,0) ); + g_free(name); doupdate(); mpdclient_disconnect(mpd); @@ -286,9 +344,9 @@ timer_reconnect(G_GNUC_UNUSED gpointer data) mpd->source = mpd_glib_new(connection, idle_callback, mpd); - screen_status_printf(_("Connected to %s"), - options.host != NULL - ? options.host : "localhost"); + name = connection_settings_name(connection); + screen_status_printf(_("Connected to %s"), name); + g_free(name); doupdate(); /* update immediately */