Add answerable interface for popups 09/122209/11
authorZofia Abramowska <z.abramowska@samsung.com>
Mon, 3 Apr 2017 17:44:56 +0000 (19:44 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Mon, 3 Apr 2017 17:44:56 +0000 (19:44 +0200)
Add class for evaluating answers from popups (with buttons
and with or without checkbox).

Change-Id: I88cdf10ede966a8de1510284432b8563abc1e180

src/agent/notification-daemon/ui/Answerable.h [new file with mode: 0644]

diff --git a/src/agent/notification-daemon/ui/Answerable.h b/src/agent/notification-daemon/ui/Answerable.h
new file mode 100644 (file)
index 0000000..f610d70
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co.
+ *
+ *  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        src/agent/notification-daemon/ui/Answerable.h
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief       Implementation Answerable button pressed events classes
+ */
+#pragma once
+
+#include "PopupCheck.h"
+#include "Popup.h"
+
+#include <types/NotificationResponse.h>
+
+namespace AskUser {
+namespace Notification {
+
+class IAnswerable {
+public:
+    enum class Button {
+        ALLOW,
+        DENY
+    };
+    typedef std::function<void(int, NResponseType)> AnswerHandler;
+
+    IAnswerable(AnswerHandler handler) : m_handler(handler) {}
+    virtual void process(enum Button) const = 0;
+    virtual ~IAnswerable() {}
+protected:
+    AnswerHandler m_handler;
+};
+
+class AnswerablePopupCheck : public IAnswerable {
+public:
+    AnswerablePopupCheck(PopupCheck *popup, AnswerHandler handler)
+        : IAnswerable(handler), m_popup(popup) {}
+    virtual void process(enum Button button) const {
+        NResponseType answer;
+        switch (button) {
+        case IAnswerable::Button::ALLOW:
+            if (m_popup->getCheckboxState())
+                answer = NResponseType::AllowAlways;
+            else
+                answer = NResponseType::Allow;
+            break;
+        case IAnswerable::Button::DENY:
+            if (m_popup->getCheckboxState())
+                answer = NResponseType::DenyAlways;
+            else
+                answer = NResponseType::Deny;
+            break;
+        default:
+            answer = NResponseType::Error;
+        }
+        m_handler(m_popup->getId(), answer);
+    }
+private:
+    PopupCheck *m_popup;
+};
+
+class AnswerablePopupLaunch : public IAnswerable {
+public:
+    AnswerablePopupLaunch(Popup *popup, AnswerHandler handler)
+        : IAnswerable(handler), m_popup(popup) {}
+    virtual void process(enum Button button) const {
+        NResponseType answer;
+        switch (button) {
+        case IAnswerable::Button::ALLOW:
+            answer = NResponseType::AllowAlways;
+            break;
+        case IAnswerable::Button::DENY:
+            answer = NResponseType::DenyAlways;
+            break;
+        default:
+            answer = NResponseType::Error;
+        }
+        m_handler(m_popup->getId(), answer);
+    }
+private:
+    Popup *m_popup;
+};
+
+} // namespace AskUser
+} // namespace Notification