Added more verbose error to view_set_image.
[apps/native/sample/sample-core-components.git] / rule / project / src / view.c
1 /*
2  * Copyright (c) 2016 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 static struct view_info {
18         Evas_Object *win;
19         Evas_Object *conform;
20 } s_info = {
21         .win = NULL,
22         .conform = NULL,
23 };
24
25 /*
26  * @brief: Create Essential Object window, conformant and layout
27  */
28 void view_create(void)
29 {
30         /* Create window */
31         s_info.win = view_create_win(PACKAGE);
32         if (s_info.win == NULL) {
33                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a window.");
34                 return;
35         }
36
37         /* Create conformant */
38         s_info.conform = view_create_conformant_without_indicator(s_info.win);
39         if (s_info.conform == NULL) {
40                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a conformant");
41                 return;
42         }
43
44         /* Show window after main view is set up */
45         evas_object_show(s_info.win);
46 }
47
48 /*
49  * @brief: Make a basic window named package
50  * @param[pkg_name]: Name of the window
51  */
52 Evas_Object *view_create_win(const char *pkg_name)
53 {
54         Evas_Object *win = NULL;
55
56         /*
57          * Window
58          * Create and initialize elm_win.
59          * elm_win is mandatory to manipulate window
60          */
61         win = elm_win_util_standard_add(pkg_name, pkg_name);
62         elm_win_conformant_set(win, EINA_TRUE);
63         elm_win_autodel_set(win, EINA_TRUE);
64
65         /* Rotation setting */
66         if (elm_win_wm_rotation_supported_get(win)) {
67                 int rots[4] = { 0, 90, 180, 270 };
68                 elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
69         }
70
71         evas_object_smart_callback_add(win, "delete,request", _win_delete_request_cb, NULL);
72
73         return win;
74 }
75
76 /*
77  * @brief: Make a conformant without indicator for wearable app
78  * @param[win]: The object to which you want to set this conformant
79  * Conformant is mandatory for base GUI to have proper size
80  */
81 Evas_Object *view_create_conformant_without_indicator(Evas_Object *win)
82 {
83         /*
84          * Conformant
85          * Create and initialize elm_conformant.
86          * elm_conformant is mandatory for base GUI to have proper size
87          * when indicator or virtual keypad is visible.
88          */
89         Evas_Object *conform = NULL;
90
91         if (win == NULL) {
92                 dlog_print(DLOG_ERROR, LOG_TAG, "window is NULL.");
93                 return NULL;
94         }
95
96         conform = elm_conformant_add(win);
97         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
98         elm_win_resize_object_add(win, conform);
99
100         evas_object_show(conform);
101
102         return conform;
103 }
104
105 /*
106  * @brief: Make a layout to target parent object with edje file
107  * @param[parent]: The object to which you want to add this layout
108  * @param[file_path]: File path of EDJ file will be used
109  * @param[group_name]: Name of group in EDJ you want to set to
110  * @param[cb_function]: The function will be called when back event is detected
111  * @param[user_data]: The user data to be passed to the callback functions
112  */
113 Evas_Object *view_create_layout(Evas_Object *parent, const char *file_path, const char *group_name, Eext_Event_Cb cb_function, void *user_data)
114 {
115         Evas_Object *layout = NULL;
116
117         if (parent == NULL) {
118                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
119                 return NULL;
120         }
121
122         /* Create layout by EDC(edje file) */
123         layout = elm_layout_add(parent);
124         elm_layout_file_set(layout, file_path, group_name);
125
126         /* Layout size setting */
127         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
128
129         if (cb_function)
130                 eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, cb_function, user_data);
131
132         evas_object_show(layout);
133
134         return layout;
135 }
136
137 /*
138  * @brief: Make and set a layout to conformant
139  * @param[parent]: Target conformant object
140  * @param[file_path]: File path of EDJ will be used
141  * @param[group_name]: Group name in EDJ you want to set to layout
142  * @param[cb_function]: The function will be called when the back event is detected
143  * @param[user_data]: The user data to be passed to the callback functions
144  */
145 Evas_Object *view_create_layout_for_conformant(Evas_Object *parent, const char *file_path, const char *group_name, Eext_Event_Cb cb_function, void *user_data)
146 {
147         Evas_Object *layout = NULL;
148
149         if (parent == NULL) {
150                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
151                 return NULL;
152         }
153
154         /* Create layout for conformant */
155         if (file_path == NULL) {
156                 layout = view_create_layout_by_theme(parent, "layout", "application", "default");
157         } else {
158                 layout = view_create_layout(parent, file_path, group_name, cb_function, user_data);
159         }
160
161         if (layout == NULL) {
162                 dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL.");
163                 return NULL;
164         }
165
166         elm_object_content_set(parent, layout);
167
168         return layout;
169 }
170
171 /*
172  * @brief: Make a layout with theme.
173  * @param[parent]: Object to which you want to add this layout
174  * @param[class_name]: The class of the group
175  * @param[group_name]: Group name in EDJ that you want to set to layout
176  * @param[style]: The style to use
177  */
178 Evas_Object *view_create_layout_by_theme(Evas_Object *parent, const char *class_name, const char *group_name, const char *style)
179 {
180         /*
181          * Layout
182          * Create and initialize elm_layout.
183          * view_create_layout_by_theme() is used to create layout by using premade edje file.
184          */
185         Evas_Object *layout = NULL;
186
187         if (parent == NULL) {
188                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
189                 return NULL;
190         }
191
192         layout = elm_layout_add(parent);
193         elm_layout_theme_set(layout, class_name, group_name, style);
194         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
195
196         evas_object_show(layout);
197
198         return layout;
199 }
200
201 /*
202  * @brief: Make and set a layout to the part
203  * @param[parent]: Object to which you want to set this layout
204  * @param[file_path]: File path of EDJ will be used
205  * @param[group_name]: Group name in EDJ that you want to set to layout
206  * @param[part_name]: Part name to which you want to set this layout
207  */
208 Evas_Object *view_create_layout_for_part(Evas_Object *parent, char *file_path, char *group_name, char *part_name)
209 {
210         Evas_Object *layout = NULL;
211
212         if (parent == NULL) {
213                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
214                 return NULL;
215         }
216
217         layout = elm_layout_add(parent);
218         elm_layout_file_set(layout, file_path, group_name);
219         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
220
221         evas_object_show(layout);
222
223         elm_object_part_content_set(parent, part_name, layout);
224
225         return layout;
226 }
227
228 /*
229  * @brief: Destroy window and free important data to finish this application
230  */
231 void view_destroy(void)
232 {
233         if (s_info.win == NULL) {
234                 return;
235         }
236
237         evas_object_del(s_info.win);
238 }
239
240 /*
241  * @brief: Destroy given layout
242  * @param[layout]: The layout you want to destroy
243  */
244 void view_destroy_layout(Evas_Object *layout)
245 {
246         evas_object_del(layout);
247 }
248
249 /*
250  * @brief: Set image to given part
251  * @param[parent]: Object has part to which you want to set this image
252  * @param[part_name]: Part name to which you want to set this image
253  * @param[image_path]: Path of the image file
254  */
255 void view_set_image(Evas_Object *parent, const char *part_name, const char *image_path)
256 {
257         Evas_Object *image = NULL;
258
259         if (parent == NULL) {
260                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
261                 return;
262         }
263
264         image = elm_object_part_content_get(parent, part_name);
265         if (image == NULL) {
266                 image = elm_image_add(parent);
267                 if (image == NULL) {
268                         dlog_print(DLOG_ERROR, LOG_TAG, "failed to create an image object.");
269                         return;
270                 }
271
272                 elm_object_part_content_set(parent, part_name, image);
273         }
274
275         if (EINA_FALSE == elm_image_file_set(image, image_path, NULL)) {
276                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to set image: %s", image_path);
277                 return;
278         }
279
280         evas_object_show(image);
281
282         return;
283 }
284
285 /*
286  * @brief: Set text to the part
287  * @param[parent]: Object has part to which you want to set text
288  * @param[part_name]: Part name to which you want to set the text
289  * @param[text]: Text you want to set to the part
290  */
291 void view_set_text(Evas_Object *parent, const char *part_name, const char *text)
292 {
293         if (parent == NULL) {
294                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
295                 return;
296         }
297
298         /* Set text of target part object */
299         elm_object_part_text_set(parent, part_name, text);
300 }
301
302 /*
303  * @brief: Set color of the part
304  * @param[parent]: Object has part to which you want to set color
305  * @param[part_name]: Name of part to which you want to set color
306  * @param[r]: R of RGBA you want to set to the part
307  * @param[g]: G of RGBA you want to set to the part
308  * @param[b]: B of RGBA you want to set to the part
309  * @param[a]: A of RGBA you want to set to the part
310  */
311 void view_set_color(Evas_Object *parent, const char *part_name, int r, int g, int b, int a)
312 {
313         Evas_Object *obj = NULL;
314
315         if (parent == NULL) {
316                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
317                 return;
318         }
319
320         obj = elm_object_part_content_get(parent, part_name);
321         if (obj == NULL) {
322                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get parent.");
323                 return;
324         }
325
326         /* Set color of target part object */
327         evas_object_color_set(obj, r, g, b, a);
328 }
329
330 /*
331  * @brief: Set the color of circle line and font in a given circle object
332  * @param[parent]: Object has part to which you want to set color
333  * @param[part_name]: Name of part to which you want to set color
334  * @param[r] The red component of the given color
335  * @param[g] The green component of the given color
336  * @param[b] The blue component of the given color
337  * @param[a] The alpha component of the given color
338  */
339 void view_set_color_of_circle_object(Evas_Object *parent, const char *part_name, int r, int g, int b, int a)
340 {
341         Evas_Object *obj = NULL;
342
343         if (parent == NULL) {
344                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
345                 return;
346         }
347
348         /* if the "part" is NULL, this function will get the content from "default" part */
349         obj = elm_object_part_content_get(parent, part_name);
350         if (obj == NULL) {
351                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get parent.");
352                 return;
353         }
354
355         /* Set color of target part object */
356         eext_circle_object_color_set(obj, r, g, b, a);
357 }
358
359 /*
360  * @brief: Make a naviframe and set to parent
361  * @param[parent]: Object to which you want to set naviframe
362  * @Add callback function will be operated when back key is pressed
363  */
364 Evas_Object *view_create_naviframe(Evas_Object *parent)
365 {
366         /* Naviframe
367          * Create and initialize elm_naviframe.
368          * Naviframe stands for navigation frame.
369          * elm_naviframe is a views manager for applications.
370          */
371         Evas_Object *nf = NULL;
372
373         if (parent == NULL) {
374                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
375                 return NULL;
376         }
377
378         nf = elm_naviframe_add(parent);
379
380         elm_object_part_content_set(parent, "elm.swallow.content", nf);
381         eext_object_event_callback_add(nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
382         eext_object_event_callback_add(nf, EEXT_CALLBACK_MORE, eext_naviframe_more_cb, NULL);
383
384         evas_object_show(nf);
385
386         return nf;
387 }
388
389 /*
390  * @brief: Push item to naviframe
391  * @param[nf]: Naviframe has several views
392  * @param[item]: Object will be added to naviframe
393  * @param[pop_cb]: Function will be operated when this item is popped from naviframe
394  * @param[user_data]: Data passed to the 'pop_cb' function
395  * Naviframe make changing of view is easy and effectively
396  */
397 Elm_Object_Item* view_push_item_to_naviframe(Evas_Object *nf, Evas_Object *item, Elm_Naviframe_Item_Pop_Cb pop_cb, void *user_data)
398 {
399         Elm_Object_Item* nf_it = NULL;
400
401         if (nf == NULL) {
402                 dlog_print(DLOG_ERROR, LOG_TAG, "naviframe is NULL.");
403                 return NULL;
404         }
405
406         if (item == NULL) {
407                 dlog_print(DLOG_ERROR, LOG_TAG, "item is NULL.");
408                 return NULL;
409         }
410
411         nf_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, item, "empty");
412
413         if (pop_cb != NULL)
414                 elm_naviframe_item_pop_cb_set(nf_it, pop_cb, user_data);
415
416         return nf_it;
417 }
418
419 /*
420  * @brief: Set a more button
421  * @param[parent]: Object has part to which you want to set
422  * @param[part]: Part name to which you want to set
423  * @param[opened_cb]: Function will be operated when the more button is opened
424  * @param[closed_cb]: Function will be operated when the more button is closed
425  * @param[seleted_cb]: Function will be operated when the more button item is selected
426  * @param[user_data]: Data needed in this function
427  */
428 void view_set_more_button(Evas_Object *parent, const char *part, Evas_Smart_Cb opened_cb, Evas_Smart_Cb closed_cb, Evas_Smart_Cb seleted_cb, void *user_data)
429 {
430         Evas_Object *more_btn = NULL;
431
432         if (parent == NULL) {
433                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
434                 return;
435         }
436
437         more_btn = eext_more_option_add(parent);
438         if (more_btn == NULL) {
439                 dlog_print(DLOG_ERROR, LOG_TAG, "more option is NULL.");
440                 return;
441         }
442
443         /* Add smart callback */
444         evas_object_smart_callback_add(more_btn, "more,option,opened", opened_cb, user_data);
445         evas_object_smart_callback_add(more_btn, "more,option,closed", closed_cb, user_data);
446         evas_object_smart_callback_add(more_btn, "item,selected", seleted_cb, user_data);
447
448         elm_object_part_content_set(parent, part, more_btn);
449 }
450
451 /*
452  * @brief: Make and set button.
453  * @param[parent]: Object to which you want to set the button
454  * @param[part_name]: Name of part to which you want to set the button
455  * @param[style]: Style of the button
456  * @param[image_path]: Path of image file will be used as button icon
457  * @param[text]: The text will be written on the button
458  * @param[down_cb]: Function will be operated when the button is pressed
459  * @param[up_cb]: Function will be operated when the button is released
460  * @param[clicked_cb]: Function will be operated when the button is clicked
461  * @param[user_data]: Data passed to the 'clicked_cb' function
462  */
463 void view_set_button(Evas_Object *parent, const char *part_name, const char *style, const char *image_path, const char *text,
464                 Evas_Object_Event_Cb down_cb, Evas_Object_Event_Cb up_cb, Evas_Smart_Cb clicked_cb, void *user_data)
465 {
466         Evas_Object *btn = NULL;
467
468         if (parent == NULL) {
469                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
470                 return;
471         }
472
473         btn = elm_button_add(parent);
474         if (btn == NULL) {
475                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create button.");
476                 return;
477         }
478
479         if (style)
480                 elm_object_style_set(btn, style);
481
482         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
483         elm_object_part_content_set(parent, part_name, btn);
484
485         if (text)
486                 elm_object_text_set(btn, text);
487
488         if (image_path)
489                 view_set_image(btn, NULL, image_path);
490
491         if (down_cb)
492                 evas_object_event_callback_add(btn , EVAS_CALLBACK_MOUSE_DOWN, down_cb, user_data);
493         if (up_cb)
494                 evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_UP, up_cb, user_data);
495         if (clicked_cb)
496                 evas_object_smart_callback_add(btn, "clicked", clicked_cb, user_data);
497
498         evas_object_show(btn);
499 }
500
501 /*
502  * @brief: Add a more button item
503  * @param[parent]: object that contains more button
504  * @param[part_name]: Name of the part has more option
505  * @param[main_txt]: text will be written in the middle of the selector
506  * @param[sub_txt] Text will be written under the main_txt
507  * @param[image_path]: path of image file will be used as more button item icon
508  * @param[clicked_cb]: function will be operated when the more button item is clicked
509  * @param[user_data]: data needed in this function
510  */
511 void view_add_more_button_item(Evas_Object *parent, const char *part_name, const char *main_txt, const char *sub_txt, const char *image_path, Evas_Smart_Cb clicked_cb, void *user_data)
512 {
513         Evas_Object *image = NULL;
514         Evas_Object *more_btn = NULL;
515         char full_path[PATH_MAX] = { 0, };
516
517         if (parent == NULL) {
518                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
519                 return;
520         }
521
522         more_btn = elm_object_part_content_get(parent, part_name);
523         if (more_btn == NULL) {
524                 return;
525         }
526
527         /* Create the new item */
528         Eext_Object_Item *item  = eext_more_option_item_append(more_btn);
529
530         /* Set the text in item text part */
531         eext_more_option_item_part_text_set(item, "selector,main_text", main_txt);
532         eext_more_option_item_part_text_set(item, "selector,sub_text", sub_txt);
533
534         image = elm_image_add(more_btn);
535         _get_resource(image_path, full_path, sizeof(full_path));
536         elm_image_file_set(image, full_path, NULL);
537
538         /* Set the content in item content part */
539         eext_more_option_item_part_content_set(item, "item,icon", image);
540
541         evas_object_smart_callback_add(more_btn, "item,clicked", clicked_cb, user_data);
542 }
543
544 /*
545  * @brief: Make a Entry Object to target window
546  * @param[parent]: Object to which you want to set Entry
547  * @param[part_name]: Part of the layout which you want to locate Entry
548  * @param[clicked_cb]: The function will be called when the entry is clicked
549  * @param[user_data]: The user data passed to the callback function
550  * @Add callback function will be operated when mouse clicked event is triggered
551  */
552 Evas_Object *view_create_entry(Evas_Object *parent, const char *part_name, Evas_Smart_Cb clicked_cb, void *user_data)
553 {
554         Evas_Object *entry = NULL;
555
556         if (parent == NULL) {
557                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
558                 return NULL;
559         }
560
561         /* Add Entry object to parent */
562         entry = elm_entry_add(parent);
563         if (entry == NULL) {
564                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to add a entry");
565                 return NULL;
566         }
567
568         /* Set Entry size option */
569         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
570
571         /* Set Entry option for display and functionalities */
572         elm_entry_single_line_set(entry, EINA_TRUE);
573         elm_entry_scrollable_set(entry, EINA_TRUE);
574         elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
575         elm_entry_editable_set(entry, EINA_FALSE);
576         elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
577         elm_entry_cursor_handler_disabled_set(entry, EINA_TRUE);
578         elm_entry_select_allow_set(entry, EINA_FALSE);
579
580         /* Set Entry text style using predefined style description */
581         elm_entry_text_style_user_push(entry, DIAL_TEXT_STYLE_NORMAL);
582
583         elm_object_part_content_set(parent, part_name, entry);
584
585         /* Set callback for event about Entry */
586         if (clicked_cb) {
587                 evas_object_smart_callback_add(entry, "clicked", clicked_cb, user_data);
588         }
589
590         return entry;
591 }
592
593 /*
594  * @brief: make genlist for circular shape
595  * @param[parent]: object to which you want to set genlist
596  */
597 Evas_Object *view_create_circle_genlist(Evas_Object *parent)
598 {
599         Evas_Object *genlist = NULL;
600         Evas_Object *circle_genlist = NULL;
601
602         if (parent == NULL) {
603                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
604                 return NULL;
605         }
606
607         if (s_info.circle_surface == NULL) {
608                 dlog_print(DLOG_ERROR, LOG_TAG, "circle surface is NULL.");
609                 return NULL;
610         }
611
612         genlist = elm_genlist_add(parent);
613         /*
614          * This make selected list item is shown compressed.
615          */
616         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
617         evas_object_smart_callback_add(genlist, "selected", _gl_selected_cb, NULL);
618
619         /*
620          * This make genlist style circular.
621          */
622         circle_genlist = eext_circle_object_genlist_add(genlist, s_info.circle_surface);
623         eext_circle_object_genlist_scroller_policy_set(circle_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
624         eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
625
626         evas_object_show(genlist);
627
628         return genlist;
629 }
630
631 /*
632  * @brief: Add item to genlist.
633  * @param[genlist]: Genlist shows several items
634  * @param[style]: Style of item determine how to show this item, such as "1text", "1text1icon" and so on
635  * @param[gen_data]: Item data that use item's callback function
636  * @param[clicked_cb]: function will be operated when the item is clicked
637  * @param[user_data]: Data passed to 'clicked_cb' function
638  * This make item's class and add item to genlist.
639  */
640 Elm_Object_Item *view_append_item_to_genlist(Evas_Object *genlist, const char *style,
641                 const void *gen_data, Evas_Smart_Cb clicked_cb, const void *user_data)
642 {
643         Elm_Genlist_Item_Class *item_class;
644         Elm_Object_Item *item;
645
646         if (genlist == NULL) {
647                 dlog_print(DLOG_ERROR, LOG_TAG, "genlist is NULL.");
648                 return NULL;
649         }
650
651         if (style == NULL) {
652                 dlog_print(DLOG_ERROR, LOG_TAG, "item style is NULL.");
653                 return NULL;
654         }
655
656         item_class = _set_genlist_item_class(style);
657
658         item = elm_genlist_item_append(genlist, item_class, gen_data, NULL, ELM_GENLIST_ITEM_NONE, clicked_cb, user_data);
659
660         elm_genlist_item_class_free(item_class);
661
662         return item;
663 }
664
665 /*
666  * @brief: Find item from genlist.
667  * @param[genlist]: Genlist shows several items
668  * @param[val]: value determine which of the items has to remove
669  */
670 Elm_Object_Item *view_find_item_from_genlist(Evas_Object *genlist, const char *val)
671 {
672         int item_count;
673         int i;
674         Elm_Object_Item *item = NULL;
675         struct genlist_data *gendata = NULL;
676
677         if (genlist == NULL) {
678                 dlog_print(DLOG_ERROR, LOG_TAG, "genlist is NULL.");
679                 return NULL;
680         }
681
682         item_count = elm_genlist_items_count(genlist);
683
684         /*
685          * The fist item and the last item are "padding".
686          */
687         for (i = 1; i < item_count-1; i++) {
688                 item = elm_genlist_nth_item_get(genlist, i);
689                 gendata = elm_object_item_data_get(item);
690
691                 if (gendata->alarm_id == atoi(val)) {
692                         return item;
693                 }
694         }
695
696         return NULL;
697 }
698
699 /*
700  * @brief: Remove item.
701  * @param[item]: item from genlist
702  */
703 void view_delete_item(Elm_Object_Item *item)
704 {
705         elm_object_item_del(item);
706 }
707
708 /*
709  * @brief: Make popup with theme.
710  * @param[timeout]: Duration that popup is showing
711  * @param[text]: Text displayed on the popup
712  */
713 void view_create_text_popup(Evas_Object *parent, double timeout, const char *text)
714 {
715         Evas_Object *popup = NULL;
716         Evas_Object *popup_layout = NULL;
717
718         if (parent == NULL) {
719                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
720                 return;
721         }
722
723         popup = elm_popup_add(parent);
724         elm_object_style_set(popup, "circle");
725         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
726
727         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_hide_cb, NULL);
728         /*
729          * Delete popup object in _popup_hide_finished_cb(), when the "dismissed" signal will be called.
730          */
731         evas_object_smart_callback_add(popup, "dismissed", _popup_hide_finished_cb, NULL);
732
733         popup_layout = elm_layout_add(popup);
734         elm_layout_theme_set(popup_layout, "layout", "popup", "content/circle");
735
736         elm_object_content_set(popup, popup_layout);
737
738         elm_popup_timeout_set(popup, timeout);
739
740         if (text)
741                 view_set_text(popup_layout, "elm.text", text);
742
743         evas_object_show(popup);
744 }
745
746 /*
747  * @brief: Set the content to the given part
748  * @param[part_name]: Name of the part to which you want to set
749  * @param[content]: The object will be set to the given part
750  */
751 void view_set_content_to_part(Evas_Object *layout, const char *part_name, Evas_Object *content)
752 {
753         elm_object_part_content_set(layout, part_name, content);
754 }
755
756 /*
757  * @brief: Send signal with source to the EDJ object
758  * @param[layout]: The layout object will receive the signal
759  * @param[signal]: The appointed signal to trigger the function
760  * @param[source]: The appointed source that normally indicate the object triggered the event
761  */
762 void view_send_signal_to_edje(Evas_Object *layout, const char *signal, const char *source)
763 {
764         elm_object_signal_emit(layout, signal, source);
765 }
766
767 /*
768  * @brief: Set the function will be called when the appointed signal is occurred
769  * @param[item]: The object triggered the signal
770  * @param[signal]: The appointed signal to trigger the function
771  * @param[source]: The appointed source that normally indicate the object triggered the event
772  * @param[signal_cb]: The function will be called when the signal is detected
773  * @param[user_data]: The data passed to the 'signal_cb' function
774  */
775 void view_set_customized_event_callback(Evas_Object *item, char *signal, char *source, Edje_Signal_Cb signal_cb, void *user_data)
776 {
777         elm_object_signal_callback_add(item, signal, source, signal_cb, user_data);
778 }
779
780 /*
781  * @brief: Register rotary event callback function.
782  * @param[obj]: object that will receive rotary event
783  * @param[rotary_cb]: function will be operated when rotary event happens
784  * @param[user_data]: Data passed to the 'rotary_cb' function
785  */
786 void view_set_rotary_event_callback(Evas_Object *obj, Eext_Rotary_Event_Cb rotary_cb, void *user_data)
787 {
788         if (obj == NULL) {
789                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
790                 return;
791         }
792
793         eext_rotary_object_event_activated_set(obj, EINA_TRUE);
794         eext_rotary_object_event_callback_add(obj, rotary_cb, user_data);
795 }
796
797 /*
798  * @brief: Make a label and set label options.
799  * @param[parent]: The object to which you want to add this label
800  */
801 Evas_Object *view_create_label(Evas_Object *parent)
802 {
803         Evas_Object *label = elm_label_add(parent);
804
805         if (parent == NULL) {
806                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
807                 return NULL;
808         }
809
810         elm_object_style_set(label, "slide_short");
811         elm_label_wrap_width_set(label, 230);
812         elm_label_ellipsis_set(label, EINA_TRUE);
813         elm_label_slide_duration_set(label, 2);
814         elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_NONE);
815         elm_label_slide_go(label);
816         evas_object_show(label);
817
818         return label;
819 }
820
821 /*
822  * @brief: Set a text to label object
823  * @param[parent]: Object has part to which you want to set text
824  * @param[part_name]: Part name to which you want to set text
825  * @param[text]: text you want to set to the part
826  */
827 void view_set_label_text(Evas_Object *parent, const char *part_name, const char *text)
828 {
829         Evas_Object *label = NULL;
830         char *markup_text = NULL;
831         char buf[256] = { 0, };
832
833         if (parent == NULL) {
834                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
835                 return;
836         }
837
838         markup_text = elm_entry_utf8_to_markup(text);
839         snprintf(buf, sizeof(buf), "%s%s%s", LABEL_STYLE_START, markup_text, LABEL_STYLE_END);
840         free(markup_text);
841
842         label = elm_object_part_content_get(parent, part_name);
843         if (label == NULL) {
844                 dlog_print(DLOG_ERROR, LOG_TAG, "label is NULL.");
845                 return;
846         }
847
848         elm_object_text_set(label, buf);
849 }
850
851 /*
852  * @brief: Set a label to given part
853  * @param[parent]: Object has part to which you want to set this label
854  * @param[part_name]: Part name to which you want to set this label
855  */
856 void view_set_label(Evas_Object *parent, const char *part_name)
857 {
858         Evas_Object *label = NULL;
859
860         if (parent == NULL) {
861                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
862                 return;
863         }
864
865         label = view_create_label(parent);
866         if (label == NULL) {
867                 dlog_print(DLOG_ERROR, LOG_TAG, "label is NULL.");
868                 return;
869         }
870
871         elm_object_part_content_set(parent, part_name, label);
872 }
873
874 /*
875  * @brief: Create a progressbar
876  * @param[parent]: Object has part to which you want to set this progressbar
877  * @param[radius]: Radius The radius value of a given circle object
878  * @param[line_width]: Line_width The line width value of the circle object
879  */
880 Evas_Object *view_create_progressbar(Evas_Object *parent, int radius, int line_width)
881 {
882         Evas_Object *progressbar = NULL;
883
884         if (parent == NULL) {
885                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
886                 return NULL;
887         }
888
889         progressbar = eext_circle_object_progressbar_add(parent, NULL);
890
891         eext_circle_object_value_min_max_set(progressbar, 0.0, 100.0);
892         eext_circle_object_radius_set(progressbar, radius);
893         eext_circle_object_line_width_set(progressbar, line_width);
894         evas_object_show(progressbar);
895
896         return progressbar;
897 }
898
899 /*
900  * @brief: Set a progressbar to given part
901  * @param[parent]: Object has part to which you want to set
902  * @param[part_name]: Part name to which you want to set
903  * @param[radius]: Radius The radius value of a given circle object
904  * @param[line_width]: Line_width The line width value of the circle object
905  */
906 void view_set_progressbar(Evas_Object *parent, const char *part_name, int radius, int line_width)
907 {
908         Evas_Object *progressbar = NULL;
909
910         if (parent == NULL) {
911                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
912                 return;
913         }
914
915         progressbar = view_create_progressbar(parent, radius, line_width);
916         if (progressbar == NULL) {
917                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
918                 return;
919         }
920
921         elm_object_part_content_set(parent, part_name, progressbar);
922 }
923
924 /*
925  * @brief: Set value to a progressbar
926  * @param[parent]: Object has part to which you want to set
927  * @param[part_name]: Part name to which you want to set
928  * @param[val]: Value to which you want to set
929  */
930 void view_set_progressbar_val(Evas_Object *parent, const char *part_name, int val)
931 {
932         Evas_Object *progressbar = NULL;
933
934         if (parent == NULL) {
935                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
936                 return;
937         }
938
939         if (part_name == NULL) {
940                 dlog_print(DLOG_ERROR, LOG_TAG, "part is NULL.");
941                 return;
942         }
943
944         progressbar = elm_object_part_content_get(parent, part_name);
945         if (progressbar == NULL) {
946                 dlog_print(DLOG_ERROR, LOG_TAG, "progressbar is NULL.");
947                 return;
948         }
949
950         eext_circle_object_value_set(progressbar, val);
951 }
952
953 /*
954  * @brief: Make a check box
955  * @param[parent]: The object to which you want to add this check box
956  */
957 Evas_Object *view_create_checkbox(Evas_Object *parent)
958 {
959         Evas_Object *check;
960
961         if (parent == NULL) {
962                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
963                 return NULL;
964         }
965
966         check = elm_check_add(parent);
967         elm_check_state_set(check, EINA_FALSE);
968         evas_object_smart_callback_add(check, "changed", _icon_clicked_cb, NULL);
969         evas_object_show(check);
970
971         return check;
972 }
973
974 /*
975  * @brief: Make no content view
976  * @param[parent]: Naviframe has several views
977  * @param[title]: title of this view
978  * @param[detail]: detail text of this view
979  * @param[image_path]: Image file path will be used in this view
980  * This function make a view consists of one title, one center image and one detail text at the bottom
981  */
982 Evas_Object *view_create_layout_no_content(Evas_Object *parent, char *title, char *detail, char *image_path)
983 {
984         Evas_Object *layout = NULL;
985         Evas_Object *image;
986         Elm_Object_Item *it;
987
988         if (parent == NULL) {
989                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
990                 return NULL;
991         }
992
993         layout = elm_layout_add(parent);
994         /* this make you can use layout consists of one title, one image and one detail text */
995         elm_layout_theme_set(layout, "layout", "nocontents", "default");
996         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
997         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
998
999         if (image_path) {
1000                 image = elm_image_add(parent);
1001                 elm_image_file_set(image, image_path, NULL);
1002                 elm_object_part_content_set(layout, "elm.swallow.icon", image);
1003                 evas_object_show(image);
1004         }
1005
1006         if (detail) {
1007                 char detail_text[256] = {0, };
1008
1009                 /* Customize font style bellow */
1010                 snprintf(detail_text, sizeof(detail_text), "<font=TIZEN:style=Medium align=center color=#FFFFFF><font_size=28>%s</font_size></font>", detail);
1011                 elm_object_part_text_set(layout, "elm.text", detail_text);
1012         }
1013         if (title) {
1014                 char title_text[256] = {0, };
1015
1016                 snprintf(title_text, sizeof(title_text), "<font=TIZEN:style=Medium align=center color=#12B4FF><font_size=28>%s</font_size></font>", title);
1017                 elm_object_part_text_set(layout, "elm.text.title", title_text);
1018         }
1019
1020         /* if this signal is not sent, title text will be disappear */
1021         elm_object_signal_emit(layout, "elm,state,title,enable", "elm");
1022         /* push this no voice memo view to naviframe to show */
1023         it = elm_naviframe_item_push(parent, "Title Enabled", NULL, NULL, layout, NULL);
1024         /* if this is EINA_TRUE, you can see Title of naviframe on the top of the screen */
1025         elm_naviframe_item_title_enabled_set(it, EINA_FALSE, EINA_FALSE);
1026
1027         return layout;
1028 }
1029
1030 /*
1031  * @brief: Set datetime to the part
1032  * @param[parent]: object to which you want to set datetime
1033  * @param[style]: style of the datetime
1034  */
1035 Evas_Object *view_create_datetime(Evas_Object *parent, const char *style)
1036 {
1037         Evas_Object *circle_datetime = NULL;
1038
1039         if (parent == NULL) {
1040                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get parent.");
1041                 return NULL;
1042         }
1043
1044         if (s_info.circle_surface == NULL) {
1045                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get circle_surface.");
1046                 return NULL;
1047         }
1048
1049         s_info.datetime = elm_datetime_add(parent);
1050         circle_datetime = eext_circle_object_datetime_add(s_info.datetime, s_info.circle_surface);
1051
1052         eext_rotary_object_event_activated_set(s_info.datetime, EINA_TRUE);
1053         elm_datetime_format_set(s_info.datetime, FORMAT);
1054
1055         elm_object_style_set(s_info.datetime, style);
1056
1057         elm_object_part_content_set(parent, "elm.swallow.content", s_info.datetime);
1058
1059         return s_info.datetime;
1060 }