upload tizen1.0 source
[pkgs/n/native-installer.git] / frontend / ui / src / frontendhomeview.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 <appcore-efl.h>
28 #include <Ecore_X.h>
29 #include "frontend.h"
30 #include "native_installer_util.h"
31 #include "nativeinstaller.h"
32
33 #define DESKTOP_W   720.0
34
35 extern struct appdata ad;
36 extern struct frontenddata frontdata;
37 int do_upgrade = -1;
38
39 static void __response_cb(void *data, Evas_Object * obj, void *event);
40 static void __win_del(void *data, Evas_Object * obj, void *event);
41 static Eina_Bool __perform_downgrade(void *data);
42
43 void _information_popup(Evas_Smart_Cb func, const char *output,
44                                 void *user_param)
45 {
46         if (!ad.win_main)
47                 return;
48         evas_object_show(ad.win_main);
49         Evas_Object *popup = NULL;
50         popup = elm_popup_add(ad.win_main);
51         if (!popup)
52                 return;
53         elm_object_part_text_set(popup, dgettext("sys_string",
54                                                 "IDS_COM_BODY_INFORMATION"), NULL);
55         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
56                                                 EVAS_HINT_EXPAND);
57         elm_object_text_set(popup, output);
58
59         Evas_Object *button = NULL;
60         button = elm_button_add(popup);
61         elm_object_text_set(button, dgettext("sys_string", "IDS_COM_SK_OK"));
62         elm_object_part_content_set(popup, "button1", button);
63
64         evas_object_smart_callback_add(button, "clicked", func, user_param);
65         evas_object_show(popup);
66 }
67
68 void _package_downgrade_popup(Evas_Smart_Cb func1, Evas_Smart_Cb func2,
69                                 const char *output, void *user_param)
70 {
71         if (!ad.win_main) {
72                 d_msg_frontend(DEBUG_ERR, "Main Window NULL\n");
73                 return;
74         }
75         evas_object_show(ad.win_main);
76         
77         Evas_Object *popup = NULL;
78         popup = elm_popup_add(ad.win_main);
79         if (!popup) {
80                 d_msg_frontend(DEBUG_ERR, "Add Popup Fail\n");
81                 return;
82         }
83         elm_object_part_text_set(popup,
84                                         dgettext("sys_string", "IDS_COM_BODY_INFORMATION"), NULL);
85         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
86                                          EVAS_HINT_EXPAND);
87         elm_object_text_set(popup, output);
88
89         Evas_Object *button1 = NULL;
90         Evas_Object *button2 = NULL;
91
92         button1 = elm_button_add(popup);
93         elm_object_text_set(button1, dgettext("sys_string", "IDS_COM_SK_YES"));
94         elm_object_part_content_set(popup, "button1", button1);
95         evas_object_smart_callback_add(button1, "clicked", func1, user_param);
96
97         button2 = elm_button_add(popup);
98         elm_object_text_set(button2, dgettext("sys_string", "IDS_COM_SK_NO"));
99         elm_object_part_content_set(popup, "button2", button2);
100         evas_object_smart_callback_add(button2, "clicked", func2, user_param);
101
102         evas_object_show(popup);
103 }
104
105 static void __win_del(void *data, Evas_Object * obj, void *event)
106 {
107         elm_exit();
108 }
109
110 static Eina_Bool __perform_downgrade(void *data)
111 {
112         int ret = -1;
113         ret = _pkgmgr_package_install(frontdata.cmdlineargs->ppkgname,
114                                                            false, NULL);
115         if (ret != 0) {
116                 char *errstr = NULL;
117                 _error_no_to_string(ret, &errstr);
118                 _broadcast_status_notification(frontdata.cmdlineargs->ppkgname,
119                                                "error", errstr);
120                 stat_cb(frontdata.cmdlineargs->ppkgname, "error", errstr);
121                 _broadcast_status_notification(frontdata.cmdlineargs->ppkgname,
122                                                "end", "fail");
123                 stat_cb(frontdata.cmdlineargs->ppkgname, "end", "fail");
124                 d_msg_backend(DEBUG_ERR,
125                               "install failed with err(%d) (%s)\n",
126                               ret, errstr);
127         } else {
128                 d_msg_backend(DEBUG_INFO, "install success\n");
129                 _broadcast_status_notification(frontdata.cmdlineargs->ppkgname,
130                                                "end", "ok");
131                 stat_cb(frontdata.cmdlineargs->ppkgname, "end", "ok");
132         }
133         _set_backend_state_info(REQUEST_COMPLETED);
134         _set_backend_state(1);
135         return 0;
136 }
137
138 static void __response_cb1(void *data, Evas_Object * obj, void *event)
139 {
140         printf("\nresponse callback=%d\n", (int)event);
141         Ecore_Idler *handle = NULL;
142         int response = (int)event;
143         
144         do_upgrade = 1;
145         handle = ecore_idler_add(__perform_downgrade, NULL);
146         d_msg_frontend(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
147         evas_object_del(obj);
148         obj = NULL;
149 }
150
151 static void __response_cb2(void *data, Evas_Object * obj, void *event)
152 {
153         printf("\nresponse callback=%d\n", (int)event);
154         Ecore_Idler *handle = NULL;
155         
156         do_upgrade = 0;
157         handle = ecore_idler_add(__perform_downgrade, NULL);
158         evas_object_del(obj);
159         d_msg_frontend(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
160         obj = NULL;
161 }
162
163 Eina_Bool _init_appdata(struct appdata *user_data)
164 {
165         unsigned char *prop_data = NULL;
166         int rotation = 0;
167         int w;
168         int h;
169         int x;
170         int y;
171         int count = 0;
172         user_data->win_main = elm_win_add(NULL, PACKAGE, ELM_WIN_DIALOG_BASIC);
173         if (!user_data->win_main)
174                 return EINA_FALSE;
175
176         elm_win_title_set(user_data->win_main, PACKAGE);
177         elm_win_alpha_set(user_data->win_main, EINA_TRUE);
178         elm_win_borderless_set(user_data->win_main, EINA_TRUE);
179         elm_win_raise(user_data->win_main);
180         ecore_x_window_geometry_get(ecore_x_window_root_get
181                                     (ecore_x_window_focus_get()), &x, &y, &w,
182                                     &h);
183         int ret =
184             ecore_x_window_prop_property_get(ecore_x_window_root_get
185                                      (ecore_x_window_focus_get()),
186                                      ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE,
187                                      ECORE_X_ATOM_CARDINAL, 32,
188                                      &prop_data, &count);
189         if (ret && prop_data)
190                 memcpy(&rotation, prop_data, sizeof(int));
191         if (prop_data)
192                 free(prop_data);
193         evas_object_resize(user_data->win_main, w, h);
194         evas_object_move(user_data->win_main, x, y);
195         /*evas_object_show(user_data->win_main); */
196         evas_object_smart_callback_add(user_data->win_main, "delete,request",
197                                        __win_del, NULL);
198         elm_win_indicator_mode_set(user_data->win_main, ELM_WIN_INDICATOR_SHOW);
199
200         double s;
201         s = w / DESKTOP_W;
202         elm_config_scale_set(s);
203
204         /*evas_object_geometry_get(user_data->win_main, NULL,
205         NULL, &user_data->root_w, &user_data->root_h); */
206
207         user_data->evas = evas_object_evas_get(user_data->win_main);
208         if (!user_data->evas)
209                 return EINA_FALSE;
210
211         return EINA_TRUE;
212 }
213
214 Eina_Bool _init_home_view(struct appdata *user_data)
215 {
216         return EINA_TRUE;
217
218 }
219
220 void _destroy_home_view(struct appdata *user_data)
221 {
222
223         if (!user_data) {
224                 return;
225         }
226         evas_object_del(user_data->main_view);
227 }
228
229 int _frontend_launch_main_view(struct appdata *data)
230 {
231         /* create UI */
232         if (!_init_appdata(data)) {
233                 printf("ERROR: fail create window\n");
234                 return 0;
235         }
236         /*ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, keydown_event, NULL); */
237
238         if (!_init_home_view(data)) {
239                 printf("ERROR: fail create home view\n");
240                 return 0;
241         }
242         return 0;
243 }
244
245
246 void _frontend_update_progress_info(struct appdata *data, char *progressinfo)
247 {
248         elm_object_text_set(data->scrollbar_label, progressinfo);
249         _information_popup(__win_del, progressinfo, data);
250 }
251
252 void _package_downgrade_information(const char *message)
253 {
254         _package_downgrade_popup(__response_cb1, __response_cb2, message, &ad);
255 }
256