df2a289c63df21e29e35e688ff5d105917449ff4
[apps/home/call-setting.git] / src / cst-main.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://www.tizenopensource.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 #ifndef UG_MODULE_API
18 #define UG_MODULE_API __attribute__ ((visibility("default")))
19 #endif
20
21 #include <Elementary.h>
22 #include <ui-gadget-module.h>
23 #include <Eina.h>
24 #include <vconf.h>
25
26 #include "cst-common.h"
27 #include "cst-debug.h"
28 #include "cst-common-string.h"
29 #include "cst-tapi-request.h"
30 #include "cst-call-setting.h"
31
32
33 static Evas_Object *__cst_create_content(Evas_Object *parent, CstUgData_t *ugd)
34 {
35         ENTER(__cst_create_content);
36         Evas_Object *nf;
37         Evas_Object *eo;
38         Evas_Object *l_button;
39         retv_if(parent == NULL, NULL);
40
41         nf = elm_naviframe_add(parent);
42         ugd->nf = nf;
43         evas_object_show(nf);
44         ugd->popup = NULL;
45
46         elm_object_part_content_set(ugd->base, "elm.swallow.content", nf);
47         _cst_create_call_setting(ugd);
48
49         LEAVE();
50
51         return nf;
52 }
53
54 static Evas_Object *__cst_create_fullview(Evas_Object *parent, CstUgData_t *ugd)
55 {
56         ENTER(__cst_create_fullview);
57         Evas_Object *base;
58
59         /* Create Full view */
60         base = elm_layout_add(parent);
61         if (!base)
62                 return NULL;
63
64         elm_layout_theme_set(base, "layout", "application", "default");
65         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
66         elm_win_resize_object_add(parent, base);
67
68         evas_object_show(base);
69         LEAVE();
70
71         return base;
72 }
73
74 static Evas_Object *__cst_create_frameview(Evas_Object *parent, CstUgData_t *ugd)
75 {
76         ENTER(__cst_create_frameview);
77         Evas_Object *base = NULL;
78
79         return base;
80 }
81
82 static Evas_Object *__cst_create_bg(Evas_Object *parent)
83 {
84         ENTER(__cst_create_bg);
85         Evas_Object *bg = elm_bg_add(parent);
86         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
87         elm_win_resize_object_add(parent, bg);
88         evas_object_show(bg);
89
90         return bg;
91 }
92
93 static void *__cst_on_create(struct ui_gadget *ug, enum ug_mode mode, bundle *data, void *priv)
94 {
95         ENTER(__cst_on_create);
96         Evas_Object *parent, *content;
97         CstUgData_t *ugd;
98
99         if (!ug || !priv)
100                 return NULL;
101
102         ugd = priv;
103         ugd->ug = ug;
104
105         bindtextdomain(UGNAME, "/opt/ug/res/locale");
106
107         parent = ug_get_parent_layout(ug);
108         ugd->win_main = parent;
109         retv_if(parent == NULL, NULL);
110         ugd->back_button = NULL;
111         ugd->req_queue = NULL;
112
113         // Register the telephony ss events
114         _cst_ciss_register_tel_event(ugd);
115
116         ugd->bg = __cst_create_bg(parent);
117         elm_object_style_set(ugd->bg, "transparent");
118         elm_object_style_set(ugd->bg, "group_list");
119
120         if (mode == UG_MODE_FULLVIEW)
121                 ugd->base = __cst_create_fullview(parent, ugd);
122         else
123                 ugd->base = __cst_create_frameview(parent, ugd);
124
125         if (ugd->base) {
126                 content = __cst_create_content(parent, ugd);
127                 elm_object_part_content_set(ugd->base, "elm.swallow.content", content);
128         }
129
130         elm_object_part_content_set(ugd->base, "elm.swallow.bg", ugd->bg);
131
132         DBG("scale factor=%f", elm_config_scale_get());
133         return ugd->base;
134 }
135
136 static void __cst_on_start(struct ui_gadget *ug, bundle *data, void *priv)
137 {
138 }
139
140 static void __cst_on_pause(struct ui_gadget *ug, bundle *data, void *priv)
141 {
142
143 }
144
145 static void __cst_on_resume(struct ui_gadget *ug, bundle *data, void *priv)
146 {
147
148 }
149
150 static void __cst_on_destroy(struct ui_gadget *ug, bundle *data, void *priv)
151 {
152         ENTER(__cst_on_destroy);
153
154         CstUgData_t *ugd;
155
156         if (!ug || !priv)
157                 return;
158
159         ugd = priv;
160
161         if (ugd->req_queue) {
162                 Eina_List *l;
163                 CallSettingReq_t *req;
164
165                 EINA_LIST_FOREACH(ugd->req_queue, l, req) {
166                         free(req);
167                 }
168                 ugd->req_queue = eina_list_free(ugd->req_queue);
169         }
170
171         if (ugd->popup != NULL) {
172                 evas_object_del(ugd->popup);
173                 ugd->popup = NULL;
174         }
175
176         _cst_ciss_deregister_tel_event(ugd);
177
178         if(ugd->bg) {
179                 evas_object_del(ugd->bg);
180                 ugd->bg = NULL;
181         }
182
183         if(ugd->base) {
184                 evas_object_del(ugd->base);
185                 ugd->base = NULL;
186         }
187         LEAVE();
188 }
189
190 static void __cst_on_message(struct ui_gadget *ug, bundle *msg, bundle *data, void *priv)
191 {
192 }
193
194 static void __cst_on_key_event(struct ui_gadget *ug, enum ug_key_event event, bundle *data, void *priv)
195 {
196         ENTER(__cst_on_key_event);
197
198         CstUgData_t *ugd;
199
200         if (!ug || !priv)
201                 return;
202
203         ugd = priv;
204
205         switch (event) {
206         case UG_KEY_EVENT_END:
207                 if (ugd->popup != NULL) {
208                         DBG("popup=0x%p", ugd->popup);
209                         evas_object_del(ugd->popup);
210                         ugd->popup = NULL;
211                 } else if (ugd->back_button != NULL) {
212                         DBG("back_button = 0x%p", ugd->back_button);
213                         evas_object_smart_callback_call(ugd->back_button, "clicked", NULL);
214                 } else {
215                         DBG("Error: No action is defined for END KEY EVENT, popup=0x%p, back_button=0x%p", ugd->popup, ugd->back_button);
216                 }
217                 break;
218
219         default:
220                 DBG("Unknown Event Detected, event=%d", event);
221                 break;
222         }
223 }
224
225 static void __cst_on_event(struct ui_gadget *ug, enum ug_event event, bundle *data, void *priv)
226 {
227         ENTER(__cst_on_event);
228         switch (event) {
229         case UG_EVENT_LOW_MEMORY:
230                 DBG("UG_EVENT_LOW_MEMORY");
231                 break;
232         case UG_EVENT_LOW_BATTERY:
233                 DBG("UG_EVENT_LOW_BATTERY");
234                 break;
235         case UG_EVENT_LANG_CHANGE:
236                 DBG("UG_EVENT_LANG_CHANGE");
237                 break;
238         case UG_EVENT_ROTATE_PORTRAIT:
239                 DBG("UG_EVENT_ROTATE_PORTRAIT");
240                 break;
241         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
242                 DBG("UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN");
243                 break;
244         case UG_EVENT_ROTATE_LANDSCAPE:
245                 DBG("UG_EVENT_ROTATE_LANDSCAPE");
246                 break;
247         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
248                 DBG("UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN");
249                 break;
250         default:
251                 break;
252         }
253         LEAVE();
254 }
255
256 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
257 {
258         ENTER(UG_MODULE_INIT);
259
260         CstUgData_t *ugd;
261
262         if (!ops)
263                 return -1;
264
265         ugd = calloc(1, sizeof(CstUgData_t));
266         if (!ugd)
267                 return -1;
268
269         ops->create = __cst_on_create;
270         ops->start = __cst_on_start;
271         ops->pause = __cst_on_pause;
272         ops->resume = __cst_on_resume;
273         ops->destroy = __cst_on_destroy;
274         ops->message = __cst_on_message;
275         ops->event = __cst_on_event;
276         ops->key_event = __cst_on_key_event;
277         ops->priv = ugd;
278         ops->opt = UG_OPT_INDICATOR_ENABLE;
279         LEAVE();
280         return 0;
281 }
282
283 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
284 {
285         ENTER(UG_MODULE_EXIT);
286         struct ug_data *ugd;
287
288         if (!ops)
289                 return;
290
291         ugd = ops->priv;
292         if (ugd)
293                 free(ugd);
294         LEAVE();
295 }
296
297 /**
298 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
299 *
300 * @param[in] data
301 * @param[in] priv
302 */
303 UG_MODULE_API int setting_plugin_reset(bundle *data, void *priv)
304 {
305         ENTER(setting_plugin_reset);
306         int ret = 0;
307
308                 ret += vconf_set_int(VCONFKEY_CISSAPPL_SHOW_MY_NUMBER_INT, CST_CLI_BY_NETWORK);
309
310                 /*Prefix dialling*/
311                 ret += vconf_set_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, EINA_FALSE);
312                 ret += vconf_set_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_INT, 0);
313                 ret += vconf_set_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_VALUE_INT, 0);
314                 ret += vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR, "");
315                 ret += vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR, "");
316                 ret += vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR, "");
317                 ret += vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR, "");
318                 ret += vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR, "");
319                 /*Call status tone*/
320                 ret += vconf_set_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, EINA_FALSE);
321                 ret += vconf_set_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, EINA_FALSE);
322                 ret += vconf_set_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, EINA_FALSE);
323
324                 ret += vconf_set_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, CST_ALERTS_ON_CALL_OFF);
325
326                 ret += vconf_set_bool(VCONFKEY_CISSAPPL_VOICE_AUTO_REDIAL_BOOL, EINA_FALSE);
327                 ret += vconf_set_bool(VCONFKEY_CISSAPPL_VIDEO_AUTO_REDIAL_BOOL, EINA_FALSE);
328
329         return ret;
330 }