2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
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 CallCallInfo.cpp
19 * @brief Call Information class
21 #include "CallAppUtility.h"
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Media;
29 using namespace Tizen::Social;
30 using namespace Tizen::Telephony;
32 AppCallInfo::AppCallInfo(void)
34 //by Default, neither a conference call nor emergency call
36 __isEmergency = false;
37 __callType = VOICE_CALL;
39 __callConnectTime = 0;
41 __callNotificationTime = 0;
43 __pEndCallCause = null;
44 __pParticipantCallHandles = null;
46 __pAddressBook = null;
49 AppCallInfo::~AppCallInfo(void)
58 delete __pEndCallCause;
61 if (__pParticipantCallHandles)
63 delete __pParticipantCallHandles;
64 __pParticipantCallHandles = null;
66 if (__pContact != null)
70 if(__pAddressBook != null)
72 delete __pAddressBook;
77 AppCallInfo::GetCallHandle(void)
83 AppCallInfo::SetCallHandle(unsigned int handle)
85 if (__pCallHandle != null)
89 __pCallHandle = new (std::nothrow) Long(handle);
93 AppCallInfo::IsConferenceCall(void)
99 AppCallInfo::SetConference(bool isConferenceCall)
101 __isConfCall = isConferenceCall;
105 AppCallInfo::IsEmergency(void)
107 return __isEmergency;
111 AppCallInfo::SetEmergency(bool isEmergency)
113 __isEmergency = isEmergency;
117 AppCallInfo::GetContactNumber(void)
119 return __contactNumber;
123 AppCallInfo::ResetContactNumber(String* contactNumber)
125 if(contactNumber == null)
127 if (__isConfCall == false)
129 __contactNumber = null;
136 AppCallInfo::ResetContactInfo(const Contact* contact)
140 if (__pContact != null)
148 AppCallInfo::SetContactNumber(String& contactNumber)
150 if (__isConfCall == false)
152 __contactNumber = contactNumber;
157 AppCallInfo::SetContactInfo(const Contact& contact)
159 if (__pContact != null)
164 __pContact = new (std::nothrow) Contact(contact);
168 AppCallInfo::IsOnHold(void)
174 AppCallInfo::SetOnHold(bool onHold)
180 AppCallInfo::GetCallConnectTime(void)
182 return __callConnectTime;
186 AppCallInfo::SetCallConnectTime(long long connectTime)
188 __callConnectTime = connectTime;
192 AppCallInfo::SetDurationTime(long long durationTime)
194 __durationTime = durationTime;
198 AppCallInfo::GetCallNotificationTime(void)
200 return __callNotificationTime;
204 AppCallInfo::GetDurationTime(void)
206 return __durationTime;
210 AppCallInfo::SetCallNotificationTime(long long callNotificationTime)
212 __callNotificationTime = callNotificationTime;
216 AppCallInfo::GetEndCallCause(void)
218 return *(__pEndCallCause);
222 AppCallInfo::SetEndCallCause(String& pEndCause)
224 if (__pEndCallCause != null)
226 delete __pEndCallCause;
228 __pEndCallCause = new (std::nothrow) String(pEndCause);
232 AppCallInfo::GetCallerList(void)
234 return __pParticipantCallHandles;
238 AppCallInfo::GetCallerListCount(void)
240 if (__pParticipantCallHandles != null)
242 return __pParticipantCallHandles->GetCount();
248 AppCallInfo::AddCallToCallerList(AppCallInfo& callInfo)
250 if (__pParticipantCallHandles == NULL)
252 __pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
254 result r = E_FAILURE;
255 AppCallInfo* pNewCallInfo = new (std::nothrow) AppCallInfo();
256 *pNewCallInfo = callInfo;
257 r = __pParticipantCallHandles->Add(*pNewCallInfo);
263 AppCallInfo::RemoveCallFromCallerList(int index)
265 result r = E_FAILURE;
266 if (__pParticipantCallHandles == NULL)
270 r = __pParticipantCallHandles->RemoveAt(index);
275 AppCallInfo::SetCalllogType(CallLogType callLogType)
277 __calllogType = callLogType;
281 AppCallInfo::GetCalllogType(void)
283 return __calllogType;
287 AppCallInfo::operator ==(const AppCallInfo& rhs) const
289 return (this->__pCallHandle->Equals(*(rhs.__pCallHandle)));
293 AppCallInfo::operator !=(const AppCallInfo& rhs) const
295 return (!(this->__pCallHandle->Equals(*(rhs.__pCallHandle))));
299 AppCallInfo::operator =(const AppCallInfo& rhs)
303 this->__isConfCall = rhs.__isConfCall;
304 this->__callType = rhs.__callType;
305 this->__isEmergency = rhs.__isEmergency;
306 this->__contactNumber = rhs.__contactNumber;
307 this->__isOnHold = rhs.__isOnHold;
308 //call connected time
309 this->__callConnectTime = rhs.__callConnectTime;
310 this->__durationTime = rhs.__durationTime;
311 //call notification time
312 this->__callNotificationTime = rhs.__callNotificationTime;
313 this->__calllogType = rhs.__calllogType;
314 //copy call handle, if exist
315 if (this->__pCallHandle != null)
317 delete this->__pCallHandle;
318 this->__pCallHandle = null;
320 if (rhs.__pCallHandle != null)
322 this->__pCallHandle = new (std::nothrow) Long(*(rhs.__pCallHandle));
325 //copy end call cause, if any exist
326 if (this->__pEndCallCause != null)
328 delete this->__pEndCallCause;
329 this->__pEndCallCause = null;
331 if (rhs.__pEndCallCause)
333 this->__pEndCallCause = new (std::nothrow) String(*(rhs.__pEndCallCause));
336 //Add participant call list
337 if (this->__pParticipantCallHandles != null)
339 delete this->__pParticipantCallHandles;
340 this->__pParticipantCallHandles = null;
342 if (rhs.__pParticipantCallHandles != null)
344 this->__pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
345 this->__pParticipantCallHandles->Construct(*(rhs.__pParticipantCallHandles));
347 if (this->__pContact != null)
349 delete this->__pContact;
350 this->__pContact = null;
352 if (rhs.__pContact != null)
354 this->__pContact = new (std::nothrow) Contact(*(rhs.__pContact));
362 AppCallInfo::FetchCallerNameN(void)
364 String displayName(L"");
365 //get caller name from already fetched contact info
366 if (__pContact != null)
368 //fetch name to be displayed
369 String firstName(L"");
370 String lastName(L"");
371 String middlename(L"");
372 __pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
373 __pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
374 __pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
375 displayName.Append(firstName + middlename + lastName);
377 if (displayName.IsEmpty() == false)
379 __pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
383 return new (std::nothrow) String(displayName);
387 AppCallInfo::FetchContactN(const Tizen::Base::String& phoneNumber)
389 Tizen::Social::Contact* pFoundContact = null;
390 if(__pAddressBook == null)
392 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
394 IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumber);
395 if (pContactList == null || IsFailed(GetLastResult()))
400 //Fetch the contact's info to be displayed
401 IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
402 while (E_SUCCESS == pContactEnum->MoveNext())
404 Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
406 IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
407 if (pPhoneNumberList != null)
409 IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
410 while (E_SUCCESS == pPhoneEnum->MoveNext())
412 PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
413 //Check if this is the correct contact
414 if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumber))
416 //save newly fetched contact info.
417 pFoundContact = new (std::nothrow) Contact(*pContact);
422 pPhoneNumberList->RemoveAll(true);
423 delete pPhoneNumberList;
427 pContactList->RemoveAll(true);
430 if(pFoundContact == null)
435 return pFoundContact;
441 AppCallInfo::FetchLatestCallerNameN(const Tizen::Base::String& phoneNumber)
443 String displayName(L"");
444 Tizen::Social::Contact* pContact = null;
445 //Fetch the contact for a number from address book
446 pContact = FetchContactN(phoneNumber);
449 String firstName(L"");
450 String lastName(L"");
451 String middlename(L"");
452 pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
453 pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
454 pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
455 displayName.Append(firstName + middlename + lastName);
457 if (displayName.IsEmpty() == false)
459 pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
464 return new (std::nothrow) String(displayName);
469 AppCallInfo::FetchLatestCallerPhotoN(const Tizen::Base::String& phoneNumber)
471 result r = E_FAILURE;
472 Tizen::Social::Contact* pContact = null;
473 String thumbnailPath;
474 Bitmap* pThumbnail = null;
475 pContact = FetchContactN(phoneNumber);
478 pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL,thumbnailPath);
479 if(thumbnailPath.IsEmpty() == true)
481 IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(pContact->GetRecordId());
482 if(pCategoryList != null && pCategoryList->GetCount() > 0)
484 AppLogDebug("Changes to get thumbnail group photo");
485 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
486 thumbnailPath = pCategory->GetThumbnailPath();
489 ImageBuffer thumbnailImageBuffer;
490 r = thumbnailImageBuffer.Construct(thumbnailPath);
493 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
496 if(pThumbnail != null)
507 AppCallInfo::FetchCallerPhotoN(void)
510 if (__pContact != null)
512 String thumbnailPath;
513 Bitmap* pThumbnail = null;
514 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
516 result r = __pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL, thumbnailPath);
517 //Now check if there is a group ring tone
518 if(thumbnailPath.IsEmpty() == true)
520 IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(__pContact->GetRecordId());
521 if(pCategoryList != null && pCategoryList->GetCount() > 0)
523 AppLogDebug("Changes to get thumbnail group photo");
524 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
525 thumbnailPath = pCategory->GetThumbnailPath();
528 //thumbnailPath = __pContact->GetThumbnailPath();
529 ImageBuffer thumbnailImageBuffer;
530 r = thumbnailImageBuffer.Construct(thumbnailPath);
533 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
541 AppCallInfo::GetContactInfo(void)