c51933101429c5fdd7745f95e915393b37833e3a
[apps/core/preloaded/calendar.git] / ug / settings / ug-settings.c
1 /*
2
3 Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
4
5 This file is part of org.tizen.efl-calendar
6 Written by Taeho Kang <taeho84.kang@samsung.com>
7
8 PROPRIETARY/CONFIDENTIAL
9
10 This software is the confidential and proprietary information of
11 SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
12 disclose such Confidential Information and shall use it only in
13 accordance with the terms of the license agreement you entered
14 into with SAMSUNG ELECTRONICS.
15
16 SAMSUNG make no representations or warranties about the suitability
17 of the software, either express or implied, including but not limited
18 to the implied warranties of merchantability, fitness for a particular
19 purpose, or non-infringement. SAMSUNG shall not be liable for any
20 damages suffered by licensee as a result of using, modifying or
21 distributing this software or its derivatives.
22
23 */
24
25
26 #include <ui-gadget-module.h>
27 #include <libintl.h>
28 #include <vconf.h>
29 #include <vconf-keys.h>
30
31 #include "cld.h"
32 #include "ug-settings.h"
33 #include "ug-settings-view.h"
34
35 extern int appcore_set_i18n(const char *, const char *);
36
37 static void __cal_setting_ug_back_button_callback(void *data, Evas_Object *obj, void *event_info)
38 {
39         struct ug_data *ugd = data;
40         evas_object_hide(ugd->bg);
41         ug_destroy_me(ugd->ug);
42 }
43
44 static void __cal_setting_ug_initialize(struct ug_data *ugd)
45 {
46         char *tz_path = NULL;
47         char *tz_city = NULL;
48         char *tz_offset = NULL;
49         int   ret;
50
51         ret = cal_util_get_timezone_info(&tz_path, &tz_city, &tz_offset);
52         c_warn_if(ret, "cal_util_get_timezone_info is failed");
53
54         if (tz_city)
55                 ugd->city = strdup(tz_city);
56         else {
57                 ERR("tz_city is null");
58                 ugd->city = strdup("IDS_WCL_BODY_CITYNAME_SEOUL");
59                 c_warn_if(!ugd->city, "ugd->city is null");
60         }
61
62         if (tz_offset)
63                 ugd->time_zone = strdup(tz_offset);
64         else {
65                 ERR("tz_offset is null");
66                 ugd->time_zone = strdup("GMT+9");
67                 c_warn_if(!ugd->time_zone, "ugd->city is null");
68         }
69
70         if (tz_path)
71                 free(tz_path);
72         if (tz_city)
73                 free(tz_city);
74         if (tz_offset)
75                 free(tz_offset);
76
77         ret = vconf_get_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, &ugd->is_on);
78         c_warn_if(ret, "vconf_get_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, &ugd->is_on) is failed");
79
80         if (0 != vconf_get_int(VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT,&ugd->is_monday))
81         {
82                 ret = vconf_set_int(VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, 1);
83                 c_warn_if(ret != 0,"vconf_set_int(VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, 0) is failed(%d)", ret);
84         }
85
86         if (0 != vconf_get_int(CAL_VCONFKEY_FOCUS_VIEW,&ugd->is_daily))
87         {
88                 ret = vconf_set_int(CAL_VCONFKEY_FOCUS_VIEW, 1);
89                 c_warn_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_FOCUS_VIEW, 0) is failed(%d)", ret);
90         }
91 }
92
93 static Evas_Object *__cal_setting_ug_create_layout(Evas_Object *parent, struct ug_data *ugd)
94 {
95         Evas_Object *bt_back = NULL;
96         Evas_Object *layout = NULL;
97         Elm_Object_Item* navi_item = NULL;
98
99         ugd->base = cal_util_add_layout(parent, NULL);
100         CAL_ASSERT(ugd->base);
101
102         ugd->bg = cal_util_add_bg(ugd->base, EINA_FALSE);
103         CAL_ASSERT(ugd->bg);
104
105         ugd->nv = elm_naviframe_add(ugd->base);
106         CAL_ASSERT(ugd->nv);
107
108         layout = cal_setting_ug_create_view(ugd->nv, ugd);
109         CAL_ASSERT(layout);
110
111         navi_item = elm_naviframe_item_push(ugd->nv, "Calendar", NULL, NULL, layout, NULL);
112
113         bt_back = elm_object_item_part_content_get(navi_item, "prev_btn");
114         if (!bt_back)
115         {
116                 bt_back = elm_button_add(ugd->nv);
117                 elm_object_item_part_content_set(navi_item, "prev_btn", bt_back);
118         }
119         elm_object_style_set(bt_back, "naviframe/back_btn/default");
120         evas_object_smart_callback_add(bt_back, "clicked", __cal_setting_ug_back_button_callback, ugd);
121
122         elm_object_part_content_set(ugd->base, "elm.swallow.content", ugd->nv);
123         elm_object_part_content_set(ugd->base, "elm.swallow.bg", ugd->bg);
124
125         return ugd->base;
126 }
127
128 static void *__cal_setting_ug_create_callback(struct ui_gadget *ug, enum ug_mode mode, bundle *data, void *priv)
129 {
130         Evas_Object *parent;
131         struct ug_data *ugd;
132         Evas_Object *base;
133
134         if (!ug || !priv)
135                 return NULL;
136
137         cal_util_connect_pattern_generator();
138
139         ugd = priv;
140         ugd->ug = ug;
141         __cal_setting_ug_initialize(ugd);
142         if (mode != UG_MODE_FULLVIEW)
143                 return NULL;
144         parent = ug_get_parent_layout(ug);
145         if (!parent)
146                 return NULL;
147
148         base = __cal_setting_ug_create_layout(parent, ugd);
149         c_retvm_if(!base, NULL, "base is null");
150
151         return base;
152 }
153
154 static void __cal_setting_ug_destroy_callback(struct ui_gadget *ug, bundle *data, void *priv)
155 {
156         struct ug_data *ugd;
157
158         if (!ug || !priv)
159                 return;
160
161         ugd = priv;
162
163         cal_util_delete_evas_object(&ugd->base);
164 }
165
166 static void __cal_setting_ug_key_callback(struct ui_gadget *ug, enum ug_key_event evt,
167                 bundle *data, void *priv)
168 {
169         if (!ug)
170                 return;
171
172         DBG("UG: key event %d", evt);
173
174         switch (evt) {
175         case UG_KEY_EVENT_END:
176                 ug_destroy_me(ug);
177                 break;
178         default:
179                 break;
180         }
181 }
182
183 static inline void __cal_setting_ug_bind_text_domain()
184 {
185         const char *r;
186
187         r = bindtextdomain(UGSETTINGS, UGLOCALE);
188         if (!r)
189                 ERR("UG: bindtextdomain error");
190 }
191
192 API int setting_plugin_reset(bundle *data, void *priv)
193 {
194         CAL_FN_START;
195
196         int ret;
197
198         ret = CALENDAR_SVC_CONNECT();
199         c_warn_if(ret != CAL_SUCCESS, "CALENDAR_SVC_CONNECT is failed(%d)", ret);
200
201         ret = vconf_set_int(CAL_VCONFKEY_FOCUS_VIEW, 0);
202         c_warn_if(ret != 0, "vconf_set_int(CAL_VCONFKEY_FOCUS_VIEW, 0) is failed(%d)", ret);
203
204         ret = vconf_set_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, 0);
205         c_warn_if(ret != 0, "vconf_set_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, 0) is failed(%d)", ret);
206
207         ret = vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_PATH, "Asia/Seoul");
208         c_warn_if(ret != 0, "vconf_set_int(CAL_VCONFKEY_LOCK_TIMEZONE_PATH, 'Seoul') is failed(%d)", ret);
209
210         ret = vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_CITY, "IDS_WCL_BODY_CITYNAME_SEOUL");
211         c_warn_if(ret != 0, "vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_CITY, tzpath) is failed");
212
213         ret = vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_OFFSET, "+9");
214         c_warn_if(ret != 0, "vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_OFFSET, tzpath) is failed");
215
216         ret = CALENDAR_SVC_DELETE_ALL(ALL_ACCOUNT_ID, NULL);
217         c_warn_if(ret != CAL_SUCCESS, "CALENDAR_SVC_DELETE_ALL(ALL_ACCOUNT_ID, NULL) is failed(%d)", ret);
218
219         ret = CALENDAR_SVC_DISCONNECT();
220         c_warn_if(ret != CAL_SUCCESS, "CALENDAR_SVC_DISCONNECT is failed(%d)", ret);
221
222         return 0;
223 }
224
225 API int UG_MODULE_INIT(struct ug_module_ops *ops)
226 {
227         struct ug_data *ugd;
228
229         if (!ops)
230                 return -1;
231
232         CAL_CALLOC(ugd, 1, struct ug_data);
233
234         ops->create = __cal_setting_ug_create_callback;
235         ops->destroy = __cal_setting_ug_destroy_callback;
236         ops->key_event = __cal_setting_ug_key_callback;
237         ops->priv = ugd;
238         ops->opt = UG_OPT_INDICATOR_PORTRAIT_ONLY;
239
240         __cal_setting_ug_bind_text_domain();
241
242         appcore_set_i18n(CALENDAR_PACKAGE, LOCALEDIR);
243
244         return 0;
245 }
246
247 API void UG_MODULE_EXIT(struct ug_module_ops *ops)
248 {
249         struct ug_data *ugd;
250
251         cal_util_disconnect_pattern_generator();
252
253         if (!ops)
254                 return;
255
256         ugd = ops->priv;
257         free(ugd);
258 }