Remove trivial unnecessary build dependency
[apps/core/preloaded/lockscreen.git] / src / time_format_ctrl.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 "log.h"
18 #include "time_format.h"
19 #include "display.h"
20 #include "main_view.h"
21
22 #include <Ecore.h>
23 #include <time.h>
24
25 static Ecore_Event_Handler *handler, *display_handler;
26 static Ecore_Timer *update_timer;
27 static Evas_Object *main_view;
28
29 static void _time_update(void)
30 {
31         lockscreen_main_view_time_set(main_view, lockscreen_time_format_locale_get(),
32                         lockscreen_time_format_timezone_get(), lockscreen_time_format_use_24h(), time(NULL));
33 }
34
35 static Eina_Bool _timer_cb(void *data)
36 {
37         _time_update();
38         ecore_timer_interval_set(update_timer, 60.0);
39         return ECORE_CALLBACK_RENEW;
40 }
41
42 static void _time_spawn_align(void)
43 {
44         time_t tt;
45         struct tm st;
46
47         tt = time(NULL);
48         localtime_r(&tt, &st);
49
50         ecore_timer_interval_set(update_timer, 60 - st.tm_sec);
51 }
52
53 static Eina_Bool _time_changed(void *data, int event, void *event_info)
54 {
55         _time_update();
56         _time_spawn_align();
57         return EINA_TRUE;
58 }
59
60 static Eina_Bool _display_status_changed(void *data, int event, void *event_info)
61 {
62         if (lockscreen_display_is_off()) {
63                 if (update_timer) ecore_timer_freeze(update_timer);
64         }
65         else {
66                 _time_update();
67                 _time_spawn_align();
68         }
69         return EINA_TRUE;
70 }
71
72 int lockscreen_time_format_ctrl_init(Evas_Object *view)
73 {
74         if (lockscreen_display_init()) {
75                 FAT("lockscreen_display_init failed");
76                 return 1;
77         }
78
79         if (lockscreen_time_format_init()) {
80                 lockscreen_display_shutdown();
81                 FAT("lockscreen_time_format_init failed");
82                 return 1;
83         }
84
85         handler = ecore_event_handler_add(LOCKSCREEN_EVENT_TIME_FORMAT_CHANGED, _time_changed, NULL);
86         if (!handler)
87                 FAT("ecore_event_handler_add failed on LOCKSCREEN_DATA_MODEL_EVENT_TIME_FORMAT_CHANGED event");
88         display_handler = ecore_event_handler_add(LOCKSCREEN_EVENT_DISPLAY_STATUS_CHANGED, _display_status_changed, NULL);
89         if (!display_handler)
90                 FAT("ecore_event_handler_add failed on LOCKSCREEN_DATA_MODEL_EVENT_LCD_STATUS_CHANGED event");
91         main_view = view;
92         update_timer = ecore_timer_add(60.0, _timer_cb, NULL);
93         _time_update();
94         _time_spawn_align();
95
96         return 0;
97 }
98
99 void lockscreen_time_ctrl_shutdown(void)
100 {
101         ecore_timer_del(update_timer);
102         ecore_event_handler_del(handler);
103         ecore_event_handler_del(display_handler);
104         lockscreen_display_shutdown();
105         lockscreen_time_format_shutdown();
106 }
107
108 void lockscreen_time_format_ctrl_time_update(void)
109 {
110         _time_update();
111 }
112