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.
19 #include <ui-gadget-module.h>
21 #include <appcore-common.h>
25 #define MAX_STR_LEN 1024
27 // TODO: get full path from caller
28 #define VFILE_PATH "/opt/data/ug-calendar"
30 static void __cal_edit_ug_init_base_time(ug_data *ugd)
40 localtime_r(&now, &tm);
41 tm.tm_min = 0; // min, sec reset for mktime()
45 ugd->base_tm = ugd->today_tm;
48 static Evas_Object *__cal_edit_ug_create_layout(Evas_Object *parent, ug_data *ugd)
50 ugd->base = cal_util_add_layout(parent, NULL);
51 CAL_ASSERT(ugd->base);
53 ugd->nv = elm_naviframe_add(parent);
56 ugd->bg = cal_util_add_bg(ugd->base, EINA_FALSE);
59 elm_object_part_content_set(ugd->base, "elm.swallow.content", ugd->nv);
60 elm_object_part_content_set(ugd->base, "elm.swallow.bg", ugd->bg);
61 elm_object_theme_set(ugd->nv, ugd->theme);
63 ugd->u_type = UG_EDIT;
65 __cal_edit_ug_init_base_time(ugd);
67 cal_edit_create_view(ugd, ugd->nv);
72 static void __cal_edit_ug_get_strnote(ug_data *ugd, service_h service)
80 char strnote_tag[MAX_STR_LEN]= {0, };
82 if ((0 != ugd->account_id) && (0 != ugd->mail_id) && (NULL != ugd->src_box)) {
84 int r = service_get_extra_data(service, "note", &str);
85 c_ret_if(r != SERVICE_ERROR_NONE);
87 snprintf(strnote_tag, sizeof(strnote_tag), "%s%d_%d_%s", EMAIL_LINK_FLAG, ugd->account_id, ugd->mail_id, ugd->src_box);
88 strnote_len = strlen(str)+strlen(strnote_tag);
90 CAL_CALLOC(strnote, strnote_len+1, char);
92 snprintf(strnote, strnote_len+1, "%s%s", str, strnote_tag);
93 ugd->strnote = strdup(strnote);
99 int r = service_get_extra_data(service, "note", &str);
100 c_ret_if(r != SERVICE_ERROR_NONE);
105 static void __cal_edit_ug_get_bundle_parameter(ug_data *ugd, service_h service)
111 time_t t = time(NULL);
113 struct tm *returned_tm = gmtime_r(&t, &cur_tm);
114 c_ret_if(!returned_tm);
117 int r = service_get_extra_data(service, "year", &str);
118 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data() is failed(%d)", r);
120 ugd->tm_year = atoi(str);
126 ugd->tm_year = cur_tm.tm_year;
130 r = service_get_extra_data(service, "month", &str);
131 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data() is failed(%d)", r);
133 ugd->tm_mon = atoi(str);
139 ugd->tm_mon = cur_tm.tm_mon;
143 r = service_get_extra_data(service, "day", &str);
144 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data() is failed(%d)", r);
146 ugd->tm_mday = atoi(str);
152 ugd->tm_mday = cur_tm.tm_mday;
157 r = service_get_extra_data(service, "hour", &str);
158 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data() is failed(%d)", r);
160 ugd->base_hour = atoi(str);
170 r = service_get_extra_data(service, "index", &str);
171 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data() is failed(%d)", r);
173 ugd->cid = atoi(str);
182 r = service_get_extra_data(service, "account_id", &str);
183 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data() is failed(%d)", r);
185 ugd->account_id = atoi(str);
194 r = service_get_extra_data(service, "mail_id", &str);
195 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data() is failed(%d)", r);
197 ugd->mail_id = atoi(str);
206 r = service_get_extra_data(service, "src_box", &str);
207 c_warn_if(r != SERVICE_ERROR_NONE, "service_get_extra_data() is failed(%d)", r);
209 ugd->src_box = strdup(str);
218 __cal_edit_ug_get_strnote(ugd, service);
221 static void *__cal_edit_ug_create_callback(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
223 if (NULL == ug || NULL == priv)
228 Evas_Object *parent = NULL;
230 Evas_Object *base = NULL;
235 __cal_edit_ug_get_bundle_parameter(ugd,service);
237 if (UG_MODE_FULLVIEW != mode)
240 parent = ug_get_parent_layout(ug);
243 ugd->win = ug_get_window();
244 CAL_ASSERT(ugd->win);
246 base = __cal_edit_ug_create_layout(parent, ugd);
249 CALENDAR_SVC_DISCONNECT();
256 static void __cal_edit_ug_destroy_callback(ui_gadget_h ug, service_h service, void *priv)
267 cal_util_delete_evas_object(&ugd->base);
272 static void __cal_edit_ug_key_callback(ui_gadget_h ug, enum ug_key_event evt, service_h service, void *priv)
277 DBG("UG: key event %d", evt);
281 case UG_KEY_EVENT_END:
290 static int __cal_edit_ug_initialize(ug_data *ugd)
299 r = CALENDAR_SVC_CONNECT();
300 if (r != CAL_SUCCESS)
302 ERR("calendar service connect failed");
306 r = account_connect();
307 c_retvm_if(r != ACCOUNT_ERROR_NONE, -1, "account_connect is failed(%x)", r);
309 appcore_set_i18n(CALENDAR_PACKAGE, LOCALEDIR);
311 ugd->theme = elm_theme_new();
312 if (NULL == ugd->theme)
317 elm_theme_ref_set(ugd->theme, NULL); //refer to default theme(NULL)
319 cal_util_connect_pattern_generator();
324 static int __cal_edit_ug_finish(ug_data *ugd)
328 r = CALENDAR_SVC_DISCONNECT();
329 if (r != CAL_SUCCESS)
331 ERR("calendar service close failed");
335 r = account_disconnect();
336 c_retvm_if(r != ACCOUNT_ERROR_NONE, -1, "account_disconnect is failed(%x)", r);
338 if(NULL != ugd->theme)
340 elm_theme_extension_del(ugd->theme, EDJDIR "/calendar_theme.edj"); //delete extension to the new theme (optional)
341 elm_theme_free(ugd->theme);
345 cal_util_disconnect_pattern_generator();
351 static inline void __cal_edit_ug_bind_text_domain()
355 r = bindtextdomain(UGSETTINGS, UGLOCALE);
357 ERR("UG: bindtextdomain error");
360 API int UG_MODULE_INIT(struct ug_module_ops *ops)
367 CAL_CALLOC(ugd, 1, ug_data);
369 ops->create = __cal_edit_ug_create_callback;
370 ops->destroy = __cal_edit_ug_destroy_callback;
371 ops->key_event = __cal_edit_ug_key_callback;
373 ops->opt = UG_OPT_INDICATOR_ENABLE;
375 __cal_edit_ug_bind_text_domain();
377 __cal_edit_ug_initialize(ugd);
382 API void UG_MODULE_EXIT(struct ug_module_ops *ops)
392 __cal_edit_ug_finish(ugd);