/* * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include "utils.h" #include "defs.h" struct icon_info _icon_info[] = { { IMAGE_USER_DEFAULT, IMAGE_USER_DEFAULT_FOCUS, IMAGE_USER_CURRENT_DEFAULT, IMAGE_USER_CURRENT_DEFAULT_FOCUS }, { IMAGE_USER_DEFAULT_02, IMAGE_USER_DEFAULT_02_FOCUS, IMAGE_USER_CURRENT_DEFAULT_02, IMAGE_USER_CURRENT_DEFAULT_02_FOCUS }, { IMAGE_USER_DEFAULT_03, IMAGE_USER_DEFAULT_03_FOCUS, IMAGE_USER_CURRENT_DEFAULT_03, IMAGE_USER_CURRENT_DEFAULT_03_FOCUS }, { IMAGE_USER_DEFAULT_04, IMAGE_USER_DEFAULT_04_FOCUS, IMAGE_USER_CURRENT_DEFAULT_04, IMAGE_USER_CURRENT_DEFAULT_04_FOCUS }, { IMAGE_USER_DEFAULT_05, IMAGE_USER_DEFAULT_05_FOCUS, IMAGE_USER_CURRENT_DEFAULT_05, IMAGE_USER_CURRENT_DEFAULT_05_FOCUS }, { IMAGE_USER_DEFAULT_06, IMAGE_USER_DEFAULT_06_FOCUS, IMAGE_USER_CURRENT_DEFAULT_06, IMAGE_USER_CURRENT_DEFAULT_06_FOCUS }, { IMAGE_USER_DEFAULT_07, IMAGE_USER_DEFAULT_07_FOCUS, IMAGE_USER_CURRENT_DEFAULT_07, IMAGE_USER_CURRENT_DEFAULT_07_FOCUS }, { IMAGE_USER_ADD, IMAGE_USER_ADD_FOCUS, ICON_ADD, ICON_ADD } }; struct icon_info *utils_get_icon_info(void) { return _icon_info; } const char *utils_get_focus_photo_from_photo(const char *photo) { int i; for (i = 0; i < MAX_ITEM_COUNT; i++) { if (!strcmp(photo, _icon_info[i].photo_file)) return _icon_info[i].focus_photo_file; } return photo; } const char *utils_get_focus_icon_from_icon(const char *icon) { int i; for (i = 0; i < MAX_ITEM_COUNT; i++) { if (!strcmp(icon, _icon_info[i].icon_file)) return _icon_info[i].focus_icon_file; } return icon; } const char *utils_get_icon_from_photo(const char *photo) { int i; for (i = 0; i < MAX_ITEM_COUNT; i++) { if (!strcmp(photo, _icon_info[i].photo_file)) return _icon_info[i].icon_file; } return photo; } const char *utils_get_photo_from_icon(const char *icon) { int i; for (i = 0; i < MAX_ITEM_COUNT; i++) { if (!strcmp(icon, _icon_info[i].icon_file)) return _icon_info[i].photo_file; } return icon; } Evas_Object *utils_add_layout(Evas_Object *base, const char *group, bool focus_allow, const char *part) { Evas_Object *ly; if (!base || !group) { _ERR("Invalid argument"); return NULL; } ly = elm_layout_add(base); if (!ly) { _ERR("failed to add layout"); return false; } elm_layout_file_set(ly, EDJEFILE, group); if (focus_allow) elm_object_focus_allow_set(ly, EINA_TRUE); if (part) elm_object_part_content_set(base, part, ly); return ly; } Evas_Object *utils_add_icon(Evas_Object *base, const char *file, const char *part) { Evas_Object *ic; if (!base || !file) { _ERR("Invalid argument"); return NULL; } ic = elm_icon_add(base); if (!ic) { _ERR("failed to add icon"); return NULL; } elm_image_file_set(ic, file, NULL); if (part) elm_object_part_content_set(base, part, ic); evas_object_show(ic); return ic; } Evas_Object *utils_add_label(Evas_Object *base, char *text, const char *style, const char *part) { Evas_Object *lbl; const char *s; if (!base || !text) { _ERR("Invalid argument"); return NULL; } lbl = elm_label_add(base); if (!lbl) { _ERR("failed to add label"); return NULL; } if (style) elm_object_style_set(lbl, style); s = edje_object_data_get(elm_layout_edje_get(base), TITLE_WIDTH); if (s) elm_label_wrap_width_set(lbl, atoi(s)); elm_label_ellipsis_set(lbl, EINA_TRUE); elm_object_text_set(lbl, text); if (part) elm_object_part_content_set(base, part, lbl); evas_object_show(lbl); return lbl; } Evas_Object *utils_add_bg(Evas_Object *base, int r, int g, int b, int a, const char *part) { Evas_Object *bg; if (!base) { _ERR("Invalid argument"); return NULL; } bg = evas_object_rectangle_add(evas_object_evas_get(base)); if (!bg) { _ERR("failed to add label"); return NULL; } evas_object_color_set(bg, r, g, b, a); if (part) elm_object_part_content_set(base, part, bg); evas_object_show(bg); return bg; } Evas_Object *utils_add_scroller(Evas_Object *base) { Evas_Object *scr; scr = elm_scroller_add(base); if (!scr) { _ERR("failed to add scroller"); return NULL; } elm_scroller_policy_set(scr, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); evas_object_show(scr); return scr; } Evas_Object *utils_add_box(Evas_Object *base, bool horizon) { Evas_Object *box; box = elm_box_add(base); if (!box) { _ERR("failed to add box"); return NULL; } if (horizon) elm_box_horizontal_set(box, EINA_TRUE); evas_object_show(box); return box; } Evas_Object *utils_add_table(Evas_Object *base, bool homo, const char *part) { Evas_Object *table; table = elm_table_add(base); if (!table) { _ERR("failed to add table"); return NULL; } if (homo) elm_table_homogeneous_set(table, EINA_TRUE); if (part) elm_object_part_content_set(base, part, table); return table; } Evas_Object *utils_add_button(Evas_Object *base, char *text, const char *part) { Evas_Object *btn; btn = elm_button_add(base); if (!btn) { _ERR("failed to add btn"); return NULL; } if (part) elm_object_part_content_set(base, part, btn); if (text) elm_object_text_set(btn, text); evas_object_show(btn); return btn; } static void _entry_focused(int id, void *data, Evas_Object *obj, Elm_Object_Item *item) { elm_object_signal_emit(data, SIG_FOCUS, SRC_PROG); } static void _entry_unfocused(int id, void *data, Evas_Object *obj, Elm_Object_Item *item) { elm_object_signal_emit(data, SIG_UNFOCUS, SRC_PROG); } static input_handler entry_handle = { .focused = _entry_focused, .unfocused = _entry_unfocused }; Evas_Object *utils_add_entry(Evas_Object *base, char *text, bool password, const char *part) { Evas_Object *ly, *entry; ly = utils_add_layout(base, GRP_USER_EDIT_ENTRY, false, part); if (!ly) { _ERR("failed to add entry layout"); return NULL; } entry = elm_entry_add(ly); if (!entry) { _ERR("failed to add entry"); return NULL; } if (password) { elm_entry_password_set(entry, EINA_TRUE); elm_config_password_show_last_set(EINA_FALSE); } elm_object_style_set(entry, STYLE_INPUT); elm_entry_single_line_set(entry, EINA_TRUE); elm_entry_input_panel_language_set(entry, ELM_INPUT_PANEL_LANG_ALPHABET); elm_entry_cursor_end_set(entry); elm_entry_scrollable_set(entry, EINA_TRUE); elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); if (text) elm_entry_entry_set(entry, text); elm_object_part_content_set(ly, PART_USER_EDIT_ENTRY, entry); inputmgr_add_callback(entry, 0, &entry_handle, ly); evas_object_show(entry); return entry; } Evas_Object *utils_add_popup(Evas_Object *base, char *title, char *message) { Evas_Object *popup; if (!base) { _ERR("Invalid argument"); return NULL; } popup = elm_popup_add(base); if (!popup) { _ERR("failed to add popup"); return NULL; } if (title) elm_object_part_text_set(popup, PART_TITLE_TEXT, title); if (message) elm_object_text_set(popup, message); elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER); evas_object_show(popup); return popup; } bool utils_launch_app(const char *pkg) { app_control_h app_control; int r; if (!pkg) { _ERR("Invalid argument"); return false; } app_control_create(&app_control); app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT); app_control_set_app_id(app_control, pkg); r = app_control_send_launch_request(app_control, NULL, NULL); if (r != APP_CONTROL_ERROR_NONE) { _ERR("failed to launch pkg"); app_control_destroy(app_control); return false; } app_control_destroy(app_control); return true; }