2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file PhnTabLogs.cpp
24 #include <FGraphics.h>
25 #include "PhnPhoneApp.h"
26 #include "PhnAppUtility.h"
27 #include "PhnSettingsConstants.h"
28 #include "PhnCommonUtils.h"
29 #include "PhnTabLogs.h"
30 #include "PhnSceneRegister.h"
31 #include "PhnCalllogManager.h"
32 #include "PhnCallPresentationModel.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Media;
41 using namespace Tizen::Ui;
42 using namespace Tizen::Ui::Scenes;
44 const int W_NOCONTENTS_IMAGE = 280;
45 const int H_NOCONTENTS_IMAGE = 280;
47 const int H_TOAST_MSG = 48;
48 const int H_SELECTALL_CHK_BOX = 112;
50 const wchar_t* IDL_PANEL_LOGS = L"IDL_PANEL_LOGS";
51 const wchar_t* IDC_LABEL_SELECTED_POPUP = L"IDC_LABEL_SELECTED_POPUP";
52 const unsigned int COLOR_LABEL_SELECTED = Color32<215, 225, 232, 255>::Value;
54 DialTabLogs::DialTabLogs(void)
56 __pDataProvider = new CustomDataProvider();
58 __plogsListView = null;
60 __pButtonSelectAll = null;
63 __isSelectAll = false;
64 __selectedItemCount = 0;
69 DialTabLogs::~DialTabLogs(void)
71 if (__pDataProvider != null)
73 delete __pDataProvider;
74 __pDataProvider = null;
76 if (__pCallMgr != null)
83 DialTabLogs::Initialize(void)
85 result r = Construct(IDL_PANEL_LOGS);
86 TryCatch(r == E_SUCCESS, , "DialTabLogs::Initialise() - Fail to initialise Call log panel");
94 DialTabLogs::OnInitializing(void)
99 const Form* pForm = dynamic_cast<Form*>(GetParent());
105 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(pForm->GetLandscapeLayoutN());
106 if (pRelativeLayout != null)
108 pRelativeLayout->SetHorizontalFitPolicy(*this, FIT_POLICY_PARENT);
109 pRelativeLayout->SetVerticalFitPolicy(*this, FIT_POLICY_PARENT);
110 delete pRelativeLayout;
113 pRelativeLayout = dynamic_cast<RelativeLayout*>(pForm->GetPortraitLayoutN());
114 if (pRelativeLayout != null)
116 pRelativeLayout->SetHorizontalFitPolicy(*this, FIT_POLICY_PARENT);
117 pRelativeLayout->SetVerticalFitPolicy(*this, FIT_POLICY_PARENT);
118 delete pRelativeLayout;
121 __pFormFooter = pForm->GetFooter();
122 if (__pFormFooter != null)
124 __pFormFooter->SetShowState(true);
125 __pFormFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
126 __pFormFooter->AddActionEventListener(*this);
128 __footerItemDelete.Construct(IDA_FOOTER_LOG_DELETE);
129 String delStr = AppUtility::GetResourceString(IDS_DELETE_BTN_STRING);
130 __footerItemDelete.SetText(delStr);
131 __pFormFooter->AddItem(__footerItemDelete);
132 String cancelStr = AppUtility::GetResourceString(IDS_CANCEL_BTN_STRING);
133 __footerItemCancel.Construct(IDA_FOOTER_LOG_CANCEL);
134 __footerItemCancel.SetText(cancelStr);
137 __pButtonSelectAll = static_cast<CheckButton*>(GetControl("IDC_CHECKBUTTON_SELECTALL"));
138 if (__pButtonSelectAll != null)
140 __pButtonSelectAll->SetShowState(false);
141 __pButtonSelectAll->SetActionId(IDA_CHECKBUTTON_SELECT_ALL, IDA_CHECKBUTTON_UNSELECT_ALL);
142 __pButtonSelectAll->AddActionEventListener(*this);
143 __pButtonSelectAll->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
147 __plogsListView = new (std::nothrow) GroupedListView();
148 if (__plogsListView != null)
150 __plogsListView->Construct(Rectangle(pForm->GetX(), pForm->GetY(), pForm->GetWidth(), pForm->GetClientAreaBounds().height), GROUPED_LIST_VIEW_STYLE_INDEXED, true, SCROLL_STYLE_FADE_OUT);
151 __plogsListView->AddGroupedListViewItemEventListener(*this);
152 Bitmap* pNoContentBitmap = AppUtility::GetBitmapFromResourcesN(IDB_LOG_NO_CONTENT,W_NOCONTENTS_IMAGE,H_NOCONTENTS_IMAGE);
153 if(pNoContentBitmap != null)
155 __plogsListView->SetBitmapOfEmptyList(pNoContentBitmap);
157 __plogsListView->SetTextOfEmptyList(AppUtility::GetResourceString(IDS_NO_LOGS));
158 __plogsListView->SetTextColorOfEmptyList(Color(128,128,128));
159 r = AddControl(*__plogsListView);
160 TryCatch(r == E_SUCCESS, , "Calllog list control not added");
163 __pSelectedLabel = static_cast<Label*>(GetControl(IDC_LABEL_SELECTED_POPUP));
164 if(__pSelectedLabel != null)
166 SetControlAlwaysOnTop(*__pSelectedLabel,true);
167 __pSelectedLabel->SetBackgroundColor(COLOR_LABEL_SELECTED);
168 __pSelectedLabel->SetShowState(false);
176 DialTabLogs::OnTerminating(void)
178 result r = E_SUCCESS;
183 DialTabLogs::DeleteSelectedCalllog(void)
185 CallLogDetails* pCalllogInfo = null;
188 if(__selectedItemCount == __pCallMgr->GetAllCalllogCount())
190 __pCallMgr->DeleteAllCalllog();
191 __pDataProvider->DeleteAllItems();
195 for(int groupIndex = 0; groupIndex < __groupCount; groupIndex++)
197 itemCount = __plogsListView->GetItemCountAt(groupIndex);
198 for(int itemIndex = itemCount-1; itemIndex >=0 ; itemIndex--)
200 bool isSelected = __plogsListView->IsItemChecked(groupIndex, itemIndex);
201 if(isSelected == true)
203 __pDataProvider->GetItemAtGroupIndex(groupIndex, itemIndex, &pCalllogInfo);
204 if(pCalllogInfo != null)
206 __pCallMgr->DeleteCalllogByDbId(pCalllogInfo->GetCalllogDbId());
207 __pDataProvider->DeleteItemAtGroupIndex(groupIndex, itemIndex);
216 DialTabLogs::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
218 __pCallMgr = CallLogManager::GetInstance();
219 __pCallMgr->AddCalllogChangeListener(*this);
221 __plogsListView->SetItemProvider(*__pDataProvider);
222 //Reset the delete status
223 //SetCallLogDisplayMode(false);
225 //Check if opened in edit mode
226 if(__isEditMode == true)
228 //Check if "select all" is already selected
229 if (__pButtonSelectAll->IsSelected() == true)
231 HandleAllItemSelection();
233 //If there is no items selected the reset the display mode
234 else if(__selectedItemCount == 0)
236 SetCallLogDisplayMode(false);
240 if (__pFormFooter != null)
242 __pFormFooter->SetShowState(true);
243 __pFormFooter->SetBackButton();
244 if(__pCallMgr->GetAllCalllogCount() > 0)
246 __pFormFooter->SetItemEnabled(0, true);
250 __pFormFooter->SetItemEnabled(0, false);
256 DialTabLogs::HandleAllItemSelection(void)
258 SetListItemSelectStatus(true);
259 __itemCount = __pCallMgr->GetAllCalllogCount();
260 __selectedItemCount = __itemCount;
262 String selItemStr = L"";
263 if(__selectedItemCount > 1)
265 selItemStr = AppUtility::GetResourceString(IDS_SELECTED_ITEMS_STRING);
269 selItemStr = AppUtility::GetResourceString(IDS_SELECTED_ITEM_STRING);
271 text.Format(100, selItemStr.GetPointer(), __itemCount);
272 __pSelectedLabel->SetText(text);
273 __pSelectedLabel->Invalidate(false);
277 DialTabLogs::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
279 if (__pCallMgr != null)
281 __pCallMgr->RemoveCalllogChangeListner(*this);
284 __pFormFooter->RemoveBackButton();
288 DialTabLogs::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus state)
290 if (__isEditMode == false)
292 __pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
293 __pArgs->Construct();
294 CallLogDetails* pCalllogInfo = null;
295 __pDataProvider->GetItemAtGroupIndex(groupIndex, itemIndex, &pCalllogInfo);
296 if(pCalllogInfo != null && pCalllogInfo->GetPhoneNumber() == null)
298 //handling hidden call
301 if(pCalllogInfo != null)
303 __pArgs->Add((new String(pCalllogInfo->GetPhoneNumber())));
305 SceneManager* pSceneManager = SceneManager::GetInstance();
306 pSceneManager->GoForward( ForwardSceneTransition(IDSCN_CALL_LOG_DETAILS, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
307 SCENE_HISTORY_OPTION_NO_HISTORY), __pArgs);
313 if (state == LIST_ITEM_STATUS_CHECKED)
315 __selectedItemCount++;
317 else if (state == LIST_ITEM_STATUS_UNCHECKED)
319 __selectedItemCount--;
321 if (__selectedItemCount == __itemCount)
323 __pButtonSelectAll->SetSelected(true);
327 __pButtonSelectAll->SetSelected(false);
329 if (__selectedItemCount == 0)
331 __pFormFooter->SetItemEnabled(0, false);
332 String selStr = AppUtility::GetResourceString(IDS_SELECT_CALL_LOG);
333 __pSelectedLabel->SetText(selStr);
337 __pFormFooter->SetItemEnabled(0, true);
338 String selItemStr = L"";
339 if(__selectedItemCount > 1)
341 selItemStr = AppUtility::GetResourceString(IDS_SELECTED_ITEMS_STRING);
345 selItemStr = AppUtility::GetResourceString(IDS_SELECTED_ITEM_STRING);
347 text.Format(100, selItemStr.GetPointer(), __selectedItemCount);
348 __pSelectedLabel->SetText(text);
350 __pFormFooter->Invalidate(true);
351 __pButtonSelectAll->Invalidate(false);
352 __pSelectedLabel->Invalidate(false);
357 DialTabLogs::OnGroupedListViewContextItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListContextItemStatus state)
359 //Empty implementation
360 CallLogDetails* pCalllogInfo = null;
361 __pDataProvider->GetItemAtGroupIndex(groupIndex, itemIndex, &pCalllogInfo);
362 if(pCalllogInfo != null)
367 case IDA_LIST_ELEMENT_DELETE:
369 if(pCalllogInfo != null)
371 __pCallMgr->DeleteCalllogByDbId(pCalllogInfo->GetCalllogDbId());
372 __pDataProvider->DeleteItemAtGroupIndex(groupIndex, itemIndex);
373 if(__pCallMgr->GetAllCalllogCount() > 0)
375 __pFormFooter->SetItemEnabled(0, true);
379 __pFormFooter->SetItemEnabled(0, false);
381 __pFormFooter->Invalidate(true);
385 case IDA_LIST_ELEMENT_CALL:
387 SceneManager* pSceneManager = SceneManager::GetInstance();
388 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
389 char* pPhoneNumber = pCalllogInfo->GetPhoneNumber();
390 if(pPhoneNumber == null)
394 String phoneNumber=L"";
395 phoneNumber.Append(pPhoneNumber);
396 //make an outgoing call with given number
397 String* contactTxt = new (std::nothrow) String(phoneNumber);
398 //switch to dialing outgoing call form
399 IList* pContact = new (std::nothrow) ArrayList(SingleObjectDeleter);
400 pContact->Add(contactTxt);
401 //Check if dialing an emergency call
402 bool isEmergencyCall = pCallPresentor->IsEmergencyNumber(*contactTxt, true);
405 pSceneManager->GoForward( ForwardSceneTransition( IDSCN_SCENE_OUT_EMERGENCYCALL), pContact);
409 pSceneManager->GoForward( ForwardSceneTransition(IDSCN_SCENE_OUTCALL), pContact);
414 case IDA_LIST_ELEMENT_MESSAGE:
416 result r = E_SUCCESS;
417 char* pPhoneNumber = pCalllogInfo->GetPhoneNumber();
418 if(pPhoneNumber == null)
422 String phoneNumber=L"";
423 phoneNumber.Append(pPhoneNumber);
426 extraData.Construct();
428 extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
429 extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(phoneNumber));
431 AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
434 r = pAc->Start(null, null, &extraData, null);
439 extraData.RemoveAll(true);
443 case IDA_LIST_ELEMENT_VIDEO_CALL:
445 //todo: call once video call implemented
452 listView.UpdateList();
456 DialTabLogs::OnGroupedListViewItemSwept(GroupedListView& listView, int groupIndex, int itemIndex, SweepDirection direction)
458 //Empty implementation
462 DialTabLogs::OnActionPerformed(const Control& source, int actionId)
466 case IDA_FOOTER_LOG_DELETE:
468 if (__isEditMode == false)
470 SetCallLogDisplayMode(true);
474 //Delete selected items
475 DeleteSelectedCalllog();
476 SetCallLogDisplayMode(false);
481 case IDA_FOOTER_LOG_CANCEL:
483 SetCallLogDisplayMode(false);
487 case IDA_CHECKBUTTON_SELECT_ALL:
489 HandleAllItemSelection();
493 case IDA_CHECKBUTTON_UNSELECT_ALL:
495 SetListItemSelectStatus(false);
496 __selectedItemCount = 0;
497 String selStr = AppUtility::GetResourceString(IDS_SELECT_CALL_LOG);
498 __pSelectedLabel->SetText(selStr);
499 __pSelectedLabel->Invalidate(false);
509 DialTabLogs::SetListItemSelectStatus(bool status)
515 __isSelectAll = status;
516 for (; groupIndex < __groupCount; groupIndex++)
518 itemCount = __plogsListView->GetItemCountAt(groupIndex);
519 for (itemIndex = 0; itemIndex < itemCount; itemIndex++)
521 __plogsListView->SetItemChecked(groupIndex, itemIndex, status);
524 __pFormFooter->SetItemEnabled(0, status);
525 __pFormFooter->Invalidate(true);
526 __plogsListView->Invalidate(true);
530 DialTabLogs::SetCallLogDisplayMode(bool isEdit)
535 if(isEdit == __isEditMode)
540 for (; groupIndex < __groupCount; groupIndex++)
542 itemCount += __plogsListView->GetItemCountAt(groupIndex);
544 __itemCount = __pCallMgr->GetAllCalllogCount();//itemCount;
545 __groupCount = __plogsListView->GetGroupCount();
546 __pButtonSelectAll->SetSelected(false);
549 __isEditMode = false;
550 __pDataProvider->SetListItemStyle(false);
551 __plogsListView->SetSweepEnabled(true);
552 const Form* pForm = dynamic_cast<Form*>(GetParent());
557 __plogsListView->SetBounds(pForm->GetX(), pForm->GetY(), pForm->GetWidth(), pForm->GetClientAreaBounds().height);
558 __plogsListView->UpdateList();
559 __pFormFooter->RemoveItemAt(1);
560 __pFormFooter->SetBackButton();
561 if(__pCallMgr->GetAllCalllogCount() > 0)
563 __pFormFooter->SetItemEnabled(0, true);
567 __pFormFooter->SetItemEnabled(0, false);
570 __pButtonSelectAll->SetShowState(false);
571 __pSelectedLabel->SetShowState(false);
572 __pSelectedLabel->Invalidate(false);
577 const Form* pForm = dynamic_cast<Form*>(GetParent());
582 __pDataProvider->SetListItemStyle(isEdit);
583 __plogsListView->SetSweepEnabled(false);
585 //reset size to allow "SELECT ALL" & "TOAST MSG"
586 Rectangle newRect(pForm->GetX(), H_SELECTALL_CHK_BOX, pForm->GetWidth(), (pForm->GetClientAreaBounds().height - H_SELECTALL_CHK_BOX - H_TOAST_MSG));
587 __plogsListView->SetBounds(newRect);
589 __plogsListView->UpdateList();
590 __pFormFooter->AddItem(__footerItemCancel);
591 __pFormFooter->RemoveBackButton();
592 __pButtonSelectAll->SetShowState(true);
593 __pFormFooter->SetItemEnabled(0, false);
594 __pFormFooter->Invalidate(false);
595 __selectedItemCount = 0;
596 String selStr = AppUtility::GetResourceString(IDS_SELECT_CALL_LOG);
597 __pSelectedLabel->SetText(selStr);
598 __pSelectedLabel->SetShowState(true);
599 __pSelectedLabel->Invalidate(false);
605 DialTabLogs::UnCheckAllItems(void)
608 for(int groupIndex = 0; groupIndex < __groupCount; groupIndex++)
610 itemCount = __plogsListView->GetItemCountAt(groupIndex);
611 for(int itemIndex = itemCount-1; itemIndex >=0 ; itemIndex--)
613 bool isSelected = __plogsListView->IsItemChecked(groupIndex, itemIndex);
614 if(isSelected == true)
616 __plogsListView->SetItemChecked(groupIndex,itemIndex,false);
620 __selectedItemCount = 0;
623 void DialTabLogs::OnCalllogChanged(void)
625 // If select all was selected before and some new calls are added (Auto rejeted call)
626 //Then we will not update the call log list.
627 if(__isEditMode == false)
629 if(__pCallMgr->GetAllCalllogCount() > 0)
631 __pFormFooter->SetShowState(true);
632 __pFormFooter->SetItemEnabled(0,true);
633 __pFormFooter->Invalidate(true);
635 __plogsListView->UpdateList();
636 __plogsListView->Invalidate(false);