[Tizen 3.0] 2.4 source code merge
[apps/core/preloaded/quickpanel.git] / daemon / settings / settings_view_all.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
18 #include <Elementary.h>
19 #include <glib.h>
20
21 #include <notification.h>
22 #include <tzsh.h>
23 #include <tzsh_quickpanel_service.h>
24 #include <E_DBus.h>
25
26 #include "common.h"
27 #include "common_uic.h"
28 #include "quickpanel-ui.h"
29 #include "quickpanel_def.h"
30 #include "modules.h"
31 #include "preference.h"
32 #include "settings.h"
33 #include "setting_utils.h"
34 #include "settings_gridbox.h"
35 #include "setting_module_api.h"
36 #include "settings_view_all.h"
37 #include "pager.h"
38 #include "pager_common.h"
39 #include "page_setting_all.h"
40 #include "accessibility.h"
41
42 #ifdef QP_EMERGENCY_MODE_ENABLE
43 #include "emergency_mode.h"
44 #endif
45
46 static int _init(void *data);
47 static int _fini(void *data);
48 static int _resume(void *data);
49 static void _opened(void *data);
50 static void _closed(void *data);
51 static void _refresh(void *data);
52 static void _view_icons_add(void);
53 static void _view_icons_del(void);
54
55 QP_Module settings_view_all = {
56         .name = "settings_view_all",
57         .init = _init,
58         .fini = _fini,
59         .resume = _resume,
60         .qp_opened = _opened,
61         .qp_closed = _closed,
62         .refresh = _refresh,
63         .lang_changed = NULL,
64 };
65
66 static int _icons_rotation_set(int angle)
67 {
68         Evas_Object *icon = NULL;
69         Eina_List *icons = NULL;
70         Evas_Object *section = NULL;
71         Eina_List *l = NULL;
72         const char *signal = NULL;
73
74         retif(angle < 0, -1, "angle is %d", angle);
75
76         section = quickpanel_page_setting_all_view_get("ACTIVE.BUTTONS");
77         retif(!section, -1, "box is NULL");
78
79         icons = elm_box_children_get(section);
80         retif(!icons, -1, "icons list is NULL");
81
82         if (angle % 180 == 0) {
83                 signal = "icon.portrait";
84         } else {
85                 signal = "icon.landscape";
86         }
87
88         EINA_LIST_FOREACH(icons, l, icon) {
89                 elm_object_signal_emit(icon, signal, "quickpanl.prog");
90                 edje_object_message_signal_process(_EDJ(icon));
91         }
92
93         eina_list_free(icons);
94
95         return 0;
96 }
97
98 static Evas_Object *_icon_create(QP_Module_Setting *module, Evas_Object *parent) {
99         retif(module == NULL, NULL, "Invalid parameter!");
100         retif(parent == NULL, NULL, "Invalid parameter!");
101
102         return quickpanel_setting_module_icon_create(module, parent);
103 }
104
105 static Evas_Object *_divider_create(Evas_Object *parent) {
106         Evas_Object *divider = NULL;
107         retif(parent == NULL, NULL, "invalid parameter");
108
109         struct appdata *ad = (struct appdata*)quickpanel_get_app_data();
110         retif(ad == NULL, NULL, "application data is NULL");
111
112         divider = quickpanel_uic_load_edj(parent, DEFAULT_EDJ, "quickpanel/setting_icon_divider", 0);
113
114         retif(divider == NULL, NULL, "failed to load divider");
115
116         return divider;
117 }
118
119 static void _icon_pack(Evas_Object *gridbox, Evas_Object *icon, int need_divider)
120 {
121         Evas_Object *divider = NULL;
122         retif(gridbox == NULL, , "Invalid parameter!");
123         retif(icon == NULL, , "Invalid parameter!");
124
125         quickpanel_settings_gridbox_item_add(gridbox, icon, SETTINGS_GRIDBOX_ITEM_ICON, SETTINGS_GRIDBOX_APPEND);
126
127         if (need_divider == 1) {
128                 divider = _divider_create(gridbox);
129                 if (divider != NULL) {
130                         quickpanel_settings_gridbox_item_add(gridbox, divider,
131                                         SETTINGS_GRIDBOX_ITEM_DIVIDER, SETTINGS_GRIDBOX_APPEND);
132                 }
133         }
134 }
135
136 static void _view_icons_add(void)
137 {
138         int index = 0, total = 0;
139         Eina_List *l;
140         Eina_List *l_next;
141         Evas_Object *gridbox = NULL;
142         Evas_Object *icon = NULL;
143         QP_Module_Setting *module = NULL;
144         Eina_List *list_all_icon = NULL;
145         Evas_Object *layout = quickpanel_page_setting_all_view_get("LAYOUT");
146         retif(layout == NULL, , "Invalid parameter!");
147
148         quickpanel_settings_all_list_get(&list_all_icon);
149         retif(list_all_icon == NULL, , "Invalid parameter!");
150
151         gridbox = quickpanel_page_setting_all_view_get("ACTIVE.BUTTONS");
152         if (gridbox == NULL) {
153                 gridbox = quickpanel_settings_gridbox_create(layout, quickpanel_get_app_data());
154                 quickpanel_page_setting_all_view_set("ACTIVE.BUTTONS", gridbox);
155         }
156
157         total = eina_list_count(list_all_icon);
158         DBG("total:%d", total);
159         EINA_LIST_FOREACH_SAFE(list_all_icon, l, l_next, module) {
160                 icon = _icon_create(module, gridbox);
161                 if (icon != NULL) {
162                         _icon_pack(gridbox, icon, (index != total - 1) ? 1 : 0);
163                         quickpanel_setting_module_icon_add(module, icon, QP_SETTING_ICON_CONTAINER_ALL_LIST);
164                         quickpanel_setting_module_icon_status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
165                 }
166                 DBG("all list:%s", module->name);
167                 index++;
168         }
169
170         eina_list_free(list_all_icon);
171 }
172
173 static void _view_icons_del(void)
174 {
175         Eina_List *l;
176         Eina_List *l_next;
177         Evas_Object *icon = NULL;
178         QP_Module_Setting *module = NULL;
179         Eina_List *list_icons = NULL;
180         Evas_Object *box = quickpanel_page_setting_all_view_get("ACTIVE.BUTTONS");
181         retif(box == NULL, , "Invalid parameter!");
182
183         list_icons = elm_box_children_get(box);
184
185         EINA_LIST_FOREACH_SAFE(list_icons, l, l_next, icon) {
186                 module = quickpanel_setting_module_get_from_icon(icon);
187                 quickpanel_setting_module_icon_remove(module, icon);
188                 elm_box_unpack(box, icon);
189                 if (icon != NULL) {
190                         evas_object_del(icon);
191                         icon = NULL;
192                 }
193         }
194
195         eina_list_free(list_icons);
196 }
197
198 static int _view_create(void *data)
199 {
200         _view_icons_add();
201
202         return QP_OK;
203 }
204
205 static int _view_destroy(void *data)
206 {
207         _view_icons_del();
208
209         return QP_OK;
210 }
211
212 /*****************************************************************************
213  *
214  * Util functions
215  *
216  *****************************************************************************/
217 static int _init(void *data)
218 {
219         struct appdata *ad = (struct appdata *)data;
220         retif(ad == NULL, QP_FAIL, "Invalid parameter!");
221
222         _view_create(data);
223
224         return QP_OK;
225 }
226
227 static int _fini(void *data)
228 {
229         struct appdata *ad = (struct appdata *)data;
230         retif(ad == NULL, QP_FAIL, "Invalid parameter!");
231
232         _view_destroy(ad);
233
234         return QP_OK;
235 }
236
237 static int _resume(void *data)
238 {
239         struct appdata *ad = data;
240         retif(ad == NULL, QP_FAIL, "Invalid parameter!");
241
242         return QP_OK;
243 }
244
245 static void _opened(void *data)
246 {
247         struct appdata *ad = data;
248         retif(ad == NULL, , "Invalid parameter!");
249 }
250
251 static void _closed(void *data)
252 {
253         struct appdata *ad = data;
254         retif(ad == NULL, , "Invalid parameter!");
255 }
256
257 static void _refresh(void *data) {
258         struct appdata *ad = data;
259         retif(ad == NULL, , "Invalid parameter!");
260
261         _icons_rotation_set(ad->angle);
262 }
263
264 HAPI void quickpanel_setting_view_all_reload(Eina_List *list_all_module)
265 {
266         int index = 0, total = 0;
267         Eina_List *l;
268         Eina_List *l_next;
269         Evas_Object *gridbox = NULL;
270         Evas_Object *icon = NULL;
271         QP_Module_Setting *module = NULL;
272         retif(list_all_module == NULL, , "Invalid parameter!");
273
274         gridbox = quickpanel_page_setting_all_view_get("ACTIVE.BUTTONS");
275         retif(gridbox == NULL, , "Invalid parameter!");
276
277         quickpanel_settings_gridbox_unpack_all(gridbox);
278
279         total = eina_list_count(list_all_module);
280         DBG("total:%d", total);
281         EINA_LIST_FOREACH_SAFE(list_all_module, l, l_next, module) {
282                 if ((icon = quickpanel_setting_module_icon_get(module,
283                                                 QP_SETTING_ICON_CONTAINER_ALL_LIST)) == NULL) {
284                         icon = _icon_create(module, gridbox);
285                 }
286                 if (icon != NULL) {
287                         _icon_pack(gridbox, icon, (index != total - 1) ? 1 : 0);
288                         quickpanel_setting_module_icon_add(module, icon, QP_SETTING_ICON_CONTAINER_ALL_LIST);
289                         quickpanel_setting_module_icon_status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
290                 }
291                 DBG("all list:%s", module->name);
292                 index++;
293         }
294 }