Cutting new release
[profile/ivi/clock.git] / timer / src / timer_lib.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (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 #define __TMR_LIB_C__
18
19 #include <feedback.h>
20 #include "timer.h"
21 #include "timer_lib.h"
22 #include "timer_utils.h"
23 /**********************************************************************
24 ******************Global val , static global val*************************************
25 ***********************************************************************/
26 static struct appdata *g_ad;
27
28 /**
29  * Create navigationbar for lib
30  *
31  * @param[in]  parent   parent for new navigationbar
32  *
33  * @return     NULL if meet error
34  *             Pointer to new navigationbar
35  */
36 static Evas_Object *__timer_create_navigation_layout(Evas_Object * parent)
37 {
38         CLK_FUN_BEG();
39         Evas_Object *navi_bar;
40
41         retv_if(NULL == parent, NULL);
42
43         // add navigationbar
44         navi_bar = elm_naviframe_add(parent);
45
46         // show navigationbar
47         evas_object_show(navi_bar);
48
49         CLK_FUN_END();
50         return navi_bar;
51 }
52
53 static void timer_view_back_btn_cb(void *data, Evas_Object * obj,
54                                    void *event_info)
55 {
56         ret_if(!data);
57         Evas_Object *win = (Evas_Object *) data;
58         elm_win_lower(win);
59 }
60
61 /**********************************************************************
62 ******************Global function ref*************************************
63 ***********************************************************************/
64
65 /**
66  * Debug function: to create and show view of timer.
67  * It will be called by Clock application and the standalone timer application.
68  * This function requires parent and cb as parameters
69  *
70  * timer_view_add()
71  * @param[in] parent                  Pointer to the parent in which the new add layout will be placed
72  * @param[in] cb                       a Eina_Bool value to indicate whether the controlbar should be displayed
73  *
74  * @return      Evas_Object*,      the new created layout
75  */
76 EAPI Evas_Object *timer_view_add(Evas_Object * parent, Evas_Object * win,
77                                  timer_controlbar_visible cb)
78 {
79         int nErr = SUCCESS;
80         Evas_Object *ret = NULL;
81         CLK_GOTO_IF_RUN(g_ad, End, ret = g_ad->layout_main, "g_ad is not null");
82         struct appdata *ad = CALLOC(1, struct appdata);
83         CLK_GOTO_IF_RUN(!ad, End, ret = NULL, "ad null");
84         g_ad = ad;
85         //
86         ad->view_setting = CALLOC(1, setting_view);
87         CLK_GOTO_IF_RUN(!ad->view_setting, End, ret =
88                         NULL, "ad->view_setting null");
89         //
90         ad->view_motion = CALLOC(1, motion_view);
91         CLK_GOTO_IF_RUN(!ad->view_motion, End, ret =
92                         NULL, "ad->view_motion null");
93         /* init internationalization */
94         bindtextdomain(PACKAGE, LOCALEDIR);
95         //
96         ad->win_main = win;
97         ad->parent = parent;
98         ad->navi_bar = __timer_create_navigation_layout(parent);
99         ad->controlbar_cb = cb;
100         ad->isTimerView = 1;
101         ad->timer_interval = 0.9;
102         /*ad->evas = evas_object_evas_get(ad->win_main); */
103         //
104         ad->layout_main = widget_create_layout_empty(parent);
105         ad->layout = load_edj(ad->layout_main, EDJ_NAME, GRP_MAIN);
106         CLK_GOTO_IF_RUN(!ad->layout, End, ret = NULL, "ad->layout null");
107         elm_object_part_content_set(ad->layout_main,
108                                     STRING_TIMER_ELM_SWALLOW_CONTENT,
109                                     ad->layout);
110         ad->eo_effect = load_edj(ad->layout, EDJ_NAME, STRING_TIMER_EFFECT);
111         elm_object_part_content_set(ad->layout,
112                                     STRING_TIMER_ELM_SWALLOW_CONTENT,
113                                     ad->eo_effect);
114         //
115         nErr = alarmmgr_init(PKGNAME);
116         CLK_GOTO_IF_RUN(nErr != SUCCESS, End, ret =
117                         NULL, "alarmmgr_init error");
118         nErr = alarmdb_init(NULL);
119         CLK_GOTO_IF_RUN(nErr != SUCCESS, End, ret = NULL, "alarmdb_init error");
120         //
121         ad->page = timer_utils_read_alarm_state(ad);
122         if (IS_EQUAL(ad->page, TIMER_VIEW_PAGE_MOTION)) {
123                 timer_view_motion.create(ad);
124                 elm_object_part_content_set(ad->eo_effect,
125                                             STRING_TIMER_ELM_SWALLOW_CENTER,
126                                             ad->view_motion->eo_content);
127         } else {
128                 timer_view_setting.create(ad);
129                 elm_object_part_content_set(ad->eo_effect,
130                                             STRING_TIMER_ELM_SWALLOW_CENTER,
131                                             ad->view_setting->eo_content);
132         }
133
134         ad->back_button =
135             widget_create_button(ad->layout,
136                                  STRING_TIMER_NAVIFRAME_END_BTN_DEFAULT, NULL,
137                                  NULL, timer_view_back_btn_cb, ad->win_main);
138
139         ad->ei_naviframe =
140             widget_naviframe_push(ad->navi_bar,
141                                   STRING_TIMER_IDS_COM_BODY_TIMER_S_,
142                                   ad->back_button, NULL, ad->layout_main,
143                                   "tabbar", NULL);
144         elm_naviframe_item_title_visible_set(ad->ei_naviframe, EINA_FALSE);
145         ret = ad->navi_bar;
146         ad->controlbar_cb(EINA_TRUE);
147
148         feedback_initialize();
149  End:
150         if (!ret) {
151                 timer_view_free(NULL);
152         }
153         return ret;
154 }
155
156 /**
157  * Debug function: to create and show view.
158  * It will show motion view if there is an alarm of timer in server. otherwise, setting view will be shown.
159  * This function doesn't requires any input parameter
160  *
161  * timer_view_reload()
162  *
163  * @return     void
164  */
165 EAPI void timer_view_reload()
166 {
167         retm_if(!g_ad, "g_ad null");
168         struct appdata *ad = g_ad;
169
170         g_ad->isTimerView = 1;
171         ad->controlbar_cb(EINA_TRUE);
172         timer_utils_view_update(g_ad);
173         if (IS_EQUAL(ad->page, TIMER_VIEW_PAGE_MOTION)) {
174                 timer_repaint_time(g_ad);
175         }
176 }
177
178 /**
179  * Debug function: to set a variable which indicates whether timer view is active in Clock application.
180  * This function doesn't requires any input parameter
181  *
182  * timer_view_reload()
183  *
184  * @return     void
185  */
186 EAPI void timer_view_unload()
187 {
188         retm_if(!g_ad, "g_ad null");
189         g_ad->isTimerView = 0;  // timer view doesn't exist.
190 }
191
192 /**
193  * Debug function: to free all objects in the view going to be distroyed
194  * This function requires data as parameters
195  *
196  * timer_view_free()
197  * @param[in] obj                  Pointer to view which will be distroyed
198  *
199  * @return      void
200  */
201 EAPI void timer_view_free(Evas_Object * obj)
202 {
203         retm_if(NULL_CHECK(g_ad), "g_ad null");
204         struct appdata *ad = g_ad;
205         alarmdb_fini();
206         alarmmgr_fini();
207         feedback_deinitialize();
208         timer_view_setting.destroy(ad);
209         timer_view_motion.destroy(ad);
210         EVAS_OBJECT_DELIF(ad->ly_parent);
211         FREEIF(ad->view_setting);
212         FREEIF(ad->view_motion);
213         FREEIF(ad);
214 }