3 * Copyright 2012 Samsung Electronics Co., Ltd
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
9 * http://www.tizenopensource.org/license
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.
23 #include <ui-gadget-module.h>
25 #include <appcore-common.h>
29 #define MAX_STR_LEN 1024
31 // TODO: get full path from caller
32 #define VFILE_PATH "/opt/data/ug-calendar"
34 static void __cal_edit_ug_init_base_time(ug_data *ugd)
44 localtime_r(&now, &tm);
45 tm.tm_min = 0; // min, sec reset for mktime()
49 ugd->base_tm = ugd->today_tm;
52 static Evas_Object *__cal_edit_ug_create_layout(Evas_Object *parent, ug_data *ugd)
54 ugd->base = cal_util_add_layout(parent, NULL);
55 CAL_ASSERT(ugd->base);
57 ugd->nv = elm_naviframe_add(parent);
60 ugd->bg = cal_util_add_bg(ugd->base, EINA_FALSE);
63 elm_object_part_content_set(ugd->base, "elm.swallow.content", ugd->nv);
64 elm_object_part_content_set(ugd->base, "elm.swallow.bg", ugd->bg);
65 elm_object_theme_set(ugd->nv, ugd->theme);
67 ugd->u_type = UG_EDIT;
69 __cal_edit_ug_init_base_time(ugd);
71 cal_edit_create_view(ugd, ugd->nv);
76 static void __cal_edit_ug_get_strnote(ug_data *ugd, bundle *data)
78 if (NULL == ugd || NULL == data)
83 const char *str = bundle_get_val(data, "note");
85 ugd->strnote = strdup(str);
89 static void __cal_edit_ug_get_bundle_parameter(ug_data *ugd, bundle *data)
91 const char *str = NULL;
92 time_t t = time(NULL);
94 struct tm* returned_tm = gmtime_r(&t, &cur_tm);
97 ERR("gmtime return null");
104 str = bundle_get_val(data, "year");
107 ugd->tm_year = atoi(str);
111 ugd->tm_year = cur_tm.tm_year;
115 str = bundle_get_val(data, "month");
118 ugd->tm_mon = atoi(str);
122 ugd->tm_mon = cur_tm.tm_mon;
126 str = bundle_get_val(data, "day");
129 ugd->tm_mday = atoi(str);
133 ugd->tm_mday = cur_tm.tm_mday;
138 str = bundle_get_val(data, "hour");
141 ugd->base_hour = atoi(str);
149 str = bundle_get_val(data, "index");
152 ugd->cid = atoi(str);
159 str = bundle_get_val(data, "account_id");
162 ugd->account_id = atoi(str);
169 str = bundle_get_val(data, "mail_id");
172 ugd->mail_id = atoi(str);
179 str = bundle_get_val(data, "src_box");
182 ugd->src_box = strdup(str);
189 __cal_edit_ug_get_strnote(ugd, data);
194 static void *__cal_edit_ug_create_callback(struct ui_gadget *ug, enum ug_mode mode, bundle *data, void *priv)
196 if (NULL == ug || NULL == priv)
201 Evas_Object *parent = NULL;
203 Evas_Object *base = NULL;
208 __cal_edit_ug_get_bundle_parameter(ugd,data);
210 if (UG_MODE_FULLVIEW != mode)
213 parent = ug_get_parent_layout(ug);
216 ugd->win = ug_get_window();
217 CAL_ASSERT(ugd->win);
219 base = __cal_edit_ug_create_layout(parent, ugd);
222 CALENDAR_SVC_DISCONNECT();
229 static void __cal_edit_ug_destroy_callback(struct ui_gadget *ug, bundle *data, void *priv)
240 cal_util_delete_evas_object(&ugd->base);
245 static void __cal_edit_ug_key_callback(struct ui_gadget *ug, enum ug_key_event evt, bundle *data, void *priv)
250 DBG("UG: key event %d", evt);
254 case UG_KEY_EVENT_END:
263 static int __cal_edit_ug_initialize(ug_data *ugd)
272 r = CALENDAR_SVC_CONNECT();
273 if (r != CAL_SUCCESS)
275 ERR("calendar service connect failed");
279 r = account_connect();
280 c_retvm_if(r != ACCOUNT_ERROR_NONE, -1, "account_connect is failed(%x)", r);
282 appcore_set_i18n(CALENDAR_PACKAGE, LOCALEDIR);
284 ugd->theme = elm_theme_new();
285 if (NULL == ugd->theme)
290 elm_theme_ref_set(ugd->theme, NULL); //refer to default theme(NULL)
292 cal_util_connect_pattern_generator();
297 static int __cal_edit_ug_finish(ug_data *ugd)
301 r = CALENDAR_SVC_DISCONNECT();
302 if (r != CAL_SUCCESS)
304 ERR("calendar service close failed");
308 r = account_disconnect();
309 c_retvm_if(r != ACCOUNT_ERROR_NONE, -1, "account_disconnect is failed(%x)", r);
311 if(NULL != ugd->theme)
313 elm_theme_extension_del(ugd->theme, EDJDIR "/calendar_theme.edj"); //delete extension to the new theme (optional)
314 elm_theme_free(ugd->theme);
318 cal_util_disconnect_pattern_generator();
324 static inline void __cal_edit_ug_bind_text_domain()
328 r = bindtextdomain(UGSETTINGS, UGLOCALE);
330 ERR("UG: bindtextdomain error");
333 API int UG_MODULE_INIT(struct ug_module_ops *ops)
340 CAL_CALLOC(ugd, 1, ug_data);
342 ops->create = __cal_edit_ug_create_callback;
343 ops->destroy = __cal_edit_ug_destroy_callback;
344 ops->key_event = __cal_edit_ug_key_callback;
346 ops->opt = UG_OPT_INDICATOR_ENABLE;
348 __cal_edit_ug_bind_text_domain();
350 __cal_edit_ug_initialize(ugd);
355 API void UG_MODULE_EXIT(struct ug_module_ops *ops)
365 __cal_edit_ug_finish(ugd);