Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnSettingsBarringPwdForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 /**
18  * @file    PhnSettingsBarringPwdForm.cpp
19  * @brief   Call Baring Password form
20  */
21 #include <FApp.h>
22 #include "PhnAppUtility.h"
23 #include "PhnSettingsBarringPwdForm.h"
24 #include "PhnSettingsConstants.h"
25 #include "PhnSettingsPresentationModel.h"
26 #include "PhnSceneRegister.h"
27 #include "PhnTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37 static const wchar_t* IDL_SETTINGS_SET_BARRING_PWD__FORM = L"IDL_SETTINGS_SET_BARRING_PWD__FORM";
38
39 SettingsBarringPwdForm::SettingsBarringPwdForm(void)
40                 : __pErrorMsgPopup(null)
41 {
42 }
43
44 SettingsBarringPwdForm::~SettingsBarringPwdForm(void)
45 {
46 }
47
48 void
49 SettingsBarringPwdForm::Initialize(void)
50 {
51         Construct(IDL_SETTINGS_SET_BARRING_PWD__FORM);
52 }
53
54 result
55 SettingsBarringPwdForm::OnInitializing(void)
56 {
57         result r = E_SUCCESS;
58
59         //Initialize Header
60         InitializeHeader();
61         //Initialize reject message editArea
62         EditField* pSetPwd = static_cast<EditField*>(GetControl(IDC_EDITFIELD));
63         if (pSetPwd != null)
64         {
65                 pSetPwd->AddTextEventListener(*this);
66                 pSetPwd->SetFocus();
67                 pSetPwd->SetOverlayKeypadCommandButtonVisible(false);
68                 pSetPwd->ShowKeypad();
69         }
70         return r;
71 }
72
73 void
74 SettingsBarringPwdForm::InitializeHeader(void)
75 {
76         Header* pHeader = GetHeader();
77         if (pHeader != null)
78         {
79                 //TODO: get correct icons.
80                 //'Save' item
81                 String saveItemName;
82                 saveItemName.Append(AppUtility::GetResourceString(IDS_SETTING_SAVE_HEADER_ITEM));
83                 ButtonItem saveHeaderItem;
84                 saveHeaderItem.Construct(BUTTON_ITEM_STYLE_TEXT, IDA_SAVE_HEADER_ITEMID);
85                 saveHeaderItem.SetText(saveItemName);
86                 pHeader->SetButton(BUTTON_POSITION_LEFT, saveHeaderItem);
87                 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
88
89                 //'Cancel' item
90                 Bitmap* pNormalBmp = AppUtility::GetBitmapFromResourcesN(IDB_CANCEL_FOOTER_ITEM, W_HDR_FTR_ICON, H_HDR_FTR_ICON);
91                 ButtonItem cancelHeaderItem;
92                 cancelHeaderItem.Construct(BUTTON_ITEM_STYLE_ICON, IDA_CANCEL_HEADER_ITEMID);
93                 cancelHeaderItem.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pNormalBmp);
94                 cancelHeaderItem.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pNormalBmp);
95                 pHeader->SetButton(BUTTON_POSITION_RIGHT, cancelHeaderItem);
96                 delete pNormalBmp;
97
98                 pHeader->AddActionEventListener(*this);
99         }
100 }
101
102 result
103 SettingsBarringPwdForm::OnTerminating(void)
104 {
105         result r = E_SUCCESS;
106         return r;
107 }
108
109 void
110 SettingsBarringPwdForm::OnActionPerformed(const Control& source, int actionId)
111 {
112         SceneManager* pSceneManager = SceneManager::GetInstance();
113         AppAssert(pSceneManager != null);
114
115         switch (actionId)
116         {
117         case IDA_CANCEL_HEADER_ITEMID:
118         {
119         }
120         break;
121
122         case IDA_SAVE_HEADER_ITEMID:
123         {
124                 //save call barring settings
125                 EditField* pSetPwd = static_cast<EditField*>(GetControl(IDC_EDITFIELD));
126                 if (pSetPwd != null)
127                 {
128                         SettingsPresentationModel* pPresentor = SettingsPresentationModel::GetInstance();
129                         String password = pSetPwd->GetText();
130                         //set call barring status
131                         int errorCode = pPresentor->SetCallBarringStatus(password, __callBarringCondition, __conditionState);
132                         if(errorCode != ERROR_NONE)
133                         {
134                                 ShowErrorMessage(errorCode);
135                                 return;
136                         }
137                         else
138                         {
139                                 if(__conditionState == false)
140                                 {
141                                         if(__callBarringCondition == CALL_BARRING_ALL_OUTGOING)
142                                         {
143                                                 pPresentor->SetCallBarringStatus(password, CALL_BARRING_INTERNATIONAL_OUTGOING, false);
144                                                 pPresentor->SetCallBarringStatus(password, CALL_BARRING_INTERNATIONAL_EXCEPT_HOME, false);
145                                         }
146                                         if(__callBarringCondition == CALL_BARRING_ALL_INCOMING)
147                                         {
148                                                 pPresentor->SetCallBarringStatus(password, CALL_BARRING_INCOMING_ROAMING, false);
149
150                                         }
151                                 }
152                         }
153
154                 }
155         }
156         break;
157
158         default:
159                 break;
160         }
161         //switch back to previous form
162         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALL_BARRING_OPTIONS), null);
163 }
164
165 void
166 SettingsBarringPwdForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
167 {
168         if (pArgs != null)
169         {
170                 Integer* pIndexInt = static_cast<Integer*>(pArgs->GetAt(0));
171                 switch (pIndexInt->ToInt())
172                 {
173                 case 0:
174                 {
175                         __callBarringCondition = CALL_BARRING_ALL_OUTGOING;
176                 }
177                 break;
178
179                 case 1:
180                 {
181                         __callBarringCondition = CALL_BARRING_INTERNATIONAL_OUTGOING;
182                 }
183                 break;
184
185                 case 2:
186                 {
187                         __callBarringCondition = CALL_BARRING_INTERNATIONAL_EXCEPT_HOME;
188                 }
189                 break;
190
191                 case 3:
192                 {
193                         __callBarringCondition = CALL_BARRING_ALL_INCOMING;
194                 }
195                 break;
196
197                 case 4:
198                 {
199                         __callBarringCondition = CALL_BARRING_INCOMING_ROAMING;
200                 }
201                 break;
202
203                 default:
204                         break;
205                 }
206
207                 Integer* pItemState = static_cast<Integer*>(pArgs->GetAt(1));
208                 if (pItemState->ToInt() == LIST_ITEM_STATUS_CHECKED)
209                 {
210                         __conditionState = true;
211                 }
212                 else
213                 {
214                         __conditionState = false;
215                 }
216
217                 //Clear edit field and disable "save"
218                 EditField* pSetPwd = static_cast<EditField*>(GetControl(IDC_EDITFIELD));
219                 if (pSetPwd != null)
220                 {
221                         pSetPwd->Clear();
222                         pSetPwd->SetFocus();
223                         pSetPwd->Invalidate(true);
224                 }
225                 Header* pHeader = GetHeader();
226                 if (pHeader != null)
227                 {
228                         pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
229                         pHeader->Invalidate(true);
230                 }
231
232                 pArgs->RemoveAll();
233                 delete pArgs;
234                 pArgs = null;
235         }
236 }
237
238 void
239 SettingsBarringPwdForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
240 {
241         EditField* pSetPwd = static_cast<EditField*>(GetControl(IDC_EDITFIELD));
242         if (pSetPwd != null)
243         {
244                 pSetPwd->HideKeypad();
245         }
246 }
247
248 void
249 SettingsBarringPwdForm::OnTextValueChanged(const Control& source)
250 {
251         int textLen = -1;
252         EditField* pSetPwd = static_cast<EditField*>(GetControl(IDC_EDITFIELD));
253         Header* pHeader = GetHeader();
254         if (pSetPwd != null && pHeader != null)
255         {
256                 textLen = pSetPwd->GetTextLength();
257                 if (textLen > 0)
258                 {
259                         //Enable save button
260                         pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
261                 }
262                 else
263                 {
264                         //disable
265                         pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
266                 }
267                 pHeader->Invalidate(true);
268         }
269 }
270
271 void
272 SettingsBarringPwdForm::OnTextValueChangeCanceled(const Control& source)
273 {
274         Header* pHeader = GetHeader();
275         if (pHeader != null)
276         {
277                 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
278                 pHeader->Invalidate(true);
279         }
280 }
281
282 void
283 SettingsBarringPwdForm::ShowErrorMessage(int errorCode)
284 {
285         //show error msg Popup
286         if (__pErrorMsgPopup == null)
287         {
288                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
289         }
290         __pErrorMsgPopup->ShowErrorMsgPopupN(errorCode);
291 }
292
293 void
294 SettingsBarringPwdForm::HandlePopupClosed(void)
295 {
296         Draw();
297         delete __pErrorMsgPopup;
298         __pErrorMsgPopup = null;
299         return;
300 }