3 Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
5 This file is part of org.tizen.efl-calendar
6 Written by Taeho Kang <taeho84.kang@samsung.com>
8 PROPRIETARY/CONFIDENTIAL
10 This software is the confidential and proprietary information of
11 SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
12 disclose such Confidential Information and shall use it only in
13 accordance with the terms of the license agreement you entered
14 into with SAMSUNG ELECTRONICS.
16 SAMSUNG make no representations or warranties about the suitability
17 of the software, either express or implied, including but not limited
18 to the implied warranties of merchantability, fitness for a particular
19 purpose, or non-infringement. SAMSUNG shall not be liable for any
20 damages suffered by licensee as a result of using, modifying or
21 distributing this software or its derivatives.
30 #include "edit-repeat.h"
31 #include "external-ug.h"
33 static const char *_name = NULL;
35 #define MONTH_CAL_CBAR_H 41
37 #define MONTH_CAL_Y 200
39 #define ANIMATION_TIME 0.2
41 #define INITIAL_FETCH_SIZE 4
42 #define IDLER_FETCH_SIZE 4
48 }focus_in_month_view_type;
54 Evas_Object *ly; // self
57 Evas_Object *month_left;
58 Evas_Object *month_right;
59 Evas_Coord_Rectangle rect;
60 Evas_Coord_Rectangle oringinal_size;
62 focus_in_month_view_type calendar_focus_view;
69 Evas_Coord_Point down1, down2;
73 Evas_Coord_Point move1, move2;
81 Evas_Coord_Rectangle pos_from;
82 Evas_Coord_Rectangle pos_to;
88 extern void cal_month_update_month_calendar(Evas_Object *ly, struct tm *t);
89 static Evas_Object *__cal_month_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part);
90 static char* __cal_month_get_genlist_item_label(void *data, Evas_Object *obj, const char *part);
91 static void __cal_month_mouse_move_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei);
92 static void __cal_month_update_genlist(cal_month_data *p);
93 static void __cal_month_changed_callback(void *data, Evas_Object *obj, const char *e, const char *src);
94 static void __cal_month_rendering_flush_callback(void *data, Evas *e, void *event_info);
96 static Elm_Genlist_Item_Class itc = {
97 .item_style = "3text.5icon",
98 .func.content_get = __cal_month_get_genlist_item_icon,
99 .func.text_get = __cal_month_get_genlist_item_label,
102 static int is_hour24;
103 static Calendar_color calendar_color;
105 static inline void __cal_month_stop_animation(cal_month_data *p)
108 ecore_animator_del(p->ani);
113 static void __cal_month_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
117 c_retm_if(!data, "data is null");
118 c_retm_if(!e, "e is null");
120 cal_month_data *p = data;
122 CALENDAR_SVC_FREE_CS(&p->csv);
124 __cal_month_stop_animation(p);
127 ecore_idler_del(p->idler);
129 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback);
136 static void __cal_month_resize_view(void *data, Evas *e, Evas_Object *ly, void *ei)
138 cal_month_data *p = data;
140 cal_util_get_geometry(&p->rect, p->month);
143 static void __cal_month_make_time_text(time_t t, struct tm *tm, char *buf, int sz)
149 localtime_r(&t, &ttm);
152 time = CAL_UTIL_TIME_FORMAT_6;
154 time = CAL_UTIL_TIME_FORMAT_1;
156 if (ttm.tm_year != tm->tm_year)
157 date = CAL_UTIL_DATE_FORMAT_11;
158 else if (ttm.tm_mon != tm->tm_mon)
159 date = CAL_UTIL_DATE_FORMAT_10;
160 else if (ttm.tm_mday != tm->tm_mday)
161 date = CAL_UTIL_DATE_FORMAT_9;
165 cal_util_get_time_text(buf, sz, NULL, time, &ttm);
168 static char* __cal_month_get_time_text(struct tmnode *tm, cal_month_data *p)
173 __cal_month_make_time_text(tm->st, &p->ad->base_tm, stime, sizeof(stime));
175 snprintf(buf, sizeof(buf), "%s", stime);
179 static Evas_Object *__cal_month_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
181 Evas_Object *icon = NULL;
182 struct tmnode *tm = (struct tmnode *)data;
184 cal_struct *cs = NULL;
185 cal_struct *calendar = NULL;
186 cal_month_data* p = NULL;
201 p = CAL_UTIL_GET_PRIV_DATA(obj);
203 if (!CAL_STRCMP(part, "elm.swallow.colorbar"))
205 r = CALENDAR_SVC_GET(CAL_STRUCT_CALENDAR, CALENDAR_SVC_STRUCT_GET_INT(cs,CAL_VALUE_INT_CALENDAR_ID), NULL, &calendar);
206 if (r != CAL_SUCCESS)
208 ERR("CALENDAR_SVC_GET fail. %d", r);
212 icon = evas_object_rectangle_add(evas_object_evas_get(obj));
213 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
215 CALENDAR_SVC_GET_CALENDAR_COLOR(calendar, &calendar_color);
217 evas_object_color_set(icon, calendar_color.red, calendar_color.green, calendar_color.blue, calendar_color.alpha);
219 CALENDAR_SVC_STRUCT_FREE(&calendar);
227 static char* __cal_month_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
230 struct tmnode *tm = (struct tmnode *)data;
236 if (!CAL_STRCMP(part, "elm.text.1"))
238 str = CALENDAR_SVC_STRUCT_GET_STR(tm->cs, CAL_VALUE_TXT_SUMMARY);
242 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
244 else if (!CAL_STRCMP(part, "elm.text.2"))
246 str = CALENDAR_SVC_STRUCT_GET_STR(tm->cs, CAL_VALUE_TXT_LOCATION);
250 return strdup(C_("IDS_CLD_BODY_NO_LOCATION_SELECTED"));
252 else if (!CAL_STRCMP(part, "elm.text.3"))
254 int allday = CALENDAR_SVC_STRUCT_GET_INT(tm->cs, CAL_VALUE_INT_ALL_DAY_EVENT);
256 return strdup(C_("IDS_COM_BODY_ALL_DAY"));
258 p = CAL_UTIL_GET_PRIV_DATA(obj);
259 return __cal_month_get_time_text(tm, p);
265 static void __cal_month_genlist_item_select_callback(void *data, Evas_Object *obj, void *ei)
267 struct tmnode* tm = data;
268 cal_struct *cs = tm->cs;
274 it = elm_genlist_selected_item_get(obj);
276 elm_genlist_item_selected_set(it, EINA_FALSE);
278 idx = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_INDEX);
280 p = CAL_UTIL_GET_PRIV_DATA(obj);
283 repeat = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_TERM);
286 memcpy(p->ad->tm, tm, sizeof(struct tmnode));
290 cal_detail_create_view(p->ad, p->parent);
293 static void __cal_month_get_events(cal_month_data *p)
297 cal_util_get_day_time_t(&p->ad->base_tm, &st, &et);
299 p->csv = CALENDAR_SVC_GET_EVENT(p->ad->acct_id, st, et);
302 static void __cal_month_update_genlist(cal_month_data *p)
304 c_retm_if(!p, "p is null");
311 CALENDAR_SVC_FREE_CS(&p->csv);
312 __cal_month_get_events(p);
314 if (!p->csv || !p->csv->tmlist || !eina_list_count(p->csv->tmlist))
317 elm_genlist_clear(p->gl);
324 gl = elm_genlist_add(p->ly);
328 elm_object_part_content_set(p->ly, "list/sw", gl);
329 evas_object_data_set(gl, "priv", p);
333 elm_genlist_clear(p->gl);
337 EINA_LIST_FOREACH(p->csv->tmlist, l, tm)
341 elm_genlist_item_append(p->gl, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
346 //First time, Just need to show 4 items. Another items will be add with idler
347 if (count == INITIAL_FETCH_SIZE)
353 static Eina_Bool __cal_month_update_genlist_with_idler(void* data)
357 c_retvm_if(!data, ECORE_CALLBACK_CANCEL, "data is null");
359 Eina_List *l, *event_list;
363 cal_month_data* p = data;
364 c_retvm_if(!p, ECORE_CALLBACK_CANCEL, "p is null");
368 ERR("p->gl is null");
370 return ECORE_CALLBACK_CANCEL;
375 ERR("p->csv is null");
377 return ECORE_CALLBACK_CANCEL;
380 event_list = eina_list_nth_list(p->csv->tmlist, p->event_offset);
382 EINA_LIST_FOREACH(event_list, l, tm)
386 elm_genlist_item_append(p->gl, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
391 if (count == IDLER_FETCH_SIZE && p->event_offset < eina_list_count(p->csv->tmlist))
392 return ECORE_CALLBACK_RENEW;
400 return ECORE_CALLBACK_CANCEL;
403 static Evas_Object* __cal_month_create_month_d(cal_month_data *p, int d)
406 struct appdata *ad = p->ad;
411 r = cal_util_update_tm_month(&t, d);
413 return cal_util_add_layout(p->ly, "rect/empty");
415 return cal_month_calendar_create_content(&t, ad, p->parent, EINA_TRUE);
418 static void __cal_month_move_month_calendar_to_left(cal_month_data *p, Evas_Coord x)
420 if (p->month_left == NULL) {
421 p->month_left = __cal_month_create_month_d(p, -1);
422 elm_object_part_content_set(p->ly, "cal/sw/left", p->month_left);
425 if(0 > p->oringinal_size.x)
427 evas_object_move(p->month_left, x, p->rect.y);
431 evas_object_move(p->month_left, x, p->oringinal_size.y);
435 static void __cal_month_move_month_calendar_to_right(cal_month_data *p, Evas_Coord x)
437 if (p->month_right == NULL) {
438 p->month_right = __cal_month_create_month_d(p, 1);
439 elm_object_part_content_set(p->ly, "cal/sw/right", p->month_right);
442 if(0 > p->oringinal_size.x)
444 evas_object_move(p->month_right, x, p->rect.y);
448 evas_object_move(p->month_right, x, p->oringinal_size.y);
453 static void __cal_month_move_month_calendar(cal_month_data *p)
458 dx = p->move1.x - p->down1.x;
459 if (!p->single_moved && dx < 15 && dx > -15)
462 if (!p->single_moved)
463 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->month), "moved", "prog");
467 if(0 > p->oringinal_size.x)
471 evas_object_move(p->month, x, p->rect.y);
473 __cal_month_move_month_calendar_to_left(p, x - p->rect.w);
474 __cal_month_move_month_calendar_to_right(p, x + p->rect.w);
478 x = p->oringinal_size.x + dx;
480 evas_object_move(p->month, x, p->oringinal_size.y);
482 __cal_month_move_month_calendar_to_left(p, x - p->oringinal_size.w);
483 __cal_month_move_month_calendar_to_right(p, x + p->oringinal_size.w);
487 static inline void __cal_month_move_objects(cal_month_data *p, Evas_Coord dx)
496 x = p->pos_from.x + dx;
498 evas_object_move(p->month, x, p->rect.y);
500 __cal_month_move_month_calendar_to_left(p, x - p->rect.w);
501 __cal_month_move_month_calendar_to_right(p, x + p->rect.w);
505 static inline int __cal_month_update_month_view(cal_month_data *p, int d)
511 r = cal_util_update_tm_month(&p->ad->base_tm, d);
515 edje_object_signal_callback_del(CAL_UTIL_GET_EDJ_DATA(p->month), "changed", "prog", __cal_month_changed_callback);
516 evas_object_event_callback_del(p->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback);
518 elm_object_part_content_unset(p->ly, "cal/sw");
519 elm_object_part_content_unset(p->ly, "cal/sw/left");
520 elm_object_part_content_unset(p->ly, "cal/sw/right");
524 evas_object_del(p->month_left);
525 p->month_left = p->month;
526 p->month = p->month_right;
527 p->month_right = __cal_month_create_month_d(p, 1);
531 evas_object_del(p->month_right);
532 p->month_right = p->month;
533 p->month = p->month_left;
534 p->month_left = __cal_month_create_month_d(p, -1);
539 CAL_ASSERT(EINA_FALSE);
542 cal_month_calendar_update_select(p->month);
543 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->ly), "go,line%d", cal_month_get_weekline(p->month));
545 elm_object_part_content_set(p->ly, "cal/sw", p->month);
546 elm_object_part_content_set(p->ly, "cal/sw/left", p->month_left);
547 elm_object_part_content_set(p->ly, "cal/sw/right", p->month_right);
549 evas_object_show(p->ly);
551 evas_object_event_callback_add(p->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback, p);
552 edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(p->month), "changed", "prog", __cal_month_changed_callback, p);
554 __cal_month_update_genlist(p);
560 static Eina_Bool __cal_month_animation(void *data)
562 cal_month_data *p = data;
566 elapsed_t = ecore_time_get() - p->ani_start;
567 if (elapsed_t > ANIMATION_TIME)
568 elapsed_t = ANIMATION_TIME;
570 dx = (p->pos_to.x - p->pos_from.x) * cal_util_nsin(elapsed_t / ANIMATION_TIME);
571 __cal_month_move_objects(p, dx);
573 if (elapsed_t == ANIMATION_TIME || dx == 0)
577 ecore_animator_del(p->ani);
583 __cal_month_update_month_view(p,p->d);
586 return ECORE_CALLBACK_CANCEL;
589 return ECORE_CALLBACK_RENEW;
592 static inline void __cal_month_start_animation(cal_month_data *p)
594 if (p->pos_from.x == p->pos_to.x)
598 p->ani = ecore_animator_add(__cal_month_animation, p);
599 p->ani_start = ecore_time_get();
603 static void __cal_month_mouse_up_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
606 cal_month_data *p = data;
609 struct appdata* ad = p->ad;
611 Evas_Event_Mouse_Up *ev = ei;
613 p->down_is_called = 0;
617 int dx = p->down1.x - ev->canvas.x;
627 cal_util_get_geometry(&p->pos_from,p->month);
630 if (dx > (p->rect.w >> 1))
635 p->pos_to.x = p->ad->win_w;
636 p->pos_to.y = p->pos_from.y;
637 p->pos_to.w = p->pos_from.w;
638 p->pos_to.h = p->pos_from.h;
643 p->pos_to.x = -(p->ad->win_w);
644 p->pos_to.y = p->pos_from.y;
645 p->pos_to.w = p->pos_from.w;
646 p->pos_to.h = p->pos_from.h;
648 __cal_month_start_animation(p);
652 __cal_month_move_month_calendar_to_left(p, MONTH_CAL_X - ad->win_w);
653 __cal_month_move_month_calendar_to_right(p, MONTH_CAL_X + ad->win_w);
654 evas_object_move(p->month, MONTH_CAL_X, p->pos_from.y);
662 static void __cal_month_mouse_down_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
664 cal_month_data *p = data;
665 Evas_Event_Mouse_Down *ev = ei;
667 p->down1.x = p->move1.x = ev->canvas.x;
668 p->down1.y = p->move1.y = ev->canvas.y;
670 p->down_is_called = 1;
672 cal_util_get_geometry(&p->oringinal_size,p->month);
675 static void __cal_month_mouse_move_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
677 cal_month_data *p = data;
678 Evas_Event_Mouse_Move *ev = ei;
680 if (0 == p->down_is_called)
683 p->move1.x = ev->cur.canvas.x;
684 p->move1.y = ev->cur.canvas.y;
686 if (!p->multi_touched)
687 __cal_month_move_month_calendar(p);
690 static void __cal_month_changed_callback(void *data, Evas_Object *obj, const char *e, const char *src)
692 __cal_month_update_genlist(data);
695 static void __cal_month_rendering_flush_callback(void *data, Evas *e, void *event_info)
699 c_retm_if(!data, "data is null");
700 c_retm_if(!e, "evas is null");
702 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback);
704 cal_month_data* p = data;
706 if (!p->gl || p->idler ||!p->csv || eina_list_count(p->csv->tmlist) == p->event_offset)
709 p->idler = ecore_idler_add(__cal_month_update_genlist_with_idler, p);
710 c_retm_if(!p->idler, "p->idler is null");
715 Evas_Object* cal_month_create_view(struct appdata *ad, Evas_Object *main)
719 c_retvm_if(!ad, NULL, "ad is null");
720 c_retvm_if(!main, NULL, "main is null");
725 Evas_Object *list_bg;
727 p = calloc(1, sizeof(cal_month_data));
728 c_retvm_if(!p, NULL, "calloc(1, sizeof(cal_month_data)) is failed");
730 vconf_get_int(CAL_VCONFKEY_FOCUS_VIEW, (int*)&p->calendar_focus_view);
732 if (FOCUS_IN_DAILY == p->calendar_focus_view)
734 ad->is_weekly = FALSE;
735 p->name = _name = "main/month";
737 else if (FOCUS_IN_WEEKLY == p->calendar_focus_view)
739 ad->is_weekly = TRUE;
740 p->name = _name = "main/month/weekly";
747 is_hour24 = ad->is_hour24;
750 p->oringinal_size.x = -1;
751 p->oringinal_size.y = -1;
752 p->oringinal_size.w = -1;
753 p->oringinal_size.h = -1;
754 ly = cal_util_add_layout(ad->nv, p->name);
759 evas_object_data_set(ly, "priv", p);
762 month = cal_month_calendar_create_content(&ad->base_tm, ad, main, EINA_FALSE);
765 ERR("cal_month_calendar_create_content(&ad->base_tm, ad, ly, EINA_FALSE) is failed");
771 elm_object_part_content_set(ly, "cal/sw", month);
773 edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(month), "changed", "prog", __cal_month_changed_callback, p);
775 list_bg = cal_util_add_bg(ly, EINA_FALSE);
778 ERR("cal_util_add_bg(ly, EINA_FALSE) is failed");
784 elm_object_part_content_set(ly, "list/base", list_bg);
786 evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_month_delete_layout, p);
787 evas_object_event_callback_add(ly, EVAS_CALLBACK_MOUSE_DOWN, __cal_month_mouse_down_event_callback, p);
788 evas_object_event_callback_add(ly, EVAS_CALLBACK_MOUSE_UP, __cal_month_mouse_up_event_callback, p);
789 evas_object_event_callback_add(month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback, p);
790 evas_object_event_callback_add(ly, EVAS_CALLBACK_RESIZE, __cal_month_resize_view, p);
797 void cal_month_update_view(Evas_Object *ly)
801 c_retm_if(!ly, "ly is null");
807 p = CAL_UTIL_GET_PRIV_DATA(ly);
808 if (!p || CAL_STRCMP(p->name, _name)) {
809 ERR("update month view: Invalid object");
814 c_retm_if(!ad, "ad is null");
816 cal_month_update_month_calendar(p->month, &ad->base_tm);
817 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->ly), "go,line%d", cal_month_get_weekline(p->month));
819 __cal_month_update_genlist(p);
821 cal_util_delete_evas_object(&p->month_left);
822 cal_util_delete_evas_object(&p->month_right);
824 e = evas_object_evas_get(ly);
825 c_retm_if(!e, "evas_object_evas_get(ly) is failed");
827 evas_event_callback_add(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback,p);