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.
20 #include <appcore-efl.h>
23 #include <ui-gadget.h>
28 #define SERVICE_CALENDAR_VIEWER_CAL_ID_NAME "cal_id"
29 #define SERVICE_CALENDAR_VIEWER_MIME_NAME AUL_K_MIME_CONTENT
30 #define VCALENDAR_LABLE_STRING_LENGTH 128
32 #if !defined(CV_PACKAGE)
33 # define CV_PACKAGE "calendar-viewer"
38 unsigned int check_num;
41 Evas_Object *notify_layout;
42 Elm_Object_Item *save_to_calendar;
50 static char *__cal_viewer_get_vcs_genlist_item_label(void *data, Evas_Object *obj, const char *part);
51 static Evas_Object* __cal_viewer_get_vcs_genlist_icon(void *item_data, Evas_Object *obj, const char *part);
52 static void __cal_viewer_create_view(struct appdata *ad, Evas_Object *parent, GList *glist);
53 static void __cal_viewer_show_small_info(cal_viewer_data *p, int count);
55 static Elm_Genlist_Item_Class itc_3text_1icon_2 = {
56 .item_style = "3text.1icon.2",
57 .func.text_get = __cal_viewer_get_vcs_genlist_item_label,
58 .func.content_get = __cal_viewer_get_vcs_genlist_icon,
60 .decorate_all_item_style = "edit_default",
63 static char* __cal_viewer_vcs_get_time_str(cal_struct *cs)
65 c_retvm_if(!cs, NULL, "cs is null");
71 const char* time = CAL_UTIL_TIME_FORMAT_1;
73 cal_util_convert_lli_to_tm(NULL, CALENDAR_SVC_STRUCT_GET_LLI(cs, CALS_VALUE_LLI_DTSTART_UTIME), &tm);
75 cal_util_get_time_text(stime, sizeof(stime), NULL, time, &tm);
76 snprintf(buf, sizeof(buf), "%s", stime);
81 static char *__cal_viewer_get_vcs_genlist_item_label(void *data, Evas_Object *obj, const char *part)
83 c_retvm_if(!data, NULL, "data is null");
84 c_retvm_if(!part, NULL, "part is null");
86 vcs_item_data *item_data = (vcs_item_data*)data;
87 c_retvm_if(!item_data->cs, NULL, "part is null");
89 const char *name = NULL;
91 if (!CAL_STRCMP(part,"elm.text.1")) {
92 name = CALENDAR_SVC_STRUCT_GET_STR(item_data->cs, CAL_VALUE_TXT_SUMMARY);
96 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
97 } else if (!CAL_STRCMP(part,"elm.text.2")) {
98 name = CALENDAR_SVC_STRUCT_GET_STR(item_data->cs, CAL_VALUE_TXT_LOCATION);
102 return strdup(C_("IDS_CLD_BODY_NO_LOCATION_SELECTED"));
103 } else if (!CAL_STRCMP(part, "elm.text.3")) {
104 char *name = __cal_viewer_vcs_get_time_str(item_data->cs);
111 static void __cal_viewer_show_small_info(cal_viewer_data *p, int count)
113 c_retm_if(!p, "p is null");
116 struct appdata *ad = p->ad;
117 c_retm_if(!ad, "ad is null");
119 Evas_Object *nv = ad->nv;
120 c_retm_if(!nv, "nv is null");
122 Evas_Object *notify = NULL;
123 Evas_Object *notify_layout = NULL;
125 char lable_str[VCALENDAR_LABLE_STRING_LENGTH] = { '\0'};
128 notify = elm_notify_add(nv);
129 c_retm_if(!notify, "notify is null");
131 elm_notify_orient_set(notify, ELM_NOTIFY_ORIENT_BOTTOM);
134 notify_layout = elm_layout_add(notify);
135 if (!notify_layout) {
136 evas_object_del(p->notify);
141 p->notify_layout = notify_layout;
142 elm_layout_theme_set(notify_layout, "standard", "selectioninfo", "vertical/bottom_64");
143 elm_object_content_set(notify, notify_layout);
145 snprintf(lable_str, sizeof(lable_str), "%s (%d)", S_("IDS_COM_POP_SELECTED"), count);
146 edje_object_part_text_set(CAL_UTIL_GET_EDJ_DATA(p->notify_layout), "elm.text", lable_str);
149 evas_object_show(p->notify);
151 evas_object_hide(p->notify);
155 static void __cal_viewer_vcs_check_changed_callback(void *data, Evas_Object *obj, void *event_info)
157 c_retm_if(!data, "data is null");
159 vcs_item_data *item_data= data;
161 Evas_Object *genlist = elm_object_parent_widget_get(obj);
162 c_retm_if(!genlist, "genlist is null");
164 cal_viewer_data *p = evas_object_data_get(genlist, "priv");
165 c_retm_if(!p, "p is null");
167 Eina_Bool checked = elm_check_state_get(obj);
170 item_data->checked = EINA_TRUE;
173 item_data->checked = EINA_FALSE;
176 if (0 < p->check_num)
177 elm_object_item_disabled_set(p->save_to_calendar, EINA_FALSE);
179 elm_object_item_disabled_set(p->save_to_calendar, EINA_TRUE);
181 __cal_viewer_show_small_info(p, p->check_num);
184 static Evas_Object* __cal_viewer_get_vcs_genlist_icon(void *item_data, Evas_Object *obj, const char *part)
186 c_retvm_if(!part, NULL, "part is null");
187 c_retvm_if(!obj, NULL, "obj is null");
188 c_retvm_if(!item_data, NULL, "data is null");
190 Evas_Object *icon = NULL;
191 vcs_item_data *item = item_data;
192 c_retvm_if(!item->cs, NULL, "item->cs is null");
194 if (!CAL_STRCMP(part, "elm.icon") ) {
195 icon = elm_check_add(obj);
196 c_retvm_if(!icon, NULL, "elm_check_add returned null");
198 elm_check_state_pointer_set(icon, &item->checked);
199 evas_object_smart_callback_add(icon, "changed", __cal_viewer_vcs_check_changed_callback, item);
200 evas_object_propagate_events_set(icon, EINA_FALSE);
207 static bool viewer_create(void *data)
209 struct appdata *ad = data;
216 CALENDAR_SVC_CONNECT();
219 win = cal_util_add_window(CV_PACKAGE, NULL, NULL);
220 c_retvm_if(!win, false, "cal_util_add_window() Failed");
223 bg = cal_util_add_bg(win, EINA_TRUE);
224 c_retvm_if(NULL == bg, false, "cal_util_add_bg() Failed");
226 ly = cal_util_add_layout(win, NULL);
228 elm_win_resize_object_add(win, ly);
232 nv = elm_naviframe_add(ad->win);
233 c_retvm_if(NULL == win, false, "elm_naviframe_add() Failed");
235 elm_object_part_content_set(ad->base, "elm.swallow.content", ad->nv);
237 /* init internationalization */
238 r = appcore_set_i18n(CALENDAR, LOCALEDIR);
239 c_retvm_if(r, false, "appcore_set_i18n() Failed");
241 cal_util_connect_pattern_generator();
243 evas_object_show(win);
245 UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_PORTRAIT_ONLY);
250 static void viewer_terminate(void *data)
253 struct appdata *ad = data;
255 cal_util_disconnect_pattern_generator();
260 evas_object_del(ad->win);
262 ret = CALENDAR_SVC_DISCONNECT();
263 c_warn_if(ret != CAL_SUCCESS, "CALENDAR_SVC_DISCONNECT() Failed(%d)", ret);
268 static void viewer_pause(void *data)
275 static void viewer_resume(void *data)
282 static void viewer_service(service_h service, void *data)
284 c_retm_if(!service, "service is null.");
285 c_retm_if(!data, "data is null.");
289 char *operation = NULL;
290 char *val_cal_id = NULL;
291 char *val_ical = NULL;
292 struct appdata *ad = data;
294 if (NULL == ad->win) {
300 r = service_get_extra_data(service, SERVICE_CALENDAR_VIEWER_CAL_ID_NAME, &val_cal_id);
301 c_warn_if(SERVICE_ERROR_NONE != r, "service_get_extra_data is failed(%d).", r);
303 if (val_cal_id && *val_cal_id) {
304 cal_id = atoi(val_cal_id);
306 ERR("bundle value(cal_id) is wrong(%d)", cal_id);
310 cal_detail_create_view(ad, ad->nv);
316 r = service_get_operation(service, &operation);
317 c_retm_if(SERVICE_ERROR_NONE != r, "service_get_operation is failed.");
319 r = service_get_uri(service, &val_ical);
320 c_retm_if(SERVICE_ERROR_NONE != r, "service_get_uri is failed.");
322 /*MIME CONTENT FOR VCS*/
324 char *raw_data = NULL;
328 FILE * file = fopen(val_ical, "r");
331 ERR("Failed to open file!");
337 CAL_CALLOC(raw_data, (size+1), char);
338 CAL_ASSERT(raw_data);
339 memset(raw_data,0,(size+1));
341 r = fread(raw_data, 1, size, file);
344 ERR("Failed to read file!");
350 ad->is_aul = EINA_TRUE;
351 ad->request_view = CV_DETAIL;
353 GList *schedules = NULL;
354 int r = CALENDAR_SVC_READ_SCHEDULES(raw_data, &schedules);
355 if (r != CAL_SUCCESS || NULL == schedules) {
356 ERR("CALENDAR_SVC_READ_SCHEDULES fail. : %d", r);
360 __cal_viewer_create_view(ad, ad->nv, schedules);
367 ERR("bundle value is NULL");
373 elm_win_activate(ad->win);
377 static void __cal_viewer_genlist_select_callback(void *data, Evas_Object *obj, void *event_info)
379 c_retm_if(!data, "data is null");
381 vcs_item_data *item = data;
382 c_retm_if(!item->cs, "__cal_viewer_genlist_sel param error");
384 cal_viewer_data *p = evas_object_data_get(obj, "priv");
385 c_retm_if(!p || !p->ad, "p is null");
388 evas_object_hide(p->notify);
390 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
391 cal_detail_create_viewer(p->ad, p->ad->nv, item->cs);
394 static void __cal_viewer_save_to_calendar_button_callback(void *data, Evas_Object *obj, void *ei)
398 cal_viewer_data *p = data;
399 c_retm_if(!p, "p is null");
401 Elm_Object_Item *it = NULL;
402 Elm_Object_Item *temp = NULL;
403 vcs_item_data *item = NULL;
405 it = elm_genlist_first_item_get(p->genlist);
407 item = elm_object_item_data_get(it);
408 temp = elm_genlist_item_next_get(it);
414 if (item && item->cs && EINA_TRUE == item->checked) {
415 r = CALENDAR_SVC_INSERT(item->cs);
416 if (CAL_SUCCESS != r) {
417 ERR("Calendar service delete failed: %d", r);
424 static void __cal_viewer_back_button_callback(void *data, Evas_Object *obj, void *ei)
428 cal_viewer_data *p = data;
429 c_retm_if(!p || !p->genlist, "p is null");
431 elm_genlist_clear(p->genlist);
435 static void __cal_viewer_create_view(struct appdata *ad, Evas_Object *parent, GList *glist)
439 c_retm_if(!ad || !parent || !glist, "Input parameter is null");
441 cal_viewer_data *p = calloc(1, sizeof(cal_viewer_data));
442 c_retm_if(!p, "calloc is null");
446 Evas_Object *genlist = elm_genlist_add(parent);
447 c_retm_if(!genlist, "genlist is null");
449 Evas_Object *back_button;
450 Elm_Object_Item* navi_item;
451 cal_struct *cs = NULL;
455 ERR("Not cal struct\n");
458 vcs_item_data *item_data = calloc(1, sizeof(vcs_item_data));
459 c_retm_if(!item_data, "calloc is null");
461 item_data->checked = EINA_FALSE;
463 elm_genlist_item_append(genlist, &itc_3text_1icon_2, item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_viewer_genlist_select_callback, item_data);
464 glist = g_list_next(glist);
466 evas_object_data_set(genlist, "priv", p);
467 p->genlist = genlist;
470 navi_item = elm_naviframe_item_push(ad->nv, _("VCS Viewer"), NULL, NULL, genlist, NULL);
472 ERR("elm_naviframe_item_push is failed");
473 evas_object_del(genlist);
477 Evas_Object *controlbar = cal_util_add_controlbar(ad->nv);
479 ERR("cal_util_add_controlbar(ad->nv) is failed");
480 elm_naviframe_item_pop(ad->nv);
484 p->save_to_calendar = elm_toolbar_item_append(controlbar, NULL, S_("IDS_COM_OPT_SAVE"), __cal_viewer_save_to_calendar_button_callback, p);
485 elm_object_item_disabled_set(p->save_to_calendar, EINA_TRUE);
486 elm_object_item_part_content_set(navi_item, "controlbar", controlbar);
488 back_button = elm_object_item_part_content_get(navi_item, "prev_btn");
490 back_button = elm_button_add(ad->nv);
491 c_retm_if(!back_button, "elm_button_add is failed.");
493 elm_object_style_set(back_button, "naviframe/back_btn/default");
494 elm_object_item_part_content_set(navi_item, "prev_btn", back_button);
496 elm_object_style_set(back_button, "naviframe/back_btn/default");
497 evas_object_smart_callback_add(back_button, "clicked", __cal_viewer_back_button_callback, p);
500 API int main(int argc, char *argv[])
504 app_event_callback_s event_callback;
506 event_callback.create = viewer_create;
507 event_callback.terminate = viewer_terminate;
508 event_callback.pause = viewer_pause;
509 event_callback.resume = viewer_resume;
510 event_callback.service = viewer_service;
511 event_callback.low_memory = NULL;
512 event_callback.low_battery = NULL;
513 event_callback.device_orientation = NULL;
514 event_callback.language_changed = NULL;
515 event_callback.region_format_changed = NULL;
517 memset(&ad, 0x0, sizeof(struct appdata));
519 return app_efl_main(&argc, &argv, &event_callback, &ad);