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