Code

main: show real server address in status message
authorMax Kellermann <max@duempel.org>
Thu, 23 Dec 2010 19:28:42 +0000 (20:28 +0100)
committerMax Kellermann <max@duempel.org>
Thu, 23 Dec 2010 19:31:00 +0000 (20:31 +0100)
Use the new mpd_settings object to determine the real server host
(libmpdclient 2.4).

NEWS
src/main.c

diff --git a/NEWS b/NEWS
index 013de6600156af3dd1580b0c0e3e1e3e47d149b4..49693f2afa81301cff1b10253e40b7c098ce2a99 100644 (file)
--- 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)
index bc2a8c73dc30eb4193cc913556abb40ff658ece0..8536cb67c77d8e7fa8258f9ccab837b46d4bb75d 100644 (file)
@@ -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 */