Modify enum values
[apps/home/usb-syspopup.git] / usb-syspopup.c
1 /*
2  * usb-syspopup
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
5  *
6  * Contact: Taeyoung Kim <ty317.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <appcore-efl.h>
24 #include <Ecore_X.h>
25 #include <devman.h>
26 #include <heynoti.h>
27 #include <time.h>
28 #include "usb-syspopup.h"
29
30 #define SYSPOPUP_PARAM_LEN 3
31 #define USB_SYSPOPUP_MESSAGE_DOMAIN \
32                         "usb-syspopup"
33 #define USB_NOTICE_SYSPOPUP_FAIL \
34                         "USB system popup failed."
35
36 char *matchedApps[MAX_NUM_OF_MATCHED_APPS];
37 Elm_Genlist_Item_Class itc;
38 Evas_Object *genlist;
39 Elm_Object_Item *item;
40
41 syspopup_handler handler = {
42         .def_term_fn = NULL,
43         .def_timeout_fn = NULL
44 };
45
46 int ipc_socket_client_init(int *sock_remote)
47 {
48         __USB_FUNC_ENTER__ ;
49         if (!sock_remote) return -1;
50         int t, len;
51         struct sockaddr_un remote;
52         char str[SOCK_STR_LEN];
53
54         if (((*sock_remote) = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
55                 perror("socket");
56                 USB_LOG(USB_LOG_VERBOSE, "FAIL: socket(AF_UNIX, SOCK_STREAM, 0)");
57                 return -1;;
58         }
59         remote.sun_family = AF_UNIX;
60         strncpy(remote.sun_path, SOCK_PATH, strlen(SOCK_PATH)+1);
61         len = strlen(remote.sun_path) + sizeof(remote.sun_family);
62
63         if (connect((*sock_remote), (struct sockaddr *)&remote, len) == -1) {
64                 perror("connect");
65                 USB_LOG(USB_LOG_VERBOSE, "FAIL: connect((*sock_remote), (struct sockaddr *)&remote, len)");
66                 return -1;
67         }
68         __USB_FUNC_EXIT__ ;
69         return 0;
70 }
71
72 int ipc_socket_client_close(int *sock_remote)
73 {
74         __USB_FUNC_ENTER__ ;
75         if (!sock_remote) return -1;
76         close (*sock_remote);
77         __USB_FUNC_EXIT__ ;
78         return 0;
79 }
80 static void __win_del(void *data, Evas_Object * obj, void *event)
81 {
82         __USB_FUNC_ENTER__ ;
83         elm_exit();
84         __USB_FUNC_EXIT__ ;
85 }
86
87 static Evas_Object *__create_win(const char *name)
88 {
89         __USB_FUNC_ENTER__ ;
90
91         if(!name) return ;
92         Evas_Object *eo;
93         int w;
94         int h;
95
96         eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
97         if (eo) {
98                 elm_win_title_set(eo, name);
99                 elm_win_borderless_set(eo, EINA_TRUE);
100                 elm_win_alpha_set(eo, EINA_TRUE);
101                 elm_win_raise(eo);
102                 evas_object_smart_callback_add(eo, "delete,request",
103                                                    __win_del, NULL);
104                 ecore_x_window_size_get(ecore_x_window_root_first_get(),
105                                         &w, &h);
106                 evas_object_resize(eo, w, h);
107         }
108
109         __USB_FUNC_EXIT__ ;
110
111         return eo;
112 }
113
114 static void usb_chgdet_cb(void *data)
115 {
116         __USB_FUNC_ENTER__ ;
117         int val;
118         if(device_get_property(DEVTYPE_JACK,JACK_PROP_USB_ONLINE,&val)==0)
119         {
120                 USB_LOG(USB_LOG_VERBOSE, "device_get_property(): %d\n", val);
121                 if(!val)
122                 {
123                         USB_LOG(USB_LOG_VERBOSE, "Calling elm_exit()\n");
124                         elm_exit();
125                 }
126         }
127         __USB_FUNC_EXIT__ ;
128 }
129
130 static int register_heynoti(void *data)
131 {
132         __USB_FUNC_ENTER__ ;
133
134         if(!data) return -1;
135         struct appdata *ad = data;
136
137         /* Registering heynoti to recognize the change of the status of USB cable connection */
138         ad->noti_fd = heynoti_init();
139         if (ad->noti_fd < 0)
140         {
141                 USB_LOG(USB_LOG_VERBOSE, "FAIL: heynoti_init()\n");
142                 __USB_FUNC_EXIT__ ;
143                 return -1;
144         }
145         if(heynoti_attach_handler(ad->noti_fd) < 0)
146         {
147                 USB_LOG(USB_LOG_VERBOSE, "FAIL: heynoti_attach_handler()\n");
148                 __USB_FUNC_EXIT__ ;
149                 return -1;
150         }
151         if (heynoti_subscribe(ad->noti_fd,"device_usb_chgdet", usb_chgdet_cb, NULL) != 0)
152         {
153                 USB_LOG(USB_LOG_VERBOSE, "FAIL: heynoti_subscribe()\n");
154                 __USB_FUNC_EXIT__ ;
155                 return -1;
156         }
157         __USB_FUNC_EXIT__ ;
158         return 0;
159 }
160
161 static void deregister_heynoti(void *data)
162 {
163         __USB_FUNC_ENTER__ ;
164
165         if(!data) return ;
166         struct appdata *ad = data;
167
168         /* Closing heynoti */
169         if (heynoti_unsubscribe(ad->noti_fd, "device_usb_chgdet", usb_chgdet_cb) < 0)
170         {
171                 USB_LOG(USB_LOG_VERBOSE, "ERROR: heynoti_unsubscribe() \n");
172         }
173         if (heynoti_detach_handler(ad->noti_fd) < 0)
174         {
175                 USB_LOG(USB_LOG_VERBOSE, "ERROR: heynoti_detach_handler() \n");
176         }
177         heynoti_close(ad->noti_fd);
178
179         __USB_FUNC_EXIT__ ;
180
181 }
182
183 static int __app_create(void *data)
184 {
185         __USB_FUNC_ENTER__ ;
186
187         if(!data) return -1;
188         struct appdata *ad = data;
189         int r;
190         int ret = -1;
191
192         register_heynoti(ad);
193
194         /* When USB cable is removed before registering heynoti, syspopup should be terminated */
195         usb_chgdet_cb(NULL);
196
197         /* init internationalization */
198         r = appcore_set_i18n(PACKAGE, LOCALEDIR);
199         if (r != 0)
200         {
201                 USB_LOG(USB_LOG_VERBOSE, "FAIL: appcore_set_i18n(PACKAGE, LOCALEDIR)\n");
202                 return -1;
203         }
204
205         __USB_FUNC_EXIT__ ;
206
207         return 0;
208 }
209
210 static void unload_popup(void *data)
211 {
212         __USB_FUNC_ENTER__ ;
213
214         if(!data) return ;
215         struct appdata *ad = data;
216
217         if (ad->lbtn) {
218                 evas_object_del(ad->lbtn);
219                 ad->lbtn = NULL;
220         }
221         if (ad->rbtn) {
222                 evas_object_del(ad->rbtn);
223                 ad->rbtn = NULL;
224         }
225         if (ad->popup) {
226                 evas_object_del(ad->popup);
227                 ad->popup = NULL;
228         }
229         if (ad->win) {
230                 evas_object_del(ad->win);
231                 ad->win = NULL;
232         }
233
234         __USB_FUNC_EXIT__ ;
235 }
236
237 static int __app_terminate(void *data)
238 {
239         __USB_FUNC_ENTER__ ;
240
241         if(!data) return -1;
242         struct appdata *ad = data;
243         int ret = -1;
244
245         USB_LOG(USB_LOG_VERBOSE, "[SYSPOPUP] %s, %d\n", __func__, __LINE__);
246
247         deregister_heynoti(ad);
248         unload_popup(ad);
249
250         if (ad->b)
251         {
252                 ret = bundle_free(ad->b);
253                 if (ret != 0 )
254                 {
255                         USB_LOG(USB_LOG_VERBOSE, "FAIL: bundle_free(ad->b)\n");
256                 }
257                 ad->b = NULL;
258         }
259
260         __USB_FUNC_EXIT__ ;
261         return 0;
262 }
263
264 static int __app_pause(void *data)
265 {
266         __USB_FUNC_ENTER__ ;
267         __USB_FUNC_EXIT__ ;
268         return 0;
269 }
270
271 static int __app_resume(void *data)
272 {
273         __USB_FUNC_ENTER__ ;
274         __USB_FUNC_EXIT__ ;
275         return 0;
276 }
277
278 int request_to_usb_server(int request, char *pkgName, char *answer)
279 {
280         __USB_FUNC_ENTER__ ;
281         int sock_remote;
282         char str[SOCK_STR_LEN];
283         int t, ret;
284         ret = ipc_socket_client_init(&sock_remote);
285         if (0 != ret) {
286                 USB_LOG(USB_LOG_VERBOSE, "FAIL: ipc_socket_client_init(&sock_remote)");
287                 return -1;
288         }
289         if(LAUNCH_APP_FOR_ACC == request) {
290                 snprintf(str, SOCK_STR_LEN, "%d|%s", request, pkgName);
291         } else {
292                 snprintf(str, SOCK_STR_LEN, "%d|", request);
293         }
294         USB_LOG(USB_LOG_VERBOSE, "request: %s", str);
295         if (send (sock_remote, str, strlen(str)+1, 0) == -1) {
296                 USB_LOG(USB_LOG_VERBOSE, "FAIL: send (sock_remote, str, strlen(str), 0)");
297                 ipc_socket_client_close(&sock_remote);
298                 return -1;
299         }
300         if ((t = recv(sock_remote, answer, SOCK_STR_LEN, 0)) > 0) {
301                 answer[t] = '\0';
302                 USB_LOG(USB_LOG_VERBOSE, "[CLIENT] Received value: %s", answer);
303         } else {
304                 USB_LOG(USB_LOG_VERBOSE, "FAIL: recv(sock_remote, str, SOCK_STR_LEN, 0)");
305                 return -1;
306         }
307         ipc_socket_client_close(&sock_remote);
308         __USB_FUNC_EXIT__ ;
309         return 0;
310 }
311
312 static void load_connection_failed_popup_ok_response_cb(void *data, 
313                                                                 Evas_Object * obj, void *event_info)
314 {
315         __USB_FUNC_ENTER__;
316
317         if(!data) return ;
318         struct appdata *ad = data;
319         unload_popup(ad);
320
321         evas_object_smart_callback_del(ad->lbtn, "clicked", load_connection_failed_popup_ok_response_cb);
322         char buf[SOCK_STR_LEN];
323         int ret = request_to_usb_server(ERROR_POPUP_OK_BTN, NULL, buf);
324         if (ret < 0) {
325                 USB_LOG(USB_LOG_VERBOSE, "FAIL: request_to_usb_server(ERROR_POPUP_OK_BTN, NULL, buf)\n");
326                 return;
327         }
328
329         elm_exit();
330
331         __USB_FUNC_EXIT__ ;
332
333 }
334
335 static void request_perm_popup_yes_response_cb(void *data,
336                                                                 Evas_Object * obj, void *event_info)
337 {
338         __USB_FUNC_ENTER__;
339         if (!data) return ;
340         struct appdata *ad = (struct appdata *)data;
341         unload_popup(ad);
342         evas_object_smart_callback_del(ad->lbtn, "clicked", request_perm_popup_yes_response_cb);
343         evas_object_smart_callback_del(ad->rbtn, "clicked", request_perm_popup_no_response_cb);
344
345         char buf[SOCK_STR_LEN];
346         int ret = request_to_usb_server(REQ_ACC_PERM_NOTI_YES_BTN, NULL, buf);
347         if (ret < 0) {
348                 USB_LOG(USB_LOG_VERBOSE, "FAIL: request_to_usb_server(NOTICE_YES_BTN, NULL, buf)\n");
349                 return;
350         }
351         elm_exit();
352         __USB_FUNC_EXIT__ ;
353 }
354
355 static void request_perm_popup_no_response_cb(void *data,
356                                                                 Evas_Object * obj, void *event_info)
357 {
358         __USB_FUNC_ENTER__;
359         if (!data) return ;
360         struct appdata *ad = (struct appdata *)data;
361         unload_popup(ad);
362         evas_object_smart_callback_del(ad->lbtn, "clicked", request_perm_popup_yes_response_cb);
363         evas_object_smart_callback_del(ad->rbtn, "clicked", request_perm_popup_no_response_cb);
364
365         char buf[SOCK_STR_LEN];
366         int ret = request_to_usb_server(REQ_ACC_PERM_NOTI_NO_BTN, NULL, buf);
367         if (ret < 0) {
368                 USB_LOG(USB_LOG_VERBOSE, "FAIL: request_to_usb_server(NOTICE_NO_BTN, NULL, buf)\n");
369                 return;
370         }
371         elm_exit();
372         __USB_FUNC_EXIT__ ;
373 }
374
375 static void load_connection_failed_popup(void *data)
376 {
377         __USB_FUNC_ENTER__ ;
378
379         if(!data) return ;
380         struct appdata *ad = data;
381         int ret = -1;
382         ad->lbtn = NULL;
383
384         /* create window */
385         ad->win = __create_win(PACKAGE);
386         if (ad->win == NULL)
387                 return ;
388
389         ret = syspopup_create(ad->b, &handler, ad->win, ad);
390         if(ret == 0)
391         {
392                 ad->content = dgettext(USB_SYSPOPUP_MESSAGE_DOMAIN, "IDS_USB_POP_USB_CONNECTION_FAILED");
393                 USB_LOG(USB_LOG_VERBOSE, "ad->content is (%s)\n", ad->content);
394
395                 evas_object_show(ad->win);
396                 ad->popup = elm_popup_add(ad->win);
397                 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
398                 elm_object_text_set(ad->popup, ad->content);
399
400                 /* a button */
401                 ad->lbtn = elm_button_add(ad->popup);
402                 elm_object_text_set(ad->lbtn, dgettext("sys_string","IDS_COM_SK_OK"));
403                 elm_object_part_content_set(ad->popup, "button1", ad->lbtn);
404                 evas_object_smart_callback_add(ad->lbtn, "clicked",
405                                                 load_connection_failed_popup_ok_response_cb, ad);
406
407                 evas_object_show(ad->popup);
408         }
409         else
410         {
411                 USB_LOG(USB_LOG_VERBOSE, "syspopup_create() returns an integer which is not 0\n");
412         }
413
414         __USB_FUNC_EXIT__ ;
415 }
416
417 static int get_accessory_matched(struct appdata* ad)
418 {
419         __USB_FUNC_ENTER__ ;
420         int numOfApps = 0;
421         matchedApps[0]=strdup("acc_test");
422         numOfApps++;
423
424
425         __USB_FUNC_EXIT__ ;
426         return numOfApps;
427 }
428
429 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part)
430 {
431         __USB_FUNC_ENTER__ ;
432         int index = (int)data;
433         USB_LOG(USB_LOG_VERBOSE, "App name: %s\n", matchedApps[index]);
434         __USB_FUNC_EXIT__ ;
435         return strdup(matchedApps[index]);
436 }
437
438 static void select_app_popup_cancel_response_cb(void *data, Evas_Object * obj, void *event_info)
439 {
440         __USB_FUNC_ENTER__ ;
441         if (!data) return ;
442         struct appdata *ad = (struct appdata *)data;
443         unload_popup(ad);
444         elm_exit();
445         __USB_FUNC_EXIT__ ; 
446 }
447
448 static int send_sel_pkg_to_usb_server(struct appdata *ad)
449 {
450         __USB_FUNC_ENTER__ ;
451         int ret = -1;
452         char answer[SOCK_STR_LEN];
453         ret = request_to_usb_server(LAUNCH_APP_FOR_ACC, ad->selPkg, answer);
454         if (0 != ret) {
455                 USB_LOG(USB_LOG_VERBOSE, "FAIL: request_to_usb_server(LAUNCH_APP, ad->selPkg, answer)");
456                 return -1;
457         }
458         USB_LOG(USB_LOG_VERBOSE, "Launching app result is %s\n", answer);
459         __USB_FUNC_EXIT__ ;
460         return 0;
461 }
462
463 static void select_app_popup_gl_select_cb(void *data, Evas_Object *obj, void *event_info)
464 {
465         __USB_FUNC_ENTER__ ;
466         if (!event_info) return;
467         if (!data) return;
468         struct appdata *ad = (struct appdata *)data;
469         int index = 0;
470         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
471         if (item) {
472                 index = (int)elm_object_item_data_get(item);
473                 USB_LOG(USB_LOG_VERBOSE, "Selected Item: %d: %s\n", index, matchedApps[index]);
474                 snprintf(ad->selPkg, PKG_NAME_LEN, "%s", matchedApps[index]);
475         }
476         unload_popup(ad);
477         int ret = send_sel_pkg_to_usb_server(ad);
478         if ( 0!= ret ) USB_LOG(USB_LOG_VERBOSE,"FAIL: send_sel_pkg_to_usb_server(ad)");
479         elm_exit();
480         
481         __USB_FUNC_EXIT__ ;
482 }
483
484 static void load_popup_to_select_app(struct appdata *ad, int numOfApps)
485 {
486         __USB_FUNC_ENTER__ ;
487         if(!ad) return ;
488         int ret = -1;
489         ad->lbtn = NULL;
490         int index;
491         Evas_Object *win;
492
493         /* create window */
494         win = __create_win(PACKAGE);
495         if (win == NULL)
496                 return ;
497         ad->win = win;
498
499         ret = syspopup_create(ad->b, &handler, ad->win, ad);
500         USB_LOG(USB_LOG_VERBOSE, "ret: %d\n", ret);
501         if(ret == 0) {
502                 evas_object_show(ad->win);
503                 ad->popup = elm_popup_add(ad->win);
504                 elm_object_style_set(ad->popup,"menustyle");
505                 elm_object_part_text_set(ad->popup, "title,text", "Select app to launch");
506                 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
507                 ad->lbtn = elm_button_add(ad->popup);
508                 elm_object_text_set(ad->lbtn, "Cancel");
509                 elm_object_part_content_set(ad->popup, "button1", ad->lbtn);
510                 evas_object_smart_callback_add(ad->lbtn, "clicked", select_app_popup_cancel_response_cb, ad);
511         
512                 itc.item_style = "1text";
513                 itc.func.text_get = _gl_text_get;
514                 itc.func.content_get = NULL;
515                 itc.func.state_get = NULL;
516                 itc.func.del = NULL;
517                 genlist = elm_genlist_add(ad->popup);
518                 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND,     EVAS_HINT_EXPAND);
519                 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
520                 for (index = 0; index < numOfApps; index++) {
521                         USB_LOG(USB_LOG_VERBOSE, "%d\n", numOfApps);
522                         item = elm_genlist_item_append(genlist, &itc, (void *) index, NULL,
523                                 ELM_GENLIST_ITEM_NONE, select_app_popup_gl_select_cb, ad);
524                         if (NULL == item) USB_LOG(USB_LOG_VERBOSE, "NULL ==item\n");
525                 }
526                 elm_object_content_set(ad->popup, genlist);
527                 evas_object_show(ad->popup);
528         }
529         __USB_FUNC_EXIT__ ; 
530 }
531
532 static void load_popup_to_confirm_uri(struct appdata *ad)
533 {
534         __USB_FUNC_ENTER__ ;
535         __USB_FUNC_EXIT__ ;
536 }
537
538 static int get_accessory_info(struct appdata *ad)
539 {
540         __USB_FUNC_ENTER__ ;
541         if (!ad) return -1;
542         int ret, i;
543         char device[ACC_INFO_NUM][ACC_ELEMENT_LEN];
544         char key[SYSPOPUP_PARAM_LEN];
545         for (i = 0; i < ACC_INFO_NUM; i++) {
546                 snprintf(key, SYSPOPUP_PARAM_LEN, "%d", 1 + i);
547                 const char* type = bundle_get_val(ad->b, (const char *)key);
548                 if (!type) {
549                         USB_LOG(USB_LOG_VERBOSE, "ERROR: bundle_get_val(b)\n");
550                         return -1;
551                 } else {
552                         USB_LOG(USB_LOG_VERBOSE, "%d: %s\n", i, type);
553                         snprintf(device[i], ACC_ELEMENT_LEN, "%s", type);
554                 }
555         }
556
557         USB_LOG(USB_LOG_VERBOSE, "Get USB Acc info\n");
558         snprintf(ad->usbAcc->manufacturer, ACC_ELEMENT_LEN, "%s", device[ACC_MANUFACTURER]);
559         snprintf(ad->usbAcc->model, ACC_ELEMENT_LEN, "%s", device[ACC_MODEL]);
560         snprintf(ad->usbAcc->description, ACC_ELEMENT_LEN, "%s", device[ACC_DESCRIPTION]);
561         snprintf(ad->usbAcc->version, ACC_ELEMENT_LEN, "%s", device[ACC_VERSION]);
562         snprintf(ad->usbAcc->uri, ACC_ELEMENT_LEN, "%s", device[ACC_URI]);
563         snprintf(ad->usbAcc->serial, ACC_ELEMENT_LEN, "%s", device[ACC_SERIAL]);
564
565         USB_LOG(USB_LOG_VERBOSE, "Print USB acc info\n");
566         USB_LOG(USB_LOG_VERBOSE, "** USB ACCESSORY INFO **");
567         USB_LOG(USB_LOG_VERBOSE, "* Manufacturer: %s *", ad->usbAcc->manufacturer);
568         USB_LOG(USB_LOG_VERBOSE, "* Model       : %s *", ad->usbAcc->model);
569         USB_LOG(USB_LOG_VERBOSE, "* Description : %s *", ad->usbAcc->description);
570         USB_LOG(USB_LOG_VERBOSE, "* Version     : %s *", ad->usbAcc->version);
571         USB_LOG(USB_LOG_VERBOSE, "* URI         : %s *", ad->usbAcc->uri);
572         USB_LOG(USB_LOG_VERBOSE, "* SERIAL      : %s *", ad->usbAcc->serial);
573         USB_LOG(USB_LOG_VERBOSE, "************************");
574         __USB_FUNC_EXIT__ ;
575         return 0;
576 }
577
578 static void load_select_pkg_for_acc_popup(struct appdata *ad)
579 {
580         __USB_FUNC_ENTER__ ;
581         if (!ad) return;
582         int ret = -1;
583         UsbAccessory usbAcc;
584         memset(&usbAcc, 0x0, sizeof(UsbAccessory));
585         ad->usbAcc = &usbAcc;
586         ret = get_accessory_info(ad);
587         if (0 != ret) {
588                 USB_LOG(USB_LOG_VERBOSE, "FAIL: get_accessory_info(ad)");
589                 elm_exit();
590         }
591
592         int numOfApps = get_accessory_matched(ad);
593         if (numOfApps > 0) {
594                 USB_LOG(USB_LOG_VERBOSE, "number of apps matched: %d\n", numOfApps);
595                 load_popup_to_select_app(ad, numOfApps);
596         } else {
597                 USB_LOG(USB_LOG_VERBOSE, "number of apps matched is 0\n");
598                 load_popup_to_confirm_uri(ad);
599         }
600         __USB_FUNC_EXIT__ ;
601 }
602
603 void load_request_perm_popup(struct appdata *ad)
604 {
605         __USB_FUNC_ENTER__ ;
606
607         if(!ad) return ;
608         Evas_Object *win;
609         int ret = -1;
610         ad->lbtn = NULL;
611         ad->rbtn = NULL;
612
613         /* create window */
614         win = __create_win(PACKAGE);
615         if (win == NULL)
616                 return ;
617         ad->win = win;
618
619         ret = syspopup_create(ad->b, &handler, ad->win, ad);
620         if(ret == 0)
621         {
622                 ad->content = dgettext(USB_SYSPOPUP_MESSAGE_DOMAIN,
623                                                 "IDS_COM_POP_ALLOW_APPLICATION_P1SS_TO_ACCESS_USB_ACCESSORY_Q_ABB");
624                 USB_LOG(USB_LOG_VERBOSE, "ad->content is (%s)\n", ad->content);
625
626                 evas_object_show(ad->win);
627                 ad->popup = elm_popup_add(ad->win);
628                 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
629                 elm_object_text_set(ad->popup, ad->content);
630
631                 /* Left button */
632                 ad->lbtn = elm_button_add(ad->popup);
633                 elm_object_text_set(ad->lbtn, dgettext("sys_string","IDS_COM_SK_YES"));
634                 elm_object_part_content_set(ad->popup, "button1", ad->lbtn);
635                 evas_object_smart_callback_add(ad->lbtn, "clicked", request_perm_popup_yes_response_cb, ad);
636
637                 /* Right button */
638                 ad->rbtn = elm_button_add(ad->popup);
639                 elm_object_text_set(ad->rbtn, dgettext("sys_string","IDS_COM_SK_NO"));
640                 elm_object_part_content_set(ad->popup, "button2", ad->rbtn);
641                 evas_object_smart_callback_add(ad->rbtn, "clicked", request_perm_popup_no_response_cb, ad);
642
643                 evas_object_show(ad->popup);
644         }
645         else
646         {
647                 USB_LOG(USB_LOG_VERBOSE, "syspopup_create() returns an integer which is not 0\n");
648         }
649
650         __USB_FUNC_EXIT__ ;
651 }
652
653 static int __app_reset(bundle *b, void *data)
654 {
655         __USB_FUNC_ENTER__ ;
656
657         if(!data) return -1;
658         struct appdata *ad = data;
659         char key[SYSPOPUP_PARAM_LEN];
660         int ret = 0;
661
662         ad->b = bundle_dup(b);
663
664         /* When syspopup is already loaded, remove the popup and load new popup */
665         if (syspopup_has_popup(b)) {
666                 USB_LOG(USB_LOG_VERBOSE, "syspopup_has_popup(b) returns 1\n");
667                 unload_popup(ad);
668                 /* Resetting all proporties of syspopup */
669                 syspopup_reset(b);
670         }
671
672         snprintf(key, SYSPOPUP_PARAM_LEN, "%d", SYSPOPUP_TYPE);
673         const char* type = bundle_get_val(b, (const char *)key);
674         if (!type) {
675                 USB_LOG(USB_LOG_VERBOSE, "ERROR: Non existing type of popup\n");
676                 elm_exit();
677         } else {
678                 ad->type = atoi(type);
679                 USB_LOG(USB_LOG_VERBOSE, "ad->type is (%d)\n", ad->type);
680         }
681
682         switch(ad->type) {
683         case ERROR_POPUP:
684                 USB_LOG(USB_LOG_VERBOSE, "Connection failed popup is loaded\n");
685                 load_connection_failed_popup(ad);
686                 break;
687         case SELECT_PKG_FOR_ACC_POPUP:
688                 USB_LOG(USB_LOG_VERBOSE, "Select pkg for acc popup is loaded\n");
689                 load_select_pkg_for_acc_popup(ad);
690                 break;
691         case REQ_ACC_PERM_POPUP:
692                 USB_LOG(USB_LOG_VERBOSE, "Request Permission popup is loaded\n");
693                 load_request_perm_popup(ad);
694         default:
695                 USB_LOG(USB_LOG_VERBOSE, "ERROR: The popup type(%d) does not exist\n", ad->type);
696                 break;
697         }
698
699         __USB_FUNC_EXIT__ ;
700
701         return 0;
702 }
703
704 int main(int argc, char *argv[])
705 {
706         __USB_FUNC_ENTER__ ;
707
708         struct appdata ad;
709         struct appcore_ops ops = {
710                 .create = __app_create,
711                 .terminate = __app_terminate,
712                 .pause = __app_pause,
713                 .resume = __app_resume,
714                 .reset = __app_reset,
715         };
716
717         memset(&ad, 0x0, sizeof(struct appdata));
718         ops.data = &ad;
719
720         __USB_FUNC_EXIT__ ;
721         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
722 }
723