npruntime plugins copy task was cleaned up.
[framework/web/wrt-installer.git] / src / jobs / widget_install / widget_install_popup.cpp
1 /*
2  * Copyright (c) 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  * @file    widget_install_popup.cpp
18  * @author  lke01.lee (lke01.lee@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for installer popup
21  */
22 #include <dpl/log/log.h>
23 #include <widget_install/job_widget_install.h>
24 #include <widget_install/widget_install_errors.h>
25 #include <widget_install/widget_install_context.h>
26 #include <widget_install_popup.h>
27
28 namespace {
29 const char * const EDJFILE = "/usr/share/edje/wrt/widget_install_popup.edj";
30 const char * const EDJGROUP = "widget_install_popup";
31 const char * const TITLE_TEXT = "title,text";
32 const char * const name = "WidgetInstallPopup";
33 const char * const FEATURE_TITLE = "Widget Feature Info";
34 const char * const INFO_TITLE = "Widget Info";
35 const char * const INSTALLATION_FAILURE = "Installation failure";
36 const char * const INFO_LEFT_BUTTON = "OK";
37 const char * const INFO_RIGHT_BUTTON = "CANCEL ";
38 const char * const WARNING_TITLE = "Widget Warning";
39 const char * const WARNING_LEFT_BUTTON = "YES";
40 const char * const WARNING_RIGHT_BUTTON = "NO";
41 const char * const QUESTION =
42     "Widget use Device API below. <br>Do you want to install?";
43 }
44
45 namespace Jobs {
46 namespace WidgetInstall {
47 WidgetInstallPopup::WidgetInstallPopup(InstallerContext &installContext) :
48     m_win(NULL),
49     m_popup(NULL),
50     m_installContext(installContext),
51     m_installCancel(WRT_POPUP_BUTTON)
52 {
53     LogDebug("InstallPopup");
54 }
55
56 WidgetInstallPopup::~WidgetInstallPopup()
57 {
58     LogDebug("~InstallPopup");
59 }
60
61 bool WidgetInstallPopup::addWin(const char *name)
62 {
63     int w, h;
64     m_win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
65     if (!m_win) {
66         LogError("addWin failed");
67         return false;
68     }
69
70     elm_win_alpha_set(m_win, EINA_TRUE);
71     elm_win_title_set(m_win, name);
72     elm_win_borderless_set(m_win, EINA_TRUE);
73     elm_win_raise(m_win);
74
75     ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
76     evas_object_resize(m_win, w, h);
77     return true;
78 }
79
80 bool WidgetInstallPopup::addPopup()
81 {
82     m_popup = elm_popup_add(m_win);
83     if (!m_popup) {
84         return false;
85     }
86
87     evas_object_size_hint_align_set(m_popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
88     evas_object_size_hint_weight_set(m_popup,
89                                      EVAS_HINT_EXPAND,
90                                      EVAS_HINT_EXPAND);
91     return true;
92 }
93
94 void WidgetInstallPopup::addTitle(PopupType type)
95 {
96     switch (type) {
97     case PopupType::WIDGET_FEATURE_INFO:
98         elm_object_part_text_set(m_popup, TITLE_TEXT, FEATURE_TITLE);
99         break;
100     case PopupType::WIDGET_AUTHOR_INFO:
101         elm_object_part_text_set(m_popup, TITLE_TEXT, INFO_TITLE);
102         break;
103     case PopupType::WIDGET_MIN_VERSION:
104     case PopupType::WIDGET_UNRECOGNIZED:
105         elm_object_part_text_set(m_popup, TITLE_TEXT, WARNING_TITLE);
106         break;
107     case PopupType::WIDGET_WRONG_FEATURE_INFO:
108         elm_object_part_text_set(m_popup, TITLE_TEXT, INSTALLATION_FAILURE);
109         break;
110     default:
111         break;
112     }
113 }
114
115 void WidgetInstallPopup::addScrollLabel(const std::string &str)
116 {
117     Evas_Object *ly = elm_layout_add(m_popup);
118     if (!ly) {
119         LogError(" install popup layout add failed");
120         return;
121     }
122     elm_layout_file_set(ly, EDJFILE, "popup");
123     evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
124     evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
125     evas_object_show(ly);
126     elm_object_content_set(m_popup, ly);
127
128     Evas_Object *question_label = elm_label_add(m_popup);
129     if (!question_label) {
130         return;
131     }
132     evas_object_size_hint_align_set(question_label,
133                                     EVAS_HINT_FILL,
134                                     EVAS_HINT_FILL);
135     evas_object_size_hint_weight_set(question_label,
136                                      EVAS_HINT_EXPAND,
137                                      EVAS_HINT_EXPAND);
138     evas_object_show(question_label);
139     elm_object_text_set(question_label, QUESTION);
140     elm_object_part_content_set(ly, "elm.swallow.label", question_label);
141
142     Evas_Object *scroller = elm_scroller_add(m_popup);
143     if (!scroller) {
144         return;
145     }
146     evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
147     evas_object_size_hint_weight_set(scroller,
148                                      EVAS_HINT_EXPAND,
149                                      EVAS_HINT_EXPAND);
150     elm_scroller_bounce_set(scroller, EINA_TRUE, EINA_TRUE);
151     elm_scroller_policy_set(scroller,
152                             ELM_SCROLLER_POLICY_AUTO,
153                             ELM_SCROLLER_POLICY_AUTO);
154
155     elm_object_part_content_set(ly, "elm.swallow.scroller", scroller);
156     evas_object_show(scroller);
157
158     Evas_Object *feature_label = elm_label_add(m_popup);
159     if (!feature_label) {
160         return;
161     }
162     evas_object_size_hint_align_set(feature_label,
163                                     EVAS_HINT_FILL,
164                                     EVAS_HINT_FILL);
165     evas_object_size_hint_weight_set(feature_label,
166                                      EVAS_HINT_EXPAND,
167                                      EVAS_HINT_EXPAND);
168     evas_object_show(feature_label);
169     elm_object_text_set(feature_label, str.c_str());
170     elm_object_content_set(scroller, feature_label);
171 }
172
173 void WidgetInstallPopup::addContent(PopupType type, const std::string &str)
174 {
175     switch (type) {
176     case PopupType::WIDGET_FEATURE_INFO:
177         addScrollLabel(str);
178         break;
179     default:
180         elm_object_part_text_set(m_popup, "default", str.c_str());
181         break;
182     }
183 }
184
185 void WidgetInstallPopup::addButton(PopupType type)
186 {
187     Evas_Object *lbutton = elm_button_add(m_popup);
188     Evas_Object *rbutton = elm_button_add(m_popup);
189     if (!lbutton || !rbutton) {
190         return;
191     }
192
193     switch (type) {
194     case PopupType::WIDGET_WRONG_FEATURE_INFO:
195         elm_object_text_set(lbutton, INFO_LEFT_BUTTON);
196         elm_object_part_content_set(m_popup, "button1", lbutton);
197         evas_object_smart_callback_add(lbutton,
198                                        "clicked",
199                                        userCancelCallback,
200                                        this);
201         return;
202     case PopupType::WIDGET_FEATURE_INFO:
203         elm_object_text_set(lbutton, INFO_LEFT_BUTTON);
204         elm_object_text_set(rbutton, INFO_RIGHT_BUTTON);
205         break;
206     default:
207         elm_object_text_set(lbutton, WARNING_LEFT_BUTTON);
208         elm_object_text_set(rbutton, WARNING_RIGHT_BUTTON);
209         break;
210     }
211
212     elm_object_part_content_set(m_popup, "button1", lbutton);
213     evas_object_smart_callback_add(lbutton,
214                                    "clicked",
215                                    userPermitCallback,
216                                    this);
217     elm_object_part_content_set(m_popup, "button2", rbutton);
218     evas_object_smart_callback_add(rbutton,
219                                    "clicked",
220                                    userCancelCallback,
221                                    this);
222 }
223
224 bool WidgetInstallPopup::createPopup()
225 {
226     bool ret = addWin(name);
227     if (!ret) {
228         return false;
229     }
230     evas_object_show(m_win);
231
232     ret = addPopup();
233     if (!ret) {
234         evas_object_del(m_win);
235         m_win = NULL;
236         return false;
237     }
238
239     return true;
240 }
241
242 void WidgetInstallPopup::destroyPopup()
243 {
244     if (m_win) {
245         evas_object_del(m_win);
246         m_win = NULL;
247         m_popup = NULL;
248     }
249 }
250
251 void WidgetInstallPopup::loadPopup(PopupType type, const std::string &label)
252 {
253     addTitle(type);
254     addContent(type, label);
255     addButton(type);
256 }
257
258 void WidgetInstallPopup::showPopup()
259 {
260     evas_object_show(m_popup);
261 }
262
263 void WidgetInstallPopup::userPermitCallback(void * data,
264                                             Evas_Object */*obj*/,
265                                             void */*event_info*/)
266 {
267     WidgetInstallPopup *This = static_cast<WidgetInstallPopup *>(data);
268     This->m_installCancel = WRT_POPUP_BUTTON_OK;
269     This->m_installContext.job->Resume();
270 }
271
272 void WidgetInstallPopup::userCancelCallback(void *data,
273                                             Evas_Object */*obj*/,
274                                             void */*event_info*/)
275 {
276     WidgetInstallPopup *This = static_cast<WidgetInstallPopup *>(data);
277     This->m_installCancel = WRT_POPUP_BUTTON_CANCEL;
278     This->m_installContext.job->Resume();
279 }
280 }
281 }
282