3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <unicode/ucal.h>
21 #include <unicode/udat.h>
22 #include <unicode/udatpg.h>
23 #include <unicode/uloc.h>
24 #include <unicode/ustring.h>
25 #include <unicode/ustdio.h>
29 #include "cld-images.h"
31 static UDateTimePatternGenerator *pattern_generator = NULL;
32 static pthread_mutex_t mutex_lock = PTHREAD_MUTEX_INITIALIZER;
33 static UErrorCode status = U_ZERO_ERROR;
34 static int pattern_generator_reference_counter = 0;
36 static char _partbuf[1024];
37 static char _textbuf[1024];
38 static char _sigbuf[1024];
39 static char _timezone[32];
41 Evas_Object* cal_util_add_bg(Evas_Object *obj, Eina_Bool is_window)
51 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
54 elm_win_resize_object_add(obj, bg);
56 elm_object_style_set(bg, "group_list");
65 Evas_Object* cal_util_add_layout(Evas_Object *win, const char *g)
67 c_retvm_if(!win, NULL, "win is null");
70 Evas_Object *eo = elm_layout_add(win);
71 c_retvm_if(!eo, NULL, "elm_layout_add returned null");
74 r = elm_layout_file_set(eo, EDJ_FILE, g);
75 c_warn_if(r == EINA_FALSE, "elm_layout_file_set is failed");
78 r = elm_layout_theme_set(eo, "layout", "application", "default");
79 c_warn_if(r == EINA_FALSE, "elm_layout_theme_set is failed");
82 if (r == EINA_FALSE) {
87 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
93 Evas_Object* cal_util_add_layout_noindicator(Evas_Object *win)
95 c_retvm_if(!win, NULL, "win is null");
98 Evas_Object *eo = elm_layout_add(win);
99 c_retvm_if(!eo, NULL, "elm_layout_add returned null");
101 r = elm_layout_theme_set(eo, "layout", "application", "noindicator");
102 c_warn_if(r == EINA_FALSE, "elm_layout_theme_set is failed");
104 if (r == EINA_FALSE) {
109 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
110 evas_object_show(eo);
115 Evas_Object* cal_util_add_rectangle(Evas_Object *p)
119 r = evas_object_rectangle_add(evas_object_evas_get(p));
126 static void __cal_util_delete_window(void *data, Evas_Object *obj, void *event)
131 static void profile_changed_cb(void *data, Evas_Object * obj, void *event)
133 const char *profile = elm_config_profile_get();
135 if (strcmp(profile, "desktop") == 0)
136 elm_win_indicator_mode_set (obj, ELM_WIN_INDICATOR_HIDE);
138 elm_win_indicator_mode_set (obj, ELM_WIN_INDICATOR_SHOW);
141 Evas_Object* cal_util_add_window(const char *name, Evas_Coord* w, Evas_Coord* h)
145 Evas_Object *eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
146 c_retvm_if(!eo, NULL, "elm_win_add returned null");
148 Evas_Coord width, height;
150 elm_win_title_set(eo, name);
152 /*For calendar ring, window delete callback is not needed.*/
153 if (strcmp(name, CALENDAR_RING))
154 evas_object_smart_callback_add(eo, "delete,request", __cal_util_delete_window, NULL);
156 evas_object_smart_callback_add(eo, "profile,changed", profile_changed_cb, NULL);
158 ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
159 evas_object_resize(eo, width, height);
161 elm_win_conformant_set(eo, EINA_TRUE);
162 elm_win_indicator_mode_set(eo, ELM_WIN_INDICATOR_SHOW);
169 if (elm_win_wm_rotation_supported_get(eo)) {
170 int rots[4] = { CAL_WINDOW_ROTATION_0,
171 CAL_WINDOW_ROTATION_90,
172 CAL_WINDOW_ROTATION_180,
173 CAL_WINDOW_ROTATION_270 };
174 elm_win_wm_rotation_available_rotations_set(eo, &rots, 4);
182 char* cal_util_get_part_text(const char *fmt, int pos)
184 snprintf(_partbuf, sizeof(_partbuf), fmt, pos);
189 void cal_util_set_text(Evas_Object *obj, const char *part, const char *fmt, ...)
194 vsnprintf(_textbuf, sizeof(_textbuf), fmt, ap);
197 edje_object_part_text_set(obj, part, _textbuf);
200 int cal_util_connect_pattern_generator()
204 pthread_mutex_lock(&mutex_lock);
205 if(pattern_generator_reference_counter == 0)
207 uloc_setDefault(getenv("LC_TIME"), &status);
208 if(!pattern_generator)
209 pattern_generator = udatpg_open(uloc_getDefault(), &status);
210 if(!pattern_generator)
212 ERR("udatpg_open fail : %s", u_errorName(status));
213 pthread_mutex_unlock(&mutex_lock);
218 pattern_generator_reference_counter++;
219 pthread_mutex_unlock(&mutex_lock);
226 int cal_util_disconnect_pattern_generator()
228 pthread_mutex_lock(&mutex_lock);
230 if(pattern_generator_reference_counter == 1)
232 if(pattern_generator)
233 udatpg_close(pattern_generator);
234 pattern_generator = NULL;
237 pattern_generator_reference_counter--;
239 pthread_mutex_unlock(&mutex_lock);
244 void cal_util_set_timezone(const char *timezone)
248 snprintf(_timezone, sizeof(_timezone), "%s", timezone);
251 void cal_util_initialize_timezone()
255 int is_lock_timezone = 0;
257 int ret = vconf_get_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, &is_lock_timezone);
262 if (is_lock_timezone)
263 text = vconf_get_str(CAL_VCONFKEY_LOCK_TIMEZONE_PATH);
265 text = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
267 if (CAL_STRLEN(text)) {
269 cal_util_set_timezone(text);
273 ERR("vconf_get_str is failed.");
278 void cal_util_convert_lli_to_tm(const char *timezone, long long int lli, struct tm *tm)
282 UErrorCode status = U_ZERO_ERROR;
283 UChar utf16_timezone[64] = {0};
286 u_uastrncpy(utf16_timezone, timezone, 64);
288 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
290 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
293 ucal_setMillis(cal, (double)(lli* 1000.0), &status);
295 tm->tm_year = ucal_get(cal, UCAL_YEAR, &status) - 1900;
296 tm->tm_mon = ucal_get(cal, UCAL_MONTH, &status);
297 tm->tm_mday = ucal_get(cal, UCAL_DATE, &status);
299 if (ucal_get(cal, UCAL_AM_PM, &status))
300 tm->tm_hour = ucal_get(cal, UCAL_HOUR, &status) + 12;
302 tm->tm_hour = ucal_get(cal, UCAL_HOUR, &status);
304 tm->tm_min = ucal_get(cal, UCAL_MINUTE, &status);
305 tm->tm_sec = ucal_get(cal, UCAL_SECOND, &status);
306 tm->tm_isdst = ucal_get(cal, UCAL_DST_OFFSET, &status);
307 tm->tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK, &status) - 1;
308 tm->tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR, &status) - 1;
313 void cal_util_convert_tm_to_lli(const char *timezone, const struct tm *tm, long long int *lli)
318 UErrorCode status = U_ZERO_ERROR;
319 UChar utf16_timezone[64] = {0};
322 u_uastrncpy(utf16_timezone, timezone, 64);
324 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
326 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
329 ucal_setAttribute(cal, UCAL_LENIENT, 1);
330 ucal_setDateTime(cal, tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, &status);
332 UDate millis = ucal_getMillis(cal, &status);
334 *lli = (long long int)(millis / 1000);
339 void cal_util_convert_lli_to_time_t(const char *timezone, long long int lli, time_t *time)
343 UErrorCode status = U_ZERO_ERROR;
344 UChar utf16_timezone[64] = {0};
347 u_uastrncpy(utf16_timezone, timezone, 64);
349 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
351 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
354 ucal_setMillis(cal, (double)(lli* 1000.0), &status);
358 tm.tm_year = ucal_get(cal, UCAL_YEAR, &status) - 1900;
359 tm.tm_mon = ucal_get(cal, UCAL_MONTH, &status);
360 tm.tm_mday = ucal_get(cal, UCAL_DATE, &status);
362 if (ucal_get(cal, UCAL_AM_PM, &status))
363 tm.tm_hour = ucal_get(cal, UCAL_HOUR, &status) + 12;
365 tm.tm_hour = ucal_get(cal, UCAL_HOUR, &status);
367 tm.tm_min = ucal_get(cal, UCAL_MINUTE, &status);
368 tm.tm_sec = ucal_get(cal, UCAL_SECOND, &status);
369 tm.tm_isdst = ucal_get(cal, UCAL_DST_OFFSET, &status);
370 tm.tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK, &status) - 1;
371 tm.tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR, &status) - 1;
378 void cal_util_convert_time_t_to_lli(const char *timezone, time_t time, long long int *lli)
382 UErrorCode status = U_ZERO_ERROR;
383 UChar utf16_timezone[64] = {0};
386 u_uastrncpy(utf16_timezone, timezone, 64);
388 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
390 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
393 ucal_setAttribute(cal, UCAL_LENIENT, 1);
397 ucal_setDateTime(cal, tm.tm_year + 1900, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, &status);
399 UDate millis = ucal_getMillis(cal, &status);
401 *lli = (long long int)(millis / 1000);
407 UDate cal_util_get_u_date_from_time_t(time_t time)
410 date = (UDate ) time*1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */
414 UDate cal_util_get_u_date_from_tm(const struct tm* tm)
419 time = timelocal((struct tm*)tm);
421 date = (UDate ) time*1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */
425 static void __cal_util_generate_best_pattern(UChar *custom_format, const struct tm* tm, char *buffer, int buffer_size)
427 UErrorCode status = U_ZERO_ERROR;
428 UDateFormat *formatter;
430 UChar bestPattern[64] = {0,};
431 UChar formatted[64] = {0,};
432 char bestPatternString[128]={0,};
433 char formattedString[128] = {0,};
434 int32_t bestPatternCapacity, formattedCapacity;
435 int32_t bestPatternLength, formattedLength;
436 uloc_setDefault(getenv("LC_TIME"), &status);
437 const char* locale = uloc_getDefault();
439 bestPatternCapacity = (int32_t)(sizeof(bestPattern)/sizeof((bestPattern)[0]));
440 bestPatternLength = udatpg_getBestPattern(pattern_generator, custom_format, u_strlen(custom_format), bestPattern, bestPatternCapacity, &status);
442 u_austrncpy(bestPatternString, bestPattern, 128);
444 date = cal_util_get_u_date_from_tm(tm);
445 formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
447 formattedCapacity = (int32_t)(sizeof(formatted)/sizeof((formatted)[0]));
448 formattedLength = udat_format(formatter, date, formatted, formattedCapacity, NULL, &status);
450 u_austrncpy(formattedString, formatted, 128);
452 udat_close(formatter);
454 snprintf(buffer, buffer_size, "%s", formattedString);
457 static void __cal_util_get_time_text_from_format(const char *date_format, const char *time_format, const struct tm* tm, char *buffer, int buffer_size)
459 char format[128]={0};
460 UChar custom_format[64]={0};
461 int date_format_length = 0;
462 int time_format_length = 0;
463 int format_length = 0;
466 date_format_length = CAL_STRLEN(date_format);
467 CAL_STRNCPY(format,date_format,date_format_length);
471 time_format_length = CAL_STRLEN(time_format);
472 CAL_STRNCAT(format,time_format,time_format_length);
475 format_length = CAL_STRLEN(format);
477 u_uastrncpy(custom_format, format, format_length);
479 __cal_util_generate_best_pattern(custom_format, tm, buffer, buffer_size);
482 void cal_util_set_time_text(Evas_Object *obj, const char *part, const char *date, const char* time, const struct tm *tm)
484 char time_text[128] = {0};
485 __cal_util_get_time_text_from_format(date, time, tm, time_text, sizeof(time_text) - 1);
487 edje_object_part_text_set(obj, part, time_text);
490 void cal_util_set_item_time_text(Elm_Object_Item *item, const char *part, const char *date, const char* time, const struct tm *tm)
492 char time_text[128] = {0};
493 __cal_util_get_time_text_from_format(date, time, tm, time_text, sizeof(time_text) - 1);
495 elm_object_item_part_text_set(item, part, time_text);
499 static void __cal_util_generate_best_pattern_toupper(UChar *custom_format, const struct tm* tm, char *buffer, int buffer_size)
501 UErrorCode status = U_ZERO_ERROR;
502 UDateFormat *formatter;
504 UChar bestPattern[64] = {0,};
505 UChar formatted[64] = {0,};
506 UChar formatted_upper[64] = {0,};
507 char bestPatternString[128]={0,};
508 char formattedString[128] = {0,};
509 int32_t bestPatternCapacity, formattedCapacity;
510 int32_t bestPatternLength, formattedLength;
511 uloc_setDefault(getenv("LC_TIME"), &status);
512 const char* locale = uloc_getDefault();
514 bestPatternCapacity = (int32_t)(sizeof(bestPattern)/sizeof((bestPattern)[0]));
515 bestPatternLength = udatpg_getBestPattern(pattern_generator, custom_format, u_strlen(custom_format), bestPattern, bestPatternCapacity, &status);
517 u_austrncpy(bestPatternString, bestPattern, 128);
519 date = cal_util_get_u_date_from_tm(tm);
520 formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
522 formattedCapacity = (int32_t)(sizeof(formatted)/sizeof((formatted)[0]));
523 formattedLength = udat_format(formatter, date, formatted, formattedCapacity, NULL, &status);
525 u_strToUpper(formatted_upper, 64, formatted, 64, "", &status);
527 u_austrncpy(formattedString, formatted_upper, 128);
529 udat_close(formatter);
531 snprintf(buffer, buffer_size, "%s", formattedString);
534 static void __cal_util_get_time_text_from_format_toupper(const char *date_format, const char *time_format, const struct tm* tm, char *buffer, int buffer_size)
536 char format[128]={0};
537 UChar custom_format[64]={0};
538 int date_format_length = 0;
539 int time_format_length = 0;
540 int format_length = 0;
543 date_format_length = CAL_STRLEN(date_format);
544 CAL_STRNCPY(format,date_format,date_format_length);
548 time_format_length = CAL_STRLEN(time_format);
549 CAL_STRNCAT(format,time_format,time_format_length);
552 format_length = CAL_STRLEN(format);
554 u_uastrncpy(custom_format, format, format_length);
556 __cal_util_generate_best_pattern_toupper(custom_format, tm, buffer, buffer_size);
559 void cal_util_set_time_text_toupper(Evas_Object *obj, const char *part, const char *date, const char* time, const struct tm *tm)
561 char time_text[128] = {0};
562 __cal_util_get_time_text_from_format_toupper(date, time, tm, time_text, sizeof(time_text) - 1);
564 edje_object_part_text_set(obj, part, time_text);
567 void cal_util_set_time_week_text(Evas_Object *obj, const char *part, const char *date, const char* time,
568 const struct tm *t, int start)
570 c_retm_if(!obj, "obj is null.");
571 c_retm_if(!part, "part is null.");
572 c_retm_if(!t, "t is null.");
576 char start_date[8] = {0};
577 char end_date[8] = {0};
578 char month_year[32] = {0};
579 char time_text[128] = {0};
581 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_16, NULL, &tm, week, sizeof(week) - 1);
583 tm.tm_mday -= CAL_UTIL_GET_WDAY(tm.tm_wday - start);
584 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, start_date, sizeof(start_date) - 1);
586 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_6, NULL, &tm, month_year, sizeof(month_year) - 1);
589 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, end_date, sizeof(end_date) - 1);
591 snprintf(time_text, sizeof(time_text) - 1,"W%s(%s-%s) %s", week, start_date, end_date, month_year);
593 edje_object_part_text_set(obj, part, time_text);
596 void cal_util_set_item_time_week_text(Elm_Object_Item *item, const char *part, const char *date, const char* time,
597 const struct tm *t, int start)
599 c_retm_if(!item, "item is null.");
600 c_retm_if(!part, "part is null.");
601 c_retm_if(!t, "t is null.");
605 char start_date[8] = {0};
606 char end_date[8] = {0};
607 char month_year[32] = {0};
608 char time_text[128] = {0};
610 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_16, NULL, &tm, week, sizeof(week) - 1);
612 tm.tm_mday -= CAL_UTIL_GET_WDAY(tm.tm_wday - start);
613 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, start_date, sizeof(start_date) - 1);
615 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_18, NULL, &tm, month_year, sizeof(month_year) - 1);
618 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, end_date, sizeof(end_date) - 1);
620 snprintf(time_text, sizeof(time_text) - 1,"W%s %s", week, month_year);
622 elm_object_item_part_text_set(item, part, time_text);
625 int cal_util_get_time_text(char* buf, int buf_size, const char *date, const char* time, const struct tm *tm)
627 char time_text[128] = {0};
629 __cal_util_get_time_text_from_format(date, time, tm, time_text, sizeof(time_text) - 1);
631 snprintf(buf, buf_size, "%s", time_text);
633 return CAL_STRLEN(time_text);
636 void cal_util_emit_signal(Evas_Object *obj, const char *fmt, ...)
641 vsnprintf(_sigbuf, sizeof(_sigbuf), fmt, ap);
644 edje_object_signal_emit(obj, _sigbuf, "prog");
647 Evas_Object* cal_util_add_separator(Evas_Object *box, const char *style)
651 if (!box || CAL_STRCMP(elm_object_widget_type_get(box), "box"))
654 sp = elm_separator_add(box);
656 elm_separator_horizontal_set(sp, EINA_TRUE);
657 elm_object_style_set(sp, style);
658 evas_object_show(sp);
659 elm_box_pack_end(box, sp);
665 Evas_Object* cal_util_add_scroller(Evas_Object *p)
669 Evas_Object *sc = NULL;
671 sc = elm_scroller_add(p);
672 c_retv_if(!sc, NULL);
674 elm_scroller_bounce_set(sc, EINA_FALSE, EINA_TRUE);
675 elm_scroller_policy_set(sc, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
677 evas_object_show(sc);
682 Evas_Object* cal_util_add_box(Evas_Object *p)
690 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
691 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, 0.0);
692 evas_object_show(bx);
697 void cal_util_set_controlbar_button(Evas_Object *btn, char *label, char *style, void (*func) (void *data, Evas_Object *obj, void *event_info), void* data)
701 elm_object_style_set(btn, style);
702 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
703 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.5);
704 elm_object_text_set(btn, label);
705 evas_object_smart_callback_add(btn, "clicked", func, data);
706 evas_object_show(btn);
709 static void __cal_util_edit_field_changed_callback(void *data, Evas_Object *obj, void *event_info) // This callback is for showing(hiding) X marked button.
711 c_retm_if(!data, "data is null");
712 c_retm_if(!obj, "obj is null");
714 if (elm_object_focus_get(data)) {
715 if (elm_entry_is_empty(obj))
716 elm_object_signal_emit(data, "elm,state,rename,hide", "");
718 elm_object_signal_emit(data, "elm,state,eraser,show", "");
722 static void __cal_util_edit_field_focused_callback(void *data, Evas_Object *obj, void *event_info) // Focused callback will show X marked button and hide guidetext.
724 c_retm_if(!data, "data is null");
725 c_retm_if(!obj, "obj is null");
727 elm_object_signal_emit(data, "elm,state,eraser,show", "");
728 elm_object_signal_emit(data, "elm,state,rename,hide", "");
732 static void __cal_util_edit_field_unfocused_callback(void *data, Evas_Object *obj, void *event_info) // Unfocused callback will show guidetext and hide X marked button.
734 c_retm_if(!data, "data is null");
735 c_retm_if(!obj, "obj is null");
737 elm_object_signal_emit(data, "elm,state,eraser,hide", "");
738 elm_object_signal_emit(data, "elm,state,rename,show", "");
742 static void __cal_util_edit_field_eraser_clicked_callback(void *data, Evas_Object *obj, const char *emission, const char *source) // When X marked button is clicked, empty entry's contents.
744 c_retm_if(!data, "data is null");
746 elm_entry_entry_set(data, "");
749 static void __cal_util_edit_field_clicked_callback(void *data, Evas_Object *obj, const char *emission, const char *source)
753 elm_object_focus_set(data, EINA_TRUE);
756 Evas_Object * cal_util_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable, Eina_Bool is_no_bg)
758 c_retvm_if(!parent, NULL, "parent is null");
760 Evas_Object *layout = elm_layout_add(parent);
761 c_retvm_if(!layout, NULL, "layout is null");
763 if (CAL_STRLEN(title)) {
764 elm_layout_theme_set(layout, "layout", "dialogue/editfield", "title");
765 elm_object_part_text_set(layout, "elm.text", title);
768 elm_layout_theme_set(layout, "layout", "editfield/no_bg", "default");
770 elm_layout_theme_set(layout, "layout", "dialogue/editfield", "default");
773 Evas_Object *entry = elm_entry_add(parent);
774 c_retvm_if(!entry, layout, "entry is null");
776 elm_object_part_content_set(layout, "elm.icon.entry", entry);
777 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
779 if (CAL_STRLEN(guide))
780 elm_object_part_text_set(entry, "elm.guide", guide);
782 elm_entry_single_line_set(entry, single_line);
783 elm_entry_scrollable_set(entry, single_line);
785 evas_object_smart_callback_add(entry, "changed", __cal_util_edit_field_changed_callback, layout);
786 evas_object_smart_callback_add(entry, "focused", __cal_util_edit_field_focused_callback, layout);
787 evas_object_smart_callback_add(entry, "unfocused", __cal_util_edit_field_unfocused_callback, layout);
789 elm_object_part_content_set(layout, "elm.icon.entry", entry);
791 Evas_Object *button = elm_button_add(parent);
792 elm_object_style_set(button, "editfield_clear");
793 elm_object_part_content_set(layout, "elm.icon.eraser", button);
796 evas_object_smart_callback_add(button, "clicked", __cal_util_edit_field_eraser_clicked_callback, entry);
798 elm_entry_editable_set(entry, is_editable);
799 elm_object_signal_emit(layout, "elm,state,rename,hide", "");
800 elm_object_signal_emit(layout, "elm,state,eraser,hide", "");
803 evas_object_show(layout);
805 elm_object_signal_callback_add(layout, "mouse,clicked,1", "*", __cal_util_edit_field_clicked_callback, entry);
810 Evas_Object * cal_util_add_nocontents(Evas_Object *parent, const char *label)
812 c_retvm_if(!parent, NULL, "parent is null");
814 Evas_Object *layout = elm_layout_add(parent);
815 c_retvm_if(!layout, NULL, "layout is null");
817 elm_layout_theme_set(layout, "layout", "nocontents", "full");
819 if (label && strlen(label))
820 elm_object_part_text_set(layout, "elm.text", label);
825 Evas_Object * cal_util_add_search_nocontents(Evas_Object *parent, const char *label)
827 c_retvm_if(!parent, NULL, "parent is null");
829 Evas_Object *layout = elm_layout_add(parent);
830 c_retvm_if(!layout, NULL, "layout is null");
832 elm_layout_theme_set(layout, "layout", "nocontents", "search");
834 if (CAL_STRLEN(label))
835 elm_object_part_text_set(layout, "elm.text", label);
840 static void __cal_util_popup_response_callback(void *data, Evas_Object *obj, void *event_info)
842 evas_object_del(data);
845 Evas_Object * cal_util_add_popup(Evas_Object *parent, const char *style, const char *title, const char *desc,
846 void (*callback_func)(void *data, Evas_Object *obj, void *ei), void *data, ...)
848 c_retvm_if(!parent, NULL, "parent is null");
850 Evas_Object *popup = elm_popup_add(parent);
851 c_retvm_if(!popup, NULL, "popup is null");
853 if (CAL_STRLEN(style))
854 elm_object_style_set(popup, style);
857 evas_object_data_set(popup, "data", data);
859 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
861 if (CAL_STRLEN(title))
862 elm_object_part_text_set(popup, "title,text", title);
864 if (CAL_STRLEN(desc))
865 elm_object_text_set(popup, desc);
869 Evas_Object *btn = NULL;
870 const char *label = NULL;
874 callback_func = __cal_util_popup_response_callback;
878 while ((label = va_arg(arg, char*))) {
879 btn = elm_button_add(popup);
885 elm_object_text_set(btn, label);
886 snprintf(part, sizeof(part), "button%d", ++i);
887 elm_object_part_content_set(popup, part, btn);
888 if (!CAL_STRCMP(label, S_("IDS_COM_BODY_DELETE"))) {
889 elm_object_style_set(btn, "sweep/delete");
890 char buffer[128] = {0};
891 snprintf(buffer, sizeof(buffer), "<font_size=36>%s</font_size>", label);
892 elm_object_text_set(btn, buffer);
894 elm_object_style_set(btn, "popup_button/default");
896 evas_object_smart_callback_add(btn, "clicked", callback_func, popup);
902 elm_popup_timeout_set(popup, 3.0);
904 evas_object_show(popup);
905 elm_object_focus_set(popup, EINA_TRUE);
910 Evas_Object * cal_util_add_datetime(Evas_Object *parent, const char *title, const struct tm *tm)
912 c_retvm_if(!parent, NULL, "parent is null");
914 Evas_Object *datetime = NULL;
916 if (CAL_STRLEN(title)) {
918 Evas_Object *layout = elm_layout_add(parent);
919 c_retvm_if(!layout, NULL, "layout is null");
921 Eina_Bool r = elm_layout_file_set(layout, EDJ_FILE, "dialoguegroup/datetime");
922 c_retvm_if(!r, NULL, "r is null");
924 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
926 datetime = elm_datetime_add(layout);
927 c_retvm_if(!datetime, NULL, "datetime is null");
929 elm_object_part_text_set(layout, "elm.text", title);
930 elm_object_part_content_set(layout, "elm.icon", datetime);
932 elm_datetime_field_limit_set(datetime, ELM_DATETIME_YEAR, 70, 136);
934 elm_datetime_value_set(datetime, tm);
940 datetime = elm_datetime_add(parent);
941 c_retvm_if(!datetime, NULL, "datetime is null");
943 evas_object_size_hint_weight_set(datetime, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
945 elm_datetime_field_limit_set(datetime, ELM_DATETIME_YEAR, 70, 136);
947 elm_datetime_value_set(datetime, tm);
953 void cal_util_get_week_number_text(const struct tm* tm, char *buffer, int buffer_size)
955 c_retm_if(!tm, "tm is null");
956 c_retm_if(!buffer, "buffer is null");
958 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_16, NULL ,tm, buffer, buffer_size);
961 int cal_util_get_distance(Evas_Coord_Point *s, Evas_Coord_Point *e)
963 c_retvm_if(!s, -1, "s is null");
964 c_retvm_if(!e, -1, "e is null");
966 return (Evas_Coord)sqrt((s->x - e->x) * (s->x - e->x)
967 + (s->y - e->y) * (s->y - e->y));
970 static Eina_Bool __cal_util_hide_small_information_by_timer(void *user_data)
972 c_retv_if(!user_data, ECORE_CALLBACK_CANCEL);
974 cal_util_hide_small_information((Evas_Object *)user_data);
976 return ECORE_CALLBACK_CANCEL;
979 void cal_util_show_small_information(Evas_Object *layout, const char *message, double timeout)
982 c_ret_if(!CAL_STRLEN(message));
984 Evas_Object *small_information = elm_object_part_content_get(layout, "sel.swallow.contents");
986 if (!small_information) {
988 small_information = elm_layout_add(layout);
989 c_ret_if(!small_information);
991 elm_object_part_content_set(layout, "sel.swallow.contents", small_information);
992 evas_object_size_hint_weight_set(small_information, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
993 evas_object_size_hint_align_set(small_information, EVAS_HINT_FILL, EVAS_HINT_FILL);
995 Eina_Bool ret = elm_layout_theme_set(small_information, "standard", "selectioninfo", "center_text");
996 c_warn_if(!ret, "elm_layout_theme_set() is failed.");
998 evas_object_show(small_information);
1001 elm_object_part_text_set(small_information, "elm.text", message);
1003 elm_object_signal_emit(layout, "show,selection,info", "elm");
1006 Ecore_Timer *timer = ecore_timer_add(timeout, __cal_util_hide_small_information_by_timer, layout);
1007 c_warn_if(!timer, "ecore_timer_add() is failed.");
1011 void cal_util_hide_small_information(Evas_Object *layout)
1015 elm_object_signal_emit(layout, "hide,selection,info", "elm");
1018 Evas_Object * cal_util_add_toolbar_button(Evas_Object *naviframe, const char *part, const char *text, Evas_Smart_Cb func, void *data)
1020 c_retv_if(!naviframe, NULL);
1021 c_retv_if(!CAL_STRLEN(part), NULL);
1023 Evas_Object *button = elm_button_add(naviframe);
1024 c_retv_if(!button, NULL);
1026 elm_object_style_set(button, "naviframe/toolbar/default");
1028 if (CAL_STRLEN(text))
1029 elm_object_text_set(button, text);
1031 evas_object_smart_callback_add(button, "clicked", func, data);
1033 Elm_Object_Item *navi_item = elm_naviframe_top_item_get(naviframe);
1034 c_retv_if(!navi_item, NULL);
1036 elm_object_item_part_content_set(navi_item, part, button);
1041 Evas_Object * cal_util_add_toolbar_button2(Evas_Object* naviframe, const char* part, const char* filename, Evas_Smart_Cb func, void* data)
1043 c_retv_if(!naviframe, NULL);
1044 c_retv_if(!CAL_STRLEN(part), NULL);
1046 Evas_Object* button = elm_button_add(naviframe);
1047 c_retv_if(!button, NULL);
1049 elm_object_style_set(button, "naviframe/title_icon");
1051 Evas_Object* icon = elm_icon_add(naviframe);
1052 elm_icon_file_set(icon, CAL_IMAGES_EDJ, filename);
1054 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1055 elm_icon_resizable_set(icon, EINA_TRUE, EINA_TRUE);
1057 elm_object_part_content_set(button, "icon", icon);
1059 evas_object_smart_callback_add(button, "clicked", func, data);
1061 Elm_Object_Item *navi_item = elm_naviframe_top_item_get(naviframe);
1062 c_retv_if(!navi_item, NULL);
1064 elm_object_item_part_content_set(navi_item, part, button);
1069 int cal_util_get_default_first_day_of_week()
1071 UErrorCode status = U_ZERO_ERROR;
1072 UChar utf16_timezone[64] = {0};
1074 char *locale = vconf_get_str(VCONFKEY_REGIONFORMAT);
1076 if (CAL_STRLEN(locale)) {
1077 uloc_setDefault(locale, &status);
1081 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
1083 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
1084 c_retvm_if(!cal, -1, "cal is null");
1086 int first_day_of_week = 0;
1088 first_day_of_week = ucal_getAttribute(cal, UCAL_FIRST_DAY_OF_WEEK);
1092 return first_day_of_week;