Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnCallOptionPopup.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        PhnCallOptionPopup.cpp
19  * @brief       Call Options Popup class
20  */
21 #include <FApp.h>
22 #include <FSocial.h>
23 #include <FSystem.h>
24 #include <FUi.h>
25 #include <FGraphics.h>
26 #include <FMedia.h>
27
28 #include "PhnCallOptionPopup.h"
29 #include "PhnAppUtility.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Base::Utility;
34 using namespace Tizen::App;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Social;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
40
41 const int W_POPUP = 620;
42 const int H_POPUP = 712;
43 const int W_CANCEL_BUTTON = 400;
44 const int H_CANCEL_BUTTON = 72;
45 const int CANCEL_BUTTON_PADDING = 20;
46 const int H_LIST_ITEM = 112;
47 const int W_LIST_ITEM = 112;
48 const int HORIZONTAL_PADDING = 16;
49 const int VERTICAL_PADDING = 110;
50 const int IDA_BUTTON_CANCEL_OPTIONS_POPUP = 502;
51 static const wchar_t* IDL_CALL_OPTION_POPUP = L"IDL_CALL_OPTION_POPUP";
52
53 CallOptionPopup::CallOptionPopup(IPopupItemSelectListener& listener, CallPresentationModel& callPresenter)
54         : __pContactList(null)
55         , __popupListener(listener)
56         , __callPresenter(callPresenter)
57 {
58
59 }
60
61 CallOptionPopup::~CallOptionPopup(void)
62 {
63         if (__pContactList)
64         {
65                 __pContactList->RemoveAll();
66                 delete __pContactList;
67                 __pContactList = null;
68         }
69 }
70
71 result
72 CallOptionPopup::Initialize(void)
73 {
74         result r = E_SUCCESS;
75         r = Construct(IDL_CALL_OPTION_POPUP);
76         TryReturn(r == E_SUCCESS, r, "CallOptionPopup construction failed");
77
78         ConstructListData();
79         int listHeight = H_LIST_ITEM * __pContactList->GetCount();
80         int popupHeight = H_CANCEL_BUTTON + listHeight + CANCEL_BUTTON_PADDING + VERTICAL_PADDING;
81         r = SetSize(Dimension(W_POPUP + HORIZONTAL_PADDING, popupHeight));
82         TryReturn(r == E_SUCCESS, r, "CallOptionPopup::SetSize() failed");
83
84         String strText;
85         Application::GetInstance()->GetAppResource()->GetString(L"IDS_CANCEL", strText);
86         Button* pCancelButton = new (std::nothrow) Button();
87         r = pCancelButton->Construct(Rectangle(VERTICAL_PADDING, listHeight + CANCEL_BUTTON_PADDING , W_CANCEL_BUTTON, H_CANCEL_BUTTON), strText);
88         pCancelButton->SetActionId(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
89         pCancelButton->AddActionEventListener(*this);
90         r = AddControl(*pCancelButton);
91         TryReturn(r == E_SUCCESS, r, "CallOptionPopup::AddControl() failed");
92
93         ListView* pListView = new (std::nothrow) ListView();
94         pListView->Construct(Rectangle(0, 0, W_POPUP - HORIZONTAL_PADDING, listHeight), true, SCROLL_STYLE_FADE_OUT);
95         pListView->AddListViewItemEventListener(*this);
96         pListView->SetItemProvider(*this);
97         r = AddControl(*pListView);
98
99         return r;
100 }
101
102 void
103 CallOptionPopup::ConstructListData(void)
104 {
105         ArrayListT<CallInfo>* pCallList  = static_cast<ArrayListT<CallInfo>*>(__callPresenter.GetCallListN());
106         if (pCallList != null)
107         {
108                 int callCount = pCallList->GetCount();
109                 switch (callCount)
110                 {
111                 case 1:
112                 {
113                         //only one call.
114                         CallInfo phnCallInfo;
115                         pCallList->GetAt(0,phnCallInfo);
116                         //show contact number
117                         String contactNo;
118                         contactNo.Append(phnCallInfo.GetContactNumber());
119                         String* displayName = phnCallInfo.FetchCallerNameN();
120                         if (displayName->IsEmpty() == true)
121                         {
122                                 displayName->Append(contactNo);
123                         }
124
125                         __pContactList =  new (std::nothrow) ArrayList();
126                         __pContactList->Construct(2);
127                         if (phnCallInfo.IsConferenceCall() == false)
128                         {
129                                 String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION1");
130                                 String* listItem1 = new (std::nothrow) String();
131                                 listItem1->Format(100,optionStr.GetPointer(),displayName->GetPointer());//(L"Putting " + *displayName + L" on hold");
132                                 __pContactList->Add(*listItem1);
133                                 optionStr.Clear();
134                                 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION2");
135                                 String* listItem2 = new (std::nothrow) String();
136                                 listItem2->Append(optionStr + *displayName);
137                                 __pContactList->Add(*listItem2);
138                         }
139                         else
140                         {
141                                 String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION7");
142                                 String* listItem1 = new (std::nothrow) String();
143                                 if (phnCallInfo.IsOnHold() == true)
144                                 {
145                                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION8");
146                                         listItem1->Format(100, optionStr.GetPointer(),phnCallInfo.GetCallerListCount());
147                                 }
148                                 else
149                                 {
150                                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION7");
151                                         listItem1->Format(100, optionStr.GetPointer(),phnCallInfo.GetCallerListCount());
152                                 }
153                                 __pContactList->Add(*listItem1);
154                                 String* listItem2 = new (std::nothrow) String();
155                                 if (phnCallInfo.IsOnHold() == true)
156                                 {
157                                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
158                                         listItem2->Format(100, optionStr.GetPointer(),phnCallInfo.GetCallerListCount());
159                                 }
160                                 else
161                                 {
162                                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
163                                         listItem2->Format(100, optionStr.GetPointer(),phnCallInfo.GetCallerListCount());
164                                 }
165                                 __pContactList->Add(*listItem2);
166                         }
167
168                         delete displayName;
169                 }
170                 break;
171
172                 case 2:
173                 {
174                         //2calls present. active call and held call
175                         CallInfo firstCallInfo;
176                         pCallList->GetAt(0,firstCallInfo);
177                         CallInfo secondCallInfo;
178                         pCallList->GetAt(1,secondCallInfo);
179                         __pContactList =  new (std::nothrow) ArrayList();
180                         __pContactList->Construct(3);
181                         //show contact number
182                         String contactNo;
183                         contactNo.Append(firstCallInfo.GetContactNumber());
184                         String* displayName = firstCallInfo.FetchCallerNameN();
185                         if (displayName->IsEmpty() == true)
186                         {
187                                 displayName->Append(contactNo);
188                         }
189                         String* listItem1 = new (std::nothrow) String();
190                         if (firstCallInfo.IsConferenceCall() == true)
191                         {
192                                 if (firstCallInfo.IsOnHold() == true)
193                                 {
194                                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
195                                         listItem1->Format(100, optionStr.GetPointer(),firstCallInfo.GetCallerListCount());
196                                 }
197                                 else
198                                 {
199                                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
200                                         listItem1->Format(100, optionStr.GetPointer(),firstCallInfo.GetCallerListCount());
201                                 }
202                         }
203                         else
204                         {
205                                 String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION5");
206                                 listItem1->Append(optionStr + *displayName );
207                         }
208                         delete displayName;
209                         contactNo.Clear();
210                         contactNo.Append(secondCallInfo.GetContactNumber());
211                         displayName = secondCallInfo.FetchCallerNameN();
212                         if (displayName->IsEmpty() == true)
213                         {
214                                 displayName->Append(contactNo);
215                         }
216                         String* listItem2 = new (std::nothrow) String();
217                         if (secondCallInfo.IsConferenceCall() == true)
218                         {
219                                 String callCountStr;
220                                 callCountStr.Append(secondCallInfo.GetCallerListCount());
221
222                                 if (secondCallInfo.IsOnHold() == true)
223                                 {
224                                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
225                                         listItem2->Format(100, optionStr.GetPointer(),secondCallInfo.GetCallerListCount());
226                                 }
227                                 else
228                                 {
229                                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
230                                         listItem2->Format(100, optionStr.GetPointer(),secondCallInfo.GetCallerListCount());
231                                 }
232                         }
233                         else
234                         {
235                                 String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION5");
236                                 listItem2->Append(optionStr + *displayName );
237                         }
238                         if (firstCallInfo.IsOnHold() == true)
239                         {
240                                 __pContactList->Add(*listItem2);
241                                 __pContactList->Add(*listItem1);
242                         }
243                         else
244                         {
245                                 __pContactList->Add(*listItem1);
246                                 __pContactList->Add(*listItem2);
247                         }
248                         String optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION6");
249                         String* listItem3 = new (std::nothrow) String();
250                         listItem3->Append(optionStr);
251                         __pContactList->Add(*listItem3);
252                         delete displayName;
253                 }
254                 break;
255
256                 default:
257                         break;
258                 }
259                 pCallList->RemoveAll();
260                 delete pCallList;
261         }
262 }
263
264 void
265 CallOptionPopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId,
266                 Tizen::Ui::Controls::ListItemStatus status)
267 {
268         Popup::SetShowState(false);
269         __popupListener.OnItemSelected(elementId);
270         return;
271 }
272
273 void
274 CallOptionPopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index,
275                 Tizen::Ui::Controls::SweepDirection direction)
276 {
277         return;
278 }
279
280 void
281 CallOptionPopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId,
282                 Tizen::Ui::Controls::ListContextItemStatus state)
283 {
284         return;
285 }
286
287 void
288 CallOptionPopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId,
289                 bool& invokeListViewItemCallback)
290 {
291         return;
292 }
293
294 int
295 CallOptionPopup::GetItemCount(void)
296 {
297         if (__pContactList != null)
298         {
299                 return __pContactList->GetCount();
300         }
301         return 0;
302 }
303
304 Tizen::Ui::Controls::ListItemBase*
305 CallOptionPopup::CreateItem(int index, int itemWidth)
306 {
307         int elementId = 0;
308         String* strText = static_cast<String*>(__pContactList->GetAt(index));
309         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
310         CustomItem* pItem = new CustomItem();
311         pItem->Construct(Dimension(itemWidth, W_LIST_ITEM), style);
312         if (__pContactList->GetCount() == 2)
313         {
314                 elementId = ID_SECOND_INCOMING_CALL + index;
315         }
316         else
317         {
318                 elementId = ID_MULTI_PARTY_CALL + index;
319         }
320         pItem->AddElement(Rectangle(HORIZONTAL_PADDING, 0, W_POPUP - HORIZONTAL_PADDING, H_LIST_ITEM), elementId, *strText);
321         return pItem;
322 }
323
324 bool
325 CallOptionPopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
326 {
327         delete pItem;
328         pItem = null;
329         return true;
330 }
331
332
333 void
334 CallOptionPopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
335 {
336         switch (actionId)
337         {
338         case IDA_BUTTON_CANCEL_OPTIONS_POPUP:
339         {
340                 Popup::SetShowState(false);
341                 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
342         }
343         break;
344
345         default:
346                 break;
347         }
348 }