Tizen souce update
[apps/home/calendar.git] / src / view-main-month.c
index 9e241b6..36db9b9 100755 (executable)
@@ -61,7 +61,7 @@ typedef struct {
 
        focus_in_month_view_type calendar_focus_view;
 
-       Evas_Object *gl;
+       Evas_Object *genlist;
        struct calsvc *csv;
 
        int single_moved;
@@ -91,7 +91,6 @@ static char* __cal_month_get_genlist_item_label(void *data, Evas_Object *obj, co
 static void __cal_month_mouse_move_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei);
 static void __cal_month_update_genlist(cal_month_data *p);
 static void __cal_month_changed_callback(void *data, Evas_Object *obj, const char *e, const char *src);
-static void __cal_month_rendering_flush_callback(void *data, Evas *e, void *event_info);
 
 static Elm_Genlist_Item_Class itc = {
        .item_style = "3text.5icon",
@@ -126,11 +125,7 @@ static void __cal_month_delete_layout(void *data, Evas *e, Evas_Object *obj, voi
        if (p->idler)
                ecore_idler_del(p->idler);
 
-       evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback);
-
        free(p);
-
-       DBG("");
 }
 
 static void __cal_month_resize_view(void *data, Evas *e, Evas_Object *ly, void *ei)
@@ -299,105 +294,114 @@ static void __cal_month_get_events(cal_month_data *p)
        p->csv = CALENDAR_SVC_GET_EVENT(p->ad->acct_id, st, et);
 }
 
