Remove SMACK rule file(.rule) according three domain model
[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.1 (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 void _diable_popup(void *data)
168 {
169         Evas_Object *btn = NULL;
170         Evas_Object *eo = (Evas_Object *)data;
171         if(eo == NULL) {
172                 printf("[Error] Invalid argument: popup is NULL\n");
173                 return;
174         }
175
176         btn = elm_object_part_content_get(eo, "button1");
177         if(btn) {
178                 elm_object_disabled_set(btn, EINA_TRUE);
179         }
180
181         btn = elm_object_part_content_get(eo, "button2");
182         if(btn) {
183                 elm_object_disabled_set(btn, EINA_TRUE);
184         }
185 }
186
187 Evas_Object *_add_popup_ask(Evas_Object *parent, char *text, void *data)
188 {
189         Evas_Object *pu, *bt1, *bt2;
190         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL\n");
191
192         pu = elm_popup_add(parent);
193         retvm_if(pu == NULL, NULL, "Falied to add popup\n");
194         evas_object_size_hint_weight_set(pu, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
195         elm_object_part_text_set(pu, "title,text", S_("IDS_COM_POP_WARNING"));
196         elm_object_text_set(pu, text);
197         evas_object_show(pu);
198
199         bt1 = elm_button_add(pu);
200         elm_object_text_set(bt1, S_("IDS_COM_SK_OK"));
201         elm_object_part_content_set(pu, "button1", bt1);
202         evas_object_smart_callback_add(bt1, "clicked", _ok_response_cb, data);
203
204         bt2 = elm_button_add(pu);
205         elm_object_text_set(bt2, S_("IDS_COM_POP_CANCEL"));
206         elm_object_part_content_set(pu, "button2", bt2);
207         evas_object_smart_callback_add(bt2, "clicked", _cancel_response_cb, data);
208
209
210         return pu;
211 }
212
213 void util_show_popup_with_message(Evas_Object *parent, double in,
214                                   const char *msg)
215 {
216         Evas_Object *eo = NULL;
217
218         eo = elm_popup_add(parent);
219         if (eo == NULL) {
220                 printf("[Error] Cannot add popup\n");
221                 return;
222         }
223
224         evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
225                                          EVAS_HINT_EXPAND);
226         elm_object_text_set(eo, msg);
227
228         ecore_timer_add(in, _disappear_popup, eo);
229 }
230
231 Evas_Object *_add_naviframe(Evas_Object *parent)
232 {
233         Evas_Object *nv;
234
235         retv_if(parent == NULL, NULL);
236
237         nv = elm_naviframe_add(parent);
238         retvm_if(nv == NULL, NULL, "Failed to add naviframe\n");
239         elm_object_part_content_set(parent, "elm.swallow.content", nv);
240
241         evas_object_show(nv);
242
243         return nv;
244 }
245
246 Evas_Object *_add_layout_main(Evas_Object *parent,
247                 Eina_Bool content, Eina_Bool transparent)
248 {
249         Evas_Object *ly;
250
251         retv_if(parent == NULL, NULL);
252
253         ly = elm_layout_add(parent);
254         retvm_if(ly == NULL, NULL, "Failed elm_layout_add.\n");
255
256         elm_layout_theme_set(ly, "layout", "application", "default");
257         evas_object_size_hint_weight_set(ly,
258                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
259         elm_win_resize_object_add(parent, ly);
260         if (content)
261                 elm_object_signal_emit(ly, "elm,state,show,content", "elm");
262         if (transparent)
263                 elm_object_signal_emit(ly, "elm,bg,show,transparent", "elm");
264         evas_object_show(ly);
265         return ly;
266 }
267
268 Evas_Object *_add_progressbar(Evas_Object *parent, const char *style,
269                 Evas_Coord w, Evas_Coord h)
270 {
271         Evas_Object *pb;
272         double scale;
273
274         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL\n");
275
276         scale = elm_config_scale_get();
277
278         pb = elm_progressbar_add(parent);
279         retvm_if(pb == NULL, NULL, "Failed to add progressbar\n");
280
281         elm_object_style_set(pb, style);
282         evas_object_resize(pb, w, (int)(60 * scale));
283         evas_object_move(pb, 0, h / 2);
284         elm_progressbar_pulse(pb, EINA_TRUE);
285         evas_object_show(pb);
286
287         return pb;
288 }
289
290