Tizen release 1.0
[pkgs/p/phone-lock.git] / phone-lock-main / src / phone-lock-ui.c
1 /*
2  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved 
3  *
4  * This file is part of <phone-lock>
5  * Written by <Seungtaek Chung> <seungtaek.chung@samsung.com>, <Mi-Ju Lee> <miju52.lee@samsung.com>, <Xi Zhichan> <zhichan.xi@samsung.com>
6  *
7  * PROPRIETARY/CONFIDENTIAL
8  *
9  * This software is the confidential and proprietary information of SAMSUNG ELECTRONICS ("Confidential Information").
10  * You shall not disclose such Confidential Information and shall use it only in accordance
11  * with the terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
12  * SAMSUNG make no representations or warranties about the suitability of the software,
13  * either express or implied, including but not limited to the implied warranties of merchantability,
14  * fitness for a particular purpose, or non-infringement.
15  * SAMSUNG shall not be liable for any damages suffered by licensee as a result of using,
16  * modifying or distributing this software or its derivatives.
17  *
18  */
19
20 #include <appcore-efl.h>
21 #include <ui-gadget.h>
22 #include <Ecore_X.h>
23 #include <vconf.h>
24 #include <bundle.h>
25
26 #include "phone-lock.h"
27 #include "phone-lock-util.h"
28 #include "phone-lock-ui.h"
29 #include "phone-lock-string.h"
30
31 static void _phone_lock_alpha_ug_layout_cb(struct ui_gadget *ug,
32                                            enum ug_mode mode, void *priv)
33 {
34         struct appdata *ad = NULL;
35         Evas_Object *base;
36
37         if (!ug || !priv)
38                 return;
39
40         ad = priv;
41         base = ug_get_layout(ug);
42         if (!base)
43                 return;
44
45         switch (mode) {
46         case UG_MODE_FULLVIEW:
47                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
48                                                  EVAS_HINT_EXPAND);
49                 elm_win_resize_object_add(ad->win, base);
50                 evas_object_show(base);
51                 break;
52         case UG_MODE_FRAMEVIEW:
53                 break;
54         default:
55                 break;
56         }
57 }
58
59 static void _phone_lock_alpha_ug_result_cb(struct ui_gadget *ug,
60                                            bundle * result, void *priv)
61 {
62         struct appdata *ad = (struct appdata *)priv;
63         const char *val1 = NULL, *val2 = NULL;
64         int alpha;
65
66         if (!ug || !priv)
67                 return;
68         ad = (struct appdata *)priv;
69
70         val1 = bundle_get_val(result, "name");
71
72         if (val1 == NULL)
73                 return;
74
75         if (!strcmp(val1, "phonelock-ug")) {
76                 val2 = bundle_get_val(result, "result");
77                 if (val2 == NULL)
78                         return;
79
80                 if (!strcmp(val2, "success")) {
81                         _DBG("password verified. Unlock!\n");
82                 }
83         } else if (!strcmp(val1, "phonelock-ug-alpha")) {
84                 val2 = bundle_get_val(result, "result");
85                 if (val2 == NULL)
86                         return;
87
88                 alpha = atoi(val2);
89         }
90 }
91
92 static void _phone_lock_alpha_ug_destroy_cb(struct ui_gadget *ug, void *priv)
93 {
94         struct appdata *ad = (struct appdata *)priv;
95
96         if (!ug)
97                 return;
98
99         ug_destroy(ug);
100         ug = NULL;
101         phone_lock_send_cmd("unlock");
102 }
103
104 int phone_lock_show_alpha_ug(struct appdata *ad)
105 {
106         _DBG("%s,%d", __func__, __LINE__);
107
108         bundle *b = NULL;
109         struct ug_cbs cbs = { 0, };
110
111         cbs.layout_cb = _phone_lock_alpha_ug_layout_cb;
112         cbs.result_cb = _phone_lock_alpha_ug_result_cb;
113         cbs.destroy_cb = _phone_lock_alpha_ug_destroy_cb;
114         cbs.priv = (void *)ad;
115
116         b = bundle_create();
117         bundle_add(b, "phone-lock-type", "phone-lock");
118         bundle_add(b, "window-type", "alpha");
119
120         elm_win_alpha_set(ad->win, TRUE);
121         evas_object_color_set(ad->win, 0, 0, 0, 0);
122
123         Evas_Object *bg = elm_bg_add(ad->win);
124         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
125                                          EVAS_HINT_EXPAND);
126         evas_object_color_set(bg, 255, 255, 255, 120);
127         elm_win_resize_object_add(ad->win, bg);
128         evas_object_show(bg);
129
130         ecore_x_icccm_name_class_set(elm_win_xwindow_get(ad->win),
131                                      "LOCK_SCREEN", "LOCK_SCREEN");
132
133         UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_ENABLE);
134         ug_create(NULL, "phone-lock-efl", UG_MODE_FULLVIEW, b, &cbs);
135
136         if (b) {
137                 bundle_free(b);
138         }
139
140         evas_object_show(ad->win);
141         phone_lock_set_win_prop(ad, ECORE_X_WINDOW_TYPE_NOTIFICATION);
142         return 1;
143 }