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 char bf1[32] = { 0, };
109 if (ts->tm_hour >= 0 && ts->tm_hour < 12)
110 snprintf(ampm_buf, sizeof(ampm_buf),
111 LABEL_STRING, AMPM_FONT_SIZE,
112 _("IDS_COM_POP_AM_M_ABB"));
114 snprintf(ampm_buf, sizeof(ampm_buf),
115 LABEL_STRING, AMPM_FONT_SIZE,
116 _("IDS_COM_POP_PM_M_ABB"));
118 strftime(bf1, sizeof(bf1), "%l", ts);
120 strftime(bf1, sizeof(bf1), ":%M", ts);
122 snprintf(time_str, sizeof(time_str), "%d%s", hour, bf1);
123 // strftime(time_str, sizeof(time_str), "%I:%M", ts);
125 strftime(time_str, sizeof(time_str), "%H:%M", ts);
128 snprintf(time_buf, sizeof(time_buf), LABEL_STRING,
129 TIME_FONT_SIZE, time_str);
130 len = snprintf(buf, sizeof(buf), "%s%s", time_buf, ampm_buf);
132 ERR("Unexpected ERROR!");
136 INFO("[CLOCK MODULE] Timer Status : %d Time: %s", timer, buf);
138 edje_object_part_text_set(elm_layout_edje_get(ad->layout_main),
139 "elm.text.clock", buf);
143 static void indicator_clock_format_changed_cb(keynode_t *node, void *data)
145 retif(data == NULL, , "Invalid parameter!");
149 bool is_24hour_enabled = false;
151 INFO("[Enter] indicator_clock_format_changed_cb");
153 r = runtime_info_get_value_bool(
154 RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &is_24hour_enabled);
156 /* Check Time format. If timeformat have invalid value, Set to 12H */
157 if( r==RUNTIME_INFO_ERROR_NONE&&is_24hour_enabled==true)
159 clock_mode = INDICATOR_CLOCK_MODE_24H;
163 clock_mode = INDICATOR_CLOCK_MODE_12H;
166 indicator_clock_changed_cb(data);
169 static int language_changed_cb(void *data)
171 indicator_clock_changed_cb(data);
175 static int region_changed_cb(void *data)
177 indicator_clock_format_changed_cb(NULL, data);
181 static int register_clock_module(void *data)
185 retif(data == NULL, FAIL, "Invalid parameter!");
187 notifd = heynoti_init();
190 heynoti_subscribe(notifd, SETTING_TIME_CHANGED_NOTI,
191 indicator_clock_changed_cb, data);
193 ERR("Fail: register SETTING_TIME_CHANGED_NOTI");
198 heynoti_subscribe(notifd, SYSTEM_RESUME, indicator_clock_changed_cb,
201 ERR("Fail: register SYSTEM_RESUME");
205 ret = heynoti_attach_handler(notifd);
207 ERR("Failed to attach heynoti handler!");
211 ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
212 indicator_clock_format_changed_cb, data);
214 ERR("Fail: register VCONFKEY_REGIONFORMAT_TIME1224");
218 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT,
219 indicator_clock_format_changed_cb, data);
221 ERR("Fail: register VCONFKEY_SETAPPL_TIMEZONE_INT");
225 indicator_clock_format_changed_cb(NULL, data);
230 static int unregister_clock_module(void)
234 heynoti_unsubscribe(notifd, SETTING_TIME_CHANGED_NOTI,
235 indicator_clock_changed_cb);
237 heynoti_unsubscribe(notifd, SYSTEM_RESUME, indicator_clock_changed_cb);
239 heynoti_close(notifd);
242 ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
243 indicator_clock_format_changed_cb);
245 ERR("Fail: unregister VCONFKEY_REGIONFORMAT_TIME1224");
247 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT,
248 indicator_clock_format_changed_cb);
250 ERR("Fail: unregister VCONFKEY_SETAPPL_TIMEZONE_INT");
253 ecore_timer_del(timer);
259 static int hib_enter_clock_module(void)
263 ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
264 indicator_clock_format_changed_cb);
266 ERR("Fail: unregister VCONFKEY_REGIONFORMAT_TIME1224");
269 ecore_timer_del(timer);
276 static int hib_leave_clock_module(void *data)
280 retif(data == NULL, FAIL, "Invalid parameter!");
282 ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
283 indicator_clock_format_changed_cb, data);
284 retif(ret != OK, FAIL, "Failed to register callback!");
286 indicator_clock_format_changed_cb(NULL, data);