27340831c0b58c97799719ec9721f443c5038c4a
[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_DESTROY), 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_DESTROY), 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_DESTROY), 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_DESTROY), pCallInfoList);
181                 }
182         }
183         break;
184
185         default:
186                 break;
187         }
188 }
189
190 void
191 BaseForm::HandleCallActive(bool isActive)
192 {
193         AppLogDebug("Enter");
194         ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
195         if(pActiveCallForm != null)
196         {
197                 pActiveCallForm->OnActiveTelephonyCallback(isActive);
198         }
199 }
200
201 void
202 BaseForm::HandleCallHeld(bool isHeld)
203 {
204         AppLogDebug("Enter");
205         ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
206         if(pActiveCallForm != null)
207         {
208                 pActiveCallForm->OnHoldTelephonyCallback(isHeld);
209         }
210 }
211
212 void
213 BaseForm::HandleCallDisconnected(bool isLastCall, IListT<AppCallInfo>& pCurrentActiveCallList)
214 {
215         AppLogDebug("Enter");
216         if(__pCallPresentor->IsIncomingorDialingCallPresent() == true)
217         {
218                 //This scenario will come, if this disconnected call is neither incoming nor dialing call.
219                 //In this case, if there is any dialing call exists, then ignore.
220                 //Else, if there is any incoming call exists, then update call option popup.
221                 AppLogDebug("IsIncomingorDialingCallPresent %d",__formType);
222                 switch (__formType)
223                 {
224                 case FORMTYPE_INCOMINGCALL:
225                 {
226                         IncomingCallForm* pIncomingCallForm = dynamic_cast<IncomingCallForm*>(this);
227                         if (pIncomingCallForm != null)
228                         {
229                                 pIncomingCallForm->CallDisconnected();
230                         }
231                 }
232                         break;
233
234                 default:
235                         break;
236                 }
237                 return;
238         }
239
240         SceneManager* pSceneManager = SceneManager::GetInstance();
241         CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
242
243         int callCount = pCurrentActiveCallList.GetCount();
244         if (callCount > 0)
245         {
246                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
247                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
248                 pCallInfoList->Construct(callCount);
249                 for (int index = 0; index < callCount; index++)
250                 {
251                         //fetch call info and add to list
252                         AppCallInfo callInfo;
253                         result r = pCurrentActiveCallList.GetAt(index, callInfo);
254                         if (r == E_SUCCESS)
255                         {
256                                 //copy call information to new instance
257                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
258                                 *pCaller = callInfo;
259                                 pCallInfoList->Add(pCaller);
260                         }
261                 }
262
263                 if (callCount == 1)
264                 {
265                         //fetch call info and add to list
266                         AppCallInfo callInfo;
267                         result r = pCurrentActiveCallList.GetAt(0, callInfo);
268                         if (r == E_SUCCESS)
269                         {
270                                 //copy call information to new instance
271                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
272                                 *pCaller = callInfo;
273                                 pCallInfoList->Add(pCaller);
274                         }
275
276                         if (isLastCall == true)
277                         {
278                                 //list contains 1 last ended call to show EndCall screen.
279                                 //goto End Call form if single call was ended else terminate
280                         //      if (callInfo.IsConferenceCall() == false)
281                                 if (1)
282                                 {
283                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ENDCALL,
284                                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
285                                 }
286                                 else
287                                 {
288                                         pPhoneApp->Terminate();
289                                 }
290                         }
291                         else
292                         {
293                                 //list contains 1 active call
294                                 if (pCurrentActiveCallList.GetCount() == 1)
295                                 {
296                                         if (callInfo.IsConferenceCall() == true)
297                                         {
298                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL,
299                                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
300                                         }
301                                         else
302                                         {
303                                                 //goto Single Active Call form
304                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL,
305                                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
306                                         }
307                                 }
308                         }
309                 }
310                 else
311                 {
312                         //multiple active calls are present.
313                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL,
314                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
315                 }
316         }
317         else
318         {
319                 //This is done to show end call form in missed call case also
320                 //this was done on request received from HQ to solve a bug in
321                 //camera application. In which if a call comes when camera is
322                 //running and user disconnects before the ui is shown the camera
323                 //application hangs
324                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
325                 pCallInfoList->Construct(1);
326                 AppCallInfo callInfo;
327                 result r = pCurrentActiveCallList.GetAt(0, callInfo);
328                 if (r == E_SUCCESS)
329                 {
330                         //copy call information to new instance
331                         AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
332                         *pCaller = callInfo;
333                         pCallInfoList->Add(pCaller);
334                         //multiple active calls are present.
335                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ENDCALL,
336                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
337
338                 }
339                 else
340                 {
341                         pPhoneApp->Terminate();
342                 }
343
344         }
345 }
346
347
348 void
349 BaseForm::HandleConferenceCall(AppCallInfo& pCallInfo)
350 {
351         SceneManager* pSceneManager = SceneManager::GetInstance();
352
353         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
354         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
355         pCallInfoList->Construct(1);
356
357         //update list to be passed
358         AppCallInfo* pConfInfo = new (std::nothrow) AppCallInfo();
359         *pConfInfo = pCallInfo;
360         pCallInfoList->Add(pConfInfo);
361
362         //Todo: create screens for single conf call and conf call with another held call
363         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL,
364                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
365 }
366
367 void
368 BaseForm::HandleIncomingCall(AppCallInfo& pCallInfo)
369 {
370         SceneManager* pSceneManager = SceneManager::GetInstance();
371
372         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
373         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
374         pCallInfoList->Construct(1);
375
376         //update list to be passed
377         AppCallInfo* pIncomingCall = new (std::nothrow) AppCallInfo();
378         *pIncomingCall = pCallInfo;
379         pCallInfoList->Add(pIncomingCall);
380
381         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL,
382                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pCallInfoList);
383 }
384
385 void
386 BaseForm::HandleConfCallHoldOccured(bool success)
387 {
388
389         switch (__formType)
390         {
391         case FORMTYPE_CONFCALLLIST:
392         {
393                 ConfCallerListForm* pConfCallerListForm = dynamic_cast<ConfCallerListForm*>(this);
394                 if(pConfCallerListForm != null)
395                 {
396                         pConfCallerListForm->OnConfCallHoldTelephoneCallBackOccured(success);
397                 }
398         }
399         break;
400         case FORMTYPE_ACTIVECONFCALL:
401         {
402                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
403                 if(pActiveCallForm != null)
404                 {
405                         pActiveCallForm->OnConfCallHoldTelephonyCallback(success);
406                 }
407         }
408         break;
409         default:
410                 break;
411         }
412 }
413
414 void
415 BaseForm::HandleConfCallActiveOccured(bool success)
416 {
417         switch (__formType)
418         {
419         case FORMTYPE_CONFCALLLIST:
420         {
421                 ConfCallerListForm* pConfCallerListForm = dynamic_cast<ConfCallerListForm*>(this);
422                 if(pConfCallerListForm != null)
423                 {
424                         pConfCallerListForm->OnConfCallActiveTelephoneCallBackOccured(success);
425                 }
426         }
427         break;
428         case FORMTYPE_ACTIVECONFCALL:
429         {
430                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
431                 if(pActiveCallForm != null)
432                 {
433                         pActiveCallForm->OnConfCallActiveTelephonyCallback(success);
434                 }
435         }
436         break;
437         default:
438                 break;
439         }
440 }
441
442 void
443 BaseForm::HandleCallSwapOccured(IListT<AppCallInfo>& pCallList)
444 {
445         int noOfCalls = pCallList.GetCount();
446         if(noOfCalls != IDI_MAX_ACTIVE_CALLS && __formType != FORMTYPE_MULTIPLECALLS)
447         {
448                 return;
449         }
450         ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
451         if(pActiveCallForm != null)
452         {
453                 //update calls state
454                 pActiveCallForm->UpdateMultipleCallScreen(pCallList);
455                 pActiveCallForm->SetSwapInProgress(false);
456
457         }
458 }
459
460 void
461 BaseForm::HandleConferenceChange(void)
462 {
463         if(__pCallPresentor->IsIncomingorDialingCallPresent() == true)
464         {
465                 //This scenario will come, if 1 call is disconnected from conf. call having more than 2 participants.
466                 //In this case, if there is any dialing call exists, then ignore.
467                 //Else, if there is any incoming call exists, then update call option popup.
468                 switch (__formType)
469                 {
470                 case FORMTYPE_INCOMINGCALL:
471                 {
472                         IncomingCallForm* pIncomingCallForm = dynamic_cast<IncomingCallForm*>(this);
473                         if (pIncomingCallForm != null)
474                         {
475                                 pIncomingCallForm->CallDisconnected();
476                         }
477                 }
478                         break;
479
480                 default:
481                         break;
482                 }
483                 return;
484         }
485
486         switch (__formType)
487         {
488         case FORMTYPE_CONFCALLLIST:
489         {
490                 ConfCallerListForm* pConfCallerListForm = dynamic_cast<ConfCallerListForm*>(this);
491                 if(pConfCallerListForm != null)
492                 {
493                         pConfCallerListForm->HandleParticipantsChanged();
494                 }
495         }
496                 break;
497
498         case FORMTYPE_ACTIVECONFCALL:
499         case FORMTYPE_MULTIPLECALLS:
500         {
501                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
502                 if(pActiveCallForm != null)
503                 {
504                         pActiveCallForm->HandleConfCallChanged();
505                 }
506         }
507                 break;
508         default:
509                 break;
510         }
511 }
512
513 void
514 BaseForm::HandleTelephonyError(int errorCode)
515 {
516         //show error msg Popup
517         if (__pErrorMsgPopup == null)
518         {
519                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
520                 __pErrorMsgPopup->ShowErrorMsgPopupN(errorCode);
521         }
522 }
523
524 void
525 BaseForm::HandlePopupClosed(void)
526 {
527         Draw();
528         delete __pErrorMsgPopup;
529         __pErrorMsgPopup = null;
530
531         switch(__formType)
532         {
533         case FORMTYPE_OUTGOINGCALL:
534         {
535                 //fetch no of calls from telephony
536                 CallPresentationModel* pPresentor = CallPresentationModel::GetInstance();
537                 if(pPresentor != null)
538                 {
539                         //check if any call is present
540                         if(pPresentor->GetCurrentCallCount() > 0)
541                         {
542                                 //fetch current call list
543                                 IListT<AppCallInfo>* pCurrentCallList = pPresentor->GetCallListN();
544                                 HandleCallDisconnected(false,*pCurrentCallList);
545                                 delete pCurrentCallList;
546                                 pCurrentCallList = null;
547                         }
548                         else
549                         {
550                                 //No more calls are active
551                                 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
552                                 pPhoneApp->Terminate();
553
554                         }
555                 }
556         }
557         break;
558
559         case FORMTYPE_ENDCALL:
560         {
561                 //It comes here, only when we make voice call for Last call from EndCallForm
562                 //and some TAPI error is encountered.
563                 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
564                 pPhoneApp->Terminate();
565         }
566         break;
567
568         default:
569         break;
570         }
571 }
572