tizen 2.3.1 release
[apps/home/b2-clocksetting.git] / src / setting_view_toast.c
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  *  Licensed under the Flora License, Version 1.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://floralicense.org/license/
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         if (toast) {
26                 toast->is_show = 0;
27                 toast->str = strdup(msg);
28                 toast->toast_popup = NULL;
29         }
30
31         return toast;
32 }
33
34 void _destroy_toast(Toast_Data *toast)
35 {
36         if (toast) {
37                 if (toast->str) {
38                         free(toast->str);
39                 }
40                 if (toast->toast_popup) {
41                         evas_object_del(toast->toast_popup);
42                         toast->toast_popup = NULL;
43                 }
44                 free(toast);
45         }
46 }
47
48 void _dismiss_toast(void *data, Evas_Object *obj, void *event_info)
49 {
50         Toast_Data *toast = (Toast_Data *)data;
51         _destroy_toast(toast);
52 }
53
54 void _show_toast(void *data, Toast_Data *toast)
55 {
56         appdata *ad = data;
57         if (ad == NULL || toast == NULL) {
58                 return;
59         }
60
61         if (toast->is_show) {
62                 return;
63         }
64
65         toast->toast_popup = elm_popup_add(ad->nf);
66 #ifdef _CIRCLE
67         elm_object_style_set(toast->toast_popup, "toast/circle");
68 #else
69         elm_object_style_set(toast->toast_popup, "toast");
70 #endif
71         elm_popup_orient_set(toast->toast_popup, ELM_POPUP_ORIENT_BOTTOM);
72         evas_object_size_hint_weight_set(toast->toast_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
73         ea_object_event_callback_add(toast->toast_popup, EA_CALLBACK_BACK, ea_popup_back_cb, NULL);
74         elm_object_part_text_set(toast->toast_popup, "elm.text", toast->str);
75         elm_popup_timeout_set(toast->toast_popup, 2.0);
76
77         evas_object_smart_callback_add(toast->toast_popup, "block,clicked", _dismiss_toast, toast);
78         evas_object_smart_callback_add(toast->toast_popup, "timeout", _dismiss_toast, toast);
79
80         evas_object_show(toast->toast_popup);
81 }