[Custom handler] Merge popups into one
authorPrzemyslaw Ciezkowski <p.ciezkowski@samsung.com>
Fri, 14 Dec 2012 14:35:00 +0000 (15:35 +0100)
committerPrzemyslaw Ciezkowski <p.ciezkowski@samsung.com>
Mon, 17 Dec 2012 15:18:22 +0000 (16:18 +0100)
[Issue#] N/A
[Problem] Two popups are used to save user's decision.
[Cause] N/A
[Solution] Used one popup with checkbox to give a user
option to save if decision should be remembered.
Added option to block popups for WRT_TEST_MODE (for tests).
[Verification]
1. Run custom_handlers.wgt test widget. Check if option "remember" works".
2. set WRT_TEST_MODE=1. Run widget again. Check if popups are not
shown for register action.

Change-Id: I21ffacef7e615bd7aca52f4d9996cd56e708f5b8

src/view/webkit/view_logic.cpp

index ddaecf4..ca878ef 100755 (executable)
@@ -34,6 +34,7 @@
 #include <vconf.h>
 #include <widget_model.h>
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/utils/wrt_global_settings.h>
 
 #include <common/application_data.h>
 #include <common/application_launcher.h>
@@ -131,8 +132,10 @@ const char * const EWK_CONTENTHANDLER_UNREGISTRATION = "contenthandler,unregistr
 
 const char PROTOCOL_HANDLER_ASK_MSG[] = "Add protocol?";
 const char PROTOCOL_HANDLER_ASK_TITLE[] = "Add protocol";
+const char PROTOCOL_HANDLER_ASK_REMEMBER[] = "Remember dicision";
 const char CONTENT_HANDLER_ASK_MSG[] = "Add content?";
 const char CONTENT_HANDLER_ASK_TITLE[] = "Add content";
+const char CONTENT_HANDLER_AKS_REMEMBER[] = "Remember dicision";
 }
 
 ViewLogic::ViewLogic():
@@ -1777,6 +1780,37 @@ char const * const contentBlackList[contentBlackListLenth] = {
     "text/xml"
 };
 
+/**
+ * Saves user's response from popup to custom handler. Saves Yes/No and remember
+ * state.
+ * @param response
+ * @param customHandler
+ */
+void saveUserResponse(Wrt::Popup::PopupResponse response,
+        CustomHandlerDB::CustomHandlerPtr customHandler)
+{
+    switch (response) {
+        case Wrt::Popup::YES_DO_REMEMBER:
+            LogDebug("User allowed, remember");
+            customHandler->user_decision = static_cast<CustomHandlerDB::HandlerState>
+                (CustomHandlerDB::Agreed | CustomHandlerDB::DecisionSaved);
+            break;
+        case Wrt::Popup::YES_DONT_REMEMBER:
+            LogDebug("User allowed, don't remember");
+            customHandler->user_decision = CustomHandlerDB::Agreed;
+            break;
+        case Wrt::Popup::NO_DO_REMEMBER:
+            LogDebug("User didn't allow, remember");
+            customHandler->user_decision = static_cast<CustomHandlerDB::HandlerState>
+                    (CustomHandlerDB::Declined | CustomHandlerDB::DecisionSaved);
+            break;
+        case Wrt::Popup::NO_DONT_REMEMBER:
+            LogDebug("User didn't allow, don't remember");
+            customHandler->user_decision = CustomHandlerDB::Declined;
+            break;
+    }
+}
+
 //TODO registration, checking if registered and unregistration can be done in
 //common functions for both types of handlers. Only white and black lists
 //have to be separated
@@ -1838,23 +1872,13 @@ void ViewLogic::protocolHandlerRegistrationCallback(void* data,
         LogDebug("Protocol already registered - nothing to do");
     } else {
         LogDebug("Protocol handler not found");
-        if (Wrt::Popup::PopupInvoker().askYesNo(PROTOCOL_HANDLER_ASK_TITLE, PROTOCOL_HANDLER_ASK_MSG)) {
-            LogDebug("User allowed");
-            customHandler->user_decision = CustomHandlerDB::Agreed;
-        } else {
-            LogDebug("User didn't allow");
-            customHandler->user_decision = CustomHandlerDB::Declined;
-        }
-        //TODO merge to one popup
-        LogDebug("Protocol handler not found");
-        if (Wrt::Popup::PopupInvoker().askYesNo("REMEMBER", "Want to remember? ")) {
-            LogDebug("User allowed");
-            customHandler->user_decision =
-                static_cast<CustomHandlerDB::HandlerState>
-                (customHandler->user_decision | CustomHandlerDB::DecisionSaved);
-        } else {
-            LogDebug("User didn't allow");
-        }
+        Wrt::Popup::PopupResponse response =
+            GlobalSettings::PopupsTestModeEnabled() ? Wrt::Popup::YES_DO_REMEMBER :
+                Wrt::Popup::PopupInvoker().askYesNoCheckbox(
+                        PROTOCOL_HANDLER_ASK_TITLE,
+                        PROTOCOL_HANDLER_ASK_MSG,
+                        PROTOCOL_HANDLER_ASK_REMEMBER);
+        saveUserResponse(response, customHandler);
         if (customHandler->user_decision == CustomHandlerDB::Declined)
             return;
         handlersDao.registerProtocolHandler(*(customHandler.get()));
@@ -1970,23 +1994,13 @@ void ViewLogic::contentHandlerRegistrationCallback(void* data,
         LogDebug("Protocol already registered - nothing to do");
     } else {
         LogDebug("Protocol handler not found");
-        if (Wrt::Popup::PopupInvoker().askYesNo(PROTOCOL_HANDLER_ASK_TITLE, PROTOCOL_HANDLER_ASK_MSG)) {
-            LogDebug("User allowed");
-            customHandler->user_decision = CustomHandlerDB::Agreed;
-        } else {
-            LogDebug("User didn't allow");
-            customHandler->user_decision = CustomHandlerDB::Declined;
-        }
-        //TODO merge to one popup
-        LogDebug("Protocol handler not found");
-        if (Wrt::Popup::PopupInvoker().askYesNo("REMEMBER", "Want to remember? ")) {
-            LogDebug("User allowed");
-            customHandler->user_decision =
-                static_cast<CustomHandlerDB::HandlerState>
-                (customHandler->user_decision | CustomHandlerDB::DecisionSaved);
-        } else {
-            LogDebug("User didn't allow");
-        }
+        Wrt::Popup::PopupResponse response =
+            GlobalSettings::PopupsTestModeEnabled() ? Wrt::Popup::YES_DO_REMEMBER :
+                Wrt::Popup::PopupInvoker().askYesNoCheckbox(
+                        CONTENT_HANDLER_ASK_TITLE,
+                        CONTENT_HANDLER_ASK_MSG,
+                        CONTENT_HANDLER_AKS_REMEMBER);
+        saveUserResponse(response, customHandler);
         if (customHandler->user_decision == CustomHandlerDB::Declined)
             return;
         handlersDao.registerContentHandler(*(customHandler.get()));