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