initial upload for tizen 2.0 beta
[apps/home/gallery.git] / src / widget / gl-progressbar.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
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
7   *
8   *     http://www.tizenopensource.org/license
9   *
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.
15   */
16
17 #include "gallery.h"
18 #include "gl-progressbar.h"
19 #include "gl-ui-util.h"
20 #include "gl-util.h"
21 #include "gl-debug.h"
22 #include "gl-albums.h"
23 #include "gl-controlbar.h"
24 #include "gl-thread-util.h"
25 #include "gl-strings.h"
26 #include "gl-button.h"
27
28 #define GL_PROGRESSBAR_STYLE_PROGRESS "list_progress"
29
30 static void
31 _gl_pb_cancel_thread_pbar_cb(void *data, Evas_Object * obj, void *event_info)
32 {
33         gl_dbg("");
34         //set cancel false value
35         gl_thread_set_cancel_state(data, GL_PB_CANCEL_BUTTON);
36         //delete progressbar
37         gl_pb_del_pbar(data);
38 }
39
40 int gl_pb_make_thread_pbar(void *data, Evas_Object * parent, char *title)
41 {
42         GL_CHECK_VAL(data, -1);
43         gl_appdata *ad = (gl_appdata *)data;
44         Evas_Object *popup = NULL;
45         Evas_Object *progressbar = NULL;
46         Evas_Object *box = NULL;
47         Evas_Object *label = NULL;
48
49         gl_pb_del_pbar(ad);
50
51         popup = elm_popup_add(parent);
52         GL_CHECK_VAL(popup, -1);
53
54         elm_object_part_text_set(popup, GL_POPUP_TEXT, title);
55
56         label = elm_label_add(popup);
57         elm_object_text_set(label, GL_STR_EMPTY);
58         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND,
59                                          EVAS_HINT_EXPAND);
60         evas_object_show(label);
61
62         progressbar = elm_progressbar_add(popup);
63         elm_object_style_set(progressbar, GL_PROGRESSBAR_STYLE_PROGRESS);
64         elm_progressbar_unit_format_set(progressbar, NULL);
65         elm_progressbar_value_set(progressbar, 0.0);
66         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL,
67                                         EVAS_HINT_FILL);
68         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND,
69                                          EVAS_HINT_EXPAND);
70         evas_object_show(progressbar);
71
72         box = elm_box_add(popup);
73         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
74                                          EVAS_HINT_EXPAND);
75         elm_box_horizontal_set(box, EINA_FALSE);
76         elm_box_homogeneous_set(box, EINA_TRUE);
77         elm_box_pack_end(box, progressbar);
78         elm_box_pack_end(box, label);
79         evas_object_show(box);
80
81         elm_object_content_set(popup, box);
82         Evas_Object *btn1 = NULL;
83         btn1 = _gl_but_create_but_popup(popup, GL_STR_CANCEL,
84                                         _gl_pb_cancel_thread_pbar_cb, data);
85         elm_object_part_content_set(popup, "button1", btn1);
86
87         evas_object_show(popup);
88
89         ad->pbarinfo.pbar_popup = popup;
90         ad->pbarinfo.pbar = progressbar;
91         ad->pbarinfo.status_label = label;
92         ad->pbarinfo.finished_cnt = 0;
93
94         return 0;
95 }
96
97 int
98 gl_pb_refresh_thread_pbar(void *data, int cur_cnt, int total_cnt)
99 {
100         GL_CHECK_VAL(data, -1);
101         char status_info[GL_POPUP_DESC_LEN_MAX] = { 0, };
102         double percent = 0.0;
103         gl_appdata *ad = (gl_appdata *)data;
104         GL_CHECK_VAL(ad->pbarinfo.pbar, -1);
105         GL_CHECK_VAL(ad->pbarinfo.status_label, -1);
106
107         snprintf(status_info, sizeof(status_info),
108                  GL_FONT_STYLE_POP_S"%d/%d"GL_FONT_STYLE_POP_E, cur_cnt,
109                  total_cnt);
110         /* Save medias count already operated */
111         ad->pbarinfo.finished_cnt = cur_cnt;
112         elm_object_text_set(ad->pbarinfo.status_label, status_info);
113         evas_object_show(ad->pbarinfo.status_label);
114
115         percent = (double)cur_cnt / (double)total_cnt;
116         elm_progressbar_value_set(ad->pbarinfo.pbar, percent);
117
118         return 0;
119 }
120
121 int
122 gl_pb_del_pbar(void *data)
123 {
124         GL_CHECK_VAL(data, -1);
125         gl_appdata *ad = (gl_appdata *)data;
126         gl_dbg("destroy progressbar");
127
128         if (ad->pbarinfo.pbar_popup)
129         {
130                 evas_object_del(ad->pbarinfo.pbar_popup);
131                 ad->pbarinfo.pbar_popup = NULL;
132                 ad->pbarinfo.pbar = NULL;
133                 ad->pbarinfo.status_label = NULL;
134                 ad->pbarinfo.finished_cnt = 0;
135         }
136
137         return 0;
138 }
139
140 /* Add list_progress style progressbar */
141 Evas_Object *_gl_pb_add_list_pbar(Evas_Object *parent, const double ratio)
142 {
143         GL_CHECK_NULL(parent);
144
145         Evas_Object *pbar = elm_progressbar_add(parent);
146         GL_CHECK_NULL(pbar);
147         elm_object_style_set(pbar, GL_PROGRESSBAR_STYLE_PROGRESS);
148         elm_progressbar_horizontal_set(pbar, EINA_TRUE);
149         evas_object_size_hint_align_set(pbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
150         evas_object_size_hint_weight_set(pbar, EVAS_HINT_EXPAND,
151                                          EVAS_HINT_EXPAND);
152         elm_progressbar_value_set(pbar, ratio);
153         evas_object_show(pbar);
154         return pbar;
155 }
156