License and Privilege changes
[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), pCallInfoList);
129                         }
130                         else
131                         {
132                                 //single active call - goto active call form
133                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL), pCallInfoList);
134                         }
135                 }
136                 else if(noOfCalls == 2)
137                 {
138                         //goto multiple active call form
139                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL), pCallInfoList);
140                 }
141         }
142         break;
143
144         case FORMTYPE_MULTIPLECALLS:
145         {
146                 //This case can come on Multiple Calls screen, when one of the calls is conference call with 2 participants
147                 //and one of the participants exits himself from ConfCall.
148                 int noOfCalls = pCallList.GetCount();
149                 AppLogDebug("Active Call Count = %d", noOfCalls);
150                 //this is just a safety check, call count will aleays be 2 here.
151                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
152                 if(noOfCalls == IDI_MAX_ACTIVE_CALLS && pActiveCallForm != null)
153                 {
154                         //update calls state
155                         pActiveCallForm->UpdateMultipleCallScreen(pCallList);
156                 }
157         }
158         break;
159
160         case FORMTYPE_EMERGENCYOUTGOINGCALL:
161         {
162                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
163                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
164                 pCallInfoList->Construct(1);
165
166                 //fetch call info and add to list
167                 AppCallInfo callInfo;
168                 result r = pCallList.GetAt(0, callInfo);
169                 if (r == E_SUCCESS)
170                 {
171                         //copy call information to new instance
172                         AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
173                         *pCaller = callInfo;
174                         pCallInfoList->Add(pCaller);
175                         //single active call - goto active call form
176                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVE_EMERGENCYCALL), pCallInfoList);
177                 }
178         }
179         break;
180
181         default:
182                 break;
183         }
184 }
185
186 void
187 BaseForm::HandleCallDisconnected(bool isLastCall, IListT<AppCallInfo>& pCurrentActiveCallList)
188 {
189         if(__pCallPresentor->IsIncomingorDialingCallPresent() == true)
190         {
191                 //This scenario will come, if this disconnected call is neither incoming nor dialing call.
192                 //In this case, if there is any dialing call exists, then ignore.
193                 //Else, if there is any incoming call exists, then update call option popup.
194                 switch (__formType)
195                 {
196                 case FORMTYPE_INCOMINGCALL:
197                 {
198                         IncomingCallForm* pIncomingCallForm = dynamic_cast<IncomingCallForm*>(this);
199                         if (pIncomingCallForm != null)
200                         {
201                                 pIncomingCallForm->CallDisconnected();
202                         }
203                 }
204                         break;
205
206                 default:
207                         break;
208                 }
209                 return;
210         }
211
212         SceneManager* pSceneManager = SceneManager::GetInstance();
213         CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
214
215         int callCount = pCurrentActiveCallList.GetCount();
216         if (callCount > 0)
217         {
218                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
219                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
220                 pCallInfoList->Construct(callCount);
221                 for (int index = 0; index < callCount; index++)
222                 {
223                         //fetch call info and add to list
224                         AppCallInfo callInfo;
225                         result r = pCurrentActiveCallList.GetAt(index, callInfo);
226                         if (r == E_SUCCESS)
227                         {
228                                 //copy call information to new instance
229                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
230                                 *pCaller = callInfo;
231                                 pCallInfoList->Add(pCaller);
232                         }
233                 }
234
235                 if (callCount == 1)
236                 {
237                         //fetch call info and add to list
238                         AppCallInfo callInfo;
239                         result r = pCurrentActiveCallList.GetAt(0, callInfo);
240                         if (r == E_SUCCESS)
241                         {
242                                 //copy call information to new instance
243                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
244                                 *pCaller = callInfo;
245                                 pCallInfoList->Add(pCaller);
246                         }
247
248                         if (isLastCall == true)
249                         {
250                                 //list contains 1 last ended call to show EndCall screen.
251                                 //goto End Call form if single call was ended else terminate
252                                 if (callInfo.IsConferenceCall() == false)
253                                 {
254                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ENDCALL), pCallInfoList);
255                                 }
256                                 else
257                                 {
258                                         pPhoneApp->Terminate();
259                                 }
260                         }
261                         else
262                         {
263                                 //list contains 1 active call
264                                 if (pCurrentActiveCallList.GetCount() == 1)
265                                 {
266                                         if (callInfo.IsConferenceCall() == true)
267                                         {
268                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallInfoList);
269                                         }
270                                         else
271                                         {
272                                                 //goto Single Active Call form
273                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL), pCallInfoList);
274                                         }
275                                 }
276                         }
277                 }
278                 else
279                 {
280                         //multiple active calls are present.
281                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL), pCallInfoList);
282                 }
283         }
284         else
285         {
286                 pPhoneApp->Terminate();
287         }
288 }
289
290
291 void
292 BaseForm::HandleConferenceCall(AppCallInfo& pCallInfo)
293 {
294         SceneManager* pSceneManager = SceneManager::GetInstance();
295
296         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
297         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
298         pCallInfoList->Construct(1);
299
300         //update list to be passed
301         AppCallInfo* pConfInfo = new (std::nothrow) AppCallInfo();
302         *pConfInfo = pCallInfo;
303         pCallInfoList->Add(pConfInfo);
304
305         //Todo: create screens for single conf call and conf call with another held call
306         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallInfoList);
307 }
308
309 void
310 BaseForm::HandleIncomingCall(AppCallInfo& pCallInfo)
311 {
312         SceneManager* pSceneManager = SceneManager::GetInstance();
313
314         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
315         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
316         pCallInfoList->Construct(1);
317
318         //update list to be passed
319         AppCallInfo* pIncomingCall = new (std::nothrow) AppCallInfo();
320         *pIncomingCall = pCallInfo;
321         pCallInfoList->Add(pIncomingCall);
322
323         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), pCallInfoList);
324 }
325
326 void
327 BaseForm::HandleCallSwapOccured(IListT<AppCallInfo>& pCallList)
328 {
329         int noOfCalls = pCallList.GetCount();
330         if(noOfCalls != IDI_MAX_ACTIVE_CALLS && __formType != FORMTYPE_MULTIPLECALLS)
331         {
332                 return;
333         }
334         ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
335         if(pActiveCallForm != null)
336         {
337                 //update calls state
338                 pActiveCallForm->UpdateMultipleCallScreen(pCallList);
339         }
340 }
341
342 void
343 BaseForm::HandleConferenceChange(void)
344 {
345         if(__pCallPresentor->IsIncomingorDialingCallPresent() == true)
346         {
347                 //This scenario will come, if 1 call is disconnected from conf. call having more than 2 participants.
348                 //In this case, if there is any dialing call exists, then ignore.
349                 //Else, if there is any incoming call exists, then update call option popup.
350                 switch (__formType)
351                 {
352                 case FORMTYPE_INCOMINGCALL:
353                 {
354                         IncomingCallForm* pIncomingCallForm = dynamic_cast<IncomingCallForm*>(this);
355                         if (pIncomingCallForm != null)
356                         {
357                                 pIncomingCallForm->CallDisconnected();
358                         }
359                 }
360                         break;
361
362                 default:
363                         break;
364                 }
365                 return;
366         }
367
368         switch (__formType)
369         {
370         case FORMTYPE_CONFCALLLIST:
371         {
372                 ConfCallerListForm* pConfCallerListForm = dynamic_cast<ConfCallerListForm*>(this);
373                 if(pConfCallerListForm != null)
374                 {
375                         pConfCallerListForm->HandleParticipantsChanged();
376                 }
377         }
378                 break;
379
380         case FORMTYPE_ACTIVECONFCALL:
381         case FORMTYPE_MULTIPLECALLS:
382         {
383                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
384                 if(pActiveCallForm != null)
385                 {
386                         pActiveCallForm->HandleConfCallChanged();
387                 }
388         }
389                 break;
390         default:
391                 break;
392         }
393 }
394
395 void
396 BaseForm::HandleTelephonyError(int errorCode)
397 {
398         //show error msg Popup
399         if (__pErrorMsgPopup == null)
400         {
401                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
402                 __pErrorMsgPopup->ShowErrorMsgPopupN(errorCode);
403         }
404 }
405
406 void
407 BaseForm::HandlePopupClosed(void)
408 {
409         Draw();
410         delete __pErrorMsgPopup;
411         __pErrorMsgPopup = null;
412
413         switch(__formType)
414         {
415         case FORMTYPE_OUTGOINGCALL:
416         {
417                 //fetch no of calls from telephony
418                 CallPresentationModel* pPresentor = CallPresentationModel::GetInstance();
419                 if(pPresentor != null)
420                 {
421                         //check if any call is present
422                         if(pPresentor->GetCurrentCallCount() > 0)
423                         {
424                                 //fetch current call list
425                                 IListT<AppCallInfo>* pCurrentCallList = pPresentor->GetCallListN();
426                                 HandleCallDisconnected(false,*pCurrentCallList);
427                                 delete pCurrentCallList;
428                                 pCurrentCallList = null;
429                         }
430                         else
431                         {
432                                 //No more calls are active
433                                 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
434                                 pPhoneApp->Terminate();
435
436                         }
437                 }
438         }
439         break;
440
441         case FORMTYPE_ENDCALL:
442         {
443                 //It comes here, only when we make voice call for Last call from EndCallForm
444                 //and some TAPI error is encountered.
445                 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
446                 pPhoneApp->Terminate();
447         }
448         break;
449
450         default:
451         break;
452         }
453 }
454