--- onplay.c.orig	2006-10-25 10:17:53.000000000 +0000
+++ apps/onplay.c	2006-11-09 20:23:12.000000000 +0000
@@ -50,6 +50,7 @@
 #include "action.h"
 #include "splash.h"
 #include "yesno.h"
+#include "gwps.h"
 #ifdef HAVE_LCD_COLOR
 #include "backdrop.h"
 #endif
@@ -399,9 +400,156 @@
     return ret;
 }
 
+/* helper function to remove a non-empty directory */
+static int remove_dir_execute(char* dirname, int len, unsigned int files, unsigned long bytes, unsigned int* filecounter, unsigned long* bytescounter)
+{
+    int result = 0;
+    DIR* dir;
+    int dirlen = strlen(dirname);
+    unsigned long size;
+
+    static unsigned long last_tick;
+    unsigned char string[30]; 
+    int progress;
+    int posa,posb;
+
+    /* only a shortcut */
+    struct prog_img pgb;
+    pgb = gui_wps[0].data->progressbar;
+
+    dir = opendir(dirname);
+    if (!dir)
+        return -1; /* open error */
+
+    while(true)
+    {
+        struct dirent* entry;
+        /* walk through the directory content */
+        entry = readdir(dir);
+        if (!entry)
+            break;
+
+        /* append name to current directory */
+        snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
+
+        if (entry->attribute & ATTR_DIRECTORY)
+        {   /* remove a subdirectory */
+            if (!strcmp((char *)entry->d_name, ".") ||
+                !strcmp((char *)entry->d_name, ".."))
+                continue; /* skip these */
+
+            result = remove_dir_execute(dirname, len, files, bytes, filecounter, bytescounter); /* recursion */
+            if (result)
+                break; /* or better continue, delete what we can? */
+        }
+        else
+        {   
+            /* count the file */
+            *filecounter += 1;
+	    /* we want M like 1024*1024 */
+	    size = entry->size >> 20;
+	    /* we round up not down */
+	    size += 1;
+	    *bytescounter += size; 
+
+            /* remove a file */
+            result = remove(dirname); 
+#ifdef SIMULATOR
+	    sleep(HZ/10);
+#endif
+	    /* we do that here because we want to enshure that 100% is drawn 	*/
+	    /* even if it is not within the HZ/4 timeslot			*/
+            progress = (int)(*filecounter*100/files+*bytescounter*100/bytes)/2;
+          
+            /* we don't want to print that out too often */
+            if(((current_tick-last_tick)/(HZ/4)) >= 1 || progress == 100)
+            {
+                /* progress = (int)(*filecounter*100/files+*bytescounter*100/bytes)/2; */
+                snprintf(string,sizeof string, "%d%% deleted", progress);
+                lcd_getstringsize(string, &posa, &posb);
+                lcd_putsxy(LCD_WIDTH/2-(posa/2),(LCD_HEIGHT/2)-posb, string);
+                if (pgb.have_bitmap_pb)
+                    gui_bitmap_scrollbar_draw(gui_wps[0].display, pgb.bm, 
+		        (LCD_WIDTH-pgb.bm.width)/2, LCD_HEIGHT/2+pgb.bm.height,
+                        pgb.bm.width, pgb.bm.height,
+                        100,
+                       	0, progress,HORIZONTAL);
+		else
+                    gui_scrollbar_draw(gui_wps[0].display,LCD_WIDTH*10/100, LCD_HEIGHT/2+posb , 
+                        LCD_WIDTH*80/100, posb*2,
+			100,
+			0, progress,HORIZONTAL);
+	        lcd_update();
+#ifdef HAVE_REMOTE_LCD
+		/* whithin this context HAVE_REMOTE_LCD implies also having HAVE_LCD_BITMAP	*/
+		snprintf(string,sizeof string, "%d%% deleted", progress);
+                lcd_remote_getstringsize(string, &posa, &posb);
+                lcd_remote_putsxy(LCD_REMOTE_WIDTH/2-(posa/2), LCD_REMOTE_HEIGHT/2-posb, string);
+	        lcd_remote_update();
+#endif
+		last_tick = current_tick;
+		/* some people would like to see this explicitely	*/
+		if (progress == 100)
+		    sleep(HZ/4);
+	    }
+        }
+    }
+    closedir(dir);
+
+    if (!result)
+    {   /* remove the now empty directory */
+        dirname[dirlen] = '\0'; /* terminate to original length */
+
+        result = rmdir(dirname);
+    }
+
+    return result;
+}
+
+static void get_remove_dir_summary(char* dirname, int len, unsigned int* files, unsigned long* bytes)
+{
+    DIR* dir;
+    int dirlen = strlen(dirname);
+    unsigned long size;
+
+    dir = opendir(dirname);
+    if (!dir)
+        return;
+    while(true)
+    {
+         struct dirent* entry;
+        /* walk through the directory content */
+        entry = readdir(dir);
+        if (!entry)
+            break;
+	
+        /* append name to current directory */
+        snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
+
+        if (entry->attribute & ATTR_DIRECTORY)
+        {   /* walk int subdirectory */
+            if (!strcmp((char *)entry->d_name, ".") ||
+                !strcmp((char *)entry->d_name, ".."))
+                continue; /* skip these */
+
+            get_remove_dir_summary(dirname, len, files, bytes); /* recursion */
+        }
+        else
+        {   /* count the file */
+            *files += 1;
+	    /* we want M like 1024*1024 */
+	    size = entry->size >> 20;
+	    /* we round up not down */
+	    size += 1;
+	    *bytes += size; 
+	}
+    }
+    closedir(dir);
+}
 
 /* helper function to remove a non-empty directory */
-static int remove_dir(char* dirname, int len)
+/* the original version without any ouput	*/
+static int remove_dir_muted(char* dirname, int len)
 {
     int result = 0;
     DIR* dir;
@@ -428,7 +576,7 @@
                 !strcmp((char *)entry->d_name, ".."))
                 continue; /* skip these */
 
-            result = remove_dir(dirname, len); /* recursion */
+            result = remove_dir_muted(dirname, len); /* recursion */
             if (result)
                 break; /* or better continue, delete what we can? */
         }
@@ -450,6 +598,41 @@
 }
 
 
+/* helper function to remove a non-empty directory */
+/* the more verbose version			*/
+static int remove_dir(char* dirname, int len)
+{
+    int result = 0;
+    unsigned int filecount = 0;
+    unsigned long filebytes = 0;
+    unsigned int countera = 0;
+    unsigned long counterb = 0;
+    int posa,posb;
+
+    char pdirname[MAX_PATH];
+    strncpy(pdirname, dirname, strlen(dirname)+1);
+
+#ifdef HAVE_LCD_BITMAP
+    /* if we have a grafical display, we output some information while deleting
+     * files and directories. */
+    lcd_clear_display();
+    lcd_getstringsize("building summary", &posa, &posb);
+    lcd_putsxy((LCD_WIDTH/2) - (posa/2),(LCD_HEIGHT/2)-posb, "building summary");
+    lcd_update();
+
+    get_remove_dir_summary(dirname, len, &filecount, &filebytes);
+    strncpy(dirname, pdirname, strlen(pdirname)+1);
+
+    lcd_clear_display();
+
+    result = remove_dir_execute(dirname, len, filecount, filebytes, &countera, &counterb);
+#elif
+    /* without grafical output we use the old delete routine */
+    result = remove_dir_muted(dirname,len);
+#endif
+    return result;
+}
+
 /* share code for file and directory deletion, saves space */
 static bool delete_handler(bool is_dir)
 {
