Fix for N_SE-48378 N_SE-48015
[apps/osp/Call.git] / src / CallBaseForm.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        CallBaseForm.cpp
19  * @brief       Base class for all Call forms
20  */
21 #include "CallActiveCallForm.h"
22 #include "CallIncomingCallForm.h"
23 #include "CallBaseForm.h"
24 #include "CallInfo.h"
25 #include "CallPresentationModel.h"
26 #include "CallConfCallerListForm.h"
27 #include "CallPhoneFormFactory.h"
28 #include "CallSceneRegister.h"
29 #include "CallApp.h"
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Scenes;
37 using namespace Tizen::Ui::Controls;
38
39 BaseForm::BaseForm(FormType formType)
40                 : __formType(formType)
41 {
42         __pCallPresentor = null;
43         __pErrorMsgPopup = null;
44 }
45
46 BaseForm::~BaseForm(void)
47 {
48 }
49
50 result
51 BaseForm::OnInitializing(void)
52 {
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<AppCallInfo>& pCallList)
68 {
69         if(__pCallPresentor->IsIncomingorDialingCallPresent() == true)
70         {
71                 //This scenario will come, if 1 call is disconnected from conf. call having 2 participants.
72                 //In this case, if there is any dialing call exists, then ignore.
73                 //Else, if there is any incoming call exists, then update call option popup.
74                 switch (__formType)
75                 {
76                 case FORMTYPE_INCOMINGCALL:
77                 {
78                         IncomingCallForm* pIncomingCallForm = dynamic_cast<IncomingCallForm*>(this);
79                         if (pIncomingCallForm != null)
80                         {
81                                 pIncomingCallForm->CallDisconnected();
82                         }
83                 }
84                         break;
85
86                 default:
87                         break;
88                 }
89                 return;
90         }
91
92         SceneManager* pSceneManager = SceneManager::GetInstance();
93
94         switch (__formType)
95         {
96         case FORMTYPE_OUTGOINGCALL:
97         case FORMTYPE_INCOMINGCALL:
98         case FORMTYPE_CONFCALLLIST:
99         case FORMTYPE_ACTIVECALL:
100         case FORMTYPE_ACTIVECONFCALL:
101         {
102                 int noOfCalls = pCallList.GetCount();
103                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
104                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
105                 pCallInfoList->Construct(noOfCalls);
106
107                 for (int index = 0; index < noOfCalls; index++)
108                 {
109                         //fetch call info and add to list
110                         AppCallInfo callInfo;
111                         result r = pCallList.GetAt(index, callInfo);
112                         if (r == E_SUCCESS)
113                         {
114                                 //copy call information to new instance
115                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
116                                 *pCaller = callInfo;
117                                 pCallInfoList->Add(pCaller);
118                         }
119                 }
120
121                 if (noOfCalls == 1)
122                 {
123                         //Check if active call is conference call
124                         AppCallInfo* pActiveCallInfo = static_cast<AppCallInfo*>(pCallInfoList->GetAt(0));
125                         if(pActiveCallInfo->IsConferenceCall() == true)
126                         {
127                                 //single Conference call - goto active Conf. call form
128                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL,
129                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
130                         }
131                         else
132                         {
133                                 //single active call - goto active call form
134                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL,
135                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
136                         }
137                 }
138                 else if(noOfCalls == 2)
139                 {
140                         //goto multiple active call form
141                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL,
142                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
143                 }
144         }
145         break;
146
147         case FORMTYPE_MULTIPLECALLS:
148         {
149                 //This case can come on Multiple Calls screen, when one of the calls is conference call with 2 participants
150                 //and one of the participants exits himself from ConfCall.
151                 int noOfCalls = pCallList.GetCount();
152                 AppLogDebug("Active Call Count = %d", noOfCalls);
153                 //this is just a safety check, call count will aleays be 2 here.
154                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
155                 if(noOfCalls == IDI_MAX_ACTIVE_CALLS && pActiveCallForm != null)
156                 {
157                         //update calls state
158                         pActiveCallForm->UpdateMultipleCallScreen(pCallList);
159                 }
160         }
161         break;
162
163         case FORMTYPE_EMERGENCYOUTGOINGCALL:
164         {
165                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
166                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
167                 pCallInfoList->Construct(1);
168
169                 //fetch call info and add to list
170                 AppCallInfo callInfo;
171                 result r = pCallList.GetAt(0, callInfo);
172                 if (r == E_SUCCESS)
173                 {
174                         //copy call information to new instance
175                         AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
176                         *pCaller = callInfo;
177                         pCallInfoList->Add(pCaller);
178                         //single active call - goto active call form
179                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVE_EMERGENCYCALL,
180                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
181                 }
182         }
183         break;
184
185         default:
186                 break;
187         }
188 }
189
190 void
191 BaseForm::HandleCallDisconnected(bool isLastCall, IListT<AppCallInfo>& pCurrentActiveCallList)
192 {
193         AppLogDebug("Enter");
194         if(__pCallPresentor->IsIncomingorDialingCallPresent() == true)
195         {
196                 //This scenario will come, if this disconnected call is neither incoming nor dialing call.
197                 //In this case, if there is any dialing call exists, then ignore.
198                 //Else, if there is any incoming call exists, then update call option popup.
199                 AppLogDebug("IsIncomingorDialingCallPresent %d",__formType);
200                 switch (__formType)
201                 {
202                 case FORMTYPE_INCOMINGCALL:
203                 {
204                         IncomingCallForm* pIncomingCallForm = dynamic_cast<IncomingCallForm*>(this);
205                         if (pIncomingCallForm != null)
206                         {
207                                 pIncomingCallForm->CallDisconnected();
208                         }
209                 }
210                         break;
211
212                 default:
213                         break;
214                 }
215                 return;
216         }
217
218         SceneManager* pSceneManager = SceneManager::GetInstance();
219         CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
220
221         int callCount = pCurrentActiveCallList.GetCount();
222         if (callCount > 0)
223         {
224                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
225                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
226                 pCallInfoList->Construct(callCount);
227                 for (int index = 0; index < callCount; index++)
228                 {
229                         //fetch call info and add to list
230                         AppCallInfo callInfo;
231                         result r = pCurrentActiveCallList.GetAt(index, callInfo);
232                         if (r == E_SUCCESS)
233                         {
234                                 //copy call information to new instance
235                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
236                                 *pCaller = callInfo;
237                                 pCallInfoList->Add(pCaller);
238                         }
239                 }
240
241                 if (callCount == 1)
242                 {
243                         //fetch call info and add to list
244                         AppCallInfo callInfo;
245                         result r = pCurrentActiveCallList.GetAt(0, callInfo);
246                         if (r == E_SUCCESS)
247                         {
248                                 //copy call information to new instance
249                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
250                                 *pCaller = callInfo;
251                                 pCallInfoList->Add(pCaller);
252                         }
253
254                         if (isLastCall == true)
255                         {
256                                 //list contains 1 last ended call to show EndCall screen.
257                                 //goto End Call form if single call was ended else terminate
258                         //      if (callInfo.IsConferenceCall() == false)
259                                 if (1)
260                                 {
261                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ENDCALL,
262                                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
263                                 }
264                                 else
265                                 {
266                                         pPhoneApp->Terminate();
267                                 }
268                         }
269                         else
270                         {
271                                 //list contains 1 active call
272                                 if (pCurrentActiveCallList.GetCount() == 1)
273                                 {
274                                         if (callInfo.IsConferenceCall() == true)
275                                         {
276                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL,
277                                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
278                                         }
279                                         else
280                                         {
281                                                 //goto Single Active Call form
282                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL,
283                                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
284                                         }
285                                 }
286                         }
287                 }
288                 else
289                 {
290                         //multiple active calls are present.
291                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL,
292                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
293                 }
294         }
295         else
296         {
297                 //This is done to show end call form in missed call case also
298                 //this was done on request received from HQ to solve a bug in
299                 //camera application. In which if a call comes when camera is
300                 //running and user disconnects before the ui is shown the camera
301                 //application hangs
302                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
303                 pCallInfoList->Construct(1);
304                 AppCallInfo callInfo;
305                 result r = pCurrentActiveCallList.GetAt(0, callInfo);
306                 if (r == E_SUCCESS)
307                 {
308                         //copy call information to new instance
309                         AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
310                         *pCaller = callInfo;
311                         pCallInfoList->Add(pCaller);
312                         //multiple active calls are present.
313                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ENDCALL,
314                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
315
316                 }
317                 else
318                 {
319                         pPhoneApp->Terminate();
320                 }
321
322         }
323 }
324
325
326 void
327 BaseForm::HandleConferenceCall(AppCallInfo& pCallInfo)
328 {
329         SceneManager* pSceneManager = SceneManager::GetInstance();
330
331         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
332         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
333         pCallInfoList->Construct(1);
334
335         //update list to be passed
336         AppCallInfo* pConfInfo = new (std::nothrow) AppCallInfo();
337         *pConfInfo = pCallInfo;
338         pCallInfoList->Add(pConfInfo);
339
340         //Todo: create screens for single conf call and conf call with another held call
341         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL,
342                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
343 }
344
345 void
346 BaseForm::HandleIncomingCall(AppCallInfo& pCallInfo)
347 {
348         SceneManager* pSceneManager = SceneManager::GetInstance();
349
350         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
351         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
352         pCallInfoList->Construct(1);
353
354         //update list to be passed
355         AppCallInfo* pIncomingCall = new (std::nothrow) AppCallInfo();
356         *pIncomingCall = pCallInfo;
357         pCallInfoList->Add(pIncomingCall);
358
359         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL,
360                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
361 }
362
363 void
364 BaseForm::HandleCallSwapOccured(IListT<AppCallInfo>& pCallList)
365 {
366         int noOfCalls = pCallList.GetCount();
367         if(noOfCalls != IDI_MAX_ACTIVE_CALLS && __formType != FORMTYPE_MULTIPLECALLS)
368         {
369                 return;
370         }
371         ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
372         if(pActiveCallForm != null)
373         {
374                 //update calls state
375                 pActiveCallForm->UpdateMultipleCallScreen(pCallList);
376                 pActiveCallForm->SetSwapInProgress(false);
377
378         }
379 }
380
381 void
382 BaseForm::HandleConferenceChange(void)
383 {
384         if(__pCallPresentor->IsIncomingorDialingCallPresent() == true)
385         {
386                 //This scenario will come, if 1 call is disconnected from conf. call having more than 2 participants.
387                 //In this case, if there is any dialing call exists, then ignore.
388                 //Else, if there is any incoming call exists, then update call option popup.
389                 switch (__formType)
390                 {
391                 case FORMTYPE_INCOMINGCALL:
392                 {
393                         IncomingCallForm* pIncomingCallForm = dynamic_cast<IncomingCallForm*>(this);
394                         if (pIncomingCallForm != null)
395                         {
396                                 pIncomingCallForm->CallDisconnected();
397                         }
398                 }
399                         break;
400
401                 default:
402                         break;
403                 }
404                 return;
405         }
406
407         switch (__formType)
408         {
409         case FORMTYPE_CONFCALLLIST:
410         {
411                 ConfCallerListForm* pConfCallerListForm = dynamic_cast<ConfCallerListForm*>(this);
412                 if(pConfCallerListForm != null)
413                 {
414                         pConfCallerListForm->HandleParticipantsChanged();
415                 }
416         }
417                 break;
418
419         case FORMTYPE_ACTIVECONFCALL:
420         case FORMTYPE_MULTIPLECALLS:
421         {
422                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
423                 if(pActiveCallForm != null)
424                 {
425                         pActiveCallForm->HandleConfCallChanged();
426                 }
427         }
428                 break;
429         default:
430                 break;
431         }
432 }
433
434 void
435 BaseForm::HandleTelephonyError(int errorCode)
436 {
437         //show error msg Popup
438         if (__pErrorMsgPopup == null)
439         {
440                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
441                 __pErrorMsgPopup->ShowErrorMsgPopupN(errorCode);
442         }
443 }
444
445 void
446 BaseForm::HandlePopupClosed(void)
447 {
448         Draw();
449         delete __pErrorMsgPopup;
450         __pErrorMsgPopup = null;
451
452         switch(__formType)
453         {
454         case FORMTYPE_OUTGOINGCALL:
455         {
456                 //fetch no of calls from telephony
457                 CallPresentationModel* pPresentor = CallPresentationModel::GetInstance();
458                 if(pPresentor != null)
459                 {
460                         //check if any call is present
461                         if(pPresentor->GetCurrentCallCount() > 0)
462                         {
463                                 //fetch current call list
464                                 IListT<AppCallInfo>* pCurrentCallList = pPresentor->GetCallListN();
465                                 HandleCallDisconnected(false,*pCurrentCallList);
466                                 delete pCurrentCallList;
467                                 pCurrentCallList = null;
468                         }
469                         else
470                         {
471                                 //No more calls are active
472                                 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
473                                 pPhoneApp->Terminate();
474
475                         }
476                 }
477         }
478         break;
479
480         case FORMTYPE_ENDCALL:
481         {
482                 //It comes here, only when we make voice call for Last call from EndCallForm
483                 //and some TAPI error is encountered.
484                 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
485                 pPhoneApp->Terminate();
486         }
487         break;
488
489         default:
490         break;
491         }
492 }
493