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