Remove trivial unnecessary build dependency
[apps/core/preloaded/lockscreen.git] / src / main_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 "main_ctrl.h"
19 #include "main_view.h"
20 #include "window.h"
21 #include "battery_ctrl.h"
22 #include "background.h"
23 #include "camera_ctrl.h"
24 #include "time_format_ctrl.h"
25 #include "util.h"
26 #include "sim_ctrl.h"
27 #include "display.h"
28 #include "events_ctrl.h"
29
30 #include <Elementary.h>
31 #include <app.h>
32
33 static Evas_Object *win;
34 static Evas_Object *view;
35
36 static void _view_unlocked(void *data, Evas_Object *obj, void *event)
37 {
38         ui_app_exit();
39 }
40
41 static void _swipe_finished(void *data, Evas_Object *obj, void *event)
42 {
43         /* When swipe finished play unlock animation and exit */
44         evas_object_smart_callback_add(obj, SIGNAL_UNLOCK_ANIMATION_FINISHED, _view_unlocked, NULL);
45         lockscreen_main_view_unlock(obj);
46 }
47
48 static Eina_Bool _lockscreen_main_ctrl_win_event_cb(void *data, Evas_Object *obj, Evas_Object *source, Evas_Callback_Type type, void *event_info)
49 {
50         if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_TRUE;
51         Evas_Event_Key_Down *ev = event_info;
52
53         if (!strcmp(ev->key, "XF86PowerOff") || !strcmp(ev->key, "XF86Menu")) {
54                 lockscreen_time_format_ctrl_time_update();
55         }
56         else if (!strcmp(ev->key, "XF86Back")) {
57                 util_feedback_tap_play();
58         }
59
60         return EINA_TRUE;
61 }
62
63 static void _lockcscreen_main_ctrl_win_touch_start_cb(void *data, Evas_Object *obj, void *event_info)
64 {
65         lockscreen_display_timer_freeze();
66 }
67
68 static void _lockcscreen_main_ctrl_win_touch_end_cb(void *data, Evas_Object *obj, void *event_info)
69 {
70         lockscreen_display_timer_renew();
71 }
72
73 int lockscreen_main_ctrl_init(void)
74 {
75         win = lockscreen_window_create();
76         if (!win)
77                 FAT("elm_win_add failed.");
78
79         view = lockscreen_main_view_create(win);
80         if (!view)
81                 FAT("lockscreen_main_view_create failed.");
82
83         if (lockscreen_background_init()) {
84                 FAT("lockscreen_background_init failed. Background changes will not be available");
85         } else {
86                 if (!lockscreen_main_view_background_set(view, LOCKSCREEN_BACKGROUND_TYPE_DEFAULT, lockscreen_background_file_get()))
87                         FAT("lockscreen_main_view_background_image_set failed");
88         }
89
90         if (lockscreen_display_init()) {
91                 FAT("lockscreen_display_init failed. Display on/off changes will not be available.");
92         } else {
93                 evas_object_smart_callback_add(win, SIGNAL_TOUCH_STARTED, _lockcscreen_main_ctrl_win_touch_start_cb, NULL);
94                 evas_object_smart_callback_add(win, SIGNAL_TOUCH_ENDED, _lockcscreen_main_ctrl_win_touch_end_cb, NULL);
95         }
96
97         lockscreen_window_content_set(view);
98         evas_object_smart_callback_add(view, SIGNAL_SWIPE_GESTURE_FINISHED, _swipe_finished, NULL);
99         elm_object_event_callback_add(win, _lockscreen_main_ctrl_win_event_cb, NULL);
100
101         // init subcontrollers
102         if (lock_battery_ctrl_init(view))
103                 FAT("lock_battery_ctrl_init failed. Battery information will not be available");
104
105         if (lockscreen_camera_ctrl_init(view))
106                 FAT("lockscreen_camera_ctrl_init failed. Camera quickshot will not be available");
107
108         if (lockscreen_time_format_ctrl_init(view))
109                 FAT("lockscreen_time_format_ctrl_init failed. Time format changes will not be available");
110
111         if (lockscreen_sim_ctrl_init(view))
112                 FAT("lockscreen_sim_ctrl_init failed. Sim PLMN updates will not be available");
113
114         if (lockscreen_events_ctrl_init(view))
115                 FAT("lockscreen_events_ctrl_init failed. Lockscreen events will not be displayed");
116
117         return 0;
118 }
119
120 void lockscreen_main_ctrl_shutdown(void)
121 {
122         lockscreen_background_shutdown();
123         evas_object_del(win);
124 }