Source code formating unification
[platform/framework/web/wrt.git] / src / domain / widget_data_types.cpp
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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  * This file  have been implemented in compliance with  W3C WARP SPEC.
18  * but there are some patent issue between  W3C WARP SPEC and APPLE.
19  * so if you want to use this file, refer to the README file in root directory
20  */
21 /**
22  * @file       widget_data_types.cpp
23  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
24  * @author     Tomasz Iwanek (t.iwanek@samsung.com) (implementation moved to
25  * cpp)
26  * @version    0.1
27  * @brief
28  */
29
30 #include <widget_data_types.h>
31
32 #include <dpl/foreach.h>
33
34 WidgetAccessList::WidgetAccessList() : m_isAccessAll(false)
35 {}
36
37 WidgetAccessList::WidgetAccessList(
38     const WrtDB::WidgetAccessInfoList &widgetAccessInfoList) :
39     m_isAccessAll(false)
40 {
41     FOREACH(it, widgetAccessInfoList)
42     {
43         if (DPL::FromUTF32String(L"*") == it->strIRI) {
44             m_isAccessAll = true;
45             m_warpIriList.clear();
46             return;
47         }
48
49         WarpIRI warpIri;
50
51         warpIri.set(DPL::ToUTF8String(it->strIRI).c_str(),
52                     it->bSubDomains);
53
54         if (warpIri.isAccessDefinition()) {
55             m_warpIriList.push_back(warpIri);
56         }
57     }
58 }
59
60 bool WidgetAccessList::getIsAccessAll() const
61 {
62     return m_isAccessAll;
63 }
64
65 const WarpIRIList* WidgetAccessList::getWarpIRIList() const
66 {
67     return &m_warpIriList;
68 }
69
70 bool WidgetAccessList::isRequiredIRI(const DPL::String &iri) const
71 {
72     if (m_isAccessAll) {
73         return true;
74     }
75
76     WarpIRI requestIri;
77     requestIri.set(iri.c_str(), false);
78
79     FOREACH(it, m_warpIriList)
80     {
81         if (it->isSubDomain(requestIri)) {
82             return true;
83         }
84     }
85
86     return false;
87 }
88
89 bool WidgetAccessList::operator ==(const WidgetAccessList& other) const
90 {
91     return m_warpIriList == other.m_warpIriList &&
92            m_isAccessAll == other.m_isAccessAll;
93 }
94
95 WidgetSettingList::WidgetSettingList() :
96     m_RotationLock(Screen_Portrait),
97     m_IndicatorPresence(Indicator_Enable),
98     m_BackButtonPresence(BackButton_Disable),
99     m_ContextMenu(ContextMenu_Enable),
100     m_Encryption(Encryption_Disable),
101     m_BackgroundSupport(BackgroundSupport_Disable)
102 {}
103
104 WidgetSettingList::WidgetSettingList(WidgetSettings &widgetSettings)
105 {
106     m_RotationLock = Screen_Portrait;
107     m_IndicatorPresence = Indicator_Enable;
108     m_BackButtonPresence = BackButton_Disable;
109     m_ContextMenu = ContextMenu_Enable;
110     m_Encryption = Encryption_Disable;
111     m_BackgroundSupport = BackgroundSupport_Disable;
112
113     FOREACH(it, widgetSettings)
114     {
115         DPL::String name = it->settingName;
116         DPL::String value = it->settingValue;
117
118         if (name == SETTING_NAME_SCREEN_ORIENTATION) {
119             if (value == SETTING_VALUE_SCREEN_ORIENTATION_PORTRAIT) {
120                 m_RotationLock = Screen_Portrait;
121             } else if (value ==
122                        SETTING_VALUE_SCREEN_ORIENTATION_LANDSCAPE)
123             {
124                 m_RotationLock = Screen_Landscape;
125             } else {
126                 LogError("Invalid screen orientation value!! [" <<
127                          value << "]");
128                 m_RotationLock = Screen_Portrait;
129             }
130         } else if (name == SETTING_NAME_INDICATOR_PRESENCE) {
131             if (value == SETTING_VALUE_INDICATOR_PRESENCE_ENALBE) {
132                 m_IndicatorPresence = Indicator_Enable;
133             } else if (value == SETTING_VALUE_INDICATOR_PRESENCE_DISABLE) {
134                 m_IndicatorPresence = Indicator_Disable;
135             } else {
136                 LogError("Invalid indicator presence value!! [" <<
137                          value << "]");
138                 m_IndicatorPresence = Indicator_Enable;
139             }
140         } else if (name == SETTING_NAME_BACKBUTTON_PRESENCE) {
141             if (value == SETTING_VALUE_BACKBUTTON_PRESENCE_ENALBE) {
142                 m_BackButtonPresence = BackButton_Enable;
143             } else if (value ==
144                        SETTING_VALUE_BACKBUTTON_PRESENCE_DISABLE)
145             {
146                 m_BackButtonPresence = BackButton_Disable;
147             } else {
148                 LogError("Invalid backbutton presence value!! [" <<
149                          value << "]");
150                 m_BackButtonPresence = BackButton_Disable;
151             }
152         } else if (name == SETTING_NAME_CONTEXT_MENU
153 #ifndef DEPRECATED_SETTING_STRING
154                    || name == SETTING_NAME_CONTEXTMENU
155 #endif
156                    )
157         {
158             if (value == SETTING_VALUE_ENABLE) {
159                 m_ContextMenu = ContextMenu_Enable;
160             } else if (value == SETTING_VALUE_DISABLE) {
161                 m_ContextMenu = ContextMenu_Disable;
162             } else {
163                 LogError("Invalid contextmenu value!! [" <<
164                          value << "]");
165                 m_ContextMenu = ContextMenu_Enable;
166             }
167         } else if (name == SETTING_NAME_ENCRYPTION) {
168             if (value == SETTING_VALUE_ENCRYPTION_ENABLE) {
169                 m_Encryption = Encryption_Enable;
170             } else if (value ==
171                        SETTING_VALUE_ENCRYPTION_DISABLE)
172             {
173                 m_Encryption = Encryption_Disable;
174             } else {
175                 LogError("Invalid encryption value!! [" <<
176                          value << "]");
177                 m_Encryption = Encryption_Disable;
178             }
179         } else if (name == SETTING_NAME_BACKGROUND_SUPPORT) {
180             if (value == SETTING_VALUE_ENABLE) {
181                 m_BackgroundSupport = BackgroundSupport_Enable;
182             } else if (value == SETTING_VALUE_DISABLE) {
183                 m_BackgroundSupport = BackgroundSupport_Disable;
184             } else {
185                 LogError("Invalid background-support value!! [" <<
186                          value << "]");
187                 m_BackgroundSupport = BackgroundSupport_Disable;
188             }
189         } else if (name == SETTING_NAME_USER_AGENT) {
190             DPL::OptionalString userAgent = value;
191             if (!userAgent.IsNull()) {
192                 m_UserAgent = DPL::ToUTF8String(*userAgent);
193             }
194         } else {
195             LogError("Invalid setting name!! [" << name << "]");
196         }
197     }
198     LogDebug("m_RotationLock: " << m_RotationLock);
199     LogDebug("m_IndicatorPresence: " << m_IndicatorPresence);
200     LogDebug("m_BackButtonPresence: " << m_BackButtonPresence);
201     LogDebug("m_ContextMenu: " << m_ContextMenu);
202     LogDebug("m_Encryption: " << m_Encryption);
203     LogDebug("m_BackgroundSupport: " << m_BackgroundSupport);
204 }
205
206 WidgetSettingScreenLock WidgetSettingList::getRotationValue() const
207 {
208     return m_RotationLock;
209 }
210
211 WidgetSettingIndicatorPresence WidgetSettingList::getIndicatorPresence() const
212 {
213     return m_IndicatorPresence;
214 }
215
216 WidgetSettingBackButtonPresence WidgetSettingList::getBackButtonPresence()
217 const
218 {
219     return m_BackButtonPresence;
220 }
221
222 WidgetSettingContextMenu WidgetSettingList::getContextMenu() const
223 {
224     return m_ContextMenu;
225 }
226
227 WidgetSettingEncryption WidgetSettingList::getEncryption() const
228 {
229     return m_Encryption;
230 }
231
232 WidgetSettingBackgroundSupport WidgetSettingList::getBackgroundSupport() const
233 {
234     return m_BackgroundSupport;
235 }
236
237 bool WidgetSettingList::isEncrypted() const
238 {
239     if (m_Encryption == Encryption_Enable) {
240         return true;
241     }
242     return false;
243 }
244
245 std::string WidgetSettingList::getUserAgent() const
246 {
247     return m_UserAgent;
248 }
249
250 bool WidgetSettingList::operator ==(const WidgetSettingList& other) const
251 {
252     return m_RotationLock == other.m_RotationLock &&
253            m_IndicatorPresence == other.m_IndicatorPresence &&
254            m_BackButtonPresence == other.m_BackButtonPresence &&
255            m_ContextMenu == other.m_ContextMenu &&
256            m_Encryption == other.m_Encryption &&
257            m_BackgroundSupport == other.m_BackgroundSupport &&
258            m_UserAgent == other.m_UserAgent;
259 }