4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <setting-common-data-type.h>
22 #include <setting-common-data-slp-setting.h>
23 #include <setting-common-draw-widget.h>
24 #include <setting-common-view.h>
26 #include <setting-security-locktype.h>
27 #include <setting-security.h>
28 #include <setting-debug.h>
30 #include <pkgmgr-info.h>
34 static int setting_security_locktype_create(void *cb);
35 static int setting_security_locktype_destroy(void *cb);
36 static int setting_security_locktype_update(void *cb);
37 static int setting_security_locktype_cleanup(void *cb);
38 setting_view setting_view_security_locktype = {
39 .create = setting_security_locktype_create,
40 .destroy = setting_security_locktype_destroy,
41 .update = setting_security_locktype_update,
42 .cleanup = setting_security_locktype_cleanup,
45 openlock_appdata *lockapp_data = NULL;
47 /* ***************************************************
51 ****************************************************/
53 static int __get_lockapp_index_from_pkgname(char *pkg_name)
57 return SETTING_RETURN_FAIL;
59 openlock_appdata *item = lockapp_data;
60 for(; item != NULL; item = item->next)
62 if(safeStrCmp(item->pkg_name, pkg_name) == 0)
65 return SETTING_RETURN_FAIL;
67 static int __get_lockapp_index_from_appname(char *app_name)
71 return SETTING_RETURN_FAIL;
73 openlock_appdata *item = lockapp_data;
74 for(; item != NULL; item = item->next)
76 if(safeStrCmp(item->app_name, app_name) == 0)
79 return SETTING_RETURN_FAIL;
81 static char* __get_lockapp_pkgname_from_appname(char *app_name)
87 openlock_appdata *item = lockapp_data;
88 for(; item != NULL; item = item->next)
90 if(safeStrCmp(item->app_name, app_name) == 0)
91 return item->app_name;
96 ail_cb_ret_e __get_appinfo_cb(const ail_appinfo_h appinfo, void *user_data)
100 openlock_appdata *item = lockapp_data;
101 openlock_appdata *new_item = NULL;
102 char *pkg_name = NULL;
103 char *app_name = NULL;
105 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &pkg_name);
106 ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &app_name);
108 while(item->next != NULL)
111 if(item->index == 0 && item->pkg_name == NULL)
114 item->pkg_name = strdup(pkg_name);
115 item->app_name = strdup(app_name);
117 SETTING_TRACE_DEBUG("app info %d %s %s", item->index, item->pkg_name, item->app_name);
122 new_item = (openlock_appdata*)malloc(sizeof(openlock_appdata));
125 memset(new_item, 0x00, sizeof(openlock_appdata));
126 new_item->pkg_name = strdup(pkg_name);
127 new_item->app_name = strdup(app_name);
128 new_item->index = item->index + 1;
129 new_item->prev = item;
130 item->next = new_item;
132 SETTING_TRACE_DEBUG("app info %d %s %s", new_item->index, new_item->pkg_name, new_item->app_name);
136 SETTING_TRACE_DEBUG("malloc() failed");
139 return AIL_CB_RET_CONTINUE;
142 static void __add_3rd_party_lock(void *data)
145 ret_if(data == NULL);
147 SettingSecurityUG *ad = (SettingSecurityUG *) data;
149 /* Get info from AIL */
150 pkgmgrinfo_appinfo_filter_h filter; //ail_filter_h filter;
151 int ret = 0; //ail_error_e ret;
152 int count = -1; //int count = 0;
154 ret = pkgmgrinfo_appinfo_filter_create(&filter); //ret = ail_filter_new(&filter);
155 if(ret > 0) //if(ret != AIL_ERROR_OK)
157 SETTING_TRACE_DEBUG("pkgmgrinfo_appinfo_filter_create() failed"); //SETTING_TRACE_DEBUG("ail_filter_new() failed");
160 ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_CATEGORY, "http://tizen.org/category/lockapp");
161 //ret = ail_filter_add_str(filter, AIL_PROP_CATEGORIES_STR, "lockscreen");
162 ret = pkgmgrinfo_appinfo_filter_count(filter, &count); ////ret = ail_filter_count_appinfo(filter, &count);
163 SETTING_TRACE_DEBUG("There is/are %d 3rd lock app(s)", count);
166 SETTING_TRACE_DEBUG("No 3rd lock app");
167 pkgmgrinfo_appinfo_filter_destroy(filter); //ail_filter_destroy(filter);
172 lockapp_data = (openlock_appdata*)malloc(sizeof(openlock_appdata));
173 if(lockapp_data == NULL)
175 SETTING_TRACE_DEBUG("malloc() failed");
178 memset(lockapp_data, 0x00, sizeof(openlock_appdata));
179 lockapp_data->prev = NULL;
180 lockapp_data->next = NULL;
181 lockapp_data->pkg_name = NULL;
182 lockapp_data->app_name = NULL;
183 lockapp_data->index = 0;
185 pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, __get_appinfo_cb, ad); //ail_filter_list_appinfo_foreach(filter, __get_appinfo_cb, ad);
186 pkgmgrinfo_appinfo_filter_destroy(filter); //ail_filter_destroy(filter);
189 openlock_appdata *list = lockapp_data;
190 Setting_GenGroupItem_Data *item_data = NULL;
192 for(index = 0; index < count; index++)
194 ad->data_locktype_3rd[index] = setting_create_Gendial_field_1radio(ad->sl_scroller,
195 &(itc_1text_1icon_2),
196 setting_security_locktype_mouse_up_Gendial_list_cb, /*add to sel_cb */
199 ad->lock_type_rd, SETTING_SCREEN_LOCK_TYPE_OTHER + index,
202 if (ad->data_locktype_3rd[index]) {
203 ad->data_locktype_3rd[index]->userdata = ad;
205 SETTING_TRACE_ERROR("item_data is NULL");
212 void __add_locktype_items(void *data)
215 retv_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
217 SettingSecurityUG *ad = (SettingSecurityUG *) data;
219 Elm_Object_Item *item = NULL;
221 Setting_GenGroupItem_Data *item_data = NULL;
225 vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype);
227 radio = elm_radio_add(ad->sl_scroller);
228 elm_radio_state_value_set(radio, -1);
229 ad->lock_type_rd = radio;
232 item = elm_genlist_item_append(ad->sl_scroller, &(ad->itc_seperator), NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
233 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
235 //evas_object_smart_callback_add(ad->sl_scroller, "realized", __gl_realized_cb, NULL);
237 /* to do : radio menu */
239 ad->data_locktype_swipe =
240 setting_create_Gendial_field_1radio(ad->sl_scroller,
241 &(itc_1text_1icon_2),
242 setting_security_locktype_mouse_up_Gendial_list_cb, /*add to sel_cb */
245 radio, SETTING_SCREEN_LOCK_TYPE_SWIPE,
248 if (ad->data_locktype_swipe) {
249 ad->data_locktype_swipe->userdata = ad;
250 ad->data_locktype_swipe->group_style = SETTING_GROUP_STYLE_TOP;
252 SETTING_TRACE_ERROR("item_data is NULL");
255 /* Add 3rd party lock apps in list. */
256 __add_3rd_party_lock(ad);
259 /* To do : If type is OTHER, should calculate something.*/
260 if(locktype == SETTING_SCREEN_LOCK_TYPE_OTHER)
262 char *open_lock_name = NULL;
263 open_lock_name = vconf_get_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR);
264 index = __get_index_of_lockapp(open_lock_name);
267 FREE(open_lock_name);
271 elm_radio_value_set(radio, locktype);
273 elm_radio_value_set(radio, locktype + index);
276 static int setting_security_locktype_create(void *cb)
279 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
281 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
283 /* add basic layout */
285 Evas_Object *scroller = NULL;
287 setting_push_layout_navi_bar_genlist(ad->win_main_layout,
289 _(Keystr_ScreenLockType),
290 _("IDS_COM_BODY_BACK"), NULL,
291 setting_security_locktype_click_softkey_back_cb,
292 NULL, ad, &scroller, ad->navi_bar);
294 ad->sl_scroller = scroller;
296 __add_locktype_items(ad);
298 setting_view_security_locktype.is_create = 1;
300 return SETTING_RETURN_SUCCESS;
303 static int setting_security_locktype_destroy(void *cb)
307 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
309 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
312 evas_object_del(ad->notify);
316 elm_naviframe_item_pop(ad->navi_bar);
318 setting_view_security_locktype.is_create = 0;
320 return SETTING_RETURN_SUCCESS;
323 static int setting_security_locktype_update(void *cb)
327 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
329 return SETTING_RETURN_SUCCESS;
332 static int setting_security_locktype_cleanup(void *cb)
336 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
338 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
340 return setting_security_locktype_destroy(ad);
343 /* ***************************************************
347 ****************************************************/
350 setting_security_locktype_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
355 setting_retm_if(data == NULL, "Data parameter is NULL");
357 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
358 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
359 elm_genlist_item_selected_set(item, 0);
360 Setting_GenGroupItem_Data *list_item =
361 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
362 SettingSecurityUG *ad = (SettingSecurityUG *) data;
363 int lock_type = list_item->chk_status;
364 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
365 int old_type = elm_radio_value_get(list_item->eo_check);
367 ad->selected_lock_type = list_item->keyStr;
369 /* If lock_type is same with old_lock_type, return. */
370 if(lock_type == old_type)
372 SETTING_TRACE_DEBUG("[Screen Lock Type] Selected same type");
377 char *pkg_name = NULL;
381 case SETTING_SCREEN_LOCK_TYPE_SWIPE:
382 if(vconf_set_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, lock_type) == 0)
385 elm_radio_value_set(list_item->eo_check, lock_type);
387 ug_destroy_me(ad->ug);
389 case SETTING_SCREEN_LOCK_TYPE_OTHER:
390 index = __get_lockapp_index_from_appname(list_item->keyStr);
391 pkg_name = __get_lockapp_pkgname_from_appname(list_item->keyStr);
392 SETTING_TRACE_DEBUG("3rd lock selected. index[%d] pkg_name[%s]", index, pkg_name);
393 vconf_set_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, pkg_name);
394 vconf_set_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, lock_type);
396 elm_radio_value_set(list_item->eo_check, lock_type + index);
404 setting_security_locktype_click_softkey_back_cb(void *data, Evas_Object *obj,
409 retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
411 SettingSecurityUG *ad = (SettingSecurityUG *) data;
412 setting_view_change(&setting_view_security_locktype, &setting_view_security_main, ad);