2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <notification.h>
19 #include "ge-ui-util.h"
21 #include "ge-button.h"
22 #include "ge-gridview.h"
23 #include "ge-albums.h"
26 #include <efl_extension.h>
28 #define GE_NOBUT_EXIT_POPUP_HIDE_TIME_DELAY 3.0
30 static void _ge_ui_response_cb(void *data, Evas_Object *obj, void *ei)
33 ge_ugdata *ugd = (ge_ugdata *)data;
34 ge_dbg("popup mode: %d", ugd->popup_mode);
40 static Eina_Bool __ge_popup_timeout_cb(void *data)
43 ge_ugdata *ugd = (ge_ugdata *)data;
45 ecore_timer_del(ugd->del_timer);
46 ugd->del_timer = NULL;
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);
58 GE_IF_DEL_OBJ(ugd->popup);
59 return ECORE_CALLBACK_CANCEL;
62 static int __ge_popup_add_timer(void *data, double to_inc)
64 GE_CHECK_VAL(data, -1);
65 ge_ugdata *ugd = (ge_ugdata *)data;
67 ecore_timer_del(ugd->del_timer);
68 ugd->del_timer = NULL;
71 ugd->del_timer = ecore_timer_add(to_inc, __ge_popup_timeout_cb, data);
75 Evas_Object* ge_ui_load_edj(Evas_Object *parent, const char *file, const char *group)
77 GE_CHECK_NULL(parent);
83 eo = elm_layout_add(parent);
86 r = elm_layout_file_set(eo, file, group);
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);
100 Evas_Object* ge_ui_create_nocontents(ge_ugdata* ugd)
103 Evas_Object *layout = NULL;
104 char label_str[GE_NOCONTENTS_LABEL_LEN_MAX] ={0,};
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);
116 snprintf(label_str, sizeof(label_str),
117 "%s", (char*)GE_STR_NO_ITEMS);
119 snprintf(label_str, sizeof(label_str), "%s",
120 (char*)GE_STR_NO_ITEMS);
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);
126 ge_dbgE("view mode is error.");
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);
139 Evas_Object *ge_ui_create_main_ly(Evas_Object *parent)
141 GE_CHECK_NULL(parent);
142 Evas_Object *layout = NULL;
144 layout = elm_layout_add(parent);
145 GE_CHECK_NULL(layout);
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",
153 } else if (!g_strcmp0(profile,"extension")) {
154 elm_layout_theme_set(layout, "layout", "application",
157 elm_layout_theme_set(layout, "layout", "application",
161 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
163 evas_object_show(layout);
167 Evas_Object* ge_ui_create_naviframe(ge_ugdata *ugd, Evas_Object *parent)
170 GE_CHECK_NULL(parent);
171 Evas_Object *nf = NULL;
173 nf = elm_naviframe_add(parent);
175 /* Disable Naviframe Back Button Auto creation function */
176 elm_naviframe_prev_btn_auto_pushed_set(nf, EINA_FALSE);
178 elm_object_theme_set(nf, ugd->th);
180 elm_object_part_content_set(parent, "elm.swallow.content", nf);
182 evas_object_show(nf);
187 Evas_Object* ge_ui_create_popup(ge_ugdata* ugd, ge_popup_mode_e mode,
195 ge_dbg("The existed popup is deleted");
196 evas_object_del(ugd->popup);
200 Evas_Object *popup = NULL;
202 popup = elm_popup_add(ugd->ly_main);
203 GE_CHECK_NULL(popup);
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,
209 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
211 elm_object_text_set(popup, desc);
216 __ge_popup_add_timer(ugd, GE_NOBUT_EXIT_POPUP_HIDE_TIME_DELAY);
218 case GE_POPUP_ONEBUT:
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);
226 case GE_POPUP_TWOBUT:
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,
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,
237 elm_object_part_content_set(popup, "button2", btn2);
241 ge_dbgE("mode is not supported...");
245 evas_object_show(popup);
248 ugd->popup_mode = mode;
253 int _ge_ui_create_notiinfo(const char *text)
255 GE_CHECK_VAL(text, -1);
256 int ret = notification_status_message_post(text);
258 ge_sdbgE("status_message_post()... [0x%x]!", ret);
263 * In case of system folder, the displayed name should be translated into system language
266 * check album display name for getting proper translation
269 * the translated album display name
271 char *_ge_ui_get_i18n_album_name(ge_album_s *cluster)
273 GE_CHECK_NULL(cluster);
274 char *i18n_name = NULL;
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;
292 /* if the folder is not a system folder, return itself */
293 i18n_name = cluster->display_name;
296 /* if the folder is not a system folder, return itself */
297 i18n_name = cluster->display_name;
300 if (i18n_name == NULL || strlen(i18n_name) <= 0)
301 i18n_name = GE_ALBUM_ROOT_NAME;
306 int _ge_ui_reset_scroller_pos(Evas_Object *obj)
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);
316 int _ge_ui_del_scroller_pos(Evas_Object *obj)
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");
326 int _ge_ui_save_scroller_pos(Evas_Object *obj)
328 GE_CHECK_VAL(obj, -1);
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);
343 int _ge_ui_restore_scroller_pos(Evas_Object *obj)
345 GE_CHECK_VAL(obj, -1);
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);
357 elm_scroller_region_show(obj, x, y, w, h);
361 int _ge_ui_set_translate_str(Evas_Object *obj, const char *str)
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);
372 int _ge_ui_set_translate_part_str(Evas_Object *obj, const char *part,
375 GE_CHECK_VAL(str, -1);
376 GE_CHECK_VAL(part, -1);
377 GE_CHECK_VAL(obj, -1);
379 char *domain = GE_STR_DOMAIN_LOCAL;
380 if (strstr(str, "IDS_COM"))
381 domain = GE_STR_DOMAIN_SYS;
383 elm_object_domain_translatable_part_text_set(obj, part, domain, str);
388 int _ge_ui_set_translatable_item(Elm_Object_Item *nf_it, const char *str)
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);
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,
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;
407 /* Update the label text */
410 text = g_strdup_printf(pd_selected, sel_cnt);
411 elm_object_item_text_set(nf_it, text);
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);
421 int _ge_ui_get_indicator_state(ge_ugdata *ugd)
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,
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);
435 int _ge_ui_hide_indicator(ge_ugdata *ugd)
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);
448 #ifdef _USE_HIDE_INDICATOR
449 /********Restore indicator state of caller*********/
450 int _ge_ui_reset_indicator(ge_ugdata *ugd)
452 GE_CHECK_VAL(ugd, -1);
453 ge_dbgW("indi_o_mode: %d, indi_mode: %d", ugd->indi_o_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);
466 ge_dbgW("indicator restored done!");
471 Evas_Object *_ge_ui_add_toolbar(Evas_Object *parent)
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);
482 Elm_Object_Item *_ge_ui_append_item(Evas_Object *obj, const char *icon,
483 const char *label, Evas_Smart_Cb func,
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);
492 int _ge_ui_disable_item(Elm_Object_Item *it, Eina_Bool b_disabled)
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);