diff --git a/src/main.c b/src/main.c
index bc2a8c73dc30eb4193cc913556abb40ff658ece0..8536cb67c77d8e7fa8258f9ccab837b46d4bb75d 100644 (file)
--- a/src/main.c
+++ b/src/main.c
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.
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);
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 */