Initialize Tizen 2.3
[apps/home/b2-clocksetting.git] / src / setting_view_toast.c
1 /*
2  * Copyright (c) 2000 - 2013 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 #include <string.h>
18
19 #include "setting_view_toast.h"
20 #include "util.h"
21
22 Toast_Data* _create_toast( void * data, char * msg )
23 {
24         Toast_Data * toast = (Toast_Data *) calloc(sizeof(Toast_Data), 1);
25
26         toast->is_show = 0;
27         toast->str = strdup(msg);
28         toast->toast_popup = NULL;
29
30         return toast;
31 }
32
33 void _destroy_toast( Toast_Data* toast )
34 {
35         if( toast ) {
36                 if(toast->str) {
37                         free(toast->str);
38                 }
39                 if(toast->toast_popup) {
40                         evas_object_del(toast->toast_popup);
41                         toast->toast_popup = NULL;
42                 }
43                 free(toast);
44         }
45 }
46
47 void _dismiss_toast(void *data, Evas_Object *obj, void *event_info)
48 {
49          Toast_Data* toast =(Toast_Data*)data;
50         _destroy_toast(toast);
51 }
52
53 void _show_toast( void * data, Toast_Data* toast )
54 {
55         appdata * ad = data;
56         if( ad == NULL || toast == NULL ) {
57                 return;
58         }
59
60         if( toast->is_show ) {
61                 return;
62         }
63
64         toast->toast_popup = elm_popup_add(ad->nf);
65         elm_object_style_set(toast->toast_popup, "toast");
66         elm_popup_orient_set(toast->toast_popup, ELM_POPUP_ORIENT_BOTTOM);
67         evas_object_size_hint_weight_set(toast->toast_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
68         ea_object_event_callback_add(toast->toast_popup, EA_CALLBACK_BACK, ea_popup_back_cb, NULL);
69         elm_object_part_text_set(toast->toast_popup,"elm.text", toast->str);
70         elm_popup_timeout_set(toast->toast_popup, 2.0);
71
72         evas_object_smart_callback_add(toast->toast_popup, "block,clicked", _dismiss_toast, toast);
73         evas_object_smart_callback_add(toast->toast_popup, "timeout", _dismiss_toast, toast);
74
75         evas_object_show(toast->toast_popup);
76 }