add lock/unlock sound
[apps/home/draglock.git] / src / draglock-util.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 <app.h>
18 #include <Ecore_X.h>
19 #include <vconf-keys.h>
20 #include <svi.h>
21
22 #include "draglock.h"
23
24 static void _draglock_util_window_deleted_cb(void *data, Evas_Object *obj,
25                 void *event) {
26         app_efl_exit();
27 }
28
29 Evas_Object *draglock_util_add_window(const char *name) {
30         Evas_Object *obj_window = NULL;
31         int width = 0, height = 0;
32
33         obj_window = elm_win_add(NULL, name, ELM_WIN_BASIC);
34         if (obj_window != NULL) {
35                 elm_win_alpha_set(obj_window, EINA_TRUE);
36                 elm_win_title_set(obj_window, name);
37                 elm_win_borderless_set(obj_window, EINA_TRUE);
38                 evas_object_smart_callback_add(obj_window, "delete,request",
39                                 _draglock_util_window_deleted_cb, NULL);
40                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &width,
41                                 &height);
42                 evas_object_resize(obj_window, width, height);
43                 elm_win_indicator_mode_set(obj_window, ELM_WIN_INDICATOR_SHOW);
44         }
45
46         return obj_window;
47 }
48
49 Evas_Object *draglock_util_add_bg(Evas_Object *window) {
50         Evas_Object *obj_background = NULL;
51
52         if (window == NULL) {
53                 return NULL;
54         }
55
56         obj_background = elm_bg_add(window);
57
58         if (obj_background != NULL) {
59                 evas_object_size_hint_weight_set(obj_background, EVAS_HINT_EXPAND,
60                                 EVAS_HINT_EXPAND);
61                 elm_object_style_set(obj_background, "transparent");
62
63                 elm_win_resize_object_add(window, obj_background);
64
65                 evas_object_show(obj_background);
66         }
67
68         return obj_background;
69 }
70
71 Evas_Object *draglock_util_add_layout(Evas_Object *parent, const char *file,
72                 const char *group) {
73         Evas_Object *layout = NULL;
74         Eina_Bool ret = EINA_FALSE;
75
76         if (parent == NULL) {
77                 DRAGLOCK_ERR("parent is NULL");
78                 return NULL;
79         }
80
81         layout = elm_layout_add(parent);
82         if (layout == NULL) {
83                 DRAGLOCK_ERR("layout is NULL");
84                 return NULL;
85         }
86
87         ret = elm_layout_file_set(layout, file, group);
88         DRAGLOCK_DBG("File:%s, Group:%s", file, group);
89         if (ret != EINA_TRUE) {
90                 DRAGLOCK_DBG("File:%s, Group:%s", file, group);
91                 evas_object_del(layout);
92                 return NULL;
93         }
94         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
95                         EVAS_HINT_EXPAND);
96         evas_object_show(layout);
97
98         return layout;
99 }
100
101 int draglock_init_svi(int *handle)
102 {
103         if (svi_init(handle) != SVI_SUCCESS) {
104                 DRAGLOCK_ERR("Cannot initialize SVI.");
105                 svi_fini(*handle);
106                 return -1;
107         }
108
109         return 0;
110 }
111
112 int draglock_fini_svi(int handle)
113 {
114         if (svi_fini(handle) != SVI_SUCCESS) {
115                 DRAGLOCK_ERR("[Error] Cannot get vconf\n");
116                 return -1;
117         }
118         return 0;
119 }
120
121
122 void draglock_play_sound(int handle, int unlock)
123 {
124         int ret = -1, val = 0;
125
126         ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, &val);
127         DRAGLOCK_DBG("val = %d", val);
128
129         if (ret == 0 && val == 1) {
130                 svi_play(handle, SVI_VIB_NONE,
131                          unlock ? SVI_SND_OPERATION_UNLOCK :
132                          SVI_SND_OPERATION_LOCK);
133         }
134 }
135