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://floralicense.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.
25 // TODO: get full path from caller
26 #define VFILE_PATH "/opt/usr/media/Others"
28 static char* __cal_ug_get_caller(service_h b, const char *key)
32 int r = service_get_extra_data(b, key, &v);
33 c_retv_if(r != SERVICE_ERROR_NONE, NULL);
35 if (!v || v[0] == '\0')
36 return strdup("Unknown");
41 static char* __cal_ug_get_file_name(service_h b, const char *key)
44 char path[FILENAME_MAX];
46 int r = service_get_extra_data(b, key, &v);
47 c_retv_if(r != SERVICE_ERROR_NONE, NULL);
49 // TODO: check full path or not
51 snprintf(path, sizeof(path), "%s/%s", VFILE_PATH, v);
55 r = access(path, R_OK);
58 ERR("UG: Access failed: %s", path);
65 static char* __cal_ug_get_file_path(service_h b, const char *key)
69 int r = service_get_extra_data(b, key, &path);
70 c_retv_if(r != SERVICE_ERROR_NONE, NULL);
72 r = access(path, R_OK);
75 ERR("UG: Access failed: %s", path);
83 static enum cld_ug_mode __cal_ug_get_mode(service_h service, const char *key)
85 c_retv_if(!service, _MODE_UNKNOWN);
86 c_retv_if(!key, _MODE_UNKNOWN);
90 int r = service_get_extra_data(service, key, &value);
91 c_retvm_if(r != SERVICE_ERROR_NONE, _MODE_GET_VCS, "%d", r);
95 if (!CAL_STRCMP(value, "text"))
97 else if (!CAL_STRCMP(value, "view"))
107 static inline int __cal_ug_set_ug_data(struct ug_data *ugd, service_h service)
109 c_retv_if(!service, -1);
112 ugd->mode = __cal_ug_get_mode(service, "mode");
114 char *selection_mode = NULL;
115 char *item_type = NULL;
117 service_get_extra_data(service, CAL_APPCONTROL_SELECTION_MODE, &selection_mode);
119 if (!CAL_STRCMP(selection_mode, CAL_APPCONTROL_SELECTION_MODE_SINGLE))
120 ugd->selection_mode = SELECTION_MODE_SINGLE;
122 ugd->selection_mode = SELECTION_MODE_MULTIPLE;
124 service_get_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, &item_type);
126 if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_TODO))
127 ugd->item_type = ITEM_TYPE_TODO;
129 ugd->item_type = ITEM_TYPE_EVENT;
131 int r = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &val);
134 else if( val == 1 || val == 2)
137 ERR("vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &val); error");
141 ugd->caller = __cal_ug_get_caller(service, "caller");
144 ugd->vcs_file = __cal_ug_get_file_name(service, "file");
147 ERR("UG: Invalid filename");
157 free(selection_mode);
165 static void __cal_ug_back_button_callback(void *data, Evas_Object *obj, void *ei)
169 struct ug_data *ugd = data;
175 service_create(&service);
177 service_add_extra_data(service, CAL_APPCONTROL_RESULT, CAL_APPCONTROL_RESULT_CANCEL);
179 if (ugd->item_type == ITEM_TYPE_EVENT)
180 service_add_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, CAL_APPCONTROL_ITEM_TYPE_EVENT);
182 service_add_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, CAL_APPCONTROL_ITEM_TYPE_TODO);
184 ug_send_result(ugd->ug, service);
186 service_destroy(service);
188 ug_destroy_me(ugd->ug);
191 static void __cal_ug_add_back_button(struct ug_data *ugd)
195 bt = elm_button_add(ugd->naviframe);
199 elm_object_style_set(bt, "naviframe/back_btn/default");
201 elm_object_text_set(bt, "Back");
202 evas_object_show(bt);
204 Elm_Object_Item* navi_item = elm_naviframe_top_item_get(ugd->naviframe);
206 elm_object_item_part_content_set(navi_item, "prev_btn", bt);
208 evas_object_smart_callback_add(bt, "clicked", __cal_ug_back_button_callback, ugd);
211 extern void cal_vcs_viewer_ug_create(struct ug_data *ugd);
213 static Evas_Object *__cal_ug_create(Evas_Object *parent, struct ug_data *ugd)
217 ugd->base = cal_util_add_layout(parent, NULL);
218 CAL_ASSERT(ugd->base);
220 ugd->naviframe = elm_naviframe_add(parent);
221 CAL_ASSERT(ugd->naviframe);
223 ugd->bg = cal_util_add_bg(ugd->base, EINA_FALSE);
226 elm_object_theme_set(ugd->naviframe, ugd->theme);
227 elm_object_part_content_set(ugd->base, "elm.swallow.content", ugd->naviframe);
228 elm_object_part_content_set(ugd->base, "elm.swallow.bg", ugd->bg);
234 cal_list_ug_create(S_("IDS_COM_BODY_CALENDAR"), ugd);
237 cal_vcs_viewer_ug_create(ugd);
245 evas_object_del(ugd->base);
249 __cal_ug_add_back_button(ugd);
254 static void __cal_ug_free_data(struct ug_data *ugd)
261 static void *__cal_ug_create_callback(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
265 c_retv_if(!ug, NULL);
266 c_retv_if(!service, NULL);
267 c_retv_if(!priv, NULL);
276 cal_util_connect_pattern_generator();
278 if (mode != UG_MODE_FULLVIEW)
281 Evas_Object *parent = ug_get_parent_layout(ug);
282 c_retv_if(!parent, NULL);
284 r = __cal_ug_set_ug_data(ugd, service);
286 calendar_error_e err = CALENDAR_ERROR_NONE;
287 err = calendar_connect();
288 c_warn_if(err != CALENDAR_ERROR_NONE, "calendar_connect is failed(%d)", err);
290 _calendar_init_hash();
292 if (err != CALENDAR_ERROR_NONE) {
293 ERR("UG: calendar service connect failed");
294 __cal_ug_free_data(ugd);
298 base = __cal_ug_create(parent, ugd);
300 calendar_error_e error = CALENDAR_ERROR_NONE;
302 error = calendar_disconnect();
303 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_disconnect() is failed(%x)", error);
304 __cal_ug_free_data(ugd);
311 static void __cal_ug_destroy_callback(ui_gadget_h ug, service_h data, void *priv)
320 calendar_error_e error = CALENDAR_ERROR_NONE;
322 error = calendar_disconnect();
323 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_disconnect() is failed(%x)", error);
325 cal_util_disconnect_pattern_generator();
327 __cal_ug_free_data(ugd);
329 cal_util_delete_evas_object(&ugd->base);
332 static void __cal_ug_key_callback(ui_gadget_h ug, enum ug_key_event evt, service_h data, void *priv)
337 DBG("UG: key event %d", evt);
341 case UG_KEY_EVENT_END:
349 API int UG_MODULE_INIT(struct ug_module_ops *ops)
358 CAL_CALLOC(ugd, 1, struct ug_data);
360 ops->create = __cal_ug_create_callback;
361 ops->destroy = __cal_ug_destroy_callback;
362 ops->key_event = __cal_ug_key_callback;
364 ops->opt = UG_OPT_INDICATOR_ENABLE;
366 const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
367 c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
372 API void UG_MODULE_EXIT(struct ug_module_ops *ops)