cca277711a3dfdce25c1f4dbb615e1c5c755a934
[apps/core/preloaded/settings.git] / setting-menuscreen / src / setting-menuscreen-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-menuscreen-main.h>
22 #include <setting-common-draw-widget.h>
23 #include <Ecore_X.h>
24
25 static int setting_menuscreen_main_create(void *cb);
26 static int setting_menuscreen_main_destroy(void *cb);
27 static int setting_menuscreen_main_update(void *cb);
28 static int setting_menuscreen_main_cleanup(void *cb);
29
30
31 // BUSINESS LOGIC  ---
32 static void _get_menuscreen_info2(/*[OUT]*/int* pkglist_cnt, void* data);
33 ail_cb_ret_e appinfo_menuscreen_func(const ail_appinfo_h appinfo, void *user_data);
34 // BUSINESS LOGIC  ---
35 static void setting_menuscreen_main_click_softkey_back_cb(void *data, Evas_Object *obj, void *event_info);
36
37 static void setting_menuscreen_mouse_up_Gendial_list_radio_cb(void *data, Evas_Object *obj, void *event_info);
38
39 setting_view setting_view_menuscreen_main = {
40         .create = setting_menuscreen_main_create,
41         .destroy = setting_menuscreen_main_destroy,
42         .update = setting_menuscreen_main_update,
43         .cleanup = setting_menuscreen_main_cleanup,
44 };
45
46 static int setting_menuscreen_main_create(void *cb)
47 {
48         SETTING_TRACE_BEGIN;
49         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
50         SettingMenuscreenUG *ad = (SettingMenuscreenUG *) cb;
51         Evas_Object *scroller = NULL;
52         ad->ly_main =
53             setting_create_layout_navi_bar_genlist(ad->win_main_layout,
54                                                    ad->win_get,
55                                                    _("IDS_ST_HEADER_HOME_SCREEN_ABB"), _("IDS_COM_BODY_BACK"),
56                                                    NULL,
57                                                    setting_menuscreen_main_click_softkey_back_cb,
58                                                    NULL, ad, &scroller,
59                                                    &(ad->navi_bar));
60
61         Elm_Object_Item *item = NULL;
62         item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
63                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
64         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
65
66         int* pkglist_cnt = &ad->pkglist_cnt;
67
68         _get_menuscreen_info2(pkglist_cnt, ad);
69
70         // radio button
71         ad->chk_radio = elm_radio_add(scroller);
72         elm_radio_state_value_set(ad->chk_radio, -1);
73
74         Setting_GenGroupItem_Data *item_data = NULL;
75         Eina_List* elist = NULL;
76         ug_menuscreen_info* pnode = NULL;
77         int idx = 0;
78         char *sel_str = vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME);
79
80         EINA_LIST_FOREACH( ad->menuscreen_list, elist, pnode)
81         {
82                 item_data = setting_create_Gendial_field_2radio(scroller,
83                                                         &(ad->itc_1text_1icon_2),
84                                                         setting_menuscreen_mouse_up_Gendial_list_radio_cb,
85                                                         ad->chk_radio,
86                                                         SWALLOW_Type_1RADIO,
87                                                         ad->chk_radio,
88                                                         idx,
89                                                         pnode->appname,
90                                                         pnode->pkgname,
91                                                          NULL);
92
93                 if (item_data) {
94                         item_data->userdata = ad;
95                 } else {
96                         SETTING_TRACE_ERROR("item_data is NULL");
97                 }
98                 SETTING_TRACE("pkgname[%s] sel_str[%s]", pnode->pkgname, sel_str);
99                 if (0 == safeStrCmp(pnode->pkgname, sel_str))
100                 {
101                         elm_radio_value_set(ad->chk_radio, idx);
102                 }
103
104                 idx++;
105         }
106         FREE(sel_str);
107
108
109         setting_view_menuscreen_main.is_create = 1;
110         return SETTING_RETURN_SUCCESS;
111 }
112
113 static int setting_menuscreen_main_destroy(void *cb)
114 {
115         SETTING_TRACE_BEGIN;
116         /* error check */
117         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
118
119         SettingMenuscreenUG *ad = (SettingMenuscreenUG *) cb;
120
121         if (ad->ly_main != NULL) {
122                 evas_object_del(ad->ly_main);
123                 /* if(ad->back_dialData) FREE(ad->back_dialData); */
124                 setting_view_menuscreen_main.is_create = 0;
125         }
126
127         return SETTING_RETURN_SUCCESS;
128 }
129
130 static int setting_menuscreen_main_update(void *cb)
131 {
132         SETTING_TRACE_BEGIN;
133         /* error check */
134         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
135
136         return SETTING_RETURN_SUCCESS;
137 }
138
139 static int setting_menuscreen_main_cleanup(void *cb)
140 {
141         SETTING_TRACE_BEGIN;
142         /* error check */
143         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
144
145         SettingMenuscreenUG *ad = (SettingMenuscreenUG *) cb;
146
147         if (ad->ly_main != NULL) {
148                 /*         evas_object_hide(ad->ly_main); */
149         }
150
151         return SETTING_RETURN_SUCCESS;
152 }
153
154 /* ***************************************************
155  *
156  *general func
157  *
158  ***************************************************/
159
160 static void
161 setting_menuscreen_main_click_softkey_back_cb(void *data, Evas_Object *obj,
162                                            void *event_info)
163 {
164         SETTING_TRACE_BEGIN;
165         /* error check */
166         setting_retm_if(data == NULL,
167                         "[Setting > Menuscreen] Data parameter is NULL");
168
169         SettingMenuscreenUG *ad = (SettingMenuscreenUG *) data;
170
171         /* Send destroy request */
172         ug_destroy_me(ad->ug);
173         SETTING_TRACE_END;
174
175 }
176
177
178 static void _get_menuscreen_info2(/*[OUT]*/int* pkglist_cnt, void* data)
179 {
180         SETTING_TRACE_BEGIN;
181         SettingMenuscreenUG *ugd = (SettingMenuscreenUG *) data;
182
183     ail_filter_h filter;
184     ail_error_e ret;
185     // int i=0;
186      int n=0;
187
188     ret = ail_filter_new(&filter);
189     if (ret != AIL_ERROR_OK) {
190         return ;
191     }
192
193     ret = ail_filter_count_appinfo(filter, &n);
194     //printf("count =%d \n", n);
195     *pkglist_cnt = n;
196
197     ret = ail_filter_add_str(filter, AIL_PROP_CATEGORIES_STR, "home-screen");
198     if (ret != AIL_ERROR_OK) {
199         return ;
200     }
201
202     ail_filter_list_appinfo_foreach(filter, appinfo_menuscreen_func, (void *)ugd);
203     ail_filter_destroy(filter);
204 }
205
206 /*
207     /opt/home/root/aaa/cprog/ail_test # ./ail_test
208     i=0 List Menu
209     i=1 BEAT
210 */
211 ail_cb_ret_e appinfo_menuscreen_func(const ail_appinfo_h appinfo, void *user_data)
212 {
213         SETTING_TRACE_BEGIN;
214         SettingMenuscreenUG *ugd = (SettingMenuscreenUG *) user_data;
215
216     char *package;
217     char *appname;
218     static int s_i = 0 ;
219
220     ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
221     ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &appname);
222
223     Eina_List** d_menuscreen_list = &ugd->menuscreen_list;
224
225     ug_menuscreen_info* pnode = (ug_menuscreen_info*)malloc(sizeof(ug_menuscreen_info));
226     pnode->pkgname = strdup(package);
227     pnode->appname = strdup(appname);
228
229     SETTING_TRACE(" >>>>>>>>>> s_i=%d %s\n", s_i++, package);
230
231     *d_menuscreen_list = eina_list_append(*d_menuscreen_list, pnode);
232
233     if (s_i > 30)
234         return AIL_CB_RET_CANCEL;
235
236     return AIL_CB_RET_CONTINUE;
237 }
238
239 static void setting_menuscreen_mouse_up_Gendial_list_radio_cb(void *data, Evas_Object *obj, void *event_info)
240 {
241         SETTING_TRACE_BEGIN;
242         /* error check */
243         setting_retm_if(data == NULL, "Data parameter is NULL");
244         setting_retm_if(event_info == NULL, "Invalid argument: event info is NULL");
245
246         Evas_Object *radio = (Evas_Object *) data;
247         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
248         elm_genlist_item_selected_set(item, 0);
249
250         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
251         if (list_item->chk_status == elm_radio_value_get(radio))
252         {//select the same item
253                 return;
254         }
255
256         SettingMenuscreenUG *ad = (SettingMenuscreenUG *) list_item->userdata;
257
258         SETTING_TRACE("---------------------------------------------");
259         SETTING_TRACE("chk_status = %d ", list_item->chk_status);
260         SETTING_TRACE("sub_desc= %s", list_item->sub_desc);
261         SETTING_TRACE("KeyStr= %s", list_item->keyStr);
262         SETTING_TRACE("---------------------------------------------");
263
264         // store list_itemdata
265         ad->selected_theme = list_item->sub_desc;
266
267         if ( 0 == strcmp(list_item->sub_desc, SETTING_THEME_LIVE_MAGAZINE))
268         {
269                 setting_view_change(&setting_view_menuscreen_main, &setting_view_menuscreen_password, ad);
270                 return;
271         } 
272         else if (0 == strcmp(list_item->sub_desc, SETTING_THEME_CLUSTER_HOME))
273         {
274                 setting_view_change(&setting_view_menuscreen_main, &setting_view_menuscreen_password, ad);
275                 return;
276         }
277         else {
278                 elm_radio_value_set(radio, list_item->chk_status);
279                 vconf_set_str( VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, ad->selected_theme);
280         }
281         ug_destroy_me(ad->ug);
282 }
283
284