tizen 2.3.1 release
[apps/home/settings.git] / setting-password / src / setting-password-forgot-password.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
22 #include <sys/socket.h>
23 #include <sys/un.h>
24 #include <ode.h>
25
26 #include <setting-password.h>
27 #include <setting-password-forgot-password.h>
28
29 static int setting_password_forgot_password_create(void *cb);
30 static int setting_password_forgot_password_destroy(void *cb);
31 static int setting_password_forgot_password_update(void *cb);
32 static int setting_password_forgot_password_cleanup(void *cb);
33
34 setting_view setting_view_password_forgot_password = {
35         .create = setting_password_forgot_password_create,
36         .destroy = setting_password_forgot_password_destroy,
37         .update = setting_password_forgot_password_update,
38         .cleanup = setting_password_forgot_password_cleanup,
39 };
40
41 void __reset_personal_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
42 {
43         SETTING_TRACE_BEGIN;
44         ret_if(!data);
45
46         SettingPasswordUG *ad = (SettingPasswordUG *)data;
47
48         char *btn_str = elm_entry_markup_to_utf8(elm_object_text_get(obj));
49         if (!safeStrCmp(btn_str, _(PW_ST_RESET))) {
50                 int ret = 0;
51                 /* call ode API */
52                 if (ode_init() == 0) {
53                         ret = pse_restore();
54                         SETTING_TRACE("pse_restore() returns %d", ret);
55
56                         /* initialize vconf */
57                         vconf_set_int(VCONFKEY_SETAPPL_PERSONAL_MODE_UNLOCK_METHOD_INT, -1);
58                         vconf_set_bool(VCONFKEY_SETAPPL_PERSONAL_MODE_STATUS_BOOL, 0);
59
60                         ode_deinit();
61                         /* send resunt to personal mode ug */
62                         app_control_h svc;
63                         if (!app_control_create(&svc)) {
64                                 app_control_add_extra_data(svc, "result", "Restore");
65                                 ug_send_result(ad->ug, svc);
66                                 app_control_destroy(svc);
67                         }
68                         ug_destroy_me(ad->ug);
69                 }
70         }
71
72         if (ad->reset_personal_popup) {
73                 evas_object_del(ad->reset_personal_popup);
74                 ad->reset_personal_popup = NULL;
75         }
76 }
77
78 static void __launch_lockscreen(void)
79 {
80         SETTING_TRACE_BEGIN;
81         struct sockaddr_un saddr;
82         int fd;
83         int retry = 1;
84
85         fd = socket(AF_UNIX, SOCK_STREAM, 0);
86         if (fd < 0) {
87                 fd = socket(AF_UNIX, SOCK_STREAM, 0);
88                 if (fd < 0) {
89                         SETTING_TRACE("socket() failed");
90                         return;
91                 }
92         }
93         bzero(&saddr, sizeof(saddr));
94         saddr.sun_family = AF_UNIX;
95         strncpy(saddr.sun_path, "/tmp/phlock", strlen("/tmp/phlock"));
96         saddr.sun_path[strlen("/tmp/phlock")] = 0;
97
98         SETTING_TRACE("saddr.sun_path = %s", saddr.sun_path);
99 retry_con:
100         if (connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
101                 if (retry > 0) {
102                         usleep(100 * 1000);
103                         retry--;
104                         goto retry_con;
105                 }
106                 close(fd);
107                 SETTING_TRACE("connect() failed");
108                 return;
109         }
110         char *cmd = "launch_phone_lock";
111         int len = strlen(cmd);
112         send(fd, cmd, len, 0);
113 }
114
115 static void setting_password_forgot_password_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info)
116 {
117         SETTING_TRACE_BEGIN;
118         /* error check */
119         setting_retm_if(data == NULL, "Data parameter is NULL");
120         SettingPasswordUG *ad = (SettingPasswordUG *)data;
121
122         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
123         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
124         elm_genlist_item_selected_set(item, 0);
125         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
126
127         SETTING_TRACE("%s clicked", list_item->keyStr);
128         if (!safeStrCmp(list_item->keyStr, PW_ST_RESET_PERSONAL_MODE)) {
129                 /* if lock type is simple password or password, call lockscreen. */
130                 int screen_lock_type = 0;
131                 vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &screen_lock_type);
132                 if (screen_lock_type == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD
133                     || screen_lock_type == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
134                         /* call lockscreen app */
135                         __launch_lockscreen();
136                         /*int ret = 0; */
137                         /*ret = aul_launch_app("org.tizen.lockscreen", NULL); */
138                         /*SETTING_TRACE("aul_launch_app() returns %d", ret); */
139                 }
140
141                 /* draw popup */
142                 ad->reset_personal_popup = setting_create_popup_with_btn(ad, ad->win_get,
143                                                                          PW_ST_RESET_PERSONAL_MODE,
144                                                                          PW_ST_RESET_PERSONAL_MODE_POPUP_Q,
145                                                                          __reset_personal_popup_resp_cb, 0,
146                                                                          2, PW_ST_RESET, PW_ST_CANCEL);
147         }
148 }
149
150 static Eina_Bool __forgot_password_pop_cb(void *data, Elm_Object_Item *it)
151 {
152         SETTING_TRACE_BEGIN;
153
154         setting_view_change(&setting_view_password_forgot_password, &setting_view_password_main, data);
155
156         return EINA_TRUE;
157 }
158
159 static int setting_password_forgot_password_create(void *cb)
160 {
161         SETTING_TRACE_BEGIN;
162         /* error check */
163         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
164
165         SettingPasswordUG *ad = (SettingPasswordUG *) cb;
166
167         Evas_Object *genlist = NULL;
168         Elm_Object_Item *navi_it = NULL;
169
170         navi_it = setting_push_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get,
171                                                        PW_ST_FORGOT_PASSWORD,
172                                                        NULL, NULL, NULL, NULL, NULL,
173                                                        &genlist, ad->navi_bar);
174         /* add pop cb */
175         elm_naviframe_item_pop_cb_set(navi_it, (Elm_Naviframe_Item_Pop_Cb)__forgot_password_pop_cb, ad);
176
177         if (genlist) {
178                 Elm_Object_Item *item = elm_genlist_item_append(genlist,
179                                                                 &itc_seperator, NULL, NULL,
180                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
181                 if (item)
182                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
183
184                 /* menu 1. */
185                 setting_create_Gendial_field_def(genlist, &(itc_1text),
186                                                  setting_password_forgot_password_mouse_up_Gendial_list_cb, ad,
187                                                  SWALLOW_Type_INVALID,
188                                                  NULL, NULL,
189                                                  0, PW_ST_RESET_PERSONAL_MODE, NULL, NULL);
190
191                 /* menu 2. */
192                 ADD_GL_HELP(genlist, PW_ST_RESET_PERSONAL_MODE_HELP);
193         }
194
195
196         setting_view_password_forgot_password.is_create = 1;
197
198         SETTING_TRACE_END;
199         return SETTING_RETURN_SUCCESS;
200 }
201
202 static int setting_password_forgot_password_destroy(void *cb)
203 {
204         SETTING_TRACE_BEGIN;
205         /* error check */
206         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
207
208         setting_view_password_forgot_password.is_create = 0;
209
210         SETTING_TRACE_END;
211         return SETTING_RETURN_SUCCESS;
212 }
213
214 static int setting_password_forgot_password_update(void *cb)
215 {
216         SETTING_TRACE_BEGIN;
217         /* error check */
218         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
219
220         SettingPasswordUG *ad = (SettingPasswordUG *) cb;
221
222         if (ad->ly_main != NULL) {
223                 evas_object_show(ad->ly_main);
224         }
225
226         return SETTING_RETURN_SUCCESS;
227 }
228
229 static int setting_password_forgot_password_cleanup(void *cb)
230 {
231         /* error check */
232         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
233
234         return setting_password_forgot_password_destroy(cb);
235 }
236
237 /* ***************************************************
238  *
239  *general func
240  *
241  ***************************************************/
242