afc80ac69f8832980e84783f7b37d0d96383f6d9
[platform/core/base/rpm-installer.git] / frontend / ui / src / rpm-homeview.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 #include <appcore-efl.h>
24 #include <Ecore_X.h>
25 #include <pthread.h>
26 #include "rpm-frontend.h"
27 #include "rpm-installer-util.h"
28 #include "rpm-homeview.h"
29 #include "rpm-installer.h"
30
31 #define DESKTOP_W   720.0
32
33 extern struct appdata ad;
34 int do_upgrade = -1;
35 extern ri_frontend_data front_data;
36 Evas_Object *popup_global;
37
38 static void __ri_response_cb1(void *data, Evas_Object *obj, void *event);
39 static void __ri_response_cb2(void *data, Evas_Object *obj, void *event);
40 static void __ri_win_del(void *data, Evas_Object *obj, void *event);
41 static Eina_Bool __ri_perform_downgrade(void *data);
42
43 void _ri_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         Evas_Object *button = NULL;
59         button = elm_button_add(popup);
60         elm_object_text_set(button, dgettext("sys_string", "IDS_COM_SK_OK"));
61         elm_object_part_content_set(popup, "button1", button);
62         evas_object_smart_callback_add(button, "clicked", func, user_param);
63         evas_object_show(popup);
64 }
65
66 void _ri_package_downgrade_popup(Evas_Smart_Cb func1,
67                                 Evas_Smart_Cb func2,
68                                 const char *output, void *user_param)
69 {
70         if (!ad.win_main)
71                 return;
72         evas_object_show(ad.win_main);
73         Evas_Object *popup = NULL;
74         popup = elm_popup_add(ad.win_main);
75         if (!popup)
76                 return;
77         elm_object_part_text_set(popup, dgettext("sys_string",
78                                         "IDS_COM_BODY_INFORMATION"), NULL);
79         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
80                                  EVAS_HINT_EXPAND);
81         elm_object_text_set(popup, output);
82         Evas_Object *button1 = NULL;
83         Evas_Object *button2 = NULL;
84         button1 = elm_button_add(popup);
85         elm_object_text_set(button1, dgettext("sys_string", "IDS_COM_SK_YES"));
86         elm_object_part_content_set(popup, "button1", button1);
87         evas_object_smart_callback_add(button1, "clicked", func1, user_param);
88
89         button2 = elm_button_add(popup);
90         elm_object_text_set(button2, dgettext("sys_string", "IDS_COM_SK_NO"));
91         elm_object_part_content_set(popup, "button2", button2);
92         evas_object_smart_callback_add(button2, "clicked", func2, user_param);
93         popup_global = popup;
94         evas_object_show(popup);
95 }
96
97 static void __ri_win_del(void *data, Evas_Object *obj, void *event)
98 {
99         elm_exit();
100 }
101
102 static Eina_Bool __ri_perform_downgrade(void *data)
103 {
104         int ret = -1;
105         ret = _rpm_installer_package_install(front_data.args->pkgid,
106                                              true, "--force");
107         if (ret != 0) {
108                 char *errstr = NULL;
109                 _ri_error_no_to_string(ret, &errstr);
110                 _ri_broadcast_status_notification(front_data.args->pkgid,
111                                                   "error", errstr);
112                 _ri_stat_cb(front_data.args->pkgid, "error", errstr);
113                 _ri_broadcast_status_notification(front_data.args->pkgid,
114                                                   "end", "fail");
115                 _ri_stat_cb(front_data.args->pkgid, "end", "fail");
116                 _d_msg(DEBUG_ERR,
117                        "install failed with err(%d) (%s)\n", ret, errstr);
118         } else {
119                 _d_msg(DEBUG_INFO, "install success\n");
120                 _ri_broadcast_status_notification(front_data.args->pkgid,
121                                                   "end", "ok");
122                 _ri_stat_cb(front_data.args->pkgid, "end", "ok");
123         }
124         _ri_set_backend_state_info(REQUEST_COMPLETED);
125         _ri_set_backend_state(1);
126         return 0;
127 }
128
129 static void __ri_response_cb1(void *data, Evas_Object *obj, void *event)
130 {
131         printf("\nresponse callback=%d\n", (int)event);
132         do_upgrade = 1;
133
134         ecore_idler_add(__ri_perform_downgrade, NULL);
135         _d_msg(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
136         evas_object_del(obj);
137         evas_object_del(popup_global);
138         obj = NULL;
139 }
140 static void __ri_response_cb2(void *data, Evas_Object *obj, void *event)
141 {
142         printf("\nresponse callback=%d\n", (int)event);
143         do_upgrade = 0;
144
145         ecore_idler_add(__ri_perform_downgrade, NULL);
146         evas_object_del(obj);
147         evas_object_del(popup_global);
148         _d_msg(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
149         obj = NULL;
150 }
151
152 Eina_Bool _ri_init_appdata(struct appdata *user_data)
153 {
154         unsigned char *prop_data = NULL;
155         int rotation = 0;
156         int w;
157         int h;
158         int x;
159         int y;
160         int count = 0;
161         user_data->win_main = elm_win_add(NULL, PACKAGE, ELM_WIN_DIALOG_BASIC);
162         if (!user_data->win_main)
163                 return EINA_FALSE;
164
165         elm_win_title_set(user_data->win_main, PACKAGE);
166         elm_win_alpha_set(user_data->win_main, EINA_TRUE);
167         elm_win_borderless_set(user_data->win_main, EINA_TRUE);
168         elm_win_raise(user_data->win_main);
169         ecore_x_window_geometry_get(ecore_x_window_root_get
170                                     (ecore_x_window_focus_get()), &x, &y, &w,
171                                     &h);
172         int ret =
173             ecore_x_window_prop_property_get(ecore_x_window_root_get
174                                      (ecore_x_window_focus_get()),
175                                      ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE,
176                                      ECORE_X_ATOM_CARDINAL, 32,
177                                      &prop_data, &count);
178         if (ret && prop_data)
179                 memcpy(&rotation, prop_data, sizeof(int));
180         if (prop_data)
181                 free(prop_data);
182         evas_object_resize(user_data->win_main, w, h);
183         evas_object_move(user_data->win_main, x, y);
184         /*evas_object_show(user_data->win_main);
185         evas_object_smart_callback_add(user_data->win_main, "delete,request",
186                                        __ri_win_del, NULL);
187         elm_win_indicator_state_set(user_data->win_main, EINA_TRUE);*/
188         double s;
189         s = w / DESKTOP_W;
190         elm_config_scale_set(s);
191         user_data->evas = evas_object_evas_get(user_data->win_main);
192         if (!user_data->evas)
193                 return EINA_FALSE;
194
195         return EINA_TRUE;
196 }
197
198 Eina_Bool _ri_init_home_view(struct appdata *user_data)
199 {
200         return EINA_TRUE;
201
202 }
203
204 void _ri_destroy_home_view(struct appdata *user_data)
205 {
206
207         if (!user_data) {
208                 return;
209         }
210         evas_object_del(user_data->main_view);
211 }
212
213 int _ri_frontend_launch_main_view(struct appdata *data)
214 {
215         /* create UI */
216         if (!_ri_init_appdata(data)) {
217                 return 0;
218         }
219         if (!_ri_init_home_view(data)) {
220                 return 0;
221         }
222         return 0;
223 }
224
225 void _ri_frontend_update_progress_info(struct appdata *data, char *progressinfo)
226 {
227         elm_object_text_set(data->scrollbar_label, progressinfo);
228         _ri_information_popup(__ri_win_del, progressinfo, data);
229 }
230
231 void _ri_package_downgrade_information(const char *message)
232 {
233         _ri_package_downgrade_popup(__ri_response_cb1, __ri_response_cb2, message, &ad);
234 }