2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
17 #include "ge-ui-util.h"
19 #include "ge-button.h"
20 #include "ge-gridview.h"
21 #include "ge-albums.h"
24 #include "ge-strings.h"
27 #define HOME_ALBUM_COVER_NUM 1
28 #define VIDEO_SHARE_NUM 1
29 #define GE_NOBUT_EXIT_POPUP_HIDE_TIME_DELAY 3.0
30 #define GE_SELINFO_HIDE_TIME_DELAY 3.0
31 #define GE_CTRLBAR_STYLE_NAVIFRAME "naviframe"
32 #define GE_BUTTON_STYLE_NAVIBAR_PRE "naviframe/back_btn/default"
33 #define GE_NAVIFRAME_PREB_BTN "prev_btn"
34 #define GE_NAVIFRAME_CONTROLBAR "controlbar"
35 #define GE_TRANS_FINISHED "transition,finished"
36 ///This variable is used only for emulator.
37 static int g_angle = 0;
39 static void _ge_ui_response_cb(void *data, Evas_Object *obj, void *event_info)
41 ge_dbg("event_info: %d", (int)event_info);
43 ge_ugdata *ugd = (ge_ugdata *)data;
44 ge_dbg("popup mode: %d", ugd->popup_mode);
46 if(ugd->popup_mode == GE_Popup_UgExit)
48 ug_destroy_me(ugd->ug);
55 static Eina_Bool __ge_popup_timeout_cb(void *data)
58 ge_ugdata *ugd = (ge_ugdata *)data;
60 ecore_timer_del(ugd->del_timer);
61 ugd->del_timer = NULL;
65 evas_object_del(ugd->popup);
68 return ECORE_CALLBACK_CANCEL;
71 static int __ge_popup_add_timer(void *data, double to_inc)
73 GE_CHECK_VAL(data, -1);
74 ge_ugdata *ugd = (ge_ugdata *)data;
76 ecore_timer_del(ugd->del_timer);
77 ugd->del_timer = NULL;
80 ugd->del_timer = ecore_timer_add(to_inc, __ge_popup_timeout_cb, data);
84 static void __ge_ui_done_cb(void *data, Evas_Object *obj, void *event_info)
88 ge_ugdata *ugd = (ge_ugdata *)data;
91 elm_object_item_disabled_set((Elm_Object_Item *)event_info, EINA_TRUE);
93 if(ugd->file_select_mode) //file selection mode
95 ge_item* sel_item = NULL;
96 char* filepath_arg = NULL;
97 int sel_cnt = _ge_data_selected_list_count();
101 ge_dbg("No thumbs selected, return!");
102 ge_ui_create_popup(ugd, GE_Popup_NoButton, GE_POPUP_NO_FILES_SELECTED);
106 if(ugd->file_select_mode == GE_File_Select_Multiple) {
107 GString* selected_path = g_string_new(NULL);
109 for(i = 1; i <= sel_cnt; i++ ) {
110 _ge_data_get_selected_item_by_index(&sel_item, i);
111 if(sel_item && sel_item->item) {
112 ge_dbg("Selected [%s]", sel_item->item->file_url);
113 g_string_append(selected_path, sel_item->item->file_url);
114 g_string_append_c(selected_path, ';');
117 int str_len = strlen(selected_path->str);
118 ge_dbg("path string length = %d", str_len);
119 g_string_truncate(selected_path, str_len - 1);
121 filepath_arg = g_string_free(selected_path, false);
123 char t_str[32] = { 0, };
124 eina_convert_itoa(sel_cnt, t_str);
126 service_add_extra_data(ugd->service,
127 GE_FILE_SELECT_RETURN_COUNT,
129 service_add_extra_data(ugd->service,
130 GE_FILE_SELECT_RETURN_PATH,
132 ug_send_result(ugd->ug, ugd->service);
135 g_free(filepath_arg);
140 _ge_data_selected_list_finalize();
142 ug_destroy_me(ugd->ug);
146 static void _ge_ui_selinfo_destroy_cb(void *data, Evas_Object *obj, void *event_info)
149 ge_ugdata *ad = (ge_ugdata *)data;
151 ge_ui_destroy_selinfo(ad);
154 static int __ge_ui_disable_done_item(ge_ugdata *ugd, bool disabled)
156 ge_dbg("Disable Done item(%d)?", disabled);
157 GE_CHECK_VAL(ugd, -1);
158 GE_CHECK_VAL(ugd->thumbs_nf_it, -1);
160 Evas_Object *cbar = NULL;
161 cbar = elm_object_item_part_content_get(ugd->thumbs_nf_it, "controlbar");
162 GE_CHECK_VAL(cbar, -1);
163 Elm_Object_Item *cbar_it = NULL;
164 cbar_it = elm_toolbar_first_item_get(cbar);
165 GE_CHECK_VAL(cbar_it, -1);
166 elm_object_item_disabled_set(cbar_it, disabled);
170 static int __ge_ui_append_object_item(Evas_Object *cbar, Evas_Object *object)
172 Elm_Object_Item *item = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL);
174 elm_object_item_part_content_set(item, "object", object);
176 elm_object_item_disabled_set(item, EINA_TRUE);
180 static void __ge_ui_trans_finished_cb(void *data, Evas_Object *obj, void *event_info)
183 ge_ugdata *ugd = (ge_ugdata *)data;
185 evas_object_smart_callback_del(obj, GE_TRANS_FINISHED,
186 __ge_ui_trans_finished_cb);
188 /* Clear previous view after animation finished */
189 elm_gengrid_clear(ugd->albums_view);
192 static void _ge_ui_destroy_me_cb(void *data, Evas_Object *obj, void *event_info)
196 ge_ugdata *ugd = (ge_ugdata *)data;
197 /* Delete callback when it is clicked to prevent it is called for many times */
198 evas_object_smart_callback_del(obj, "clicked", _ge_ui_destroy_me_cb);
200 if (_ge_get_view_mode() != GE_AlbumsView_Mode) {
201 if(ugd->file_select_mode == GE_File_Select_Multiple) {
202 ge_ui_destroy_selinfo(ugd);
203 _ge_data_selected_list_finalize();
205 ge_grid_clear_view(ugd);
208 service_add_extra_data(ugd->service, GE_FILE_SELECT_RETURN_QUIT,
209 GE_FILE_SELECT_QUIT_STATE);
210 ug_send_result(ugd->ug, ugd->service);
212 ug_destroy_me(ugd->ug);
213 ge_dbg("ug_destroy_me");
216 static void _ge_ui_back_to_albums_cb(void *data, Evas_Object *obj, void *event_info)
220 ge_ugdata *ugd = (ge_ugdata *)data;
221 /* Delete callback when it is clicked to prevent it is called for many times */
222 evas_object_smart_callback_del(obj, "clicked",
223 _ge_ui_back_to_albums_cb);
225 ge_albums_back_to_view(ugd);
228 int _ge_ui_get_rotate_angle(void)
233 int ge_ui_create_title_and_push(ge_ugdata *ugd, Evas_Object* parent,
234 Evas_Object* obj, NaviTitleMode mode,
238 GE_CHECK_VAL(ugd, -1);
239 GE_CHECK_VAL(parent, -1);
240 GE_CHECK_VAL(obj, -1);
241 GE_CHECK_VAL(title, -1);
242 Elm_Object_Item *nf_it = NULL;
244 if (mode == AlbumsView_Title) {
245 ge_dbg("AlbumsView_Title");
246 /* Add cancel button */
247 Evas_Object *cancel_btn = NULL;
248 cancel_btn = elm_button_add(obj);
249 GE_CHECK_VAL(cancel_btn, -1);
251 elm_object_theme_set(cancel_btn, ugd->th);
252 elm_object_style_set(cancel_btn, GE_BUTTON_STYLE_NAVIBAR_PRE);
253 evas_object_smart_callback_add(cancel_btn, "clicked",
254 _ge_ui_destroy_me_cb, ugd);
255 nf_it = elm_naviframe_item_push(parent, title, cancel_btn, NULL,
257 } else if(mode == ThumbnailView_Title) {
258 if(ugd->file_select_mode == GE_File_Select_None) {
259 ge_dbgE("file_select_mode == GE_File_Select_None!");
263 ge_dbg("ThumbnailView_Title");
264 /* Add transition finished callback */
265 evas_object_smart_callback_add(parent, GE_TRANS_FINISHED,
266 __ge_ui_trans_finished_cb, ugd);
267 nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj,
269 /* Set pre_btn style to back button */
270 Evas_Object *back_btn = NULL;
271 back_btn = elm_object_item_part_content_get(nf_it,
272 GE_NAVIFRAME_PREB_BTN);
274 elm_object_theme_set(back_btn, ugd->th);
275 elm_object_style_set(back_btn, GE_BUTTON_STYLE_NAVIBAR_PRE);
276 evas_object_smart_callback_add(back_btn, "clicked",
277 _ge_ui_back_to_albums_cb, ugd);
282 if ((ugd->file_select_mode != GE_File_Select_One) &&
283 (_ge_get_view_mode() == GE_ThumbnailEdit_Mode)) {
284 ge_dbg("Multiple selection, show Done");
285 /* create tool controlbar downside */
286 Evas_Object *bot_bar = NULL;
287 bot_bar = elm_toolbar_add(obj);
288 GE_CHECK_VAL(bot_bar, -1);
289 elm_toolbar_shrink_mode_set(bot_bar, ELM_TOOLBAR_SHRINK_EXPAND);
290 /* add 'Done' item */
291 Elm_Object_Item *done_it = NULL;
292 done_it = elm_toolbar_item_append(bot_bar,
297 elm_object_item_disabled_set(done_it, EINA_TRUE);
299 __ge_ui_append_object_item(bot_bar, NULL);
300 __ge_ui_append_object_item(bot_bar, NULL);
301 __ge_ui_append_object_item(bot_bar, NULL);
302 /* Set tool bar to bottom */
303 elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_CONTROLBAR,
306 ugd->thumbs_nf_it = nf_it;
312 Evas_Object* ge_ui_load_edj(Evas_Object *parent, const char *file, const char *group)
314 GE_CHECK_NULL(parent);
316 GE_CHECK_NULL(group);
320 eo = elm_layout_add(parent);
323 r = elm_layout_file_set(eo, file, group);
330 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
331 evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
337 void ge_ui_set_rotate_angle(int rotate_mode)
339 g_angle = rotate_mode;
342 Evas_Object* ge_ui_create_nocontents(ge_ugdata* ugd)
345 Evas_Object *layout = NULL;
346 char label_str[GE_NOCONTENTS_LABEL_LEN_MAX] ={0,};
348 if(_ge_get_view_mode() == GE_ThumbnailView_Mode ||
349 _ge_get_view_mode() == GE_ThumbnailEdit_Mode) {
350 if(ugd->file_type_mode) {
351 if (ugd->file_type_mode == GE_File_Select_Type_Image)
352 snprintf(label_str, sizeof(label_str),
354 (char*)(_GE_GETSYSTEMSTR("IDS_COM_BODY_NO_IMAGES")));
355 else if (ugd->file_type_mode == GE_File_Select_Type_Video)
356 snprintf(label_str, sizeof(label_str),
358 (char*)GE_LABEL_NO_VIDEOS);
360 snprintf(label_str, sizeof(label_str),
362 (char*)(_GE_GETSYSTEMSTR("IDS_COM_BODY_NO_ITEMS")));
364 snprintf(label_str, sizeof(label_str), "%s",
365 (char*)(_GE_GETSYSTEMSTR("IDS_COM_BODY_NO_ITEMS")));
367 } else if(_ge_get_view_mode() == GE_AlbumsView_Mode) {
368 snprintf(label_str, sizeof(label_str), "%s",
369 (char*)GE_LABEL_NO_ALBUMS);
371 ge_dbgE("view mode is error.");
374 ge_dbg("\nNocontents label: %s", label_str);
375 /* Full nocontents view layout */
376 layout = elm_layout_add(ugd->navi_bar);
377 GE_CHECK_NULL(layout);
378 elm_object_part_text_set(layout, "elm.text", label_str);
379 elm_layout_theme_set(layout, "layout", "nocontents", "gallery_efl");
384 Evas_Object* ge_ui_create_main_ly(ge_ugdata* ugd, Evas_Object* parent)
387 GE_CHECK_NULL(parent);
388 Evas_Object *layout = NULL;
390 layout = elm_layout_add(parent);
391 GE_CHECK_NULL(layout);
393 /* Apply the layout style */
394 const char *profile = elm_config_profile_get();
395 if (!g_strcmp0(profile, "mobile")) {
396 elm_layout_theme_set(layout, "layout", "application", "default");
397 } else if (!g_strcmp0(profile,"extension")) {
398 elm_layout_theme_set(layout, "layout", "application", "noindicator");
401 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
403 elm_win_resize_object_add(parent, layout);
404 evas_object_show(layout);
409 Evas_Object* ge_ui_create_navibar(ge_ugdata* ugd, Evas_Object* parent)
412 GE_CHECK_NULL(parent);
413 Evas_Object *navi_bar = NULL;
415 navi_bar = elm_naviframe_add(parent);
416 GE_CHECK_NULL(navi_bar);
420 elm_object_theme_set(navi_bar, ugd->th);
422 elm_object_part_content_set(parent, "elm.swallow.content", navi_bar);
424 evas_object_show(navi_bar);
429 Evas_Object *ge_ui_create_popup(ge_ugdata* ugd, GE_PopupMode mode, char* desc)
437 ge_dbg("The existed popup is deleted");
438 evas_object_del(ugd->popup);
442 Evas_Object *popup = NULL;
444 popup = elm_popup_add(ugd->ly_main);
445 GE_CHECK_NULL(popup);
446 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
447 elm_object_text_set(popup, desc);
450 case GE_Popup_NoButton:
451 case GE_Popup_UgExit:
452 __ge_popup_add_timer(ugd, GE_NOBUT_EXIT_POPUP_HIDE_TIME_DELAY);
454 case GE_Popup_OneButton:
456 Evas_Object *btn = NULL;
457 btn = _ge_but_create_but(popup, GE_BUT_OK, _ge_ui_response_cb,
459 elm_object_part_content_set(popup, "button1", btn);
462 case GE_Popup_TwoButton:
464 Evas_Object *btn1 = NULL;
465 btn1 = _ge_but_create_but(popup, GE_BUT_OK, _ge_ui_response_cb,
467 elm_object_part_content_set(popup, "button1", btn1);
468 Evas_Object *btn2 = NULL;
469 btn2 = _ge_but_create_but(popup, GE_BUT_CANCEL,
470 _ge_ui_response_cb, ugd);
471 elm_object_part_content_set(popup, "button2", btn2);
475 ge_dbgE("mode is not supported...");
479 evas_object_show(popup);
482 ugd->popup_mode = mode;
487 int ge_ui_rotate_selinfo(ge_ugdata* ugd)
489 GE_CHECK_VAL(ugd, -1);
490 if (ugd->selectioninfo && ugd->selectioninfo_ly)
492 ge_dbg("selectioninfo rotation.");
493 int rotate_angle = _ge_ui_get_rotate_angle();
494 if ((rotate_angle == GE_ROTATE_LANDSCAPE) ||
495 (rotate_angle == GE_ROTATE_LANDSCAPE_UPSIDEDOWN))
497 edje_object_signal_emit(_EDJ(ugd->selectioninfo_ly), "elm,selectioninfo,ug_landscape", "elm");
501 edje_object_signal_emit(_EDJ(ugd->selectioninfo_ly), "elm,selectioninfo,ug_portrait", "elm");
508 int ge_ui_create_selinfo(ge_ugdata* ugd, Evas_Object* parent)
511 GE_CHECK_VAL(ugd, -1);
512 GE_CHECK_VAL(parent, -1);
515 char text[GE_SELINFO_TEXT_LEN_MAX] = {0,};
517 count = _ge_data_selected_list_count();
520 __ge_ui_disable_done_item(ugd, true);
521 if(ugd->file_select_mode == GE_File_Select_Multiple)
523 ge_ui_destroy_selinfo(ugd);
525 ge_dbg("@@@[Warning] no item selected@@@");
529 __ge_ui_disable_done_item(ugd, false);
531 if(ugd->file_select_mode == GE_File_Select_One)
536 all_count = _ge_data_get_count_all();
537 ge_dbg("New count , all count : %d,%d", count, all_count);
539 ge_ui_destroy_selinfo(ugd);
540 ugd->selectioninfo = elm_notify_add(parent);
541 GE_CHECK_VAL(ugd->selectioninfo, -1);
542 elm_notify_orient_set(ugd->selectioninfo, ELM_NOTIFY_ORIENT_BOTTOM);
543 evas_object_size_hint_weight_set(ugd->selectioninfo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
544 evas_object_size_hint_align_set(ugd->selectioninfo, EVAS_HINT_FILL, EVAS_HINT_FILL);
546 evas_object_smart_callback_add(ugd->selectioninfo, "timeout", _ge_ui_selinfo_destroy_cb, ugd);
547 elm_notify_timeout_set(ugd->selectioninfo, GE_SELINFO_HIDE_TIME_DELAY);
549 ugd->selectioninfo_ly = elm_layout_add(parent);
550 GE_CHECK_VAL(ugd->selectioninfo_ly, -1);
553 elm_object_theme_set(ugd->selectioninfo_ly, ugd->th);
555 elm_layout_theme_set(ugd->selectioninfo_ly, "standard", "selectioninfo", "ug_selectioninfo_viewer");
557 int rotate_angle = _ge_ui_get_rotate_angle();
558 if ((rotate_angle == GE_ROTATE_LANDSCAPE) ||
559 (rotate_angle == GE_ROTATE_LANDSCAPE_UPSIDEDOWN))
561 edje_object_signal_emit(_EDJ(ugd->selectioninfo_ly), "elm,selectioninfo,ug_landscape", "elm");
564 evas_object_size_hint_weight_set(ugd->selectioninfo_ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
565 evas_object_size_hint_align_set(ugd->selectioninfo_ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
566 elm_object_content_set(ugd->selectioninfo,ugd->selectioninfo_ly);
568 /* Add Space to fix H0100131538 */
569 snprintf(text, sizeof(text), "%s (%d)", GE_SELINFO_SELECTED, count);
570 text[strlen(text)] = '\0';
572 edje_object_signal_emit(_EDJ(ugd->thumbs_view_ly), "elm,thumb_view,state,moveup", "elm");/* move view up while selection view shown.*/
573 edje_object_part_text_set(_EDJ(ugd->selectioninfo_ly), "elm.text", text);
574 evas_object_show(ugd->selectioninfo);
579 int ge_ui_destroy_selinfo(ge_ugdata* ugd)
582 GE_CHECK_VAL(ugd, -1);
583 GE_CHECK_VAL(ugd->thumbs_view_ly, -1);
585 edje_object_signal_emit(_EDJ(ugd->thumbs_view_ly), "elm,thumb_view,state,default", "elm");/* reset view to default status.*/
586 if(ugd->file_select_mode != GE_File_Select_One && ugd->selectioninfo)
588 evas_object_smart_callback_del(ugd->selectioninfo, "timeout", _ge_ui_selinfo_destroy_cb);
591 if(ugd->selectioninfo_ly)
593 evas_object_del(ugd->selectioninfo_ly);
594 ugd->selectioninfo_ly = NULL;
597 if(ugd->selectioninfo)
599 evas_object_del(ugd->selectioninfo);
600 ugd->selectioninfo = NULL;