5 * Copyright 2012 Samsung Electronics Co., Ltd
7 * Licensed under the Flora License, Version 1.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://floralicense.org/license/
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
24 #include <ui-gadget.h>
27 #include "detail-view.h"
29 #define SERVICE_CALENDAR_VIEWER_CAL_ID_NAME "cal_id"
30 #define SERVICE_CALENDAR_VIEWER_MIME_NAME AUL_K_MIME_CONTENT
31 #define VCALENDAR_LABLE_STRING_LENGTH 128
33 #if !defined(CV_PACKAGE)
34 # define CV_PACKAGE "calendar-viewer"
41 Evas_Object *save_to_calendar;
42 int selected_item_count;
46 calendar_record_h record;
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, calendar_list_h list);
53 static void __cal_viewer_update_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(calendar_record_h record)
65 c_retv_if(!record, NULL);
67 char stime[512] = {0};
70 const char* time = CAL_UTIL_TIME_FORMAT_1;
72 calendar_time_s start_time = {0};
74 _calendar_get_start_time(record, &start_time);
76 cal_util_convert_lli_to_tm(NULL, start_time.time.utime, &tm);
78 cal_util_get_time_text(stime, sizeof(stime), NULL, time, &tm);
80 return g_strdup_printf("%s", stime);
83 static char *__cal_viewer_get_vcs_genlist_item_label(void *data, Evas_Object *obj, const char *part)
85 c_retvm_if(!data, NULL, "data is null");
86 c_retvm_if(!part, NULL, "part is null");
88 vcs_item_data *item_data = (vcs_item_data*)data;
89 c_retv_if(!item_data->record, NULL);
91 if (!CAL_STRCMP(part,"elm.text.1")) {
92 return _calendar_get_summary(item_data->record);
94 } else if (!CAL_STRCMP(part,"elm.text.2")) {
95 return _calendar_get_location(item_data->record);
97 } else if (!CAL_STRCMP(part, "elm.text.3")) {
99 return __cal_viewer_vcs_get_time_str(item_data->record);
105 static void __cal_viewer_update_small_info(cal_viewer_data *p, int count)
107 c_retm_if(!p, "p is null");
110 cal_util_hide_small_information(p->layout);
114 struct appdata *ad = p->ad;
115 c_retm_if(!ad, "ad is null");
117 Evas_Object *nv = ad->naviframe;
118 c_retm_if(!nv, "nv is null");
120 char lable_str[VCALENDAR_LABLE_STRING_LENGTH] = { '\0'};
122 snprintf(lable_str, sizeof(lable_str), "%s (%d)", S_("IDS_COM_POP_SELECTED"), count);
124 cal_util_show_small_information(p->layout, lable_str, 0.0);
127 static void __cal_viewer_vcs_check_changed_callback(void *data, Evas_Object *obj, void *event_info)
129 c_retm_if(!data, "data is null");
131 vcs_item_data *item_data= data;
133 Evas_Object *genlist = elm_object_parent_widget_get(obj);
134 c_retm_if(!genlist, "genlist is null");
136 cal_viewer_data *p = evas_object_data_get(genlist, "priv");
137 c_retm_if(!p, "p is null");
139 Eina_Bool checked = elm_check_state_get(obj);
141 p->selected_item_count++;
142 item_data->checked = EINA_TRUE;
144 p->selected_item_count--;
145 item_data->checked = EINA_FALSE;
148 if (0 < p->selected_item_count)
149 elm_object_disabled_set(p->save_to_calendar, EINA_FALSE);
151 elm_object_disabled_set(p->save_to_calendar, EINA_TRUE);
153 __cal_viewer_update_small_info(p, p->selected_item_count);
156 static Evas_Object* __cal_viewer_get_vcs_genlist_icon(void *item_data, Evas_Object *obj, const char *part)
158 c_retvm_if(!part, NULL, "part is null");
159 c_retvm_if(!obj, NULL, "obj is null");
160 c_retvm_if(!item_data, NULL, "data is null");
162 Evas_Object *icon = NULL;
163 vcs_item_data *item = item_data;
164 c_retvm_if(!item->record, NULL, "item->record is null");
166 if (!CAL_STRCMP(part, "elm.icon") ) {
167 icon = elm_check_add(obj);
168 c_retvm_if(!icon, NULL, "elm_check_add returned null");
170 elm_check_state_pointer_set(icon, &item->checked);
171 evas_object_smart_callback_add(icon, "changed", __cal_viewer_vcs_check_changed_callback, item);
172 evas_object_propagate_events_set(icon, EINA_FALSE);
179 static bool viewer_create(void *data)
181 struct appdata *ad = data;
186 calendar_error_e error = CALENDAR_ERROR_NONE;
188 error = calendar_connect();
189 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_connect() is failed(%x)", error);
191 _calendar_init_hash();
193 elm_theme_extension_add(NULL, "/usr/apps/"CALENDAR_PACKAGE"/res/edje/theme.edj");
196 win = cal_util_add_window(CV_PACKAGE, NULL, NULL);
197 c_retvm_if(!win, false, "cal_util_add_window() Failed");
200 bg = cal_util_add_bg(win, EINA_TRUE);
201 c_retvm_if(NULL == bg, false, "cal_util_add_bg() Failed");
203 Evas_Object *conformant = elm_conformant_add(win);
204 c_retv_if(!conformant, false);
206 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
207 elm_win_resize_object_add(win, conformant);
208 evas_object_show(conformant);
210 Evas_Object *base_layout = elm_layout_add(conformant);
211 c_retv_if(!base_layout, false);
213 Eina_Bool r = elm_layout_theme_set(base_layout, "layout", "application", "default");
214 c_warn_if(!r, "elm_layout_theme_set is failed");
216 evas_object_size_hint_weight_set(base_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
218 elm_object_content_set(conformant, base_layout);
220 ad->base = base_layout;
222 nv = elm_naviframe_add(ad->base);
223 c_retvm_if(NULL == win, false, "elm_naviframe_add() Failed");
225 elm_object_part_content_set(ad->base, "elm.swallow.content", ad->naviframe);
227 const char *path = bindtextdomain(CALENDAR, LOCALEDIR);
228 c_warn_if(!path, "bindtextdomain(%s, %s) is failed.", CALENDAR, LOCALEDIR);
230 cal_util_connect_pattern_generator();
232 evas_object_show(win);
234 UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_PORTRAIT_ONLY);
239 static void viewer_terminate(void *data)
241 struct appdata *ad = data;
243 cal_util_disconnect_pattern_generator();
248 evas_object_del(ad->win);
250 calendar_error_e error = CALENDAR_ERROR_NONE;
252 error = calendar_disconnect();
253 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_disconnect() is failed(%x)", error);
258 static void viewer_pause(void *data)
265 static void viewer_resume(void *data)
272 static void viewer_service(service_h service, void *data)
274 c_retm_if(!service, "service is null.");
275 c_retm_if(!data, "data is null.");
279 char *operation = NULL;
280 char *val_cal_id = NULL;
281 char *val_ical = NULL;
282 struct appdata *ad = data;
284 if (NULL == ad->win) {
290 r = service_get_extra_data(service, SERVICE_CALENDAR_VIEWER_CAL_ID_NAME, &val_cal_id);
291 c_warn_if(SERVICE_ERROR_NONE != r, "service_get_extra_data is failed(%d).", r);
293 if (val_cal_id && *val_cal_id) {
294 cal_id = atoi(val_cal_id);
296 ERR("bundle value(cal_id) is wrong(%d)", cal_id);
301 calendar_record_h record = _calendar_get_record_with_index(cal_id);
303 cal_detail_create_view(ad, record, NULL, NULL);
309 r = service_get_operation(service, &operation);
310 c_retm_if(SERVICE_ERROR_NONE != r, "service_get_operation is failed.");
312 r = service_get_uri(service, &val_ical);
313 c_retm_if(SERVICE_ERROR_NONE != r, "service_get_uri is failed.");
315 /*MIME CONTENT FOR VCS*/
317 char *raw_data = NULL;
321 FILE * file = fopen(val_ical, "r");
324 ERR("Failed to open file!");
328 if(stat(val_ical, &st) != 0) {
330 ERR("stat() is failed!");
336 CAL_CALLOC(raw_data, (size+1), char);
337 CAL_ASSERT(raw_data);
338 memset(raw_data,0,(size+1));
340 r = fread(raw_data, 1, size, file);
343 ERR("Failed to read file!");
349 ad->is_aul = EINA_TRUE;
350 ad->request_view = CV_DETAIL;
352 calendar_error_e error = CALENDAR_ERROR_NONE;
354 calendar_list_h list = NULL;
356 error = calendar_vcalendar_parse_to_calendar(raw_data, &list);
357 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_vcalendar_parse_to_calendar() is failed(%x)", error);
359 __cal_viewer_create_view(ad, ad->naviframe, list);
361 error = calendar_list_destroy(list, false);
362 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
369 ERR("bundle value is NULL");
375 elm_win_activate(ad->win);
379 static void __cal_viewer_genlist_select_callback(void *data, Evas_Object *obj, void *event_info)
381 c_retm_if(!data, "data is null");
383 vcs_item_data *item = data;
384 c_retm_if(!item->record, "__cal_viewer_genlist_sel param error");
386 cal_viewer_data *p = evas_object_data_get(obj, "priv");
387 c_retm_if(!p || !p->ad, "p is null");
389 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
391 cal_detail_create_view(p->ad, item->record, NULL, NULL);
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;
404 it = elm_genlist_first_item_get(p->genlist);
406 int saved_item_count = 0;
409 item = elm_object_item_data_get(it);
410 temp = elm_genlist_item_next_get(it);
416 if (item && item->record && EINA_TRUE == item->checked) {
417 calendar_error_e error = CALENDAR_ERROR_NONE;
419 error = calendar_db_insert_record(item->record, NULL);
420 if (error == CALENDAR_ERROR_NONE)
423 ERR("calendar_db_insert_record() is failed(%x)", error);
430 static void __cal_viewer_back_button_callback(void *data, Evas_Object *obj, void *ei)
434 cal_viewer_data *p = data;
435 c_retm_if(!p || !p->genlist, "p is null");
437 elm_genlist_clear(p->genlist);
441 static void __cal_viewer_create_view(struct appdata *ad, Evas_Object *parent, calendar_list_h list)
445 c_retm_if(!ad || !parent || !list, "Input parameter is null");
447 cal_viewer_data *p = calloc(1, sizeof(cal_viewer_data));
448 c_retm_if(!p, "calloc is null");
452 Evas_Object *layout = cal_util_add_layout(parent, "selectioninfo");
454 ERR("layout is NULL!");
461 Evas_Object *genlist = elm_genlist_add(layout);
463 ERR("genlist is NULL!");
464 evas_object_del(p->layout);
469 elm_object_part_content_set(layout, "gen.swallow.contents", genlist);
471 Evas_Object *back_button;
472 Elm_Object_Item* navi_item;
477 calendar_error_e error = CALENDAR_ERROR_NONE;
479 error = calendar_list_get_count(list, &count);
480 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
482 error = calendar_list_first(list);
483 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
485 calendar_record_h record = NULL;
487 for (i = 0; i < count; i++) {
488 error = calendar_list_get_current_record_p(list, &record);
489 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
491 vcs_item_data *item_data = calloc(1, sizeof(vcs_item_data));
494 ERR("calloc is null!");
499 item_data->checked = EINA_FALSE;
500 item_data->record = record;
501 elm_genlist_item_append(genlist, &itc_3text_1icon_2, item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_viewer_genlist_select_callback, item_data);
503 calendar_list_next(list);
506 evas_object_data_set(genlist, "priv", p);
507 p->genlist = genlist;
510 navi_item = elm_naviframe_item_push(ad->naviframe, _("VCS Viewer"), NULL, NULL, layout, NULL);
512 ERR("elm_naviframe_item_push is failed");
513 evas_object_del(genlist);
517 p->save_to_calendar = cal_util_add_toolbar_button(ad->naviframe, "toolbar_button1", S_("IDS_COM_OPT_SAVE"), __cal_viewer_save_to_calendar_button_callback, p);
518 elm_object_disabled_set(p->save_to_calendar, EINA_TRUE);
520 back_button = elm_object_item_part_content_get(navi_item, "prev_btn");
522 back_button = elm_button_add(ad->naviframe);
523 c_retm_if(!back_button, "elm_button_add is failed.");
525 elm_object_style_set(back_button, "naviframe/back_btn/default");
526 elm_object_item_part_content_set(navi_item, "prev_btn", back_button);
528 elm_object_style_set(back_button, "naviframe/back_btn/default");
529 evas_object_smart_callback_add(back_button, "clicked", __cal_viewer_back_button_callback, p);
532 API int main(int argc, char *argv[])
536 app_event_callback_s event_callback;
538 event_callback.create = viewer_create;
539 event_callback.terminate = viewer_terminate;
540 event_callback.pause = viewer_pause;
541 event_callback.resume = viewer_resume;
542 event_callback.service = viewer_service;
543 event_callback.low_memory = NULL;
544 event_callback.low_battery = NULL;
545 event_callback.device_orientation = NULL;
546 event_callback.language_changed = NULL;
547 event_callback.region_format_changed = NULL;
549 memset(&ad, 0x0, sizeof(struct appdata));
551 return app_efl_main(&argc, &argv, &event_callback, &ad);