Initialize Tizen 2.3
[framework/base/syspopup.git] / mobile / 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
28 #include "syspopup.h"
29 #include "syspopup-app.h"
30
31 #include <time.h>
32
33 #include <dlog.h>
34
35 #undef LOG_TAG
36 #define LOG_TAG "SYSPOPUP-APP"
37
38 #define _E(fmt, arg...) LOGE(fmt,##arg)
39 #define _D(fmt, arg...) LOGD(fmt,##arg)
40
41 /*
42 struct quickpanel {
43         int type;
44         int priv_id; 
45         char *title;
46         char *content;
47         time_t rtime;
48         bundle *args; 
49         bundle *args_group;
50         int group_id;
51 };
52 */
53
54 int myterm(bundle *b, void *data)
55 {
56         /*
57         char b_str[QP_BUF_LEN];
58         int ret = 0;
59         const char* val;
60
61         struct appdata *ad = data;
62         struct quickpanel* qp;
63
64         val = bundle_get_val(b,"_INTERNAL_SYSPOPUP_NAME_");
65         printf("[SYSTEM POPUP] Popup Name : %s\n", val);
66
67         qp = malloc(sizeof(struct quickpanel));
68         memset(qp,0,sizeof(struct quickpanel));
69
70         //qp->type = QP_TYPE_SYSPOPUP;
71         qp->type = quickpanel_get_type_id("org.tizen.syspopup-app", NULL, 0);
72         qp->priv_id = QP_PRIVID;
73         qp->title = ad->title;
74         qp->content = ad->content;
75         qp->args = b;
76         qp->group_id = qp->priv_id;
77
78         ret = quickpanel_insert(qp);
79         if (ret < 0)
80                 printf("[SYSTEM POPUP] Error!! Cannot insert to quickpanel!\n");
81
82         free(qp);
83         */
84         return 0;
85 }
86
87 int mytimeout(bundle *b, void* data)
88 {
89         /*
90         char b_str[QP_BUF_LEN];
91         int ret = 0;
92         const char* val;
93
94         struct appdata *ad = data;
95         struct quickpanel* qp;
96
97         val = bundle_get_val(b,"_INTERNAL_SYSPOPUP_NAME_");
98         printf("[SYSTEM POPUP] Popup Name : %s\n", val);
99
100         qp = malloc(sizeof(struct quickpanel));
101         memset(qp,0,sizeof(struct quickpanel));
102
103         //qp->type = QP_TYPE_SYSPOPUP;
104         qp->type = quickpanel_get_type_id("org.tizen.syspopup-app", NULL, 0);
105         qp->priv_id = QP_PRIVID;
106         qp->title = ad->title;
107         qp->content = ad->content;
108         qp->args = b;
109         qp->group_id = qp->priv_id;
110
111         ret = quickpanel_insert(qp);
112         if (ret < 0)
113                 printf("[SYSTEM POPUP] Error!! Cannot insert to quickpanel!\n");
114
115         free(qp);
116         */
117         return 0;
118 }
119
120 syspopup_handler handler = {
121         .def_term_fn = myterm,
122         .def_timeout_fn = mytimeout
123 };
124
125 static void __win_del(void *data, Evas_Object * obj, void *event)
126 {
127         elm_exit();
128 }
129
130 /*
131 static int rotate(enum appcore_rm m, void *data)
132 {
133         struct appdata *ad = data;
134         int r;
135
136         if (ad == NULL || ad->win == NULL)
137                 return 0;
138
139         switch(m) {
140         case APPCORE_RM_PORTRAIT_NORMAL:
141                 r = 0;
142                 break;
143         case APPCORE_RM_PORTRAIT_REVERSE:
144                 r = 180;
145                 break;
146         case APPCORE_RM_LANDSCAPE_NORMAL:
147                 r = 270;
148                 break;
149         case APPCORE_RM_LANDSCAPE_REVERSE:
150                 r = 90;
151                 break;
152         default:
153                 r = -1;
154                 break;
155         }
156
157         if (r >= 0)
158                 elm_win_rotation_with_resize_set(ad->win, r);
159
160         return 0;
161 }
162 */
163
164 static Evas_Object *__create_win(const char *name)
165 {
166         Evas_Object *eo;
167         int w;
168         int h;
169
170         eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
171         if (eo) {
172                 elm_win_title_set(eo, name);
173                 elm_win_borderless_set(eo, EINA_TRUE);
174
175                 elm_win_alpha_set(eo, EINA_TRUE);
176
177                 evas_object_smart_callback_add(eo, "delete,request",
178                                                __win_del, NULL);
179                 ecore_x_window_size_get(ecore_x_window_root_first_get(),
180                                         &w, &h);
181                 evas_object_resize(eo, w, h);
182         }
183
184         return eo;
185 }
186
187 static int __app_create(void *data)
188 {
189         struct appdata *ad = data;
190         Evas_Object *win;
191         int r;
192
193         /* create window */
194         win = __create_win(PACKAGE);
195         if (win == NULL)
196                 return -1;
197         ad->win = win;
198         /* evas_object_show(win);*/
199
200         /* init internationalization */
201         r = appcore_set_i18n(PACKAGE, LOCALEDIR);
202         if (r)
203                 return -1;
204
205         /* appcore_set_rotation_cb(rotate, ad);*/
206
207         appcore_measure_start();
208         return 0;
209 }
210
211 static int __app_terminate(void *data)
212 {
213         struct appdata *ad = data;
214
215         _D("__app_terminate called");
216
217         if (ad->win)
218                 evas_object_del(ad->win);
219
220         return 0;
221 }
222
223 static int __app_pause(void *data)
224 {
225         struct appdata *ad = data;
226
227         return 0;
228 }
229
230 static int __app_resume(void *data)
231 {
232         struct appdata *ad = data;
233
234         return 0;
235 }
236
237 static void __prt_recvd_bundle(const char *key, const char *value, void *d)
238 {
239         _D("recvd - key: %s, value: %s\n", key, value);
240 }
241
242 static void __response_cb(void *data, Evas_Object * obj, void *event_info)
243 {
244         if ((int)event_info != 5)
245                 evas_object_del(obj);
246         elm_exit();
247 }
248
249 static void _block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
250 {
251         evas_object_del(obj);
252 }
253
254 static int __app_reset(bundle *b, void *data)
255 {
256         struct appdata *ad = data;
257         Evas_Object *popup;
258         const char *val;
259         int ret = 0;
260
261         ad->b = bundle_dup(b);
262
263         bundle_iterate(b, __prt_recvd_bundle, NULL);
264
265         if (syspopup_has_popup(b)) {
266                 syspopup_reset(b);
267         } else {
268                 popup = elm_popup_add(ad->win);
269                 if (popup != NULL) {
270                         ret = syspopup_create(b, &handler, ad->win, ad);
271                         evas_object_show(ad->win);
272
273                         if (ret == 0) {
274                                 val = bundle_get_val(b, "_SYSPOPUP_TITLE_");
275                                 if (val) {
276                                         snprintf(ad->title, TITLE_BUF_LEN, "%s",
277                                                  val);
278                                 } else {
279                                         snprintf(ad->title, TITLE_BUF_LEN, "%s",
280                                                  "Unknown Title");
281                                 }
282
283                                 val = bundle_get_val(b, "_SYSPOPUP_CONTENT_");
284                                 if (val) {
285                                         snprintf(ad->content, CONTENT_BUF_LEN,
286                                                  "%s", val);
287                                 } else {
288                                         snprintf(ad->content, CONTENT_BUF_LEN,
289                                                  "%s", "Unknown Content");
290                                 }
291
292                                 elm_object_style_set(popup, "char_wrap_style");
293                                 evas_object_size_hint_weight_set(popup,
294                                                         EVAS_HINT_EXPAND,
295                                                         EVAS_HINT_EXPAND);
296                                 evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb, NULL);
297                                 elm_object_part_text_set(popup, "title,text", ad->title);
298                                 elm_object_text_set(popup, ad->content);
299                                 evas_object_smart_callback_add(popup,
300                                                                "response",
301                                                                __response_cb,
302                                                                NULL);
303
304                                 evas_object_show(popup);
305                         }
306                 }
307         }
308
309         return 0;
310 }
311
312 int main(int argc, char *argv[])
313 {
314         struct appdata ad;
315         struct appcore_ops ops = {
316                 .create = __app_create,
317                 .terminate = __app_terminate,
318                 .pause = __app_pause,
319                 .resume = __app_resume,
320                 .reset = __app_reset,
321         };
322
323         memset(&ad, 0x0, sizeof(struct appdata));
324         ops.data = &ad;
325
326         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
327 }
328