diff --git a/src/main.c b/src/main.c
index 8d0d4b2f2ef6067d96cfc4db3388a4b8c028f586..8abdcbda94c60f4a043b9bd4bd403645abae8436 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include "ncu.h"
#include "screen.h"
#include "screen_utils.h"
+#include "screen_message.h"
#include "strfsong.h"
#include "i18n.h"
#include "player_command.h"
#define BUFSIZE 1024
static struct mpdclient *mpd = NULL;
-static gboolean connected = FALSE;
static GMainLoop *main_loop;
static guint reconnect_source_id, update_source_id;
static guint check_key_bindings_source_id;
#endif
-static const gchar *
-error_msg(const gchar *msg)
-{
- gchar *p;
-
- if ((p = strchr(msg, '}')) == NULL)
- return msg;
-
- do {
- p++;
- } while (*p == '}' || * p== ' ');
-
- return p;
-}
-
-static void
-error_callback(G_GNUC_UNUSED struct mpdclient *c, gint error, const gchar *_msg)
-{
- char *msg = utf8_to_locale(_msg);
-
- error = error & 0xFF;
- switch (error) {
- case MPD_ERROR_SERVER:
- screen_status_printf("%s", error_msg(msg));
- screen_bell();
- break;
- default:
- screen_status_printf("%s", msg);
- screen_bell();
- doupdate();
- connected = FALSE;
- }
-
- g_free(msg);
-}
-
#ifndef NCMPC_MINI
static void
update_xterm_title(void)
static char title[BUFSIZE];
char tmp[BUFSIZE];
struct mpd_status *status = NULL;
- struct mpd_song *song = NULL;
+ const struct mpd_song *song = NULL;
if (mpd) {
status = mpd->status;
}
if (options.xterm_title_format && status && song &&
- IS_PLAYING(mpd_status_get_state(status)))
+ mpd_status_get_state(status) == MPD_STATE_PLAY)
strfsong(tmp, BUFSIZE, options.xterm_title_format, song);
else
g_strlcpy(tmp, PACKAGE " version " VERSION, BUFSIZE);
static gboolean
timer_reconnect(G_GNUC_UNUSED gpointer data)
{
- int ret;
+ bool success;
- if (connected)
- return FALSE;
+ assert(!mpdclient_is_connected(mpd));
screen_status_printf(_("Connecting to %s... [Press %s to abort]"),
options.host, get_key_names(CMD_QUIT,0) );
doupdate();
mpdclient_disconnect(mpd);
- ret = mpdclient_connect(mpd,
- options.host, options.port,
- 1.5,
- options.password);
- if (ret != 0) {
+ success = mpdclient_connect(mpd,
+ options.host, options.port,
+ 1.5,
+ options.password);
+ if (!success) {
/* try again in 5 seconds */
g_timeout_add(5000, timer_reconnect, NULL);
return FALSE;
#ifndef NCMPC_MINI
/* quit if mpd is pre 0.11.0 - song id not supported by mpd */
- if (mpd_connection_cmp_server_version(mpd->connection, 0, 11, 0) < 0) {
+ if (mpd_connection_cmp_server_version(mpd->connection, 0, 12, 0) < 0) {
const unsigned *version =
mpd_connection_get_server_version(mpd->connection);
screen_status_printf(_("Error: MPD version %d.%d.%d is to old (%s needed)"),
version[0], version[1], version[2],
- "0.11.0");
+ "0.12.0");
mpdclient_disconnect(mpd);
doupdate();
? options.host : "localhost");
doupdate();
- connected = TRUE;
-
/* update immediately */
g_timeout_add(1, timer_mpd_update, GINT_TO_POINTER(FALSE));
static gboolean
timer_mpd_update(gpointer data)
{
- if (connected)
+ if (mpdclient_is_connected(mpd))
mpdclient_update(mpd);
else if (reconnect_source_id == 0)
reconnect_source_id = g_timeout_add(1000, timer_reconnect,
screen_update(mpd);
+ mpd->events = 0;
+
return GPOINTER_TO_INT(data);
}
/* create mpdclient instance */
mpd = mpdclient_new();
- mpdclient_install_error_callback(mpd, error_callback);
/* initialize curses */
screen_init(mpd);