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.
21 #include <runtime_info.h>
24 #include "indicator.h"
25 #include "indicator_ui.h"
26 #include "indicator_gui.h"
27 #include "indicator_icon_util.h"
30 #define SETTING_TIME_CHANGED_NOTI "setting_time_changed"
31 #define SYSTEM_RESUME "system_wakeup"
33 #define TIME_FONT_SIZE 26
34 #define TIME_FONT_COLOR 127, 104, 79, 255
36 #define AMPM_FONT_SIZE 20
37 #define AMPM_FONT_COLOR 148, 125, 99, 255
38 #define LABEL_STRING "<font_size=%d>%s" \
42 INDICATOR_CLOCK_MODE_12H = 0,
43 INDICATOR_CLOCK_MODE_24H,
44 INDICATOR_CLOCK_MODE_MAX
48 static int clock_mode = INDICATOR_CLOCK_MODE_12H;
49 static Ecore_Timer *timer;
51 static int register_clock_module(void *data);
52 static int unregister_clock_module(void);
53 static int hib_enter_clock_module(void);
54 static int hib_leave_clock_module(void *data);
55 static int language_changed_cb(void *data);
56 static int region_changed_cb(void *data);
58 Indicator_Icon_Object sysclock = {
59 .type = INDICATOR_TXT_ICON,
61 .priority = INDICATOR_PRIORITY_FIXED1,
62 .always_top = EINA_FALSE,
65 .obj_exist = EINA_FALSE,
66 .exist_in_view = EINA_FALSE,
67 .init = register_clock_module,
68 .fini = unregister_clock_module,
69 .hib_enter = hib_enter_clock_module,
70 .hib_leave = hib_leave_clock_module,
72 .region_changed = region_changed_cb,
75 static void indicator_clock_changed_cb(void *data)
77 struct appdata *ad = (struct appdata *)data;
79 char time_buf[128], ampm_buf[128];
85 retif(data == NULL, , "Invalid parameter!");
89 ts = localtime(&ctime);
94 ecore_timer_del(timer);
98 memset(time_str, 0x00, sizeof(time_str));
99 memset(time_buf, 0x00, sizeof(time_buf));
100 memset(ampm_buf, 0x00, sizeof(ampm_buf));
101 memset(buf, 0x00, sizeof(buf));
104 ecore_timer_add(60 - ts->tm_sec, (void *)indicator_clock_changed_cb,
106 if (clock_mode == INDICATOR_CLOCK_MODE_12H) {
107 if (ts->tm_hour >= 0 && ts->tm_hour < 12)
108 snprintf(ampm_buf, sizeof(ampm_buf),
109 LABEL_STRING, AMPM_FONT_SIZE,
112 snprintf(ampm_buf, sizeof(ampm_buf),
113 LABEL_STRING, AMPM_FONT_SIZE,
115 strftime(time_str, sizeof(time_str), "%I:%M", ts);
117 strftime(time_str, sizeof(time_str), "%H:%M", ts);
120 snprintf(time_buf, sizeof(time_buf), LABEL_STRING,
121 TIME_FONT_SIZE, time_str);
122 len = snprintf(buf, sizeof(buf), "%s%s", time_buf, ampm_buf);
124 ERR("Unexpected ERROR!");
128 INFO("[CLOCK MODULE] Timer Status : %d Time: %s", timer, buf);
130 edje_object_part_text_set(elm_layout_edje_get(ad->layout_main),
131 "elm.text.clock", buf);
135 static void indicator_clock_format_changed_cb(keynode_t *node, void *data)
137 retif(data == NULL, , "Invalid parameter!");
141 bool is_24hour_enabled = false;
143 INFO("[Enter] indicator_clock_format_changed_cb");
145 r = runtime_info_get_value_bool(
146 RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &is_24hour_enabled);
148 /* Check Time format. If timeformat have invalid value, Set to 12H */
149 if( r==RUNTIME_INFO_ERROR_NONE&&is_24hour_enabled==true)
151 clock_mode = INDICATOR_CLOCK_MODE_24H;
155 clock_mode = INDICATOR_CLOCK_MODE_12H;
158 indicator_clock_changed_cb(data);
161 static int language_changed_cb(void *data)
163 indicator_clock_changed_cb(data);
167 static int region_changed_cb(void *data)
169 indicator_clock_format_changed_cb(NULL, data);
173 static int register_clock_module(void *data)
177 retif(data == NULL, FAIL, "Invalid parameter!");
179 notifd = heynoti_init();
182 heynoti_subscribe(notifd, SETTING_TIME_CHANGED_NOTI,
183 indicator_clock_changed_cb, data);
185 ERR("Fail: register SETTING_TIME_CHANGED_NOTI");
190 heynoti_subscribe(notifd, SYSTEM_RESUME, indicator_clock_changed_cb,
193 ERR("Fail: register SYSTEM_RESUME");
197 ret = heynoti_attach_handler(notifd);
199 ERR("Failed to attach heynoti handler!");
203 ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
204 indicator_clock_format_changed_cb, data);
206 ERR("Fail: register VCONFKEY_REGIONFORMAT_TIME1224");
210 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT,
211 indicator_clock_format_changed_cb, data);
213 ERR("Fail: register VCONFKEY_SETAPPL_TIMEZONE_INT");
217 indicator_clock_format_changed_cb(NULL, data);
222 static int unregister_clock_module(void)
226 heynoti_unsubscribe(notifd, SETTING_TIME_CHANGED_NOTI,
227 indicator_clock_changed_cb);
229 heynoti_unsubscribe(notifd, SYSTEM_RESUME, indicator_clock_changed_cb);
231 heynoti_close(notifd);
234 ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
235 indicator_clock_format_changed_cb);
237 ERR("Fail: unregister VCONFKEY_REGIONFORMAT_TIME1224");
239 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT,
240 indicator_clock_format_changed_cb);
242 ERR("Fail: unregister VCONFKEY_SETAPPL_TIMEZONE_INT");
245 ecore_timer_del(timer);
251 static int hib_enter_clock_module(void)
255 ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
256 indicator_clock_format_changed_cb);
258 ERR("Fail: unregister VCONFKEY_REGIONFORMAT_TIME1224");
261 ecore_timer_del(timer);
268 static int hib_leave_clock_module(void *data)
272 retif(data == NULL, FAIL, "Invalid parameter!");
274 ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
275 indicator_clock_format_changed_cb, data);
276 retif(ret != OK, FAIL, "Failed to register callback!");
278 indicator_clock_format_changed_cb(NULL, data);