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.
16 /* @file PromptModel.cpp
17 * @author Justyna Mejzner (j.kwiatkowsk@samsung.com)
18 * @author Jaroslaw Osmanski (j.osmanski@samsung.com)
23 #include <ace-dao-ro/PromptModel.h>
26 #include <dpl/log/log.h>
27 #include <dpl/assert.h>
31 const char INFO[] = "Widget requires access to:";
32 const char DENY[] = "Deny";
33 const char ALLOW[] = "Permit";
35 const char BLANKET_CHECKBOX_LABEL[] = "Keep setting as permanent";
36 const char SESSION_CHECKBOX_LABEL[] = "Remember for one run";
38 Prompt::ButtonLabels aceQuestionLabel = {DENY, ALLOW};
40 static Prompt::PromptLabels* getModel(
41 Prompt::PromptModel::PromptType promptType,
42 const std::string& resourceId)
47 strLabel += resourceId;
49 return new Prompt::PromptLabels(promptType, aceQuestionLabel, strLabel);
52 Prompt::Validity fromPromptTypeToValidity(int aPromptType, bool checkClicked)
54 using namespace Prompt;
55 PromptModel::PromptType promptTypeEnum =
56 static_cast<PromptModel::PromptType>(aPromptType);
57 switch (promptTypeEnum) {
58 case PromptModel::PROMPT_ONESHOT:
59 return Validity::ONCE;
60 case PromptModel::PROMPT_SESSION:
63 return Validity::SESSION;
67 return Validity::ONCE;
69 case PromptModel::PROMPT_BLANKET:
72 return Validity::ALWAYS;
76 return Validity::ONCE;
80 return Validity::ONCE;
83 } // namespace anonymous
88 PromptLabels::PromptLabels(int promptType,
89 const Prompt::ButtonLabels& questionLabel,
90 const std::string& mainLabel) :
91 m_promptType(promptType),
92 m_buttonLabels(questionLabel),
93 m_mainLabel(mainLabel)
98 int PromptLabels::getPromptType() const
102 const ButtonLabels& PromptLabels::getButtonLabels() const
104 return m_buttonLabels;
106 const std::string& PromptLabels::getMainLabel() const
111 DPL::OptionalString PromptLabels::getCheckLabel() const
113 if (PromptModel::PROMPT_BLANKET == m_promptType)
115 return DPL::OptionalString(
116 DPL::FromUTF8String(BLANKET_CHECKBOX_LABEL));
118 else if (PromptModel::PROMPT_SESSION == m_promptType)
120 return DPL::OptionalString(
121 DPL::FromUTF8String(SESSION_CHECKBOX_LABEL));
124 return DPL::OptionalString();
127 bool PromptLabels::isAllowed(const size_t buttonClicked) const
129 Assert(buttonClicked < aceQuestionLabel.size() &&
130 "Button Clicked number is not in range of questionLabel");
132 return aceQuestionLabel[buttonClicked] == ALLOW;
135 PromptAnswer::PromptAnswer(bool isAccessAllowed, Validity validity) :
136 m_isAccessAllowed(isAccessAllowed),
142 PromptAnswer::PromptAnswer(
143 int aPromptType, unsigned int buttonAns, bool checkAns)
145 Assert(buttonAns < aceQuestionLabel.size() &&
146 "Button Clicked number is not in range of questionLabel");
148 m_isAccessAllowed = aceQuestionLabel[buttonAns] == ALLOW;
149 m_validity = fromPromptTypeToValidity(aPromptType, checkAns);
152 bool PromptAnswer::isAccessAllowed() const
154 return m_isAccessAllowed;
157 Validity PromptAnswer::getValidity() const
162 PromptLabels* PromptModel::getOneShotModel(const std::string& resourceId)
164 return getModel(PROMPT_ONESHOT, resourceId);
167 PromptLabels* PromptModel::getSessionModel(const std::string& resourceId)
169 return getModel(PROMPT_SESSION, resourceId);
172 PromptLabels* PromptModel::getBlanketModel(const std::string& resourceId)
174 return getModel(PROMPT_BLANKET, resourceId);