2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file widget_install_popup.cpp
18 * @author lke01.lee (lke01.lee@samsung.com)
20 * @brief Implementation file for installer popup
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>
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?";
46 namespace WidgetInstall {
47 WidgetInstallPopup::WidgetInstallPopup(InstallerContext &installContext) :
50 m_installContext(installContext),
51 m_installCancel(WRT_POPUP_BUTTON)
53 LogDebug("InstallPopup");
56 WidgetInstallPopup::~WidgetInstallPopup()
58 LogDebug("~InstallPopup");
61 bool WidgetInstallPopup::addWin(const char *name)
64 m_win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
66 LogError("addWin failed");
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);
75 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
76 evas_object_resize(m_win, w, h);
80 bool WidgetInstallPopup::addPopup()
82 m_popup = elm_popup_add(m_win);
87 evas_object_size_hint_align_set(m_popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
88 evas_object_size_hint_weight_set(m_popup,
94 void WidgetInstallPopup::addTitle(PopupType type)
97 case PopupType::WIDGET_FEATURE_INFO:
98 elm_object_part_text_set(m_popup, TITLE_TEXT, FEATURE_TITLE);
100 case PopupType::WIDGET_AUTHOR_INFO:
101 elm_object_part_text_set(m_popup, TITLE_TEXT, INFO_TITLE);
103 case PopupType::WIDGET_MIN_VERSION:
104 case PopupType::WIDGET_UNRECOGNIZED:
105 elm_object_part_text_set(m_popup, TITLE_TEXT, WARNING_TITLE);
107 case PopupType::WIDGET_WRONG_FEATURE_INFO:
108 elm_object_part_text_set(m_popup, TITLE_TEXT, INSTALLATION_FAILURE);
115 void WidgetInstallPopup::addScrollLabel(const std::string &str)
117 Evas_Object *ly = elm_layout_add(m_popup);
119 LogError(" install popup layout add failed");
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);
128 Evas_Object *question_label = elm_label_add(m_popup);
129 if (!question_label) {
132 evas_object_size_hint_align_set(question_label,
135 evas_object_size_hint_weight_set(question_label,
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);
142 Evas_Object *scroller = elm_scroller_add(m_popup);
146 evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
147 evas_object_size_hint_weight_set(scroller,
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);
155 elm_object_part_content_set(ly, "elm.swallow.scroller", scroller);
156 evas_object_show(scroller);
158 Evas_Object *feature_label = elm_label_add(m_popup);
159 if (!feature_label) {
162 evas_object_size_hint_align_set(feature_label,
165 evas_object_size_hint_weight_set(feature_label,
168 evas_object_show(feature_label);
169 elm_object_text_set(feature_label, str.c_str());
170 elm_object_content_set(scroller, feature_label);
173 void WidgetInstallPopup::addContent(PopupType type, const std::string &str)
176 case PopupType::WIDGET_FEATURE_INFO:
180 elm_object_part_text_set(m_popup, "default", str.c_str());
185 void WidgetInstallPopup::addButton(PopupType type)
187 Evas_Object *lbutton = elm_button_add(m_popup);
188 Evas_Object *rbutton = elm_button_add(m_popup);
189 if (!lbutton || !rbutton) {
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,
202 case PopupType::WIDGET_FEATURE_INFO:
203 elm_object_text_set(lbutton, INFO_LEFT_BUTTON);
204 elm_object_text_set(rbutton, INFO_RIGHT_BUTTON);
207 elm_object_text_set(lbutton, WARNING_LEFT_BUTTON);
208 elm_object_text_set(rbutton, WARNING_RIGHT_BUTTON);
212 elm_object_part_content_set(m_popup, "button1", lbutton);
213 evas_object_smart_callback_add(lbutton,
217 elm_object_part_content_set(m_popup, "button2", rbutton);
218 evas_object_smart_callback_add(rbutton,
224 bool WidgetInstallPopup::createPopup()
226 bool ret = addWin(name);
230 evas_object_show(m_win);
234 evas_object_del(m_win);
242 void WidgetInstallPopup::destroyPopup()
245 evas_object_del(m_win);
251 void WidgetInstallPopup::loadPopup(PopupType type, const std::string &label)
254 addContent(type, label);
258 void WidgetInstallPopup::showPopup()
260 evas_object_show(m_popup);
263 void WidgetInstallPopup::userPermitCallback(void * data,
264 Evas_Object */*obj*/,
265 void */*event_info*/)
267 WidgetInstallPopup *This = static_cast<WidgetInstallPopup *>(data);
268 This->m_installCancel = WRT_POPUP_BUTTON_OK;
269 This->m_installContext.job->Resume();
272 void WidgetInstallPopup::userCancelCallback(void *data,
273 Evas_Object */*obj*/,
274 void */*event_info*/)
276 WidgetInstallPopup *This = static_cast<WidgetInstallPopup *>(data);
277 This->m_installCancel = WRT_POPUP_BUTTON_CANCEL;
278 This->m_installContext.job->Resume();