-static void __cal_month_update_genlist(cal_month_data *p)
-{
-       c_retm_if(!p, "p is null");
 
-       Evas_Object* gl;
-       Eina_List *l;
-       struct tmnode *tm;
-       int count = 0;
 
-       CALENDAR_SVC_FREE_CS(&p->csv);
-       __cal_month_get_events(p);
+static Eina_Bool __cal_month_update_genlist_with_idler(void* data)
+{
+       CAL_FN_START;
 
-       if (!p->csv || !p->csv->tmlist || !eina_list_count(p->csv->tmlist))
-       {
-               if (p->gl)
-                       elm_genlist_clear(p->gl);
+       c_retvm_if(!data, ECORE_CALLBACK_CANCEL, "data is null");
 
-               return;
+       cal_month_data* p = data;
+
+       if (!p->genlist) {
+               ERR("p->genlist is null");
+               p->idler = NULL;
+               return ECORE_CALLBACK_CANCEL;
        }
 
-       if (!p->gl)
-       {
-               gl = elm_genlist_add(p->ly);
-               if (gl)
-               {
-                       p->gl = gl;
-                       elm_object_part_content_set(p->ly, "list/sw", gl);
-                       evas_object_data_set(gl, "priv", p);
-               }
+       if (!p->csv) {
+               ERR("p->csv is null");
+               p->idler = NULL;
+               return ECORE_CALLBACK_CANCEL;
        }
-       else
-               elm_genlist_clear(p->gl);
 
-       p->event_offset = 0;
+       Eina_List *event_list = eina_list_nth_list(p->csv->tmlist, p->event_offset);
 
-       EINA_LIST_FOREACH(p->csv->tmlist, l, tm)
-       {
-               if (tm)
-               {
-                       elm_genlist_item_append(p->gl, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
+       Eina_List *l = NULL;
+       struct tmnode *tm = NULL;
+       int count = 0;
+
+       EINA_LIST_FOREACH(event_list, l, tm) {
+               if (tm) {
+                       elm_genlist_item_append(p->genlist, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
 
                        count ++;
                        p->event_offset++;
 
-                       //First time, Just need to show 4 items. Another items will be add with idler
-                       if (count == INITIAL_FETCH_SIZE)
-                               return;
+                       if (count == IDLER_FETCH_SIZE && p->event_offset < eina_list_count(p->csv->tmlist))
+                               return ECORE_CALLBACK_RENEW;
                }
        }
+
+       p->idler = NULL;
+
+       CAL_FN_END;
+
+       return ECORE_CALLBACK_CANCEL;
 }
 
-static Eina_Bool __cal_month_update_genlist_with_idler(void* data)
+static void __cal_month_update_genlist(cal_month_data *p)
 {
        CAL_FN_START;
 
-       c_retvm_if(!data, ECORE_CALLBACK_CANCEL, "data is null");
+       c_retm_if(!p, "p is null");
 
-       Eina_List *l, *event_list;
-       struct tmnode *tm;
-       int count = 0;
+       Evas_Object* genlist = p->genlist;
 
-       cal_month_data* p = data;
-       c_retvm_if(!p, ECORE_CALLBACK_CANCEL, "p is null");
+       CALENDAR_SVC_FREE_CS(&p->csv);
 
-       if (!p->gl)
-       {
-               ERR("p->gl is null");
-               p->idler = NULL;
-               return ECORE_CALLBACK_CANCEL;
+       __cal_month_get_events(p);
+
+       if (!p->csv || !p->csv->tmlist || !eina_list_count(p->csv->tmlist)) {
+               if (genlist)
+                       elm_genlist_clear(genlist);
+
+               CAL_FN_END;
+
+               return;
        }
 
-       if (!p->csv)
-       {
-               ERR("p->csv is null");
-               p->idler = NULL;
-               return ECORE_CALLBACK_CANCEL;
+       if (!genlist) {
+               genlist = elm_genlist_add(p->ly);
+               c_retm_if(!genlist, "gl is null");
+
+               p->genlist = genlist;
+
+               elm_object_part_content_set(p->ly, "list/sw", genlist);
+               evas_object_data_set(genlist, "priv", p);
        }
+       else
+               elm_genlist_clear(genlist);
+
+       p->event_offset = 0;
 
-       event_list = eina_list_nth_list(p->csv->tmlist, p->event_offset);
+       Eina_List *l = NULL;
+       struct tmnode *tm = NULL;
+       int count = 0;
 
-       EINA_LIST_FOREACH(event_list, l, tm)
-       {
-               if (tm)
-               {
-                       elm_genlist_item_append(p->gl, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
+       EINA_LIST_FOREACH(p->csv->tmlist, l, tm) {
+               if (tm) {
+                       elm_genlist_item_append(genlist, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
 
                        count ++;
                        p->event_offset++;
 
-                       if (count == IDLER_FETCH_SIZE && p->event_offset < eina_list_count(p->csv->tmlist))
-                               return ECORE_CALLBACK_RENEW;
+                       //First time, Just need to show 4 items. Another items will be add with idler
+                       if (count == INITIAL_FETCH_SIZE) {
+                               if (INITIAL_FETCH_SIZE < eina_list_count(p->csv->tmlist)) {
+                                       p->idler = ecore_idler_add(__cal_month_update_genlist_with_idler, p);
+                                       c_retm_if(!p->idler, "p->idler is null");
+                               }
+
+                               CAL_FN_END;
+
+                               return;
+                       }
                }
        }
 
-       p->idler = NULL;
-
        CAL_FN_END;
-
-       return ECORE_CALLBACK_CANCEL;
 }
 
 static Evas_Object* __cal_month_create_month_d(cal_month_data *p, int d)
@@ -409,8 +413,7 @@ static Evas_Object* __cal_month_create_month_d(cal_month_data *p, int d)
        t = ad->base_tm;
 
        r = cal_util_update_tm_month(&t, d);
-       if (r == -1)
-               return cal_util_add_layout(p->ly, "rect/empty");
+       c_retvm_if(r < 0, NULL,  "month cross the border ");
 
        return cal_month_calendar_create_content(&t, ad, p->parent, EINA_TRUE);
 }
@@ -452,10 +455,9 @@ static void __cal_month_move_month_calendar_to_right(cal_month_data *p, Evas_Coo
 
 static void __cal_month_move_month_calendar(cal_month_data *p)
 {
-       Evas_Coord dx;
-       Evas_Coord x;
+       c_ret_if(!p);
 
-       dx = p->move1.x - p->down1.x;
+       Evas_Coord dx = p->move1.x - p->down1.x;
        if (!p->single_moved && dx < 15 && dx > -15)
                return;
 
@@ -464,17 +466,37 @@ static void __cal_month_move_month_calendar(cal_month_data *p)
 
        p->single_moved = 1;
 
-       if(0 > p->oringinal_size.x)
-       {
+       struct appdata *ad = p->ad;
+       c_retm_if(!ad, "ad is null");
+
+       struct tm t;
+       int r = 0;
+
+       if (0 <= dx) {
+
+               t = ad->base_tm;
+               r = cal_util_update_tm_month(&t, -1);
+               c_ret_if(r < 0);
+
+       }
+       else {
+
+               t = ad->base_tm;
+               r = cal_util_update_tm_month(&t, 1);
+               c_ret_if(r < 0);
+       }
+
+       Evas_Coord x;
+       if (p->oringinal_size.x < 0) {
                x = p->rect.x + dx;
 
                evas_object_move(p->month, x, p->rect.y);
 
                __cal_month_move_month_calendar_to_left(p, x - p->rect.w);
                __cal_month_move_month_calendar_to_right(p, x + p->rect.w);
-       }
-       else
-       {
+
+       } else {
+
                x = p->oringinal_size.x + dx;
 
                evas_object_move(p->month, x, p->oringinal_size.y);
@@ -486,14 +508,31 @@ static void __cal_month_move_month_calendar(cal_month_data *p)
 
 static inline void __cal_month_move_objects(cal_month_data *p, Evas_Coord dx)
 {
-       CAL_ASSERT(p);
+       c_ret_if(!p);
 
        if(!dx)
                return;
 
-       Evas_Coord x;
+       struct appdata *ad = p->ad;
+       c_retm_if(!ad, "ad is null");
+
+       struct tm t;
+       int r = 0;
+
+       if (0 <= dx) {
+
+               t = ad->base_tm;
+               r = cal_util_update_tm_month(&t, -1);
+               c_ret_if(r < 0);
+
+       } else {
+
+               t = ad->base_tm;
+               r = cal_util_update_tm_month(&t, 1);
+               c_ret_if(r < 0);
+       }
 
-       x = p->pos_from.x + dx;
+       Evas_Coord x = p->pos_from.x + dx;
 
        evas_object_move(p->month, x, p->rect.y);
 
@@ -692,26 +731,6 @@ static void __cal_month_changed_callback(void *data, Evas_Object *obj, const cha
        __cal_month_update_genlist(data);
 }
 
-static void __cal_month_rendering_flush_callback(void *data, Evas *e, void *event_info)
-{
-       CAL_FN_START;
-
-       c_retm_if(!data, "data is null");
-       c_retm_if(!e, "evas is null");
-
-       evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback);
-
-       cal_month_data* p = data;
-
-       if (!p->gl || p->idler ||!p->csv || eina_list_count(p->csv->tmlist) == p->event_offset)
-               return;
-
-       p->idler = ecore_idler_add(__cal_month_update_genlist_with_idler, p);
-       c_retm_if(!p->idler, "p->idler is null");
-
-       CAL_FN_END;
-}
-
 Evas_Object* cal_month_create_view(struct appdata *ad, Evas_Object *main)
 {
        CAL_FN_START;
@@ -824,8 +843,6 @@ void cal_month_update_view(Evas_Object *ly)
        e = evas_object_evas_get(ly);
        c_retm_if(!e, "evas_object_evas_get(ly) is failed");
 
-       evas_event_callback_add(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback,p);
-
        CAL_FN_END;
 }