4d47e1009b0a08d416ee4992f5d99036818096c5
[profile/tv/apps/native/air_home.git] / src / view / view_user_edit.c
1 /*
2
3  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <Elementary.h>
19 #include <app_debug.h>
20 #include <viewmgr.h>
21 #include <inputmgr.h>
22
23 #include "defs.h"
24 #include "view.h"
25 #include "datamgr.h"
26 #include "utils.h"
27
28 #define KEY_ICON "icon"
29 #define KEY_FOCUS_ICON "focusicon"
30
31 #define CTXPOPUP_X 294
32 #define CTXPOPUP_Y 310
33 #define MAX_BUF 128
34
35 enum input_handler_type {
36         INPUT_HANDLER_TYPE_PHOTO,
37         INPUT_HANDLER_TYPE_DELETE,
38         INPUT_HANDLER_TYPE_EO,
39         INPUT_HANDLER_TYPE_BTN_DONE,
40         INPUT_HANDLER_TYPE_BTN_CANCEL,
41         INPUT_HANDLER_TYPE_POPUP_BTN_DISCARD,
42         INPUT_HANDLER_TYPE_POPUP_BTN_CANCEL,
43         INPUT_HANDLER_TYPE_DELETE_POPUP_BTN_DELETE,
44         INPUT_HANDLER_TYPE_DELETE_POPUP_BTN_CANCEL,
45         INPUT_HANDLER_TYPE_ENTRY
46 };
47
48 enum user_item_type {
49         USER_ITEM_NONE = 0x00,
50         USER_ITEM_ADD = 0x01,
51         USER_ITEM_ADMIN = 0x02,
52         USER_ITEM_NORMAL = 0x08
53 };
54
55 struct _icon_info {
56         const char *file;
57         const char *focus_file;
58         const char *message;
59         const char *focus_message;
60 };
61
62 struct _priv {
63         Evas_Object *win;
64         Evas_Object *base;
65         Evas_Object *ly;
66         Evas_Object *photo;
67         Evas_Object *name;
68         Evas_Object *icon;
69         Evas_Object *focus_icon;
70         Evas_Object *done;
71         Evas_Object *cancel;
72         Evas_Object *ctxpopup;
73         Evas_Object *del;
74         Evas_Object *popup;
75
76         char *selected_photo;
77
78         struct datamgr *dm;
79         struct datamgr_item *di;
80
81         enum user_item_type user_type;
82 };
83
84 static void _focused(int id, void *data, Evas_Object *obj,
85                 Elm_Object_Item *item)
86 {
87         struct _priv *priv;
88
89         switch (id) {
90         case INPUT_HANDLER_TYPE_PHOTO:
91         case INPUT_HANDLER_TYPE_DELETE:
92         case INPUT_HANDLER_TYPE_EO:
93                 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
94                 break;
95         case INPUT_HANDLER_TYPE_ENTRY:
96                 priv = data;
97                 elm_object_signal_emit(obj, SIG_SELECT, SRC_ELM);
98                 elm_object_signal_emit(priv->ly, SIG_FOCUS, SRC_PROG);
99                 break;
100         default:
101                  return;
102         }
103 }
104
105 static void _unfocused(int id, void *data, Evas_Object *obj,
106                 Elm_Object_Item *item)
107 {
108         struct _priv *priv;
109
110         switch (id) {
111         case INPUT_HANDLER_TYPE_PHOTO:
112         case INPUT_HANDLER_TYPE_DELETE:
113         case INPUT_HANDLER_TYPE_EO:
114                 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
115                 break;
116         case INPUT_HANDLER_TYPE_ENTRY:
117                 priv = data;
118                 elm_object_signal_emit(obj, SIG_UNSELECT, SRC_ELM);
119                 elm_object_signal_emit(priv->ly, SIG_UNFOCUS, SRC_PROG);
120                 break;
121         default:
122                 return;
123         }
124 }
125
126 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
127                 Evas_Event_Key_Down *ev);
128
129 static void _mouse_up(int id, void *data, Evas *e, Evas_Object *obj,
130                 Evas_Event_Mouse_Up *ev);
131
132 static void _mouse_move(int id, void *data, Evas *e, Evas_Object *obj,
133                 Evas_Event_Mouse_Move *ev)
134 {
135         if (!elm_object_focus_get(obj))
136                 elm_object_focus_set(obj, EINA_TRUE);
137 }
138
139 static input_handler handler = {
140         .focused = _focused,
141         .unfocused = _unfocused,
142         .key_down = _key_down,
143         .mouse_up = _mouse_up,
144         .mouse_move = _mouse_move
145 };
146
147 static void _get_profile(struct _priv *priv, const char **name,
148                 const char **photo)
149 {
150         *name = elm_entry_entry_get(priv->name);
151         elm_image_file_get(priv->icon, photo, NULL);
152         *photo = utils_get_icon_from_photo(*photo);
153 }
154
155 static void _delete_popup(struct _priv *priv, Evas_Object *obj)
156 {
157         inputmgr_remove_callback(obj, &handler);
158         evas_object_del(priv->popup);
159         priv->popup = NULL;
160 }
161
162 static void _add_discard_popup(struct _priv *priv)
163 {
164         Evas_Object *popup, *discard_btn, *cancel_btn;
165
166         popup = utils_add_popup(priv->base, MESSAGE_DISCARD,
167                         MESSAGE_DISCARD_CONTENTS);
168         if (!popup) {
169                 _ERR("failed to add popup");
170                 return;
171         }
172         priv->popup = popup;
173
174         discard_btn = utils_add_button(popup, MESSAGE_DISCARD,
175                         PART_POPUP_BUTTON_1);
176         if (!discard_btn) {
177                 _ERR("failed to add delete btn");
178                 evas_object_del(popup);
179                 return;
180         }
181         inputmgr_add_callback(discard_btn, INPUT_HANDLER_TYPE_POPUP_BTN_DISCARD,
182                         &handler, priv);
183
184         cancel_btn = utils_add_button(popup, MESSAGE_CANCEL,
185                         PART_POPUP_BUTTON_2);
186         if (!cancel_btn) {
187                 _ERR("failed to add cancel btn");
188                 evas_object_del(popup);
189                 return;
190         }
191         inputmgr_add_callback(cancel_btn, INPUT_HANDLER_TYPE_POPUP_BTN_CANCEL,
192                         &handler, priv);
193         elm_object_focus_set(cancel_btn, EINA_TRUE);
194 }
195
196 static bool _check_changed_input(struct _priv *priv)
197 {
198         const char *photo, *name;
199
200         _get_profile(priv, &name, &photo);
201
202         if (priv->di) {
203                 if (!strcmp(photo, priv->di->icon))
204                         return false;
205         } else {
206                 if (!strcmp(name, "") && !strcmp(photo, IMAGE_USER_DEFAULT))
207                         return false;
208         }
209
210         return true;
211 }
212
213 static bool _add_btns(struct _priv *priv)
214 {
215         Evas_Object *done, *cancel;
216
217         done = utils_add_button(priv->base, MESSAGE_DONE,
218                         PART_USER_EDIT_BTN_DONE);
219         if (!done) {
220                 _ERR("failed to add done btn");
221                 return false;
222         }
223         inputmgr_add_callback(done, INPUT_HANDLER_TYPE_BTN_DONE, &handler,
224                         priv);
225
226         cancel = utils_add_button(priv->base, MESSAGE_CANCEL,
227                         PART_USER_EDIT_BTN_CANCEL);
228         if (!cancel) {
229                 _ERR("failed to add cancel btn");
230                 evas_object_del(done);
231                 return false;
232         }
233         inputmgr_add_callback(cancel, INPUT_HANDLER_TYPE_BTN_CANCEL, &handler,
234                         priv);
235
236         priv->cancel = cancel;
237         priv->done = done;
238
239         return true;
240 }
241
242 static void _load_user_icon(struct _priv *priv, const char *file,
243                 const char *focus_file)
244 {
245         Evas_Object *icon, *focus_icon;
246
247         icon = utils_add_icon(priv->photo, file, PART_USER_EDIT_PHOTO);
248         if (!icon)
249                 _ERR("failed to add icon");
250
251         focus_icon = utils_add_icon(priv->photo, focus_file,
252                         PART_USER_EDIT_PHOTO_FOCUS);
253         if (!focus_icon)
254                 _ERR("failed to add focus icon");
255
256         priv->icon = icon;
257         priv->focus_icon = focus_icon;
258 }
259
260 static Evas_Object *_pack_icon(Evas_Object *table, struct icon_info *_icon_info,
261                 int i)
262 {
263         Evas_Object *eo, *ic, *focus_ic;
264
265         eo = utils_add_layout(table, GRP_USER_EDIT_ICON_LIST_ITEM, true, NULL);
266         if (!eo) {
267                 _ERR("failed to add layout");
268                 return NULL;
269         }
270         evas_object_show(eo);
271         elm_table_pack(table, eo, i % 4, i / 4, 1, 1);
272
273         ic = utils_add_icon(eo, _icon_info->icon_file,
274                         PART_USER_EDIT_ICON_LIST_ITEM);
275         if (!ic) {
276                 _ERR("failed to add icon");
277                 evas_object_del(eo);
278                 return NULL;
279         }
280
281         focus_ic = utils_add_icon(eo, _icon_info->focus_icon_file,
282                         PART_USER_EDIT_ICON_LIST_ITEM_FOCUS);
283         if (!focus_ic) {
284                 _ERR("failed to add focus icon");
285                 evas_object_del(eo);
286                 return NULL;
287         }
288         evas_object_data_set(eo, KEY_ICON, _icon_info->photo_file);
289
290         return eo;
291 }
292
293 static void _dismissed(void *data, Evas_Object *obj, void *ei)
294 {
295         struct _priv *priv = data;
296
297         elm_object_focus_allow_set(priv->photo, EINA_TRUE);
298 }
299
300 static void _add_icon_list(struct _priv *priv)
301 {
302         Evas_Coord x, y, w, h;
303         Evas_Object *ctxpopup, *ly, *table, *eo;
304         int i;
305         struct icon_info *_icon_info;
306
307         ctxpopup = elm_ctxpopup_add(priv->base);
308         if (!ctxpopup) {
309                 _ERR("failed to add ctxpopup");
310                 return;
311         }
312         elm_ctxpopup_horizontal_set(ctxpopup, EINA_TRUE);
313         elm_ctxpopup_auto_hide_disabled_set(ctxpopup, EINA_TRUE);
314         evas_object_smart_callback_add(ctxpopup, "dismissed", _dismissed, priv);
315
316         ly = utils_add_layout(ctxpopup, GRP_USER_EDIT_ICON_LIST, false, NULL);
317         if (!ly) {
318                 _ERR("failed to layout");
319                 evas_object_del(ctxpopup);
320                 return;
321         }
322         elm_object_content_set(ctxpopup, ly);
323         evas_object_show(ly);
324         evas_object_show(ctxpopup);
325
326         evas_object_geometry_get(priv->photo, &x, &y, &w, &h);
327         evas_object_move(ctxpopup,
328                         (x + w + CTXPOPUP_X) * elm_config_scale_get(),
329                         (y + CTXPOPUP_Y) * elm_config_scale_get());
330
331         table = utils_add_table(ly, true, PART_USER_EDIT_ICON_LIST);
332         if (!table) {
333                 _ERR("failed to add table");
334                 evas_object_del(ctxpopup);
335                 return;
336         }
337         elm_table_padding_set(table, elm_config_scale_get() * 1,
338                         elm_config_scale_get() * 1);
339         evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND,
340                         EVAS_HINT_EXPAND);
341
342         _icon_info = utils_get_icon_info();
343
344         for (i = 0; i < MAX_ITEM_COUNT; i++) {
345                 eo = _pack_icon(table, &_icon_info[i], i);
346                 if (!eo)
347                         continue;
348
349                 inputmgr_add_callback(eo, INPUT_HANDLER_TYPE_EO, &handler,
350                                 priv);
351                 if (i == 0)
352                         elm_object_focus_set(eo, EINA_TRUE);
353         }
354
355         elm_object_focus_allow_set(priv->photo, EINA_FALSE);
356         priv->ctxpopup = ctxpopup;
357 }
358
359 static Evas_Object *_add_layout(struct _priv *priv)
360 {
361         Evas_Object *ly, *photo, *name, *lock;
362
363         ly = utils_add_layout(priv->base, GRP_USER_EDIT_CONTENTS, false,
364                         PART_USER_EDIT_CONTENTS);
365         if (!ly) {
366                 _ERR("failed to add layout");
367                 return NULL;
368         }
369
370         photo = utils_add_layout(ly, GRP_USER_EDIT_PHOTO, true,
371                         PART_USER_EDIT_CONTENTS_PHOTO);
372         if (!photo)
373                 goto err;
374
375         name = utils_add_entry(ly, "", false, PART_USER_EDIT_CONTENTS_NAME);
376         if (!name)
377                 goto err;
378
379         lock = utils_add_layout(ly, GRP_USER_EDIT_SWITCH, false,
380                         PART_USER_EDIT_CONTENTS_LOCK);
381         if (!lock)
382                 goto err;
383
384         utils_add_icon(lock, IMAGE_SWITCH_OFF, PART_USER_EDIT_SWITCH);
385
386         inputmgr_add_callback(photo, INPUT_HANDLER_TYPE_PHOTO, &handler, priv);
387         inputmgr_add_callback(name, INPUT_HANDLER_TYPE_ENTRY, &handler, priv);
388
389         priv->photo = photo;
390         priv->name = name;
391
392         return ly;
393 err:
394         _ERR("failed to add layout");
395         evas_object_del(ly);
396         return NULL;
397 }
398
399 static bool _add_user_edit(struct _priv *priv)
400 {
401         Evas_Object *ly;
402
403         ly = _add_layout(priv);
404         if (!ly) {
405                 _ERR("failed to add edit layout");
406                 return false;
407         }
408
409         if (!_add_btns(priv)) {
410                 _ERR("failed to add buttons");
411                 evas_object_del(ly);
412                 return false;
413         }
414
415         priv->ly = ly;
416
417         return true;
418 }
419
420 static Evas_Object *_create(Evas_Object *win, void *data)
421 {
422         struct _priv *priv;
423         Evas_Object *base;
424
425         if (!win || !data) {
426                 _ERR("Invalid argument");
427                 return NULL;
428         }
429
430         priv = calloc(1, sizeof(*priv));
431         if (!priv) {
432                 _ERR("failed to calloc priv");
433                 return NULL;
434         }
435
436         base = utils_add_layout(win, GRP_USER_EDIT, false, NULL);
437         if (!base) {
438                 _ERR("failed to create base");
439                 free(priv);
440                 return NULL;
441         }
442         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
443                         EVAS_HINT_EXPAND);
444         elm_win_resize_object_add(win, base);
445
446         priv->win = win;
447         priv->base = base;
448         priv->dm = data;
449
450         if (!_add_user_edit(priv)) {
451                 _ERR("failed to add user edit layout");
452                 evas_object_del(base);
453                 free(priv);
454                 return NULL;
455         }
456
457         viewmgr_set_view_data(VIEW_USER_EDIT, priv);
458         viewmgr_add_view(view_photo_get_vclass(), NULL);
459
460         return base;
461 }
462
463 static void _add_delete_popup(struct _priv *priv)
464 {
465         Evas_Object *popup, *delete_btn, *cancel_btn;
466         char buf[MAX_BUF];
467
468         snprintf(buf, sizeof(buf), "%s %s?<br> %s", MESSAGE_DELETE,
469                         priv->di->title, MESSAGE_DELETE_CONTENTS);
470
471         popup = utils_add_popup(priv->base, MESSAGE_DELETE_USER, buf);
472         if (!popup) {
473                 _ERR("failed to add popup");
474                 return;
475         }
476         priv->popup = popup;
477
478         delete_btn = utils_add_button(popup, MESSAGE_DELETE,
479                         PART_POPUP_BUTTON_1);
480         if (!delete_btn) {
481                 _ERR("failed to add delete btn");
482                 evas_object_del(popup);
483                 return;
484         }
485         inputmgr_add_callback(delete_btn,
486                         INPUT_HANDLER_TYPE_DELETE_POPUP_BTN_DELETE,
487                         &handler, priv);
488
489         cancel_btn = utils_add_button(popup, MESSAGE_CANCEL,
490                         PART_POPUP_BUTTON_2);
491         if (!cancel_btn) {
492                 _ERR("failed to add cancel btn");
493                 evas_object_del(popup);
494                 return;
495         }
496         inputmgr_add_callback(cancel_btn,
497                         INPUT_HANDLER_TYPE_DELETE_POPUP_BTN_CANCEL,
498                         &handler, priv);
499
500         elm_object_focus_allow_set(priv->del, EINA_FALSE);
501         elm_object_focus_set(cancel_btn, EINA_TRUE);
502 }
503
504 static void _select_eo(struct _priv *priv, Evas_Object *obj)
505 {
506         const char *file, *focus_file;
507
508         evas_object_del(priv->ctxpopup);
509         priv->ctxpopup = NULL;
510         elm_object_focus_allow_set(priv->photo, EINA_TRUE);
511
512         file = evas_object_data_get(obj, KEY_ICON);
513         focus_file = utils_get_focus_photo_from_photo(file);
514
515         if (!strcmp(file, ICON_ADD) || !strcmp(focus_file, ICON_ADD)) {
516                 viewmgr_push_view(VIEW_PHOTO);
517                 elm_object_focus_allow_set(obj, EINA_FALSE);
518         } else
519                 _load_user_icon(priv, file, focus_file);
520 }
521
522 static void _select_btn_done(struct _priv *priv)
523 {
524         const char *name, *photo;
525
526         _get_profile(priv, &name, &photo);
527         if (priv->di) {
528                 priv->di->action = ITEM_SELECT_ACTION_UPDATE;
529                 priv->di->title = strdup(name ? name : "");
530                 priv->di->icon = strdup(photo ? photo :
531                                 IMAGE_USER_DEFAULT);
532                 datamgr_select_item(priv->dm, priv->di);
533         } else {
534                 if (!name || !strcmp(name, "")) {
535                         elm_object_focus_set(priv->name, EINA_TRUE);
536                         return;
537                 }
538                 datamgr_add_item(priv->dm, name, photo, "");
539         }
540
541         priv->di = NULL;
542         viewmgr_pop_view();
543 }
544
545 static void _select(struct _priv *priv, int id, Evas_Object *obj)
546 {
547         switch (id) {
548         case INPUT_HANDLER_TYPE_PHOTO:
549                 _add_icon_list(priv);
550                 break;
551         case INPUT_HANDLER_TYPE_DELETE:
552                 _add_delete_popup(priv);
553                 break;
554         case INPUT_HANDLER_TYPE_EO:
555                 _select_eo(priv, obj);
556                 break;
557         case INPUT_HANDLER_TYPE_ENTRY:
558         case INPUT_HANDLER_TYPE_BTN_DONE:
559                 _select_btn_done(priv);
560                 break;
561         case INPUT_HANDLER_TYPE_BTN_CANCEL:
562                 if (_check_changed_input(priv)) {
563                         _add_discard_popup(priv);
564                         return;
565                 }
566                 viewmgr_pop_view();
567                 break;
568         case INPUT_HANDLER_TYPE_DELETE_POPUP_BTN_DELETE:
569                 _delete_popup(priv, obj);
570                 elm_object_focus_allow_set(priv->del, EINA_TRUE);
571                 priv->di->action = ITEM_SELECT_ACTION_DELETE;
572                 datamgr_select_item(priv->dm, priv->di);
573                 viewmgr_pop_view();
574                 break;
575         case INPUT_HANDLER_TYPE_POPUP_BTN_DISCARD:
576                 _delete_popup(priv, obj);
577                 viewmgr_pop_view();
578                 break;
579         case INPUT_HANDLER_TYPE_DELETE_POPUP_BTN_CANCEL:
580                 elm_object_focus_allow_set(priv->del, EINA_TRUE);
581         case INPUT_HANDLER_TYPE_POPUP_BTN_CANCEL:
582                 _delete_popup(priv, obj);
583                 break;
584         default:
585                 return;
586         }
587 }
588
589 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
590                 Evas_Event_Key_Down *ev)
591 {
592         struct _priv *priv;
593
594         if (!data) {
595                 _ERR("Invalid argument");
596                 return;
597         }
598
599         priv = data;
600         if (!strcmp(ev->keyname, KEY_BACK) ||
601                         !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
602                 switch (id) {
603                 case INPUT_HANDLER_TYPE_PHOTO:
604                 case INPUT_HANDLER_TYPE_BTN_DONE:
605                 case INPUT_HANDLER_TYPE_BTN_CANCEL:
606                 case INPUT_HANDLER_TYPE_DELETE:
607                 case INPUT_HANDLER_TYPE_ENTRY:
608                         if (_check_changed_input(priv)) {
609                                 _add_discard_popup(priv);
610                                 return;
611                         }
612                         viewmgr_pop_view();
613                         break;
614                 case INPUT_HANDLER_TYPE_EO:
615                         evas_object_del(priv->ctxpopup);
616                         priv->ctxpopup = NULL;
617                         elm_object_focus_allow_set(priv->photo, EINA_TRUE);
618                         break;
619                 case INPUT_HANDLER_TYPE_DELETE_POPUP_BTN_DELETE:
620                         _delete_popup(priv, obj);
621                         elm_object_focus_allow_set(priv->del, EINA_TRUE);
622                         break;
623                 case INPUT_HANDLER_TYPE_POPUP_BTN_DISCARD:
624                         _delete_popup(priv, obj);
625                         break;
626                 case INPUT_HANDLER_TYPE_DELETE_POPUP_BTN_CANCEL:
627                         elm_object_focus_allow_set(priv->del, EINA_TRUE);
628                 case INPUT_HANDLER_TYPE_POPUP_BTN_CANCEL:
629                         _delete_popup(priv, obj);
630                         break;
631                 default:
632                         return;
633                 }
634         } else if (!strcmp(ev->keyname, KEY_ENTER) ||
635                         !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
636                 _select(priv, id, obj);
637         } else if (!strcmp(ev->keyname, KEY_RIGHT)) {
638                 if (id == INPUT_HANDLER_TYPE_PHOTO && priv->del)
639                         elm_object_focus_set(priv->del, EINA_TRUE);
640         }
641 }
642
643 static void _mouse_up(int id, void *data, Evas *e, Evas_Object *obj,
644                 Evas_Event_Mouse_Up *ev)
645 {
646         struct _priv *priv;
647
648         if (!data) {
649                 _ERR("Invalid argument");
650                 return;
651         }
652
653         priv = data;
654         _select(priv, id, obj);
655 }
656
657 static void _load_del_btn(struct _priv *priv)
658 {
659         Evas_Object *btn;
660
661         btn = utils_add_layout(priv->ly, GRP_USER_EDIT_DELETE, true,
662                         PART_USER_EDIT_CONTENTS_DELETE);
663         if (!btn) {
664                 _ERR("failed to add delete button");
665                 return;
666         }
667         inputmgr_add_callback(btn, INPUT_HANDLER_TYPE_DELETE, &handler, priv);
668
669         priv->del = btn;
670 }
671
672 static void _change_entry(Evas_Object *name, Evas_Object *ly, Eina_Bool disable,
673                 const char *text, const char *signal)
674 {
675         elm_entry_entry_set(name, text);
676         elm_object_focus_allow_set(name, disable);
677         elm_entry_editable_set(name, disable);
678         elm_object_signal_emit(ly, signal, SRC_PROG);
679 }
680
681 static void _show(void *data)
682 {
683         struct _priv *priv;
684         const char *photo, *focus_photo;
685
686         if (!data) {
687                 _ERR("Invalid argument");
688                 return;
689         }
690
691         priv = data;
692
693         if (priv->di) {
694                 elm_object_part_text_set(priv->base, PART_USER_EDIT_TITLE,
695                                 MESSAGE_EDIT_USER);
696                 _change_entry(priv->name, priv->ly, EINA_FALSE, priv->di->title,
697                                 SIG_DISABLE);
698                 if (priv->selected_photo) {
699                         _load_user_icon(priv, priv->selected_photo,
700                                         priv->selected_photo);
701                  } else {
702                         photo = utils_get_photo_from_icon(priv->di->icon);
703                         focus_photo = utils_get_focus_photo_from_photo(photo);
704                         _load_user_icon(priv, photo, focus_photo);
705                 }
706                 if (priv->user_type == USER_ITEM_ADMIN &&
707                                 priv->di->type != USER_ITEM_ADMIN)
708                         _load_del_btn(priv);
709         } else {
710                 elm_object_part_text_set(priv->base, PART_USER_EDIT_TITLE,
711                                 MESSAGE_ADD_USER);
712                 _change_entry(priv->name, priv->ly, EINA_TRUE, "", SIG_ENABLE);
713                 if (priv->selected_photo)
714                         _load_user_icon(priv, priv->selected_photo,
715                                         priv->selected_photo);
716                 else
717                         _load_user_icon(priv, IMAGE_USER_CURRENT_DEFAULT,
718                                         IMAGE_USER_CURRENT_DEFAULT_FOCUS);
719         }
720
721         evas_object_show(priv->base);
722         elm_object_focus_set(priv->cancel, EINA_TRUE);
723 }
724
725 static void _hide(void *data)
726 {
727         struct _priv *priv;
728
729         if (!data) {
730                 _ERR("Invalid argument");
731                 return;
732         }
733
734         priv = data;
735         if (priv->del) {
736                 inputmgr_remove_callback(priv->del, &handler);
737                 evas_object_del(priv->del);
738                 priv->del = NULL;
739         }
740
741         priv->selected_photo = NULL;
742         evas_object_hide(priv->base);
743 }
744
745 static void _destroy(void *data)
746 {
747         struct _priv *priv;
748
749         if (!data) {
750                 _ERR("Invalid argument");
751                 return;
752         }
753
754         priv = data;
755
756         inputmgr_remove_callback(priv->photo, &handler);
757         inputmgr_remove_callback(priv->done, &handler);
758         inputmgr_remove_callback(priv->cancel, &handler);
759         viewmgr_remove_view(VIEW_PHOTO);
760         evas_object_del(priv->base);
761         free(priv);
762 }
763
764 static void _update(void *view_data, int update_type, void *data)
765 {
766         struct _priv *priv;
767
768         if (!view_data) {
769                 _ERR("Invalid argument");
770                 return;
771         }
772
773         priv = view_data;
774
775         switch (update_type) {
776         case UPDATE_TYPE_EDIT:
777                 priv->di = data;
778                 break;
779         case UPDATE_TYPE_PHOTO:
780                 priv->selected_photo = data;
781                 break;
782         case UPDATE_TYPE_USER:
783                 priv->user_type = (enum user_item_type) data;
784                 break;
785         default:
786                 _ERR("Invalid type");
787                 return;
788         }
789 }
790
791 static view_class vclass = {
792         .view_id = VIEW_USER_EDIT,
793         .create = _create,
794         .show = _show,
795         .hide = _hide,
796         .destroy = _destroy,
797         .update = _update
798 };
799
800 view_class *view_user_edit_get_vclass(void)
801 {
802         return &vclass;
803 }