tizen 2.4 release
[apps/home/attach-panel-gallery.git] / src / util / ge-ui-util.c
1 /*
2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 <notification.h>
19 #include "ge-ui-util.h"
20 #include "ge-util.h"
21 #include "ge-button.h"
22 #include "ge-gridview.h"
23 #include "ge-albums.h"
24 #include "ge-data.h"
25 #include "ge-icon.h"
26 #include <efl_extension.h>
27
28 #define GE_NOBUT_EXIT_POPUP_HIDE_TIME_DELAY 3.0
29
30 static void _ge_ui_response_cb(void *data, Evas_Object *obj, void *ei)
31 {
32         GE_CHECK(data);
33         ge_ugdata *ugd = (ge_ugdata *)data;
34         ge_dbg("popup mode: %d", ugd->popup_mode);
35
36         evas_object_del(obj);
37         ugd->popup = NULL;
38 }
39
40 static Eina_Bool __ge_popup_timeout_cb(void *data)
41 {
42         GE_CHECK_FALSE(data);
43         ge_ugdata *ugd = (ge_ugdata *)data;
44         if (ugd->del_timer) {
45                 ecore_timer_del(ugd->del_timer);
46                 ugd->del_timer = NULL;
47         }
48
49         /* Used for adding shortcut failed */
50         if (ugd->popup_mode == GE_POPUP_EXIT) {
51                 ge_dbgW("Terminate me!");
52                 if (!ugd->is_attach_panel) {
53                         ug_destroy_me(ugd->ug);
54                         ugd->ug = NULL;
55                 }
56         }
57
58         GE_IF_DEL_OBJ(ugd->popup);
59         return ECORE_CALLBACK_CANCEL;
60 }
61
62 static int __ge_popup_add_timer(void *data, double to_inc)
63 {
64         GE_CHECK_VAL(data, -1);
65         ge_ugdata *ugd = (ge_ugdata *)data;
66         if (ugd->del_timer) {
67                 ecore_timer_del(ugd->del_timer);
68                 ugd->del_timer = NULL;
69         }
70
71         ugd->del_timer = ecore_timer_add(to_inc, __ge_popup_timeout_cb, data);
72         return 0;
73 }
74
75 Evas_Object* ge_ui_load_edj(Evas_Object *parent, const char *file, const char *group)
76 {
77         GE_CHECK_NULL(parent);
78         GE_CHECK_NULL(file);
79         GE_CHECK_NULL(group);
80         Evas_Object *eo;
81         int r;
82
83         eo = elm_layout_add(parent);
84         if (eo)
85         {
86                 r = elm_layout_file_set(eo, file, group);
87                 if (!r)
88                 {
89                         evas_object_del(eo);
90                         return NULL;
91                 }
92
93                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
94                 evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
95         }
96
97         return eo;
98 }
99
100 Evas_Object* ge_ui_create_nocontents(ge_ugdata* ugd)
101 {
102         GE_CHECK_NULL(ugd);
103         Evas_Object *layout = NULL;
104         char label_str[GE_NOCONTENTS_LABEL_LEN_MAX] ={0,};
105
106         if (_ge_get_view_mode(ugd) == GE_VIEW_THUMBS ||
107             _ge_get_view_mode(ugd) == GE_VIEW_THUMBS_EDIT) {
108                 if (ugd->file_type_mode) {
109                         if (ugd->file_type_mode == GE_FILE_T_IMAGE)
110                                 snprintf(label_str, sizeof(label_str),
111                                          "%s", (char*)GE_STR_NO_IMAGES);
112                         else if (ugd->file_type_mode == GE_FILE_T_VIDEO)
113                                 snprintf(label_str, sizeof(label_str),
114                                          "%s", (char*)GE_STR_NO_VIDEOS);
115                         else
116                                 snprintf(label_str, sizeof(label_str),
117                                          "%s", (char*)GE_STR_NO_ITEMS);
118                 } else {
119                         snprintf(label_str, sizeof(label_str), "%s",
120                                  (char*)GE_STR_NO_ITEMS);
121                 }
122         } else if (_ge_get_view_mode(ugd) == GE_VIEW_ALBUMS) {
123                 snprintf(label_str, sizeof(label_str), "%s",
124                          (char*)GE_STR_NO_ALBUMS);
125         } else {
126                 ge_dbgE("view mode is error.");
127         }
128
129         ge_dbg("\nNocontents label: %s", label_str);
130         /* Full nocontents view layout */
131         layout = elm_layout_add(ugd->naviframe);
132         GE_CHECK_NULL(layout);
133         elm_layout_theme_set(layout, "layout", "nocontents", "text");
134         elm_object_part_text_set(layout, "elm.text", label_str);
135
136         return layout;
137 }
138
139 Evas_Object *ge_ui_create_main_ly(Evas_Object *parent)
140 {
141         GE_CHECK_NULL(parent);
142         Evas_Object *layout = NULL;
143
144         layout = elm_layout_add(parent);
145         GE_CHECK_NULL(layout);
146
147         /* Apply the layout style */
148         const char *profile = elm_config_profile_get();
149         ge_dbg("profile: %s", profile);
150         if (!g_strcmp0(profile, "mobile"))      {
151                 elm_layout_theme_set(layout, "layout", "application",
152                                      "default");
153         } else if (!g_strcmp0(profile,"extension")) {
154                 elm_layout_theme_set(layout, "layout", "application",
155                                      "noindicator");
156         } else {
157                 elm_layout_theme_set(layout, "layout", "application",
158                                      "default");
159         }
160
161         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
162                                          EVAS_HINT_EXPAND);
163         evas_object_show(layout);
164         return layout;
165 }
166
167 Evas_Object* ge_ui_create_naviframe(ge_ugdata *ugd, Evas_Object *parent)
168 {
169         GE_CHECK_NULL(ugd);
170         GE_CHECK_NULL(parent);
171         Evas_Object *nf = NULL;
172
173         nf = elm_naviframe_add(parent);
174         GE_CHECK_NULL(nf);
175         /* Disable Naviframe Back Button Auto creation function */
176         elm_naviframe_prev_btn_auto_pushed_set(nf, EINA_FALSE);
177         if (ugd->th) {
178                 elm_object_theme_set(nf, ugd->th);
179         }
180         elm_object_part_content_set(parent, "elm.swallow.content", nf);
181
182         evas_object_show(nf);
183
184         return nf;
185 }
186
187 Evas_Object* ge_ui_create_popup(ge_ugdata* ugd, ge_popup_mode_e mode,
188                                 char* desc)
189 {
190         ge_dbg("");
191         GE_CHECK_NULL(ugd);
192         GE_CHECK_NULL(desc);
193
194         if (ugd->popup) {
195                 ge_dbg("The existed popup is deleted");
196                 evas_object_del(ugd->popup);
197                 ugd->popup = NULL;
198         }
199
200         Evas_Object *popup = NULL;
201
202         popup = elm_popup_add(ugd->ly_main);
203         GE_CHECK_NULL(popup);
204
205         /*Delete the Popup if the Popup has a BACK event.*/
206         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb,
207                                       NULL);
208
209         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
210                                          EVAS_HINT_EXPAND);
211         elm_object_text_set(popup, desc);
212
213         switch (mode) {
214         case GE_POPUP_NOBUT:
215         case GE_POPUP_EXIT:
216                 __ge_popup_add_timer(ugd, GE_NOBUT_EXIT_POPUP_HIDE_TIME_DELAY);
217                 break;
218         case GE_POPUP_ONEBUT:
219         {
220                 Evas_Object *btn = NULL;
221                 btn = _ge_but_create_but(popup, ugd->th, NULL, GE_STR_ID_OK,
222                                          GE_BTN_POPUP, _ge_ui_response_cb, ugd);
223                 elm_object_part_content_set(popup, "button1", btn);
224                 break;
225         }
226         case GE_POPUP_TWOBUT:
227         {
228                 Evas_Object *btn1 = NULL;
229                 btn1 = _ge_but_create_but(popup, ugd->th, NULL, GE_STR_ID_OK,
230                                           GE_BTN_POPUP, _ge_ui_response_cb,
231                                           ugd);
232                 elm_object_part_content_set(popup, "button1", btn1);
233                 Evas_Object *btn2 = NULL;
234                 btn2 = _ge_but_create_but(popup, ugd->th, NULL, GE_STR_ID_CANCEL,
235                                           GE_BTN_POPUP, _ge_ui_response_cb,
236                                           ugd);
237                 elm_object_part_content_set(popup, "button2", btn2);
238                 break;
239         }
240         default:
241                 ge_dbgE("mode is not supported...");
242                 break;
243         }
244
245         evas_object_show(popup);
246
247         ugd->popup = popup;
248         ugd->popup_mode = mode;
249
250         return popup;
251 }
252
253 int _ge_ui_create_notiinfo(const char *text)
254 {
255         GE_CHECK_VAL(text, -1);
256         int ret = notification_status_message_post(text);
257         if (ret != 0)
258                 ge_sdbgE("status_message_post()... [0x%x]!", ret);
259         return ret;
260 }
261
262 /* *
263 * In case of system folder, the displayed name should be translated into system language
264 *
265 * @param name
266 *    check album display name for getting proper translation
267 *
268 * @return
269 *    the translated album display name
270 */
271 char *_ge_ui_get_i18n_album_name(ge_album_s *cluster)
272 {
273         GE_CHECK_NULL(cluster);
274         char *i18n_name = NULL;
275
276         if (_ge_data_is_camera_album(cluster)) {
277                 /* system folder name: Camera */
278                 i18n_name = GE_STR_CAMERA;
279         } else if (_ge_data_is_default_album(GE_ALBUM_DOWNLOADS_NAME, cluster)) {
280                 /* system folder name: Downloads */
281                 i18n_name = GE_STR_DOWNLOADS;
282         } else if (cluster->type == GE_ALL) {
283                 /* Update data in memory */
284                 GE_FREEIF(cluster->display_name);
285                 cluster->display_name = strdup(GE_ALBUM_ALL_NAME);
286                 i18n_name = cluster->display_name;
287         } else if (cluster->type == GE_PHONE || cluster->type == GE_MMC) {
288                 if (_ge_data_is_root_path(cluster->path)) {
289                         /* check root case */
290                         i18n_name = GE_ALBUM_ROOT_NAME;
291                 } else {
292                         /* if the folder is not a system folder, return itself */
293                         i18n_name = cluster->display_name;
294                 }
295         } else {
296                 /* if the folder is not a system folder, return itself */
297                 i18n_name = cluster->display_name;
298         }
299
300         if (i18n_name == NULL || strlen(i18n_name) <= 0)
301                 i18n_name = GE_ALBUM_ROOT_NAME;
302
303         return i18n_name;
304 }
305
306 int _ge_ui_reset_scroller_pos(Evas_Object *obj)
307 {
308         GE_CHECK_VAL(obj, -1);
309         evas_object_data_set(obj, "prev_scroller_x", (void *)0);
310         evas_object_data_set(obj, "prev_scroller_y", (void *)0);
311         evas_object_data_set(obj, "prev_scroller_w", (void *)0);
312         evas_object_data_set(obj, "prev_scroller_h", (void *)0);
313         return 0;
314 }
315
316 int _ge_ui_del_scroller_pos(Evas_Object *obj)
317 {
318         GE_CHECK_VAL(obj, -1);
319         evas_object_data_del(obj, "prev_scroller_x");
320         evas_object_data_del(obj, "prev_scroller_y");
321         evas_object_data_del(obj, "prev_scroller_w");
322         evas_object_data_del(obj, "prev_scroller_h");
323         return 0;
324 }
325
326 int _ge_ui_save_scroller_pos(Evas_Object *obj)
327 {
328         GE_CHECK_VAL(obj, -1);
329         Evas_Coord x = 0;
330         Evas_Coord y = 0;
331         Evas_Coord w = 0;
332         Evas_Coord h = 0;
333
334         elm_scroller_region_get(obj, &x, &y, &w, &h);
335         ge_dbg("(%dx%d), (%dx%d)", x, y, w, h);
336         evas_object_data_set(obj, "prev_scroller_x", (void *)x);
337         evas_object_data_set(obj, "prev_scroller_y", (void *)y);
338         evas_object_data_set(obj, "prev_scroller_w", (void *)w);
339         evas_object_data_set(obj, "prev_scroller_h", (void *)h);
340         return 0;
341 }
342
343 int _ge_ui_restore_scroller_pos(Evas_Object *obj)
344 {
345         GE_CHECK_VAL(obj, -1);
346         Evas_Coord x = 0;
347         Evas_Coord y = 0;
348         Evas_Coord w = 0;
349         Evas_Coord h = 0;
350
351         x = (Evas_Coord)evas_object_data_get(obj, "prev_scroller_x");
352         y = (Evas_Coord)evas_object_data_get(obj, "prev_scroller_y");
353         w = (Evas_Coord)evas_object_data_get(obj, "prev_scroller_w");
354         h = (Evas_Coord)evas_object_data_get(obj, "prev_scroller_h");
355         ge_dbg("(%dx%d), (%dx%d)", x, y, w, h);
356         if (w > 0 && h > 0)
357                 elm_scroller_region_show(obj, x, y, w, h);
358         return 0;
359 }
360
361 int _ge_ui_set_translate_str(Evas_Object *obj, const char *str)
362 {
363         GE_CHECK_VAL(str, -1);
364         GE_CHECK_VAL(obj, -1);
365         char *domain = GE_STR_DOMAIN_LOCAL;
366         if (strstr(str, "IDS_COM"))
367                 domain = GE_STR_DOMAIN_SYS;
368         elm_object_domain_translatable_text_set(obj, domain, str);
369         return 0;
370 }
371
372 int _ge_ui_set_translate_part_str(Evas_Object *obj, const char *part,
373                                   const char *str)
374 {
375         GE_CHECK_VAL(str, -1);
376         GE_CHECK_VAL(part, -1);
377         GE_CHECK_VAL(obj, -1);
378
379         char *domain = GE_STR_DOMAIN_LOCAL;
380         if (strstr(str, "IDS_COM"))
381                 domain = GE_STR_DOMAIN_SYS;
382
383         elm_object_domain_translatable_part_text_set(obj, part, domain, str);
384
385         return 0;
386 }
387
388 int _ge_ui_set_translatable_item(Elm_Object_Item *nf_it, const char *str)
389 {
390         GE_CHECK_VAL(str, -1);
391         GE_CHECK_VAL(nf_it, -1);
392         char *domain = GE_STR_DOMAIN_LOCAL;
393         if (strstr(str, "IDS_COM"))
394                 domain = GE_STR_DOMAIN_SYS;
395         elm_object_item_domain_text_translatable_set(nf_it, domain, EINA_TRUE);
396         return 0;
397 }
398
399 /* Update the label text for selected item showed in naviframe title  */
400 int _ge_ui_update_label_text(Elm_Object_Item *nf_it, int sel_cnt,
401                              const char *text)
402 {
403         GE_CHECK_VAL(nf_it, -1);
404         ge_sdbg("Count: %d, text: %s", sel_cnt, text);
405         char *pd_selected = GE_STR_PD_SELECTED;
406
407         /* Update the label text */
408         if (sel_cnt > 0) {
409                 char *text = NULL;
410                 text = g_strdup_printf(pd_selected, sel_cnt);
411                 elm_object_item_text_set(nf_it, text);
412                 GE_GFREEIF(text);
413         } else {
414                 /* Don't need to update text if it's called by language_changed_cb*/
415                 elm_object_item_text_set(nf_it, text);
416                 _ge_ui_set_translatable_item(nf_it, text);
417         }
418         return 0;
419 }
420
421 int _ge_ui_get_indicator_state(ge_ugdata *ugd)
422 {
423         GE_CHECK_VAL(ugd, -1);
424         /* Save old view's indicator values */
425         ugd->indi_mode = elm_win_indicator_mode_get(ugd->win);
426         ugd->indi_o_mode = elm_win_indicator_opacity_get(ugd->win);
427         ge_dbgW("indi_o_mode: %d, indi_mode: %d", ugd->indi_o_mode,
428                 ugd->indi_mode);
429         /* Save old view's overlap mode */
430         ugd->overlap_mode = (int)evas_object_data_get(ugd->conform, "overlap");
431         ge_dbgW("overlap_mode: %d", ugd->overlap_mode);
432         return 0;
433 }
434
435 int _ge_ui_hide_indicator(ge_ugdata *ugd)
436 {
437         GE_CHECK_VAL(ugd, -1);
438         /* transparent indicator setting */
439         elm_win_indicator_mode_set(ugd->win, ELM_WIN_INDICATOR_SHOW);
440         elm_win_indicator_opacity_set(ugd->win, ELM_WIN_INDICATOR_TRANSPARENT);
441         /* Modify to start content from 0,0 */
442         elm_object_signal_emit(ugd->conform, "elm,state,indicator,overlap", "");
443         /* Save overlap mode when showing new view(ex: ug) */
444         evas_object_data_set(ugd->conform, "overlap", (void *)EINA_TRUE);
445         return 0;
446 }
447
448 #ifdef _USE_HIDE_INDICATOR
449 /********Restore indicator state of caller*********/
450 int _ge_ui_reset_indicator(ge_ugdata *ugd)
451 {
452         GE_CHECK_VAL(ugd, -1);
453         ge_dbgW("indi_o_mode: %d, indi_mode: %d", ugd->indi_o_mode,
454                 ugd->indi_mode);
455         ge_dbgW("overlap_mode: %d", ugd->overlap_mode);
456         /* Set old view's indicator */
457         elm_win_indicator_mode_set(ugd->win, ugd->indi_mode);
458         elm_win_indicator_opacity_set(ugd->win, ugd->indi_o_mode);
459         /* set old view's conformant overlap mode
460             if layout is different with new view and needs starts from (0,60) */
461         if (!ugd->overlap_mode) {
462                 elm_object_signal_emit(ugd->conform,
463                                        "elm,state,indicator,nooverlap", "");
464                 evas_object_data_set(ugd->conform, "overlap", NULL);
465         }
466         ge_dbgW("indicator restored done!");
467         return 0;
468 }
469 #endif
470
471 Evas_Object *_ge_ui_add_toolbar(Evas_Object *parent)
472 {
473         Evas_Object *toolbar = elm_toolbar_add(parent);
474         GE_CHECK_NULL(toolbar);
475         elm_object_style_set(toolbar, "default");
476         elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
477         elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
478         elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_NONE);
479         return toolbar;
480 }
481
482 Elm_Object_Item *_ge_ui_append_item(Evas_Object *obj, const char *icon,
483                                     const char *label, Evas_Smart_Cb func,
484                                     const void *data)
485 {
486         Elm_Object_Item *it = NULL;
487         it = elm_toolbar_item_append(obj, icon, label, func, data);
488         _ge_ui_set_translatable_item(it, label);
489         return it;
490 }
491
492 int _ge_ui_disable_item(Elm_Object_Item *it, Eina_Bool b_disabled)
493 {
494         GE_CHECK_VAL(it, -1);
495         /* dlog fatal is enabled. Elm_Object_Item cannot be NULL. */
496         elm_object_item_disabled_set(it, b_disabled);
497         return 0;
498 }
499