--- apps/onplay.c.orig	2006-11-13 00:45:19.000000000 +0000
+++ apps/onplay.c	2006-11-20 22:15:58.000000000 +0000
@@ -50,6 +50,7 @@
 #include "action.h"
 #include "splash.h"
 #include "yesno.h"
+#include "gwps.h"
 #if LCD_DEPTH > 1
 #include "backdrop.h"
 #endif
@@ -399,13 +400,60 @@
     return ret;
 }
 
+void prb(int progress, char *str)
+{
+    static unsigned long last_tick;
+    int posa,posb;
+    unsigned char string[30];
+
+    /* only a shortcut */
+    struct prog_img pgb;
+    pgb = gui_wps[0].data->progressbar;
+
+
+    /* 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%% %s", progress,str);
+        lcd_getstringsize(string, &posa, &posb);
+        lcd_putsxy(LCD_WIDTH/2-posa/2,LCD_HEIGHT/2-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*2,
+                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*2 , 
+                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%% %s", progress,str);
+        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);
+    }
+
+}
 
 /* helper function to remove a non-empty directory */
-static int remove_dir(char* dirname, int len)
+static int remove_dir_gra(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;
+
+    int progress;
 
     dir = opendir(dirname);
     if (!dir)
@@ -428,7 +476,115 @@
                 !strcmp((char *)entry->d_name, ".."))
                 continue; /* skip these */
 
-            result = remove_dir(dirname, len); /* recursion */
+            result = remove_dir_gra(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;
+         
+            prb(progress,"deleted"); 
+        }
+    }
+    closedir(dir);
+
+    if (!result)
+    {   /* remove the now empty directory */
+        dirname[dirlen] = '\0'; /* terminate to original length */
+
+        result = rmdir(dirname);
+    }
+
+    return result;
+}
+
+static void get_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_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 */
+/* the original version without any ouput	*/
+static int remove_dir_muted(char* dirname, int len)
+{
+    int result = 0;
+    DIR* dir;
+    int dirlen = strlen(dirname);
+
+    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_muted(dirname, len); /* recursion */
             if (result)
                 break; /* or better continue, delete what we can? */
         }
@@ -449,6 +605,43 @@
     return result;
 }
 
+/* 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();
+#ifdef HAVE_REMOTE_LCD
+    lcd_remote_clear_display();
+#endif
+    lcd_getstringsize("building summary", &posa, &posb);
+    lcd_putsxy((LCD_WIDTH/2) - (posa/2),(LCD_HEIGHT/2)-posb, "building summary");
+    lcd_update();
+
+    get_dir_summary(dirname, len, &filecount, &filebytes);
+    strncpy(dirname, pdirname, strlen(pdirname)+1);
+
+    lcd_clear_display();
+
+    result = remove_dir_gra(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)
@@ -670,7 +863,7 @@
 }
 
 /* Paste a directory to a new location. Designed to be called by clipboard_paste */
