upload tizen1.0 source
[pkgs/n/native-installer.git] / frontend / src / frontendappcoreintf.c
1 /*
2  * rpm-installer
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>, Shobhit Srivastava <shobhit.s@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
25
26   
27 #include <stdio.h>
28 #include <Elementary.h>
29 #include <appcore-efl.h>
30 #include <string.h>
31 #include <glib-object.h>
32 /*#include <utilX.h>*/
33
34 #include "frontend.h"
35 #include "frontendhomeview.h"
36 #include "native_installer_util.h"
37 #include "nativeinstaller.h"
38 #include<pkgmgr_installer.h>
39
40 static void __start_processing(void *user_data);
41
42 int greturn_main_value = -1;
43 struct appdata ad;
44 extern struct frontenddata frontdata;
45 extern char scrolllabel[256];
46 pkgmgr_installer *pi = NULL;
47 extern int do_upgrade;
48
49 /**< Called before main loop */
50 int app_create(void *user_data)
51 {
52         int ret = 0;
53         struct appdata *data = (struct appdata *)user_data;
54         struct frontendcmdlinearg *pardata = frontdata.cmdlineargs;
55
56         if (pardata->quiteoptions == 0) {
57                 /* Launch UI */
58                 ret = _frontend_launch_main_view(data);
59                 return ret;
60         }
61
62         return 0;
63 }
64
65 /**< Called after main loop */
66 int app_terminate(void *user_data)
67 {
68         struct appdata *data = (struct appdata *)user_data;
69         struct frontendcmdlinearg *pardata = frontdata.cmdlineargs;
70         if (pardata->quiteoptions == 0) {
71                 /* Launch UI */
72                 _destroy_home_view(data);
73         }
74         return 0;
75 }
76
77 /**< Called when every window goes back */
78 int app_pause(void *user_data)
79 {
80         /*printf("called app_pause\n"); */
81         return 0;
82 }
83
84 /**< Called when any window comes on top */
85 int app_resume(void *user_data)
86 {
87         /*printf("called app_resume\n"); */
88         return 0;
89 }
90
91 /**< Called at the first idler*/
92 int app_reset(bundle *b, void *user_data)
93 {
94         /*printf("called app_reset\n"); */
95         return 0;
96 }
97
98 /**< Called at rotate device*/
99 int app_rotation(enum appcore_rm mode, void *user_data)
100 {
101         struct appdata *data = (struct appdata *)user_data;
102         int angle;
103         switch (mode) {
104         case APPCORE_RM_LANDSCAPE_NORMAL:
105                 angle = -90;
106                 break;
107
108         case APPCORE_RM_LANDSCAPE_REVERSE:
109                 angle = 90;
110                 break;
111
112         case APPCORE_RM_PORTRAIT_REVERSE:
113                 angle = 180;
114                 break;
115
116         case APPCORE_RM_UNKNOWN:
117         case APPCORE_RM_PORTRAIT_NORMAL:
118         default:
119                 angle = 0;
120                 break;
121         }
122         elm_win_rotation_with_resize_set(data->win_main, angle);
123         return 0;
124 }
125
126 Eina_Bool show_popup_cb(void *data)
127 {
128         int state = -1;
129         const char message[256] = {'\0'};
130         strncpy(message, _("Continue Downgrade?"), 255);
131         state = _get_backend_state_info();
132         switch (state) {
133         case REQUEST_ACCEPTED:
134                 break;
135         case GOT_PACKAGE_INFO_SUCCESSFULLY:
136                 break;
137         case DPKG_REQUEST_PENDING:
138                 _package_downgrade_information(message);
139                 _set_backend_state_info(REQUEST_ACCEPTED);
140                 break;
141         case DPKG_REQUEST_COMPLETED:
142         default:
143                 if (frontdata.cmdlineargs->quiteoptions == 0) {
144                         _frontend_update_progress_info(&ad, scrolllabel);
145                         return 0;
146                 }
147                 else
148                         elm_exit();
149                 break;
150         }
151
152         return 1;
153 }
154
155 static void __start_processing(void *user_data)
156 {
157         int ret = 0;
158         struct frontenddata *data = (struct frontenddata *)user_data;
159         g_type_init();
160         ret = _cmdline_process(data);
161         greturn_main_value = ret;
162         _cmdline_destroy(data);
163         
164 }
165
166 int main(int argc, char *argv[])
167 {
168         int ret = 0;
169         struct frontendcmdlinearg *pardata = NULL;
170         struct appcore_ops ops;
171         Ecore_Idler *popup_handle = NULL;
172         ops.create = app_create;
173         ops.terminate = app_terminate;
174         ops.pause = app_pause;
175         ops.resume = app_resume;
176         ops.reset = app_reset;
177         ops.data = &ad;
178
179         ecore_init();
180         appcore_set_i18n(PACKAGE, LOCALE_PATH);
181         _d_msg_init("frontend");
182         d_msg_frontend(DEBUG_RESULT, "Frontend version: %s\n",
183                        NATIVE_INSTALLER_VERSION);
184         pardata = (struct frontendcmdlinearg *)calloc(1,
185                                         sizeof(struct frontendcmdlinearg));
186         if (pardata == NULL) {
187                 d_msg_frontend(DEBUG_ERR, "not enough memory\n");
188                 ret = NATIVEINSTALLER_ERR_NOT_ENOUGH_MEMORY;
189                 goto ERROR;
190         }
191         pardata->pkeyid = NULL;
192         pardata->ppkgname = NULL;
193         pardata->quiteoptions = 0;
194         pardata->reqcommand = INVALID_CMD;
195
196         /* We need to use pkgmgr_installer_receive request() 
197         to parse the arguments */
198         if ((ret =
199              _parse_cmdline(argc, argv, pardata)) != NATIVEINSTALLER_SUCCESS) {
200                 d_msg_frontend(DEBUG_ERR, "_parse_cmdline failed \n");
201                 goto ERROR;
202         }
203
204         frontdata.cmdlineargs = pardata;
205         frontdata.gptr_security_cookie = NULL;
206         frontdata.perror_string = NULL;
207         __start_processing(&frontdata);
208         
209         /*The installer has finished the installation/uninstallation.
210         Now, if it was a non quite operation we need to show the popup. */
211         popup_handle = ecore_idler_add(show_popup_cb, NULL);
212         
213         d_msg_frontend(DEBUG_RESULT, "about to run efl main loop");
214         appcore_efl_main(PACKAGE, &argc, &argv, &ops);
215         d_msg_frontend(DEBUG_RESULT, "%d\n", greturn_main_value);
216 #if 1
217         _d_msg_deinit();
218         if (pi) {
219                 pkgmgr_installer_free(pi);
220                 pi = NULL;
221         }
222 #endif
223         return greturn_main_value;
224
225  ERROR:
226         if (pardata) {
227                 if (pardata->ppkgname) {
228                         free(pardata->ppkgname);
229                         pardata->ppkgname = NULL;
230                 }
231                 if (pardata->pkeyid) {
232                         free(pardata->pkeyid);
233                         pardata->pkeyid = NULL;
234                 }
235                 free(pardata);
236                 pardata = NULL;
237         }
238         d_msg_frontend(DEBUG_RESULT, "%d\n", ret);
239         _d_msg_deinit();
240         return ret;
241
242 }
243