upload codes for TIZEN 2.0
[apps/home/clock.git] / worldclock / src / worldclock_ug_add_view.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 <stdio.h>
20 #include <appcore-efl.h>
21 #include <Elementary.h>
22 #include <Ecore_X.h>
23 #include <vconf.h>
24 #include <unicode/utf8.h>
25 #include <unicode/ustring.h>
26 #include <unicode/ucol.h>
27
28
29 #include "worldclock.h"
30 #include "worldclock_dlog.h"
31 #include "worldclock_util.h"
32 #include "worldclock_data.h"
33 #include "worldclock_fwk_icu.h"
34 #include "worldclock_ug_add_view.h"
35
36 static Wcl_Return_Cb g_return_cb = NULL;
37
38 static void __ug_addview_launch_ug_destroy_cb(ui_gadget_h ug,
39                                                         void *priv)
40 {
41         CLK_FUN_BEG();
42         /* if(ug) ug_destroy(ug); */
43         /* restore the '<-' button on the navigate bar */
44         ret_if(!priv);
45         struct appdata *ad = (struct appdata *) priv;
46         if (ug) {
47                 ug_destroy(ug);
48                 ad->ug = NULL;
49         }
50
51         CLK_FUN_END();
52 }
53
54 static void __ug_addview_launch_ug_result_cb(ui_gadget_h ug,
55                                                  service_h result, void *priv)
56 {
57         CLK_FUN_BEG();
58         /* error check */
59         retm_if(priv == NULL, "Data parameter is NULL");
60
61         char *city;
62         service_get_extra_data(result, "city", &city);
63
64         if (city) {
65                 // create new structure to store new city
66                 Wcl_CitySet *cs = calloc(1, sizeof(Wcl_CitySet));
67                 retm_if(cs == NULL, "city set data calloc failed");
68                 // copy city name
69                 snprintf(cs->city, CITY_BUF_SIZE, "%s", city);
70
71                 // Synchronize data
72                 worldclock_data_get_city_status_from_db(cs);
73
74                 if (g_return_cb) {
75                         g_return_cb(cs, EINA_TRUE);
76                 }
77         }
78         FREEIF(city);
79         CLK_FUN_END();
80 }
81
82 static void __ug_addview_launch_ug_layout_cb(ui_gadget_h ug,
83                                                         enum ug_mode mode,
84                                                         void *priv)
85 {
86         CLK_FUN_BEG();
87         struct appdata *ad = (struct appdata *) priv;
88         Evas_Object *base;
89
90         ret_if (!ug || !priv);
91
92         base = (Evas_Object *) ug_get_layout(ug);
93         ret_if (!base);
94
95         switch (mode) {
96                 case UG_MODE_FULLVIEW:
97                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
98                                                         EVAS_HINT_EXPAND);
99                         elm_win_resize_object_add(ad->win, base);
100                         evas_object_show(base);
101                         break;
102                 default:
103                         break;
104         }
105         CLK_FUN_END();
106 }
107
108 /**
109  * Create map view for append new city into the selection list of worldclock
110  *
111  * @param[in]  parent   Evas_Object which is the parent of map view
112  * @param[in]  data      data which used in this function
113  * @param[in]  func      Callback function which used for invoking when exit from map view
114  *
115  * @return      FAILED if create map view failed.
116  *                      SUCCESS if create map view successfully.
117  */
118 int worldclock_ug_addview_add(Evas_Object *parent, void *data, Wcl_Return_Cb func)
119 {
120         CLK_FUN_BEG();
121         retv_if(!data, FAILED);
122         retvm_if(data == NULL, FAILED, "Data parameter is NULL");
123         struct appdata *ad = (struct appdata *)data;
124         service_h service = NULL;
125
126         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
127         retvm_if(!cbs, FAILED, "ug callbacks calloc failed");
128         cbs->layout_cb  = __ug_addview_launch_ug_layout_cb;
129         cbs->result_cb  = __ug_addview_launch_ug_result_cb;
130         cbs->destroy_cb = __ug_addview_launch_ug_destroy_cb;
131         cbs->priv = (void *)ad;
132
133         if (WCL_PAGE_MAIN == ad->page) {
134                 service_create(&service);
135                 service_add_extra_data(service, "caller", "clock");
136         }
137
138         CLK_INFO("to load ug[%s]", "worldclock-efl");
139         ad->ug = ug_create(NULL, "worldclock-efl", UG_MODE_FULLVIEW, service, cbs);
140         if (NULL == ad->ug) {
141                 /* error handling */
142                 CLK_ERR("failed to load ug[%s]", "worldclock-efl");
143                 return FAILED;
144         }
145
146         g_return_cb = func;
147
148         free(cbs);
149         service_destroy(service);
150         return SUCCESS;
151 }
152
153 /**
154  * Release all resources which used in map view when exit from map view
155  *
156  * @param[in]  data   data which used in this function
157  *
158  * @return
159  */
160 void worldclock_ug_addview_free(void *data)
161 {
162         CLK_FUN_BEG();
163         ret_if(!data);
164         struct appdata *ad = (struct appdata *)data;
165
166         if(ad->ug) {
167                 ug_destroy(ad->ug);
168                 ad->ug = NULL;
169         }
170
171         CLK_FUN_END();
172 }
173