[Request]Update Flora license version
[apps/home/clock.git] / worldclock / src / worldclock_lib.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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
18 #include <stdio.h>
19 #include <appcore-efl.h>
20 #include <Elementary.h>
21 #include <Ecore_X.h>
22
23 #include <vconf.h>
24 #include <bundle.h>
25
26 #include "worldclock_lib.h"
27
28 #include "worldclock.h"
29 #include "worldclock_data.h"
30 #include "worldclock_noti.h"
31 #include "worldclock_dlog.h"
32 #include "worldclock_main_view.h"
33 #include "worldclock_add_view.h"
34 #include "worldclock_edit_view.h"
35 static struct appdata *g_ad;
36
37 /**
38  * Create navigationbar for lib
39  *
40  * @param[in]  parent   parent for new navigationbar
41  *
42  * @return     NULL if meet error
43  *             Pointer to new navigationbar
44  */
45 static Evas_Object *__worldclock_navibar_add(Evas_Object *parent)
46 {
47         CLK_FUN_BEG();
48         Evas_Object *navi_bar;
49
50         retv_if(NULL == parent, NULL);
51
52         // add navigationbar
53         navi_bar = elm_naviframe_add(parent);
54         //elm_object_part_content_set( parent, "elm.swallow.content", navi_bar );
55         edje_object_part_swallow(_EDJ(parent), "elm.swallow.content", navi_bar);
56         // show navigationbar
57         evas_object_show(navi_bar);
58
59         CLK_FUN_END();
60         return navi_bar;
61 }
62
63 /**
64  * Create new view of lib
65  *
66  * @param[in]  parent   Parent of new view
67  * @param[in]  cb       Callback function register by caller to show & hide controlbar
68  * @param[in]  icap     Callback function register by caller for idle capture
69  *
70  * @return     NULL if meet error
71  *             Pointer to new view
72  */
73 EAPI Evas_Object *worldclock_view_add(Evas_Object * parent, Evas_Object * win,
74                                       Wcl_Ctrlbar_Visible_Set cb,
75                                       Wcl_Idle_Capture icap)
76 {
77         CLK_FUN_BEG();
78         retv_if(parent == NULL, NULL);
79
80         if (!g_ad) {
81                 // init data
82                 struct appdata *ad =
83                     (struct appdata *)calloc(1, sizeof(struct appdata));
84                 retv_if(!ad, NULL);
85                 g_ad = ad;
86                 // set parent
87                 ad->win = win;
88
89             ad->layout_main = load_edj(parent, WCL_EDJ_NAME, GRP_LIB);
90             elm_object_part_content_set(parent, "elm.swallow.content",
91                 ad->layout_main);
92
93                 /* language set */
94                 bindtextdomain(PACKAGE, LOCALEDIR);
95
96                 /* region setting */
97                 worldclock_noti_reg_vconf_changed(ad);
98
99                 /* navigation bar */
100                 ad->navi_bar = __worldclock_navibar_add(ad->layout_main);
101                 retv_if(ad->navi_bar == NULL, NULL);
102
103                 /* init db */
104                 if (EINA_FALSE == worldclock_data_open_database()) {
105                         CLK_ERR
106                             ("\nworldclock db not work well, please check it !!!!!!!!!!!!!!!!!!\n");
107                         return NULL;
108                 }
109
110                 // set caller flag
111                 ad->caller = WCL_CALLER_IS_SHARED_LIBRARY;
112                 // set selection flag
113                 ad->selectionFlag = WCL_SELECT_IN_ALL;  //the selection flag
114                 ad->controlbar_cb = cb;
115                 // display main view
116                 worldclock_mainview_add(ad->navi_bar, ad, NULL);
117                 // set callback function for show & hide controlbar
118                 // set callback function for idle capture
119                 ad->idle_capture_cb = icap;
120         }
121
122         CLK_FUN_END();
123         return g_ad->layout_main;
124 }
125
126 /**
127  * Free view of worldclock lib
128  *
129  * @param[in]  obj    Pointer for view of worldclock lib
130  *
131  * @return     SUCCESS exit worldclock
132  *             FAILED not exit
133  */
134 EAPI int worldclock_view_free(Evas_Object * obj)
135 {
136         CLK_FUN_BEG();
137
138         if (g_ad && (g_ad->layout_main == obj)) {
139                 if (g_ad->add_ly) {
140                         // free add view
141                         worldclock_addview_free(g_ad);
142                 }
143                 if (g_ad->edit_ly) {
144                         // free edit view
145                         worldclock_editview_free(g_ad);
146                 }
147                 if (g_ad->main_ly) {
148                         // free main view
149                         worldclock_mainview_free(g_ad);
150                         // free navigationbar
151                         EVAS_OBJECT_DELIF(g_ad->navi_bar);
152                 }
153                 // close database
154                 worldclock_data_close_database();
155
156                 // free data
157                 if (g_ad) {
158                         free(g_ad);
159                         g_ad = NULL;
160                 }
161
162                 return SUCCESS;
163         }
164
165         CLK_FUN_END();
166         return FAILED;
167 }
168
169 /**
170  * reload view of worldclock lib
171  *
172  * @return
173  */
174 EAPI void worldclock_view_reload()
175 {
176         ret_if(!g_ad);
177         CLK_FUN_BEG();
178         struct appdata *ad = g_ad;
179         if(ad->edit_selectioninfo) {
180                 evas_object_show(ad->edit_selectioninfo);
181         }
182         if (IS_EQUAL(ad->page, WCL_PAGE_ADD)) {
183                 ad->controlbar_cb(EINA_FALSE);
184         } else {
185                 ad->controlbar_cb(EINA_TRUE);
186         }
187         worldclock_mainview_update(ad);
188         worldclock_editview_update(ad);
189
190
191         CLK_FUN_END();
192 }
193
194
195 /**
196  * unload view of worldclock lib
197  *
198  * @return
199  */
200 EAPI void worldclock_view_unload()
201 {
202         ret_if(!g_ad);
203         CLK_FUN_BEG();
204         struct appdata *ad = g_ad;
205         if(ad->edit_selectioninfo) {
206                 evas_object_hide(ad->edit_selectioninfo);
207         }
208         worldclock_ctxpopup_delete();
209         CLK_FUN_END();
210 }