Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnErrorMsgPopup.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    PhnErrorMsgPopup.cpp
19  * @brief       Error message pop class
20  */
21 #include <FGraphics.h>
22 #include "PhnAppUtility.h"
23 #include "PhnErrorMsgPopup.h"
24 #include "PhnTypes.h"
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Ui;
28 using namespace Tizen::Ui::Controls;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Base::Utility;
31 using namespace Tizen::Base::Runtime;
32
33 const int IDI_VERTICAL_LINE_SPACING = 20;
34 const int W_ERROR_MSG_POPUP = 720;
35 const int IDI_VERTICAL_MARGIN = 39;
36 static const wchar_t* IDL_ERROR_MSG_POPUP = L"IDL_ERROR_MSG_POPUP";
37 static const wchar_t* IDC_MSG_TEXTBOX = L"IDC_MSG_TEXTBOX";
38 static const wchar_t* IDS_DIAL_ERROR_MSG = L"IDS_DIAL_ERROR_MSG";
39 static const wchar_t* IDS_JOIN_FAILED_ERROR_MSG = L"IDS_JOIN_FAILED_ERROR_MSG";
40 static const wchar_t* IDS_REJECT_FAILED_ERROR_MSG = L"IDS_REJECT_FAILED_ERROR_MSG";
41 static const wchar_t* IDS_CALL_SWAP_ERROR_MSG = L"IDS_CALL_SWAP_ERROR_MSG";
42 static const wchar_t* IDS_END_PARTICIPANT_ERROR_MSG = L"IDS_END_PARTICIPANT_ERROR_MSG";
43 static const wchar_t* IDS_SPLIT_PARTICIPANT_ERROR_MSG = L"IDS_SPLIT_PARTICIPANT_ERROR_MSG";
44 static const wchar_t* IDS_SIM_INIT_ERROR_MSG = L"IDS_SIM_INIT_ERROR_MSG";
45 static const wchar_t* IDS_EMERGENCY_CALLS_ONLY_ERROR_MSG = L"IDS_EMERGENCY_CALLS_ONLY_ERROR_MSG";
46 static const wchar_t* IDS_INVALID_ARGS_ERROR_MSG = L"IDS_INVALID_ARGS_ERROR_MSG";
47 static const wchar_t* IDS_TAPI_INIT_ERROR_MSG = L"IDS_TAPI_INIT_ERROR_MSG";
48 static const wchar_t* IDS_GENERAL_TAPI_ERROR_MSG = L"IDS_GENERAL_TAPI_ERROR_MSG";
49 static const wchar_t* IDS_LONG_BARRING_PWD_ERROR_MSG = L"IDS_LONG_BARRING_PWD_ERROR_MSG";
50 static const wchar_t* IDS_INVALID_NUMBER_ERROR_MSG = L"IDS_INVALID_NUMBER_ERROR_MSG";
51 static const wchar_t* IDS_GENERAL_ERROR_MSG = L"IDS_GENERAL_ERROR_MSG";
52
53 ErrorMsgPopup::ErrorMsgPopup(IPopupClosedEventListener* pEventListener)
54 : __pEventListener(pEventListener)
55 {
56         __pTimer = null;
57 }
58
59 ErrorMsgPopup::~ErrorMsgPopup(void)
60 {
61         if (__pTimer)
62         {
63                 __pTimer->Cancel();
64                 delete __pTimer;
65                 __pTimer = null;
66         }
67 }
68
69 void
70 ErrorMsgPopup::ConstructPopup(int errorCode)
71 {
72         Construct(IDL_ERROR_MSG_POPUP);
73         //Fetch error message
74         String msg = FetchErrorMessage(errorCode);
75
76         //Set text to Message box
77         TextBox* pMsgTxtBox = static_cast<TextBox*>(GetControl(IDC_MSG_TEXTBOX));
78         pMsgTxtBox->SetLineSpacing(1,1);
79         pMsgTxtBox->SetText(msg);
80         pMsgTxtBox->SetEnabled(false);
81         pMsgTxtBox->SetTextAlignment(ALIGNMENT_CENTER);
82
83         Rectangle msgTxtBoxRect = pMsgTxtBox->GetBounds();
84         //get no. of lines to show message
85         int noOfLines = pMsgTxtBox->GetLineCount();
86         pMsgTxtBox->SetSize(msgTxtBoxRect.width,((noOfLines * msgTxtBoxRect.height) + IDI_VERTICAL_LINE_SPACING));
87
88         Dimension popUpDimen = pMsgTxtBox->GetSize();
89         popUpDimen.width = W_ERROR_MSG_POPUP;
90         popUpDimen.height +=  (2 * IDI_VERTICAL_MARGIN);
91         SetSize(popUpDimen);
92
93         SetControlAlwaysOnTop(*pMsgTxtBox,true);
94         RelativeLayout* relPopUpLayout = static_cast<RelativeLayout*>(GetLayoutN());
95         if(relPopUpLayout != null)
96         {
97                 // Set Relations between msgtextbox and Popup
98                 relPopUpLayout->SetCenterAligned(*pMsgTxtBox, CENTER_ALIGN_HORIZONTAL);
99                 relPopUpLayout->SetCenterAligned(*pMsgTxtBox, CENTER_ALIGN_VERTICAL);
100         }
101         //construct timer
102         __pTimer = new (std::nothrow) Timer();
103         __pTimer->Construct(*this);
104 }
105
106 void
107 ErrorMsgPopup::ShowErrorMsgPopupN(int errorCode)
108 {
109         //Construct the message popup
110         ConstructPopup(errorCode);
111         //Show popup message
112         ShowPopup();
113 }
114
115 void
116 ErrorMsgPopup::ShowPopup(void)
117 {
118         __popupModalResult = 0;
119         //start timer to show popup
120         __pTimer->Start(2000);
121         SetShowState(true);
122         Show();
123 }
124
125 void
126 ErrorMsgPopup::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
127 {
128         //Call default implementation of "Object.Equals()"
129         //returns true, if they are pointing to same address.
130         if (__pTimer->Equals(timer))
131         {
132                 SetShowState(false);
133                 //notify the listener
134                 __pEventListener->HandlePopupClosed();
135         }
136 }
137
138 String
139 ErrorMsgPopup::FetchErrorMessage(int errorCode)
140 {
141         String msg(L"");
142         switch (errorCode)
143         {
144         case ERROR_NONE:
145                 break;
146
147         case ERROR_DIAL_FAILED:
148         {
149                 msg.Append(AppUtility::GetResourceString(IDS_DIAL_ERROR_MSG));
150         }
151         break;
152
153         case ERROR_JOIN_FAILED:
154         {
155                 msg.Append(AppUtility::GetResourceString(IDS_JOIN_FAILED_ERROR_MSG));
156         }
157         break;
158
159         case ERROR_REJECT_FAILED:
160         {
161                 msg.Append(AppUtility::GetResourceString(IDS_REJECT_FAILED_ERROR_MSG));
162         }
163         break;
164
165         case ERROR_SWAP_FAILED:
166         {
167                 msg.Append(AppUtility::GetResourceString(IDS_CALL_SWAP_ERROR_MSG));
168         }
169         break;
170
171         case ERROR_END_FROM_CONFERENCE_FAILED:
172         {
173                 msg.Append(AppUtility::GetResourceString(IDS_END_PARTICIPANT_ERROR_MSG));
174         }
175         break;
176
177         case ERROR_SPLIT_FROM_CONFERENCE_FAILED:
178         {
179                 msg.Append(AppUtility::GetResourceString(IDS_SPLIT_PARTICIPANT_ERROR_MSG));
180         }
181         break;
182
183         case ERROR_CODE_SIM_INITIALIZATION_FAILED:
184         {
185                 msg.Append(AppUtility::GetResourceString(IDS_SIM_INIT_ERROR_MSG));
186         }
187         break;
188
189         case ERROR_NOT_EMERGENCY_NUM:
190         {
191                 msg.Append(AppUtility::GetResourceString(IDS_EMERGENCY_CALLS_ONLY_ERROR_MSG));
192         }
193         break;
194
195         case ERROR_INVALID_INPUT:
196         {
197                 msg.Append(AppUtility::GetResourceString(IDS_INVALID_ARGS_ERROR_MSG));
198         }
199         break;
200
201         case ERROR_TAPI_INIT_FAILED:
202         {
203                 msg.Append(AppUtility::GetResourceString(IDS_TAPI_INIT_ERROR_MSG));
204         }
205         break;
206
207         case ERROR_TAPI_ERROR:
208         {
209                 msg.Append(AppUtility::GetResourceString(IDS_GENERAL_TAPI_ERROR_MSG));
210         }
211         break;
212
213         case ERROR_BARRING_PWD_TOO_LONG:
214         {
215                 msg.Append(AppUtility::GetResourceString(IDS_LONG_BARRING_PWD_ERROR_MSG));
216         }
217         break;
218
219         case ERROR_INVALID_NUMBER:
220         {
221                 msg.Append(AppUtility::GetResourceString(IDS_INVALID_NUMBER_ERROR_MSG));
222         }
223         break;
224
225         case ERROR_FLIGHT_MODE_SET:
226         {
227                 msg.Append(AppUtility::GetResourceString(IDS_FLIGHT_MODE_ON));
228         }
229         break;
230
231         case ERROR_GENERAL:
232         default:
233         {
234                 msg.Append(AppUtility::GetResourceString(IDS_GENERAL_ERROR_MSG));
235         }
236         break;
237         }
238
239         return msg;
240 }
241
242