2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <appcore-efl.h>
22 #include <vconf-keys.h>
24 #include "openlock-setting-pw.h"
25 #include "openlock-setting-debug.h"
26 #include "starter-vconf.h"
28 static Evas_Object *done_button = NULL;
29 static Elm_Gen_Item_Class itc_label, itc_entry;
30 static Evas_Object *_openlock_setting_pw_editfield_create(Evas_Object * parent,
32 static Evas_Object *_openlock_setting_pw_editfield_entry_get(Evas_Object *
35 static Evas_Object *_openlock_setting_pw_create_conformant(Evas_Object * parent)
37 Evas_Object *conform = NULL;
38 elm_win_conformant_set(parent, 1);
39 conform = elm_conformant_add(parent);
40 elm_object_style_set(conform, "internal_layout");
41 evas_object_show(conform);
46 static void _openlock_setting_pw_done_button_changed(void *data,
47 Evas_Object * obj, void *e)
49 openlock_setting_appdata *openlock_setting_data =
50 (openlock_setting_appdata *) data;
52 if (!openlock_setting_data) {
55 int length = strlen(elm_entry_entry_get(obj));
58 elm_object_disabled_set(done_button, EINA_TRUE);
60 elm_object_disabled_set(done_button, EINA_FALSE);
63 if (elm_object_focus_get(obj)) {
64 if (elm_entry_is_empty(obj)) {
65 elm_object_signal_emit
66 (openlock_setting_data->editfield_layout,
67 "elm,state,eraser,hide", "elm");
69 elm_object_signal_emit
70 (openlock_setting_data->editfield_layout,
71 "elm,state,eraser,show", "elm");
76 static void _openlock_setting_pw_focused_cb(void *data, Evas_Object * obj,
79 if (!elm_entry_is_empty(obj)) {
80 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
82 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
85 static void _openlock_setting_pw_unfocused_cb(void *data, Evas_Object * obj,
88 if (elm_entry_is_empty(obj)) {
89 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
91 elm_object_signal_emit(data, "elm,state,eraser,hide", "elm");
94 static void _openlock_setting_pw_eraser_clicked_cb(void *data,
99 elm_entry_entry_set(data, "");
102 static Evas_Object *_openlock_setting_pw_editfield_create(Evas_Object * parent,
105 Evas_Object *layout = NULL;
106 Evas_Object *entry = NULL;
107 openlock_setting_appdata *openlock_setting_data =
108 (openlock_setting_appdata *) data;
109 static Elm_Entry_Filter_Limit_Size limit_filter_data;
111 limit_filter_data.max_char_count = 15; /* hard code for demo */
112 limit_filter_data.max_byte_count = 0;
114 layout = elm_layout_add(parent);
115 elm_layout_theme_set(layout, "layout", "editfield", "title");
117 entry = elm_entry_add(parent);
118 elm_entry_scrollable_set(entry, EINA_TRUE);
119 elm_entry_single_line_set(entry, EINA_TRUE);
120 elm_entry_password_set(entry, EINA_TRUE);
121 elm_entry_input_panel_layout_set(entry,
122 ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
123 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size,
125 elm_object_focus_set(entry, EINA_TRUE);
126 evas_object_show(entry);
127 evas_object_smart_callback_add(entry, "changed",
128 _openlock_setting_pw_done_button_changed,
129 openlock_setting_data);
130 evas_object_smart_callback_add(entry, "focused",
131 _openlock_setting_pw_focused_cb, layout);
132 evas_object_smart_callback_add(entry, "unfocused",
133 _openlock_setting_pw_unfocused_cb,
136 elm_object_part_content_set(layout, "elm.swallow.content", entry);
137 elm_object_part_text_set(layout, "elm.guidetext", "");
138 elm_object_signal_callback_add(layout, "elm,eraser,clicked", "elm",
139 _openlock_setting_pw_eraser_clicked_cb,
142 Ecore_IMF_Context *imf_context =
143 (Ecore_IMF_Context *) elm_entry_imf_context_get(entry);
145 ecore_imf_context_input_panel_show(imf_context);
147 elm_object_focus_set(entry, EINA_TRUE);
152 static Evas_Object *_openlock_setting_pw_editfield_entry_get(Evas_Object *
155 Evas_Object *entry = NULL;
157 entry = elm_object_part_content_get(parent, "elm.swallow.content");
162 static char *_openlock_setting_pw_gl_label_get_title(void *data,
166 openlock_setting_appdata *openlock_setting_data =
167 (openlock_setting_appdata *) data;
168 char buf[50] = { 0, };
170 if (!openlock_setting_data || !part) {
174 if (!strcmp(part, "elm.text")) {
175 snprintf(buf, sizeof(buf), "%s", "Enter Password"); /* hard code for demo */
181 static Evas_Object *_openlock_setting_pw_gl_icon_get(void *data,
185 Evas_Object *layout = NULL;
186 openlock_setting_appdata *openlock_setting_data =
187 (openlock_setting_appdata *) data;
189 if (!openlock_setting_data || !part) {
193 if (!strcmp(part, "elm.icon")) {
195 _openlock_setting_pw_editfield_create(obj,
196 openlock_setting_data);
197 openlock_setting_data->editfield_layout = layout;
205 static void _openlock_setting_pw_list_set_styles()
207 itc_label.item_style = "dialogue/title";
208 itc_label.func.text_get = _openlock_setting_pw_gl_label_get_title;
209 itc_label.func.content_get = NULL;
210 itc_label.func.state_get = NULL;
211 itc_label.func.del = NULL;
213 itc_entry.item_style = "dialogue/1icon";
214 itc_entry.func.text_get = NULL;
215 itc_entry.func.content_get = _openlock_setting_pw_gl_icon_get;
216 itc_entry.func.state_get = NULL;
217 itc_entry.func.del = NULL;
220 static void _openlock_setting_pw_back_cb(void *data, Evas_Object * obj,
223 openlock_setting_appdata *openlock_setting_data =
224 (openlock_setting_appdata *) data;
225 openlock_ug_data *openlock_data = NULL;
227 if (!openlock_setting_data) {
231 openlock_data = openlock_setting_data->openlock_data;
232 if (!openlock_data) {
235 OPENLOCKS_DBG("_openlock_setting_pw_back_cb\n");
236 openlock_setting_data->count = 0;
238 elm_naviframe_item_pop(openlock_data->navi_bar);
239 if (openlock_setting_data->editfield_layout) {
240 evas_object_del(openlock_setting_data->editfield_layout);
241 openlock_setting_data->editfield_layout = NULL;
243 if (openlock_setting_data->genlist) {
244 evas_object_del(openlock_setting_data->genlist);
245 openlock_setting_data->genlist = NULL;
247 if (openlock_setting_data->ly) {
248 evas_object_del(openlock_setting_data->ly);
249 openlock_setting_data->ly = NULL;
253 static Eina_Bool _openlock_setting_pw_input_panel_show_idler(void *data)
255 Evas_Object *entry = (Evas_Object *) data;
257 OPENLOCKS_DBG("_openlock_setting_pw_input_panel_show_idler");
259 elm_object_focus_set(entry, EINA_TRUE);
261 return ECORE_CALLBACK_CANCEL;
264 static void _openlock_setting_pw_imf_context_input_panel_show(void *data)
266 openlock_setting_appdata *openlock_setting_data =
267 (openlock_setting_appdata *) data;
268 Evas_Object *entry = NULL;
270 if (!openlock_setting_data) {
274 OPENLOCKS_DBG("_openlock_setting_pw_imf_context_input_panel_show\n");
276 entry = _openlock_setting_pw_editfield_entry_get(
277 openlock_setting_data->editfield_layout);
278 evas_object_show(entry);
280 ecore_idler_add(_openlock_setting_pw_input_panel_show_idler, entry);
283 static void _openlock_setting_pw_imf_context_input_panel_hide(void *data)
285 openlock_setting_appdata *openlock_setting_data =
286 (openlock_setting_appdata *) data;
287 Evas_Object *entry = NULL;
289 if (!openlock_setting_data) {
293 OPENLOCKS_DBG("_openlock_setting_pw_imf_context_input_panel_hide\n");
295 entry = _openlock_setting_pw_editfield_entry_get(
296 openlock_setting_data->editfield_layout);
297 evas_object_hide(entry);
299 elm_object_focus_set(entry, EINA_FALSE);
302 static void _openlock_setting_pw_destroy_popup_cb(void *data, Evas_Object * obj,
305 openlock_setting_appdata *openlock_setting_data =
306 (openlock_setting_appdata *) data;
307 Evas_Object *popup = NULL;
309 OPENLOCKS_DBG("_openlock_setting_pw_destroy_popup_cb\n");
310 _openlock_setting_pw_imf_context_input_panel_show
311 (openlock_setting_data);
313 if (!openlock_setting_data) {
317 popup = openlock_setting_data->popup;
319 evas_object_del(popup);
324 static void _openlock_setting_pw_show_popup(void *data, const char *mesg)
326 openlock_setting_appdata *openlock_setting_data =
327 (openlock_setting_appdata *) data;
328 openlock_ug_data *openlock_data = NULL;
329 Evas_Object *popup = NULL;
331 if (!openlock_setting_data) {
334 openlock_data = openlock_setting_data->openlock_data;
335 if (!openlock_data) {
339 OPENLOCKS_DBG("_openlock_setting_pw_show_popup\n");
341 _openlock_setting_pw_imf_context_input_panel_hide
342 (openlock_setting_data);
343 popup = elm_popup_add(openlock_data->win_main);
344 openlock_setting_data->popup = popup;
345 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
347 elm_object_text_set(popup, mesg);
348 elm_popup_timeout_set(popup, 3);
349 evas_object_smart_callback_add(popup, "timeout",
350 _openlock_setting_pw_destroy_popup_cb,
351 openlock_setting_data);
352 evas_object_show(popup);
355 static void _openlock_setting_pw_set_str(char **s, const char *str)
363 if (str && str[0] != '\0')
369 static void _openlock_setting_pw_done_cb(void *data, Evas_Object * obj, void *e)
371 openlock_setting_appdata *openlock_setting_data =
372 (openlock_setting_appdata *) data;
373 openlock_ug_data *openlock_data = NULL;
374 Evas_Object *entry = NULL;
375 Evas_Object *editfield_layout = NULL;
378 if (!openlock_setting_data) {
382 OPENLOCKS_DBG("_openlock_setting_pw_done_cb\n");
383 editfield_layout = openlock_setting_data->editfield_layout;
385 _openlock_setting_pw_editfield_entry_get
386 (openlock_setting_data->editfield_layout);
388 _openlock_setting_pw_set_str(&str, elm_entry_entry_get(entry));
389 OPENLOCKS_DBG("str = %s\n", str);
391 _openlock_setting_pw_show_popup(openlock_setting_data, "Wrong Password!"); /* hard code for demo */
393 elm_object_part_text_set(editfield_layout,
394 "elm.guidetext", "");
395 elm_entry_entry_set(entry, "");
398 if (strcmp(str, "16777216") == 0) { /* hard code for demo */
399 OPENLOCKS_DBG("right pw\n");
400 OPENLOCKS_DBG("openlock_setting_data->index: %d",
401 openlock_setting_data->index);
402 if (openlock_setting_data != NULL
403 && openlock_setting_data->pkg_name != NULL) {
404 vconf_set_str(VCONF_PRIVATE_LOCKSCREEN_PKGNAME,
405 openlock_setting_data->pkg_name);
406 OPENLOCKS_DBG("vconf pkgname set : %s",
407 openlock_setting_data->pkg_name);
409 openlock_data = openlock_setting_data->openlock_data;
410 if (!openlock_data) {
413 OPENLOCKS_DBG("_openlock_setting_pw_done_cb\n");
414 openlock_setting_data->count = 0; /* reset the count */
416 elm_naviframe_item_pop(openlock_data->navi_bar);
417 if (openlock_setting_data->editfield_layout) {
419 (openlock_setting_data->editfield_layout);
420 openlock_setting_data->editfield_layout = NULL;
422 if (openlock_setting_data->genlist) {
423 evas_object_del(openlock_setting_data->genlist);
424 openlock_setting_data->genlist = NULL;
426 if (openlock_setting_data->ly) {
427 evas_object_del(openlock_setting_data->ly);
428 openlock_setting_data->ly = NULL;
431 _openlock_setting_pw_show_popup(openlock_setting_data, "Wrong Password!"); /* hard code for demo */
433 elm_object_part_text_set(editfield_layout,
434 "elm.guidetext", "");
435 elm_entry_entry_set(entry, "");
442 openlock_setting_pw_create_view(openlock_setting_appdata *
443 openlock_setting_data)
445 Evas_Object *navi_bar = NULL;
446 Evas_Object *win_main = NULL;
447 Evas_Object *genlist = NULL;
448 Evas_Object *ly = NULL;
449 Evas_Object *cancel_button = NULL;
450 Evas_Object *back_button = NULL;
451 Elm_Object_Item *genlist_item = NULL;
452 Elm_Object_Item *navi_it = NULL;
453 openlock_ug_data *openlock_data = NULL;
455 if (!openlock_setting_data) {
459 openlock_data = openlock_setting_data->openlock_data;
460 if (!openlock_data) {
464 OPENLOCKS_DBG("openlock_setting_pw_create_view begin\n");
466 win_main = openlock_data->win_main;
467 navi_bar = openlock_data->navi_bar;
469 ly = _openlock_setting_pw_create_conformant(win_main);
470 openlock_setting_data->ly = ly;
473 genlist = elm_genlist_add(navi_bar);
474 _openlock_setting_pw_list_set_styles();
476 elm_genlist_item_append(genlist, &itc_label,
477 (void *)openlock_setting_data, NULL,
478 ELM_GENLIST_ITEM_NONE, NULL, NULL);
479 elm_genlist_item_select_mode_set(genlist_item, EINA_TRUE);
482 elm_genlist_item_append(genlist, &itc_entry,
483 (void *)openlock_setting_data, NULL,
484 ELM_GENLIST_ITEM_NONE, NULL, NULL);
485 elm_genlist_item_select_mode_set(genlist_item, EINA_TRUE);
487 evas_object_show(genlist);
488 elm_object_content_set(ly, genlist);
489 openlock_setting_data->genlist = genlist;
492 done_button = elm_button_add(navi_bar);
493 elm_object_style_set(done_button, "naviframe/title/default");
494 elm_object_text_set(done_button, "Done"); /* hard code for demo */
495 elm_object_disabled_set(done_button, EINA_TRUE);
496 evas_object_smart_callback_add(done_button, "clicked",
497 _openlock_setting_pw_done_cb,
498 openlock_setting_data);
501 cancel_button = elm_button_add(navi_bar);
502 elm_object_style_set(cancel_button, "naviframe/title/default");
503 elm_object_text_set(cancel_button, "Cancel"); /* hard code for demo */
504 elm_object_disabled_set(cancel_button, EINA_FALSE);
505 evas_object_smart_callback_add(cancel_button, "clicked",
506 _openlock_setting_pw_back_cb, openlock_setting_data);
508 /* Set navigation objects and push */
509 navi_it = elm_naviframe_item_push(navi_bar, "Enter Password", NULL, NULL,
510 ly, NULL); /* hard code for demo */
511 elm_object_item_part_content_set(navi_it, "title_right_btn", done_button);
512 elm_object_item_part_content_set(navi_it, "title_left_btn", cancel_button);
514 /* Remove <- button */
515 back_button = elm_object_item_part_content_get(navi_it, "prev_btn");
516 if (back_button != NULL) {
517 elm_object_item_part_content_set(navi_it, "prev_btn", NULL);
518 if (back_button != NULL) {
519 evas_object_del(back_button);