Fix N_SE-16408 : progressbar is still showing when app is dead.
[apps/core/preloaded/taskmanager.git] / src / _util_efl.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
18
19
20 #include <appcore-efl.h>
21
22 #include "taskmanager.h"
23 #include "_util_log.h"
24 #include "_util_efl.h"
25 #include "_logic.h"
26
27 Evas_Object *_add_window(const char *name)
28 {
29         Evas_Object *eo;
30         int w, h;
31
32         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
33         if (eo) {
34                 elm_win_title_set(eo, name);
35                 elm_win_borderless_set(eo, EINA_TRUE);
36                 ecore_x_window_size_get(ecore_x_window_root_first_get(),
37                                         &w, &h);
38                 evas_object_resize(eo, w, h);
39         }
40
41         return eo;
42 }
43
44 Evas_Object *_add_bg(Evas_Object *parent, char *style)
45 {
46         Evas_Object *bg;
47
48         bg = elm_bg_add(parent);
49         retvm_if(bg == NULL, NULL, "Failed to add bg\n");
50         if (style)      elm_object_style_set(bg, style);
51         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
52                                          EVAS_HINT_EXPAND);
53         evas_object_show(bg);
54         return bg;
55 }
56
57 Evas_Object *_add_genlist(Evas_Object *parent)
58 {
59         Evas_Object *eo;
60
61         eo = elm_genlist_add(parent);
62         if (eo == NULL) {
63                 printf("[Error] Cannot add genlist\n");
64                 return NULL;
65         }
66
67         evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
68                                          EVAS_HINT_EXPAND);
69         evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
70
71         return eo;
72 }
73
74 Evas_Object *_add_icon(Evas_Object *parent, const char *png)
75 {
76         Evas_Object *eo;
77         char buf[128] = { 0, };
78
79         eo = elm_icon_add(parent);
80         if (eo == NULL) {
81                 printf("[Error] Cannot add button\n");
82                 return NULL;
83         }
84
85         snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR, png);
86         elm_icon_file_set(eo, buf, NULL);
87         elm_icon_resizable_set(eo, 1, 1);
88         evas_object_size_hint_aspect_set(eo, EVAS_ASPECT_CONTROL_VERTICAL, 1,
89                                          1);
90
91         return eo;
92 }
93
94 Evas_Object *_add_layout(Evas_Object *parent, const char *file,
95                               const char *group)
96 {
97         Evas_Object *eo = NULL;
98         int r;
99
100         eo = elm_layout_add(parent);
101         if (eo == NULL) {
102                 printf("[Error] Cannot add layout\n");
103                 return NULL;
104         }
105
106         r = elm_layout_file_set(eo, file, group);
107         if (!r) {
108                 printf("[Error] Cannot set file layout\n");
109                 evas_object_del(eo);
110                 return NULL;
111         }
112
113         evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
114                                          EVAS_HINT_EXPAND);
115
116         return eo;
117 }
118
119 Evas_Object *_add_ctxpopup(Evas_Object *parent)
120 {
121         Evas_Object *eo = NULL;
122
123         eo = elm_ctxpopup_add(parent);
124         if (eo == NULL) {
125                 printf("[Error] Cannot add ctxpopup\n");
126                 return NULL;
127         }
128
129         elm_ctxpopup_horizontal_set(eo, EINA_TRUE);
130         elm_ctxpopup_direction_priority_set(eo,
131                                             ELM_CTXPOPUP_DIRECTION_DOWN,
132                                             ELM_CTXPOPUP_DIRECTION_UP,
133                                             ELM_CTXPOPUP_DIRECTION_LEFT,
134                                             ELM_CTXPOPUP_DIRECTION_RIGHT);
135
136         return eo;
137 }
138
139 Evas_Object *_add_label(Evas_Object *parent, const char *msg)
140 {
141         Evas_Object *eo = NULL;
142
143         eo = elm_label_add(parent);
144         if (eo == NULL) {
145                 printf("[Error] Cannot add label\n");
146                 return NULL;
147         }
148
149         elm_label_line_wrap_set(eo, ELM_WRAP_WORD);
150         elm_object_text_set(eo, msg);
151
152         return eo;
153 }
154
155 static Eina_Bool _disappear_popup(void *data)
156 {
157         Evas_Object *eo = (Evas_Object *)data;
158         if (eo == NULL) {
159                 printf("[Error] Invalid argument: popup is NULL\n");
160                 return ECORE_CALLBACK_CANCEL;
161         }
162         evas_object_del(eo);
163         return ECORE_CALLBACK_CANCEL;
164 }
165
166 Evas_Object *_add_popup_ask(Evas_Object *parent, char *text, void *data)
167 {
168         Evas_Object *pu, *bt1, *bt2;
169         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL\n");
170
171         pu = elm_popup_add(parent);
172         retvm_if(pu == NULL, NULL, "Falied to add popup\n");
173         evas_object_size_hint_weight_set(pu, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174         elm_object_part_text_set(pu, "title,text", S_("IDS_COM_POP_WARNING"));
175         elm_object_text_set(pu, text);
176         evas_object_show(pu);
177
178         bt1 = elm_button_add(pu);
179         elm_object_text_set(bt1, S_("IDS_COM_SK_OK"));
180         elm_object_part_content_set(pu, "button1", bt1);
181         evas_object_smart_callback_add(bt1, "clicked", _ok_response_cb, data);
182
183         bt2 = elm_button_add(pu);
184         elm_object_text_set(bt2, S_("IDS_COM_POP_CANCEL"));
185         elm_object_part_content_set(pu, "button2", bt2);
186         evas_object_smart_callback_add(bt2, "clicked", _cancel_response_cb, data);
187
188
189         return pu;
190 }
191
192 void util_show_popup_with_message(Evas_Object *parent, double in,
193                                   const char *msg)
194 {
195         Evas_Object *eo = NULL;
196
197         eo = elm_popup_add(parent);
198         if (eo == NULL) {
199                 printf("[Error] Cannot add popup\n");
200                 return;
201         }
202
203         evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
204                                          EVAS_HINT_EXPAND);
205         elm_object_text_set(eo, msg);
206
207         ecore_timer_add(in, _disappear_popup, eo);
208 }
209
210 Evas_Object *_add_naviframe(Evas_Object *parent)
211 {
212         Evas_Object *nv;
213
214         retv_if(parent == NULL, NULL);
215
216         nv = elm_naviframe_add(parent);
217         retvm_if(nv == NULL, NULL, "Failed to add naviframe\n");
218         elm_object_part_content_set(parent, "elm.swallow.content", nv);
219
220         evas_object_show(nv);
221
222         return nv;
223 }
224
225 Evas_Object *_add_layout_main(Evas_Object *parent,
226                 Eina_Bool content, Eina_Bool transparent)
227 {
228         Evas_Object *ly;
229
230         retv_if(parent == NULL, NULL);
231
232         ly = elm_layout_add(parent);
233         retvm_if(ly == NULL, NULL, "Failed elm_layout_add.\n");
234
235         elm_layout_theme_set(ly, "layout", "application", "default");
236         evas_object_size_hint_weight_set(ly,
237                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
238         elm_win_resize_object_add(parent, ly);
239         if (content)
240                 elm_object_signal_emit(ly, "elm,state,show,content", "elm");
241         if (transparent)
242                 elm_object_signal_emit(ly, "elm,bg,show,transparent", "elm");
243         evas_object_show(ly);
244         return ly;
245 }
246
247 Evas_Object *_add_progressbar(Evas_Object *parent, const char *style,
248                 Evas_Coord w, Evas_Coord h)
249 {
250         Evas_Object *pb;
251         double scale;
252
253         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL\n");
254
255         scale = elm_config_scale_get();
256
257         pb = elm_progressbar_add(parent);
258         retvm_if(pb == NULL, NULL, "Failed to add progressbar\n");
259
260         elm_object_style_set(pb, style);
261         evas_object_resize(pb, w, (int)(60 * scale));
262         evas_object_move(pb, 0, h / 2);
263         elm_progressbar_pulse(pb, EINA_TRUE);
264         evas_object_show(pb);
265
266         return pb;
267 }
268
269