Code

Check playlist length and remove songs (plchanges command)
authorKalle Wallin <kaw@linux.se>
Tue, 8 Jun 2004 13:15:03 +0000 (13:15 +0000)
committerKalle Wallin <kaw@linux.se>
Tue, 8 Jun 2004 13:15:03 +0000 (13:15 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1393 09075e82-0dd4-0310-85a5-a0d7c8717e4f

TODO
src/libmpdclient.c
src/libmpdclient.h
src/mpc.c

diff --git a/TODO b/TODO
index a09a8a24e7ebb88c3901e0c0517fcece08f6f552..c0c3ae8562cfc832fd4be5e629e52b37b74fe0ec 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,18 +1,13 @@
 
-client functions
-----------------------------------------------------------------------------
-  * move songs in playlists
-  * search screen
-  * id3 browser
-
-ncurses
-----------------------------------------------------------------------------
-  * a small line editor (with history and support for KEY_RESIZE).
-
-other
-----------------------------------------------------------------------------
-  * internationalization - gettext
-  * A cleanup would be nice
+Features:
+* search screen
+* id3 browser
+
+Other:
+* Remove popt dependency
+* A cleanup would be nice
+
+*** Cleanup mpc.c !!!
 
 
 
index a879b53e65fb08e25264e82fa7d60b8eab43ad9a..b61e2d1e9e33bf6dbfb33ac4e17df470f92c70e7 100644 (file)
@@ -469,13 +469,13 @@ void mpd_getNextReturnElement(mpd_Connection * connection) {
        
                strcpy(connection->errorStr, output);
                connection->error = MPD_ERROR_ACK;
-               connection->errorCode = MPD_ERROR_CODE_UNK;
+               connection->errorCode = MPD_ACK_ERROR_UNK;
                connection->errorAt = MPD_ERROR_AT_UNK;
                connection->doneProcessing = 1;
 
                needle = strchr(output, '[');
                if(!needle) return;
-               val = strtol(needle, &test, 10);
+               val = strtol(needle+1, &test, 10);
                if(*test != '@') return;
                connection->errorCode = val;
                val = strtol(test+1, &test, 10);
@@ -966,7 +966,7 @@ void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songNum) {
 
 void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist) {
        char * string = malloc(strlen("plchanges")+25);
-       sprintf(string,"plchanges \"%i\"\n",playlist);
+       sprintf(string,"plchanges \"%lld\"\n",playlist);
        mpd_sendInfoCommand(connection,string);
        free(string);
 }
index 55d2ff077e4ed92b211472b5a15da3e45575a9a0..c4b022cd9e88442515418f4ffb2125e4cbbcb88a 100644 (file)
 #define MPD_ERROR_ACK          18 /* ACK returned! */
 #define MPD_ERROR_BUFFEROVERRUN        19 /* Buffer was overrun! */
 
-#define MPD_ERROR_CODE_UNK     -1;
-#define MPD_ERROR_AT_UNK       -1;
+#define MPD_ACK_ERROR_UNK      -1
+#define MPD_ERROR_AT_UNK       -1
+
+#define MPD_ACK_ERROR_NOT_LIST                 1
+#define MPD_ACK_ERROR_ARG                      2
+#define MPD_ACK_ERROR_PASSWORD                 3
+#define MPD_ACK_ERROR_PERMISSION               4
+#define MPD_ACK_ERROR_UNKNOWN                  5
+#define MPD_ACK_ERROR_NO_EXIST                 6
+#define MPD_ACK_ERROR_PLAYLIST_MAX             7
+#define MPD_ACK_ERROR_SYSTEM                   8
+#define MPD_ACK_ERROR_PLAYLIST_LOAD            9
+#define MPD_ACK_ERROR_UPDATE_ALREADY           10
+#define MPD_ACK_ERROR_PLAYER_SYNC              11
 
 #ifdef __cplusplus
 extern "C" {
index ab25f1964991eb36115e4c724078f300bb934d08..08ca970f6c1e563caab234a9a841808d51ac18df 100644 (file)
--- a/src/mpc.c
+++ b/src/mpc.c
@@ -103,8 +103,9 @@ mpc_error(mpd_client_t *c)
 {
   if( c == NULL || c->connection == NULL )
     return 1;
+
   if( c->connection->error )
-    return c->connection->error;
+      return c->connection->error;
 
   return 0;
 }
@@ -194,7 +195,8 @@ mpc_update_playlist(mpd_client_t *c)
 {
   mpd_InfoEntity *entity;
 
-  D(fprintf(stderr, "mpc_update_playlist() [%lld]\n", c->status->playlist));
+  D(fprintf(stderr, "mpc_update_playlist() [%lld -> %lld]\n", 
+           c->status->playlist, c->playlist_id));
 
   if( mpc_error(c) )
     return -1;
@@ -202,9 +204,8 @@ mpc_update_playlist(mpd_client_t *c)
   mpd_sendPlChangesCommand(c->connection, c->playlist_id);
   if( mpc_error(c) )
     return -1;
-  if( (entity=mpd_getNextInfoEntity(c->connection)) == NULL )
-    return mpc_get_playlist(c);
-  while( entity ) 
+
+  while( (entity=mpd_getNextInfoEntity(c->connection)) != NULL   ) 
     {
       if(entity->type==MPD_INFO_ENTITY_TYPE_SONG) 
        {
@@ -212,11 +213,15 @@ mpc_update_playlist(mpd_client_t *c)
          GList *item;
 
          if( (song=mpd_songDup(entity->info.song)) == NULL )
-           return mpc_get_playlist(c);
+           {
+             D(fprintf(stderr, "song==NULL\n"));
+             return mpc_get_playlist(c);
+           }
 
          item =  g_list_nth(c->playlist, song->num);
          if( item && item->data)
            {
+             /* Update playlist entry */
              mpd_freeSong((mpd_Song *) item->data);
              item->data = song;
              if( c->song_id == song->num )
@@ -226,6 +231,7 @@ mpc_update_playlist(mpd_client_t *c)
            }
          else
            {
+             /* Add a new  playlist entry */
              D(fprintf(stderr, "Adding num %d - %s\n",
                        song->num, mpc_get_song_name(song)));
              c->playlist = g_list_append(c->playlist, 
@@ -233,10 +239,20 @@ mpc_update_playlist(mpd_client_t *c)
              c->playlist_length++;
            }
        }
-      mpd_freeInfoEntity(entity);
-      entity=mpd_getNextInfoEntity(c->connection);
+      mpd_freeInfoEntity(entity);      
     }
   mpd_finishCommand(c->connection);
+  
+  while( g_list_length(c->playlist) > c->status->playlistLength )
+    {
+      GList *item = g_list_last(c->playlist);
+
+      /* Remove the last playlist entry */
+      mpd_freeSong((mpd_Song *) item->data);
+      c->playlist = g_list_delete_link(c->playlist, item);
+      c->playlist_length--;      
+      D(fprintf(stderr, "Removed the last playlist entryn\n"));
+    }
 
   c->playlist_id = c->status->playlist;
   c->playlist_updated = 1;
@@ -476,9 +492,8 @@ mpc_update_filelist(mpd_client_t *c)
 
   c->filelist_length=0;
 
-  //  mpd_sendListallCommand(conn,"");
   mpd_sendLsInfoCommand(c->connection, c->cwd);
-
+  
   if( c->cwd && c->cwd[0] )
     {
       /* add a dummy entry for ./.. */