upload codes for TIZEN 2.0
[apps/home/clock.git] / stopwatch / src / stopwatch_lib.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 "stopwatch_lib.h"
20 #include "stopwatch_main.h"
21 #include "stopwatch_vconf.h"
22 #include "stopwatch_util.h"
23 /**********************************************************************
24 ******************Global val , static global val*************************************
25 ***********************************************************************/
26 static struct appdata *g_ad;
27
28 /**********************************************************************
29 ******************Local function ref*************************************
30 ***********************************************************************/
31
32 /**
33  * Debug function: to free all objects in the view going to be distroyed
34  * This function requires data as parameters
35  *
36  * stopwatch_view_add()
37  * @param[in] parent                  Pointer to the parent in which the new add layout will be placed
38  * @param[in] cb                       a Eina_Bool value to indicate whether the controlbar should be displayed
39  *
40  * @return      Evas_Object*,      the new created layout
41  */
42 EAPI Evas_Object *stopwatch_view_add(Evas_Object *parent, Evas_Object *win,
43                                      stopwatch_controlbar_visible cb)
44 {
45         retvm_if(!parent, NULL, "parent null");
46         struct appdata *ad =
47             (struct appdata *)calloc(1, sizeof(struct appdata));
48         bindtextdomain(PACKAGE, LOCALEDIR);
49         ad->parent = parent;
50         ad->win = win;
51         stw_create_main_view(ad);
52         stw_util_pm_state_set(EINA_TRUE);
53         stw_noti_init(ad);
54         ad->controlbar_cb = cb;
55
56         ad->controlbar_cb(EINA_TRUE);
57         g_ad = ad;
58         return ad->layout_main;
59 }
60
61 /**
62  * Debug function: to free all objects in the view going to be distroyed
63  * This function requires data as parameters
64  *
65  * stopwatch_view_free()
66  * @param[in] obj                  Pointer to view which will be distroyed
67  *
68  * @return      void
69  */
70 EAPI void stopwatch_view_free(Evas_Object *obj)
71 {
72         retm_if(!g_ad, "a_ad is null");
73         stw_util_pm_state_set(EINA_FALSE);
74         stw_noti_fini();
75         ECORE_TIMER_DELIF(g_ad->timer);
76         EVAS_OBJECT_DELIF(g_ad->gl);
77         EVAS_OBJECT_DELIF(g_ad->ly_main);
78         EVAS_OBJECT_DELIF(g_ad->navi_bar);
79         EVAS_OBJECT_DELIF(g_ad->layout_main);
80         FREEIF(g_ad);
81 }
82
83 /**
84  * Debug function: to add control logic to KEY_POWER when stopwatch view is shown
85  * This function requires data as parameters
86  *
87  * stopwatch_view_reload()
88  *
89  * @return      void
90  */
91 EAPI void stopwatch_view_reload()
92 {
93         retm_if(!g_ad, "a_ad is null");
94         stw_util_pm_state_set(EINA_TRUE);
95         stw_noti_init(g_ad);
96         g_ad->controlbar_cb(EINA_TRUE);
97 }
98
99 /**
100  * Debug function: to remove control logic to KEY_POWER when stopwatch view is hidden
101  * This function requires data as parameters
102  *
103  * stopwatch_view_unload()
104  *
105  * @return      void
106  */
107 EAPI void stopwatch_view_unload()
108 {
109         retm_if(!g_ad, "a_ad is null");
110         stw_util_pm_state_set(EINA_FALSE);
111         stw_noti_fini(g_ad);
112 }
113
114 EAPI void stopwatch_app_pause()
115 {
116         retm_if(!g_ad, "a_ad is null");
117         stopwatch_view_unload();
118         struct appdata *ad = g_ad;
119         if (IS_EQUAL(ad->cur_state, STW_STATE_TYPE_START) && ad->timer) {
120                 ecore_timer_freeze(ad->timer);
121         }
122 }
123
124 EAPI void stopwatch_app_resume(Eina_Bool bCurrentView)
125 {
126         retm_if(!g_ad, "a_ad is null");
127         if (bCurrentView) {
128                 stopwatch_view_reload();
129         }
130         struct appdata *ad = g_ad;
131         if (IS_EQUAL(ad->cur_state, STW_STATE_TYPE_START) && ad->timer) {
132                 ecore_timer_thaw(ad->timer);
133         }
134 }