Notify logic of popup response from popupper
[platform/core/security/askuser.git] / src / notification-daemon / ui / Answerable.h
1 /*
2  *  Copyright (c) 2017 Samsung Electronics Co.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16 /**
17  * @file        src/agent/notification-daemon/ui/Answerable.h
18  * @author      Zofia Abramowska <z.abramowska@samsung.com>
19  * @brief       Implementation Answerable button pressed events classes
20  */
21 #pragma once
22
23 #include "PopupCheck.h"
24 #include "Popup.h"
25
26 #include <types/NotificationResponse.h>
27
28 namespace AskUser {
29 namespace Notification {
30
31 class IAnswerable {
32 public:
33     enum class Button {
34         ALLOW,
35         DENY
36     };
37
38     IAnswerable() {}
39     virtual NResponseType getAnswer(enum Button) const = 0;
40     virtual ~IAnswerable() {}
41 };
42
43 class AnswerablePopupCheck : public IAnswerable {
44 public:
45     AnswerablePopupCheck(PopupCheck *popup)
46         : m_popup(popup) {}
47     virtual NResponseType getAnswer(enum Button button) const {
48         NResponseType answer;
49         switch (button) {
50         case IAnswerable::Button::ALLOW:
51             if (m_popup->getCheckboxState())
52                 answer = NResponseType::AllowAlways;
53             else
54                 answer = NResponseType::Allow;
55             break;
56         case IAnswerable::Button::DENY:
57             if (m_popup->getCheckboxState())
58                 answer = NResponseType::DenyAlways;
59             else
60                 answer = NResponseType::Deny;
61             break;
62         default:
63             answer = NResponseType::Error;
64         }
65         return answer;
66     }
67 private:
68     PopupCheck *m_popup;
69 };
70
71 } // namespace AskUser
72 } // namespace Notification