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         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
284         pCallInfoList->Construct(noOfCalls);
285
286         for (int index = 0; index < noOfCalls; index++)
287         {
288                 //fetch call info and add to list
289                 CallInfo callInfo;
290                 result r = pCallList.GetAt(index, callInfo);
291                 if (r == E_SUCCESS)
292                 {
293                         //copy call information to new instance
294                         CallInfo* pCallInfo = new (std::nothrow) CallInfo();
295                         *pCallInfo = callInfo;
296                         pCallInfoList->Add(pCallInfo);
297                 }
298         }
299
300         SceneManager* pSceneManager = SceneManager::GetInstance();
301         if (pSceneManager != null)
302         {
303                 Scene* pActiveScene = pSceneManager->GetCurrentScene();
304                 if (pActiveScene != null)
305                 {
306                         String formString = pActiveScene->GetFormId();
307                         if (formString == IDL_FORM_MULTIPLEACTIVECALL)
308                         {
309                                 ActiveCallForm* pActiveForm = (ActiveCallForm*) pActiveScene->GetForm();
310                                 pActiveForm->HandleCallSwapN(pCallInfoList);
311                         }
312                 }
313         }
314 }
315
316 void
317 BaseForm::HandleConferenceChange(void)
318 {
319         SceneManager* pSceneManager = SceneManager::GetInstance();
320         if (pSceneManager != null)
321         {
322                 Scene* pActiveScene = pSceneManager->GetCurrentScene();
323                 if (pActiveScene != null)
324                 {
325                         String formString = pActiveScene->GetFormId();
326                         if (formString == IDL_FORM_CONFCALLLIST)
327                         {
328                                 ConfCallerListForm* pConfListForm = (ConfCallerListForm*) pActiveScene->GetForm();
329                                 pConfListForm->HandleCallChange();
330                         }
331                 }
332         }
333 }
334
335 void
336 BaseForm::HandleTelephonyError(int errorCode)
337 {
338         //show error msg Popup
339         if (__pErrorMsgPopup == null)
340         {
341                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
342         }
343         __pErrorMsgPopup->ShowErrorMsgPopupN(errorCode);
344 }
345
346 void
347 BaseForm::HandlePopupClosed(void)
348 {
349         Draw();
350         delete __pErrorMsgPopup;
351         __pErrorMsgPopup = null;
352
353         SceneManager* pSceneManager = SceneManager::GetInstance();
354         switch(__formType)
355         {
356         case FORMTYPE_OUTGOINGCALL:
357         {
358                 //fetch no of calls from telephony
359                 CallPresentationModel* pPresentor = CallPresentationModel::GetInstance();
360                 if(pPresentor != null)
361                 {
362                         //check if any call is present
363                         if(pPresentor->GetCurrentCallCount() > 0)
364                         {
365                                 //fetch current call list
366                                 IListT<CallInfo>* pCurrentCallList = pPresentor->GetCallListN();
367                                 HandleCallDisconnected(false,*pCurrentCallList);
368                                 delete pCurrentCallList;
369                                 pCurrentCallList = null;
370                         }
371                         else
372                         {
373                                 //No more calls are active
374                                 PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
375                                 SceneId nextSceneId = pPhoneApp->GetInitialScene();
376                                 if (nextSceneId == IDSCN_DIALER || nextSceneId == IDSCN_CALL_LOG)
377                                 {
378                                         pSceneManager->GoForward( ForwardSceneTransition(nextSceneId, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
379                                                 SCENE_HISTORY_OPTION_NO_HISTORY));
380                                 }
381                                 else
382                                 {
383                                         PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
384                                         pPhoneApp->Terminate();
385                                 }
386                         }
387                 }
388         }
389         break;
390
391         case FORMTYPE_ENDCALL:
392         {
393                 //It comes here, only when we make voice call for Last call from EndCallForm
394                 //and some TAPI error is encountered.
395                 PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
396                 pPhoneApp->Terminate();
397         }
398         break;
399
400         default:
401         break;
402         }
403 }
404
405 void
406 BaseForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
407 {
408         SetOrientation(ORIENTATION_PORTRAIT);
409 }
410