Enlightenment CVS committal

Author  : balony
Project : e17
Module  : proto

Dir     : e17/proto/exhibit/src/bin


Modified Files:
        exhibit_file.c exhibit_file.h exhibit_main.c 


Log Message:


Make cancel download work and added more info on the progressbar.

===================================================================
RCS file: /cvs/e/e17/proto/exhibit/src/bin/exhibit_file.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- exhibit_file.c      8 Sep 2006 12:48:25 -0000       1.13
+++ exhibit_file.c      8 Sep 2006 16:54:30 -0000       1.14
@@ -29,6 +29,9 @@
    switch(response_id)
      {
       case ETK_RESPONSE_CANCEL:
+        ecore_file_download_abort_all();
+        ecore_file_unlink(data);
+        E_FREE(data);
         etk_object_destroy(ETK_OBJECT(obj));
         break;
       default:
@@ -37,9 +40,9 @@
 }
 
 void
-_ex_file_download_dialog(char *url)
+_ex_file_download_dialog(char *url, char *file)
 {
-   char string[PATH_MAX + 50];
+   char string[PATH_MAX + 16];
 
    sprintf(string, "Downloading %s", url);
 
@@ -47,7 +50,7 @@
         ETK_MESSAGE_DIALOG_CANCEL,
         string);
    etk_signal_connect("response", ETK_OBJECT(dialog),
-        ETK_CALLBACK(_ex_file_download_dialog_response), NULL);
+        ETK_CALLBACK(_ex_file_download_dialog_response), file);
 
    etk_container_border_width_set(ETK_CONTAINER(dialog), 4);
    etk_window_title_set(ETK_WINDOW(dialog),
@@ -65,15 +68,36 @@
 _ex_file_download_progress_cb(void *data, const char *file, long int dltotal, 
long int dlnow, long int ultotal, long int ulnow)
 {
    double fraction;
-   char text[32];
+   char text[42];
+   static long int last;
+   static double t_last;
+   long int diff;
+   double t_diff;
+   double kbytes;
+   static double total_kbytes;
 
    if (dlnow == 0 || dltotal == 0)
      return 0;
 
-   fraction = (double) ((double) dlnow) / ((double) dltotal);
-   snprintf(text, sizeof(text), "%d%% done", (int) (fraction * 100.0));
-   etk_progress_bar_text_set(ETK_PROGRESS_BAR(progressbar), text);
-   etk_progress_bar_fraction_set(ETK_PROGRESS_BAR(progressbar), fraction);
+   if (!total_kbytes)
+     total_kbytes = (double) ((((double)dltotal) / 1024));
+
+   if (last)
+     {
+       diff = dlnow - last;
+       t_diff = ecore_time_get() - t_last;
+       kbytes = (double) ((((double) diff) / 1024));
+       fraction = (double) ((double) dlnow) / ((double) dltotal);
+       etk_progress_bar_fraction_set(ETK_PROGRESS_BAR(progressbar), fraction);
+       snprintf(text, sizeof(text), "%d%% done at %.0f kb/s (%.0f of %.0f 
kb)", 
+             (int) (fraction * 100.0),
+             kbytes / t_diff,
+             kbytes, total_kbytes);
+       etk_progress_bar_text_set(ETK_PROGRESS_BAR(progressbar), text);
+     }
+
+   t_last = ecore_time_get();
+   last = dlnow;
    
    return 0;
 }
@@ -81,8 +105,9 @@
 void 
 _ex_file_download_complete_cb(void *data, const char *file, int status)
 {
-   etk_object_destroy(ETK_OBJECT(dialog));
    _ex_main_itree_add(file, file);
+   etk_object_destroy(ETK_OBJECT(dialog));
+   E_FREE(data);
    D(("Download of file %s is done\n", file));
 
 }
===================================================================
RCS file: /cvs/e/e17/proto/exhibit/src/bin/exhibit_file.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- exhibit_file.h      8 Sep 2006 12:48:25 -0000       1.10
+++ exhibit_file.h      8 Sep 2006 16:54:30 -0000       1.11
@@ -4,7 +4,7 @@
 #ifndef _EX_FILE_H
 #define _EX_FILE_H
 
-void        _ex_file_download_dialog(char *url);
+void        _ex_file_download_dialog(char *url, char *file);
 int         _ex_file_download_progress_cb(void *data, const char *file, long 
int dltotal, long int dlnow, long int ultotal, long int ulnow);
 void        _ex_file_download_complete_cb(void *data, const char *file, int 
status);
 int         _ex_file_is_viewable(char *file);
===================================================================
RCS file: /cvs/e/e17/proto/exhibit/src/bin/exhibit_main.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -3 -r1.80 -r1.81
--- exhibit_main.c      8 Sep 2006 12:48:25 -0000       1.80
+++ exhibit_main.c      8 Sep 2006 16:54:30 -0000       1.81
@@ -864,19 +864,17 @@
        else if (ecore_file_download_protocol_available("http://";))
          {
             char *ptr;
-            char tmp_file[PATH_MAX];
+            char *tmp_file;
             int i;
             
             if ((ptr = strrchr(dir, '/'))) ptr++;
-            D(("Trying to download %s to %s/%s\n", dir, 
-                     e->options->dl_path, ptr));
-
             if (!_ex_file_is_viewable(ptr))
               {
                  tab = _ex_tab_new(e, ".");
               }
             else
               {
+                 tmp_file = malloc(PATH_MAX);
                  for (i = 0;;i++)
                    {
                       snprintf(tmp_file, PATH_MAX, "%s/ex_%d_%s", 
@@ -890,10 +888,10 @@
                  
                  if (ecore_file_download(dir, tmp_file,
                           _ex_file_download_complete_cb,
-                          _ex_file_download_progress_cb, NULL))
+                          _ex_file_download_progress_cb, tmp_file))
                    {
-                      D(("Starting download\n"));
-                      _ex_file_download_dialog(dir);
+                      D(("Starting download to %s\n", tmp_file));
+                      _ex_file_download_dialog(dir, tmp_file);
                    }
               }
 



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to