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://floralicense.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>
22 #include <unicode/udat.h>
23 #include <unicode/udatpg.h>
25 #include "lockscreen.h"
28 static Ecore_Timer *timer = NULL;
30 static bool get_formatted_date_from_utc_time(time_t* utc_time, char* date_str, int date_size)
32 UErrorCode status = U_ZERO_ERROR;
33 UDateTimePatternGenerator *generator;
34 UDateFormat *formatter;
35 UChar skeleton[40] = { 0 }
37 , formatted[40] = { 0 };
38 int32_t patternCapacity, formattedCapacity;
39 int32_t skeletonLength, patternLength, formattedLength;
42 const char customSkeleton[] = UDAT_MONTH_WEEKDAY_DAY;
44 date = (UDate) (*utc_time) *1000;
46 uloc_setDefault(__secure_getenv("LC_TIME"), &status);
47 locale = uloc_getDefault();
49 generator = udatpg_open(locale, &status);
50 if (generator == NULL)
53 patternCapacity = (int32_t) (sizeof(pattern) / sizeof((pattern)[0]));
55 u_uastrcpy(skeleton, customSkeleton);
57 skeletonLength = strlen(customSkeleton);
60 udatpg_getBestPattern(generator, skeleton, skeletonLength, pattern,
61 patternCapacity, &status);
64 udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, NULL, -1, pattern,
65 patternLength, &status);
66 if (formatter == NULL) {
67 udatpg_close(generator);
72 (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
75 udat_format(formatter, date, formatted, formattedCapacity, NULL,
78 u_austrcpy(date_str, formatted);
80 udatpg_close(generator);
82 udat_close(formatter);
87 static Eina_Bool _set_info_time(void *data)
89 Evas_Object *info = (Evas_Object *) data;
95 char buf[512] = { 0, };
96 char bf1[32] = { 0, };
97 char bf2[32] = { 0, };
99 enum appcore_time_format timeformat;
102 localtime_r(&tt, &st);
105 ecore_timer_del(timer);
109 char utc_date[256] = { 0, };
110 get_formatted_date_from_utc_time(&tt, utc_date, sizeof(utc_date));
111 edje_object_part_text_set(_EDJ(info), "txt.date", utc_date);
113 timer = ecore_timer_add(60 - st.tm_sec, _set_info_time, info);
115 r = appcore_get_timeformat(&timeformat);
116 if (r == 0 && timeformat == APPCORE_TIME_FORMAT_24) {
117 strftime(bf1, sizeof(bf1), "%H:%M", &st);
118 snprintf(buf, sizeof(buf), "%s", bf1);
120 strftime(bf1, sizeof(bf1), "%l", &st);
122 strftime(bf1, sizeof(bf1), ":%M", &st);
123 snprintf(buf, sizeof(buf), "%d%s", hour, bf1);
124 if (st.tm_hour >= 0 && st.tm_hour < 12) {
125 snprintf(bf2, sizeof(bf2), "%s", "AM");
126 if ((st.tm_hour - 10) < 0 && st.tm_hour != 0) {
127 edje_object_signal_emit(_EDJ(info), "digit,clock", "rect.clock.ampm");
129 edje_object_signal_emit(_EDJ(info), "default,clock", "rect.clock.ampm");
132 snprintf(bf2, sizeof(bf2), "%s", "PM");
133 if ((st.tm_hour - 12) < 10 && (st.tm_hour - 12) != 0) {
134 edje_object_signal_emit(_EDJ(info), "digit,clock", "rect.clock.ampm");
136 edje_object_signal_emit(_EDJ(info), "default,clock", "rect.clock.ampm");
139 edje_object_part_text_set(_EDJ(info), "txt.clock.ampm", bf2);
141 edje_object_part_text_set(_EDJ(info), "txt.clock", buf);
146 static void _set_info_helptext(void *data)
148 struct appdata *ad = data;
153 edje_object_part_text_set(_EDJ(ad->info), "txt.helptext", _NOT_LOCALIZED("Drag along the dots to unlock"));
156 void _set_info(void *data)
158 LOGD("[ == %s == ]", __func__);
159 struct appdata *ad = data;
165 int is_helptext = -1;
167 int retc = vconf_get_bool(VCONFKEY_LOCKSCREEN_CLOCK_DISPLAY, &is_clock);
168 int retht = vconf_get_bool(VCONFKEY_LOCKSCREEN_HELP_TEXT_DISPLAY, &is_helptext);
172 _set_info_time(ad->info);
177 _set_info_helptext(ad);
182 void update_time(void *data)
184 struct appdata *ad = data;
190 int retc = vconf_get_bool(VCONFKEY_LOCKSCREEN_CLOCK_DISPLAY, &is_clock);
193 _set_info_time(ad->info);