2 * Copyright (c) 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.
17 #include <Elementary.h>
18 #include <app_debug.h>
26 struct icon_info _icon_info[] = {
29 IMAGE_USER_DEFAULT_FOCUS,
30 IMAGE_USER_CURRENT_DEFAULT,
31 IMAGE_USER_CURRENT_DEFAULT_FOCUS
34 IMAGE_USER_DEFAULT_02,
35 IMAGE_USER_DEFAULT_02_FOCUS,
36 IMAGE_USER_CURRENT_DEFAULT_02,
37 IMAGE_USER_CURRENT_DEFAULT_02_FOCUS
40 IMAGE_USER_DEFAULT_03,
41 IMAGE_USER_DEFAULT_03_FOCUS,
42 IMAGE_USER_CURRENT_DEFAULT_03,
43 IMAGE_USER_CURRENT_DEFAULT_03_FOCUS
46 IMAGE_USER_DEFAULT_04,
47 IMAGE_USER_DEFAULT_04_FOCUS,
48 IMAGE_USER_CURRENT_DEFAULT_04,
49 IMAGE_USER_CURRENT_DEFAULT_04_FOCUS
52 IMAGE_USER_DEFAULT_05,
53 IMAGE_USER_DEFAULT_05_FOCUS,
54 IMAGE_USER_CURRENT_DEFAULT_05,
55 IMAGE_USER_CURRENT_DEFAULT_05_FOCUS
58 IMAGE_USER_DEFAULT_06,
59 IMAGE_USER_DEFAULT_06_FOCUS,
60 IMAGE_USER_CURRENT_DEFAULT_06,
61 IMAGE_USER_CURRENT_DEFAULT_06_FOCUS
64 IMAGE_USER_DEFAULT_07,
65 IMAGE_USER_DEFAULT_07_FOCUS,
66 IMAGE_USER_CURRENT_DEFAULT_07,
67 IMAGE_USER_CURRENT_DEFAULT_07_FOCUS
77 struct icon_info *utils_get_icon_info(void)
82 const char *utils_get_focus_photo_from_photo(const char *photo)
86 for (i = 0; i < MAX_ITEM_COUNT; i++) {
87 if (!strcmp(photo, _icon_info[i].photo_file))
88 return _icon_info[i].focus_photo_file;
94 const char *utils_get_focus_icon_from_icon(const char *icon)
98 for (i = 0; i < MAX_ITEM_COUNT; i++) {
99 if (!strcmp(icon, _icon_info[i].icon_file))
100 return _icon_info[i].focus_icon_file;
106 const char *utils_get_icon_from_photo(const char *photo)
110 for (i = 0; i < MAX_ITEM_COUNT; i++) {
111 if (!strcmp(photo, _icon_info[i].photo_file))
112 return _icon_info[i].icon_file;
118 const char *utils_get_photo_from_icon(const char *icon)
122 for (i = 0; i < MAX_ITEM_COUNT; i++) {
123 if (!strcmp(icon, _icon_info[i].icon_file))
124 return _icon_info[i].photo_file;
130 Evas_Object *utils_add_layout(Evas_Object *base, const char *group,
131 bool focus_allow, const char *part)
135 if (!base || !group) {
136 _ERR("Invalid argument");
140 ly = elm_layout_add(base);
142 _ERR("failed to add layout");
145 elm_layout_file_set(ly, EDJEFILE, group);
148 elm_object_focus_allow_set(ly, EINA_TRUE);
150 elm_object_part_content_set(base, part, ly);
155 Evas_Object *utils_add_icon(Evas_Object *base, const char *file,
160 if (!base || !file) {
161 _ERR("Invalid argument");
165 ic = elm_image_add(base);
167 _ERR("failed to add icon");
171 elm_image_file_set(ic, file, NULL);
174 elm_object_part_content_set(base, part, ic);
175 elm_image_fill_outside_set(ic, EINA_TRUE);
177 evas_object_show(ic);
182 Evas_Object *utils_add_label(Evas_Object *base, char *text,
183 const char *style, const char *part)
188 if (!base || !text) {
189 _ERR("Invalid argument");
193 lbl = elm_label_add(base);
195 _ERR("failed to add label");
200 elm_object_style_set(lbl, style);
202 s = edje_object_data_get(elm_layout_edje_get(base), TITLE_WIDTH);
204 elm_label_wrap_width_set(lbl, atoi(s));
206 elm_label_ellipsis_set(lbl, EINA_TRUE);
207 elm_object_text_set(lbl, text);
210 elm_object_part_content_set(base, part, lbl);
212 evas_object_show(lbl);
217 Evas_Object *utils_add_bg(Evas_Object *base, int r, int g, int b, int a,
223 _ERR("Invalid argument");
227 bg = evas_object_rectangle_add(evas_object_evas_get(base));
229 _ERR("failed to add label");
233 evas_object_color_set(bg, r, g, b, a);
236 elm_object_part_content_set(base, part, bg);
238 evas_object_show(bg);
243 Evas_Object *utils_add_scroller(Evas_Object *base)
247 scr = elm_scroller_add(base);
249 _ERR("failed to add scroller");
253 elm_scroller_policy_set(scr, ELM_SCROLLER_POLICY_OFF,
254 ELM_SCROLLER_POLICY_OFF);
255 evas_object_show(scr);
260 Evas_Object *utils_add_box(Evas_Object *base, bool horizon)
264 box = elm_box_add(base);
266 _ERR("failed to add box");
271 elm_box_horizontal_set(box, EINA_TRUE);
273 evas_object_show(box);
278 Evas_Object *utils_add_table(Evas_Object *base, bool homo, const char *part)
282 table = elm_table_add(base);
284 _ERR("failed to add table");
289 elm_table_homogeneous_set(table, EINA_TRUE);
292 elm_object_part_content_set(base, part, table);
297 Evas_Object *utils_add_button(Evas_Object *base, char *text, const char *part)
301 btn = elm_button_add(base);
303 _ERR("failed to add btn");
308 elm_object_part_content_set(base, part, btn);
310 elm_object_text_set(btn, text);
311 evas_object_show(btn);
316 static void _entry_focused(int id, void *data, Evas_Object *obj,
317 Elm_Object_Item *item)
319 elm_object_signal_emit(data, SIG_FOCUS, SRC_PROG);
322 static void _entry_unfocused(int id, void *data, Evas_Object *obj,
323 Elm_Object_Item *item)
325 elm_object_signal_emit(data, SIG_UNFOCUS, SRC_PROG);
328 static input_handler entry_handle = {
329 .focused = _entry_focused,
330 .unfocused = _entry_unfocused
333 Evas_Object *utils_add_entry(Evas_Object *base, char *text, bool password,
336 Evas_Object *ly, *entry;
338 ly = utils_add_layout(base, GRP_USER_EDIT_ENTRY, false, part);
340 _ERR("failed to add entry layout");
344 entry = elm_entry_add(ly);
346 _ERR("failed to add entry");
351 elm_entry_password_set(entry, EINA_TRUE);
352 elm_config_password_show_last_set(EINA_FALSE);
355 elm_object_style_set(entry, STYLE_INPUT);
356 elm_entry_single_line_set(entry, EINA_TRUE);
357 elm_entry_input_panel_language_set(entry,
358 ELM_INPUT_PANEL_LANG_ALPHABET);
359 elm_entry_cursor_end_set(entry);
360 elm_entry_scrollable_set(entry, EINA_TRUE);
361 elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF,
362 ELM_SCROLLER_POLICY_OFF);
364 elm_entry_entry_set(entry, text);
365 elm_object_part_content_set(ly, PART_USER_EDIT_ENTRY, entry);
367 inputmgr_add_callback(entry, 0, &entry_handle, ly);
368 evas_object_show(entry);
373 Evas_Object *utils_add_popup(Evas_Object *base, char *title, char *message)
378 _ERR("Invalid argument");
382 popup = elm_popup_add(base);
384 _ERR("failed to add popup");
389 elm_object_part_text_set(popup, PART_TITLE_TEXT, title);
391 elm_object_text_set(popup, message);
393 elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
394 evas_object_show(popup);
399 bool utils_launch_app(const char *pkg)
401 app_control_h app_control;
405 _ERR("Invalid argument");
409 app_control_create(&app_control);
410 app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
411 app_control_set_app_id(app_control, pkg);
413 r = app_control_send_launch_request(app_control, NULL, NULL);
414 if (r != APP_CONTROL_ERROR_NONE) {
415 _ERR("failed to launch pkg");
416 app_control_destroy(app_control);
420 app_control_destroy(app_control);