[UI]Lockscreen for RSA
[apps/core/preloaded/lockscreen.git] / src / info.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  *  http://www.tizenopensource.org/license
9  *
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.
15  */
16
17 #include <appcore-common.h>
18 #include <vconf.h>
19 #include <vconf-keys.h>
20 #include <dlog.h>
21 #include <app_service.h>
22
23 #include <unicode/udat.h>
24 #include <unicode/udatpg.h>
25
26 #include "lockscreen.h"
27 #include "log.h"
28
29 static Ecore_Timer *timer = NULL;
30
31 static bool get_formatted_date_from_utc_time(time_t* utc_time, char* date_str, int date_size)
32 {
33         UErrorCode status = U_ZERO_ERROR;
34         UDateTimePatternGenerator *generator;
35         UDateFormat *formatter;
36         UChar skeleton[40] = { 0 }
37                 , pattern[40] = { 0 }
38                 , formatted[40] = { 0 };
39         int32_t patternCapacity, formattedCapacity;
40         int32_t skeletonLength, patternLength, formattedLength;
41         UDate date;
42         const char *locale;
43         const char customSkeleton[] = UDAT_MONTH_WEEKDAY_DAY;
44
45         date = (UDate) (*utc_time) *1000;
46
47         uloc_setDefault(__secure_getenv("LC_TIME"), &status);
48         locale = uloc_getDefault();
49
50         generator = udatpg_open(locale, &status);
51         if (generator == NULL)
52                 return false;
53
54         patternCapacity = (int32_t) (sizeof(pattern) / sizeof((pattern)[0]));
55
56         u_uastrcpy(skeleton, customSkeleton);
57
58         skeletonLength = strlen(customSkeleton);
59
60         patternLength =
61                 udatpg_getBestPattern(generator, skeleton, skeletonLength, pattern,
62                                 patternCapacity, &status);
63
64         formatter =
65                 udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, NULL, -1, pattern,
66                         patternLength, &status);
67         if (formatter == NULL) {
68                 udatpg_close(generator);
69                 return false;
70         }
71
72         formattedCapacity =
73                 (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
74
75         formattedLength =
76                 udat_format(formatter, date, formatted, formattedCapacity, NULL,
77                         &status);
78
79         u_austrcpy(date_str, formatted);
80
81         udatpg_close(generator);
82
83         udat_close(formatter);
84
85         return true;
86 }
87
88 static Eina_Bool _set_info_time(void *data)
89 {
90         Evas_Object *info = (Evas_Object *) data;
91         if (info == NULL)
92                 return false;
93
94         struct tm st;
95         time_t tt;
96         char buf[512] = { 0, };
97         char bf1[32] = { 0, };
98         char bf2[32] = { 0, };
99         int r, hour;
100         enum appcore_time_format timeformat;
101
102         tt = time(NULL);
103         localtime_r(&tt, &st);
104
105         if (timer != NULL) {
106                 ecore_timer_del(timer);
107                 timer = NULL;
108         }
109
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);
113
114         timer = ecore_timer_add(60 - st.tm_sec, _set_info_time, info);
115
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);
120         } else {
121                 strftime(bf1, sizeof(bf1), "%l", &st);
122                 hour = atoi(bf1);
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");
129                         } else {
130                                 edje_object_signal_emit(_EDJ(info), "default,clock", "rect.clock.ampm");
131                         }
132                 } else {
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");
136                         } else {
137                                 edje_object_signal_emit(_EDJ(info), "default,clock", "rect.clock.ampm");
138                         }
139                 }
140                 edje_object_part_text_set(_EDJ(info), "txt.clock.ampm", bf2);
141         }
142         edje_object_part_text_set(_EDJ(info), "txt.clock", buf);
143
144         return 0;
145 }
146
147 static void _set_info_helptext(void *data)
148 {
149         struct appdata *ad = data;
150         if (ad == NULL) {
151                 return;
152         }
153
154         edje_object_part_text_set(_EDJ(ad->info), "txt.helptext", _NOT_LOCALIZED("Drag along the dots to unlock"));
155 }
156
157 void _set_info(void *data)
158 {
159         LOGD("[ == %s == ]", __func__);
160         struct appdata *ad = data;
161         if (ad == NULL) {
162                 return;
163         }
164
165         int is_clock = -1;
166         int is_helptext = -1;
167
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);
170
171         if(0 == retc) {
172                 if(is_clock) {
173                         _set_info_time(ad->info);
174                 }
175         }
176         if(0 == retht) {
177                 if(is_helptext) {
178                         _set_info_helptext(ad);
179                 }
180         }
181 }