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.
24 #include "appcontrol.h"
26 // TODO: get full path from caller
27 #define VFILE_PATH "/opt/usr/media/Others"
29 static char* __cal_ug_get_caller(service_h b, const char *key)
33 int r = service_get_extra_data(b, key, &v);
34 c_retv_if(r != SERVICE_ERROR_NONE, NULL);
36 if (!v || v[0] == '\0')
37 return strdup("Unknown");
42 static char* __cal_ug_get_file_name(service_h b, const char *key)
45 char path[FILENAME_MAX];
47 int r = service_get_extra_data(b, key, &v);
48 c_retv_if(r != SERVICE_ERROR_NONE, NULL);
50 // TODO: check full path or not
52 snprintf(path, sizeof(path), "%s/%s", VFILE_PATH, v);
56 r = access(path, R_OK);
59 ERR("UG: Access failed: %s", path);
66 static char* __cal_ug_get_file_path(service_h b, const char *key)
70 int r = service_get_extra_data(b, key, &path);
71 c_retv_if(r != SERVICE_ERROR_NONE, NULL);
73 r = access(path, R_OK);
76 ERR("UG: Access failed: %s", path);
84 static cal_appcontrol_result_type __cal_ug_get_result_type(service_h service, const char *key)
86 cal_appcontrol_result_type result_type = RESULT_TYPE_VCS;
88 c_retv_if(!service, result_type);
89 c_retv_if(!key, result_type);
93 int r = service_get_extra_data(service, key, &value);
94 if (r != SERVICE_ERROR_NONE) {
100 if (!CAL_STRCMP(value, "text"))
101 result_type = RESULT_TYPE_ITEM_CONTENT;
108 static void __cal_ug_get_ug_input_data(service_h service, struct ug_data *ugd)
114 ugd->result_type = __cal_ug_get_result_type(service, "mode");
116 char *selection_mode = NULL;
117 char *item_type = NULL;
119 int r = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &val);
122 else if( val == 1 || val == 2)
125 ERR("vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &val); error");
127 ugd->selection_mode = SELECTION_MODE_MULTIPLE;
131 static void __cal_ug_back_button_callback(void *data, Evas_Object *obj, void *ei)
135 struct ug_data *ugd = data;
141 service_create(&service);
143 service_add_extra_data(service, "result", "cancel");
145 if (ugd->item_type == ITEM_TYPE_EVENT)
146 service_add_extra_data(service, "itemType", "event");
148 service_add_extra_data(service, "itemType", "todo");
150 ug_send_result(ugd->ug, service);
152 service_destroy(service);
154 ug_destroy_me(ugd->ug);
157 static void __cal_ug_add_back_button(struct ug_data *ugd)
161 bt = elm_button_add(ugd->naviframe);
165 elm_object_style_set(bt, "naviframe/back_btn/default");
167 elm_object_text_set(bt, "Back");
168 evas_object_show(bt);
170 Elm_Object_Item* navi_item = elm_naviframe_top_item_get(ugd->naviframe);
172 elm_object_item_part_content_set(navi_item, "prev_btn", bt);
174 evas_object_smart_callback_add(bt, "clicked", __cal_ug_back_button_callback, ugd);
177 extern void cal_vcs_viewer_ug_create(struct ug_data *ugd);
179 static Evas_Object *__cal_ug_create(Evas_Object *parent, struct ug_data *ugd)
183 ugd->base = cal_util_add_layout(parent, NULL);
184 CAL_ASSERT(ugd->base);
186 ugd->naviframe = elm_naviframe_add(parent);
187 CAL_ASSERT(ugd->naviframe);
189 ugd->bg = cal_util_add_bg(ugd->base, EINA_FALSE);
192 elm_object_theme_set(ugd->naviframe, ugd->theme);
193 elm_object_part_content_set(ugd->base, "elm.swallow.content", ugd->naviframe);
194 elm_object_part_content_set(ugd->base, "elm.swallow.bg", ugd->bg);
196 cal_list_ug_create(S_("IDS_COM_BODY_CALENDAR"), ugd);
199 evas_object_del(ugd->base);
203 __cal_ug_add_back_button(ugd);
208 static void __cal_ug_free_data(struct ug_data *ugd)
214 static void __cal_ug_get_appcontrol_input_data(service_h service, struct ug_data *ugd)
216 char *selection_mode = NULL;
218 service_get_extra_data(service, CAL_APPCONTROL_SELECTION_MODE, &selection_mode);
220 if (!CAL_STRCMP(selection_mode, CAL_APPCONTROL_SELECTION_MODE_MULTIPLE))
221 ugd->selection_mode = SELECTION_MODE_MULTIPLE;
223 ugd->selection_mode = SELECTION_MODE_SINGLE;
225 CAL_FREE(selection_mode);
227 char *item_type = NULL;
229 int r = service_get_extra_data(service, CAL_APPCONTROL_ITEM_TYPE, &item_type);
230 if (r != SERVICE_ERROR_NONE) {
231 ERR("service_get_extra_data(%s) is failed(%x).", CAL_APPCONTROL_ITEM_TYPE, r);
238 if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_EVENT))
239 ugd->item_type = ITEM_TYPE_EVENT;
240 else if (!CAL_STRCMP(item_type, CAL_APPCONTROL_ITEM_TYPE_TODO))
241 ugd->item_type = ITEM_TYPE_TODO;
243 ugd->item_type = ITEM_TYPE_EVENT_TODO;
247 char *result_type = NULL;
249 r = service_get_extra_data(service, CAL_APPCONTROL_RESULT_TYPE, &result_type);
250 if (r != SERVICE_ERROR_NONE) {
251 ERR("service_get_extra_data(%s) is failed(%x).", CAL_APPCONTROL_RESULT_TYPE, r);
253 CAL_FREE(result_type);
258 if (!CAL_STRCMP(result_type, CAL_APPCONTROL_RESULT_TYPE_ITEM_ID))
259 ugd->result_type = RESULT_TYPE_ITEM_ID;
261 ugd->result_type = RESULT_TYPE_VCS;
263 CAL_FREE(result_type);
266 static void __cal_ug_get_appcontrol_input_data_old(service_h service, struct ug_data *ugd)
270 char *selection_mode = NULL;
272 r = service_get_extra_data(service, "selectionMode", &selection_mode);
273 if (r != SERVICE_ERROR_NONE) {
274 ERR("service_get_extra_data(%s) is failed(%x).", "selectionMode", r);
276 CAL_FREE(selection_mode);
281 if (!CAL_STRCMP(selection_mode, "single"))
282 ugd->selection_mode = SELECTION_MODE_SINGLE;
284 ugd->selection_mode = SELECTION_MODE_MULTIPLE;
286 CAL_FREE(selection_mode);
288 char *item_type = NULL;
290 service_get_extra_data(service, "itemType", &item_type);
292 if (!CAL_STRCMP(item_type, "todo"))
293 ugd->item_type = ITEM_TYPE_TODO;
294 else if (!CAL_STRCMP(item_type, "event"))
295 ugd->item_type = ITEM_TYPE_EVENT;
297 ugd->item_type = ITEM_TYPE_EVENT_TODO;
301 ugd->result_type = RESULT_TYPE_VCS;
304 static void *__cal_ug_create_callback(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
308 c_retv_if(!ug, NULL);
309 c_retv_if(!service, NULL);
310 c_retv_if(!priv, NULL);
319 char *operation = NULL;
321 r = service_get_operation(service, &operation);
322 c_retvm_if(r != SERVICE_ERROR_NONE, NULL, "service_get_operation() is failed(%x)", r);
324 if (!CAL_STRCMP(operation, CAL_APPCONTROL_SOCAIL_PICK))
325 __cal_ug_get_appcontrol_input_data(service, ugd);
326 else if (!CAL_STRCMP(operation, SERVICE_OPERATION_PICK))
327 __cal_ug_get_appcontrol_input_data_old(service, ugd);
329 __cal_ug_get_ug_input_data(service, ugd);
333 cal_util_connect_pattern_generator();
335 if (mode != UG_MODE_FULLVIEW)
338 Evas_Object *parent = ug_get_parent_layout(ug);
339 c_retv_if(!parent, NULL);
341 calendar_error_e err = CALENDAR_ERROR_NONE;
342 err = calendar_connect();
343 c_warn_if(err != CALENDAR_ERROR_NONE, "calendar_connect is failed(%d)", err);
345 _calendar_init_hash();
347 if (err != CALENDAR_ERROR_NONE) {
348 ERR("UG: calendar service connect failed");
349 __cal_ug_free_data(ugd);
353 elm_theme_extension_add(NULL, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme3.edj");
355 base = __cal_ug_create(parent, ugd);
357 calendar_error_e error = CALENDAR_ERROR_NONE;
359 error = calendar_disconnect();
360 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_disconnect() is failed(%x)", error);
361 __cal_ug_free_data(ugd);
368 static void __cal_ug_destroy_callback(ui_gadget_h ug, service_h data, void *priv)
377 calendar_error_e error = CALENDAR_ERROR_NONE;
379 error = calendar_disconnect();
380 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_disconnect() is failed(%x)", error);
382 cal_util_disconnect_pattern_generator();
384 __cal_ug_free_data(ugd);
386 cal_util_delete_evas_object(&ugd->base);
389 static void __cal_ug_key_callback(ui_gadget_h ug, enum ug_key_event evt, service_h data, void *priv)
394 DBG("UG: key event %d", evt);
398 case UG_KEY_EVENT_END:
406 API int UG_MODULE_INIT(struct ug_module_ops *ops)
415 CAL_CALLOC(ugd, 1, struct ug_data);
417 ops->create = __cal_ug_create_callback;
418 ops->destroy = __cal_ug_destroy_callback;
419 ops->key_event = __cal_ug_key_callback;
421 ops->opt = UG_OPT_INDICATOR_ENABLE;
423 const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
424 c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
429 API void UG_MODULE_EXIT(struct ug_module_ops *ops)