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);
95 static Elm_Genlist_Item_Class itc = {
96 .item_style = "3text.5icon",
97 .func.content_get = __cal_month_get_genlist_item_icon,
98 .func.text_get = __cal_month_get_genlist_item_label,
101 static int is_hour24;
102 static Calendar_color calendar_color;
104 static inline void __cal_month_stop_animation(cal_month_data *p)
107 ecore_animator_del(p->ani);
112 static void __cal_month_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
116 c_retm_if(!data, "data is null");
117 c_retm_if(!e, "e is null");
119 cal_month_data *p = data;
121 CALENDAR_SVC_FREE_CS(&p->csv);
123 __cal_month_stop_animation(p);
126 ecore_idler_del(p->idler);
131 static void __cal_month_resize_view(void *data, Evas *e, Evas_Object *ly, void *ei)
133 cal_month_data *p = data;
135 cal_util_get_geometry(&p->rect, p->month);
138 static void __cal_month_make_time_text(time_t t, struct tm *tm, char *buf, int sz)
144 localtime_r(&t, &ttm);
147 time = CAL_UTIL_TIME_FORMAT_6;
149 time = CAL_UTIL_TIME_FORMAT_1;
151 if (ttm.tm_year != tm->tm_year)
152 date = CAL_UTIL_DATE_FORMAT_11;
153 else if (ttm.tm_mon != tm->tm_mon)
154 date = CAL_UTIL_DATE_FORMAT_10;
155 else if (ttm.tm_mday != tm->tm_mday)
156 date = CAL_UTIL_DATE_FORMAT_9;
160 cal_util_get_time_text(buf, sz, NULL, time, &ttm);
163 static char* __cal_month_get_time_text(struct tmnode *tm, cal_month_data *p)
168 __cal_month_make_time_text(tm->st, &p->ad->base_tm, stime, sizeof(stime));
170 snprintf(buf, sizeof(buf), "%s", stime);
174 static Evas_Object *__cal_month_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
176 Evas_Object *icon = NULL;
177 struct tmnode *tm = (struct tmnode *)data;
179 cal_struct *cs = NULL;
180 cal_struct *calendar = NULL;
181 cal_month_data* p = NULL;
196 p = CAL_UTIL_GET_PRIV_DATA(obj);
198 if (!CAL_STRCMP(part, "elm.swallow.colorbar"))
200 r = CALENDAR_SVC_GET(CAL_STRUCT_CALENDAR, CALENDAR_SVC_STRUCT_GET_INT(cs,CAL_VALUE_INT_CALENDAR_ID), NULL, &calendar);
201 if (r != CAL_SUCCESS)
203 ERR("CALENDAR_SVC_GET fail. %d", r);
207 icon = evas_object_rectangle_add(evas_object_evas_get(obj));
208 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
210 CALENDAR_SVC_GET_CALENDAR_COLOR(calendar, &calendar_color);
212 evas_object_color_set(icon, calendar_color.red, calendar_color.green, calendar_color.blue, calendar_color.alpha);
214 CALENDAR_SVC_STRUCT_FREE(&calendar);
222 static char* __cal_month_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
225 struct tmnode *tm = (struct tmnode *)data;
231 if (!CAL_STRCMP(part, "elm.text.1"))
233 str = CALENDAR_SVC_STRUCT_GET_STR(tm->cs, CAL_VALUE_TXT_SUMMARY);
237 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
239 else if (!CAL_STRCMP(part, "elm.text.2"))
241 str = CALENDAR_SVC_STRUCT_GET_STR(tm->cs, CAL_VALUE_TXT_LOCATION);
245 return strdup(C_("IDS_CLD_BODY_NO_LOCATION_SELECTED"));
247 else if (!CAL_STRCMP(part, "elm.text.3"))
249 int allday = CALENDAR_SVC_STRUCT_GET_INT(tm->cs, CAL_VALUE_INT_ALL_DAY_EVENT);
251 return strdup(C_("IDS_COM_BODY_ALL_DAY"));
253 p = CAL_UTIL_GET_PRIV_DATA(obj);
254 return __cal_month_get_time_text(tm, p);
260 static void __cal_month_genlist_item_select_callback(void *data, Evas_Object *obj, void *ei)
262 struct tmnode* tm = data;
263 cal_struct *cs = tm->cs;
269 it = elm_genlist_selected_item_get(obj);
271 elm_genlist_item_selected_set(it, EINA_FALSE);
273 idx = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_INDEX);
275 p = CAL_UTIL_GET_PRIV_DATA(obj);
278 repeat = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_TERM);
281 memcpy(p->ad->tm, tm, sizeof(struct tmnode));
285 cal_detail_create_view(p->ad, p->parent);
288 static void __cal_month_get_events(cal_month_data *p)
292 cal_util_get_day_time_t(&p->ad->base_tm, &st, &et);
294 p->csv = CALENDAR_SVC_GET_EVENT(p->ad->acct_id, st, et);
299 static Eina_Bool __cal_month_update_genlist_with_idler(void* data)
303 c_retvm_if(!data, ECORE_CALLBACK_CANCEL, "data is null");
305 cal_month_data* p = data;
308 ERR("p->genlist is null");
310 return ECORE_CALLBACK_CANCEL;
314 ERR("p->csv is null");
316 return ECORE_CALLBACK_CANCEL;
319 Eina_List *event_list = eina_list_nth_list(p->csv->tmlist, p->event_offset);
322 struct tmnode *tm = NULL;
325 EINA_LIST_FOREACH(event_list, l, tm) {
327 elm_genlist_item_append(p->genlist, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
332 if (count == IDLER_FETCH_SIZE && p->event_offset < eina_list_count(p->csv->tmlist))
333 return ECORE_CALLBACK_RENEW;
341 return ECORE_CALLBACK_CANCEL;
344 static void __cal_month_update_genlist(cal_month_data *p)
348 c_retm_if(!p, "p is null");
350 Evas_Object* genlist = p->genlist;
352 CALENDAR_SVC_FREE_CS(&p->csv);
354 __cal_month_get_events(p);
356 if (!p->csv || !p->csv->tmlist || !eina_list_count(p->csv->tmlist)) {
358 elm_genlist_clear(genlist);
366 genlist = elm_genlist_add(p->ly);
367 c_retm_if(!genlist, "gl is null");
369 p->genlist = genlist;
371 elm_object_part_content_set(p->ly, "list/sw", genlist);
372 evas_object_data_set(genlist, "priv", p);
375 elm_genlist_clear(genlist);
380 struct tmnode *tm = NULL;
383 EINA_LIST_FOREACH(p->csv->tmlist, l, tm) {
385 elm_genlist_item_append(genlist, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
390 //First time, Just need to show 4 items. Another items will be add with idler
391 if (count == INITIAL_FETCH_SIZE) {
392 if (INITIAL_FETCH_SIZE < eina_list_count(p->csv->tmlist)) {
393 p->idler = ecore_idler_add(__cal_month_update_genlist_with_idler, p);
394 c_retm_if(!p->idler, "p->idler is null");
407 static Evas_Object* __cal_month_create_month_d(cal_month_data *p, int d)
410 struct appdata *ad = p->ad;
415 r = cal_util_update_tm_month(&t, d);
416 c_retvm_if(r < 0, NULL, "month cross the border ");
418 return cal_month_calendar_create_content(&t, ad, p->parent, EINA_TRUE);
421 static void __cal_month_move_month_calendar_to_left(cal_month_data *p, Evas_Coord x)
423 if (p->month_left == NULL) {
424 p->month_left = __cal_month_create_month_d(p, -1);
425 elm_object_part_content_set(p->ly, "cal/sw/left", p->month_left);
428 if(0 > p->oringinal_size.x)
430 evas_object_move(p->month_left, x, p->rect.y);
434 evas_object_move(p->month_left, x, p->oringinal_size.y);
438 static void __cal_month_move_month_calendar_to_right(cal_month_data *p, Evas_Coord x)
440 if (p->month_right == NULL) {
441 p->month_right = __cal_month_create_month_d(p, 1);
442 elm_object_part_content_set(p->ly, "cal/sw/right", p->month_right);
445 if(0 > p->oringinal_size.x)
447 evas_object_move(p->month_right, x, p->rect.y);
451 evas_object_move(p->month_right, x, p->oringinal_size.y);
456 static void __cal_month_move_month_calendar(cal_month_data *p)
460 Evas_Coord dx = p->move1.x - p->down1.x;
461 if (!p->single_moved && dx < 15 && dx > -15)
464 if (!p->single_moved)
465 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->month), "moved", "prog");
469 struct appdata *ad = p->ad;
470 c_retm_if(!ad, "ad is null");
478 r = cal_util_update_tm_month(&t, -1);
485 r = cal_util_update_tm_month(&t, 1);
490 if (p->oringinal_size.x < 0) {
493 evas_object_move(p->month, x, p->rect.y);
495 __cal_month_move_month_calendar_to_left(p, x - p->rect.w);
496 __cal_month_move_month_calendar_to_right(p, x + p->rect.w);
500 x = p->oringinal_size.x + dx;
502 evas_object_move(p->month, x, p->oringinal_size.y);
504 __cal_month_move_month_calendar_to_left(p, x - p->oringinal_size.w);
505 __cal_month_move_month_calendar_to_right(p, x + p->oringinal_size.w);
509 static inline void __cal_month_move_objects(cal_month_data *p, Evas_Coord dx)
516 struct appdata *ad = p->ad;
517 c_retm_if(!ad, "ad is null");
525 r = cal_util_update_tm_month(&t, -1);
531 r = cal_util_update_tm_month(&t, 1);
535 Evas_Coord x = p->pos_from.x + dx;
537 evas_object_move(p->month, x, p->rect.y);
539 __cal_month_move_month_calendar_to_left(p, x - p->rect.w);
540 __cal_month_move_month_calendar_to_right(p, x + p->rect.w);
544 static inline int __cal_month_update_month_view(cal_month_data *p, int d)
550 r = cal_util_update_tm_month(&p->ad->base_tm, d);
554 edje_object_signal_callback_del(CAL_UTIL_GET_EDJ_DATA(p->month), "changed", "prog", __cal_month_changed_callback);
555 evas_object_event_callback_del(p->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback);
557 elm_object_part_content_unset(p->ly, "cal/sw");
558 elm_object_part_content_unset(p->ly, "cal/sw/left");
559 elm_object_part_content_unset(p->ly, "cal/sw/right");
563 evas_object_del(p->month_left);
564 p->month_left = p->month;
565 p->month = p->month_right;
566 p->month_right = __cal_month_create_month_d(p, 1);
570 evas_object_del(p->month_right);
571 p->month_right = p->month;
572 p->month = p->month_left;
573 p->month_left = __cal_month_create_month_d(p, -1);
578 CAL_ASSERT(EINA_FALSE);
581 cal_month_calendar_update_select(p->month);
582 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->ly), "go,line%d", cal_month_get_weekline(p->month));
584 elm_object_part_content_set(p->ly, "cal/sw", p->month);
585 elm_object_part_content_set(p->ly, "cal/sw/left", p->month_left);
586 elm_object_part_content_set(p->ly, "cal/sw/right", p->month_right);
588 evas_object_show(p->ly);
590 evas_object_event_callback_add(p->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback, p);
591 edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(p->month), "changed", "prog", __cal_month_changed_callback, p);
593 __cal_month_update_genlist(p);
599 static Eina_Bool __cal_month_animation(void *data)
601 cal_month_data *p = data;
605 elapsed_t = ecore_time_get() - p->ani_start;
606 if (elapsed_t > ANIMATION_TIME)
607 elapsed_t = ANIMATION_TIME;
609 dx = (p->pos_to.x - p->pos_from.x) * cal_util_nsin(elapsed_t / ANIMATION_TIME);
610 __cal_month_move_objects(p, dx);
612 if (elapsed_t == ANIMATION_TIME || dx == 0)
616 ecore_animator_del(p->ani);
622 __cal_month_update_month_view(p,p->d);
625 return ECORE_CALLBACK_CANCEL;
628 return ECORE_CALLBACK_RENEW;
631 static inline void __cal_month_start_animation(cal_month_data *p)
633 if (p->pos_from.x == p->pos_to.x)
637 p->ani = ecore_animator_add(__cal_month_animation, p);
638 p->ani_start = ecore_time_get();
642 static void __cal_month_mouse_up_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
645 cal_month_data *p = data;
648 struct appdata* ad = p->ad;
650 Evas_Event_Mouse_Up *ev = ei;
652 p->down_is_called = 0;
656 int dx = p->down1.x - ev->canvas.x;
666 cal_util_get_geometry(&p->pos_from,p->month);
669 if (dx > (p->rect.w >> 1))
674 p->pos_to.x = p->ad->win_w;
675 p->pos_to.y = p->pos_from.y;
676 p->pos_to.w = p->pos_from.w;
677 p->pos_to.h = p->pos_from.h;
682 p->pos_to.x = -(p->ad->win_w);
683 p->pos_to.y = p->pos_from.y;
684 p->pos_to.w = p->pos_from.w;
685 p->pos_to.h = p->pos_from.h;
687 __cal_month_start_animation(p);
691 __cal_month_move_month_calendar_to_left(p, MONTH_CAL_X - ad->win_w);
692 __cal_month_move_month_calendar_to_right(p, MONTH_CAL_X + ad->win_w);
693 evas_object_move(p->month, MONTH_CAL_X, p->pos_from.y);
701 static void __cal_month_mouse_down_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
703 cal_month_data *p = data;
704 Evas_Event_Mouse_Down *ev = ei;
706 p->down1.x = p->move1.x = ev->canvas.x;
707 p->down1.y = p->move1.y = ev->canvas.y;
709 p->down_is_called = 1;
711 cal_util_get_geometry(&p->oringinal_size,p->month);
714 static void __cal_month_mouse_move_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
716 cal_month_data *p = data;
717 Evas_Event_Mouse_Move *ev = ei;
719 if (0 == p->down_is_called)
722 p->move1.x = ev->cur.canvas.x;
723 p->move1.y = ev->cur.canvas.y;
725 if (!p->multi_touched)
726 __cal_month_move_month_calendar(p);
729 static void __cal_month_changed_callback(void *data, Evas_Object *obj, const char *e, const char *src)
731 __cal_month_update_genlist(data);
734 Evas_Object* cal_month_create_view(struct appdata *ad, Evas_Object *main)
738 c_retvm_if(!ad, NULL, "ad is null");
739 c_retvm_if(!main, NULL, "main is null");
744 Evas_Object *list_bg;
746 p = calloc(1, sizeof(cal_month_data));
747 c_retvm_if(!p, NULL, "calloc(1, sizeof(cal_month_data)) is failed");
749 vconf_get_int(CAL_VCONFKEY_FOCUS_VIEW, (int*)&p->calendar_focus_view);
751 if (FOCUS_IN_DAILY == p->calendar_focus_view)
753 ad->is_weekly = FALSE;
754 p->name = _name = "main/month";
756 else if (FOCUS_IN_WEEKLY == p->calendar_focus_view)
758 ad->is_weekly = TRUE;
759 p->name = _name = "main/month/weekly";
766 is_hour24 = ad->is_hour24;
769 p->oringinal_size.x = -1;
770 p->oringinal_size.y = -1;
771 p->oringinal_size.w = -1;
772 p->oringinal_size.h = -1;
773 ly = cal_util_add_layout(ad->nv, p->name);
778 evas_object_data_set(ly, "priv", p);
781 month = cal_month_calendar_create_content(&ad->base_tm, ad, main, EINA_FALSE);
784 ERR("cal_month_calendar_create_content(&ad->base_tm, ad, ly, EINA_FALSE) is failed");
790 elm_object_part_content_set(ly, "cal/sw", month);
792 edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(month), "changed", "prog", __cal_month_changed_callback, p);
794 list_bg = cal_util_add_bg(ly, EINA_FALSE);
797 ERR("cal_util_add_bg(ly, EINA_FALSE) is failed");
803 elm_object_part_content_set(ly, "list/base", list_bg);
805 evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_month_delete_layout, p);
806 evas_object_event_callback_add(ly, EVAS_CALLBACK_MOUSE_DOWN, __cal_month_mouse_down_event_callback, p);
807 evas_object_event_callback_add(ly, EVAS_CALLBACK_MOUSE_UP, __cal_month_mouse_up_event_callback, p);
808 evas_object_event_callback_add(month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback, p);
809 evas_object_event_callback_add(ly, EVAS_CALLBACK_RESIZE, __cal_month_resize_view, p);
816 void cal_month_update_view(Evas_Object *ly)
820 c_retm_if(!ly, "ly is null");
826 p = CAL_UTIL_GET_PRIV_DATA(ly);
827 if (!p || CAL_STRCMP(p->name, _name)) {
828 ERR("update month view: Invalid object");
833 c_retm_if(!ad, "ad is null");
835 cal_month_update_month_calendar(p->month, &ad->base_tm);
836 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->ly), "go,line%d", cal_month_get_weekline(p->month));
838 __cal_month_update_genlist(p);
840 cal_util_delete_evas_object(&p->month_left);
841 cal_util_delete_evas_object(&p->month_right);
843 e = evas_object_evas_get(ly);
844 c_retm_if(!e, "evas_object_evas_get(ly) is failed");