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