Apply string localization for authentication popup
[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 <FUiLayout.h>
32 #include <FUiVerticalBoxLayout.h>
33 #include <FWebCtrlAuthenticationChallenge.h>
34 #include <FSys_SystemResource.h>
35 #include <FSys_VibratorImpl.h>
36 #include <FUi_ControlManager.h>
37 #include <FUi_ResourceManager.h>
38 #include "FWebCtrl_WebImpl.h"
39 #include "FWebCtrl_AuthConfirmPopup.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 static const int AUTH_POPUP_TMP_LABLE_HEIGHT = 10;
51
52
53 namespace Tizen { namespace Web { namespace Controls
54 {
55
56
57 _AuthConfirmPopup::_AuthConfirmPopup(void)
58         : __pIdEditField(null)
59         , __pPwdEditField(null)
60         , __pAuthHandler(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, AuthenticationChallenge* pAuth)
73 {
74         SysTryReturnResult(NID_WEB_CTRL, pAuth != null, E_INVALID_ARG, "invalid argument(s) is used. The AuthenticationChallenge is null.");
75
76         __pAuthHandler = pAuth;
77
78         _SystemResource* pSysResource = _SystemResource::GetInstance();
79         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
80
81         result r = E_SUCCESS;
82         _WebPopupData* pPopupData = _WebPopup::GetPopupData();
83         SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
84
85         Rectangle rect(0, 0, 0, 0);
86         rect.width = pPopupData->popupDim.width;
87         rect.height = (5*pPopupData->spacePad) + (pPopupData->editDim.height*2) + pPopupData->btnDim.height + (2*pPopupData->labelDim.height);
88         r = _WebPopup::Construct(true, Dimension(rect.width, rect.height));
89         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
90
91         SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_DESTINATIONS_AUTHENTICATION_REQUIRED"));
92
93         //host realm label
94         rect.height = 2*pPopupData->labelDim.height;
95
96         std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
97         SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
98
99         String hostRealm(host);
100         hostRealm.Append(L": \n ");
101         hostRealm.Append(realm);
102         hostRealm.Append(L"\"");
103         r = pLabel->Construct(rect, hostRealm);
104         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
105
106         pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
107
108         r = AddControl(*pLabel);
109         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
110
111         Label* pHostLabel = pLabel.release();
112
113         // Id Edit Field
114         rect.x = 0;
115         rect.y = 0;
116         rect.height = pPopupData->editDim.height;
117         rect.width = pPopupData->labelDim.width;
118
119         std::unique_ptr<EditField> pIdEditField(new (std::nothrow) EditField());
120         SysTryReturnResult(NID_WEB_CTRL, pIdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
121
122         r = pIdEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
123         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124
125         pIdEditField->SetGuideText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_AUTHUSERNAME"));
126         pIdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
127         pIdEditField->SetTextSize(35);;
128
129         r = AddControl(*pIdEditField);
130         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
131
132         __pIdEditField = pIdEditField.release();
133
134         std::unique_ptr<EditField> pPwdEditField(new (std::nothrow) EditField());
135         SysTryReturnResult(NID_WEB_CTRL, pPwdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
136
137         r = pPwdEditField->Construct(rect, EDIT_FIELD_STYLE_PASSWORD);
138         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
139
140         pPwdEditField->SetGuideText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_AUTHPASSWORD"));
141         pPwdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
142         pPwdEditField->SetTextSize(35);;
143
144         r = AddControl(*pPwdEditField);
145         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
146
147         __pPwdEditField = pPwdEditField.release();
148         __pIdEditField->SetFocus();
149
150         Panel* pButtonPanel = CreateAndAddPanel();
151         SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
152
153         //Add Buttons
154         ArrayList idList;
155         r = idList.Construct();
156         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157         idList.Add(*(new Integer(ID_BUTTON_AUTH_PROCESS)));
158         idList.Add(*(new Integer(ID_BUTTON_AUTH_CANCEL)));
159
160         ArrayList titleList;
161         r = titleList.Construct();
162         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
163         titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_COM_BUTTON_LOGIN"))));
164         titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_COM_SK_CANCEL"))));
165
166         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
167         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
168
169         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
170         SysTryReturn(NID_WEB_CTRL, pLayout.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
171
172         pLayout->SetHorizontalAlignment(*pHostLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
173         pLayout->SetHorizontalAlignment(*__pIdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
174         pLayout->SetHorizontalAlignment(*__pPwdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
175         pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
176
177         pLayout->SetSpacing(*__pPwdEditField, pPopupData->spacePad);
178         pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
179
180         return E_SUCCESS;
181 }
182
183
184 void
185 _AuthConfirmPopup::OnActionPerformed(const Control& source, int actionId)
186 {
187         result r = E_SUCCESS;
188
189         switch (actionId)
190         {
191         case ID_BUTTON_AUTH_PROCESS:
192                 __pAuthHandler->Process(__pIdEditField->GetText(), __pPwdEditField->GetText());
193                 break;
194
195         case ID_BUTTON_AUTH_CANCEL:
196                 __pAuthHandler->Cancel();
197                 break;
198
199         default:
200                 break;
201         }
202
203         r = HidePopup();
204         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
205 }
206
207
208 }}} // Tizen::Web::Controls