X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fview-main-month-cal.c;h=639649f2db12252b377c611bebe71294ce3a31f0;hb=f5db89f98d5a2979be9a9aaec44c975a0c4af2f3;hp=7c815e149a11a145e62e7faa43869f52044133dd;hpb=d920a209ab99b507370520229131f5ba5b165fdf;p=apps%2Fhome%2Fcalendar.git diff --git a/src/view-main-month-cal.c b/src/view-main-month-cal.c index 7c815e1..639649f 100755 --- a/src/view-main-month-cal.c +++ b/src/view-main-month-cal.c @@ -49,7 +49,7 @@ typedef struct { time_t end_time; }weekly_event; -struct _priv { +typedef struct { const char *name; struct appdata *ad; Evas_Object *parent; @@ -72,15 +72,15 @@ struct _priv { int weekline; int down_x; int down_y; -}; +} cal_view_main_month_cal_data; static const char *_name = NULL; static Calendar_color calendar_color; static Evas_Object *__cal_month_calendar_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part); static char* __cal_month_calendar_get_genlist_item_label(void *data, Evas_Object *obj, const char *part); -static void __cal_month_calendar_signal_week(struct _priv *p,Evas_Object *eo); -static int __cal_month_calendar_get_weekly_events(struct _priv *p); +static void __cal_month_calendar_signal_week(cal_view_main_month_cal_data *p,Evas_Object *eo); +static int __cal_month_calendar_get_weekly_events(cal_view_main_month_cal_data *p); static Elm_Genlist_Item_Class itc = { .item_style = "3text.5icon", @@ -96,7 +96,7 @@ static Evas_Object *__cal_month_calendar_get_genlist_item_icon(void *data, Evas_ struct tmnode *tm = data; c_retvm_if(!tm->cs, NULL, "tm->cs is null"); - struct _priv* p = CAL_UTIL_GET_PRIV_DATA(obj); + cal_view_main_month_cal_data* p = CAL_UTIL_GET_PRIV_DATA(obj); c_retvm_if(!p, NULL, "p is null"); int r; @@ -150,7 +150,7 @@ static void __cal_month_calendar_make_time_text(time_t t, struct tm *tm, char *b } -static char* __cal_month_calendar_get_time_text(struct tmnode *tm, struct _priv *p) +static char* __cal_month_calendar_get_time_text(struct tmnode *tm, cal_view_main_month_cal_data *p) { char buf[512]; char stime[512]; @@ -193,7 +193,7 @@ static char* __cal_month_calendar_get_genlist_item_label(void *data, Evas_Object if (allday) return strdup(C_("IDS_COM_BODY_ALL_DAY")); - struct _priv *p = CAL_UTIL_GET_PRIV_DATA(obj); + cal_view_main_month_cal_data *p = CAL_UTIL_GET_PRIV_DATA(obj); c_retvm_if(!p, NULL, "p is null"); return __cal_month_calendar_get_time_text(tm, p); @@ -212,7 +212,7 @@ static void __cal_month_calendar_delete_layout(void *data, Evas *e, Evas_Object CAL_FN_START; c_retm_if(!data, "data is null"); - struct _priv *p = data; + cal_view_main_month_cal_data *p = data; struct appdata *ad = p->ad; c_retm_if(!ad, "ad is null"); @@ -242,7 +242,7 @@ static inline void __cal_month_calendar_set_color(Evas_Object *ly, int pos, int cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(ly), "%s,%d", p, pos); } -static inline void __cal_month_calendar_set_disabled(Evas_Object *ly, struct _priv *p, int pos) +static inline void __cal_month_calendar_set_disabled(Evas_Object *ly, cal_view_main_month_cal_data *p, int pos) { struct _day *d = &p->day[pos]; @@ -251,7 +251,7 @@ static inline void __cal_month_calendar_set_disabled(Evas_Object *ly, struct _pr d->enabled = 0; } -static inline void __cal_month_calendar_set_enabled(Evas_Object *ly, struct _priv *p, int pos, int wday) +static inline void __cal_month_calendar_set_enabled(Evas_Object *ly, cal_view_main_month_cal_data *p, int pos, int wday) { struct _day *d = &p->day[pos]; @@ -280,7 +280,7 @@ static inline void __cal_month_calendar_unset_today(Evas_Object *eo, int *pos) *pos = -1; } -static inline void __cal_month_calendar_set_focuse_week(struct _priv *p,Evas_Object *eo, int pos) +static inline void __cal_month_calendar_set_focuse_week(cal_view_main_month_cal_data *p,Evas_Object *eo, int pos) { if (pos == -1) return; @@ -454,7 +454,7 @@ static inline int __cal_month_calendar_get_start_day(int *st, struct tm *t, int return day; } -static int __cal_month_calendar_update_today(Evas_Object *eo, struct _priv *p) +static int __cal_month_calendar_update_today(Evas_Object *eo, cal_view_main_month_cal_data *p) { struct appdata *ad = p->ad; @@ -480,7 +480,7 @@ void cal_month_calendar_update_select(Evas_Object *ly) CAL_ASSERT(ly); Evas_Object* eo = CAL_UTIL_GET_EDJ_DATA(ly); - struct _priv* p = CAL_UTIL_GET_PRIV_DATA(ly); + cal_view_main_month_cal_data* p = CAL_UTIL_GET_PRIV_DATA(ly); CAL_ASSERT(p); CAL_ASSERT(p->ad); @@ -498,7 +498,7 @@ void cal_month_calendar_update_select(Evas_Object *ly) } } -static void __cal_month_calendar_get_simple_check(struct _priv *p, time_t st, time_t et, char *map, int map_sz) +static void __cal_month_calendar_get_simple_check(cal_view_main_month_cal_data *p, time_t st, time_t et, char *map, int map_sz) { int* month; int i = 0; @@ -515,7 +515,7 @@ static void __cal_month_calendar_get_simple_check(struct _priv *p, time_t st, ti free(month); } -static void __cal_month_calendar_update_check(Evas_Object *ly, struct _priv *p) +static void __cal_month_calendar_update_check(Evas_Object *ly, cal_view_main_month_cal_data *p) { time_t st, et; int r, i; @@ -530,6 +530,8 @@ static void __cal_month_calendar_update_check(Evas_Object *ly, struct _priv *p) ERR("Invalid time conversion"); return; } + if (st < 0) + st = 0; max = cal_util_get_max_days(p->cur_tm.tm_year, p->cur_tm.tm_mon); @@ -559,7 +561,7 @@ static void __cal_month_calendar_update_check(Evas_Object *ly, struct _priv *p) static int __cal_month_calendar_fill_calendar(Evas_Object *ly, struct tm *t, int start) { - struct _priv *p; + cal_view_main_month_cal_data *p; int line = 6; // default int prev_max, cur_max; int day, i, st, wday; @@ -618,7 +620,7 @@ static int __cal_month_calendar_fill_calendar(Evas_Object *ly, struct tm *t, int return line; } -static void __cal_month_calendar_click_event_callback(struct _priv *p, Evas_Object *obj, int pos) +static void __cal_month_calendar_click_event_callback(cal_view_main_month_cal_data *p, Evas_Object *obj, int pos) { CAL_ASSERT(p); @@ -637,8 +639,10 @@ static void __cal_month_calendar_click_event_callback(struct _priv *p, Evas_Obje else { p->ad->base_hour = -1; p->ad->cid = 0; // new + cal_edit_create_view(p->ad, p->parent); } + return; } @@ -651,7 +655,7 @@ static void __cal_month_calendar_click_event_callback(struct _priv *p, Evas_Obje static void __cal_month_calendar_cal_event_callback(void *data, Evas_Object *obj, const char *e, const char *src) { - struct _priv *p = data; + cal_view_main_month_cal_data *p = data; c_retm_if(!p, "p is null"); struct appdata *ad = p->ad; @@ -681,7 +685,7 @@ static void __cal_month_calendar_cal_event_callback(void *data, Evas_Object *obj static void __cal_month_calendar_prog_event_callback(void *data, Evas_Object *obj, const char *e, const char *src) { - struct _priv *p = data; + cal_view_main_month_cal_data *p = data; if (!CAL_STRCMP(e, "update_today")) { __cal_month_calendar_update_today(obj, p); @@ -704,7 +708,7 @@ static void __cal_month_calendar_set_wday_text(Evas_Object *ly, int start) { int i; struct tm t = { 0, }; - struct _priv* p = CAL_UTIL_GET_PRIV_DATA(ly); + cal_view_main_month_cal_data* p = CAL_UTIL_GET_PRIV_DATA(ly); if(!p) { ERR("p is null"); @@ -763,7 +767,7 @@ static gint __cal_month_calendar_events_compare(gconstpointer a,gconstpointer b) return 0; } -static void __cal_month_calendar_signal_clean(struct _priv *p,Evas_Object *eo) +static void __cal_month_calendar_signal_clean(cal_view_main_month_cal_data *p,Evas_Object *eo) { int i = 0; int line = 0; @@ -779,7 +783,7 @@ static void __cal_month_calendar_signal_clean(struct _priv *p,Evas_Object *eo) } -static int __cal_month_calendar_clean_list(struct _priv *p) +static int __cal_month_calendar_clean_list(cal_view_main_month_cal_data *p) { int i = 0; @@ -796,7 +800,7 @@ static int __cal_month_calendar_clean_list(struct _priv *p) return 0; } -static int __cal_month_calendar_get_week_time(struct _priv *p, int *first_day, int *last_day) +static int __cal_month_calendar_get_week_time(cal_view_main_month_cal_data *p, int *first_day, int *last_day) { int day = 0; int today = 0; @@ -900,7 +904,7 @@ static void __cal_month_calendar_get_next(GList** list) } } -static int __cal_month_calendar_get_weekly_events(struct _priv *p) +static int __cal_month_calendar_get_weekly_events(cal_view_main_month_cal_data *p) { c_retvm_if(!p, -1, "p is null"); @@ -952,6 +956,9 @@ static int __cal_month_calendar_get_weekly_events(struct _priv *p) end_time.tm_sec = 59; ls = mktime(&start_time); + if (ls < 0) + ls = 0; + le = mktime(&end_time); if (CAL_SUCCESS != CALENDAR_SVC_GET_EVENT_LIST_BY_PERIOD(0,ls,le,&iter)) @@ -1045,7 +1052,7 @@ static int __cal_month_calendar_get_weekly_events(struct _priv *p) return 0; } -static void __cal_month_calendar_signal_week(struct _priv *p,Evas_Object *eo) +static void __cal_month_calendar_signal_week(cal_view_main_month_cal_data *p,Evas_Object *eo) { c_retm_if(!p, "p is null"); c_retm_if(!eo, "eo is null"); @@ -1086,7 +1093,7 @@ static void __cal_month_calendar_signal_week(struct _priv *p,Evas_Object *eo) static void __cal_month_calendar_mouse_down(void *data, Evas *e, Evas_Object *ly, void *ei) { - struct _priv *p = data; + cal_view_main_month_cal_data *p = data; Evas_Event_Mouse_Down *ev = ei; char eve[8] = {0}; int offset = 0; @@ -1109,7 +1116,7 @@ static void __cal_month_calendar_mouse_down(void *data, Evas *e, Evas_Object *ly static void __cal_month_calendar_mouse_move(void *data, Evas *e, Evas_Object *ly, void *ei) { - struct _priv *p = data; + cal_view_main_month_cal_data *p = data; char eve[8] = {0}; if( -1 != p->index_for_press) @@ -1159,7 +1166,7 @@ static void __cal_month_calendar_genlist_item_select_callback(void *data, Evas_O cal_struct *cs = tm->cs; int idx; Elm_Object_Item *it; - struct _priv *p; + cal_view_main_month_cal_data *p; int repeat; it = elm_genlist_selected_item_get(obj); @@ -1185,7 +1192,7 @@ static void __cal_month_calendar_genlist_item_select_callback(void *data, Evas_O } } -static void __cal_month_calendar_get_events(struct _priv *p) +static void __cal_month_calendar_get_events(cal_view_main_month_cal_data *p) { time_t st, et; @@ -1194,7 +1201,7 @@ static void __cal_month_calendar_get_events(struct _priv *p) p->csv = CALENDAR_SVC_GET_EVENT(p->ad->acct_id, st, et); } -static void __cal_month_calendar_update_genlist(struct _priv *p) +static void __cal_month_calendar_update_genlist(cal_view_main_month_cal_data *p) { CAL_FN_START; @@ -1221,34 +1228,39 @@ static void __cal_month_calendar_update_genlist(struct _priv *p) CAL_FN_END; } -static void __cal_month_calendar_popup_delete_callback(void *data, Evas *e, Evas_Object *obj, void *ei) +static void __cal_month_calendar_popup_response_callback(void *data, Evas_Object *obj, void *ei) { c_retm_if(!data, "data is null"); - struct _priv* p = data; + Evas_Object *popup = data; - p->popup = NULL; - p->gl = NULL; + evas_object_hide(popup); } void __cal_month_calendar_events_of_one_weekday(void *data) { c_retm_if(!data, "data is null"); - struct _priv *p = data; + cal_view_main_month_cal_data *p = data; c_retm_if(!p->parent, "p->parent is null"); - char title[1024] = {0}; + struct appdata *ad = p->ad; + c_ret_if(!ad); + + char title[128] = {0}; cal_util_get_time_text(title, sizeof(title), CAL_UTIL_DATE_FORMAT_13, NULL, &p->ad->base_tm); if (!p->popup) { - p->popup = cal_util_add_popup(p->parent, title, NULL, NULL, NULL, S_("IDS_COM_BODY_CLOSE"), NULL); - c_retm_if(!p->popup, "cal_util_add_popup returned null"); + p->popup = cal_util_add_popup(ad->win, "menustyle", title, NULL, + __cal_month_calendar_popup_response_callback, p, + S_("IDS_COM_BODY_CLOSE"), NULL); - elm_object_style_set(p->popup,"menustyle"); - - evas_object_event_callback_add(p->popup, EVAS_CALLBACK_DEL, __cal_month_calendar_popup_delete_callback, p); + c_retm_if(!p->popup, "cal_util_add_popup returned null"); + } + else { + elm_object_part_text_set(p->popup, "title,text", title); + evas_object_show(p->popup); } if (!p->gl) { @@ -1263,7 +1275,7 @@ void __cal_month_calendar_events_of_one_weekday(void *data) static void __cal_month_calendar_mouse_up(void *data, Evas *e, Evas_Object *ly, void *ei) { - struct _priv *p = data; + cal_view_main_month_cal_data *p = data; Evas_Event_Mouse_Down *ev = ei; int start_day = 0; int end_day = 0; @@ -1279,127 +1291,110 @@ static void __cal_month_calendar_mouse_up(void *data, Evas *e, Evas_Object *ly, __cal_month_calendar_get_week_time(p,&start_day,&end_day); - if(7 != (num_of_enable = end_day - start_day + 1)) - { - if(end_day < 7) - { - if(ev->canvas.x < (7 - num_of_enable) * day_width) - { + if (7 != (num_of_enable = end_day - start_day + 1)) { + + if (end_day < 7) { + + if (ev->canvas.x < (7 - num_of_enable) * day_width) return; - } + start_day -= (7 - num_of_enable); } - else if(start_day > 7) - { - if(ev->canvas.x > num_of_enable * day_width) - { + else if (start_day > 7) { + + if (ev->canvas.x > num_of_enable * day_width) return; - } } } - if(ev->canvas.x > 0 && ev->canvas.x < 1*day_width) - { + if (ev->canvas.x > 0 && ev->canvas.x < 1*day_width) { + p->ad->base_tm.tm_mday = start_day; - if(!__cal_month_calendar_event_exists(p->list,0)) - { + if (!__cal_month_calendar_event_exists(p->list,0)) { p->ad->base_hour = -1; p->ad->cid = 0; // new cal_edit_create_view(p->ad, p->parent); } else - { __cal_month_calendar_events_of_one_weekday(p); - } } - else if(ev->canvas.x > 1*day_width && ev->canvas.x < 2*day_width) - { + else if (ev->canvas.x > 1*day_width && ev->canvas.x < 2*day_width) { + p->ad->base_tm.tm_mday = start_day+1; - if(!__cal_month_calendar_event_exists(p->list,1)) - { + + if (!__cal_month_calendar_event_exists(p->list,1)) { + p->ad->base_hour = -1; p->ad->cid = 0; // new cal_edit_create_view(p->ad, p->parent); } else - { __cal_month_calendar_events_of_one_weekday(p); - } } - else if(ev->canvas.x > 2*day_width && ev->canvas.x < 3*day_width) - { + else if (ev->canvas.x > 2*day_width && ev->canvas.x < 3*day_width) { + p->ad->base_tm.tm_mday = start_day+2; - if(!__cal_month_calendar_event_exists(p->list,2)) - { + if (!__cal_month_calendar_event_exists(p->list,2)) { + p->ad->base_hour = -1; p->ad->cid = 0; // new cal_edit_create_view(p->ad, p->parent); } else - { __cal_month_calendar_events_of_one_weekday(p); - } } - else if(ev->canvas.x > 3*day_width && ev->canvas.x < 4*day_width) - { + else if (ev->canvas.x > 3*day_width && ev->canvas.x < 4*day_width) { + p->ad->base_tm.tm_mday = start_day+3; - if(!__cal_month_calendar_event_exists(p->list,3)) - { + if (!__cal_month_calendar_event_exists(p->list,3)) { + p->ad->base_hour = -1; p->ad->cid = 0; // new cal_edit_create_view(p->ad, p->parent); } else - { __cal_month_calendar_events_of_one_weekday(p); - } } - else if(ev->canvas.x > 4*day_width && ev->canvas.x < 5*day_width) - { + else if (ev->canvas.x > 4*day_width && ev->canvas.x < 5*day_width) { + p->ad->base_tm.tm_mday = start_day+4; - if(!__cal_month_calendar_event_exists(p->list,4)) - { + + if (!__cal_month_calendar_event_exists(p->list,4)) { + p->ad->base_hour = -1; p->ad->cid = 0; // new cal_edit_create_view(p->ad, p->parent); } else - { __cal_month_calendar_events_of_one_weekday(p); - } } - else if(ev->canvas.x > 5*day_width && ev->canvas.x < 6*day_width) - { + else if (ev->canvas.x > 5*day_width && ev->canvas.x < 6*day_width) { + p->ad->base_tm.tm_mday = start_day+5; - if(!__cal_month_calendar_event_exists(p->list,5)) - { + + if (!__cal_month_calendar_event_exists(p->list,5)) { p->ad->base_hour = -1; p->ad->cid = 0; // new cal_edit_create_view(p->ad, p->parent); } else - { __cal_month_calendar_events_of_one_weekday(p); - } } - else - { + else { + p->ad->base_tm.tm_mday = start_day+6; - if(!__cal_month_calendar_event_exists(p->list,6)) - { + + if (!__cal_month_calendar_event_exists(p->list,6)) { p->ad->base_hour = -1; p->ad->cid = 0; // new cal_edit_create_view(p->ad, p->parent); } else - { __cal_month_calendar_events_of_one_weekday(p); - } } - if(-1 != p->index_for_press) - { + if (-1 != p->index_for_press) { snprintf(eve, sizeof(eve) , "up,%d", p->index_for_press); edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->month), eve, "prog"); p->index_for_press = -1; @@ -1412,7 +1407,7 @@ Evas_Object* cal_month_calendar_create_content(struct tm *t, struct appdata *ad, { CAL_FN_START; - struct _priv *p; + cal_view_main_month_cal_data *p; Evas_Object *ly; time_t r; @@ -1422,7 +1417,7 @@ Evas_Object* cal_month_calendar_create_content(struct tm *t, struct appdata *ad, if (r == -1) return NULL; - CAL_CALLOC(p, 1, struct _priv); + CAL_CALLOC(p, 1, cal_view_main_month_cal_data); p->ad = ad; p->parent = main; @@ -1492,29 +1487,27 @@ void cal_month_update_month_calendar(Evas_Object *ly, struct tm *t) { CAL_FN_START; - struct _priv *p; - struct appdata *ad; + c_ret_if(!ly); + c_ret_if(!t); - CAL_ASSERT(ly); - - p = CAL_UTIL_GET_PRIV_DATA(ly); + cal_view_main_month_cal_data *p = CAL_UTIL_GET_PRIV_DATA(ly); if (!p || CAL_STRCMP(p->name, _name)) { ERR("update month calendar: Invalid object"); return; } - ad = p->ad; - CAL_ASSERT(ad); + struct appdata *ad = p->ad; + c_ret_if(!ad); p->weekline = __cal_month_calendar_fill_calendar(ly, t, ad->wday_start); cal_month_calendar_update_select(ly); __cal_month_calendar_update_check(ly, p); - if (p->ad->is_weekly) - { + if (p->ad->is_weekly) { + __cal_month_calendar_get_weekly_events(p); - if(-1 == p->pos_selected) + if (-1 == p->pos_selected) __cal_month_calendar_set_focuse_week(p, CAL_UTIL_GET_EDJ_DATA(ly), p->pos_today); else __cal_month_calendar_set_focuse_week(p, CAL_UTIL_GET_EDJ_DATA(ly), p->pos_selected); @@ -1527,7 +1520,7 @@ void cal_month_update_month_calendar(Evas_Object *ly, struct tm *t) int cal_month_get_weekline(Evas_Object *ly) { - struct _priv *p; + cal_view_main_month_cal_data *p; CAL_ASSERT(ly);