Update progress bar 45/80345/1 accepted/tizen/ivi/20160717.065205 accepted/tizen/mobile/20160717.065113 accepted/tizen/tv/20160717.065130 accepted/tizen/wearable/20160717.065148 submit/tizen/20160717.052119
authorWonnam Jang <wn.jang@samsung.com>
Sun, 17 Jul 2016 05:07:46 +0000 (14:07 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Sun, 17 Jul 2016 05:07:46 +0000 (14:07 +0900)
Change-Id: Idc0534e20dc7ade7d0842e11dc3fee58c9b9ad7e
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
setting-app/src/ttssmt_setting_main.c

index 18739c3..b450300 100644 (file)
@@ -144,6 +144,9 @@ static appdata_s *g_ad;
 
 static int g_download_id;
 
+unsigned long long g_received_bytes = 0;
+unsigned long long g_total_content_bytes = 0;
+
 typedef struct {
        char*   language;
        int     type;
@@ -331,6 +334,12 @@ static void __check_changed_cb(void *data, Evas_Object *obj, void *event_info)
        elm_genlist_item_update(g_ad->selected_lang);
 }
 
+static void __progress_cb(int download_id, unsigned long long recevied, void *user_data)
+{
+       g_received_bytes = recevied;
+       dlog_print(DLOG_INFO, LOG_TAG, "download_id(%d), received(%llu), total(%llu)", download_id, g_received_bytes, g_total_content_bytes);
+}
+
 static Evas_Object * __genlist_content_get(void *data, Evas_Object *obj, const char *part)
 {
        item_index_e idx = (item_index_e)data;
@@ -362,10 +371,17 @@ static void __hide_progress_popup()
 
 static void __progress_popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
 {
+       Ecore_Timer* timer = data;
        if (NULL != g_ad->progress_popup) {
                evas_object_del(g_ad->progress_popup);
                g_ad->progress_popup = NULL;
        }
+       if (NULL != timer) {
+               ecore_timer_del(timer);
+               timer = NULL;
+       }
+       g_received_bytes = 0;
+       g_total_content_bytes = 0;
        return;
 }
 
@@ -382,6 +398,21 @@ static void __progress_popup_back_cb(void *data, Evas_Object *obj, void *event_i
        return;
 }
 
+static Eina_Bool __progress_popup_timer_cb(void* data)
+{
+       double value = 0.0;
+       char percentage[7] = {'\0',};
+       Evas_Object *progressbar = data;
+       value = (double)((long double)g_received_bytes / (long double)g_total_content_bytes);
+       dlog_print(DLOG_ERROR, LOG_TAG, "recevied(%llu), tatal(%llu), value(%lf)", g_received_bytes, g_total_content_bytes, value);
+
+       elm_progressbar_value_set(progressbar, value);
+       snprintf(percentage, 7, "%d/100", (int)(value*100));
+       elm_object_part_text_set(progressbar, "elm.text.top.right", (const char*)percentage);
+
+       return ECORE_CALLBACK_RENEW;
+}
+
 static void __show_progress_popup(bool failed, const char* msg)
 {
        if (NULL != g_ad->progress_popup) {
@@ -394,6 +425,8 @@ static void __show_progress_popup(bool failed, const char* msg)
        evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        elm_object_part_text_set(popup, "title,text", _("IDS_DOWNLOADING"));
 
+       Ecore_Timer *progress_timer = NULL;
+
        if (failed) {
                if (NULL != msg) {
                        elm_object_part_text_set(popup, "default", msg);
@@ -404,17 +437,19 @@ static void __show_progress_popup(bool failed, const char* msg)
 
        } else {
                Evas_Object *progressbar = elm_progressbar_add(popup);
-               elm_object_style_set(progressbar, "process_large");
                evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
                evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-               elm_progressbar_pulse(progressbar, EINA_TRUE);
+
+               elm_progressbar_value_set(progressbar, 0.0);
+               progress_timer = ecore_timer_add(0.5, __progress_popup_timer_cb, progressbar);
+               elm_object_part_text_set(progressbar, "elm.text.top.right", "0/100");
 
                elm_object_content_set(popup, progressbar);
                evas_object_show(progressbar);
        }
 
        evas_object_smart_callback_add(popup, "block,clicked", NULL, NULL);
-       evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __progress_popup_del_cb, NULL);
+       evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __progress_popup_del_cb, progress_timer);
        eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __progress_popup_back_cb, NULL);
 
        g_ad->progress_popup = popup;
@@ -539,15 +574,30 @@ static void __download_state_changed_cb(int download_id, download_state_e state,
        if (DOWNLOAD_STATE_COMPLETED == state) {
                dlog_print(DLOG_INFO, LOG_TAG, "===== Download Completed");
                ecore_main_loop_thread_safe_call_sync(__download_completed_cb, user_data);
+               download_unset_state_changed_cb(download_id);
+               download_unset_progress_cb(download_id);
                download_destroy(download_id);
        } else if (DOWNLOAD_STATE_FAILED == state) {
                dlog_print(DLOG_INFO, LOG_TAG, "===== Download Failed");
                ecore_main_loop_thread_safe_call_sync(__download_failed_cb, user_data);
+               download_unset_state_changed_cb(download_id);
+               download_unset_progress_cb(download_id);
                download_destroy(download_id);
        } else if (DOWNLOAD_STATE_CANCELED == state) {
                dlog_print(DLOG_INFO, LOG_TAG, "===== Download Canceled");
                ecore_main_loop_thread_safe_call_sync(__download_canceled_cb, user_data);
+               download_unset_state_changed_cb(download_id);
+               download_unset_progress_cb(download_id);
                download_destroy(download_id);
+       } else if (DOWNLOAD_STATE_DOWNLOADING == state) {
+               dlog_print(DLOG_INFO, LOG_TAG, "===== Downloading");
+               unsigned long long content_size;
+               int ret = download_get_content_size(download_id, &content_size);
+               if (DOWNLOAD_ERROR_NONE != ret) {
+                       dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to get contents size(%d)", ret);
+               }
+               g_total_content_bytes = content_size;
+               dlog_print(DLOG_INFO, LOG_TAG, "total size of contents(%llu)", g_total_content_bytes);
        }
 
        dlog_print(DLOG_INFO, LOG_TAG, "=====");
@@ -640,12 +690,24 @@ static void __lang_item_clicked_cb(void *data, Evas_Object *obj, void *event_inf
                        return;
                }
 
+               ret = download_set_progress_cb(download_id, __progress_cb, NULL);
+               if (DOWNLOAD_ERROR_NONE != ret) {
+                       dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to set progress cb(%d)", ret);
+                       __show_progress_popup(true, NULL);
+                       download_unset_state_changed_cb(download_id);
+                       download_destroy(download_id);
+                       wifi_deinitialize();
+                       return;
+               }
+
                char url[1024] = {'\0',};
                snprintf(url, 1024, "http://download.tizen.org/releases/resources/voice/tts/smt-language-pack/%s.tar.gz", item_data[idx][2]);
                ret = download_set_url(download_id, url);
                if (DOWNLOAD_ERROR_NONE != ret) {
                        dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to set url(%d)", ret);
                        __show_progress_popup(true, NULL);
+                       download_unset_state_changed_cb(download_id);
+                       download_unset_progress_cb(download_id);
                        download_destroy(download_id);
                        wifi_deinitialize();
                        return;
@@ -657,6 +719,8 @@ static void __lang_item_clicked_cb(void *data, Evas_Object *obj, void *event_inf
                if (DOWNLOAD_ERROR_NONE != ret) {
                        dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to set destination(%d)", ret);
                        __show_progress_popup(true, NULL);
+                       download_unset_state_changed_cb(download_id);
+                       download_unset_progress_cb(download_id);
                        download_destroy(download_id);
                        wifi_deinitialize();
                        return;
@@ -667,6 +731,8 @@ static void __lang_item_clicked_cb(void *data, Evas_Object *obj, void *event_inf
                if (DOWNLOAD_ERROR_NONE != ret) {
                        dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to start(%d)", ret);
                        __show_progress_popup(true, NULL);
+                       download_unset_state_changed_cb(download_id);
+                       download_unset_progress_cb(download_id);
                        download_destroy(download_id);
                        wifi_deinitialize();
                        return;