ce619b66acdcfeadce6116d3a86590ba85ff1fd4
[apps/osp/Call.git] / src / CallOptionPopup.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        CallCallOptionPopup.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 "CallOptionPopup.h"
29 #include "CallAppUtility.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         : __pOptionsList(null)
55         , __popupListener(listener)
56         , __callPresenter(callPresenter)
57 {
58 }
59
60 CallOptionPopup::~CallOptionPopup(void)
61 {
62         if (__pOptionsList != null)
63         {
64                 delete __pOptionsList;
65                 __pOptionsList = null;
66         }
67 }
68
69 result
70 CallOptionPopup::Initialize(void)
71 {
72         result r = E_SUCCESS;
73         r = Construct(IDL_CALL_OPTION_POPUP);
74         TryReturn(r == E_SUCCESS, r, "CallOptionPopup construction failed");
75
76         r = ConstructListData();
77         TryReturn(r == E_SUCCESS, r, "List data not available");
78
79         int listHeight = H_LIST_ITEM * __pOptionsList->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 result
103 CallOptionPopup::ConstructListData(void)
104 {
105         result r = E_FAILURE;
106
107         //fetch active call list
108         ArrayListT<CallInfo>* pCallList  = static_cast<ArrayListT<CallInfo>*>(__callPresenter.GetCallListN());
109         if (pCallList != null && pCallList->GetCount() > 0)
110         {
111                 String optionStr(L"");
112                 String* pFirstOption = new (std::nothrow) String();
113                 String* pSecondOption = new (std::nothrow) String();
114                 String* pThirdOption = null;
115                 if (pCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
116                 {
117                         //2 calls(Active+Held) present - 3 options are shown
118                         for (int index = 0;index < pCallList->GetCount(); index++)
119                         {
120                                 CallInfo callInfo;
121                                 pCallList->GetAt(index,callInfo);
122
123                                 optionStr.Clear();
124                                 if (callInfo.IsConferenceCall() == true)
125                                 {
126                                         String option = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");;
127                                         if (callInfo.IsOnHold() == true)
128                                         {
129                                                 option = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
130                                         }
131                                         optionStr.Format(option.GetLength(), option.GetPointer(), callInfo.GetCallerListCount());
132                                 }
133                                 else
134                                 {
135                                         //show display name, if available, Else show contact number
136                                         String* pDisplayName = callInfo.FetchCallerNameN();
137                                         if (pDisplayName->IsEmpty() == true)
138                                         {
139                                                 //If contact number is also not present show unknown
140                                                 if(callInfo.GetContactNumber().IsEmpty() == false)
141                                                 {
142                                                 pDisplayName->Append(callInfo.GetContactNumber());
143                                         }
144                                                 else
145                                                 {
146                                                         pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
147                                                 }
148                                         }
149                                         optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION5");
150                                         optionStr.Append(*pDisplayName);
151                                         delete pDisplayName;
152                                 }
153
154                                 //Check whether to show as 1st or 2nd option
155                                 if (callInfo.IsOnHold() == false)
156                                 {
157                                         pFirstOption->Append(optionStr);
158                                 }
159                                 else
160                                 {
161                                         pSecondOption->Append(optionStr);
162                                 }
163                         }
164                         //3rd Option
165                         pThirdOption = new (std::nothrow) String();
166                         pThirdOption->Append(AppUtility::GetResourceString(L"IDS_CALL_OPTION6"));
167                 }
168                 else
169                 {
170                         //only one call - 2 options are shown.
171                         CallInfo firstCallInfo;
172                         pCallList->GetAt(0,firstCallInfo);
173                         if (firstCallInfo.IsConferenceCall() == false)
174                         {
175                                 //show display name if available, else show contact number
176                                 String* pDisplayName = firstCallInfo.FetchCallerNameN();
177                                 if (pDisplayName->IsEmpty() == true)
178                                 {
179                                         if(firstCallInfo.GetContactNumber().IsEmpty() == false)
180                                         {
181                                         pDisplayName->Append(firstCallInfo.GetContactNumber());
182                                         }
183                                         else
184                                         {
185                                                 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
186                                         }
187                                 }
188                                 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION1");
189                                 pFirstOption->Format((optionStr.GetLength() + pDisplayName->GetLength()),optionStr.GetPointer(),pDisplayName->GetPointer());
190                                 //2nd option
191                                 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION2");
192                                 pSecondOption->Append(optionStr + *pDisplayName);
193                                 delete pDisplayName;
194                         }
195                         else
196                         {
197                                 String optionStr2(L"");
198                                 if (firstCallInfo.IsOnHold() == true)
199                                 {
200                                         optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION8");
201                                         optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
202                                 }
203                                 else
204                                 {
205                                         optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION7");
206                                         optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
207                                 }
208                                 pFirstOption->Format(optionStr.GetLength(), optionStr.GetPointer(), firstCallInfo.GetCallerListCount());
209                                 pSecondOption->Format(optionStr2.GetLength(), optionStr2.GetPointer(), firstCallInfo.GetCallerListCount());
210                         }
211                 }
212                 //show options
213                 __pOptionsList =  new (std::nothrow) ArrayList(SingleObjectDeleter);
214                 __pOptionsList->Construct();
215                 __pOptionsList->Add(pFirstOption);
216                 __pOptionsList->Add(pSecondOption);
217                 if (pThirdOption != null)
218                 {
219                         __pOptionsList->Add(pThirdOption);
220                 }
221                 r = E_SUCCESS;
222                 pCallList->RemoveAll();
223         }
224         delete pCallList;
225         return r;
226 }
227
228 void
229 CallOptionPopup::OnListViewItemStateChanged(ListView& listView, int index,
230                 int elementId, ListItemStatus status)
231 {
232         Popup::SetShowState(false);
233         __popupListener.OnItemSelected(elementId);
234         return;
235 }
236
237 int
238 CallOptionPopup::GetItemCount(void)
239 {
240         if (__pOptionsList != null)
241         {
242                 return __pOptionsList->GetCount();
243         }
244         return 0;
245 }
246
247 ListItemBase*
248 CallOptionPopup::CreateItem(int index, int itemWidth)
249 {
250         int elementId = ANSERWING_OPTION_HOLD_SINGLE_CALL;
251         String* strText = static_cast<String*>(__pOptionsList->GetAt(index));
252         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
253         CustomItem* pItem = new CustomItem();
254         pItem->Construct(Dimension(itemWidth, W_LIST_ITEM), style);
255         if (__pOptionsList->GetCount() == 2)
256         {
257                 if(index == 1)
258                 {
259                         elementId = ANSERWING_OPTION_END_SINGLE_CALL;
260                 }
261         }
262         else
263         {
264                 elementId = ANSERWING_OPTION_REPLACE_ACTIVE_CALL;
265                 if(index == 1)
266                 {
267                         elementId = ANSERWING_OPTION_REPLACE_HELD_CALL;
268                 }
269                 else if(index == 2)
270                 {
271                         elementId = ANSERWING_OPTION_END_ALL_CALLS;
272                 }
273         }
274         pItem->AddElement(Rectangle(HORIZONTAL_PADDING, 0, W_POPUP - HORIZONTAL_PADDING, H_LIST_ITEM), elementId, *strText);
275         return pItem;
276 }
277
278 bool
279 CallOptionPopup::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
280 {
281         delete pItem;
282         pItem = null;
283         return true;
284 }
285
286 void
287 CallOptionPopup::OnActionPerformed(const Control& source, int actionId)
288 {
289         switch (actionId)
290         {
291         case IDA_BUTTON_CANCEL_OPTIONS_POPUP:
292         {
293                 Popup::SetShowState(false);
294                 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
295         }
296         break;
297
298         default:
299                 break;
300         }
301 }