2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "gl-progressbar.h"
19 #include "gl-ui-util.h"
22 #include "gl-albums.h"
23 #include "gl-thread-util.h"
24 #include "gl-strings.h"
25 #include "gl-button.h"
27 #define GL_ALBUMS_PBAR_BG_COLOR_VAL 48
28 #define GL_PBAR_STATUS_LEN_MAX 128
30 #define GL_LABEL_STYLE_DEFAULT GL_CHECKBOX_STYLE_DEFAULT
31 #define GL_PROGRESSBAR_STYLE_PROGRESS "gallery/list_progress"
32 #define GL_PROGRESSBAR_STYLE_PROCESS "list_process"
33 /* Font style for show label of popup */
34 #define GL_FONT_STYLE_POP_S "<font=Helvetica Neue:style=Medium><font_size=42>"
35 #define GL_FONT_STYLE_POP_E "</font_size></font>"
38 _gl_pb_cancel_thread_pbar_cb(void *data, Evas_Object * obj, void *event_info)
41 //set cancel false value
42 gl_thread_set_cancel_state(data, GL_PB_CANCEL_BUTTON);
49 _gl_pb_pbar_timer_cb(void *data)
51 gl_dbg("Timeout, destroy progressbar and timer.");
52 gl_appdata *ad = (gl_appdata *)data;
53 if (ad->pbarinfo.pbar_popup != NULL)
55 evas_object_del(ad->pbarinfo.pbar_popup);
56 ad->pbarinfo.pbar_popup = NULL;
57 ad->pbarinfo.pbar = NULL;
58 ad->pbarinfo.status_label = NULL;
61 if (ad->pbarinfo.pbar_timer != NULL)
63 ecore_timer_del(ad->pbarinfo.pbar_timer);
64 ad->pbarinfo.pbar_timer = NULL;
67 return ECORE_CALLBACK_CANCEL;
70 int gl_pb_make_thread_pbar(void *data, Evas_Object * parent, char *title)
72 GL_CHECK_VAL(data, -1);
73 gl_appdata *ad = (gl_appdata *)data;
74 Evas_Object *popup = NULL;
75 Evas_Object *progressbar = NULL;
76 Evas_Object *box = NULL;
77 Evas_Object *label = NULL;
81 popup = elm_popup_add(parent);
82 elm_object_part_text_set(popup, "title,text", title);
84 label = elm_label_add(popup);
85 elm_object_text_set(label, GL_STR_EMPTY);
86 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND,
88 evas_object_show(label);
90 progressbar = elm_progressbar_add(popup);
91 elm_progressbar_unit_format_set(progressbar, NULL);
92 elm_progressbar_value_set(progressbar, 0.0);
93 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL,
95 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND,
97 evas_object_show(progressbar);
99 box = elm_box_add(popup);
100 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
102 elm_box_horizontal_set(box, EINA_FALSE);
103 elm_box_homogeneous_set(box, EINA_TRUE);
104 elm_box_pack_end(box, progressbar);
105 elm_box_pack_end(box, label);
106 evas_object_show(box);
108 elm_object_content_set(popup, box);
110 Evas_Object *btn1 = NULL;
111 btn1 = _gl_but_create_but_popup(popup, GL_STR_CANCEL,
112 _gl_pb_cancel_thread_pbar_cb, data);
113 elm_object_part_content_set(popup, "button1", btn1);
115 evas_object_show(popup);
117 ad->pbarinfo.pbar_popup = popup;
118 ad->pbarinfo.pbar = progressbar;
119 ad->pbarinfo.status_label = label;
120 ad->pbarinfo.finished_cnt = 0;
126 gl_pb_refresh_thread_pbar(void *data, int cur_cnt, int total_cnt)
128 GL_CHECK_VAL(data, -1);
129 char status_info[GL_POPUP_DESC_LEN_MAX] = { 0, };
130 double percent = 0.0;
131 gl_appdata *ad = (gl_appdata *)data;
132 GL_CHECK_VAL(ad->pbarinfo.pbar, -1);
133 GL_CHECK_VAL(ad->pbarinfo.status_label, -1);
135 snprintf(status_info, sizeof(status_info),
136 GL_FONT_STYLE_POP_S"%d/%d"GL_FONT_STYLE_POP_E, cur_cnt,
138 /* Save medias count already operated */
139 ad->pbarinfo.finished_cnt = cur_cnt;
140 elm_object_text_set(ad->pbarinfo.status_label, status_info);
141 evas_object_show(ad->pbarinfo.status_label);
143 percent = (double)cur_cnt / (double)total_cnt;
144 elm_progressbar_value_set(ad->pbarinfo.pbar, percent);
149 /* Use timer to destroy progressbar */
151 gl_pb_add_pbar_timer(void *data)
153 GL_CHECK_VAL(data, -1);
154 gl_appdata *ad = (gl_appdata *)data;
155 ad->pbarinfo.pbar_timer = ecore_timer_add(1, _gl_pb_pbar_timer_cb, data);
161 gl_pb_del_pbar(void *data)
163 GL_CHECK_VAL(data, -1);
164 gl_appdata *ad = (gl_appdata *)data;
165 gl_dbg("destroy progressbar");
167 if (ad->pbarinfo.pbar_popup)
169 evas_object_del(ad->pbarinfo.pbar_popup);
170 ad->pbarinfo.pbar_popup = NULL;
171 ad->pbarinfo.pbar = NULL;
172 ad->pbarinfo.status_label = NULL;
173 ad->pbarinfo.finished_cnt = 0;
175 if (ad->pbarinfo.pbar_timer)
177 ecore_timer_del(ad->pbarinfo.pbar_timer);
178 ad->pbarinfo.pbar_timer = NULL;
184 /* Add list_progress style progressbar */
185 Evas_Object *gl_pb_add_list_pbar(Evas_Object *parent, const double ratio)
187 GL_CHECK_NULL(parent);
189 Evas_Object *pbar = elm_progressbar_add(parent);
191 elm_object_style_set(pbar, GL_PROGRESSBAR_STYLE_PROGRESS);
192 elm_progressbar_horizontal_set(pbar, EINA_TRUE);
193 evas_object_size_hint_align_set(pbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
194 evas_object_size_hint_weight_set(pbar, EVAS_HINT_EXPAND,
196 elm_progressbar_value_set(pbar, ratio);
197 evas_object_show(pbar);
201 Evas_Object *gl_pb_make_pbar(void *data, Evas_Object *parent, char *state)
204 gl_appdata *ad = (gl_appdata *)data;
205 gl_dbg("Make progressbar, state:%s", state);
206 char label_str[GL_POPUP_DESC_LEN_MAX] = { 0, };
208 if (ad->pbarinfo.pbar_popup) {
209 if (ad->pbarinfo.pbar_timer) {
210 gl_dbg("Del pbar timer in update case!");
211 ecore_timer_del(ad->pbarinfo.pbar_timer);
212 ad->pbarinfo.pbar_timer = NULL;
214 gl_dbg("Progressbar already created, update its label.");
215 snprintf(label_str, sizeof(label_str),
216 GL_FONT_STYLE_POP_S"%s"GL_FONT_STYLE_POP_E, state);
217 elm_object_text_set(ad->pbarinfo.status_label, label_str);
218 return ad->pbarinfo.pbar_popup;
221 Evas_Object *popup = NULL;
222 Evas_Object *progressbar = NULL;
223 Evas_Object *box = NULL;
224 Evas_Object *label = NULL;
226 popup = elm_popup_add(parent);
228 label = elm_label_add(popup);
229 snprintf(label_str, sizeof(label_str),
230 GL_FONT_STYLE_POP_S"%s"GL_FONT_STYLE_POP_E, state);
231 elm_object_text_set(label, label_str);
232 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
233 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, 0.5);
234 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND,
236 evas_object_show(label);
238 progressbar = elm_progressbar_add(popup);
239 elm_object_style_set(progressbar, GL_PROGRESSBAR_STYLE_PROCESS);
240 elm_progressbar_unit_format_set(progressbar, NULL);
241 elm_progressbar_pulse(progressbar, EINA_TRUE);
242 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
243 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND,
245 evas_object_show(progressbar);
247 box = elm_box_add(popup);
248 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
250 elm_box_horizontal_set(box, EINA_TRUE);
251 elm_box_homogeneous_set(box, EINA_TRUE);
252 elm_box_pack_end(box, progressbar);
253 elm_box_pack_end(box, label);
254 evas_object_show(box);
256 elm_object_content_set(popup, box);
257 evas_object_show(popup);
259 ad->pbarinfo.pbar_popup = popup;
260 ad->pbarinfo.pbar = progressbar;
261 ad->pbarinfo.status_label = label;