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