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