Fixed Nabi issues N_SE-29062 N_SE-28663 N_SE-26280 N_SE-26281 N_SE-25992 N_SE-29298...
[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         SetMinimumSize(Dimension(W_POPUP + HORIZONTAL_PADDING, popupHeight));
84         TryReturn(r == E_SUCCESS, r, "CallOptionPopup::SetMinSize() failed");
85
86         String strText;
87         Application::GetInstance()->GetAppResource()->GetString(L"IDS_CANCEL", strText);
88         Button* pCancelButton = new (std::nothrow) Button();
89         r = pCancelButton->Construct(Rectangle(VERTICAL_PADDING, listHeight + CANCEL_BUTTON_PADDING , W_CANCEL_BUTTON, H_CANCEL_BUTTON), strText);
90         pCancelButton->SetActionId(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
91         pCancelButton->AddActionEventListener(*this);
92         r = AddControl(*pCancelButton);
93         TryReturn(r == E_SUCCESS, r, "CallOptionPopup::AddControl() failed");
94
95         ListView* pListView = new (std::nothrow) ListView();
96         pListView->Construct(Rectangle(0, 0, W_POPUP, listHeight), true, SCROLL_STYLE_FADE_OUT);
97         pListView->AddListViewItemEventListener(*this);
98         pListView->SetItemProvider(*this);
99         r = AddControl(*pListView);
100
101
102
103         return r;
104 }
105
106 result
107 CallOptionPopup::ConstructListData(void)
108 {
109         result r = E_FAILURE;
110
111         //fetch active call list
112         ArrayListT<CallInfo>* pCallList  = static_cast<ArrayListT<CallInfo>*>(__callPresenter.GetCallListN());
113         if (pCallList != null && pCallList->GetCount() > 0)
114         {
115                 String optionStr(L"");
116                 String* pFirstOption = new (std::nothrow) String();
117                 String* pSecondOption = new (std::nothrow) String();
118                 String* pThirdOption = null;
119                 if (pCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
120                 {
121                         //2 calls(Active+Held) present - 3 options are shown
122                         for (int index = 0;index < pCallList->GetCount(); index++)
123                         {
124                                 CallInfo callInfo;
125                                 pCallList->GetAt(index,callInfo);
126
127                                 optionStr.Clear();
128                                 if (callInfo.IsConferenceCall() == true)
129                                 {
130                                         String option = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");;
131                                         if (callInfo.IsOnHold() == true)
132                                         {
133                                                 option = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
134                                         }
135                                         optionStr.Format(option.GetLength(), option.GetPointer(), callInfo.GetCallerListCount());
136                                 }
137                                 else
138                                 {
139                                         //show display name, if available, Else show contact number
140                                         String* pDisplayName = callInfo.FetchCallerNameN();
141                                         if (pDisplayName->IsEmpty() == true)
142                                         {
143                                                 //If contact number is also not present show unknown
144                                                 if(callInfo.GetContactNumber().IsEmpty() == false)
145                                                 {
146                                                         pDisplayName->Append(callInfo.GetContactNumber());
147                                                 }
148                                                 else
149                                                 {
150                                                         pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
151                                                 }
152                                         }
153                                         optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION5");
154                                         optionStr.Append(*pDisplayName);
155                                         delete pDisplayName;
156                                 }
157
158                                 //Check whether to show as 1st or 2nd option
159                                 if (callInfo.IsOnHold() == false)
160                                 {
161                                         pFirstOption->Append(optionStr);
162                                 }
163                                 else
164                                 {
165                                         pSecondOption->Append(optionStr);
166                                 }
167                         }
168                         //3rd Option
169                         pThirdOption = new (std::nothrow) String();
170                         pThirdOption->Append(AppUtility::GetResourceString(L"IDS_CALL_OPTION6"));
171                 }
172                 else
173                 {
174                         //only one call - 2 options are shown.
175                         CallInfo firstCallInfo;
176                         pCallList->GetAt(0,firstCallInfo);
177                         if (firstCallInfo.IsConferenceCall() == false)
178                         {
179                                 //show display name if available, else show contact number
180                                 String* pDisplayName = firstCallInfo.FetchCallerNameN();
181                                 if (pDisplayName->IsEmpty() == true)
182                                 {
183                                         if(firstCallInfo.GetContactNumber().IsEmpty() == false)
184                                         {
185                                                 pDisplayName->Append(firstCallInfo.GetContactNumber());
186                                         }
187                                         else
188                                         {
189                                                 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
190                                         }
191                                 }
192                                 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION1");
193                                 pFirstOption->Format((optionStr.GetLength() + pDisplayName->GetLength()),optionStr.GetPointer(),pDisplayName->GetPointer());
194                                 //2nd option
195                                 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION2");
196                                 pSecondOption->Append(optionStr + *pDisplayName);
197                                 delete pDisplayName;
198                         }
199                         else
200                         {
201                                 String optionStr2(L"");
202                                 if (firstCallInfo.IsOnHold() == true)
203                                 {
204                                         optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION8");
205                                         optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
206                                 }
207                                 else
208                                 {
209                                         optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION7");
210                                         optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
211                                 }
212                                 pFirstOption->Format(optionStr.GetLength(), optionStr.GetPointer(), firstCallInfo.GetCallerListCount());
213                                 pSecondOption->Format(optionStr2.GetLength(), optionStr2.GetPointer(), firstCallInfo.GetCallerListCount());
214                         }
215                 }
216                 //show options
217                 __pOptionsList =  new (std::nothrow) ArrayList(SingleObjectDeleter);
218                 __pOptionsList->Construct();
219                 __pOptionsList->Add(pFirstOption);
220                 __pOptionsList->Add(pSecondOption);
221                 if (pThirdOption != null)
222                 {
223                         __pOptionsList->Add(pThirdOption);
224                 }
225                 r = E_SUCCESS;
226                 pCallList->RemoveAll();
227         }
228         delete pCallList;
229         return r;
230 }
231
232 void
233 CallOptionPopup::OnListViewItemStateChanged(ListView& listView, int index,
234                 int elementId, ListItemStatus status)
235 {
236         Popup::SetShowState(false);
237         __popupListener.OnItemSelected(elementId);
238         return;
239 }
240
241 int
242 CallOptionPopup::GetItemCount(void)
243 {
244         if (__pOptionsList != null)
245         {
246                 return __pOptionsList->GetCount();
247         }
248         return 0;
249 }
250
251 ListItemBase*
252 CallOptionPopup::CreateItem(int index, int itemWidth)
253 {
254         int elementId = ANSERWING_OPTION_HOLD_SINGLE_CALL;
255         String* strText = static_cast<String*>(__pOptionsList->GetAt(index));
256         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
257         CustomItem* pItem = new CustomItem();
258         pItem->Construct(Dimension(itemWidth, W_LIST_ITEM), style);
259         if (__pOptionsList->GetCount() == 2)
260         {
261                 if(index == 1)
262                 {
263                         elementId = ANSERWING_OPTION_END_SINGLE_CALL;
264                 }
265         }
266         else
267         {
268                 elementId = ANSERWING_OPTION_REPLACE_ACTIVE_CALL;
269                 if(index == 1)
270                 {
271                         elementId = ANSERWING_OPTION_REPLACE_HELD_CALL;
272                 }
273                 else if(index == 2)
274                 {
275                         elementId = ANSERWING_OPTION_END_ALL_CALLS;
276                 }
277         }
278         pItem->AddElement(Rectangle(HORIZONTAL_PADDING, 0, W_POPUP - HORIZONTAL_PADDING, H_LIST_ITEM), elementId, *strText);
279         return pItem;
280 }
281
282 bool
283 CallOptionPopup::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
284 {
285         delete pItem;
286         pItem = null;
287         return true;
288 }
289
290 void
291 CallOptionPopup::OnActionPerformed(const Control& source, int actionId)
292 {
293         switch (actionId)
294         {
295         case IDA_BUTTON_CANCEL_OPTIONS_POPUP:
296         {
297                 Popup::SetShowState(false);
298                 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
299         }
300         break;
301
302         default:
303                 break;
304         }
305 }