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 view_logic_certificate_origin_support.cpp
18 * @author Leerang Song (leerang.song@samsung.com)
20 * @brief Support certificate dao
23 #include "view_logic_certificate_support.h"
27 #include <Elementary.h>
28 #include <efl_assist.h>
29 #include <dpl/log/log.h>
30 #include <dpl/log/secure_log.h>
31 #include <dpl/unused.h>
32 #include <dpl/assert.h>
33 #include <dpl/wrt-dao-ro/common_dao_types.h>
34 #include <wrt-commons/certificate-dao/certificate_dao.h>
35 #include <widget_model.h>
36 #include <widget_string.h>
37 #include <common/view_logic_get_parent_window_util.h>
39 namespace ViewModule {
41 const double MAX_POPUP_HEIGHT = 0.80;
42 const double MAX_SCROLLER_HEIGHT = 0.5;
45 Evas_Smart_Cb eaKeyCallback;
48 static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
49 static void resizeCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
51 static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
58 DPL_UNUSED_PARAM(eventInfo);
60 CallbackData* callbackData = static_cast<CallbackData*>(data);
62 ea_object_event_callback_del(obj, EA_CALLBACK_BACK, callbackData->eaKeyCallback);
65 evas_object_event_callback_del(obj, EVAS_CALLBACK_RESIZE, resizeCallback);
68 static void resizeCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
74 DPL_UNUSED_PARAM(data);
76 DPL_UNUSED_PARAM(eventInfo);
78 Evas_Object* popup = obj;
80 evas_object_geometry_get(popup, 0, 0, 0, &popupH);
82 Evas_Object* parent = PopupUtil::getParentWindow(popup);
84 evas_object_geometry_get(parent, 0, 0, &parentW, &parentH);
86 // compare current popup height with screen height.
87 // To avoid popup is filled full screen, used magic number to be filled 80% of screen height.
88 // TODO: Automatically add scroller feature should implement in the elementary
89 double threshold = parentH * MAX_POPUP_HEIGHT;
90 double currentH = popupH;
91 if (threshold < currentH) {
92 _D("text is overflow popup height. add scroller");
93 Evas_Object* layout = elm_object_content_get(obj);
94 Evas_Object* label = elm_object_part_content_get(layout, "elm.swallow.label");
96 Evas_Object* scroller = elm_scroller_add(layout);
97 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_AUTO);
98 evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99 evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
100 elm_scroller_content_min_limit(scroller, EINA_TRUE, EINA_TRUE);
101 int scrollerHeight = parentW > parentH ? parentH : parentW;
102 evas_object_size_hint_max_set(scroller, -1, scrollerHeight * MAX_SCROLLER_HEIGHT);
104 elm_object_part_content_unset(layout, "elm.swallow.label");
105 elm_object_content_set(scroller, label);
106 elm_object_part_content_set(layout, "elm.swallow.label", scroller);
107 evas_object_show(layout);
112 class CertificateSupportImplementation
115 WidgetModel* m_model;
116 CertificateDB::CertificateDAOPtr m_certificateDAO;
119 CertificateSupportImplementation(WidgetModel* widgetModel) :
123 m_model = widgetModel;
126 ~CertificateSupportImplementation()
129 CertificateDB::CertificateDAO* getCertificateDAO(void)
132 if (!m_certificateDAO) {
133 LogDebug("initialize CertificateDAO");
135 CertificateDB::CertificateDAOPtr(
136 new CertificateDB::CertificateDAO(m_model->TzPkgId.
138 // initialize certificate result data. Remove allow, deny for
139 m_certificateDAO->removeCertificateData(
140 CertificateDB::RESULT_ALLOW_ONCE);
141 m_certificateDAO->removeCertificateData(
142 CertificateDB::RESULT_DENY_ONCE);
144 return m_certificateDAO.get();
148 CertificateSupport::CertificateSupport(WidgetModel* widgetModel) :
149 m_impl(new CertificateSupportImplementation(widgetModel))
152 CertificateSupport::~CertificateSupport()
155 CertificateDB::CertificateDAO* CertificateSupport::
156 getCertificateDAO(void)
158 return m_impl->getCertificateDAO();
161 Evas_Object* CertificateSupportUtil::createPopup(
163 const char* bodyText,
164 const char* checkText,
165 Evas_Smart_Cb buttonCallback,
166 Evas_Smart_Cb keyCallback,
169 LogDebug("createPopup");
171 Evas_Object* parentWindow = PopupUtil::getParentWindow(window);
172 Evas_Object* popup = elm_popup_add(parentWindow);
174 CallbackData* callbackData = NULL;
176 callbackData = new CallbackData;
177 callbackData->eaKeyCallback = keyCallback;
178 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, keyCallback, data);
180 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, deleteCallback, static_cast<void*>(callbackData));
181 evas_object_event_callback_add(popup, EVAS_CALLBACK_RESIZE, resizeCallback, NULL);
183 elm_object_style_set(popup, "popup/default");
184 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
185 evas_object_size_hint_align_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
187 Evas_Object* layout = elm_layout_add(popup);
188 elm_layout_file_set(layout, WRT_EDJ_PATH, "popupWithCheck");
189 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
190 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
192 Evas_Object* label = elm_label_add(popup);
193 elm_label_line_wrap_set(label, ELM_WRAP_WORD);
194 elm_object_text_set(label, bodyText);
195 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
196 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
198 Evas_Object* check = elm_check_add(layout);
199 elm_object_text_set(check, checkText);
201 elm_object_part_content_set(layout, "elm.swallow.label", label);
202 elm_object_part_content_set(layout, "elm.swallow.checkbox", check);
203 elm_object_content_set(popup, layout);
205 Evas_Object* btn1 = elm_button_add(popup);
206 elm_object_text_set(btn1, WRT_OPT_ALLOW);
207 elm_object_part_content_set(popup, "button1", btn1);
208 evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);
209 Evas_Object* btn2 = elm_button_add(popup);
210 elm_object_text_set(btn2, WRT_SK_CANCEL);
211 elm_object_part_content_set(popup, "button2", btn2);
212 evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);
217 Evas_Object* CertificateSupportUtil::getPopup(Evas_Object* button)
221 Evas_Object* popup = button;
222 while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
223 popup = elm_object_parent_widget_get(popup);
231 Evas_Object* CertificateSupportUtil::getCheck(Evas_Object* popup)
234 if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
237 Evas_Object* check = elm_object_part_content_get(
238 elm_object_content_get(popup),
239 "elm.swallow.checkbox");
243 CertificateDB::Result CertificateSupportUtil::getResult(
246 using namespace CertificateDB;
249 // get popup evas_object
250 Evas_Object* popup = getPopup(button);
252 return RESULT_UNKNOWN;
254 bool allow = !strcmp(WRT_OPT_ALLOW, elm_object_text_get(button));
256 // get check evas_object
257 Evas_Object* check = getCheck(popup);
259 return RESULT_UNKNOWN;
262 return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS :
265 return elm_check_state_get(check) ? RESULT_DENY_ALWAYS :
269 } // namespace ViewModule