bc37b5600d22e23ce6dcdb9b2a8e54e697d13bb4
[apps/home/volume-app.git] / src / _button.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
18 #include <ui-gadget.h>
19 #include <vconf.h>
20
21 #include "_util_log.h"
22 #include "volume.h"
23 #include "_sound.h"
24 #include "_logic.h"
25
26 enum {
27         IDLELOCK_OFF = 0x0,
28         IDLELOCK_ON,
29         IDLELOCK_MAX,
30 };
31
32 static void button_ug_layout_cb(ui_gadget_h ug,
33                 enum ug_mode mode, void *priv)
34 {
35         Evas_Object *base = NULL;
36         Evas_Object *win = NULL;
37
38         base = ug_get_layout(ug);
39         win = ug_get_window();
40
41         retm_if(ug == NULL, "ug_get_layout API is failed\n");
42         retm_if(ug == NULL, "ug_get_window API is failed\n");
43
44         switch (mode) {
45                 case UG_MODE_FULLVIEW:
46                         evas_object_size_hint_weight_set(base,
47                                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
48                         elm_win_resize_object_add(win, base);
49                         evas_object_show(base);
50                         break;
51                 default:
52                         break;
53         }
54 }
55
56 static void button_ug_destroy_cb(ui_gadget_h ug, void *priv)
57 {
58         _D("%s\n", __func__);
59         struct appdata *ad = (struct appdata *)priv;
60         retm_if(ug == NULL, "Invalid argument: ug is NULL\n");
61
62         /* ug_destroy 0 : success, -1 : fail */
63         _D("%d\n", ug_destroy(ug));
64         ad->ug = NULL;
65
66         ecore_x_netwm_window_type_set(elm_win_xwindow_get(ad->win), ECORE_X_WINDOW_TYPE_NOTIFICATION);
67         utilx_set_window_opaque_state(ecore_x_display_get(), elm_win_xwindow_get(ad->win), UTILX_OPAQUE_STATE_OFF);
68         elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_HIDE);
69
70         _close_volume(ad);
71 }
72
73 ui_gadget_h create_button_ug(void *data)
74 {
75         ui_gadget_h ug = NULL;
76         struct ug_cbs cbs = {0};
77         struct appdata *ad = (struct appdata *)data;
78         int vconf_status = -1;
79         int lock = -1, type = -1;
80         retvm_if(ad == NULL, 0, "Invalid argument:appdata is NULL\n");
81
82         cbs.layout_cb = button_ug_layout_cb;
83         cbs.destroy_cb = button_ug_destroy_cb;
84         cbs.priv = (void *)data;
85
86         vconf_get_int(VCONFKEY_PWLOCK_STATE, &vconf_status);
87
88         lock = _get_vconf_idlelock();
89         type = _get_volume_type();
90
91         if(vconf_status == VCONFKEY_PWLOCK_BOOTING_LOCK || (lock == IDLELOCK_ON && type == VOLUME_TYPE_MEDIA)){
92                 ecore_x_netwm_window_type_set(elm_win_xwindow_get(ad->win), ECORE_X_WINDOW_TYPE_NOTIFICATION);
93         }
94         else{
95                 ecore_x_netwm_window_type_set(elm_win_xwindow_get(ad->win), ECORE_X_WINDOW_TYPE_NORMAL);
96         }
97         utilx_set_window_opaque_state(ecore_x_display_get(), elm_win_xwindow_get(ad->win), UTILX_OPAQUE_STATE_ON);
98         ug = ug_create(NULL, "setting-profile-efl", UG_MODE_FULLVIEW, NULL, &cbs);
99
100         ecore_x_e_illume_quickpanel_state_send(ecore_x_e_illume_zone_get(elm_win_xwindow_get(ad->win)),
101                 ECORE_X_ILLUME_QUICKPANEL_STATE_OFF);
102
103         return ug;
104 }
105
106 int _open_ug(void *data)
107 {
108         struct appdata *ad = (struct appdata *)data;
109         ui_gadget_h ug= NULL;
110
111         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
112         retvm_if(ad->win == NULL, -1, "Invalid argument: window is NULL\n");
113
114         UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_PORTRAIT_ONLY);
115         elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
116         ug = create_button_ug(ad);
117         _ungrab_key(ad);
118
119         retvm_if(ug == NULL, -1, "Failed to Create ug!\n");
120
121         ad->ug = ug;
122
123         return 0;
124 }