-static bool clipboard_pastedirectory(char *src, int srclen, char *target, int targetlen, bool copy)
+static bool clipboard_pastedirectory_muted(char *src, int srclen, char *target, int targetlen, bool copy)
 {
     DIR *srcdir;
     int srcdirlen = strlen(src);
@@ -690,7 +883,7 @@
 #ifdef HAVE_MULTIVOLUME
             if (!result && errno == EXDEV) {
                 /* Try a copy as we're going across devices */
-                result = clipboard_pastedirectory(src, srclen, target, targetlen, true);
+                result = clipboard_pastedirectory_muted(src, srclen, target, targetlen, true);
 
                 /* If it worked, remove the source directory */
                 if (result) {
@@ -736,7 +929,7 @@
                 !strcmp((char *)entry->d_name, ".."))
                 continue; /* skip these */
 
-            result = clipboard_pastedirectory(src, srclen, target, targetlen, copy); /* recursion */
+            result = clipboard_pastedirectory_muted(src, srclen, target, targetlen, copy); /* recursion */
         }
         else
         {   /* copy/move a file */
@@ -754,6 +947,141 @@
     return result;
 }
 
+/* Paste a directory to a new location. Designed to be called by clipboard_paste */
+static bool clipboard_pastedirectory_gra(char *src, int srclen, char *target, int targetlen, bool copy, unsigned int files, unsigned long bytes, unsigned int* filecounter, unsigned long* bytescounter)
+{
+    DIR *srcdir;
+    int srcdirlen = strlen(src);
+    int targetdirlen = strlen(target);
+    int fd;
+    bool result = true;
+
+    unsigned long size;
+    int progress;
+
+    /* Check if the target exists */
+    fd = open(target, O_RDONLY);
+    close(fd);
+
+    if (fd < 0) {
+        if (!copy) {
+            /* Just move the directory */
+            /* we never have HAVE_MULTIVOLUME here because we cared about before */
+            /* on systems with HAVE_MULTIVOLUME the original copy/move routine is used */
+            /* not the graphical one	*/ 
+            result = rename(src, target) == 0;
+            return result;
+        } else {
+            /* Make a directory to copy things to */
+            result = mkdir(target, 0) == 0;
+        }
+    }
+
+    /* Check if something went wrong already */
+    if (!result) {
+        return result;
+    }
+
+    srcdir = opendir(src);
+    if (!srcdir) {
+        return false;
+    }
+
+    /* This loop will exit as soon as there's a problem */
+    while(result)
+    {
+        struct dirent* entry;
+        /* walk through the directory content */
+        entry = readdir(srcdir);
+        if (!entry)
+            break;
+
+        /* append name to current directory */
+        snprintf(src+srcdirlen, srclen-srcdirlen, "/%s", entry->d_name);
+        snprintf(target+targetdirlen, targetlen-targetdirlen, "/%s", entry->d_name);
+
+        DEBUGF("Copy %s to %s\n", src, target);
+
+        if (entry->attribute & ATTR_DIRECTORY)
+        {   /* copy/move a subdirectory */
+            if (!strcmp((char *)entry->d_name, ".") ||
+                !strcmp((char *)entry->d_name, ".."))
+                continue; /* skip these */
+
+            result = clipboard_pastedirectory_gra(src, srclen, target, targetlen, copy, files, bytes, filecounter, bytescounter); /* recursion */
+        }
+        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; 
+            /* copy/move a file */
+            result = clipboard_pastefile(src, target, copy);
+#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;
+        
+            prb(progress,"copied"); 
+        }
+    }
+
+    closedir(srcdir);
+
+    if (result) {
+        src[srcdirlen] = '\0'; /* terminate to original length */
+        target[targetdirlen] = '\0'; /* terminate to original length */
+    }
+
+    return result;
+}
+
+static bool clipboard_pastedirectory(char *src, int srclen, char *target, int targetlen, bool copy)
+{
+    int result;
+    unsigned int filecount = 0;
+    unsigned long filebytes = 0;
+    unsigned int countera = 0;
+    unsigned long counterb = 0;
+    int posa,posb;
+
+    char psrc[MAX_PATH];
+    strncpy(psrc, src, strlen(src)+1);
+
+#ifdef HAVE_LCD_BITMAP 
+#ifndef HAVE_MULTIVOLUME
+
+    /* if we have a grafical display, we output some information while deleting
+     * files and directories. */
+    lcd_clear_display();
+#ifdef HAVE_REMOTE_LCD
+    lcd_remote_clear_display();
+#endif
+    lcd_getstringsize("building summary", &posa, &posb);
+    lcd_putsxy((LCD_WIDTH/2) - (posa/2),(LCD_HEIGHT/2)-posb, "building summary");
+    lcd_update();
+
+    get_dir_summary(src, srclen, &filecount, &filebytes);
+    strncpy(src, psrc, strlen(psrc)+1);
+
+    lcd_clear_display();
+
+    result = clipboard_pastedirectory_gra(src, srclen, target, targetlen, copy, filecount, filebytes, &countera, &counterb);
+#elif    
+#elif
+    /* without grafical output we use the old delete routine */
+    result = clipboard_pastedirectory_muted(src, srclen, target, targetlen, copy)
+#endif
+#endif
+    return result;
+}
+
 /* Paste the clipboard to the current directory */
 static bool clipboard_paste(void)
 {
