930a1061958b6812da8c5f14f2f4fd61f4ff681c
[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://floralicense.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                 evas_object_show(base);
45                 break;
46         }
47 }
48
49 static void __cal_ug_result_callback(ui_gadget_h ug, service_h res, void *priv)
50 {
51         c_retm_if(!ug, "ug is null");
52 }
53
54 ui_gadget_h cal_launch_ug(ui_gadget_h parent_ug, service_h bd, char *ug_name, struct ug_cbs *cbs)
55 {
56         CAL_FN_START;
57
58         c_retvm_if(!bd, NULL, "bd is null");
59         c_retvm_if(!ug_name, NULL, "ug_name is null");
60
61         ui_gadget_h ug;
62         struct ug_cbs uc;
63
64         if (NULL == cbs) {
65                 uc.destroy_cb = __cal_ug_destroy_callback;
66                 uc.layout_cb = __cal_ug_layout_callback;
67                 uc.result_cb = __cal_ug_result_callback;
68                 uc.priv = NULL;
69         } else {
70                 if (NULL == cbs->destroy_cb)
71                         uc.destroy_cb = __cal_ug_destroy_callback;
72                 else
73                         uc.destroy_cb = cbs->destroy_cb;
74
75                 if (NULL == cbs->layout_cb)
76                         uc.layout_cb = __cal_ug_layout_callback;
77                 else
78                         uc.layout_cb = cbs->layout_cb;
79
80                 if (NULL == cbs->result_cb)
81                         uc.result_cb = __cal_ug_result_callback;
82                 else
83                         uc.result_cb = cbs->result_cb;
84
85                 if (NULL == cbs->priv)
86                         uc.priv = NULL;
87                 else
88                         uc.priv = cbs->priv;
89         }
90
91         ug = ug_create(parent_ug, ug_name, UG_MODE_FULLVIEW, bd, &uc);
92         if (!ug)
93                 ERR("ug create error");
94
95         return ug;
96 }
97
98 ui_gadget_h cal_launch_ug_with_var(ui_gadget_h parent_ug, char *ug_name, struct ug_cbs *cbs,...)
99 {
100         CAL_FN_START;
101
102         c_retv_if(!ug_name, NULL);
103
104         char *key = NULL;
105         char *val = NULL;
106         service_h service;
107         int r = service_create(&service);
108         c_retv_if(r != SERVICE_ERROR_NONE, NULL);
109
110         va_list ap;
111         va_start(ap, cbs);
112         while (1) {
113                 key = va_arg(ap, char *);
114                 val = va_arg(ap, char *);
115
116                 if (!key || !val) {
117                         break;
118                 }
119
120                 service_add_extra_data(service, key, val);
121                 service_set_uri(service, val);
122         }
123
124         va_end(ap);
125
126         /* Temporary code for email UG */
127         if (!CAL_STRCMP(ug_name, CAL_EMAIL_COMPOSER_UG)) {
128
129                 if(!cbs){
130                         ERR("cbs is NULL!");
131                         service_destroy(service);
132                         return NULL;
133                 }
134
135                 struct appdata *ad = (struct appdata*)cbs;
136                 if(!ad->win)
137                 {
138                         ERR("ad->win is null");
139                         service_destroy(service);
140                         return NULL;
141                 }
142
143                 service_set_operation(service, SERVICE_OPERATION_SEND);
144
145                 service_set_app_id(service, CAL_EMAIL_COMPOSER_UG);
146
147                 Ecore_X_Window win_id = elm_win_xwindow_get(ad->win);
148
149                 service_set_window(service, win_id);
150
151                 service_send_launch_request(service, NULL, NULL);
152
153                 service_destroy(service);
154
155                 return NULL;
156         } else {
157
158         ui_gadget_h ug = cal_launch_ug(parent_ug, service, ug_name, cbs);
159
160         service_destroy(service);
161
162         return ug;
163         }
164 }