tizen 2.3.1 release
[apps/home/installer.git] / src / installer.c
1 /*
2  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <app.h>
18 #include <dlog.h>
19 #include <bundle.h>
20 #include <Ecore_X.h>
21 #include <Elementary.h>
22 #include <efl_assist.h>
23 #include <Evas.h>
24 #include <utilX.h>
25 #include <glib.h>
26
27 #include <privilege_info.h>
28 #include <package-manager.h>
29 #include <package-manager-types.h>
30
31 #include "installer.h"
32 #include "installer_package_manager.h"
33 #include "installer_util.h"
34
35 #define KEY_MIME_CONTENT "__AUL_MIME_CONTENT__"
36 #define KEY_MIME_CONTENT_NEW "__APP_SVC_URI__"
37
38 #define LOCALE_FILE_NAME "org.tizen.installer"
39 #define LOCALEDIR "/usr/apps/org.tizen.installer/res/locale"
40
41 #define POP_MSG_SIZE 512
42
43 typedef struct _appdata
44 {
45         char *file_path;
46         char *extension;
47         int win_w;
48         int win_h;
49         Evas *evas;
50         Evas_Object *win;
51         Evas_Object *layout;
52         Evas_Object *conform;
53         Evas_Object *nf;
54         package_manager_pkg_detail_info_t *install_pkginfo;
55 } appdata;
56
57 typedef struct _item_data
58 {
59         bool is_selected;
60         char *privilege;
61 } item_data;
62
63 struct text_part {
64         char *part;
65         char *msgid;
66 };
67
68 struct text_part main_txt[] =
69 {
70         {"txt_title", N_("Installer"),},
71         {"txt_mesg", N_("install"),},
72 };
73
74 int create_base_gui(appdata *ad);
75 int create_popup_base_gui(appdata *ad);
76 static void _create_reinstall_popup(appdata *ad, const char* btn_str, const char* detail);
77 static void _create_error_popup(appdata *ad);
78
79 package_manager_pkg_detail_info_t *g_package_info = NULL;
80
81
82
83 static char *_gl_label_get(void *data, Evas_Object *obj, const char *part)
84 {
85         LOGD("%s part(%s)", __func__, part);
86         if (!strcmp(part, "elm.text.main.left.top"))
87         {
88                 char *name = NULL;
89                 item_data *item = (item_data *)data;
90
91                 privilege_info_get_privilege_display_name(item->privilege, &name);
92                 return name;
93         }
94         else if (!strcmp(part, "elm.text.sub.left.bottom"))
95         {
96                 char *description = NULL;
97                 item_data *item = (item_data *)data;
98
99                 privilege_info_get_privilege_description(item->privilege, &description);
100                 return description;
101         }
102         else if (!strcmp(part, "elm.text.multiline"))
103         {
104                 return strdup((char *)data);
105         }
106
107         return NULL;
108 }
109
110
111 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part)
112 {
113         LOGD("%s part(%s)", __func__, part);
114         if (!strcmp(part, "elm.text.multiline"))
115         {
116                 if ((int)data == 0)
117                 {
118                         return strdup(_("IDS_APINST_BODY_THIS_APPLICATION_MAY_BE_HARMFUL_AND_DAMAGE_YOUR_DEVICE_OR_DATA"));
119                 }
120
121         }
122         return NULL;
123 }
124
125 static char *_gl_group_text_get(void *data, Evas_Object *obj, const char *part)
126 {
127         LOGD("%s part(%s)", __func__, part);
128         if (!strcmp(part, "elm.text.multiline"))
129         {
130                 if ((int)data == 0)
131                 {
132                         return strdup(_("IDS_APINST_HEADER_WARNING"));
133                 }
134                 else if ((int)data == 1)
135                 {
136                         return strdup(_("IDS_APINST_HEADER_PERMISSION_REQUESTS_ABB"));
137                 }
138         }
139         return NULL;
140 }
141
142 static void _gl_exp_ndepth(void *data, Evas_Object *obj, void *event_info)
143 {
144         Elm_Object_Item *it;
145         Elm_Object_Item *parent = event_info;
146         Evas_Object *gl = elm_object_item_widget_get(parent);
147
148         char content[1024] = {0,};
149         char *name = NULL, *description = NULL;
150         int res = 0;
151         item_data *item = (item_data *)elm_object_item_data_get(parent);
152
153         if (item == NULL)
154                 return;
155
156         LOGD("%s is_selected(%d)", __func__, item->is_selected);
157
158         if (item->is_selected)
159         {
160                 item->is_selected = false;
161                 elm_genlist_item_subitems_clear(event_info);
162                 return;
163         }
164
165         res = privilege_info_get_privilege_display_name(item->privilege, &name);
166         if (res < 0)
167         {
168                 LOGE("%s privilege_info_get_privilege_display_name() failed. (privilege: %s)", __func__, item->privilege);
169         }
170
171         res = privilege_info_get_privilege_description(item->privilege, &description);
172         if (res < 0)
173         {
174                 LOGE("%s privilege_info_get_privilege_description() failed. (privilege: %s)", __func__, item->privilege);
175         }
176         snprintf(content, sizeof(content), "%s<br><br>%s", name, description);
177
178         Elm_Genlist_Item_Class *itc1;
179         itc1 = elm_genlist_item_class_new();
180         if (itc1 == NULL) {
181                 LOGE("out of memory");
182                 if (name)
183                         free(name);
184                 if (description)
185                         free(description);
186
187                 return;
188         }
189
190         itc1->item_style = "multiline_sub";
191         itc1->func.text_get = _gl_label_get;
192
193         it = elm_genlist_item_append(gl, itc1, content, parent, ELM_GENLIST_ITEM_NONE, NULL, NULL);
194         elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
195
196         item->is_selected = true;
197         elm_genlist_item_class_free(itc1);
198
199         if (name)
200                 free(name);
201         if (description)
202                 free(description);
203 }
204
205
206 void _region_changed(app_event_info_h event_info, void* user_data)
207 {
208         LOGD("%s", __func__);
209 }
210
211 void update_ts(Evas_Object *eo, struct text_part *tp, int size)
212 {
213         LOGD("%s", __func__);
214         int i;
215
216         if (eo == NULL || tp == NULL || size < 0) {
217                 return;
218         }
219
220         for (i = 0; i < size; i++) {
221                 if (tp[i].part && tp[i].msgid) {
222                         edje_object_part_text_set(eo, tp[i].part, _(tp[i].msgid));
223                 }
224         }
225         return;
226 }
227
228 void _lang_changed(app_event_info_h event_info, void* user_data)
229 {
230         LOGD("%s", __func__);
231         appdata* ad = user_data;
232
233         if (ad->layout == NULL) {
234                 return;
235         }
236
237         update_ts(elm_layout_edje_get(ad->layout), main_txt, sizeof(main_txt)/sizeof(main_txt[0]));
238         return;
239 }
240
241 void _orient_changed(app_event_info_h event_info, void* user_data)
242 {
243         LOGD("%s", __func__);
244         appdata* ap = (appdata*)user_data;
245         app_device_orientation_e orientation = app_get_device_orientation();
246
247         int degree = 0;
248
249         switch(orientation)
250         {
251                 case APP_DEVICE_ORIENTATION_0:
252                 {
253                         degree = 0;
254                         break;
255                 }
256                 case APP_DEVICE_ORIENTATION_90:
257                 {
258                         degree = 90;
259                         break;
260                 }
261                 case APP_DEVICE_ORIENTATION_180:
262                 {
263                         degree = 180;
264                         break;
265                 }
266                 case APP_DEVICE_ORIENTATION_270:
267                 {
268                         degree = 270;
269                         break;
270                 }
271         }
272
273         if (ap->win != NULL)
274         {
275                 elm_win_rotation_with_resize_set(ap->win, degree);
276         }
277         return;
278 }
279
280 bool _keydown_cb(void *data, int type, void *event)
281 {
282         LOGD("%s",__func__ );
283         Ecore_Event_Key* ev = event;
284         if (!strcmp(ev->keyname, KEY_END)) {
285                 ui_app_exit();
286         }
287         return true;
288 }
289
290 void _main_quit_cb(void* user_data, Evas_Object* obj, void *event_info)
291 {
292         LOGD("%s", __func__);
293         ui_app_exit();
294 }
295
296 void _main_quit_signal_cb(void* data, Evas_Object* obj, const char *emission, const char *source)
297 {
298         LOGD("%s", __func__);
299         ui_app_exit();
300 }
301
302 void _reinstall_cb(void* user_data, Evas_Object* obj, void *event_info)
303 {
304         LOGD("%s", __func__);
305         int res = 0;
306         appdata *ad = NULL;
307
308         if (!user_data) {
309                 LOGE("user_data is NULL.");
310                 return;
311         }
312         ad = (appdata*)user_data;
313
314         res = create_base_gui(ad);
315         if (res < 0)
316         {
317                 LOGE("%s create_base_gui() failed.(%d)", __func__, res);
318         }
319         ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,(Ecore_Event_Handler_Cb)_keydown_cb, NULL);        // Control back key
320 }
321
322 static void _create_reinstall_popup(appdata *ad, const char* btn_str, const char* detail)
323 {
324         Evas_Object *popup;
325         Evas_Object *btn;
326         Evas_Object *ly = ad->win;
327
328         /* popup */
329         popup = elm_popup_add(ly);
330         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, ea_popup_back_cb, NULL);
331         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
332         elm_object_text_set(popup, detail);
333
334         /* Cancel button */
335         btn = elm_button_add(popup);
336         elm_object_style_set(btn, "popup");
337         elm_object_text_set(btn, _("IDS_360V_BUTTON_CANCEL_ABB"));
338         ea_theme_object_color_replace(btn, "W011", "W0112");
339         elm_object_part_content_set(popup, "button1", btn);
340         evas_object_smart_callback_add(btn, "clicked", _main_quit_cb, ad);
341
342         /* Reinstall button */
343         btn = elm_button_add(popup);
344         elm_object_style_set(btn, "popup");
345         elm_object_text_set(btn, btn_str);
346         ea_theme_object_color_replace(btn, "W011", "W0111");
347         elm_object_part_content_set(popup, "button2", btn);
348         evas_object_smart_callback_add(btn, "clicked", _reinstall_cb, ad);
349
350         evas_object_show(popup);
351 }
352
353
354 static void _create_error_popup(appdata *ad)
355 {
356         Evas_Object *popup;
357         Evas_Object *btn;
358         Evas_Object *win = ad->win;
359
360         /* popup */
361         popup = elm_popup_add(win);
362         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, ea_popup_back_cb, NULL);
363         elm_object_part_text_set(popup, "title,text", "Error.");
364         elm_object_text_set(popup,  _("IDS_APINST_POP_UNABLE_TO_INSTALL_THIS_FILE_THE_FORMAT_IS_INVALID"));
365
366         /* ok button */
367         btn = elm_button_add(popup);
368         elm_object_style_set(btn, "popup");
369         elm_object_text_set(btn, "OK");
370         elm_object_part_content_set(popup, "button1", btn);
371         evas_object_smart_callback_add(btn, "clicked", _main_quit_cb, ad);
372         evas_object_show(popup);
373 }
374
375
376 static void
377 win_delete_request_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
378 {
379         /* To make your application go to background,
380                 Call the elm_win_lower() instead
381                 Evas_Object *win = (Evas_Object *) data;
382                 elm_win_lower(win); */
383         ui_app_exit();
384 }
385
386
387 static int __parse_argv(int argc, char **argv, char **file_path)
388 {
389         LOGD("%s", __func__);
390     static bundle *b = NULL;
391         if (b)
392         {
393                 bundle_free(b);
394         }
395
396         b = bundle_import_from_argv(argc, argv);
397         if (b == NULL)
398         {
399                 LOGD("%s bundle for bundle_import_from_argv is NULL", __func__);
400         }
401
402         errno = 0;
403         if(bundle_get_val(b, KEY_MIME_CONTENT_NEW))
404         {
405                 *file_path = (char *)bundle_get_val(b, KEY_MIME_CONTENT_NEW);
406         }
407         else
408         {
409                 *file_path = (char *)bundle_get_val(b, KEY_MIME_CONTENT);
410         }
411         if (errno)
412         {
413                 return -1;
414         }
415
416         return 0;
417 }
418
419 static void _button_clicked_cb(void *data, Evas_Object * obj, void *event_info)
420 {
421         appdata *ad = NULL;
422         ad = (appdata*)data;
423
424         SECURE_LOGD("pkg_name(%s), pkgid(%s) label(%s)",
425                         ad->install_pkginfo->pkg_name,
426                         ad->install_pkginfo->pkgid,
427                         ad->install_pkginfo->label
428                 );
429
430         int res = launch_install_service(ad->file_path, ad->install_pkginfo);
431         if (res < 0)
432         {
433                 LOGE("%s launch_install_service() failed.", __func__);
434         }
435 }
436
437 static void _gl_sel(void *data, Evas_Object *obj, void *ei)
438 {
439         if (!ei) return;
440         Eina_Bool expanded = EINA_FALSE;
441
442         elm_genlist_item_selected_set(ei, EINA_FALSE);
443
444         expanded = elm_genlist_item_expanded_get(ei);
445         elm_genlist_item_expanded_set(ei, !expanded);
446 }
447
448 static Evas_Object *_gl_btn_text_get(void *data, Evas_Object *obj, const char *part)
449 {
450         LOGD("%s part(%s)", __func__, part);
451         if (!strcmp(part, "elm.icon.entry"))
452         {
453                 Evas_Object *btn = elm_button_add(obj);
454                 elm_object_style_set(btn, "popup");
455                 elm_object_text_set(btn, _("IDS_APINST_BUTTON_ALLOW_AND_INSTALL_ABB"));
456                 evas_object_propagate_events_set(btn, EINA_FALSE);
457                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1);
458                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
459                 evas_object_smart_callback_add(btn, "clicked", _button_clicked_cb, data);
460
461                 return btn;
462         }
463         return NULL;
464 }
465
466
467 static Evas_Object *_create_content(appdata *data)
468 {
469         appdata *ad = NULL;
470         ad = data;
471
472         Evas_Object *genlist;
473         Evas_Object *nf = ad->nf;
474         Elm_Object_Item *git;
475         item_data *item = NULL;
476
477         Elm_Genlist_Item_Class *itc, *itc_group, *itc_sep_empty, *itc_expandable_box, *itc_btn_install;
478
479         itc = elm_genlist_item_class_new();
480         if (itc == NULL)
481                 return NULL;
482
483         itc_group = elm_genlist_item_class_new();
484         if (itc_group == NULL) {
485                 elm_genlist_item_class_free(itc);
486                 return NULL;
487         }
488
489         itc_sep_empty = elm_genlist_item_class_new();
490         if (itc_sep_empty == NULL) {
491                 elm_genlist_item_class_free(itc_group);
492                 elm_genlist_item_class_free(itc);
493                 return NULL;
494         }
495
496         itc_expandable_box = elm_genlist_item_class_new();
497         if (itc_expandable_box == NULL) {
498                 elm_genlist_item_class_free(itc_sep_empty);
499                 elm_genlist_item_class_free(itc_group);
500                 elm_genlist_item_class_free(itc);
501                 return NULL;
502         }
503
504         itc_btn_install = elm_genlist_item_class_new();
505         if (itc_btn_install == NULL) {
506                 elm_genlist_item_class_free(itc_expandable_box);
507                 elm_genlist_item_class_free(itc_sep_empty);
508                 elm_genlist_item_class_free(itc_group);
509                 elm_genlist_item_class_free(itc);
510                 return NULL;
511         }
512
513         itc_group->item_style = "multiline_main";
514         itc_group->func.text_get = _gl_group_text_get;
515
516         itc->item_style = "multiline_sub";
517         itc->func.text_get = _gl_text_get;
518
519         itc_sep_empty->item_style = "empty_area";
520
521         itc_expandable_box->item_style = "2line.top";
522         itc_expandable_box->func.text_get = _gl_label_get;
523
524         itc_btn_install->item_style = "entry";
525         itc_btn_install->func.content_get = _gl_btn_text_get;
526
527         genlist = elm_genlist_add(nf);
528         elm_genlist_realization_mode_set(genlist, EINA_TRUE);
529         // COMPRESS MODE
530         // If multiline text (multiline entry or multiline textblock or sliding mode)
531         // is used, use compress mode for compressing width to fit the viewport width.
532         // So genlist can calculate item's height correctly.
533         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
534         printf("Compress mode enabled\n");
535
536
537         // In dialogue group ***********************************
538         git = elm_genlist_item_append(genlist, itc_group, (void *)0, NULL,
539                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
540         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
541
542         git = elm_genlist_item_append(genlist, itc, (void *)0, NULL,
543                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
544         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
545
546         // Expandable box in dialogue group
547         if (g_list_length(ad->install_pkginfo->privilege_list) > 0)
548         {
549                 int i = 0;
550
551                 git = elm_genlist_item_append(genlist, itc_group, (void *)1, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
552                 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
553
554                 for (i=0; i< g_list_length(ad->install_pkginfo->privilege_list); i++)
555                 {
556                 //      - Expandable box
557                         item = calloc(sizeof(item_data), 1);
558                         if (item == NULL) {
559                                 LOGE("out of memory");
560                                 continue;
561                         }
562
563                         item->is_selected = false;
564                         item->privilege = g_list_nth_data(ad->install_pkginfo->privilege_list, i);
565
566                         elm_genlist_item_append(genlist, itc_expandable_box, item
567                                 , NULL, ELM_GENLIST_ITEM_NONE, _gl_sel, NULL
568                         );
569                 }
570                 evas_object_smart_callback_add(genlist, "selected", _gl_exp_ndepth, genlist);
571         }
572
573         // Install button in dialogue group
574         elm_genlist_item_append(genlist, itc_btn_install, ad, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
575
576
577         elm_genlist_item_class_free(itc);
578         elm_genlist_item_class_free(itc_group);
579         elm_genlist_item_class_free(itc_sep_empty);
580         elm_genlist_item_class_free(itc_expandable_box);
581         elm_genlist_item_class_free(itc_btn_install);
582
583         return genlist;
584 }
585
586 static void
587 create_view(appdata *ad)
588 {
589         Evas_Object *nf = ad->nf;
590         Evas_Object *content, *ic;
591         Elm_Object_Item *navi_it;
592         char buf[PATH_MAX] = {0,};
593         package_manager_pkg_detail_info_t *package_info = (package_manager_pkg_detail_info_t *)ad->install_pkginfo;
594
595         content = _create_content(ad);
596
597         //Push a new item
598         navi_it = elm_naviframe_item_push(nf, package_info->label, NULL, NULL, content, NULL);
599
600         //Title Icon
601         ic = elm_image_add(nf);
602         snprintf(buf, sizeof(buf), "%s", ICON_PATH);
603         elm_image_file_set(ic, buf, NULL);
604         evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
605         elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
606         elm_object_item_part_content_set(navi_it, "elm.swallow.icon", ic);
607 }
608
609
610 static Evas_Object *__create_win(const char *name)
611 {
612         Evas_Object *eo;
613         int w;
614         int h;
615
616         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
617         if (eo) {
618                 elm_win_title_set(eo, name);
619                 elm_win_borderless_set(eo, EINA_TRUE);
620
621                 elm_win_alpha_set(eo, EINA_TRUE);
622
623                 evas_object_smart_callback_add(eo, "delete,request", win_delete_request_cb, NULL);
624                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
625                 evas_object_resize(eo, w, h);
626
627                 ea_screen_reader_support_set(eo, EINA_TRUE);
628         }
629
630         return eo;
631 }
632
633 static Evas_Object *__create_layout_main(Evas_Object * parent)
634 {
635         Evas_Object *layout;
636
637         if (!parent)
638                 return NULL;
639
640         layout = elm_layout_add(parent);
641         if (!layout)
642                 return NULL;
643
644         elm_layout_theme_set(layout, "layout", "application", "default");
645         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
646                                          EVAS_HINT_EXPAND);
647
648         edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,show,content", "elm");
649
650         evas_object_show(layout);
651
652         return layout;
653 }
654
655 int create_popup_base_gui(appdata *ad)
656 {
657         Evas_Object *win;
658         Evas_Object *ly;
659
660         /* create window */
661         win = __create_win(PACKAGE);
662         if (win == NULL)
663                 return -1;
664         ad->win = win;
665
666         /* Base Layout */
667         ly = __create_layout_main(ad->win);
668         if (!ly)
669                 return -1;
670
671         ad->layout = ly;
672
673         edje_object_signal_emit(elm_layout_edje_get(ad->layout), "elm,bg,show,transparent", "elm");
674
675         if (elm_win_wm_rotation_supported_get(ad->win))
676         {
677                 int rots[4] = { 0, 90, 180, 270 };
678                 elm_win_wm_rotation_available_rotations_set(ad->win, (const int*)(&rots), 4);
679         }
680         else
681         {
682                 LOGE("%s win rotation no supported", __func__);
683                 return -1;
684         }
685
686         evas_object_show(win);
687
688         return 0;
689 }
690
691
692 int create_base_gui(appdata *ad)
693 {
694         /*
695          * Widget Tree
696          * Window
697          *  - conform
698          *   - layout main
699          *    - naviframe */
700
701         /* Window */
702         ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
703         elm_win_wm_desktop_layout_support_set(ad->win, EINA_TRUE);
704         elm_win_conformant_set(ad->win, EINA_TRUE);
705         elm_win_autodel_set(ad->win, EINA_TRUE);
706
707         if (elm_win_wm_rotation_supported_get(ad->win)) {
708                 int rots[4] = { 0, 90, 180, 270 };
709                 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
710         }
711
712         evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
713
714         /* Conformant */
715         ad->conform = elm_conformant_add(ad->win);
716         evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
717         elm_win_resize_object_add(ad->win, ad->conform);
718         evas_object_show(ad->conform);
719
720         /* Base Layout */
721         ad->layout = elm_layout_add(ad->conform);
722         evas_object_size_hint_weight_set(ad->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
723         elm_layout_theme_set(ad->layout, "layout", "application", "default");
724         evas_object_show(ad->layout);
725         elm_object_content_set(ad->conform, ad->layout);
726
727         /* Naviframe */
728         ad->nf = elm_naviframe_add(ad->layout);
729         elm_object_part_content_set(ad->layout, "elm.swallow.content", ad->nf);
730
731         /* Indicator */
732         elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
733
734         create_view(ad);
735
736         /* Show window after base gui is set up */
737         evas_object_show(ad->win);
738
739         ea_object_event_callback_add(ad->nf, EA_CALLBACK_BACK, ea_naviframe_back_cb, NULL);
740         ea_object_event_callback_add(ad->nf, EA_CALLBACK_MORE, ea_naviframe_more_cb, NULL);
741
742         return 0;
743 }
744
745
746
747 package_manager_pkg_detail_info_t* _get_packageInfo(char *file_path)
748 {
749         package_manager_pkg_detail_info_t *package_info = NULL;
750
751         if (file_path == NULL)
752         {
753                 LOGE("%s file_path is NULL.", __func__);
754                 return NULL;
755         }
756
757         package_info = (package_manager_pkg_detail_info_t*)get_package_info_from_file(file_path);
758         if (package_info == NULL)
759         {
760                 LOGE("%s package_info is NULL", __func__);
761                 return NULL;
762         }
763
764         SECURE_LOGD("%s filepath(%s) package(%s) pkgid(%s) version(%s) type(%s) description(%s), label(%s), icon_size(%d), icon_buf(%s)"
765                 , __func__
766                 , file_path
767                 , package_info->pkg_name
768                 , package_info->pkgid
769                 , package_info->version
770                 , package_info->pkg_type
771                 , package_info->pkg_description
772                 , package_info->label
773                 , package_info->icon_size
774                 , package_info->icon_buf
775         );
776
777         return package_info;
778 }
779
780 static bool _app_create(void* user_data)
781 {
782         LOGD("%s", __func__);
783         int res = 0;
784
785         appdata *ad = NULL;
786         char *bind = NULL;
787
788         bind = bindtextdomain(LOCALE_FILE_NAME, LOCALEDIR);
789         if (!bind)
790         {
791                 LOGE("bindtextdomain failed.");
792         }
793         LOGD("LOCALE file name is %s", bind);
794
795         if (!user_data) {
796                 LOGE("user_data is NULL.");
797                 return false;
798         }
799         ad = (appdata*)user_data;
800
801         ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,(Ecore_Event_Handler_Cb)_keydown_cb, NULL); // Control back key
802
803         // version check
804         //  - popup
805         //  - install
806         ad->install_pkginfo = _get_packageInfo(ad->file_path);
807         if (ad->install_pkginfo == NULL)
808         {
809                 LOGE("%s _get_packageInfo() failed.", __func__);
810                 create_popup_base_gui(ad);
811                 _create_error_popup(ad);
812         }
813         else
814         {
815                 if (is_valid_version(ad->install_pkginfo->version) < 0)
816                 {
817                         LOGE("%s is_valid_version() failed. Package version is invalid.", __func__);
818                         res = create_popup_base_gui(ad);
819                         _create_error_popup(ad);
820                 }
821                 else
822                 {
823                         if (is_package_installed(ad->install_pkginfo->pkgid))
824                         {
825                                 res = create_popup_base_gui(ad);
826                                 if (res < 0)
827                                 {
828                                         LOGE("%s create_popup_base_gui() failed(%d).", __func__, res);
829                                 }
830
831                                 //Compare version
832                                 char *current_pkg_version = NULL;
833                                 char *temp = NULL;
834                                 res = get_package_version(ad->install_pkginfo->pkgid, &current_pkg_version);
835                                 if (res < 0)
836                                 {
837                                         LOGE("%s get_package_version() failed(%d).", __func__, res);
838                                         _create_error_popup(ad);
839                                         return true;
840                                 }
841
842                                 res = compare_version(current_pkg_version, ad->install_pkginfo->version);
843                                 if (res < 0)
844                                 {
845                                         LOGE("%s compare_version() failed.", __func__);
846                                         _create_error_popup(ad);
847                                         free(current_pkg_version);
848                                         return true;
849                                 }
850                                 LOGI("compare_version() = %d (old:%s, new:%s)", res, current_pkg_version, ad->install_pkginfo->version);
851
852                                 if (res == VERSION_SAME)
853                                 {
854                                         LOGI("VERSION_SAME");
855                                         char popup_msg[POP_MSG_SIZE] = {0, };
856                                         char *inst_ver = NULL;
857                                         char *dwnl_ver = NULL;
858                                         temp = strdup(_("IDS_APINST_POP_THIS_VERSION_IS_ALREADY_INSTALLED_ON_YOUR_DEVICE_IT_WILL_BE_REINSTALLED"));
859                                         if (!temp)
860                                         {
861                                                 LOGE("strdup has failed");
862                                         }
863
864                                         inst_ver = strdup(_("IDS_APINST_BODY_INSTALLED_VERSION_C_ABB"));
865                                         if (!inst_ver)
866                                         {
867                                                 LOGE("inst_ver string is null");
868                                         }
869                                         dwnl_ver = strdup(_("IDS_APINST_BODY_DOWNLOADED_VERSION_C_ABB"));
870                                         if (!dwnl_ver)
871                                         {
872                                                 LOGE("downloaded version string is null");
873                                         }
874                                         sprintf(popup_msg, "%s<br><br> %s %s<br> %s %s", temp, inst_ver, current_pkg_version, dwnl_ver, ad->install_pkginfo->version);
875                                         _create_reinstall_popup(ad, _("IDS_APINST_BUTTON_REINSTALL"), popup_msg);
876
877                                         if (temp)
878                                                 free(temp);
879                                         if (dwnl_ver)
880                                                 free(dwnl_ver);
881                                         if (inst_ver)
882                                                 free(inst_ver);
883                                 }
884                                 else if (res == VERSION_NEW)
885                                 {
886                                         LOGI("VERSION_NEW");
887                                         char popup_msg[POP_MSG_SIZE] = {0, };
888                                         char *inst_ver = NULL;
889                                         char *dwnl_ver = NULL;
890                                         temp = strdup(_("IDS_APINST_POP_AN_OLDER_VERSION_IS_ALREADY_INSTALLED_ON_YOUR_DEVICE_IT_WILL_BE_UPDATED"));
891                                         if (!temp)
892                                         {
893                                                 LOGE("strdup has failed");
894                                         }
895
896                                         inst_ver = strdup(_("IDS_APINST_BODY_INSTALLED_VERSION_C_ABB"));
897                                         if (!inst_ver)
898                                         {
899                                                 LOGE("inst_ver string is null");
900                                         }
901                                         dwnl_ver = strdup(_("IDS_APINST_BODY_DOWNLOADED_VERSION_C_ABB"));
902                                         if (!dwnl_ver)
903                                         {
904                                                 LOGE("downloaded version string is null");
905                                         }
906                                         sprintf(popup_msg, "%s<br><br> %s %s<br> %s %s", temp, inst_ver, current_pkg_version, dwnl_ver, ad->install_pkginfo->version);
907                                         _create_reinstall_popup(ad, _("IDS_APINST_BUTTON_UPDATE"), popup_msg);
908
909                                         if (temp)
910                                                 free(temp);
911                                         if (dwnl_ver)
912                                                 free(dwnl_ver);
913                                         if (inst_ver)
914                                                 free(inst_ver);
915                                 }
916                                 else if (res == VERSION_OLD)
917                                 {
918                                         LOGI("VERSION_OLD");
919                                         char popup_msg[POP_MSG_SIZE] = {0, };
920                                         char *inst_ver = NULL;
921                                         char *dwnl_ver = NULL;
922                                         temp = strdup(_("IDS_APINST_POP_A_NEWER_VERSION_IS_ALREADY_INSTALLED_ON_YOUR_DEVICE_IT_WILL_BE_REPLACED_WITH_THE_OLDER_VERSION"));
923                                         if (!temp)
924                                         {
925                                                 LOGE("strdup has failed");
926                                         }
927                                         inst_ver = strdup(_("IDS_APINST_BODY_INSTALLED_VERSION_C_ABB"));
928                                         if (!inst_ver)
929                                         {
930                                                 LOGE("inst_ver string is null");
931                                         }
932                                         dwnl_ver = strdup(_("IDS_APINST_BODY_DOWNLOADED_VERSION_C_ABB"));
933                                         if (!dwnl_ver)
934                                         {
935                                                 LOGE("downloaded version string is null");
936                                         }
937                                         sprintf(popup_msg, "%s<br><br> %s %s<br> %s %s", temp, inst_ver, current_pkg_version, dwnl_ver, ad->install_pkginfo->version);
938                                         _create_reinstall_popup(ad, _("IDS_APINST_BUTTON_REINSTALL"), popup_msg);
939
940                                         if (temp)
941                                                 free(temp);
942                                         if (dwnl_ver)
943                                                 free(dwnl_ver);
944                                         if (inst_ver)
945                                                 free(inst_ver);
946                                 }
947
948                                 free(current_pkg_version);
949
950                         }
951                         else
952                         {
953                                 LOGI("%s create_base_gui() called.", __func__);
954                                 res = create_base_gui(ad);
955                                 if (res < 0)
956                                 {
957                                         LOGE("%s create_base_gui() failed(%d).", __func__, res);
958                                 }
959                         }
960                 }
961         }
962
963         return true;
964 }
965
966
967 static void _app_pause(void* user_data)
968 {
969         LOGD("%s", __func__);
970         ui_app_exit();
971 }
972
973 static void _app_resume(void* user_data)
974 {
975         LOGD("%s", __func__);
976 }
977
978 static void _app_terminate(void* user_data)
979 {
980         LOGD("%s", __func__);
981 }
982
983
984 int main(int argc, char* argv[])
985 {
986         LOGD("Start installer main()");
987         appdata ad = {0,};
988         ui_app_lifecycle_callback_s event_callback = {0,};
989
990         app_event_handler_h lang_changed_handler;
991         app_event_handler_h orient_changed_handler;
992         app_event_handler_h region_changed_handler;
993
994         event_callback.create           = _app_create;
995         event_callback.terminate        = _app_terminate;
996         event_callback.pause            = _app_pause;
997         event_callback.resume           = _app_resume;
998
999         ui_app_add_event_handler(&lang_changed_handler, APP_EVENT_LANGUAGE_CHANGED, _lang_changed, &ad);
1000         ui_app_add_event_handler(&orient_changed_handler, APP_EVENT_DEVICE_ORIENTATION_CHANGED, _orient_changed, &ad);
1001         ui_app_add_event_handler(&region_changed_handler, APP_EVENT_REGION_FORMAT_CHANGED, _region_changed, &ad);
1002
1003         char *file_path;
1004         const char *extension;
1005
1006         if (__parse_argv(argc, argv, &file_path))
1007         {
1008                 LOGE("%s Failed to parse argv!", __func__);
1009                 return -1;
1010         }
1011
1012         if (strncmp(file_path, "file", 4) == 0)
1013         {
1014                 ad.file_path = modify_file_path(file_path);
1015         }
1016         else
1017         {
1018                 ad.file_path = file_path;
1019         }
1020
1021         extension = get_file_extension(file_path);
1022         ad.extension = (char*)extension;
1023
1024         SECURE_LOGI("%s install file_path(%s), extension(%s)", __func__, ad.file_path, ad.extension);
1025
1026         int ret = ui_app_main(argc, argv, &event_callback, &ad);
1027         if (ret != APP_ERROR_NONE) {
1028                 LOGE("ui_app_main() is failed. err = %d", ret);
1029         }
1030
1031         LOGD("End installer main()");
1032         return ret;
1033 }