1.Changed appcontrol parameters of contacts 2.GUI changes 3.Changes to alert tone...
[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.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        CallBaseForm.cpp
19  * @brief       Base class for all Call forms
20  */
21 #include "CallActiveCallForm.h"
22 #include "CallBaseForm.h"
23 #include "CallInfo.h"
24 #include "CallPresentationModel.h"
25 #include "CallConfCallerListForm.h"
26 #include "CallPhoneFormFactory.h"
27 #include "CallSceneRegister.h"
28 #include "CallApp.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         //To be implemented in sub classes
53         return E_SUCCESS;
54 }
55
56 void
57 BaseForm::OnActionPerformed(const Control& source, int actionId)
58 {
59 }
60
61 /////////////////////////////////////////////////////////////////
62 /////  Event Listener methods from ITelephonyEventListener  /////
63 /////////////////////////////////////////////////////////////////
64
65 void
66 BaseForm::HandleCallConnected(IListT<AppCallInfo>& pCallList)
67 {
68         SceneManager* pSceneManager = SceneManager::GetInstance();
69
70         switch (__formType)
71         {
72         case FORMTYPE_OUTGOINGCALL:
73         case FORMTYPE_INCOMINGCALL:
74         case FORMTYPE_CONFCALLLIST:
75         case FORMTYPE_ACTIVECALL:
76         case FORMTYPE_ACTIVECONFCALL:
77         {
78                 int noOfCalls = pCallList.GetCount();
79                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
80                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
81                 pCallInfoList->Construct(noOfCalls);
82
83                 for (int index = 0; index < noOfCalls; index++)
84                 {
85                         //fetch call info and add to list
86                         AppCallInfo callInfo;
87                         result r = pCallList.GetAt(index, callInfo);
88                         if (r == E_SUCCESS)
89                         {
90                                 //copy call information to new instance
91                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
92                                 *pCaller = callInfo;
93                                 pCallInfoList->Add(pCaller);
94                         }
95                 }
96
97                 if (noOfCalls == 1)
98                 {
99                         //Check if active call is conference call
100                         AppCallInfo* pActiveCallInfo = static_cast<AppCallInfo*>(pCallInfoList->GetAt(0));
101                         if(pActiveCallInfo->IsConferenceCall() == true)
102                         {
103                                 //single Conference call - goto active Conf. call form
104                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallInfoList);
105                         }
106                         else
107                         {
108                                 //single active call - goto active call form
109                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL), pCallInfoList);
110                         }
111                 }
112                 else if(noOfCalls == 2)
113                 {
114                         //goto multiple active call form
115                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL), pCallInfoList);
116                 }
117         }
118         break;
119
120         case FORMTYPE_MULTIPLECALLS:
121         {
122                 //This case can come on Multiple Calls screen, when one of the calls is conference call with 2 participants
123                 //and one of the participants exits himself from ConfCall.
124                 int noOfCalls = pCallList.GetCount();
125                 AppLogDebug("Active Call Count = %d", noOfCalls);
126                 //this is just a safety check, call count will aleays be 2 here.
127                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
128                 if(noOfCalls == IDI_MAX_ACTIVE_CALLS && pActiveCallForm != null)
129                 {
130                         //update calls state
131                         pActiveCallForm->UpdateMultipleCallScreen(pCallList);
132                 }
133         }
134         break;
135
136         case FORMTYPE_EMERGENCYOUTGOINGCALL:
137         {
138                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
139                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
140                 pCallInfoList->Construct(1);
141
142                 //fetch call info and add to list
143                 AppCallInfo callInfo;
144                 result r = pCallList.GetAt(0, callInfo);
145                 if (r == E_SUCCESS)
146                 {
147                         //copy call information to new instance
148                         AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
149                         *pCaller = callInfo;
150                         pCallInfoList->Add(pCaller);
151                         //single active call - goto active call form
152                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVE_EMERGENCYCALL), pCallInfoList);
153                 }
154         }
155         break;
156
157         default:
158                 break;
159         }
160 }
161
162 void
163 BaseForm::HandleCallDisconnected(bool isLastCall, IListT<AppCallInfo>& pCallList)
164 {
165         SceneManager* pSceneManager = SceneManager::GetInstance();
166         CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
167
168         int callCount = pCallList.GetCount();
169         if (callCount > 0)
170         {
171                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
172                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
173                 pCallInfoList->Construct(callCount);
174                 for (int index = 0; index < callCount; index++)
175                 {
176                         //fetch call info and add to list
177                         AppCallInfo callInfo;
178                         result r = pCallList.GetAt(index, callInfo);
179                         if (r == E_SUCCESS)
180                         {
181                                 //copy call information to new instance
182                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
183                                 *pCaller = callInfo;
184                                 pCallInfoList->Add(pCaller);
185                         }
186                 }
187                 if (callCount == 1)
188                 {
189                         //fetch call info and add to list
190                         AppCallInfo callInfo;
191                         result r = pCallList.GetAt(0, callInfo);
192                         if (r == E_SUCCESS)
193                         {
194                                 //copy call information to new instance
195                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
196                                 *pCaller = callInfo;
197                                 pCallInfoList->Add(pCaller);
198                         }
199
200                         if (isLastCall == true)
201                         {
202                                 //goto End Call form if single call. else terminate
203                                 if (callInfo.IsConferenceCall() == false)
204                                 {
205                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ENDCALL), pCallInfoList);
206                                 }
207                                 else
208                                 {
209                                         pPhoneApp->Terminate();
210                                 }
211                         }
212                         else
213                         {
214                                 if (pCallList.GetCount() == 1)
215                                 {
216                                         if (callInfo.IsConferenceCall() == true)
217                                         {
218                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallInfoList);
219                                         }
220                                         else
221                                         {
222                                                 //goto Single Active Call form
223                                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL), pCallInfoList);
224                                         }
225                                 }
226                         }
227                 }
228                 else
229                 {
230                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL), pCallInfoList);
231                 }
232         }
233         else
234         {
235                 pPhoneApp->Terminate();
236         }
237 }
238
239
240 void
241 BaseForm::HandleConferenceCall(AppCallInfo& pCallInfo)
242 {
243         SceneManager* pSceneManager = SceneManager::GetInstance();
244
245         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
246         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
247         pCallInfoList->Construct(1);
248
249         //update list to be passed
250         AppCallInfo* pConfInfo = new (std::nothrow) AppCallInfo();
251         *pConfInfo = pCallInfo;
252         pCallInfoList->Add(pConfInfo);
253
254         //Todo: create screens for single conf call and conf call with another held call
255         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallInfoList);
256 }
257
258 void
259 BaseForm::HandleIncomingCall(AppCallInfo& pCallInfo)
260 {
261         SceneManager* pSceneManager = SceneManager::GetInstance();
262
263         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
264         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
265         pCallInfoList->Construct(1);
266
267         //update list to be passed
268         AppCallInfo* pIncomingCall = new (std::nothrow) AppCallInfo();
269         *pIncomingCall = pCallInfo;
270         pCallInfoList->Add(pIncomingCall);
271
272         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), pCallInfoList);
273 }
274
275 void
276 BaseForm::HandleCallSwapOccured(IListT<AppCallInfo>& pCallList)
277 {
278         int noOfCalls = pCallList.GetCount();
279         if(noOfCalls != IDI_MAX_ACTIVE_CALLS && __formType != FORMTYPE_MULTIPLECALLS)
280         {
281                 return;
282         }
283         ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
284         if(pActiveCallForm != null)
285         {
286                 //update calls state
287                 pActiveCallForm->UpdateMultipleCallScreen(pCallList);
288         }
289 }
290
291 void
292 BaseForm::HandleConferenceChange(void)
293 {
294         switch (__formType)
295         {
296         case FORMTYPE_CONFCALLLIST:
297         {
298                 ConfCallerListForm* pConfCallerListForm = dynamic_cast<ConfCallerListForm*>(this);
299                 if(pConfCallerListForm != null)
300                 {
301                         pConfCallerListForm->HandleParticipantsChanged();
302                 }
303         }
304                 break;
305
306         case FORMTYPE_ACTIVECONFCALL:
307         case FORMTYPE_MULTIPLECALLS:
308         {
309                 ActiveCallForm* pActiveCallForm = dynamic_cast<ActiveCallForm*>(this);
310                 if(pActiveCallForm != null)
311                 {
312                         pActiveCallForm->HandleConfCallChanged();
313                 }
314         }
315                 break;
316         default:
317                 break;
318         }
319 }
320
321 void
322 BaseForm::HandleTelephonyError(int errorCode)
323 {
324         //show error msg Popup
325         if (__pErrorMsgPopup == null)
326         {
327                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
328         }
329         __pErrorMsgPopup->ShowErrorMsgPopupN(errorCode);
330 }
331
332 void
333 BaseForm::HandlePopupClosed(void)
334 {
335         Draw();
336         delete __pErrorMsgPopup;
337         __pErrorMsgPopup = null;
338
339         switch(__formType)
340         {
341         case FORMTYPE_OUTGOINGCALL:
342         {
343                 //fetch no of calls from telephony
344                 CallPresentationModel* pPresentor = CallPresentationModel::GetInstance();
345                 if(pPresentor != null)
346                 {
347                         //check if any call is present
348                         if(pPresentor->GetCurrentCallCount() > 0)
349                         {
350                                 //fetch current call list
351                                 IListT<AppCallInfo>* pCurrentCallList = pPresentor->GetCallListN();
352                                 HandleCallDisconnected(false,*pCurrentCallList);
353                                 delete pCurrentCallList;
354                                 pCurrentCallList = null;
355                         }
356                         else
357                         {
358                                 //No more calls are active
359                                 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
360                                 pPhoneApp->Terminate();
361
362                         }
363                 }
364         }
365         break;
366
367         case FORMTYPE_ENDCALL:
368         {
369                 //It comes here, only when we make voice call for Last call from EndCallForm
370                 //and some TAPI error is encountered.
371                 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
372                 pPhoneApp->Terminate();
373         }
374         break;
375
376         default:
377         break;
378         }
379 }
380