apply FSL license
[apps/core/preloaded/calendar.git] / common / external-ug.c
1 /*
2   *
3   *  Copyright 2012  Samsung Electronics Co., Ltd
4   *
5   *  Licensed under the Flora License, Version 1.0 (the "License");
6   *  you may not use this file except in compliance with the License.
7   *  You may obtain a copy of the License at
8   *
9   *       http://www.tizenopensource.org/license
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17
18
19
20
21
22
23
24 #include "cld.h"
25 #include "external-ug.h"
26
27 static void __cal_ug_destroy_callback(struct ui_gadget *ug, void *priv)
28 {
29         c_retm_if(!ug, "ug is null");
30
31         ug_destroy(ug);
32 }
33
34 static void __cal_ug_layout_callback(struct ui_gadget *ug, enum ug_mode mode, void *priv)
35 {
36         c_retm_if(!ug, "ug is null");
37         c_retm_if(mode != UG_MODE_FULLVIEW, "mode is invaild");
38
39         Evas_Object *base = ug_get_layout(ug);
40         if (!base) {
41                 ERR("ug_get_layout() returned null");
42                 ug_destroy(ug);
43                 return;
44         }
45
46         switch (mode) {
47         case UG_MODE_FULLVIEW:
48                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
49                 elm_win_resize_object_add(ug_get_window(), base);
50                 evas_object_show(base);
51                 break;
52         default:
53                 break;
54         }
55 }
56
57 static void __cal_ug_result_callback(struct ui_gadget *ug, bundle *res, void *priv)
58 {
59         c_retm_if(!ug, "ug is null");
60 }
61
62 void cal_launch_ug(bundle *bd, char *ug_name, struct ug_cbs *cbs)
63 {
64         CAL_FN_START;
65
66         c_retm_if(!bd, "bd is null");
67         c_retm_if(!ug_name, "ug_name is null");
68
69         struct ui_gadget *ug;
70         struct ug_cbs uc;
71
72         if (NULL == cbs) {
73                 uc.destroy_cb = __cal_ug_destroy_callback;
74                 uc.layout_cb = __cal_ug_layout_callback;
75                 uc.result_cb = __cal_ug_result_callback;
76                 uc.priv = NULL;
77         } else {
78                 if (NULL == cbs->destroy_cb)
79                         uc.destroy_cb = __cal_ug_destroy_callback;
80                 else
81                         uc.destroy_cb = cbs->destroy_cb;
82
83                 if (NULL == cbs->layout_cb)
84                         uc.layout_cb = __cal_ug_layout_callback;
85                 else
86                         uc.layout_cb = cbs->layout_cb;
87
88                 if (NULL == cbs->result_cb)
89                         uc.result_cb = __cal_ug_result_callback;
90                 else
91                         uc.result_cb = cbs->result_cb;
92
93                 if (NULL == cbs->priv)
94                         uc.priv = NULL;
95                 else
96                         uc.priv = cbs->priv;
97         }
98
99         ug = ug_create(NULL, ug_name, UG_MODE_FULLVIEW, bd, &uc);
100         if (!ug)
101                 ERR("ug create error");
102 }
103
104 void cal_launch_ug_with_var(char *ug_name, struct ug_cbs *cbs,...)
105 {
106         CAL_FN_START;
107
108         c_retm_if(!ug_name, "ug_name is null");
109
110         char *key = NULL;
111         char *val = NULL;
112         bundle *bd = bundle_create();
113         c_retm_if(!bd, "bd is null");
114
115         va_list ap;
116         va_start(ap, cbs);
117         while (CAL_TRUE) {
118                 key = va_arg(ap, char *);
119                 val = va_arg(ap, char *);
120
121                 if (!key || !val) {
122                         break;
123                 }
124
125
126                 bundle_add(bd, key, val);
127         }
128
129         va_end(ap);
130
131         cal_launch_ug(bd, ug_name, cbs);
132
133         bundle_free(bd);
134 }
135
136