2.0 alpha
[apps/home/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 #include "cld.h"
20 #include "external-ug.h"
21
22 static void __cal_ug_destroy_callback(ui_gadget_h ug, void *priv)
23 {
24         c_retm_if(!ug, "ug is null");
25
26         ug_destroy(ug);
27 }
28
29 static void __cal_ug_layout_callback(ui_gadget_h ug, enum ug_mode mode, void *priv)
30 {
31         c_retm_if(!ug, "ug is null");
32         c_retm_if(mode != UG_MODE_FULLVIEW, "mode is invaild");
33
34         Evas_Object *base = ug_get_layout(ug);
35         if (!base) {
36                 ERR("ug_get_layout() returned null");
37                 ug_destroy(ug);
38                 return;
39         }
40
41         switch (mode) {
42         case UG_MODE_FULLVIEW:
43                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
44                 elm_win_resize_object_add(ug_get_window(), base);
45                 evas_object_show(base);
46                 break;
47         default:
48                 break;
49         }
50 }
51
52 static void __cal_ug_result_callback(ui_gadget_h ug, service_h res, void *priv)
53 {
54         c_retm_if(!ug, "ug is null");
55 }
56
57 void cal_launch_ug(service_h bd, char *ug_name, struct ug_cbs *cbs)
58 {
59         CAL_FN_START;
60
61         c_retm_if(!bd, "bd is null");
62         c_retm_if(!ug_name, "ug_name is null");
63
64         ui_gadget_h ug;
65         struct ug_cbs uc;
66
67         if (NULL == cbs) {
68                 uc.destroy_cb = __cal_ug_destroy_callback;
69                 uc.layout_cb = __cal_ug_layout_callback;
70                 uc.result_cb = __cal_ug_result_callback;
71                 uc.priv = NULL;
72         } else {
73                 if (NULL == cbs->destroy_cb)
74                         uc.destroy_cb = __cal_ug_destroy_callback;
75                 else
76                         uc.destroy_cb = cbs->destroy_cb;
77
78                 if (NULL == cbs->layout_cb)
79                         uc.layout_cb = __cal_ug_layout_callback;
80                 else
81                         uc.layout_cb = cbs->layout_cb;
82
83                 if (NULL == cbs->result_cb)
84                         uc.result_cb = __cal_ug_result_callback;
85                 else
86                         uc.result_cb = cbs->result_cb;
87
88                 if (NULL == cbs->priv)
89                         uc.priv = NULL;
90                 else
91                         uc.priv = cbs->priv;
92         }
93
94         ug = ug_create(NULL, ug_name, UG_MODE_FULLVIEW, bd, &uc);
95         if (!ug)
96                 ERR("ug create error");
97 }
98
99 void cal_launch_ug_with_var(char *ug_name, struct ug_cbs *cbs,...)
100 {
101         CAL_FN_START;
102
103         c_retm_if(!ug_name, "ug_name is null");
104
105         char *key = NULL;
106         char *val = NULL;
107         service_h bd;
108         int r = service_create(&bd);
109         c_ret_if(r != SERVICE_ERROR_NONE);
110
111         va_list ap;
112         va_start(ap, cbs);
113         while (CAL_TRUE) {
114                 key = va_arg(ap, char *);
115                 val = va_arg(ap, char *);
116
117                 if (!key || !val) {
118                         break;
119                 }
120
121                 service_add_extra_data(bd, key, val);
122         }
123
124         va_end(ap);
125
126         cal_launch_ug(bd, ug_name, cbs);
127
128         service_destroy(bd);
129 }
130
131