commit fe24be785df3f7c54905e76787f751994dcb077c
parent efb8aeb094ac6c5ef1efbc4dc7a7cf62f1977f2b
Author: Kyle Milz <kmilz@ucalgary.ca>
Date: Wed, 17 Oct 2012 14:07:36 -0600
improve downloads status with a % done meter
Diffstat:
2 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/src/buffer.c b/src/buffer.c
@@ -12,9 +12,6 @@
#include "buffer.h"
-static Eina_Bool process_keypress(void *, Window_Data*);
-Eina_Bool download_gui_update(void *data);
-
static void
webprocess_crashed_cb(void *data, Evas_Object *obj, void *event_info)
@@ -58,32 +55,41 @@ webview_create_window_cb(void *data, Evas_Object *obj, Eina_Bool js, const Elm_W
}
*/
-Eina_Bool
-download_gui_update(void *data)
+static Eina_Bool
+download_status_cb(void *data)
{
+ Ewk_Download_Job *dl;
Eina_List *l;
- void *list_data;
+
Window_Data *wd = data;
App_Data *ad = wd->app;
unsigned int dl_count = eina_list_count(ad->downloads);
+ Eina_Strbuf *buf = eina_strbuf_new();
+ double percent_done;
+
+ eina_strbuf_append_printf(buf, "%i DL", eina_list_count(ad->downloads));
- char *tmp = strdup_printf("<font=Monospace font_size=11 color=#FFF>%i DL", eina_list_count(ad->downloads));
+ percent_done = 0.0;
+ EINA_LIST_FOREACH(ad->downloads, l, dl)
+ percent_done += 100.0 * ewk_download_job_estimated_progress_get(dl);
- /* downloads is a global thing, update all windows with information */
- EINA_LIST_FOREACH(ad->windows, l, list_data) {
- Window_Data *wd_tmp = list_data;
+ percent_done /= (double)dl_count;
+ eina_strbuf_append_printf(buf, " (%.1f%%)", percent_done);
+
+ EINA_LIST_FOREACH(ad->windows, l, wd) {
if (dl_count == 0) {
- evas_object_size_hint_weight_set(wd_tmp->downloads, 0.0, 0.0);
+ evas_object_size_hint_weight_set(wd->downloads, 0.0, 0.0);
+ elm_object_text_set(wd->downloads, "");
}
else {
- evas_object_size_hint_weight_set(wd_tmp->downloads, EVAS_HINT_EXPAND, 0.0);
- elm_object_text_set(wd_tmp->downloads, tmp);
+ evas_object_size_hint_weight_set(wd->downloads, EVAS_HINT_EXPAND, 0.0);
+ elm_object_text_set(wd->downloads, eina_strbuf_string_get(buf));
}
}
+ eina_strbuf_free(buf);
- free(tmp);
- return EINA_TRUE;
+ return ECORE_CALLBACK_RENEW;
}
static void
@@ -91,21 +97,20 @@ download_request_cb(void *data, Evas_Object *obj, void *event_info)
{
Window_Data *wd = data;
App_Data *ad = wd->app;
-
+ Eina_Strbuf *full_path = eina_strbuf_new();
Ewk_Download_Job *dl = event_info;
-
const char *suggested_name = ewk_download_job_suggested_filename_get(dl);
- char *full_path = strdup_printf("%s/%s", getenv("HOME"), suggested_name);
- ewk_download_job_destination_set(dl, full_path);
- free(full_path);
+
+ eina_strbuf_append_printf(full_path, "%s/%s", efreet_desktop_dir_get(), suggested_name);
+ ewk_download_job_destination_set(dl, eina_strbuf_string_steal(full_path));
ewk_download_job_ref(dl);
ad->downloads = eina_list_append(ad->downloads, dl);
if (eina_list_count(ad->downloads) == 1)
- ad->download_gui_timer = ecore_timer_loop_add(1, download_gui_update, wd);
+ ad->download_status_timer = ecore_timer_loop_add(1, download_status_cb, wd);
- download_gui_update(wd);
+ download_status_cb(wd);
}
static void
@@ -117,9 +122,9 @@ download_remove(Window_Data *wd, Ewk_Download_Job *dl)
ad->downloads = eina_list_remove(ad->downloads, dl);
if (eina_list_count(ad->downloads) == 0)
- ecore_timer_del(ad->download_gui_timer);
+ ecore_timer_del(ad->download_status_timer);
- download_gui_update(wd);
+ download_status_cb(wd);
}
static void
diff --git a/src/viking.h b/src/viking.h
@@ -172,7 +172,7 @@ typedef struct
char *modkeys;
Ecore_Timer *session_save_timer;
- Ecore_Timer *download_gui_timer;
+ Ecore_Timer *download_status_timer;
SoupSession *soup_session;
Hist *history;