Code

Update copyright notices
[ncmpc.git] / src / screen_client.c
index 9d60ed2cd6943cbd018653fdcc0bc4338d53ffc9..f864f1998498e810ea182feddbf3183344220f14 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
 static bool
 _screen_auth(struct mpdclient *c, gint recursion)
 {
+       struct mpd_connection *connection;
        char *password;
 
-       mpd_connection_clear_error(c->connection);
+       connection = mpdclient_get_connection(c);
+       if (connection == NULL)
+               return false;
+
+       mpd_connection_clear_error(connection);
        if (recursion > 2)
                return false;
 
@@ -37,14 +42,14 @@ _screen_auth(struct mpdclient *c, gint recursion)
        if (password == NULL)
                return false;
 
-       mpd_send_password(c->connection, password);
+       mpd_send_password(connection, password);
        g_free(password);
 
-       mpd_response_finish(c->connection);
+       mpd_response_finish(connection);
        mpdclient_update(c);
 
-       if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
-           mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PASSWORD)
+       if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
+           mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_PASSWORD)
                return  _screen_auth(c, ++recursion);
 
        return true;
@@ -70,18 +75,23 @@ mpdclient_ui_error(const char *message_utf8)
 void
 screen_database_update(struct mpdclient *c, const char *path)
 {
+       struct mpd_connection *connection;
        unsigned id;
 
        assert(c != NULL);
        assert(mpdclient_is_connected(c));
 
-       id = mpd_run_update(c->connection, path);
+       connection = mpdclient_get_connection(c);
+       if (connection == NULL)
+               return;
+
+       id = mpd_run_update(connection, path);
        if (id == 0) {
-               if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
-                   mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_UPDATE_ALREADY) {
+               if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
+                   mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_UPDATE_ALREADY &&
+                   mpd_connection_clear_error(connection))
                        screen_status_printf(_("Database update running..."));
-                       mpd_connection_clear_error(c->connection);
-               } else
+               else
                        mpdclient_handle_error(c);
                return;
        }