patch for rc20
[framework/osp/web.git] / src / controls / FWebCtrl_AuthConfirmPopup.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWebCtrl_AuthConfirmPopup.cpp
20  * @brief               The file contains the definition of _AuthConfirmPopup class.
21  */
22 #include <FBaseColArrayList.h>
23 #include <FBaseSysLog.h>
24 #include <FGrpDimension.h>
25 #include <FGrpRectangle.h>
26 #include <FSysVibrator.h>
27 #include <FUiCtrlButton.h>
28 #include <FUiCtrlEditField.h>
29 #include <FUiCtrlLabel.h>
30 #include <FUiCtrlPanel.h>
31 #include <FUiKeyEventInfo.h>
32 #include <FUiLayout.h>
33 #include <FUiVerticalBoxLayout.h>
34 #include <FSys_SystemResource.h>
35 #include <FSys_VibratorImpl.h>
36 #include <FUi_ControlManager.h>
37 #include <FUi_ResourceManager.h>
38 #include "FWebCtrl_AuthConfirmPopup.h"
39 #include "FWebCtrl_WebImpl.h"
40
41
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Collection;
44 using namespace Tizen::Graphics;
45 using namespace Tizen::System;
46 using namespace Tizen::Ui;
47 using namespace Tizen::Ui::Controls;
48
49
50 namespace Tizen { namespace Web { namespace Controls
51 {
52
53
54 static const int EDIT_TEXT_SIZE = 35;
55
56
57 _AuthConfirmPopup::_AuthConfirmPopup(void)
58         : __pIdEditField(null)
59         , __pPwdEditField(null)
60         , __pImpl(null)
61 {
62 }
63
64
65 _AuthConfirmPopup::~_AuthConfirmPopup(void)
66 {
67 }
68
69
70 // Authentication popup
71 result
72 _AuthConfirmPopup::Construct(const String& host, const String& realm, _WebImpl* pImpl)
73 {
74         __pImpl = pImpl;
75         SysAssertf(__pImpl != null, "Failed to get _WebImpl");
76
77         _SystemResource* pSysResource = _SystemResource::GetInstance();
78         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
79
80         result r = E_SUCCESS;
81         _WebPopupData* pPopupData = _WebPopup::GetPopupData();
82         SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
83
84         Rectangle rect(0, 0, 0, 0);
85         rect.width = pPopupData->popupDim.width;
86         rect.height = (2*pPopupData->spacePad) + (pPopupData->editDim.height*2) + pPopupData->panelHeight + (2*pPopupData->labelDim.height);
87         r = _WebPopup::Construct(true, Dimension(rect.width, rect.height));
88         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
89
90         SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_HEADER_ENTER_CREDENTIALS_ABB"));
91
92         //host realm label
93         rect.height = 2*pPopupData->labelDim.height;
94
95         std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
96         SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
97
98         String hostRealm(host);
99         hostRealm.Append(L": \n ");
100         hostRealm.Append(realm);
101         r = pLabel->Construct(rect, hostRealm);
102         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
103
104         pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
105
106         r = AddControl(*pLabel);
107         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
108
109         Label* pHostLabel = pLabel.release();
110
111         // Id Edit Field
112         rect.x = 0;
113         rect.y = 0;
114         rect.height = pPopupData->editDim.height;
115         rect.width = pPopupData->labelDim.width;
116
117         std::unique_ptr<EditField> pIdEditField(new (std::nothrow) EditField());
118         SysTryReturnResult(NID_WEB_CTRL, pIdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
119
120         r = pIdEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
121         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
122
123         pIdEditField->SetGuideText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_WIFI_BODY_ENTER_YOUR_ID"));
124         pIdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
125         pIdEditField->SetTextSize(EDIT_TEXT_SIZE);;
126
127         r = AddControl(*pIdEditField);
128         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
129
130         __pIdEditField = pIdEditField.release();
131
132         std::unique_ptr<EditField> pPwdEditField(new (std::nothrow) EditField());
133         SysTryReturnResult(NID_WEB_CTRL, pPwdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
134
135         r = pPwdEditField->Construct(rect, EDIT_FIELD_STYLE_PASSWORD);
136         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
137
138         pPwdEditField->SetGuideText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BODY_ENTER_YOUR_PASSWORD_ABB"));
139         pPwdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
140         pPwdEditField->SetTextSize(EDIT_TEXT_SIZE);;
141
142         r = AddControl(*pPwdEditField);
143         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
144
145         __pPwdEditField = pPwdEditField.release();
146
147         __pIdEditField->SetFocus();
148
149         Panel* pButtonPanel = CreateAndAddPanel();
150         SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
151
152         //Add Buttons
153         ArrayList idList(SingleObjectDeleter);
154         r = idList.Construct();
155         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
156
157         idList.Add(new Integer(ID_BUTTON_AUTH_CANCEL));
158         idList.Add(new Integer(ID_BUTTON_AUTH_PROCESS));
159
160
161         ArrayList titleList(SingleObjectDeleter);
162         r = titleList.Construct();
163         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
164         titleList.Add(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CANCEL_ABB")));
165         titleList.Add(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CONTINUE_ABB")));
166
167         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
168         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
169
170         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
171         SysTryReturn(NID_WEB_CTRL, pLayout.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
172
173         pLayout->SetHorizontalAlignment(*pHostLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
174         pLayout->SetHorizontalAlignment(*__pIdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
175         pLayout->SetHorizontalAlignment(*__pPwdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
176
177         pLayout->SetSpacing(*__pPwdEditField, pPopupData->spacePad);
178         pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
179
180         SetPropagatedKeyEventListener(this);
181
182         return E_SUCCESS;
183 }
184
185
186 void
187 _AuthConfirmPopup::OnActionPerformed(const Control& source, int actionId)
188 {
189         result r = E_SUCCESS;
190
191         r = HidePopup();
192         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
193
194         ArrayList* pAuthValueList = null;
195
196         switch (actionId)
197         {
198         case ID_BUTTON_AUTH_PROCESS:
199
200                 pAuthValueList = new (std::nothrow) ArrayList();
201                 pAuthValueList->Construct();
202                 pAuthValueList->Add(new String(__pIdEditField->GetText()));
203                 pAuthValueList->Add(new String(__pPwdEditField->GetText()));
204                 __pImpl->SendUserEvent(ID_AUTHENTICATION_CONFIRM_POPUP_PROCESS, pAuthValueList);
205                 break;
206
207         case ID_BUTTON_AUTH_CANCEL:
208                 __pImpl->SendUserEvent(ID_AUTHENTICATION_CONFIRM_POPUP_CANCEL, null);
209                 break;
210
211         default:
212                 break;
213         }
214 }
215
216 bool
217 _AuthConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
218 {
219         return false;
220 }
221
222 bool
223 _AuthConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
224 {
225         result r = E_SUCCESS;
226         if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
227         {
228                 r = HidePopup();
229                 if (IsFailed(r))
230                 {
231                         SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
232                 }
233
234                 __pImpl->SendUserEvent(ID_AUTHENTICATION_CONFIRM_POPUP_CANCEL, null);
235         }
236
237         return false;
238 }
239
240 bool
241 _AuthConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
242 {
243         return false;
244 }
245
246 bool
247 _AuthConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
248 {
249         return false;
250 }
251
252 bool
253 _AuthConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
254 {
255         return false;
256 }
257
258
259 }}} // Tizen::Web::Controls