Change vibration pattern
[apps/native/volume-app.git] / src / main.c
1 /*
2  * Copyright (c) 2009-2015 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 <feedback.h>
18 #include <vconf.h>
19 #include <app_control_internal.h>
20
21 #include "main.h"
22 #include "_util_log.h"
23 #include "_util_efl.h"
24 #include "view.h"
25 #include "control.h"
26
27 static bool _create_app(void *user_data);
28 static void _terminate_app(void *user_data);
29 static void _pause_app(void *user_data);
30 static void _resume_app(void *user_data);
31 static void _control_app(app_control_h service, void *user_data);
32 static void _changed_language(app_event_info_h event_info, void *user_data);
33
34 int main(int argc, char *argv[])
35 {
36         int ret = 0;
37
38         ui_app_lifecycle_callback_s lifecycle_callback = {0,};
39         app_event_handler_h handlers[5] = {NULL, };
40
41         lifecycle_callback.create = _create_app;
42         lifecycle_callback.terminate = _terminate_app;
43         lifecycle_callback.pause = _pause_app;
44         lifecycle_callback.resume = _resume_app;
45         lifecycle_callback.app_control = _control_app;
46
47         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, NULL);
48         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, NULL);
49         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, NULL);
50         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _changed_language, NULL);
51         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, NULL);
52
53         ret = ui_app_main(argc, argv, &lifecycle_callback, NULL);
54         if (ret != APP_ERROR_NONE)
55                 _E("app_main() is failed. err = %d", ret);
56
57         return ret;
58 }
59
60 static bool _create_app(void *user_data)
61 {
62         elm_app_base_scale_set(1.8);
63         /* Initialize feedback */
64         feedback_initialize();
65
66         /* Initialize volume */
67         if (VOLUME_ERROR_OK != volume_control_initialize()) {
68                 _E("Failed to initialize volume");
69                 return false;
70         }
71
72         return true;
73 }
74
75 static void _terminate_app(void *user_data)
76 {
77         /* Deinitialize feedback */
78         feedback_deinitialize();
79
80         /* Deinitialize volume */
81         volume_control_deinitialize();
82 }
83
84 static void _pause_app(void *user_data)
85 {
86         if(VOLUME_ERROR_OK != volume_control_pause())
87                 _E("Failed to pause volume");
88 }
89
90 static void _resume_app(void *user_data)
91 {
92 }
93
94 static void _control_app(app_control_h service, void *user_data)
95 {
96         bundle *b = NULL;
97         app_control_to_bundle(service, &b);
98
99         if(VOLUME_ERROR_OK != volume_control_reset(b)) {
100                 _E("Failed to reset volume");
101                 return;
102         }
103
104         Evas_Object *win = volume_view_win_get();
105         if(win)
106                 elm_win_activate(win);
107 }
108
109 static void _changed_language(app_event_info_h event_info, void *user_data)
110 {
111         _D("language changed");
112         char *locale = vconf_get_str(VCONFKEY_LANGSET);
113         if (locale)
114                 elm_language_set(locale);
115         free(locale);
116 }
117