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