tizen 2.3 release
[apps/home/b2-clocksetting.git] / src / setting_view_toast.c
1 /*
2  * Copyright (c) 2010 Samsung Electronics, Inc.
3  * All rights reserved.
4  *
5  * This software is a confidential and proprietary information
6  * of Samsung Electronics, Inc. ("Confidential Information").  You
7  * shall not disclose such Confidential Information and shall use
8  * it only in accordance with the terms of the license agreement
9  * you entered into with Samsung Electronics.
10  */
11 #include <string.h>
12
13 #include "setting_view_toast.h"
14 #include "util.h"
15
16 Toast_Data* _create_toast( void * data, char * msg )
17 {
18         Toast_Data * toast = (Toast_Data *) calloc(sizeof(Toast_Data), 1);
19
20         toast->is_show = 0;
21         toast->str = strdup(msg);
22         toast->toast_popup = NULL;
23
24         return toast;
25 }
26
27 void _destroy_toast( Toast_Data* toast )
28 {
29         if( toast ) {
30                 if(toast->str) {
31                         free(toast->str);
32                 }
33                 if(toast->toast_popup) {
34                         evas_object_del(toast->toast_popup);
35                         toast->toast_popup = NULL;
36                 }
37                 free(toast);
38         }
39 }
40
41 void _dismiss_toast(void *data, Evas_Object *obj, void *event_info)
42 {
43          Toast_Data* toast =(Toast_Data*)data;
44         _destroy_toast(toast);
45 }
46
47 void _show_toast( void * data, Toast_Data* toast )
48 {
49         appdata * ad = data;
50         if( ad == NULL || toast == NULL ) {
51                 return;
52         }
53
54         if( toast->is_show ) {
55                 return;
56         }
57
58         toast->toast_popup = elm_popup_add(ad->nf);
59         elm_object_style_set(toast->toast_popup, "toast");
60         elm_popup_orient_set(toast->toast_popup, ELM_POPUP_ORIENT_BOTTOM);
61         evas_object_size_hint_weight_set(toast->toast_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
62         ea_object_event_callback_add(toast->toast_popup, EA_CALLBACK_BACK, ea_popup_back_cb, NULL);
63         elm_object_part_text_set(toast->toast_popup,"elm.text", toast->str);
64         elm_popup_timeout_set(toast->toast_popup, 2.0);
65
66         evas_object_smart_callback_add(toast->toast_popup, "block,clicked", _dismiss_toast, toast);
67         evas_object_smart_callback_add(toast->toast_popup, "timeout", _dismiss_toast, toast);
68
69         evas_object_show(toast->toast_popup);
70 }