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