Index: playlist.h
===================================================================
RCS file: /cvsroot/rockbox/apps/playlist.h,v
retrieving revision 1.7
diff -u -r1.7 playlist.h
--- playlist.h	17 Jul 2002 23:23:57 -0000	1.7
+++ playlist.h	19 Jul 2002 20:05:57 -0000
@@ -33,6 +33,8 @@
     int  index;          /* index of *NEXT* track to play           */
     int  seed;           /* random seed                             */
     int  amount;         /* number of tracks in the index           */
+    bool shuffled;       /* whether this list has been shuffled     */
+    int last_shuffled_index; /* the last shuffled song              */
 } playlist_info_t;
 
 extern playlist_info_t playlist;
@@ -41,6 +43,7 @@
 void play_list(char *dir, char *file);
 char* playlist_next(int steps, char *dirname);
 void randomise_playlist( playlist_info_t *playlist, unsigned int seed );
+void reset_playlist( playlist_info_t *playlist );
 void empty_playlist( playlist_info_t *playlist );
 void add_indices_to_playlist( playlist_info_t *playlist );
 
Index: playlist.c
===================================================================
RCS file: /cvsroot/rockbox/apps/playlist.c,v
retrieving revision 1.21
diff -u -r1.21 playlist.c
--- playlist.c	17 Jul 2002 23:07:45 -0000	1.21
+++ playlist.c	19 Jul 2002 20:05:57 -0000
@@ -43,8 +43,29 @@
     int i;
     char buf[MAX_PATH+1];
 
+    if (playlist.shuffled != global_settings.playlist_shuffle)
+    {
+        /* the shuffle mode was changed */
+        if (playlist.shuffled) {
+            seek = playlist.indices[playlist.index]; /* get current position */
+            reset_playlist(&playlist);
+            for (i=0; i<playlist.amount; i++)
+                if (playlist.indices[i] == seek) {
+                    playlist.index = i; /* set index to current position */
+                    break;
+                }
+        }
+        else {
+            randomise_playlist(&playlist, playlist.seed);
+            playlist.index = playlist.last_shuffled_index;
+        }
+
+    }
+
     playlist.index = (playlist.index+steps) % playlist.amount;
     seek = playlist.indices[playlist.index];
+    if (playlist.shuffled)
+        playlist.last_shuffled_index = playlist.index;
 
     fd = open(playlist.filename, O_RDONLY);
     if(-1 != fd) {
@@ -115,7 +136,7 @@
     if(global_settings.playlist_shuffle) {
         lcd_puts(0,0,"Shuffling...");
         lcd_update();
-        randomise_playlist( &playlist, current_tick );
+        randomise_playlist( &playlist, playlist.seed );
     }
 
     lcd_puts(0,0,"Playing...  ");
@@ -133,6 +154,9 @@
     playlist->filename[0] = '\0';
     playlist->index = 0;
     playlist->amount = 0;
+    playlist->seed = current_tick;
+    playlist->shuffled = false;
+    playlist->last_shuffled_index = 0;
 }
 
 /*
@@ -210,6 +234,9 @@
  */
 void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
 {
+    if (playlist->shuffled && playlist->seed == seed)
+        return;
+
     int count = 0;
     int candidate;
     int store;
@@ -232,6 +259,27 @@
         /* move along */
         count++;
     }
+
+    playlist->seed = seed;
+    playlist->shuffled = true;
+}
+
+static int playlist_index_compare(const void* a, const void* b)
+{
+    return ( *(int*)a - *(int*)b );
+}
+
+/*
+ * reset the array of indices for the playlist to its original configuration
+ */
+void reset_playlist( playlist_info_t *playlist )
+{
+    if (!playlist->shuffled)
+        return;
+
+    qsort(playlist->indices, playlist->amount, sizeof(int), playlist_index_compare);
+
+    playlist->shuffled = false;
 }
 
 /* -----------------------------------------------------------------
Index: wps.c
===================================================================
RCS file: /cvsroot/rockbox/apps/wps.c,v
retrieving revision 1.29
diff -u -r1.29 wps.c
--- wps.c	16 Jul 2002 11:21:59 -0000	1.29
+++ wps.c	19 Jul 2002 20:05:57 -0000
@@ -32,6 +32,7 @@
 #include "mpeg.h"
 #include "usb.h"
 #include "power.h"
+#include "main_menu.h"
 
 #define LINE_Y      1 /* initial line */
 
@@ -245,6 +246,11 @@
                     return SYS_USB_CONNECTED;
                     break;
 #endif
+                case BUTTON_F1:
+                    lcd_stop_scroll();
+                    main_menu();
+                    draw_screen(id3);
+                    break;
             }
             sleep(HZ/10);
         }

