Initialize Tizen 2.3
[apps/home/settings.git] / setting-privacy / src / setting-privacy-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-privacy-main.h>
22 //#include <package-manager.h>
23 #include <privacy_manager.h>
24 //#include <privacy_info.h>
25
26 static int setting_privacy_main_create(void *cb);
27 static int setting_privacy_main_destroy(void *cb);
28 static int setting_privacy_main_update(void *cb);
29 static int setting_privacy_main_cleanup(void *cb);
30
31 setting_view setting_view_privacy_main = {
32         .create = setting_privacy_main_create,
33         .destroy = setting_privacy_main_destroy,
34         .update = setting_privacy_main_update,
35         .cleanup = setting_privacy_main_cleanup,
36 };
37
38 typedef struct _PrivacyNode PrivacyNode;
39 struct _PrivacyNode
40 {
41         char* pkgname;  // ex) com.samsung.app
42         int state;              // 0:OFF, 1:ON
43 };
44
45
46 static int get_privacy_app(const char *appid, bool* status)
47 {
48         SETTING_TRACE_BEGIN;
49         //privacy_info_h handle;
50         return 0;
51 }
52 /*
53 static void __apps_list_cb(const pkgmgrinfo_pkginfo_h handler, void* data)
54 {
55         SettingPrivacyUG *ad = (SettingPrivacyUG *) data;
56
57         int r = 0;
58         char *pkg_name = NULL;
59         char *icon_path = NULL;
60         char *main_appid = NULL;
61         char *pkg_label = NULL;
62         bool    nodisplay = 0;
63         pkgmgrinfo_appinfo_h appinfo_h = NULL;
64
65         r = pkgmgrinfo_pkginfo_get_pkgid(handler, &pkg_name);
66         if(r < 0) {
67                 SETTING_TRACE_ERROR("pkgmgrinfo_pkginfo_get_pkgid is failed code[%d] ", r);
68                 goto end;
69         }
70         SETTING_TRACE("pkg_name: %s", pkg_name);
71
72         r = pkgmgrinfo_pkginfo_get_mainappid(handler, &main_appid);
73         if (r < 0) {
74                 SETTING_TRACE_ERROR("pkgmgrinfo_pkginfo_get_mainappid is failed code[%d]", r);
75                 goto end;
76         }
77         SETTING_TRACE("main_appid: %s", main_appid);
78
79         r = pkgmgrinfo_appinfo_get_appinfo(main_appid, &appinfo_h);
80         if (r < 0) {
81                 SETTING_TRACE_ERROR("pkgmgrinfo_appinfo_get_appinfo is failed code[%d]", r);
82                 goto end;
83         }
84
85         r = pkgmgrinfo_appinfo_is_nodisplay(appinfo_h, &nodisplay);
86         if (r < 0) {
87                 SETTING_TRACE_ERROR("pkgmgrinfo_appinfo_get_appinfo is failed code[%d]", r);
88                 goto end;
89         }
90
91         r = pkgmgrinfo_appinfo_get_label(appinfo_h, &pkg_label);
92         if (r < 0) {
93                 SETTING_TRACE_ERROR("pkgmgrinfo_appinfo_get_appinfo is failed code[%d]", r);
94                 goto end;
95         }
96
97         //PrivacyNode* node = (PrivacyNode*) malloc(sizeof(PrivacyNode));
98         //node->pkgname = strdup(pkg_name);
99         // TODO : free node->pkgname later
100
101         setting_create_Gendial_field_def(ad->genlist_privacy,
102                         &(ad->itc_2text_2),
103                         setting_privacy_main_list_Gendial_mouse_up_cb,
104                         ad,
105                         SWALLOW_Type_INVALID,
106                         NULL,
107                         NULL,
108                         0,
109                         pkg_label, pkg_name,
110                         NULL);
111
112         //ad->item_check_list = eina_list_append(ad->item_check_list, node);
113
114 end:
115         if (appinfo_h) {
116                 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
117         }
118
119         SETTING_TRACE_END;
120 }
121 */
122
123 /*
124 static void __info_cb(const privacy_info_h handler, void* data)
125 {
126         SETTING_TRACE_BEGIN;
127         SettingPrivacyUG *ad = (SettingPrivacyUG *) data;
128         bool    enabled = false;
129         char *privacy_id = NULL;
130         char *name = NULL;
131         char *description = NULL;
132
133         int r = privacy_info_is_enabled(handler, &enabled);
134         if(r < 0) {
135                 SETTING_TRACE_ERROR("privacy_info_is_enabled is failed code[%d] ", r);
136                 return;
137         }
138         SETTING_TRACE("check privacy_info_is_enabled 001");
139
140         if(enabled)
141         {
142                 r = privacy_info_get_privacy_id(handler, &privacy_id);
143                 if(r < 0) {
144                         SETTING_TRACE_ERROR("privacy_info_get_privacy_id is failed code[%d] ", r);
145                         return;
146                 }
147
148                 r = privacy_info_get_privacy_display_name(handler, &name);
149                 if(r < 0) {
150                         SETTING_TRACE_ERROR("privacy_info_get_privacy_display_name is failed code[%d] ", r);
151                         return;
152                 }
153
154                 r = privacy_info_get_privacy_description(handler, &description);
155                 if(r < 0) {
156                         SETTING_TRACE_ERROR("privacy_info_get_privacy_description is failed code[%d] ", r);
157                         return;
158                 }
159                 setting_create_Gendial_field_def(ad->genlist_privacy,
160                                 &(ad->itc_2text_2),
161                                 setting_privacy_main_list_Gendial_mouse_up_cb,
162                                 ad,
163                                 SWALLOW_Type_INVALID,
164                                 NULL,
165                                 NULL,
166                                 0,
167                                 name, description,
168                                 NULL);
169         }
170         SETTING_TRACE_END;
171 }
172
173 static void __apps_list_cb(const pkgmgrinfo_pkginfo_h handler, void* data)
174 {
175         SETTING_TRACE_BEGIN;
176         SettingPrivacyUG *ad = (SettingPrivacyUG *) data;
177
178         int r = 0;
179         char *pkg_name = NULL;
180         r = pkgmgrinfo_pkginfo_get_pkgid(handler, &pkg_name);
181         if(r < 0) {
182                 SETTING_TRACE_ERROR("pkgmgrinfo_pkginfo_get_pkgid is failed code[%d] ", r);
183                 return;
184         }
185         SETTING_TRACE("pkg_name [%s]",pkg_name);
186         privacy_manager_foreach_privacy_info(pkg_name, __info_cb, ad);
187         SETTING_TRACE_END;
188 }
189 */
190
191 static void __apps_list_cb(const char* package_id, void* data)
192 {
193         SETTING_TRACE_BEGIN;
194         SettingPrivacyUG *ad = (SettingPrivacyUG *) data;
195         SETTING_TRACE("package_id : %s", package_id);
196
197 }
198
199 /**
200  * get 3rd party applist from AIL & searching dir/file by the defined rule
201  * @param data ad
202  * if data is NULL --> just get how many items are there
203  * if data is NOT NULL --> draw UI code
204  */
205 static void setting_privacy_get_app_list(void* data)
206 {
207         SETTING_TRACE_BEGIN;
208         SettingPrivacyUG *ad = (SettingPrivacyUG *) data;
209
210         //int r = pkgmgrinfo_pkginfo_get_list(__apps_list_cb, ad);
211         int r = privacy_manager_foreach_privacy_packages(__apps_list_cb, ad);
212         if (0 != r) {
213                 SETTING_TRACE_ERROR("privacy_manager_foreach_privacy_packages failed. %d", r);
214         }
215 }
216
217
218 /* ***************************************************
219  **
220  **basic func
221  **
222  ****************************************************/
223 static int setting_privacy_main_create(void *cb)
224 {
225         SETTING_TRACE_BEGIN;
226         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
227
228         SettingPrivacyUG *ad = (SettingPrivacyUG *) cb;
229         Elm_Object_Item *item = NULL;
230         Evas_Object *scroller = NULL;
231         ad->ly_main =
232             setting_create_layout_navi_bar_genlist(ad->win_main_layout,
233                                                    ad->win_get,
234                                                    KeyStr_Privacy,
235                                                    _("IDS_COM_BODY_BACK"),
236                                                    NULL,
237                                                    setting_privacy_main_click_softkey_back_cb,
238                                                    NULL,
239                                                    ad,
240                                                    &scroller,
241                                                    &(ad->navi_bar));
242
243         /* separator */
244         item = elm_genlist_item_append(scroller , &itc_seperator, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
245         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
246
247         // init
248         //ad->item_check_list = NULL;
249
250         ad->genlist_privacy = scroller;
251         // get_applist
252         setting_privacy_get_app_list(ad);
253
254         /* separator */
255         item = elm_genlist_item_append(scroller , &itc_bottom_seperator, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
256         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
257
258         /* update info */
259         setting_view_privacy_main.is_create = 1;
260         return SETTING_RETURN_SUCCESS;
261 }
262
263 static int setting_privacy_main_destroy(void *cb)
264 {
265         SETTING_TRACE_BEGIN;
266         /* error check */
267         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
268         SettingPrivacyUG *ad = (SettingPrivacyUG *) cb;
269
270         elm_naviframe_item_pop(ad->navi_bar);
271         setting_view_privacy_main.is_create = 0;
272         return SETTING_RETURN_SUCCESS;
273 }
274
275 static int setting_privacy_main_update(void *cb)
276 {
277         SETTING_TRACE_BEGIN;
278         /* error check */
279         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
280         SettingPrivacyUG *ad = (SettingPrivacyUG *) cb;
281
282         /* to do */
283         /* update genlist when list add or delete */
284         return SETTING_RETURN_SUCCESS;
285 }
286
287 static int setting_privacy_main_cleanup(void *cb)
288 {
289         SETTING_TRACE_BEGIN;
290         /* error check */
291         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
292
293         SettingPrivacyUG *ad = (SettingPrivacyUG *) cb;
294         return setting_privacy_main_destroy(ad);
295 }
296
297 /* ***************************************************
298  **
299  **call back func
300  **
301  ****************************************************/
302 static void setting_privacy_main_click_softkey_back_cb(void *data, Evas_Object *obj,
303                                             void *event_info)
304 {
305         SETTING_TRACE_BEGIN;
306         /* error check */
307         retm_if(data == NULL, "Data parameter is NULL");
308         SettingPrivacyUG *ad = (SettingPrivacyUG *) data;
309
310         /* Send destroy request */
311         ug_destroy_me(ad->ug);
312         SETTING_TRACE_END;
313 }
314
315 static void setting_privacy_main_list_Gendial_mouse_up_cb(void *data, Evas_Object *obj,
316                                                   void *event_info)
317 {
318         /* error check */
319         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
320         //Elm_Object_Item *item = (Elm_Object_Item *) event_info;
321         //elm_genlist_item_selected_set(item, 0);
322         //Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
323         //change view to privacy services
324 }
325