Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnBaseForm.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        PhnBaseForm.cpp
19  * @brief       Base class for all Call forms
20  */
21 #include "PhnActiveCallForm.h"
22 #include "PhnBaseForm.h"
23 #include "PhnCallInfo.h"
24 #include "PhnCallPresentationModel.h"
25 #include "PhnConfCallerListForm.h"
26 #include "PhnPhoneFormFactory.h"
27 #include "PhnSceneRegister.h"
28 #include "PhnPhoneApp.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Scenes;
36 using namespace Tizen::Ui::Controls;
37
38 BaseForm::BaseForm(FormType formType)
39                 : __formType(formType)
40 {
41         __pCallPresentor = null;
42         __pErrorMsgPopup = null;
43 }
44
45 BaseForm::~BaseForm(void)
46 {
47 }
48
49 result
50 BaseForm::OnInitializing(void)
51 {
52         AddOrientationEventListener(*this);
53         //To be implemented in sub classes
54         return E_SUCCESS;
55 }
56
57 void
58 BaseForm::OnActionPerformed(const Control& source, int actionId)
59 {
60 }
61
62 /////////////////////////////////////////////////////////////////
63 /////  Event Listener methods from ITelephonyEventListener  /////
64 /////////////////////////////////////////////////////////////////
65
66 void
67 BaseForm::HandleCallConnected(IListT<CallInfo>& pCallList)
68 {
69         SceneManager* pSceneManager = SceneManager::GetInstance();
70
71         switch (__formType)
72         {
73         case FORMTYPE_OUTGOINGCALL:
74         case FORMTYPE_INCOMINGCALL:
75         case FORMTYPE_CONFCALLLIST:
76         case FORMTYPE_ACTIVECALL:
77         case FORMTYPE_ACTIVECONFCALL:
78         {
79                 int noOfCalls = pCallList.GetCount();
80                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
81                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
82                 pCallInfoList->Construct(noOfCalls);
83
84                 for (int index = 0; index < noOfCalls; index++)
85                 {
86                         //fetch call info and add to list
87                         CallInfo callInfo;
88                         result r = pCallList.GetAt(index, callInfo);
89                         if (r == E_SUCCESS)
90                         {
91                                 //copy call information to new instance
92                                 CallInfo* pCaller = new (std::nothrow) CallInfo();
93                                 *pCaller = callInfo;
94                                 pCallInfoList->Add(pCaller);
95                         }
96                 }
97
98                 if (noOfCalls == 1)
99                 {
100                         //Check if active call is conference call
101                         CallInfo* pActiveCallInfo = static_cast<CallInfo*>(pCallInfoList->GetAt(0));
102                         if(pActiveCallInfo->IsConferenceCall() == true)
103                         {
104                                 //single Conference call - goto active Conf. call form
105                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallInfoList);
106                         }
107                         else
108                         {
109                                 //single active call - goto active call form
110                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL), pCallInfoList);
111                         }
112                 }
113                 else if(noOfCalls == 2)
114                 {
115                         //goto multiple active call form
116                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL), pCallInfoList);
117                 }
118         }
119         break;
120
121         case FORMTYPE_EMERGENCYOUTGOINGCALL:
122         {
123                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
124                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
125                 pCallInfoList->Construct(1);
126
127                 //fetch call info and add to list
128                 CallInfo callInfo;
129                 result r = pCallList.GetAt(0, callInfo);
130                 if (r == E_SUCCESS)
131                 {
132                         //copy call information to new instance
133                         CallInfo* pCaller = new (std::nothrow) CallInfo();
134                         *pCaller = callInfo;
135                         pCallInfoList->Add(pCaller);
136                         //single active call - goto active call form
137                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVE_EMERGENCYCALL), pCallInfoList);
138                 }
139         }
140         break;
141
142         default:
143                 break;
144         }
145 }
146
147 void
148 BaseForm::HandleCallDisconnected(bool isLastCall, IListT<CallInfo>& pCallList)
149 {
150         SceneManager* pSceneManager = SceneManager::GetInstance();
151         PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
152
153         int callCount = pCallList.GetCount();
154         if (callCount > 0)
155         {
156                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
157                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
158                 pCallInfoList->Construct(callCount);
159                 for (int index = 0; index < callCount; index++)
160                 {
161                         //fetch call info and add to list
162                         CallInfo callInfo;
163                         result r = pCallList.GetAt(index, callInfo);
164                         if (r == E_SUCCESS)
165                         {
166                                 //copy call information to new instance
167                                 CallInfo* pCaller = new (std::nothrow) CallInfo();
168                                 *pCaller = callInfo;
169                                 pCallInfoList->Add(pCaller);
170                         }
171                 }
172                 if (callCount == 1)
173                 {
174                         //fetch call info and add to list
175                         CallInfo callInfo;
176                         result r = pCallList.GetAt(0, callInfo);
177                         if (r == E_SUCCESS)
178                         {
179                                 //copy call information to new instance
180                                 CallInfo* pCaller = new (std::nothrow) CallInfo();
181                                 *pCaller = callInfo;
182                                 pCallInfoList->Add(pCaller);
183                         }
184
185                         if (isLastCall == true)
186                         {
187                                 //goto End Call form if single call. else go to dialer
188                                 SceneId nextSceneId = pPhoneApp->GetInitialScene();
189                                 if (callInfo.IsConferenceCall() == false)
190                                 {
191                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ENDCALL), pCallInfoList);
192                                 }
193                                 else if (nextSceneId == IDSCN_DIALER || nextSceneId == IDSCN_CALL_LOG)
194                                 {
195                                         pSceneManager->GoForward( ForwardSceneTransition(nextSceneId, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
196                                                         SCENE_HISTORY_OPTION_NO_HISTORY));
197                                         pCallInfoList->RemoveAll();
198                                         delete pCallInfoList;
199                                         pCallInfoList = null;
200                                 }
201                                 else
202                                 {
203                                         pPhoneApp->Terminate();
204                                 }
205                         }
206                         else
207                         {
208                                 if (pCallList.GetCount() == 1)
209                                 {
210                                         if (callInfo.IsConferenceCall() == true)
211                                         {
212                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallInfoList);
213                                         }
214                                         else
215                                         {
216                                                 //goto Single Active Call form
217                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL), pCallInfoList);
218                                         }
219                                 }
220                         }
221                 }
222                 else
223                 {
224                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL), pCallInfoList);
225                 }
226         }
227         else
228         {
229                 SceneId nextSceneId = pPhoneApp->GetInitialScene();
230                 //No more calls are active
231                 if (nextSceneId == IDSCN_DIALER || nextSceneId == IDSCN_CALL_LOG)
232                 {
233                         pSceneManager->GoForward( ForwardSceneTransition(nextSceneId, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
234                                 SCENE_HISTORY_OPTION_NO_HISTORY));
235                 }
236                 else
237                 {
238                         pPhoneApp->Terminate();
239                 }
240         }
241 }
242
243
244 void
245 BaseForm::HandleConferenceCall(CallInfo& pCallInfo)
246 {
247         SceneManager* pSceneManager = SceneManager::GetInstance();
248
249         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
250         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
251         pCallInfoList->Construct(1);
252
253         //update list to be passed
254         CallInfo* pConfInfo = new (std::nothrow) CallInfo();
255         *pConfInfo = pCallInfo;
256         pCallInfoList->Add(pConfInfo);
257
258         //Todo: create screens for single conf call and conf call with another held call
259         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallInfoList);
260 }
261
262 void
263 BaseForm::HandleIncomingCall(CallInfo& pCallInfo)
264 {
265         SceneManager* pSceneManager = SceneManager::GetInstance();
266
267         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
268         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
269         pCallInfoList->Construct(1);
270
271         //update list to be passed
272         CallInfo* pIncomingCall = new (std::nothrow) CallInfo();
273         *pIncomingCall = pCallInfo;
274         pCallInfoList->Add(pIncomingCall);
275
276         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), pCallInfoList);
277 }
278
279 void
280 BaseForm::HandleCallSwapOccured(IListT<CallInfo>& pCallList)
281 {
282         int noOfCalls = pCallList.GetCount();
283         if(noOfCalls <= 0)
284         {
285                 return;
286         }
287
288         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
289         pCallInfoList->Construct(noOfCalls);
290
291         for (int index = 0; index < noOfCalls; index++)
292         {
293                 //fetch call info and add to list
294                 CallInfo callInfo;
295                 result r = pCallList.GetAt(index, callInfo);
296                 if (r == E_SUCCESS)
297                 {
298                         //copy call information to new instance
299                         CallInfo* pCallInfo = new (std::nothrow) CallInfo();
300                         *pCallInfo = callInfo;
301                         pCallInfoList->Add(pCallInfo);
302                 }
303         }
304
305         if (__formType == FORMTYPE_MULTIPLECALLS)
306         {
307                 ActiveCallForm* pActiveForm = dynamic_cast<ActiveCallForm*>(this);
308                 if(pActiveForm != null)
309                 {
310                         pActiveForm->HandleCallSwapN(pCallInfoList);
311                 }
312         }
313 }
314
315 void
316 BaseForm::HandleConferenceChange(void)
317 {
318         if (__formType == FORMTYPE_CONFCALLLIST)
319         {
320                 ConfCallerListForm* pConfCallerListForm = dynamic_cast<ConfCallerListForm*>(this);
321                 if(pConfCallerListForm != null)
322                 {
323                         pConfCallerListForm->HandleCallChange();
324                 }
325         }
326
327 }
328
329 void
330 BaseForm::HandleTelephonyError(int errorCode)
331 {
332         //show error msg Popup
333         if (__pErrorMsgPopup == null)
334         {
335                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
336         }
337         __pErrorMsgPopup->ShowErrorMsgPopupN(errorCode);
338 }
339
340 void
341 BaseForm::HandlePopupClosed(void)
342 {
343         Draw();
344         delete __pErrorMsgPopup;
345         __pErrorMsgPopup = null;
346
347         SceneManager* pSceneManager = SceneManager::GetInstance();
348         switch(__formType)
349         {
350         case FORMTYPE_OUTGOINGCALL:
351         {
352                 //fetch no of calls from telephony
353                 CallPresentationModel* pPresentor = CallPresentationModel::GetInstance();
354                 if(pPresentor != null)
355                 {
356                         //check if any call is present
357                         if(pPresentor->GetCurrentCallCount() > 0)
358                         {
359                                 //fetch current call list
360                                 IListT<CallInfo>* pCurrentCallList = pPresentor->GetCallListN();
361                                 HandleCallDisconnected(false,*pCurrentCallList);
362                                 delete pCurrentCallList;
363                                 pCurrentCallList = null;
364                         }
365                         else
366                         {
367                                 //No more calls are active
368                                 PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
369                                 SceneId nextSceneId = pPhoneApp->GetInitialScene();
370                                 if (nextSceneId == IDSCN_DIALER || nextSceneId == IDSCN_CALL_LOG)
371                                 {
372                                         pSceneManager->GoForward( ForwardSceneTransition(nextSceneId, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
373                                                 SCENE_HISTORY_OPTION_NO_HISTORY));
374                                 }
375                                 else
376                                 {
377                                         PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
378                                         pPhoneApp->Terminate();
379                                 }
380                         }
381                 }
382         }
383         break;
384
385         case FORMTYPE_ENDCALL:
386         {
387                 //It comes here, only when we make voice call for Last call from EndCallForm
388                 //and some TAPI error is encountered.
389                 PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
390                 pPhoneApp->Terminate();
391         }
392         break;
393
394         default:
395         break;
396         }
397 }
398
399 void
400 BaseForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
401 {
402         SetOrientation(ORIENTATION_PORTRAIT);
403 }
404