-/*\r
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-/**\r
- * @file view_logic_certificate_origin_support.cpp\r
- * @author Leerang Song (leerang.song@samsung.com)\r
- * @version 1.0\r
- * @brief Support certificate dao\r
- */\r
-\r
-#include "view_logic_certificate_support.h"\r
-\r
-#include <memory>\r
-#include <Evas.h>\r
-#include <Elementary.h>\r
-#include <vconf.h>\r
-#include <dpl/log/log.h>\r
-#include <dpl/assert.h>\r
-#include <dpl/wrt-dao-ro/common_dao_types.h>\r
-#include <dpl/wrt-dao-ro/vconf_config.h>\r
-#include <wrt-commons/certificate-dao/certificate_dao.h>\r
-#include <widget_model.h>\r
-\r
-namespace ViewModule {\r
-namespace {\r
-const char* const DAEMON_EDJ_PATH = "/usr/share/edje/wrt/Daemon.edj";\r
-}\r
-\r
-class CertificateSupportImplementation\r
-{\r
- private:\r
- WidgetModel* m_model;\r
- CertificateDB::CertificateDAOPtr m_certificateDAO;\r
-\r
- public:\r
- CertificateSupportImplementation(WidgetModel* widgetModel) :\r
- m_model(NULL)\r
- {\r
- Assert(widgetModel);\r
- m_model = widgetModel;\r
- }\r
-\r
- ~CertificateSupportImplementation()\r
- {}\r
-\r
- CertificateDB::CertificateDAO* getCertificateDAO(void)\r
- {\r
- Assert(m_model);\r
- if (!m_certificateDAO) {\r
- LogDebug("initialize CertificateDAO");\r
- m_certificateDAO =\r
- CertificateDB::CertificateDAOPtr(\r
- new CertificateDB::CertificateDAO(m_model->TzPkgId.\r
- Get()));\r
- // initialize certificate result data. Remove allow, deny for\r
- m_certificateDAO->removeCertificateData(\r
- CertificateDB::RESULT_ALLOW_ONCE);\r
- m_certificateDAO->removeCertificateData(\r
- CertificateDB::RESULT_DENY_ONCE);\r
- }\r
- return m_certificateDAO.get();\r
- }\r
-};\r
-\r
-CertificateSupport::CertificateSupport(WidgetModel* widgetModel) :\r
- m_impl(new CertificateSupportImplementation(widgetModel))\r
-{}\r
-\r
-CertificateSupport::~CertificateSupport()\r
-{}\r
-\r
-CertificateDB::CertificateDAO* CertificateSupport::\r
- getCertificateDAO(void)\r
-{\r
- return m_impl->getCertificateDAO();\r
-}\r
-\r
-Evas_Object* CertificateSupportUtil::createPopup(\r
- Evas_Object* window,\r
- const char* bodyText,\r
- const char* checkText,\r
- Evas_Smart_Cb\r
- buttonCallback,\r
- void* data)\r
-{\r
- LogDebug("createPopup");\r
- Evas_Object* popup = elm_popup_add(window);\r
-\r
- Evas_Object* label = elm_label_add(popup);\r
- elm_object_style_set(label, "popup/default");\r
- elm_label_line_wrap_set(label, ELM_WRAP_MIXED);\r
- elm_object_text_set(label, bodyText);\r
- evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);\r
- evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
- evas_object_show(label);\r
-\r
- Evas_Object* layout = elm_layout_add(popup);\r
- elm_layout_file_set(layout, DAEMON_EDJ_PATH, "popupWithCheck");\r
- evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
-\r
- Evas_Object* check = elm_check_add(popup);\r
- evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
- evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
- evas_object_show(check);\r
-\r
- elm_object_part_text_set(layout, "elm.text", checkText);\r
- elm_object_part_content_set(layout, "elm.swallow.content", label);\r
- elm_object_part_content_set(layout, "elm.swallow.end", check);\r
-\r
- evas_object_show(layout);\r
- elm_object_content_set(popup, layout);\r
- Evas_Object* btn1 = elm_button_add(popup);\r
- elm_object_text_set(btn1, "YES");\r
- elm_object_part_content_set(popup, "button1", btn1);\r
- evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);\r
- Evas_Object* btn2 = elm_button_add(popup);\r
- elm_object_text_set(btn2, "NO");\r
- elm_object_part_content_set(popup, "button2", btn2);\r
- evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);\r
- return popup;\r
-}\r
-\r
-Evas_Object* CertificateSupportUtil::getPopup(Evas_Object* button)\r
-{\r
- Assert(button);\r
-\r
- Evas_Object* popup = button;\r
- while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {\r
- popup = elm_object_parent_widget_get(popup);\r
- if (!popup) {\r
- return NULL;\r
- }\r
- }\r
- return popup;\r
-}\r
-\r
-Evas_Object* CertificateSupportUtil::getCheck(Evas_Object* popup)\r
-{\r
- Assert(popup);\r
- if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {\r
- return NULL;\r
- }\r
- Evas_Object* check = elm_object_part_content_get(\r
- elm_object_content_get(popup),\r
- "elm.swallow.end");\r
- return check;\r
-}\r
-\r
-CertificateDB::Result CertificateSupportUtil::getResult(\r
- Evas_Object* button)\r
-{\r
- using namespace CertificateDB;\r
-\r
- Assert(button);\r
- // get popup evas_object\r
- Evas_Object* popup = getPopup(button);\r
- if (popup == NULL) {\r
- return RESULT_UNKNOWN;\r
- }\r
- bool allow = !strcmp("YES", elm_object_text_get(button));\r
-\r
- // get check evas_object\r
- Evas_Object* check = getCheck(popup);\r
- if (check == NULL) {\r
- return RESULT_UNKNOWN;\r
- }\r
- if (allow) {\r
- return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS :\r
- RESULT_ALLOW_ONCE;\r
- } else {\r
- return elm_check_state_get(check) ? RESULT_DENY_ALWAYS :\r
- RESULT_DENY_ONCE;\r
- }\r
-}\r
-} // namespace ViewModule\r
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file view_logic_certificate_origin_support.cpp
+ * @author Leerang Song (leerang.song@samsung.com)
+ * @version 1.0
+ * @brief Support certificate dao
+ */
+
+#include "view_logic_certificate_support.h"
+
+#include <memory>
+#include <Evas.h>
+#include <Elementary.h>
+#include <efl_assist.h>
+#include <dpl/log/log.h>
+#include <dpl/log/secure_log.h>
+#include <dpl/unused.h>
+#include <dpl/assert.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <wrt-commons/certificate-dao/certificate_dao.h>
+#include <widget_model.h>
+#include <widget_string.h>
+#include <common/view_logic_get_parent_window_util.h>
+
+namespace ViewModule {
+namespace {
+const double MAX_POPUP_HEIGHT = 0.80;
+const double MAX_SCROLLER_HEIGHT = 0.5;
+
+struct CallbackData {
+ Evas_Smart_Cb eaKeyCallback;
+};
+
+static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
+static void resizeCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
+
+static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
+{
+ _D("called");
+
+ Assert(obj);
+
+ DPL_UNUSED_PARAM(e);
+ DPL_UNUSED_PARAM(eventInfo);
+
+ CallbackData* callbackData = static_cast<CallbackData*>(data);
+ if (callbackData) {
+ ea_object_event_callback_del(obj, EA_CALLBACK_BACK, callbackData->eaKeyCallback);
+ delete callbackData;
+ }
+ evas_object_event_callback_del(obj, EVAS_CALLBACK_RESIZE, resizeCallback);
+}
+
+static void resizeCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
+{
+ _D("called");
+
+ Assert(obj);
+
+ DPL_UNUSED_PARAM(data);
+ DPL_UNUSED_PARAM(e);
+ DPL_UNUSED_PARAM(eventInfo);
+
+ Evas_Object* popup = obj;
+ int popupH;
+ evas_object_geometry_get(popup, 0, 0, 0, &popupH);
+
+ Evas_Object* parent = PopupUtil::getParentWindow(popup);
+ int parentW, parentH;
+ evas_object_geometry_get(parent, 0, 0, &parentW, &parentH);
+
+ // compare current popup height with screen height.
+ // To avoid popup is filled full screen, used magic number to be filled 80% of screen height.
+ // TODO: Automatically add scroller feature should implement in the elementary
+ double threshold = parentH * MAX_POPUP_HEIGHT;
+ double currentH = popupH;
+ if (threshold < currentH) {
+ _D("text is overflow popup height. add scroller");
+ Evas_Object* layout = elm_object_content_get(obj);
+ Evas_Object* label = elm_object_part_content_get(layout, "elm.swallow.label");
+
+ Evas_Object* scroller = elm_scroller_add(layout);
+ elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_AUTO);
+ evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_scroller_content_min_limit(scroller, EINA_TRUE, EINA_TRUE);
+ int scrollerHeight = parentW > parentH ? parentH : parentW;
+ evas_object_size_hint_max_set(scroller, -1, scrollerHeight * MAX_SCROLLER_HEIGHT);
+
+ elm_object_part_content_unset(layout, "elm.swallow.label");
+ elm_object_content_set(scroller, label);
+ elm_object_part_content_set(layout, "elm.swallow.label", scroller);
+ evas_object_show(layout);
+ }
+}
+}
+
+class CertificateSupportImplementation
+{
+ private:
+ WidgetModel* m_model;
+ CertificateDB::CertificateDAOPtr m_certificateDAO;
+
+ public:
+ CertificateSupportImplementation(WidgetModel* widgetModel) :
+ m_model(NULL)
+ {
+ Assert(widgetModel);
+ m_model = widgetModel;
+ }
+
+ ~CertificateSupportImplementation()
+ {}
+
+ CertificateDB::CertificateDAO* getCertificateDAO(void)
+ {
+ Assert(m_model);
+ if (!m_certificateDAO) {
+ LogDebug("initialize CertificateDAO");
+ m_certificateDAO =
+ CertificateDB::CertificateDAOPtr(
+ new CertificateDB::CertificateDAO(m_model->TzPkgId.
+ Get()));
+ // initialize certificate result data. Remove allow, deny for
+ m_certificateDAO->removeCertificateData(
+ CertificateDB::RESULT_ALLOW_ONCE);
+ m_certificateDAO->removeCertificateData(
+ CertificateDB::RESULT_DENY_ONCE);
+ }
+ return m_certificateDAO.get();
+ }
+};
+
+CertificateSupport::CertificateSupport(WidgetModel* widgetModel) :
+ m_impl(new CertificateSupportImplementation(widgetModel))
+{}
+
+CertificateSupport::~CertificateSupport()
+{}
+
+CertificateDB::CertificateDAO* CertificateSupport::
+ getCertificateDAO(void)
+{
+ return m_impl->getCertificateDAO();
+}
+
+Evas_Object* CertificateSupportUtil::createPopup(
+ Evas_Object* window,
+ const char* bodyText,
+ const char* checkText,
+ Evas_Smart_Cb buttonCallback,
+ Evas_Smart_Cb keyCallback,
+ void* data)
+{
+ LogDebug("createPopup");
+
+ Evas_Object* parentWindow = PopupUtil::getParentWindow(window);
+ Evas_Object* popup = elm_popup_add(parentWindow);
+
+ CallbackData* callbackData = NULL;
+ if (keyCallback) {
+ callbackData = new CallbackData;
+ callbackData->eaKeyCallback = keyCallback;
+ ea_object_event_callback_add(popup, EA_CALLBACK_BACK, keyCallback, data);
+ }
+ evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, deleteCallback, static_cast<void*>(callbackData));
+ evas_object_event_callback_add(popup, EVAS_CALLBACK_RESIZE, resizeCallback, NULL);
+
+ elm_object_style_set(popup, "popup/default");
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ Evas_Object* layout = elm_layout_add(popup);
+ elm_layout_file_set(layout, WRT_EDJ_PATH, "popupWithCheck");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ Evas_Object* label = elm_label_add(popup);
+ elm_label_line_wrap_set(label, ELM_WRAP_WORD);
+ elm_object_text_set(label, bodyText);
+ evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ Evas_Object* check = elm_check_add(layout);
+ elm_object_text_set(check, checkText);
+
+ elm_object_part_content_set(layout, "elm.swallow.label", label);
+ elm_object_part_content_set(layout, "elm.swallow.checkbox", check);
+ elm_object_content_set(popup, layout);
+
+ Evas_Object* btn1 = elm_button_add(popup);
+ elm_object_text_set(btn1, WRT_OPT_ALLOW);
+ elm_object_part_content_set(popup, "button1", btn1);
+ evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);
+ Evas_Object* btn2 = elm_button_add(popup);
+ elm_object_text_set(btn2, WRT_SK_CANCEL);
+ elm_object_part_content_set(popup, "button2", btn2);
+ evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);
+
+ return popup;
+}
+
+Evas_Object* CertificateSupportUtil::getPopup(Evas_Object* button)
+{
+ Assert(button);
+
+ Evas_Object* popup = button;
+ while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
+ popup = elm_object_parent_widget_get(popup);
+ if (!popup) {
+ return NULL;
+ }
+ }
+ return popup;
+}
+
+Evas_Object* CertificateSupportUtil::getCheck(Evas_Object* popup)
+{
+ Assert(popup);
+ if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
+ return NULL;
+ }
+ Evas_Object* check = elm_object_part_content_get(
+ elm_object_content_get(popup),
+ "elm.swallow.checkbox");
+ return check;
+}
+
+CertificateDB::Result CertificateSupportUtil::getResult(
+ Evas_Object* button)
+{
+ using namespace CertificateDB;
+
+ Assert(button);
+ // get popup evas_object
+ Evas_Object* popup = getPopup(button);
+ if (popup == NULL) {
+ return RESULT_UNKNOWN;
+ }
+ bool allow = !strcmp(WRT_OPT_ALLOW, elm_object_text_get(button));
+
+ // get check evas_object
+ Evas_Object* check = getCheck(popup);
+ if (check == NULL) {
+ return RESULT_UNKNOWN;
+ }
+ if (allow) {
+ return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS :
+ RESULT_ALLOW_ONCE;
+ } else {
+ return elm_check_state_get(check) ? RESULT_DENY_ALWAYS :
+ RESULT_DENY_ONCE;
+ }
+}
+} // namespace ViewModule