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);
174 char* cal_util_get_part_text(const char *fmt, int pos)
176 snprintf(_partbuf, sizeof(_partbuf), fmt, pos);
181 void cal_util_set_text(Evas_Object *obj, const char *part, const char *fmt, ...)
186 vsnprintf(_textbuf, sizeof(_textbuf), fmt, ap);
189 edje_object_part_text_set(obj, part, _textbuf);
192 int cal_util_connect_pattern_generator()
196 pthread_mutex_lock(&mutex_lock);
197 if(pattern_generator_reference_counter == 0)
199 uloc_setDefault(getenv("LC_TIME"), &status);
200 if(!pattern_generator)
201 pattern_generator = udatpg_open(uloc_getDefault(), &status);
202 if(!pattern_generator)
204 ERR("udatpg_open fail : %s", u_errorName(status));
205 pthread_mutex_unlock(&mutex_lock);
210 pattern_generator_reference_counter++;
211 pthread_mutex_unlock(&mutex_lock);
218 int cal_util_disconnect_pattern_generator()
220 pthread_mutex_lock(&mutex_lock);
222 if(pattern_generator_reference_counter == 1)
224 if(pattern_generator)
225 udatpg_close(pattern_generator);
226 pattern_generator = NULL;
229 pattern_generator_reference_counter--;
231 pthread_mutex_unlock(&mutex_lock);
236 void cal_util_set_timezone(const char *timezone)
240 snprintf(_timezone, sizeof(_timezone), "%s", timezone);
243 void cal_util_initialize_timezone()
247 int is_lock_timezone = 0;
249 int ret = vconf_get_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, &is_lock_timezone);
254 if (is_lock_timezone)
255 text = vconf_get_str(CAL_VCONFKEY_LOCK_TIMEZONE_PATH);
257 text = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
259 if (CAL_STRLEN(text)) {
261 cal_util_set_timezone(text);
265 ERR("vconf_get_str is failed.");
270 void cal_util_convert_lli_to_tm(const char *timezone, long long int lli, struct tm *tm)
274 UErrorCode status = U_ZERO_ERROR;
275 UChar utf16_timezone[64] = {0};
278 u_uastrncpy(utf16_timezone, timezone, 64);
280 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
282 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
285 ucal_setMillis(cal, (double)(lli* 1000.0), &status);
287 tm->tm_year = ucal_get(cal, UCAL_YEAR, &status) - 1900;
288 tm->tm_mon = ucal_get(cal, UCAL_MONTH, &status);
289 tm->tm_mday = ucal_get(cal, UCAL_DATE, &status);
291 if (ucal_get(cal, UCAL_AM_PM, &status))
292 tm->tm_hour = ucal_get(cal, UCAL_HOUR, &status) + 12;
294 tm->tm_hour = ucal_get(cal, UCAL_HOUR, &status);
296 tm->tm_min = ucal_get(cal, UCAL_MINUTE, &status);
297 tm->tm_sec = ucal_get(cal, UCAL_SECOND, &status);
298 tm->tm_isdst = ucal_get(cal, UCAL_DST_OFFSET, &status);
299 tm->tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK, &status) - 1;
300 tm->tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR, &status) - 1;
305 void cal_util_convert_tm_to_lli(const char *timezone, const struct tm *tm, long long int *lli)
310 UErrorCode status = U_ZERO_ERROR;
311 UChar utf16_timezone[64] = {0};
314 u_uastrncpy(utf16_timezone, timezone, 64);
316 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
318 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
321 ucal_setAttribute(cal, UCAL_LENIENT, 1);
322 ucal_setDateTime(cal, tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, &status);
324 UDate millis = ucal_getMillis(cal, &status);
326 *lli = (long long int)(millis / 1000);
331 void cal_util_convert_lli_to_time_t(const char *timezone, long long int lli, time_t *time)
335 UErrorCode status = U_ZERO_ERROR;
336 UChar utf16_timezone[64] = {0};
339 u_uastrncpy(utf16_timezone, timezone, 64);
341 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
343 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
346 ucal_setMillis(cal, (double)(lli* 1000.0), &status);
350 tm.tm_year = ucal_get(cal, UCAL_YEAR, &status) - 1900;
351 tm.tm_mon = ucal_get(cal, UCAL_MONTH, &status);
352 tm.tm_mday = ucal_get(cal, UCAL_DATE, &status);
354 if (ucal_get(cal, UCAL_AM_PM, &status))
355 tm.tm_hour = ucal_get(cal, UCAL_HOUR, &status) + 12;
357 tm.tm_hour = ucal_get(cal, UCAL_HOUR, &status);
359 tm.tm_min = ucal_get(cal, UCAL_MINUTE, &status);
360 tm.tm_sec = ucal_get(cal, UCAL_SECOND, &status);
361 tm.tm_isdst = ucal_get(cal, UCAL_DST_OFFSET, &status);
362 tm.tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK, &status) - 1;
363 tm.tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR, &status) - 1;
370 void cal_util_convert_time_t_to_lli(const char *timezone, time_t time, long long int *lli)
374 UErrorCode status = U_ZERO_ERROR;
375 UChar utf16_timezone[64] = {0};
378 u_uastrncpy(utf16_timezone, timezone, 64);
380 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
382 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
385 ucal_setAttribute(cal, UCAL_LENIENT, 1);
389 ucal_setDateTime(cal, tm.tm_year + 1900, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, &status);
391 UDate millis = ucal_getMillis(cal, &status);
393 *lli = (long long int)(millis / 1000);
399 UDate cal_util_get_u_date_from_time_t(time_t time)
402 date = (UDate ) time*1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */
406 UDate cal_util_get_u_date_from_tm(const struct tm* tm)
411 time = timelocal((struct tm*)tm);
413 date = (UDate ) time*1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */
417 static void __cal_util_generate_best_pattern(UChar *custom_format, const struct tm* tm, char *buffer, int buffer_size)
419 UErrorCode status = U_ZERO_ERROR;
420 UDateFormat *formatter;
422 UChar bestPattern[64] = {0,};
423 UChar formatted[64] = {0,};
424 char bestPatternString[128]={0,};
425 char formattedString[128] = {0,};
426 int32_t bestPatternCapacity, formattedCapacity;
427 int32_t bestPatternLength, formattedLength;
428 uloc_setDefault(getenv("LC_TIME"), &status);
429 const char* locale = uloc_getDefault();
431 bestPatternCapacity = (int32_t)(sizeof(bestPattern)/sizeof((bestPattern)[0]));
432 bestPatternLength = udatpg_getBestPattern(pattern_generator, custom_format, u_strlen(custom_format), bestPattern, bestPatternCapacity, &status);
434 u_austrncpy(bestPatternString, bestPattern, 128);
436 date = cal_util_get_u_date_from_tm(tm);
437 formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
439 formattedCapacity = (int32_t)(sizeof(formatted)/sizeof((formatted)[0]));
440 formattedLength = udat_format(formatter, date, formatted, formattedCapacity, NULL, &status);
442 u_austrncpy(formattedString, formatted, 128);
444 udat_close(formatter);
446 snprintf(buffer, buffer_size, "%s", formattedString);
449 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)
451 char format[128]={0};
452 UChar custom_format[64]={0};
453 int date_format_length = 0;
454 int time_format_length = 0;
455 int format_length = 0;
458 date_format_length = CAL_STRLEN(date_format);
459 CAL_STRNCPY(format,date_format,date_format_length);
463 time_format_length = CAL_STRLEN(time_format);
464 CAL_STRNCAT(format,time_format,time_format_length);
467 format_length = CAL_STRLEN(format);
469 u_uastrncpy(custom_format, format, format_length);
471 __cal_util_generate_best_pattern(custom_format, tm, buffer, buffer_size);
474 void cal_util_set_time_text(Evas_Object *obj, const char *part, const char *date, const char* time, const struct tm *tm)
476 char time_text[128] = {0};
477 __cal_util_get_time_text_from_format(date, time, tm, time_text, sizeof(time_text) - 1);
479 edje_object_part_text_set(obj, part, time_text);
482 void cal_util_set_item_time_text(Elm_Object_Item *item, 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 elm_object_item_part_text_set(item, part, time_text);
491 static void __cal_util_generate_best_pattern_toupper(UChar *custom_format, const struct tm* tm, char *buffer, int buffer_size)
493 UErrorCode status = U_ZERO_ERROR;
494 UDateFormat *formatter;
496 UChar bestPattern[64] = {0,};
497 UChar formatted[64] = {0,};
498 UChar formatted_upper[64] = {0,};
499 char bestPatternString[128]={0,};
500 char formattedString[128] = {0,};
501 int32_t bestPatternCapacity, formattedCapacity;
502 int32_t bestPatternLength, formattedLength;
503 uloc_setDefault(getenv("LC_TIME"), &status);
504 const char* locale = uloc_getDefault();
506 bestPatternCapacity = (int32_t)(sizeof(bestPattern)/sizeof((bestPattern)[0]));
507 bestPatternLength = udatpg_getBestPattern(pattern_generator, custom_format, u_strlen(custom_format), bestPattern, bestPatternCapacity, &status);
509 u_austrncpy(bestPatternString, bestPattern, 128);
511 date = cal_util_get_u_date_from_tm(tm);
512 formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
514 formattedCapacity = (int32_t)(sizeof(formatted)/sizeof((formatted)[0]));
515 formattedLength = udat_format(formatter, date, formatted, formattedCapacity, NULL, &status);
517 u_strToUpper(formatted_upper, 64, formatted, 64, "", &status);
519 u_austrncpy(formattedString, formatted_upper, 128);
521 udat_close(formatter);
523 snprintf(buffer, buffer_size, "%s", formattedString);
526 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)
528 char format[128]={0};
529 UChar custom_format[64]={0};
530 int date_format_length = 0;
531 int time_format_length = 0;
532 int format_length = 0;
535 date_format_length = CAL_STRLEN(date_format);
536 CAL_STRNCPY(format,date_format,date_format_length);
540 time_format_length = CAL_STRLEN(time_format);
541 CAL_STRNCAT(format,time_format,time_format_length);
544 format_length = CAL_STRLEN(format);
546 u_uastrncpy(custom_format, format, format_length);
548 __cal_util_generate_best_pattern_toupper(custom_format, tm, buffer, buffer_size);
551 void cal_util_set_time_text_toupper(Evas_Object *obj, const char *part, const char *date, const char* time, const struct tm *tm)
553 char time_text[128] = {0};
554 __cal_util_get_time_text_from_format_toupper(date, time, tm, time_text, sizeof(time_text) - 1);
556 edje_object_part_text_set(obj, part, time_text);
559 void cal_util_set_time_week_text(Evas_Object *obj, const char *part, const char *date, const char* time,
560 const struct tm *t, int start)
562 c_retm_if(!obj, "obj is null.");
563 c_retm_if(!part, "part is null.");
564 c_retm_if(!t, "t is null.");
568 char start_date[8] = {0};
569 char end_date[8] = {0};
570 char month_year[32] = {0};
571 char time_text[128] = {0};
573 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_16, NULL, &tm, week, sizeof(week) - 1);
575 tm.tm_mday -= CAL_UTIL_GET_WDAY(tm.tm_wday - start);
576 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, start_date, sizeof(start_date) - 1);
578 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_6, NULL, &tm, month_year, sizeof(month_year) - 1);
581 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, end_date, sizeof(end_date) - 1);
583 snprintf(time_text, sizeof(time_text) - 1,"W%s(%s-%s) %s", week, start_date, end_date, month_year);
585 edje_object_part_text_set(obj, part, time_text);
588 void cal_util_set_item_time_week_text(Elm_Object_Item *item, const char *part, const char *date, const char* time,
589 const struct tm *t, int start)
591 c_retm_if(!item, "item is null.");
592 c_retm_if(!part, "part is null.");
593 c_retm_if(!t, "t is null.");
597 char start_date[8] = {0};
598 char end_date[8] = {0};
599 char month_year[32] = {0};
600 char time_text[128] = {0};
602 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_16, NULL, &tm, week, sizeof(week) - 1);
604 tm.tm_mday -= CAL_UTIL_GET_WDAY(tm.tm_wday - start);
605 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, start_date, sizeof(start_date) - 1);
607 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_18, NULL, &tm, month_year, sizeof(month_year) - 1);
610 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, end_date, sizeof(end_date) - 1);
612 snprintf(time_text, sizeof(time_text) - 1,"W%s %s", week, month_year);
614 elm_object_item_part_text_set(item, part, time_text);
617 int cal_util_get_time_text(char* buf, int buf_size, const char *date, const char* time, const struct tm *tm)
619 char time_text[128] = {0};
621 __cal_util_get_time_text_from_format(date, time, tm, time_text, sizeof(time_text) - 1);
623 snprintf(buf, buf_size, "%s", time_text);
625 return CAL_STRLEN(time_text);
628 void cal_util_emit_signal(Evas_Object *obj, const char *fmt, ...)
633 vsnprintf(_sigbuf, sizeof(_sigbuf), fmt, ap);
636 edje_object_signal_emit(obj, _sigbuf, "prog");
639 Evas_Object* cal_util_add_separator(Evas_Object *box, const char *style)
643 if (!box || CAL_STRCMP(elm_object_widget_type_get(box), "box"))
646 sp = elm_separator_add(box);
648 elm_separator_horizontal_set(sp, EINA_TRUE);
649 elm_object_style_set(sp, style);
650 evas_object_show(sp);
651 elm_box_pack_end(box, sp);
657 Evas_Object* cal_util_add_scroller(Evas_Object *p)
661 Evas_Object *sc = NULL;
663 sc = elm_scroller_add(p);
664 c_retv_if(!sc, NULL);
666 elm_scroller_bounce_set(sc, EINA_FALSE, EINA_TRUE);
667 elm_scroller_policy_set(sc, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
669 evas_object_show(sc);
674 Evas_Object* cal_util_add_box(Evas_Object *p)
682 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
683 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, 0.0);
684 evas_object_show(bx);
689 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)
693 elm_object_style_set(btn, style);
694 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
695 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.5);
696 elm_object_text_set(btn, label);
697 evas_object_smart_callback_add(btn, "clicked", func, data);
698 evas_object_show(btn);
701 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.
703 c_retm_if(!data, "data is null");
704 c_retm_if(!obj, "obj is null");
706 if (elm_object_focus_get(data)) {
707 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
710 if (elm_entry_is_empty(obj))
711 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
713 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
717 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.
719 c_retm_if(!data, "data is null");
720 c_retm_if(!obj, "obj is null");
722 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
724 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
727 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.
729 c_retm_if(!data, "data is null");
730 c_retm_if(!obj, "obj is null");
732 if (elm_entry_is_empty(obj))
733 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
735 elm_object_signal_emit(data, "elm,state,eraser,hide", "elm");
738 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.
740 c_retm_if(!data, "data is null");
742 elm_entry_entry_set(data, "");
745 static void __cal_util_edit_field_clicked_callback(void *data, Evas_Object *obj, const char *emission, const char *source)
749 elm_object_focus_set(data, EINA_TRUE);
752 Evas_Object * cal_util_add_edit_field(Evas_Object *parent, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
754 c_retvm_if(!parent, NULL, "parent is null");
756 Evas_Object *layout = elm_layout_add(parent);
757 c_retvm_if(!layout, NULL, "layout is null");
759 elm_layout_theme_set(layout, "layout", "editfield", "default");
761 Evas_Object *entry = elm_entry_add(parent);
762 c_retvm_if(!entry, layout, "entry is null");
764 elm_object_part_content_set(layout, "elm.swallow.content", entry);
765 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
767 if (guide && guide[0] != '\0')
768 elm_object_part_text_set(layout, "elm.guidetext", guide);
770 elm_entry_single_line_set(entry, single_line);
771 elm_entry_scrollable_set(entry, single_line);
774 elm_object_signal_callback_add(layout, "elm,eraser,clicked", "elm", __cal_util_edit_field_eraser_clicked_callback, entry);
776 elm_entry_editable_set(entry, is_editable);
777 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
780 evas_object_smart_callback_add(entry, "changed", __cal_util_edit_field_changed_callback, layout);
781 evas_object_smart_callback_add(entry, "focused", __cal_util_edit_field_focused_callback, layout);
782 evas_object_smart_callback_add(entry, "unfocused", __cal_util_edit_field_unfocused_callback, layout);
784 evas_object_show(layout);
786 elm_object_signal_callback_add(layout, "mouse,clicked,1", "*", __cal_util_edit_field_clicked_callback, entry);
791 Evas_Object * cal_util_add_nocontents(Evas_Object *parent, const char *label)
793 c_retvm_if(!parent, NULL, "parent is null");
795 Evas_Object *layout = elm_layout_add(parent);
796 c_retvm_if(!layout, NULL, "layout is null");
798 elm_layout_theme_set(layout, "layout", "nocontents", "full");
800 if (label && strlen(label))
801 elm_object_part_text_set(layout, "elm.text", label);
806 Evas_Object * cal_util_add_search_nocontents(Evas_Object *parent, const char *label)
808 c_retvm_if(!parent, NULL, "parent is null");
810 Evas_Object *layout = elm_layout_add(parent);
811 c_retvm_if(!layout, NULL, "layout is null");
813 elm_layout_theme_set(layout, "layout", "nocontents", "search");
815 if (CAL_STRLEN(label))
816 elm_object_part_text_set(layout, "elm.text", label);
821 static void __cal_util_popup_response_callback(void *data, Evas_Object *obj, void *event_info)
823 evas_object_del(data);
826 Evas_Object * cal_util_add_popup(Evas_Object *parent, const char *style, const char *title, const char *desc,
827 void (*callback_func)(void *data, Evas_Object *obj, void *ei), void *data, ...)
829 c_retvm_if(!parent, NULL, "parent is null");
831 Evas_Object *popup = elm_popup_add(parent);
832 c_retvm_if(!popup, NULL, "popup is null");
834 if (CAL_STRLEN(style))
835 elm_object_style_set(popup, style);
838 evas_object_data_set(popup, "data", data);
840 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
842 if (CAL_STRLEN(title))
843 elm_object_part_text_set(popup, "title,text", title);
845 if (CAL_STRLEN(desc))
846 elm_object_text_set(popup, desc);
850 Evas_Object *btn = NULL;
851 const char *label = NULL;
855 callback_func = __cal_util_popup_response_callback;
859 while ((label = va_arg(arg, char*))) {
860 btn = elm_button_add(popup);
866 elm_object_text_set(btn, label);
867 snprintf(part, sizeof(part), "button%d", ++i);
868 elm_object_part_content_set(popup, part, btn);
869 if (!CAL_STRCMP(label, S_("IDS_COM_BODY_DELETE"))) {
870 elm_object_style_set(btn, "sweep/delete");
871 char buffer[128] = {0};
872 snprintf(buffer, sizeof(buffer), "<font_size=36>%s</font_size>", label);
873 elm_object_text_set(btn, buffer);
875 elm_object_style_set(btn, "popup_button/default");
877 evas_object_smart_callback_add(btn, "clicked", callback_func, popup);
883 elm_popup_timeout_set(popup, 3.0);
885 evas_object_show(popup);
886 elm_object_focus_set(popup, EINA_TRUE);
891 Evas_Object * cal_util_add_datetime(Evas_Object *parent, const char *title, const struct tm *tm)
893 c_retvm_if(!parent, NULL, "parent is null");
895 Evas_Object *datetime = NULL;
897 if (CAL_STRLEN(title)) {
899 Evas_Object *layout = elm_layout_add(parent);
900 c_retvm_if(!layout, NULL, "layout is null");
902 Eina_Bool r = elm_layout_file_set(layout, EDJ_FILE, "dialoguegroup/datetime");
903 c_retvm_if(!r, NULL, "r is null");
905 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
907 datetime = elm_datetime_add(layout);
908 c_retvm_if(!datetime, NULL, "datetime is null");
910 elm_object_part_text_set(layout, "elm.text", title);
911 elm_object_part_content_set(layout, "elm.icon", datetime);
913 elm_datetime_field_limit_set(datetime, ELM_DATETIME_YEAR, 70, 136);
915 elm_datetime_value_set(datetime, tm);
921 datetime = elm_datetime_add(parent);
922 c_retvm_if(!datetime, NULL, "datetime is null");
924 evas_object_size_hint_weight_set(datetime, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
926 elm_datetime_field_limit_set(datetime, ELM_DATETIME_YEAR, 70, 136);
928 elm_datetime_value_set(datetime, tm);
934 void cal_util_get_week_number_text(const struct tm* tm, char *buffer, int buffer_size)
936 c_retm_if(!tm, "tm is null");
937 c_retm_if(!buffer, "buffer is null");
939 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_16, NULL ,tm, buffer, buffer_size);
942 int cal_util_get_distance(Evas_Coord_Point *s, Evas_Coord_Point *e)
944 c_retvm_if(!s, -1, "s is null");
945 c_retvm_if(!e, -1, "e is null");
947 return (Evas_Coord)sqrt((s->x - e->x) * (s->x - e->x)
948 + (s->y - e->y) * (s->y - e->y));
951 static Eina_Bool __cal_util_hide_small_information_by_timer(void *user_data)
953 c_retv_if(!user_data, ECORE_CALLBACK_CANCEL);
955 cal_util_hide_small_information((Evas_Object *)user_data);
957 return ECORE_CALLBACK_CANCEL;
960 void cal_util_show_small_information(Evas_Object *layout, const char *message, double timeout)
963 c_ret_if(!CAL_STRLEN(message));
965 Evas_Object *small_information = elm_object_part_content_get(layout, "sel.swallow.contents");
967 if (!small_information) {
969 small_information = elm_layout_add(layout);
970 c_ret_if(!small_information);
972 elm_object_part_content_set(layout, "sel.swallow.contents", small_information);
973 evas_object_size_hint_weight_set(small_information, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
974 evas_object_size_hint_align_set(small_information, EVAS_HINT_FILL, EVAS_HINT_FILL);
976 Eina_Bool ret = elm_layout_theme_set(small_information, "standard", "selectioninfo", "center_text");
977 c_warn_if(!ret, "elm_layout_theme_set() is failed.");
979 evas_object_show(small_information);
982 elm_object_part_text_set(small_information, "elm.text", message);
984 elm_object_signal_emit(layout, "show,selection,info", "elm");
987 Ecore_Timer *timer = ecore_timer_add(timeout, __cal_util_hide_small_information_by_timer, layout);
988 c_warn_if(!timer, "ecore_timer_add() is failed.");
992 void cal_util_hide_small_information(Evas_Object *layout)
996 elm_object_signal_emit(layout, "hide,selection,info", "elm");
999 Evas_Object * cal_util_add_toolbar_button(Evas_Object *naviframe, const char *part, const char *text, Evas_Smart_Cb func, void *data)
1001 c_retv_if(!naviframe, NULL);
1002 c_retv_if(!CAL_STRLEN(part), NULL);
1004 Evas_Object *button = elm_button_add(naviframe);
1005 c_retv_if(!button, NULL);
1007 elm_object_style_set(button, "naviframe/toolbar/default");
1009 if (CAL_STRLEN(text))
1010 elm_object_text_set(button, text);
1012 evas_object_smart_callback_add(button, "clicked", func, data);
1014 Elm_Object_Item *navi_item = elm_naviframe_top_item_get(naviframe);
1015 c_retv_if(!navi_item, NULL);
1017 elm_object_item_part_content_set(navi_item, part, button);
1022 Evas_Object * cal_util_add_toolbar_button2(Evas_Object* naviframe, const char* part, const char* filename, Evas_Smart_Cb func, void* data)
1024 c_retv_if(!naviframe, NULL);
1025 c_retv_if(!CAL_STRLEN(part), NULL);
1027 Evas_Object* button = elm_button_add(naviframe);
1028 c_retv_if(!button, NULL);
1030 elm_object_style_set(button, "naviframe/title_icon");
1032 Evas_Object* icon = elm_icon_add(naviframe);
1033 elm_icon_file_set(icon, CAL_IMAGES_EDJ, filename);
1035 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1036 elm_icon_resizable_set(icon, EINA_TRUE, EINA_TRUE);
1038 elm_object_part_content_set(button, "icon", icon);
1040 evas_object_smart_callback_add(button, "clicked", func, data);
1042 Elm_Object_Item *navi_item = elm_naviframe_top_item_get(naviframe);
1043 c_retv_if(!navi_item, NULL);
1045 elm_object_item_part_content_set(navi_item, part, button);
1050 int cal_util_get_default_first_day_of_week()
1052 UErrorCode status = U_ZERO_ERROR;
1053 UChar utf16_timezone[64] = {0};
1055 char *locale = vconf_get_str(VCONFKEY_REGIONFORMAT);
1057 if (CAL_STRLEN(locale)) {
1058 uloc_setDefault(locale, &status);
1062 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
1064 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
1065 c_retvm_if(!cal, -1, "cal is null");
1067 int first_day_of_week = 0;
1069 first_day_of_week = ucal_getAttribute(cal, UCAL_FIRST_DAY_OF_WEEK);
1073 return first_day_of_week;