7f272bd470802c6ab8d11b4e368d155481effa52
[apps/osp/Call.git] / src / CallConfCallerListForm.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    CallConfCallerListForm.cpp
19  * @brief       Conference caller list form
20  */
21 #include <FSystem.h>
22 #include "CallConfCallerListForm.h"
23 #include "CallAppUtility.h"
24 #include "CallPresentationModel.h"
25 #include "CallSceneRegister.h"
26
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Runtime;
31 using namespace Tizen::Base::Utility;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
37
38 //Constants
39 const int W_HOLD_BITMAP = 78;
40 const int H_HOLD_BITMAP = 78;
41 const int W_BACK_BITMAP = 56;
42 const int H_BACK_BITMAP = 56;
43 const int X_BACK_BITMAP = 8;
44 const int Y_BACK_BITMAP = 8;
45 const int W_SPLIT_BITMAP = 74;
46 const int H_SPLIT_BITMAP = 74;
47 const int W_END_BITMAP = 80;
48 const int H_END_BITMAP = 74;
49 const int IDI_MAX_SECONDS = 60;
50 const int IDI_MAX_MINS = 60;
51 const int LIST_ITEM_HEIGHT = 112;
52 const int X_SPLIT_BUTTON_MARGIN = 26;
53 const int Y_SPLIT_BUTTON_MARGIN = 19;
54 const int X_END_BUTTON_PADDING = 26;
55 const int X_CALLER_LABEL = 116;
56 const int Y_CALLER_LABEL = 0;
57 const int W_CALLER_LABEL = 488;
58 const int H_CALLER_LABEL = 112;
59
60
61 static const wchar_t* IDL_CONFCALL_LIST_FORM = L"IDL_CONFCALL_LIST_FORM";
62 static const wchar_t* IDC_CALL_TIME_LABEL = L"IDC_CALL_TIME_LABEL";
63 static const wchar_t* IDB_SPLIT_NORMAL_BUTTON_ICON = L"C01-1_conference_split.png";
64 static const wchar_t* IDB_SPLIT_PRESS_BUTTON_ICON = L"C01-1_conference_split_press.png";
65 static const wchar_t* IDB_END_NORMAL_BUTTON_ICON = L"C01-1_conference_end.png";
66 static const wchar_t* IDB_END_PRESS_BUTTON_ICON = L"C01-1_conference_end_press.png";
67 static const wchar_t* IDC_END_CONFCALL_BUTTON = L"IDC_END_CONFCALL_BUTTON";
68 static const wchar_t* IDC_HOLD_CONFCALL_BUTTON = L"IDC_HOLD_CONFCALL_BUTTON";
69 static const wchar_t* IDC_CALLER1_PANEL = L"IDC_CALLER1_PANEL";
70 static const wchar_t* IDC__LINE_LABEL1 = L"IDC__LINE_LABEL1";
71 static const wchar_t* IDC_CALLER2_PANEL = L"IDC_CALLER2_PANEL";
72 static const wchar_t* IDC__LINE_LABEL2 = L"IDC__LINE_LABEL2";
73 static const wchar_t* IDC_CALLER3_PANEL = L"IDC_CALLER3_PANEL";
74 static const wchar_t* IDC__LINE_LABEL3 = L"IDC__LINE_LABEL3";
75 static const wchar_t* IDC_CALLER4_PANEL = L"IDC_CALLER4_PANEL";
76 static const wchar_t* IDC__LINE_LABEL4 = L"IDC__LINE_LABEL4";
77 static const wchar_t* IDC_CALLER5_PANEL = L"IDC_CALLER5_PANEL";
78 static const wchar_t* IDC__LINE_LABEL5 = L"IDC__LINE_LABEL5";
79 static const wchar_t* IDC_END_CALLER1 = L"IDC_END_CALLER1";
80 static const wchar_t* IDC_SPLIT_CALLER1 = L"IDC_SPLIT_CALLER1";
81 static const wchar_t* IDC_CALLER1_LABEL = L"IDC_CALLER1_LABEL";
82 static const wchar_t* IDC_END_CALLER2 = L"IDC_END_CALLER2";
83 static const wchar_t* IDC_SPLIT_CALLER2 = L"IDC_SPLIT_CALLER2";
84 static const wchar_t* IDC_CALLER2_LABEL = L"IDC_CALLER2_LABEL";
85 static const wchar_t* IDC_END_CALLER3 = L"IDC_END_CALLER3";
86 static const wchar_t* IDC_SPLIT_CALLER3 = L"IDC_SPLIT_CALLER3";
87 static const wchar_t* IDC_CALLER3_LABEL = L"IDC_CALLER3_LABEL";
88 static const wchar_t* IDC_END_CALLER4 = L"IDC_END_CALLER4";
89 static const wchar_t* IDC_SPLIT_CALLER4 = L"IDC_SPLIT_CALLER4";
90 static const wchar_t* IDC_CALLER4_LABEL = L"IDC_CALLER4_LABEL";
91 static const wchar_t* IDC_END_CALLER5 = L"IDC_END_CALLER5";
92 static const wchar_t* IDC_SPLIT_CALLER5 = L"IDC_SPLIT_CALLER5";
93 static const wchar_t* IDC_CALLER5_LABEL = L"IDC_CALLER5_LABEL";
94 static const wchar_t* IDC_CONF_CALL_LIST_TABLEVIEW = L"IDC_CONF_CALL_LIST_TABLEVIEW";
95
96 //color
97 const unsigned int COLOR_END_CALL_BG = Color32<180, 60, 60>::Value;
98 const unsigned int COLOR_END_CALL_BG_PRESS = Color32<61, 153, 208>::Value;
99 const unsigned int COLOR_SPLIT_CALL_BG = Color32<129, 140, 148>::Value;
100 const unsigned int COLOR_SPLIT_CALL_BG_PRESS = Color32<63, 155, 210>::Value;
101 ConfCallerListForm::ConfCallerListForm(void)
102 : BaseForm(FORMTYPE_CONFCALLLIST)
103 {
104         __pConfCallInfo = null;
105         __pConfCallTimer = null;
106         __isCallSplit = false;
107         __pAddressbook = null;
108 }
109
110 ConfCallerListForm::~ConfCallerListForm(void)
111 {
112         if (__pConfCallTimer != null)
113         {
114                 __pConfCallTimer->Cancel();
115                 delete __pConfCallTimer;
116         }
117 }
118
119 void
120 ConfCallerListForm::Initialize(void)
121 {
122         Construct(IDL_CONFCALL_LIST_FORM);
123 }
124
125 result
126 ConfCallerListForm::OnInitializing(void)
127 {
128         result r = E_SUCCESS;
129         //Add action listener to buttons
130         AddActionListener(IDC_END_CONFCALL_BUTTON, IDA_END_CONF_CALL);
131         AddActionListener(IDC_HOLD_CONFCALL_BUTTON, IDA_HOLD_CONF_CALL);
132
133         Footer* pFooter = GetFooter();
134         if(pFooter != null)
135         {
136                 SetFormBackEventListener(this);
137         }
138         Label* pTimerLbl = static_cast<Label*>(GetControl(IDC_CALL_TIME_LABEL));
139         SetControlAlwaysOnTop(*pTimerLbl,true);
140
141         CreateTableView();
142         __pCallPresentor = CallPresentationModel::GetInstance();
143         return r;
144 }
145
146 void
147 ConfCallerListForm::CreateTableView(void)
148 {
149         __pList = static_cast <TableView*> (GetControl(IDC_CONF_CALL_LIST_TABLEVIEW));
150         __pList->SetItemProvider(this);
151         AddControl(__pList);
152 }
153
154 void
155 ConfCallerListForm::AddActionListener(const String& keyName, CommandIds cmdId)
156 {
157         Button* pButtonKeypad = static_cast<Button*>(GetControl(keyName));
158         if (pButtonKeypad != null)
159         {
160                 pButtonKeypad->SetActionId(cmdId);
161                 pButtonKeypad->AddActionEventListener(*this);
162         }
163 }
164
165 result
166 ConfCallerListForm::OnTerminating(void)
167 {
168         result r = E_SUCCESS;
169
170         if (__pCallPresentor != null)
171         {
172                 __pCallPresentor = null;
173         }
174
175         if (__pConfCallInfo != null)
176         {
177                 delete __pConfCallInfo;
178                 __pConfCallInfo = null;
179         }
180
181         //RemoveAllControls();
182         return r;
183 }
184
185 void
186 ConfCallerListForm::OnActionPerformed(const Control& source, int actionId)
187 {
188         SceneManager* pSceneManager = SceneManager::GetInstance();
189         AppAssert(pSceneManager);
190
191         switch (actionId)
192         {
193         case IDA_END_CONF_CALL:
194         {
195                 bool success = __pCallPresentor->EndConferenceCall();
196                 if (success == true)
197                 {
198                         delete __pConfCallInfo;
199                         __pConfCallInfo = null;
200                 }
201         }
202         break;
203
204         case IDA_HOLD_CONF_CALL:
205         {
206                 // User has pressed end conference call and we are waiting for TAPI response
207                 if(__pConfCallInfo == null)
208                 {
209                         return;
210                 }
211                 bool success = true;
212                 bool isCallOnHold = __pConfCallInfo->IsOnHold();
213                 if (isCallOnHold == false)
214                 {
215                         success = __pCallPresentor->HoldConferenceCall();
216                 }
217                 else
218                 {
219                         success = __pCallPresentor->ActivateConferenceCall();
220                 }
221
222                 //Check if request to Hold / UnHold call is successful.
223                 if(success == true)
224                 {
225                         //If success, then invert the Hold status in conference call
226                         isCallOnHold = !(isCallOnHold);
227                         __pConfCallInfo->SetOnHold(isCallOnHold);
228                         //update tableview
229                         __pList->UpdateTableView();
230                         SetHoldButtonStatus(isCallOnHold);
231                 }
232         }
233         break;
234
235         case IDA_BACK_EVENT:
236         {
237                 ArrayListT<AppCallInfo>* pCallList  = static_cast<ArrayListT<AppCallInfo>*>(__pCallPresentor->GetCallListN());
238                 int noOfCalls = pCallList->GetCount();
239
240                 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
241                 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
242                 pCallInfoList->Construct(noOfCalls);
243
244                 for (int index = 0; index < noOfCalls; index++)
245                 {
246                         //fetch call info and add to list
247                         AppCallInfo callInfo;
248                         result r = pCallList->GetAt(index, callInfo);
249                         if (r == E_SUCCESS)
250                         {
251                                 //copy call information to new instance
252                                 AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
253                                 *pCaller = callInfo;
254                                 pCallInfoList->Add(pCaller);
255                         }
256                 }
257
258                 if (noOfCalls == 1)
259                 {
260                         //single active call - goto active call form
261                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL,
262                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
263                 }
264                 else
265                 {
266                         //goto multiple active call form
267                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL,
268                                         SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
269                 }
270                 pCallList->RemoveAll();
271                 delete pCallList;
272         }
273         break;
274
275         case IDA_SPLIT_CALLER1:
276         case IDA_SPLIT_CALLER2:
277         case IDA_SPLIT_CALLER3:
278         case IDA_SPLIT_CALLER4:
279         case IDA_SPLIT_CALLER5:
280         {
281                 // User has pressed end conference call and we are waiting for TAPI response
282                 if(__pConfCallInfo == null)
283                 {
284                         break;
285                 }
286                 __isCallSplit = __pCallPresentor->SplitFromConference(SplitConfCallerCmdIds(actionId),__pConfCallInfo->GetCallerList());
287                 if(__isCallSplit == true)
288                 {
289                         __pList->UpdateTableView();
290                 }
291         }
292         break;
293
294         case IDA_END_CALLER1:
295         case IDA_END_CALLER2:
296         case IDA_END_CALLER3:
297         case IDA_END_CALLER4:
298         case IDA_END_CALLER5:
299         {
300                 // User has pressed end conference call and we are waiting for TAPI response
301                 if(__pConfCallInfo == null)
302                 {
303                         break;
304                 }
305                 __pCallPresentor->EndCallFromConference(EndConfCallerCmdIds(actionId),__pConfCallInfo->GetCallerList());
306         }
307         break;
308
309         default:
310                 break;
311         }
312 }
313
314 void
315 ConfCallerListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
316 {
317         //set itself as listener
318         __pCallPresentor->SetTelEventListener(this);
319         __isCallSplit = false;
320
321         AppLogDebug("Enter");
322
323         //DisableAllControls();
324         if (__pConfCallInfo != null)
325         {
326                 delete __pConfCallInfo;
327                 __pConfCallInfo = null;
328         }
329         //show 1st caller's info.
330         //Fetch Conference call info from telephony manager
331         __pConfCallInfo = __pCallPresentor->GetConferenceCallInfoN();
332         AppLogDebug("Enter %x",__pConfCallInfo);
333
334         AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
335         __pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
336         if(__pAddressbook != null)
337         {
338                 __pAddressbook->SetAddressbookChangeEventListener(this);
339         }
340
341         //show active call timer
342         ShowTimerInfo(IDC_CALL_TIME_LABEL, __pConfCallInfo->GetCallConnectTime());
343
344         //Set the correct bitmap to the "hold" button based on the current state of the call
345         SetHoldButtonStatus(__pConfCallInfo->IsOnHold());
346         //disable Hold Button, if 2 active calls are present,Else enable it.
347         Button* pButtonHold = static_cast<Button*>(GetControl(IDC_HOLD_CONFCALL_BUTTON));
348         if(pButtonHold != null)
349         {
350                 if (__pCallPresentor->GetCurrentCallCount() == IDI_MAX_ACTIVE_CALLS)
351                 {
352                         pButtonHold->SetShowState(false);
353                 }
354                 else
355                 {
356                         pButtonHold->SetShowState(true);
357                 }
358                 pButtonHold->Invalidate(true);
359         }
360
361         __pList->UpdateTableView();
362         AddOrientationEventListener(*this);
363 }
364
365 void
366 ConfCallerListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
367 {
368         RemoveOrientationEventListener(*this);
369         if (__pConfCallTimer != null)
370         {
371                 __pConfCallTimer->Cancel();
372                 delete __pConfCallTimer;
373                 __pConfCallTimer = null;
374         }
375         if(__pAddressbook != null)
376         {
377                 __pAddressbook->SetAddressbookChangeEventListener(null);
378         }
379 }
380
381 result
382 ConfCallerListForm::OnDraw(void)
383 {
384         return E_SUCCESS;
385 }
386
387 void
388 ConfCallerListForm::SetHoldButtonStatus(bool isCallOnHold)
389 {
390         Button* pButtonHold = static_cast<Button*>(GetControl(IDC_HOLD_CONFCALL_BUTTON));
391         if(pButtonHold != null)
392         {
393                 Bitmap* pNormalBitmapToBeDrawn = null;
394                 Bitmap* pPressBitmapToBeDrawn = null;
395
396                 if (isCallOnHold == true)
397                 {
398                         pNormalBitmapToBeDrawn = AppUtility::GetBitmapFromResourcesN(IDB_UNHOLD_NORMAL_BUTTON_ICON,
399                                         W_HOLD_BITMAP, W_HOLD_BITMAP);
400                         pPressBitmapToBeDrawn = AppUtility::GetBitmapFromResourcesN(IDB_UNHOLD_PRESS_BUTTON_ICON,
401                                         W_HOLD_BITMAP, W_HOLD_BITMAP);
402                 }
403                 else
404                 {
405                         pNormalBitmapToBeDrawn = AppUtility::GetBitmapFromResourcesN(IDB_HOLD_NORMAL_BUTTON_ICON,
406                                         W_HOLD_BITMAP, W_HOLD_BITMAP);
407                         pPressBitmapToBeDrawn = AppUtility::GetBitmapFromResourcesN(IDB_HOLD_PRESS_BUTTON_ICON,
408                                         W_HOLD_BITMAP, W_HOLD_BITMAP);
409                 }
410
411                 if (pNormalBitmapToBeDrawn)
412                 {
413                         pButtonHold->SetNormalBitmap(Point(0, 0), *pNormalBitmapToBeDrawn);
414                 }
415                 if (pPressBitmapToBeDrawn)
416                 {
417                         pButtonHold->SetPressedBitmap(Point(0, 0), *pPressBitmapToBeDrawn);
418                 }
419
420                 pButtonHold->Invalidate(true);
421                 delete pNormalBitmapToBeDrawn;
422                 pNormalBitmapToBeDrawn = null;
423                 delete pPressBitmapToBeDrawn;
424                 pPressBitmapToBeDrawn = null;
425         }
426 }
427
428 void
429 ConfCallerListForm::HandleParticipantsChanged(void)
430 {
431         AppLogDebug("Enter");
432         AppCallInfo* pCallInfo = __pCallPresentor->GetConferenceCallInfoN();
433         if (pCallInfo == null)
434         {
435                 return;
436         }
437         if (__pConfCallInfo != null)
438         {
439                 delete __pConfCallInfo;
440                 __pConfCallInfo = null;
441         }
442         __pConfCallInfo = new (std::nothrow) AppCallInfo();
443         *__pConfCallInfo = *pCallInfo;
444         __pList->UpdateTableView();
445 }
446
447 void
448 ConfCallerListForm::DisableAllControls(void)
449 {
450         Panel* pKeysPanel = static_cast<Panel*>(GetControl(IDC_CALLER1_PANEL));
451         if (pKeysPanel != null)
452         {
453                 pKeysPanel->SetShowState(false);
454                 Label* pLineLabel1 = static_cast<Label*>(GetControl(IDC__LINE_LABEL1));
455                 pLineLabel1->SetShowState(false);
456                 pKeysPanel = null;
457         }
458         pKeysPanel = static_cast<Panel*>(GetControl(IDC_CALLER2_PANEL));
459         if (pKeysPanel != null)
460         {
461                 pKeysPanel->SetShowState(false);
462                 Label* pLineLabel1 = static_cast<Label*>(GetControl(IDC__LINE_LABEL2));
463                 pLineLabel1->SetShowState(false);
464                 pKeysPanel = null;
465         }
466         pKeysPanel = static_cast<Panel*>(GetControl(IDC_CALLER3_PANEL));
467         if (pKeysPanel != null)
468         {
469                 pKeysPanel->SetShowState(false);
470                 Label* pLineLabel1 = static_cast<Label*>(GetControl(IDC__LINE_LABEL3));
471                 pLineLabel1->SetShowState(false);
472                 pKeysPanel = null;
473         }
474         pKeysPanel = static_cast<Panel*>(GetControl(IDC_CALLER4_PANEL));
475         if (pKeysPanel != null)
476         {
477                 pKeysPanel->SetShowState(false);
478                 Label* pLineLabel1 = static_cast<Label*>(GetControl(IDC__LINE_LABEL4));
479                 pLineLabel1->SetShowState(false);
480                 pKeysPanel = null;
481         }
482         pKeysPanel = static_cast<Panel*>(GetControl(IDC_CALLER5_PANEL));
483         if (pKeysPanel != null)
484         {
485                 pKeysPanel->SetShowState(false);
486                 Label* pLineLabel1 = static_cast<Label*>(GetControl(IDC__LINE_LABEL5));
487                 pLineLabel1->SetShowState(false);
488                 pKeysPanel = null;
489         }
490 }
491
492 void
493 ConfCallerListForm::ShowTimerInfo(const String& timerLblName, long long startTime)
494 {
495         Label* pTimerLbl = static_cast<Label*>(GetControl(timerLblName));
496
497         if (__pConfCallTimer == null)
498         {
499                 __pConfCallTimer = new (std::nothrow) Timer();
500                 __pConfCallTimer->Construct(*this);
501         }
502
503         if (pTimerLbl != null)
504         {
505                 //current system time
506                 long long currTime = 0;
507                 SystemTime::GetTicks(currTime);
508                 //Set call duration
509                 TimeSpan diffSpan(abs(startTime - currTime));
510
511                 String activeCallTime(L"");
512
513                 long long hr = diffSpan.GetHours();
514                 if (hr <= 9) {
515                         activeCallTime.Append("0");
516                 }
517                 activeCallTime.Append(hr);
518                 activeCallTime.Append(L":");
519
520                 long long min = diffSpan.GetMinutes();
521                 if (min <= 9) {
522                         activeCallTime.Append("0");
523                 }
524                 activeCallTime.Append(min);
525                 activeCallTime.Append(L":");
526
527                 long long sec = diffSpan.GetSeconds();
528                 if (sec <= 9) {
529                         activeCallTime.Append("0");
530                 }
531                 activeCallTime.Append(sec);
532
533                 pTimerLbl->SetText(activeCallTime);
534                 __pConfCallTimer->StartAsRepeatable(TimeSpan::NUM_OF_TICKS_IN_SECOND);
535
536         }
537 }
538
539 void
540 ConfCallerListForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
541 {
542         //Call default implementation of "Object.Equals()"
543         //returns true, if they are pointing to same address.
544         if (__pConfCallTimer->Equals(timer))
545         {
546                 Label* pTimerLbl = static_cast<Label*>(GetControl(IDC_CALL_TIME_LABEL));
547                 if (pTimerLbl)
548                 {
549                         String activeCallTime = pTimerLbl->GetText();
550                         // Create a StringTokenizer instance
551                         StringTokenizer strTokens(activeCallTime, L":");
552
553                         int count = strTokens.GetTokenCount(); // count == 3
554                         String token;
555                         int sec = 0;
556                         int min = 0;
557                         int hr = 0;
558                         for (int index = 0; index < count; index++)
559                         {
560                                 switch (index)
561                                 {
562                                 case 0:
563                                         strTokens.GetNextToken(token);
564                                         Integer::Parse(token, hr);
565                                         break;
566
567                                 case 1:
568                                         strTokens.GetNextToken(token);
569                                         Integer::Parse(token, min);
570                                         break;
571
572                                 case 2:
573                                         strTokens.GetNextToken(token);
574                                         Integer::Parse(token, sec);
575                                         break;
576                                 }
577                         }
578                         //update all values
579                         sec = sec + 1;
580                         if (sec == IDI_MAX_SECONDS)
581                         {
582                                 sec = 0;
583                                 min = min + 1;
584                         }
585                         if (min == IDI_MAX_MINS)
586                         {
587                                 min = 0;
588                                 hr = hr + 1;
589                         }
590
591                         //replace string
592                         activeCallTime.Clear();
593                         if (hr <= 9)
594                         {
595                                 activeCallTime.Append("0");
596                         }
597                         activeCallTime.Append(hr);
598                         activeCallTime.Append(":");
599                         if (min <= 9)
600                         {
601                                 activeCallTime.Append("0");
602                         }
603                         activeCallTime.Append(min);
604                         activeCallTime.Append(":");
605                         if (sec <= 9)
606                         {
607                                 activeCallTime.Append("0");
608                         }
609                         activeCallTime.Append(sec);
610                         //update timer label
611                         pTimerLbl->SetText(activeCallTime);
612                         pTimerLbl->Invalidate(true);
613                 }
614         }
615 }
616
617 void
618 ConfCallerListForm::OnFormBackRequested(Form& source)
619 {
620         //If the call is split then wait for it to automatically go back once it split is success
621         if(__isCallSplit == true)
622         {
623                 return;
624         }
625         SceneManager* pSceneManager = SceneManager::GetInstance();
626         AppAssert(pSceneManager);
627
628
629         ArrayListT<AppCallInfo>* pCallList  = static_cast<ArrayListT<AppCallInfo>*>(__pCallPresentor->GetCallListN());
630         int noOfCalls = pCallList->GetCount();
631
632         //Ownership - To be deleted in 'OnSceneActivatedN' of next form
633         ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
634         pCallInfoList->Construct(noOfCalls);
635
636         for (int index = 0; index < noOfCalls; index++)
637         {
638                 //fetch call info and add to list
639                 AppCallInfo callInfo;
640                 result r = pCallList->GetAt(index, callInfo);
641                 if (r == E_SUCCESS)
642                 {
643                         //copy call information to new instance
644                         AppCallInfo* pCaller = new (std::nothrow) AppCallInfo();
645                         *pCaller = callInfo;
646                         pCallInfoList->Add(pCaller);
647                 }
648         }
649
650         if (noOfCalls == 1)
651         {
652                 //single active call - goto active call form
653                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL,
654                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
655         }
656         else
657         {
658                 //goto multiple active call form
659                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MULTIPLEACTIVECALL,
660                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pCallInfoList);
661         }
662         pCallList->RemoveAll();
663         delete pCallList;
664
665 }
666
667 void
668 ConfCallerListForm::OnContactsChanged(const Tizen::Base::Collection::IList& contactChangeInfoList)
669 {
670         __pList->UpdateTableView();
671 }
672
673 void
674 ConfCallerListForm::OnCategoriesChanged(const Tizen::Base::Collection::IList& categoryChangeInfoList)
675 {
676         //No implementation
677 }
678
679 void
680 ConfCallerListForm::CreateItemAndAddActionListener( Button& splitButton,
681                 Button& endButton, Label& callerLabel, SplitConfCallerCmdIds splitCmdId,
682                 EndConfCallerCmdIds EndCmdId, const String& displayName)
683 {
684         Bitmap* pNormalSplitBitmap = null;
685         Bitmap* pPressSplitBitmap = null;
686         Bitmap* pNormalEndBitmap = null;
687         Bitmap* pPressEndBitmap = null;
688
689         pNormalSplitBitmap = AppUtility::GetBitmapFromResourcesN(IDB_SPLIT_NORMAL_BUTTON_ICON,
690                         W_SPLIT_BITMAP, H_SPLIT_BITMAP);
691         pPressSplitBitmap = AppUtility::GetBitmapFromResourcesN(IDB_SPLIT_PRESS_BUTTON_ICON,
692                         W_SPLIT_BITMAP, H_SPLIT_BITMAP);
693         pNormalEndBitmap = AppUtility::GetBitmapFromResourcesN(IDB_END_NORMAL_BUTTON_ICON,
694                         W_END_BITMAP, H_END_BITMAP);
695         pPressEndBitmap = AppUtility::GetBitmapFromResourcesN(IDB_END_PRESS_BUTTON_ICON,
696                         W_END_BITMAP, H_END_BITMAP);
697
698         bool isSplitAllowed = true;
699         if ((__pCallPresentor->IsSplitAllowed() == false) || (__pConfCallInfo->IsOnHold() == true) || (__isCallSplit == true))
700         {
701                 isSplitAllowed = false;
702         }
703
704         splitButton.SetActionId(splitCmdId);
705         splitButton.AddActionEventListener(*this);
706         splitButton.SetColor(BUTTON_STATUS_NORMAL,COLOR_SPLIT_CALL_BG);
707         splitButton.SetColor(BUTTON_STATUS_PRESSED,COLOR_SPLIT_CALL_BG_PRESS);
708         splitButton.SetNormalBitmap(Point(0, 0), *pNormalSplitBitmap);
709         splitButton.SetPressedBitmap(Point(0, 0), *pPressSplitBitmap);
710
711
712         bool isEnableEndButton = (__isCallSplit == false);
713         endButton.SetEnabled(isEnableEndButton);
714         endButton.SetActionId(EndCmdId);
715         endButton.AddActionEventListener(*this);
716         endButton.SetNormalBitmap(Point(0, 0), *pNormalEndBitmap);
717         endButton.SetColor(BUTTON_STATUS_NORMAL,COLOR_END_CALL_BG);
718         endButton.SetColor(BUTTON_STATUS_PRESSED,COLOR_END_CALL_BG_PRESS);
719         endButton.SetPressedBitmap(Point(0, 0), *pPressEndBitmap);
720
721
722         if (isSplitAllowed == false)
723         {
724                 splitButton.SetShowState(false);
725                 callerLabel.SetBounds(splitButton.GetBounds().x, callerLabel.GetBounds().y,
726                 callerLabel.GetBounds().width, callerLabel.GetBounds().height);
727         }
728         else
729         {
730                 splitButton.SetShowState(true);
731                 callerLabel.SetBounds((splitButton.GetBounds().x + splitButton.GetBounds().width), callerLabel.GetBounds().y,
732                                 callerLabel.GetBounds().width, callerLabel.GetBounds().height);
733         }
734
735
736         callerLabel.SetTextHorizontalAlignment(ALIGNMENT_LEFT);
737         callerLabel.SetText(displayName);
738         delete pNormalEndBitmap;
739         pNormalEndBitmap = null;
740         delete pPressEndBitmap;
741         pPressEndBitmap = null;
742         delete pNormalSplitBitmap;
743         pNormalSplitBitmap = null;
744         delete pPressSplitBitmap;
745         pPressSplitBitmap = null;
746 }
747
748 int
749 ConfCallerListForm::GetItemCount(void)
750 {
751         IListT<AppCallInfo>* pCallList = __pConfCallInfo->GetCallerList();
752         return pCallList->GetCount();
753 }
754
755 TableViewItem*
756 ConfCallerListForm::CreateItem(int itemIndex, int itemWidth)
757 {
758         AppLogDebug("%d %x",itemWidth,__pConfCallInfo);
759         IListT<AppCallInfo>* pCallList = __pConfCallInfo->GetCallerList();
760
761         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
762         TableViewItem* pItem = new (std::nothrow) TableViewItem();
763
764         pItem->Construct(Tizen::Graphics::Dimension(GetBounds().width, LIST_ITEM_HEIGHT), style);
765
766         Button *pSplitCallButton = new (std::nothrow) Button();
767         pSplitCallButton->Construct(Rectangle(X_SPLIT_BUTTON_MARGIN,Y_SPLIT_BUTTON_MARGIN,W_SPLIT_BITMAP,W_SPLIT_BITMAP));
768
769         Label *pCallLabel =  new (std::nothrow)Label();
770         pCallLabel->Construct(Rectangle(X_CALLER_LABEL,Y_CALLER_LABEL,W_CALLER_LABEL,H_CALLER_LABEL),L"");
771
772         Button *pEndCallButton =  new (std::nothrow)Button();
773         pEndCallButton->Construct(Rectangle(GetBounds().width-X_END_BUTTON_PADDING-W_SPLIT_BITMAP,Y_SPLIT_BUTTON_MARGIN,W_SPLIT_BITMAP,W_SPLIT_BITMAP));
774
775
776         AppCallInfo callInfo;
777         String pContactNo;
778         result r = pCallList->GetAt(itemIndex, callInfo);
779
780         if(callInfo.GetContactNumber().IsEmpty() == false)
781         {
782                 pContactNo.Append(callInfo.GetContactNumber());
783         }
784         else
785         {
786                 pContactNo.Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
787         }
788         //fetch contact details based on phone number
789         String* pDisplayName = callInfo.FetchLatestCallerNameN(pContactNo);
790
791         if(pDisplayName != null)
792         {
793                 if ((pDisplayName->IsEmpty()) || r != E_SUCCESS)
794                 {
795                         pDisplayName->Append(pContactNo);
796                 }
797                 switch (itemIndex)
798                 {
799                         case 0:
800                         {
801                                 CreateItemAndAddActionListener(*pSplitCallButton,*pEndCallButton,*pCallLabel,
802                                                 IDA_SPLIT_CALLER1,IDA_END_CALLER1,*pDisplayName);
803                         }
804                         break;
805                         case 1:
806                         {
807                                 CreateItemAndAddActionListener(*pSplitCallButton,*pEndCallButton,*pCallLabel,
808                                                 IDA_SPLIT_CALLER2,IDA_END_CALLER2,*pDisplayName);
809                         }
810                         break;
811                         case 2:
812                         {
813                                 CreateItemAndAddActionListener(*pSplitCallButton,*pEndCallButton,*pCallLabel,
814                                                 IDA_SPLIT_CALLER3,IDA_END_CALLER3,*pDisplayName);
815                         }
816                         break;
817                         case 3:
818                         {
819                                 CreateItemAndAddActionListener(*pSplitCallButton,*pEndCallButton,*pCallLabel,
820                                                 IDA_SPLIT_CALLER4,IDA_END_CALLER4,*pDisplayName);
821                         }
822                         break;
823                         case 4:
824                         {
825                                 CreateItemAndAddActionListener(*pSplitCallButton,*pEndCallButton,*pCallLabel,
826                                                 IDA_SPLIT_CALLER5,IDA_END_CALLER5,*pDisplayName);
827                         }
828                         break;
829                         default:
830                                 break;
831                 }
832         }
833         pItem->AddControl(pSplitCallButton);
834         pItem->AddControl(pCallLabel);
835         pItem->AddControl(pEndCallButton);
836         if(pDisplayName != null)
837         {
838                 delete pDisplayName;
839                 pDisplayName = null;
840         }
841         return pItem;
842
843
844 }
845
846 bool
847 ConfCallerListForm::DeleteItem(int itemIndex, TableViewItem* pItem)
848 {
849         delete pItem;
850         pItem = null;
851         return true;
852 }
853
854 void
855 ConfCallerListForm::UpdateItem(int itemIndex, TableViewItem* pItem)
856 {
857         return ;
858 }
859
860 int
861 ConfCallerListForm::GetDefaultItemHeight(void)
862 {
863         return LIST_ITEM_HEIGHT;
864 }
865
866 void
867 ConfCallerListForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
868 {
869         AppLogDebug("Enter");
870         __pList->UpdateTableView();
871 }