2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <appcore-common.h>
19 #include <vconf-keys.h>
21 #include <app_service.h>
23 #include <unicode/udat.h>
24 #include <unicode/udatpg.h>
26 #include "lockscreen.h"
29 static Ecore_Timer *timer = NULL;
31 static bool get_formatted_date_from_utc_time(time_t* utc_time, char* date_str, int date_size)
33 UErrorCode status = U_ZERO_ERROR;
34 UDateTimePatternGenerator *generator;
35 UDateFormat *formatter;
36 UChar skeleton[40] = { 0 }
38 , formatted[40] = { 0 };
39 int32_t patternCapacity, formattedCapacity;
40 int32_t skeletonLength, patternLength, formattedLength;
43 const char customSkeleton[] = UDAT_MONTH_WEEKDAY_DAY;
45 date = (UDate) (*utc_time) *1000;
47 uloc_setDefault(__secure_getenv("LC_TIME"), &status);
48 locale = uloc_getDefault();
50 generator = udatpg_open(locale, &status);
51 if (generator == NULL)
54 patternCapacity = (int32_t) (sizeof(pattern) / sizeof((pattern)[0]));
56 u_uastrcpy(skeleton, customSkeleton);
58 skeletonLength = strlen(customSkeleton);
61 udatpg_getBestPattern(generator, skeleton, skeletonLength, pattern,
62 patternCapacity, &status);
65 udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, NULL, -1, pattern,
66 patternLength, &status);
67 if (formatter == NULL) {
68 udatpg_close(generator);
73 (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
76 udat_format(formatter, date, formatted, formattedCapacity, NULL,
79 u_austrcpy(date_str, formatted);
81 udatpg_close(generator);
83 udat_close(formatter);
88 static Eina_Bool _set_info_time(void *data)
90 Evas_Object *info = (Evas_Object *) data;
96 char buf[512] = { 0, };
97 char bf1[32] = { 0, };
98 char bf2[32] = { 0, };
100 enum appcore_time_format timeformat;
103 localtime_r(&tt, &st);
106 ecore_timer_del(timer);
110 char utc_date[256] = { 0, };
111 get_formatted_date_from_utc_time(&tt, utc_date, sizeof(utc_date));
112 edje_object_part_text_set(_EDJ(info), "txt.date", utc_date);
114 timer = ecore_timer_add(60 - st.tm_sec, _set_info_time, info);
116 r = appcore_get_timeformat(&timeformat);
117 if (r == 0 && timeformat == APPCORE_TIME_FORMAT_24) {
118 strftime(bf1, sizeof(bf1), "%H:%M", &st);
119 snprintf(buf, sizeof(buf), "%s", bf1);
121 strftime(bf1, sizeof(bf1), "%l", &st);
123 strftime(bf1, sizeof(bf1), ":%M", &st);
124 snprintf(buf, sizeof(buf), "%d%s", hour, bf1);
125 if (st.tm_hour >= 0 && st.tm_hour < 12) {
126 snprintf(bf2, sizeof(bf2), "%s", "AM");
127 if ((st.tm_hour - 10) < 0 && st.tm_hour != 0) {
128 edje_object_signal_emit(_EDJ(info), "digit,clock", "rect.clock.ampm");
130 edje_object_signal_emit(_EDJ(info), "default,clock", "rect.clock.ampm");
133 snprintf(bf2, sizeof(bf2), "%s", "PM");
134 if ((st.tm_hour - 12) < 10 && (st.tm_hour - 12) != 0) {
135 edje_object_signal_emit(_EDJ(info), "digit,clock", "rect.clock.ampm");
137 edje_object_signal_emit(_EDJ(info), "default,clock", "rect.clock.ampm");
140 edje_object_part_text_set(_EDJ(info), "txt.clock.ampm", bf2);
142 edje_object_part_text_set(_EDJ(info), "txt.clock", buf);
147 static void _set_info_helptext(void *data)
149 struct appdata *ad = data;
154 edje_object_part_text_set(_EDJ(ad->info), "txt.helptext", _NOT_LOCALIZED("Drag along the dots to unlock"));
157 void _set_info(void *data)
159 LOGD("[ == %s == ]", __func__);
160 struct appdata *ad = data;
166 int is_helptext = -1;
168 int retc = vconf_get_bool(VCONFKEY_LOCKSCREEN_CLOCK_DISPLAY, &is_clock);
169 int retht = vconf_get_bool(VCONFKEY_LOCKSCREEN_HELP_TEXT_DISPLAY, &is_helptext);
173 _set_info_time(ad->info);
178 _set_info_helptext(ad);