Fix for N_SE-48378 N_SE-48015
[apps/osp/Call.git] / src / CallErrorMsgPopup.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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    CallErrorMsgPopup.cpp
19  * @brief       Error message pop class
20  */
21 #include <FGraphics.h>
22 #include "CallAppUtility.h"
23 #include "CallErrorMsgPopup.h"
24 #include "CallTypes.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*>(GetLandscapeLayoutN());
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         relPopUpLayout = static_cast<RelativeLayout*>(GetPortraitLayoutN());
102         if(relPopUpLayout != null)
103         {
104                 // Set Relations between msgtextbox and Popup
105                 relPopUpLayout->SetCenterAligned(*pMsgTxtBox, CENTER_ALIGN_HORIZONTAL);
106                 relPopUpLayout->SetCenterAligned(*pMsgTxtBox, CENTER_ALIGN_VERTICAL);
107         }
108         //construct timer
109         __pTimer = new (std::nothrow) Timer();
110         __pTimer->Construct(*this);
111 }
112
113 void
114 ErrorMsgPopup::ShowErrorMsgPopupN(int errorCode)
115 {
116         //Construct the message popup
117         ConstructPopup(errorCode);
118         //Show popup message
119         ShowPopup();
120 }
121
122 void
123 ErrorMsgPopup::ShowPopup(void)
124 {
125         __popupModalResult = 0;
126         //start timer to show popup
127         __pTimer->Start(2000);
128         SetShowState(true);
129         Show();
130 }
131
132 void
133 ErrorMsgPopup::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
134 {
135         //Call default implementation of "Object.Equals()"
136         //returns true, if they are pointing to same address.
137         if (__pTimer->Equals(timer))
138         {
139                 SetShowState(false);
140                 //notify the listener
141                 __pEventListener->HandlePopupClosed();
142         }
143 }
144
145 String
146 ErrorMsgPopup::FetchErrorMessage(int errorCode)
147 {
148         String msg(L"");
149         switch (errorCode)
150         {
151         case ERROR_NONE:
152                 break;
153
154         case ERROR_DIAL_FAILED:
155         {
156                 msg.Append(AppUtility::GetResourceString(IDS_DIAL_ERROR_MSG));
157         }
158         break;
159
160         case ERROR_JOIN_FAILED:
161         {
162                 msg.Append(AppUtility::GetResourceString(IDS_JOIN_FAILED_ERROR_MSG));
163         }
164         break;
165
166         case ERROR_REJECT_FAILED:
167         {
168                 msg.Append(AppUtility::GetResourceString(IDS_REJECT_FAILED_ERROR_MSG));
169         }
170         break;
171
172         case ERROR_SWAP_FAILED:
173         {
174                 msg.Append(AppUtility::GetResourceString(IDS_CALL_SWAP_ERROR_MSG));
175         }
176         break;
177
178         case ERROR_END_FROM_CONFERENCE_FAILED:
179         {
180                 msg.Append(AppUtility::GetResourceString(IDS_END_PARTICIPANT_ERROR_MSG));
181         }
182         break;
183
184         case ERROR_SPLIT_FROM_CONFERENCE_FAILED:
185         {
186                 msg.Append(AppUtility::GetResourceString(IDS_SPLIT_PARTICIPANT_ERROR_MSG));
187         }
188         break;
189
190         case ERROR_CODE_SIM_INITIALIZATION_FAILED:
191         {
192                 msg.Append(AppUtility::GetResourceString(IDS_SIM_INIT_ERROR_MSG));
193         }
194         break;
195
196         case ERROR_NOT_EMERGENCY_NUM:
197         {
198                 msg.Append(AppUtility::GetResourceString(IDS_EMERGENCY_CALLS_ONLY_ERROR_MSG));
199         }
200         break;
201
202         case ERROR_INVALID_INPUT:
203         {
204                 msg.Append(AppUtility::GetResourceString(IDS_INVALID_ARGS_ERROR_MSG));
205         }
206         break;
207
208         case ERROR_TAPI_INIT_FAILED:
209         {
210                 msg.Append(AppUtility::GetResourceString(IDS_TAPI_INIT_ERROR_MSG));
211         }
212         break;
213
214         case ERROR_TAPI_ERROR:
215         {
216                 msg.Append(AppUtility::GetResourceString(IDS_GENERAL_TAPI_ERROR_MSG));
217         }
218         break;
219
220         case ERROR_BARRING_PWD_TOO_LONG:
221         {
222                 msg.Append(AppUtility::GetResourceString(IDS_LONG_BARRING_PWD_ERROR_MSG));
223         }
224         break;
225
226         case ERROR_INVALID_NUMBER:
227         {
228                 msg.Append(AppUtility::GetResourceString(IDS_INVALID_NUMBER_ERROR_MSG));
229         }
230         break;
231
232         case ERROR_FLIGHT_MODE_SET:
233         {
234                 msg.Append(AppUtility::GetResourceString(IDS_FLIGHT_MODE_ON));
235         }
236         break;
237
238         case ERROR_USSD_NUMBER:
239         {
240                 msg.Append(AppUtility::GetResourceString(IDS_USSD_NUMBER));
241         }
242         break;
243
244         case ERROR_GENERAL:
245         default:
246         {
247                 msg.Append(AppUtility::GetResourceString(IDS_GENERAL_ERROR_MSG));
248         }
249         break;
250         }
251
252         return msg;
253 }
254
255