]> git.tue.mpg.de Git - paraslash.git/commitdiff
improved info status items for the playlist selector
authorAndre <maan@p133.(none)>
Sat, 13 May 2006 23:45:21 +0000 (01:45 +0200)
committerAndre <maan@p133.(none)>
Sat, 13 May 2006 23:45:21 +0000 (01:45 +0200)
With this patch, the three "dbinfo" status items contain the current
dir, the number of entries in the playlist, and the previous/next
entry in the list.

NEWS
playlist_selector.c

diff --git a/NEWS b/NEWS
index fcf9e52053416c38e1d08e4acb853784a2b6f524..1b81359ad6b28c68830dc6e898dacdc245a8753b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ NEWS
 
        o aac filter and aac audio format handler (requires libfaad)
 
+       o random/playlist selector: improved info strings
+
 
 0.2.12 (2006-05-12) "oriented abstraction"
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index 6f171d753ca8659bbfa71a0b174beb8cf4c5beee..b925453ec203234a799bbd124c5c60019b71f9dc 100644 (file)
@@ -197,7 +197,7 @@ static char **pls_get_audio_file_list(unsigned int num)
                return NULL;
        file_list = para_malloc((num + 1) * sizeof(char *));
        for (i = 0; i < num; i++) {
-               unsigned j = (current_playlist_entry + i) % playlist_len;
+               unsigned j = (current_playlist_entry + i + 1) % playlist_len;
                file_list[i] = para_strdup(playlist[j]);
        }
        file_list[i] = NULL;
@@ -251,6 +251,8 @@ static void pls_post_select(__a_unused fd_set *rfds, __a_unused fd_set *wfds)
        ret = for_each_line((char *)shm, pcd->size, &playlist_add);
        shm_detach(shm);
        PARA_NOTICE_LOG("new playlist (%d entries)\n", playlist_len);
+       sprintf(mmd->selector_info, "dbinfo1:new playlist: %d files\n"
+               "dbinfo2:\ndbinfo3:\n", playlist_len);
        pcd->retval = 1;
        pcd->size = 0;
        mutex_unlock(pcd->mutex);
@@ -258,16 +260,44 @@ out:
        mutex_unlock(ppd->server_mutex);
 }
 
+static size_t string_offset(const char *str, size_t max)
+{
+       size_t l = strlen(str);
+
+       if (l <= max)
+               return 0;
+       return l - max;
+}
+
 void pls_update_audio_file(char *audio_file)
 {
        unsigned i;
-
-       for (i = 0; i < playlist_len; i++) {
+       char *dir = para_dirname(audio_file),
+               *prev = playlist[current_playlist_entry % playlist_len];
+       size_t dir_off = string_offset(dir, 50),
+               prev_off = string_offset(prev, 70);
+
+       for (i = 1; i <= playlist_len; i++) {
+               char *next;
+               size_t next_off;
                unsigned j = (current_playlist_entry + i) % playlist_len;
                if (strcmp(playlist[j], audio_file))
                        continue;
-               current_playlist_entry = (j + 1) % playlist_len;
+               current_playlist_entry = j;
+               next = playlist[(j + 1) %playlist_len];
+               next_off = string_offset(next, 70);
+               snprintf(mmd->selector_info, MMD_INFO_SIZE,
+                       "dbinfo1: %d files, current dir: %s%s\n"
+                       "dbinfo2: prev: %s%s\n"
+                       "dbinfo3: next: %s%s\n",
+                       playlist_len,
+                       dir_off? "... " : "", dir + dir_off,
+                       prev_off? "... " : "", prev + prev_off,
+                       next_off? "... " : "", next + next_off
+               );
+               break;
        }
+       free(dir);
 }
 
 /**
@@ -318,7 +348,8 @@ int playlist_selector_init(struct audio_file_selector *db)
                goto err_out;
        ppd->client_data = shm;
        ppd->client_data->size = 0;
-       sprintf(mmd->selector_info, "dbinfo1: playlist selector initialized\n");
+       sprintf(mmd->selector_info, "dbinfo1: Welcome to the playlist "
+               "selector\ndbinfo2: no playlist loaded\ndbinfo3:\n");
        return 1;
 err_out:
        if (ppd->client_data_shm_id >= 0)