tizen 2.4 release
[framework/base/syspopup.git] / syspopup-app / syspopup-app.c
1 /*
2  * syspopup
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23
24 #include <stdio.h>
25 #include <appcore-efl.h>
26 #include <Ecore_X.h>
27 #include <bundle_internal.h>
28
29 #include "syspopup.h"
30 #include "syspopup-app.h"
31
32 #include <time.h>
33
34 #include <dlog.h>
35
36 #undef LOG_TAG
37 #define LOG_TAG "SYSPOPUP-APP"
38
39 #define _E(fmt, arg...) LOGE(fmt,##arg)
40 #define _D(fmt, arg...) LOGD(fmt,##arg)
41
42 int myterm(bundle *b, void *data)
43 {
44         _D("myterm called");
45         return 0;
46 }
47
48 int mytimeout(bundle *b, void* data)
49 {
50         _D("mytimeout called");
51         return 0;
52 }
53
54 syspopup_handler handler = {
55         .def_term_fn = myterm,
56         .def_timeout_fn = mytimeout
57 };
58
59 static void __win_del(void *data, Evas_Object * obj, void *event)
60 {
61         _D("__win_del called");
62         elm_exit();
63 }
64
65 static Evas_Object *__create_win(const char *name)
66 {
67         Evas_Object *eo;
68         int w;
69         int h;
70
71         eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
72         if (eo) {
73                 elm_win_title_set(eo, name);
74                 elm_win_borderless_set(eo, EINA_TRUE);
75
76                 elm_win_alpha_set(eo, EINA_TRUE);
77
78                 evas_object_smart_callback_add(eo, "delete,request",
79                                                __win_del, NULL);
80                 ecore_x_window_size_get(ecore_x_window_root_first_get(),
81                                         &w, &h);
82                 evas_object_resize(eo, w, h);
83         }
84
85         return eo;
86 }
87
88 static int __app_create(void *data)
89 {
90         struct appdata *ad = data;
91         Evas_Object *win;
92         int r;
93
94         _D("__app_create called");
95
96         /* create window */
97         win = __create_win(PACKAGE);
98         if (win == NULL)
99                 return -1;
100         ad->win = win;
101         /* evas_object_show(win);*/
102
103         /* init internationalization */
104         r = appcore_set_i18n(PACKAGE, LOCALEDIR);
105         if(r)
106                 return -1;
107
108         /* appcore_set_rotation_cb(rotate, ad);*/
109
110         appcore_measure_start();
111         return 0;
112 }
113
114 static int __app_terminate(void *data)
115 {
116         struct appdata *ad = data;
117
118         _D("__app_terminate called");
119
120         if (ad->win)
121                 evas_object_del(ad->win);
122
123         return 0;
124 }
125
126 static int __app_pause(void *data)
127 {
128         struct appdata *ad = data;
129
130         _D("__app_pause called");
131
132         return 0;
133 }
134
135 static int __app_resume(void *data)
136 {
137         struct appdata *ad = data;
138
139         _D("__app_resume called");
140
141         return 0;
142 }
143
144 static void __prt_recvd_bundle(const char *key, const char *value, void *d)
145 {
146         _D("recvd - key: %s, value: %s\n", key, value);
147 }
148
149 static void __response_cb(void *data, Evas_Object * obj, void *event_info)
150 {
151         _D("__response_cb called");
152
153         if ((int)event_info != 5)
154                 evas_object_del(obj);
155         elm_exit();
156 }
157
158 static void _block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
159 {
160         _D("_block_clicked_cb called");
161         evas_object_del(obj);
162 }
163
164 static int __app_reset(bundle *b, void *data)
165 {
166         struct appdata *ad = data;
167         Evas_Object *popup;
168         const char *val;
169         int ret = 0;
170
171         _D("__app_reset called");
172
173         ad->b = bundle_dup(b);
174
175         bundle_iterate(b, __prt_recvd_bundle, NULL);
176
177         if (syspopup_has_popup(b)) {
178                 syspopup_reset(b);
179         } else {
180                 popup = elm_popup_add(ad->win);
181                 if (popup != NULL) {
182                         ret = syspopup_create(b, &handler, ad->win, ad);
183                         evas_object_show(ad->win);
184
185                         if (ret == 0) {
186                                 val = bundle_get_val(b, "_SYSPOPUP_TITLE_");
187                                 if (val) {
188                                         snprintf(ad->title, TITLE_BUF_LEN, "%s",
189                                                  val);
190                                 } else {
191                                         snprintf(ad->title, TITLE_BUF_LEN, "%s",
192                                                  "Unknown Title");
193                                 }
194
195                                 val = bundle_get_val(b, "_SYSPOPUP_CONTENT_");
196                                 if (val) {
197                                         snprintf(ad->content, CONTENT_BUF_LEN,
198                                                  "%s", val);
199                                 } else {
200                                         snprintf(ad->content, CONTENT_BUF_LEN,
201                                                  "%s", "Unknown Content");
202                                 }
203
204                                 elm_object_style_set(popup, "char_wrap_style");
205                                 evas_object_size_hint_weight_set(popup,
206                                                         EVAS_HINT_EXPAND,
207                                                         EVAS_HINT_EXPAND);
208                                 evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb, NULL);
209                                 elm_object_part_text_set(popup, "title,text", ad->title);
210                                 elm_object_text_set(popup, ad->content);
211                                 evas_object_smart_callback_add(popup,
212                                                                "response",
213                                                                __response_cb,
214                                                                NULL);
215
216                                 evas_object_show(popup);
217                         }
218                 }
219         }
220
221         return 0;
222 }
223
224 int main(int argc, char *argv[])
225 {
226         struct appdata ad;
227         struct appcore_ops ops = {
228                 .create = __app_create,
229                 .terminate = __app_terminate,
230                 .pause = __app_pause,
231                 .resume = __app_resume,
232                 .reset = __app_reset,
233         };
234
235         //unsetenv("ELM_SCALE");
236
237         /* appcore measure time example */
238         _D("from AUL to %s(): %d msec\n", __func__,
239                appcore_measure_time_from("APP_START_TIME"));
240
241         memset(&ad, 0x0, sizeof(struct appdata));
242         ops.data = &ad;
243
244         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
245 }
246