--- /dev/null
+/*
+ * setting
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
+ *
+ * Contact: MyoungJune Park <mj2004.park@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <setting-common-data-type.h>
+#include <setting-common-data-slp-setting.h>
+#include <setting-common-draw-widget.h>
+#include <setting-common-view.h>
+
+#include <setting-security-locktype.h>
+#include <setting-security.h>
+#include <setting-debug.h>
+#include <ail.h>
+#include <pkgmgr-info.h>
+
+#define TBD 0
+
+static int setting_security_locktype_create(void *cb);
+static int setting_security_locktype_destroy(void *cb);
+static int setting_security_locktype_update(void *cb);
+static int setting_security_locktype_cleanup(void *cb);
+setting_view setting_view_security_locktype = {
+ .create = setting_security_locktype_create,
+ .destroy = setting_security_locktype_destroy,
+ .update = setting_security_locktype_update,
+ .cleanup = setting_security_locktype_cleanup,
+};
+
+openlock_appdata *lockapp_data = NULL;
+
+/* ***************************************************
+ **
+ **basic func
+ **
+ ****************************************************/
+
+static int __get_lockapp_index_from_pkgname(char *pkg_name)
+{
+ SETTING_TRACE_BEGIN;
+ if(pkg_name == NULL)
+ return SETTING_RETURN_FAIL;
+
+ openlock_appdata *item = lockapp_data;
+ for(; item != NULL; item = item->next)
+ {
+ if(safeStrCmp(item->pkg_name, pkg_name) == 0)
+ return item->index;
+ }
+ return SETTING_RETURN_FAIL;
+}
+static int __get_lockapp_index_from_appname(char *app_name)
+{
+ SETTING_TRACE_BEGIN;
+ if(app_name == NULL)
+ return SETTING_RETURN_FAIL;
+
+ openlock_appdata *item = lockapp_data;
+ for(; item != NULL; item = item->next)
+ {
+ if(safeStrCmp(item->app_name, app_name) == 0)
+ return item->index;
+ }
+ return SETTING_RETURN_FAIL;
+}
+static char* __get_lockapp_pkgname_from_appname(char *app_name)
+{
+ SETTING_TRACE_BEGIN;
+ if(app_name == NULL)
+ return NULL;
+
+ openlock_appdata *item = lockapp_data;
+ for(; item != NULL; item = item->next)
+ {
+ if(safeStrCmp(item->app_name, app_name) == 0)
+ return item->app_name;
+ }
+ return NULL;
+}
+
+ail_cb_ret_e __get_appinfo_cb(const ail_appinfo_h appinfo, void *user_data)
+{
+ SETTING_TRACE_BEGIN;
+
+ openlock_appdata *item = lockapp_data;
+ openlock_appdata *new_item = NULL;
+ char *pkg_name = NULL;
+ char *app_name = NULL;
+
+ ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &pkg_name);
+ ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &app_name);
+
+ while(item->next != NULL)
+ item = item->next;
+
+ if(item->index == 0 && item->pkg_name == NULL)
+ {
+ /* first app */
+ item->pkg_name = strdup(pkg_name);
+ item->app_name = strdup(app_name);
+
+ SETTING_TRACE_DEBUG("app info %d %s %s", item->index, item->pkg_name, item->app_name);
+ }
+ else
+ {
+ /* create new */
+ new_item = (openlock_appdata*)malloc(sizeof(openlock_appdata));
+ if(new_item != NULL)
+ {
+ memset(new_item, 0x00, sizeof(openlock_appdata));
+ new_item->pkg_name = strdup(pkg_name);
+ new_item->app_name = strdup(app_name);
+ new_item->index = item->index + 1;
+ new_item->prev = item;
+ item->next = new_item;
+
+ SETTING_TRACE_DEBUG("app info %d %s %s", new_item->index, new_item->pkg_name, new_item->app_name);
+ }
+ else
+ {
+ SETTING_TRACE_DEBUG("malloc() failed");
+ }
+ }
+ return AIL_CB_RET_CONTINUE;
+}
+
+static void __add_3rd_party_lock(void *data)
+{
+ SETTING_TRACE_BEGIN;
+ ret_if(data == NULL);
+
+ SettingSecurityUG *ad = (SettingSecurityUG *) data;
+
+ /* Get info from AIL */
+ pkgmgrinfo_appinfo_filter_h filter; //ail_filter_h filter;
+ int ret = 0; //ail_error_e ret;
+ int count = -1; //int count = 0;
+
+ ret = pkgmgrinfo_appinfo_filter_create(&filter); //ret = ail_filter_new(&filter);
+ if(ret > 0) //if(ret != AIL_ERROR_OK)
+ {
+ SETTING_TRACE_DEBUG("pkgmgrinfo_appinfo_filter_create() failed"); //SETTING_TRACE_DEBUG("ail_filter_new() failed");
+ return;
+ }
+ ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_CATEGORY, "http://tizen.org/category/lockapp");
+ //ret = ail_filter_add_str(filter, AIL_PROP_CATEGORIES_STR, "lockscreen");
+ ret = pkgmgrinfo_appinfo_filter_count(filter, &count); ////ret = ail_filter_count_appinfo(filter, &count);
+ SETTING_TRACE_DEBUG("There is/are %d 3rd lock app(s)", count);
+ if(count <= 0)
+ {
+ SETTING_TRACE_DEBUG("No 3rd lock app");
+ pkgmgrinfo_appinfo_filter_destroy(filter); //ail_filter_destroy(filter);
+ return;
+
+ }
+
+ lockapp_data = (openlock_appdata*)malloc(sizeof(openlock_appdata));
+ if(lockapp_data == NULL)
+ {
+ SETTING_TRACE_DEBUG("malloc() failed");
+ return;
+ }
+ memset(lockapp_data, 0x00, sizeof(openlock_appdata));
+ lockapp_data->prev = NULL;
+ lockapp_data->next = NULL;
+ lockapp_data->pkg_name = NULL;
+ lockapp_data->app_name = NULL;
+ lockapp_data->index = 0;
+
+ pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, __get_appinfo_cb, ad); //ail_filter_list_appinfo_foreach(filter, __get_appinfo_cb, ad);
+ pkgmgrinfo_appinfo_filter_destroy(filter); //ail_filter_destroy(filter);
+
+ /* Add to genlist */
+ openlock_appdata *list = lockapp_data;
+ Setting_GenGroupItem_Data *item_data = NULL;
+ int index = 0;
+ for(index = 0; index < count; index++)
+ {
+ ad->data_locktype_3rd[index] = setting_create_Gendial_field_1radio(ad->sl_scroller,
+ &(itc_1text_1icon_2),
+ setting_security_locktype_mouse_up_Gendial_list_cb, /*add to sel_cb */
+ ad, /* sel data */
+ SWALLOW_Type_1RADIO,
+ ad->lock_type_rd, SETTING_SCREEN_LOCK_TYPE_OTHER + index,
+ list->app_name,
+ NULL);
+ if (ad->data_locktype_3rd[index]) {
+ ad->data_locktype_3rd[index]->userdata = ad;
+ } else {
+ SETTING_TRACE_ERROR("item_data is NULL");
+ }
+ list = list->next;
+ }
+ SETTING_TRACE_END;
+}
+
+void __add_locktype_items(void *data)
+{
+ SETTING_TRACE_BEGIN;
+ retv_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
+
+ SettingSecurityUG *ad = (SettingSecurityUG *) data;
+
+ Elm_Object_Item *item = NULL;
+ Evas_Object *radio;
+ Setting_GenGroupItem_Data *item_data = NULL;
+
+ int index = -1;
+ int locktype = 0;
+ vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype);
+
+ radio = elm_radio_add(ad->sl_scroller);
+ elm_radio_state_value_set(radio, -1);
+ ad->lock_type_rd = radio;
+
+ /* separator */
+ item = elm_genlist_item_append(ad->sl_scroller, &(ad->itc_seperator), NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
+ elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
+
+ //evas_object_smart_callback_add(ad->sl_scroller, "realized", __gl_realized_cb, NULL);
+
+ /* to do : radio menu */
+ /* 1) swipe */
+ ad->data_locktype_swipe =
+ setting_create_Gendial_field_1radio(ad->sl_scroller,
+ &(itc_1text_1icon_2),
+ setting_security_locktype_mouse_up_Gendial_list_cb, /*add to sel_cb */
+ ad, /* sel data */
+ SWALLOW_Type_1RADIO,
+ radio, SETTING_SCREEN_LOCK_TYPE_SWIPE,
+ Keystr_Swipe,
+ NULL);
+ if (ad->data_locktype_swipe) {
+ ad->data_locktype_swipe->userdata = ad;
+ ad->data_locktype_swipe->group_style = SETTING_GROUP_STYLE_TOP;
+ } else {
+ SETTING_TRACE_ERROR("item_data is NULL");
+ }
+
+ /* Add 3rd party lock apps in list. */
+ __add_3rd_party_lock(ad);
+
+ /* update info */
+ /* To do : If type is OTHER, should calculate something.*/
+ if(locktype == SETTING_SCREEN_LOCK_TYPE_OTHER)
+ {
+ char *open_lock_name = NULL;
+ open_lock_name = vconf_get_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR);
+ index = __get_index_of_lockapp(open_lock_name);
+
+ if(open_lock_name)
+ FREE(open_lock_name);
+ }
+ /* End */
+ if(index < 0)
+ elm_radio_value_set(radio, locktype);
+ else
+ elm_radio_value_set(radio, locktype + index);
+}
+
+static int setting_security_locktype_create(void *cb)
+{
+ SETTING_TRACE_BEGIN;
+ retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
+
+ SettingSecurityUG *ad = (SettingSecurityUG *) cb;
+
+ /* add basic layout */
+
+ Evas_Object *scroller = NULL;
+
+ setting_push_layout_navi_bar_genlist(ad->win_main_layout,
+ ad->win_get,
+ _(Keystr_ScreenLockType),
+ _("IDS_COM_BODY_BACK"), NULL,
+ setting_security_locktype_click_softkey_back_cb,
+ NULL, ad, &scroller, ad->navi_bar);
+
+ ad->sl_scroller = scroller;
+
+ __add_locktype_items(ad);
+
+ setting_view_security_locktype.is_create = 1;
+
+ return SETTING_RETURN_SUCCESS;
+}
+
+static int setting_security_locktype_destroy(void *cb)
+{
+ SETTING_TRACE_BEGIN;
+ /* error check */
+ retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
+
+ SettingSecurityUG *ad = (SettingSecurityUG *) cb;
+ if (ad->notify)
+ {
+ evas_object_del(ad->notify);
+ ad->notify = NULL;
+ }
+
+ elm_naviframe_item_pop(ad->navi_bar);
+
+ setting_view_security_locktype.is_create = 0;
+
+ return SETTING_RETURN_SUCCESS;
+}
+
+static int setting_security_locktype_update(void *cb)
+{
+ SETTING_TRACE_BEGIN;
+ /* error check */
+ retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
+
+ return SETTING_RETURN_SUCCESS;
+}
+
+static int setting_security_locktype_cleanup(void *cb)
+{
+ SETTING_TRACE_BEGIN;
+ /* error check */
+ retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
+
+ SettingSecurityUG *ad = (SettingSecurityUG *) cb;
+
+ return setting_security_locktype_destroy(ad);
+}
+
+/* ***************************************************
+ **
+ **call back func
+ **
+ ****************************************************/
+
+static void
+setting_security_locktype_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
+ void *event_info)
+{
+ SETTING_TRACE_BEGIN;
+ /* error check */
+ setting_retm_if(data == NULL, "Data parameter is NULL");
+
+ retm_if(event_info == NULL, "Invalid argument: event info is NULL");
+ Elm_Object_Item *item = (Elm_Object_Item *) event_info;
+ elm_genlist_item_selected_set(item, 0);
+ Setting_GenGroupItem_Data *list_item =
+ (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
+ SettingSecurityUG *ad = (SettingSecurityUG *) data;
+ int lock_type = list_item->chk_status;
+ SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
+ int old_type = elm_radio_value_get(list_item->eo_check);
+
+ ad->selected_lock_type = list_item->keyStr;
+
+ /* If lock_type is same with old_lock_type, return. */
+ if(lock_type == old_type)
+ {
+ SETTING_TRACE_DEBUG("[Screen Lock Type] Selected same type");
+ return;
+ }
+
+ int index = -1;
+ char *pkg_name = NULL;
+
+ switch(lock_type)
+ {
+ case SETTING_SCREEN_LOCK_TYPE_SWIPE:
+ if(vconf_set_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, lock_type) == 0)
+ {
+ /* set radio */
+ elm_radio_value_set(list_item->eo_check, lock_type);
+ }
+ ug_destroy_me(ad->ug);
+ break;
+ case SETTING_SCREEN_LOCK_TYPE_OTHER:
+ index = __get_lockapp_index_from_appname(list_item->keyStr);
+ pkg_name = __get_lockapp_pkgname_from_appname(list_item->keyStr);
+ SETTING_TRACE_DEBUG("3rd lock selected. index[%d] pkg_name[%s]", index, pkg_name);
+ vconf_set_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, pkg_name);
+ vconf_set_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, lock_type);
+ /* set radio */
+ elm_radio_value_set(list_item->eo_check, lock_type + index);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+setting_security_locktype_click_softkey_back_cb(void *data, Evas_Object *obj,
+ void *event_info)
+{
+ SETTING_TRACE_BEGIN;
+ /* error check */
+ retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
+
+ SettingSecurityUG *ad = (SettingSecurityUG *) data;
+ setting_view_change(&setting_view_security_locktype, &setting_view_security_main, ad);
+ SETTING_TRACE_END;
+}