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