Merge "modified default wallpaper image for Tizen setting" into 2.0_beta
[apps/core/preloaded/settings.git] / setting-livebox / src / setting-livebox-main.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-livebox.h>
22 #include <setting-livebox-main.h>
23 #include <setting-common-data-slp-setting.h>
24 #include <setting-debug.h>
25
26 static int setting_livebox_main_create(void *cb);
27 static int setting_livebox_main_destroy(void *cb);
28 static int setting_livebox_main_update(void *cb);
29 static int setting_livebox_main_cleanup(void *cb);
30
31 setting_view setting_view_livebox_main = {
32         .create = setting_livebox_main_create,
33         .destroy = setting_livebox_main_destroy,
34         .update = setting_livebox_main_update,
35         .cleanup = setting_livebox_main_cleanup,
36 };
37
38 /* ***************************************************
39  *
40  *basic func
41  *
42  ***************************************************/
43
44 static void setting_livebox_main_sk_done_cb(void *data, Evas_Object *obj, void *event_info)
45 {
46         SETTING_TRACE_BEGIN;
47         /* error check */
48         ret_if(data == NULL);
49
50         SettingLiveboxUG *ad = (SettingLiveboxUG *)data;
51
52         /* send information of selected items to live-setting */
53         if(ad->select_count > 0)
54         {
55                 SETTING_TRACE_DEBUG("select_count : %u", ad->select_count);
56                 int idx = 0;
57                 int check_count = 0;
58                 char *result_array[MAX_SELECTION_NUM*2];
59                 service_h svc;
60
61                 if (service_create(&svc)) {
62                         return;
63                 }
64
65                 for(; idx < ad->menu_count; idx++)
66                 {
67                         if(ad->item[idx]->chk_status)
68                         {
69                                 if(check_count > ad->select_count)
70                                 {
71                                         SETTING_TRACE_DEBUG("exceed count: %u", check_count);
72                                         break;
73                                 }
74                                 SETTING_TRACE_DEBUG("item[%u] is checked", idx);
75                                 result_array[check_count*2] = setting_gettext(ad->item[idx]->keyStr);
76                                 result_array[check_count*2+1] = (char *)ad->item[idx]->r_swallow_path;
77                                 SETTING_TRACE_DEBUG("app_name : %s, icon_path : %s", result_array[check_count*2], result_array[check_count*2+1]);
78                                 check_count++;
79                         }
80                 }
81                 service_add_extra_data_array(svc, "result", (const char**)result_array, ad->select_count*2);
82                 ug_send_result(ad->ug, svc);
83
84                 service_destroy(svc);
85         }
86         /* Send destroy request */
87         ug_destroy_me(ad->ug);
88 }
89
90 static void setting_livebox_main_sk_cancel_cb(void *data, Evas_Object *obj, void *event_info)
91 {
92         SETTING_TRACE_BEGIN;
93         /* error check */
94         ret_if(data == NULL);
95
96         SettingLiveboxUG *ad = (SettingLiveboxUG *)data;
97         /* Send destroy request */
98         ug_destroy_me(ad->ug);
99 }
100
101 static void __searchbar_changed_cb(void *data, Evas_Object *obj, void *event_info)
102 {
103         SETTING_TRACE_BEGIN;
104         setting_retm_if(data == NULL, "Data parameter is NULL");
105 #if DISABLED_CODE
106         SettingLiveboxUG *ad = (SettingLiveboxUG *)data;
107
108         setting_searchbar_redraw(ad, ad->search_bar, NULL/*ad->search_text*/,
109                                  &(ad->search_idler),
110                                  NULL); //__region_genlist_update);
111 #endif
112 }
113
114 static void __create_navibar(void *data, Evas_Object *content, Evas_Object *navibar, Evas_Object *controlbar)
115 {
116         SETTING_TRACE_BEGIN;
117         ret_if(data == NULL || content == NULL || navibar == NULL);
118
119         SettingLiveboxUG *ad = (SettingLiveboxUG *)data;
120
121         setting_create_navi_bar_buttons("Customize setting Livebox",
122                                                                         "Done", "Cancel", NULL,
123                                                                         setting_livebox_main_sk_done_cb,
124                                                                         setting_livebox_main_sk_cancel_cb,
125                                                                         NULL,
126                                                                         ad, content, navibar, controlbar);
127 }
128
129 static int __create_frame(void *data)
130 {
131         SETTING_TRACE_BEGIN;
132         retv_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
133
134         SettingLiveboxUG *ad = (SettingLiveboxUG *)data;
135         Evas_Object *navi_bar = NULL;
136         Evas_Object *control_bar = NULL;
137
138         Evas_Object *content_list = elm_genlist_add(ad->win_main_layout);
139         elm_object_style_set(content_list, "dialogue");
140         if(content_list == NULL)
141                 return SETTING_RETURN_FAIL;
142
143         elm_genlist_clear(content_list);        /* first to clear list */
144         elm_genlist_mode_set(content_list, ELM_LIST_COMPRESS);
145
146         ad->ly_main = setting_create_win_layout(ad->win_main_layout, ad->win_get);
147         retv_if(!ad->ly_main, SETTING_RETURN_FAIL);
148
149         navi_bar = setting_create_navi_bar(ad->ly_main);
150         retv_if(!navi_bar, SETTING_RETURN_FAIL);
151         Evas_Object *sub_layout = elm_layout_add(navi_bar);
152         elm_layout_theme_set(sub_layout, "layout", "application", "searchbar_base");
153         elm_object_signal_emit(sub_layout, "elm,state,show,searchbar", "elm");
154         elm_object_part_content_set(sub_layout, "elm.swallow.content", content_list);
155
156         ad->search_bar = setting_create_searchbar(ad, sub_layout, __searchbar_changed_cb, NULL);
157
158         control_bar = elm_toolbar_add(navi_bar);
159         setting_retvm_if(control_bar == NULL, -1, "controlbar == NULL");
160         elm_toolbar_shrink_mode_set(control_bar, ELM_TOOLBAR_SHRINK_EXPAND);
161
162         __create_navibar(ad, sub_layout, navi_bar, control_bar);
163
164         ad->navi_bar = navi_bar;
165         ad->navi_it = elm_naviframe_top_item_get(ad->navi_bar);
166         ad->sub_layout = sub_layout;
167         ad->scroller = content_list;
168
169         return SETTING_RETURN_SUCCESS;
170 }
171
172 static void
173 setting_livebox_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info)
174 {
175         SETTING_TRACE_BEGIN;
176
177         if(data == NULL)
178                 return;
179         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
180
181         SettingLiveboxUG *ad = (SettingLiveboxUG*)data;
182         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
183         elm_genlist_item_selected_set(item, 0);
184
185         Setting_GenGroupItem_Data *list_item =
186             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
187
188         SETTING_TRACE_DEBUG("%s selected", list_item->keyStr);
189
190         int current_status = elm_check_state_get(list_item->eo_check);
191
192         if((current_status == 0) && (ad->select_count < MAX_SELECTION_NUM))
193         {
194                 elm_check_state_set(list_item->eo_check, 1);
195                 list_item->chk_status = 1;
196                 ad->select_count++;
197                 // show selection Info : "selected %u items"
198         }
199         else if(current_status == 0)
200         {
201                 // show popup : "be over the count, 4"
202         }
203         else if((current_status == 1) && (ad->select_count > 0))
204         {
205                 elm_check_state_set(list_item->eo_check, 0);
206                 list_item->chk_status = 0;
207                 ad->select_count--;
208         }
209         else
210         {
211                 // nothing to be selected.
212         }
213         SETTING_TRACE_DEBUG("select_count : %u", ad->select_count);
214 }
215
216 static void
217 setting_livebox_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info)
218 {
219         SETTING_TRACE_BEGIN;
220
221         if(data == NULL)
222                 return;
223
224         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
225         SettingLiveboxUG *ad = list_item->userdata;
226
227         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
228
229         if((list_item->chk_status == 1) && (ad->select_count < MAX_SELECTION_NUM))
230         {
231                 ad->select_count++;
232                 // show selection Info : "selected %u items"
233         }
234         else if(list_item->chk_status == 1)
235         {
236                 // recover status of checkbox
237                 // And show popup : "be over the count, 4"
238                 elm_check_state_set(obj, 0);
239                 list_item->chk_status = elm_check_state_get(obj);
240         }
241         else if((list_item->chk_status == 0) && (ad->select_count > 0))
242         {
243                 ad->select_count--;
244         }
245         else
246         {
247                 // nothing to be selected.
248         }
249         SETTING_TRACE_DEBUG("select_count : %u", ad->select_count);
250 }
251
252 void setting_livebox_add_genlist_items(void *data)
253 {
254         SETTING_TRACE_BEGIN;
255         if(data == NULL)
256                 return;
257
258         SettingLiveboxUG *ad = (SettingLiveboxUG*)data;
259
260         int i = 0;
261         int j = 0;
262         int cnt = 0;
263         char *keyStr = NULL;
264         char *icon_path = NULL;
265
266         // itc_sel_all
267
268         for (i = 0; i < setting_cfg_get_category_length(); i++)
269         {
270                 SETTING_TRACE_DEBUG("category name : %s", setting_cfg_get_category_name(i));
271                 if (safeStrCmp(setting_cfg_get_category_name(i), KeyStr_Connectivity) == 0)
272                 {
273                         (void)setting_create_Gendial_field_titleItem(ad->scroller,
274                                                      &(itc_group_item),
275                                                      KeyStr_Connectivity, NULL);
276
277                         for (j = 0; j < setting_cfg_get_menu_length(i); j++)
278                         {
279                                 keyStr = setting_cfg_get_keyname_idx(i, j);
280                                 SETTING_TRACE_DEBUG("menu name : [%d] %s", j, keyStr);
281                                 icon_path = setting_cfg_get_icon_path_idx(i, j);
282
283                                 ad->item[cnt] = setting_create_Gendial_field_def(ad->scroller, &(itc_1text_1icon_2),
284                                                                                         setting_livebox_main_mouse_up_Gendial_list_cb, NULL,
285                                                                                         SWALLOW_Type_1CHECKICON,
286                                                                                         NULL, icon_path, 0, keyStr, NULL,
287                                                                                         setting_livebox_main_chk_btn_cb);
288                                 if(ad->item[cnt])
289                                         ad->item[cnt++]->userdata = ad;
290                         }
291                         continue;
292                 }
293                 else if (safeStrCmp(setting_cfg_get_category_name(i), KeyStr_System) == 0)
294                 {
295                         (void)setting_create_Gendial_field_titleItem(ad->scroller,
296                                                      &(itc_group_item),
297                                                      KeyStr_System, NULL);
298                         for (j = 0; j < setting_cfg_get_menu_length(i); j++)
299                         {
300                                 keyStr = setting_cfg_get_keyname_idx(i, j);
301                                 SETTING_TRACE_DEBUG("menu name : [%d] %s", j, keyStr);
302                                 icon_path = setting_cfg_get_icon_path_idx(i, j);
303
304                                 ad->item[cnt] = setting_create_Gendial_field_def(ad->scroller, &(itc_1text_1icon_2),
305                                                                                         setting_livebox_main_mouse_up_Gendial_list_cb, NULL,
306                                                                                         SWALLOW_Type_1CHECKICON,
307                                                                                         NULL, icon_path, 0, keyStr, NULL,
308                                                                                         setting_livebox_main_chk_btn_cb);
309                                 ad->item[cnt++]->userdata = ad;
310                         }
311                         continue;
312                 }
313                 else if (safeStrCmp(setting_cfg_get_category_name(i), KeyStr_Applications) == 0)
314                 {
315                         (void)setting_create_Gendial_field_titleItem(ad->scroller,
316                                                      &(itc_group_item),
317                                                      KeyStr_Applications, NULL);
318                         for (j = 0; j < setting_cfg_get_menu_length(i); j++)
319                         {
320                                 keyStr = setting_cfg_get_keyname_idx(i, j);
321                                 SETTING_TRACE_DEBUG("menu name : [%d] %s", j, keyStr);
322                                 icon_path = setting_cfg_get_icon_path_idx(i, j);
323
324                                 ad->item[cnt] = setting_create_Gendial_field_def(ad->scroller, &(itc_1text_1icon_2),
325                                                                                         setting_livebox_main_mouse_up_Gendial_list_cb, NULL,
326                                                                                         SWALLOW_Type_1CHECKICON,
327                                                                                         NULL, icon_path, 0, keyStr, NULL,
328                                                                                         setting_livebox_main_chk_btn_cb);
329                                 ad->item[cnt++]->userdata = ad;
330                         }
331                         continue;
332                 }
333                 else if (safeStrCmp(setting_cfg_get_category_name(i), KeyStr_DownloadedAPPs) == 0)
334                 {
335                         (void)setting_create_Gendial_field_titleItem(ad->scroller,
336                                                      &(itc_group_item),
337                                                      KeyStr_DownloadedAPPs, NULL);
338                         for (j = 0; j < setting_cfg_get_menu_length(i); j++)
339                         {
340                                 keyStr = setting_cfg_get_keyname_idx(i, j);
341                                 SETTING_TRACE_DEBUG("menu name : [%d] %s", j, keyStr);
342                                 icon_path = setting_cfg_get_icon_path_idx(i, j);
343
344                                 ad->item[cnt] = setting_create_Gendial_field_def(ad->scroller, &(itc_1text_1icon_2),
345                                                                                         setting_livebox_main_mouse_up_Gendial_list_cb, NULL,
346                                                                                         SWALLOW_Type_1CHECKICON,
347                                                                                         NULL, icon_path, 0, keyStr, NULL,
348                                                                                         setting_livebox_main_chk_btn_cb);
349                                 ad->item[cnt++]->userdata = ad;
350                         }
351                         continue;
352                 }
353         }
354         ad->menu_count = cnt;
355         SETTING_TRACE_DEBUG("total : %u menues ", ad->menu_count);
356 }
357
358 static int
359 setting_livebox_main_create(void *cb)
360 {
361         SETTING_TRACE_BEGIN;
362         /* error check */
363         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
364
365         SettingLiveboxUG *ad = (SettingLiveboxUG *) cb;
366         int ret = 0;
367
368         ret = __create_frame(ad);
369
370         if(ret < 0)
371                 return SETTING_RETURN_FAIL;
372
373         setting_livebox_add_genlist_items(ad);
374
375         setting_view_livebox_main.is_create = 1;
376         SETTING_TRACE_END;
377         return SETTING_RETURN_SUCCESS;
378 }
379
380 static int setting_livebox_main_destroy(void *cb)
381 {
382         /* error check */
383         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
384
385         SettingLiveboxUG *ad = (SettingLiveboxUG *) cb;
386
387         if (ad->ly_main != NULL) {
388                 evas_object_del(ad->ly_main);
389                 ad->ly_main = NULL;
390                 setting_view_livebox_main.is_create = 0;
391         }
392         return SETTING_RETURN_SUCCESS;
393 }
394
395 static int setting_livebox_main_update(void *cb)
396 {
397         /* error check */
398         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
399
400         SettingLiveboxUG *ad = (SettingLiveboxUG *) cb;
401
402         if (ad->ly_main != NULL) {
403                 evas_object_show(ad->ly_main);
404         }
405
406         return SETTING_RETURN_SUCCESS;
407 }
408
409 static int setting_livebox_main_cleanup(void *cb)
410 {
411         /* error check */
412         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
413
414         SettingLiveboxUG *ad = (SettingLiveboxUG *) cb;
415
416         if (ad->ly_main != NULL) {
417                 evas_object_hide(ad->ly_main);
418         }
419
420         return SETTING_RETURN_SUCCESS;
421 }