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;
40 __callNotificationTime = 0;
42 __pEndCallCause = null;
43 __pParticipantCallHandles = null;
45 __pAddressBook = null;
48 AppCallInfo::~AppCallInfo(void)
57 delete __pEndCallCause;
60 if (__pParticipantCallHandles)
62 delete __pParticipantCallHandles;
63 __pParticipantCallHandles = null;
65 if (__pContact != null)
69 if(__pAddressBook != null)
71 delete __pAddressBook;
76 AppCallInfo::GetCallHandle(void)
82 AppCallInfo::SetCallHandle(unsigned int handle)
84 if (__pCallHandle != null)
88 __pCallHandle = new (std::nothrow) Long(handle);
92 AppCallInfo::IsConferenceCall(void)
98 AppCallInfo::SetConference(bool isConferenceCall)
100 __isConfCall = isConferenceCall;
104 AppCallInfo::IsEmergency(void)
106 return __isEmergency;
110 AppCallInfo::SetEmergency(bool isEmergency)
112 __isEmergency = isEmergency;
116 AppCallInfo::GetContactNumber(void)
118 return __contactNumber;
122 AppCallInfo::ResetContactNumber(String* contactNumber)
124 if(contactNumber == null)
126 if (__isConfCall == false)
128 __contactNumber = null;
135 AppCallInfo::ResetContactInfo(const Contact* contact)
139 if (__pContact != null)
147 AppCallInfo::SetContactNumber(String& contactNumber)
149 if (__isConfCall == false)
151 __contactNumber = contactNumber;
156 AppCallInfo::SetContactInfo(const Contact& contact)
158 if (__pContact != null)
163 __pContact = new (std::nothrow) Contact(contact);
167 AppCallInfo::IsOnHold(void)
173 AppCallInfo::SetOnHold(bool onHold)
179 AppCallInfo::GetCallConnectTime(void)
181 return __callConnectTime;
185 AppCallInfo::SetCallConnectTime(long long connectTime)
187 __callConnectTime = connectTime;
191 AppCallInfo::GetCallNotificationTime(void)
193 return __callNotificationTime;
197 AppCallInfo::SetCallNotificationTime(long long callNotificationTime)
199 __callNotificationTime = callNotificationTime;
203 AppCallInfo::GetEndCallCause(void)
205 return *(__pEndCallCause);
209 AppCallInfo::SetEndCallCause(String& pEndCause)
211 if (__pEndCallCause != null)
213 delete __pEndCallCause;
215 __pEndCallCause = new (std::nothrow) String(pEndCause);
219 AppCallInfo::GetCallerList(void)
221 return __pParticipantCallHandles;
225 AppCallInfo::GetCallerListCount(void)
227 if (__pParticipantCallHandles != null)
229 return __pParticipantCallHandles->GetCount();
235 AppCallInfo::AddCallToCallerList(AppCallInfo& callInfo)
237 if (__pParticipantCallHandles == NULL)
239 __pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
241 result r = E_FAILURE;
242 AppCallInfo* pNewCallInfo = new (std::nothrow) AppCallInfo();
243 *pNewCallInfo = callInfo;
244 r = __pParticipantCallHandles->Add(*pNewCallInfo);
250 AppCallInfo::RemoveCallFromCallerList(int index)
252 result r = E_FAILURE;
253 if (__pParticipantCallHandles == NULL)
257 r = __pParticipantCallHandles->RemoveAt(index);
262 AppCallInfo::SetCalllogType(CallLogType callLogType)
264 __calllogType = callLogType;
268 AppCallInfo::GetCalllogType(void)
270 return __calllogType;
274 AppCallInfo::operator ==(const AppCallInfo& rhs) const
276 return (this->__pCallHandle->Equals(*(rhs.__pCallHandle)));
280 AppCallInfo::operator !=(const AppCallInfo& rhs) const
282 return (!(this->__pCallHandle->Equals(*(rhs.__pCallHandle))));
286 AppCallInfo::operator =(const AppCallInfo& rhs)
290 this->__isConfCall = rhs.__isConfCall;
291 this->__callType = rhs.__callType;
292 this->__isEmergency = rhs.__isEmergency;
293 this->__contactNumber = rhs.__contactNumber;
294 this->__isOnHold = rhs.__isOnHold;
295 //call connected time
296 this->__callConnectTime = rhs.__callConnectTime;
297 //call notification time
298 this->__callNotificationTime = rhs.__callNotificationTime;
299 this->__calllogType = rhs.__calllogType;
300 //copy call handle, if exist
301 if (this->__pCallHandle != null)
303 delete this->__pCallHandle;
304 this->__pCallHandle = null;
306 if (rhs.__pCallHandle != null)
308 this->__pCallHandle = new (std::nothrow) Long(*(rhs.__pCallHandle));
311 //copy end call cause, if any exist
312 if (this->__pEndCallCause != null)
314 delete this->__pEndCallCause;
315 this->__pEndCallCause = null;
317 if (rhs.__pEndCallCause)
319 this->__pEndCallCause = new (std::nothrow) String(*(rhs.__pEndCallCause));
322 //Add participant call list
323 if (this->__pParticipantCallHandles != null)
325 delete this->__pParticipantCallHandles;
326 this->__pParticipantCallHandles = null;
328 if (rhs.__pParticipantCallHandles != null)
330 this->__pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
331 this->__pParticipantCallHandles->Construct(*(rhs.__pParticipantCallHandles));
333 if (this->__pContact != null)
335 delete this->__pContact;
336 this->__pContact = null;
338 if (rhs.__pContact != null)
340 this->__pContact = new (std::nothrow) Contact(*(rhs.__pContact));
348 AppCallInfo::FetchCallerNameN(void)
350 String displayName(L"");
351 //get caller name from already fetched contact info
352 if (__pContact != null)
354 //fetch name to be displayed
355 String firstName(L"");
356 String lastName(L"");
357 String middlename(L"");
358 __pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
359 __pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
360 __pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
361 displayName.Append(firstName + middlename + lastName);
363 if (displayName.IsEmpty() == false)
365 __pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
369 return new (std::nothrow) String(displayName);
373 AppCallInfo::FetchContactN(const Tizen::Base::String& phoneNumber)
375 Tizen::Social::Contact* pFoundContact = null;
376 if(__pAddressBook == null)
378 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
380 IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumber);
381 if (pContactList == null || IsFailed(GetLastResult()))
386 //Fetch the contact's info to be displayed
387 IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
388 while (E_SUCCESS == pContactEnum->MoveNext())
390 Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
392 IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
393 if (pPhoneNumberList != null)
395 IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
396 while (E_SUCCESS == pPhoneEnum->MoveNext())
398 PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
399 //Check if this is the correct contact
400 if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumber))
402 //save newly fetched contact info.
403 pFoundContact = new (std::nothrow) Contact(*pContact);
408 pPhoneNumberList->RemoveAll(true);
409 delete pPhoneNumberList;
413 pContactList->RemoveAll(true);
416 if(pFoundContact == null)
421 return pFoundContact;
427 AppCallInfo::FetchLatestCallerNameN(const Tizen::Base::String& phoneNumber)
429 String displayName(L"");
430 Tizen::Social::Contact* pContact = null;
431 //Fetch the contact for a number from address book
432 pContact = FetchContactN(phoneNumber);
435 String firstName(L"");
436 String lastName(L"");
437 String middlename(L"");
438 pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
439 pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
440 pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
441 displayName.Append(firstName + middlename + lastName);
443 if (displayName.IsEmpty() == false)
445 pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
449 return new (std::nothrow) String(displayName);
454 AppCallInfo::FetchLatestCallerPhotoN(const Tizen::Base::String& phoneNumber)
456 result r = E_FAILURE;
457 Tizen::Social::Contact* pContact = null;
458 String thumbnailPath;
459 Bitmap* pThumbnail = null;
460 pContact = FetchContactN(phoneNumber);
463 pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL,thumbnailPath);
464 if(thumbnailPath.IsEmpty() == true)
466 IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(pContact->GetRecordId());
467 if(pCategoryList != null && pCategoryList->GetCount() > 0)
469 AppLogDebug("Changes to get thumbnail group photo");
470 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
471 thumbnailPath = pCategory->GetThumbnailPath();
474 ImageBuffer thumbnailImageBuffer;
475 r = thumbnailImageBuffer.Construct(thumbnailPath);
478 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
481 if(pThumbnail != null)
492 AppCallInfo::FetchCallerPhotoN(void)
495 if (__pContact != null)
497 String thumbnailPath;
498 Bitmap* pThumbnail = null;
499 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
501 result r = __pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL, thumbnailPath);
502 //Now check if there is a group ring tone
503 if(thumbnailPath.IsEmpty() == true)
505 IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(__pContact->GetRecordId());
506 if(pCategoryList != null && pCategoryList->GetCount() > 0)
508 AppLogDebug("Changes to get thumbnail group photo");
509 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
510 thumbnailPath = pCategory->GetThumbnailPath();
513 //thumbnailPath = __pContact->GetThumbnailPath();
514 ImageBuffer thumbnailImageBuffer;
515 r = thumbnailImageBuffer.Construct(thumbnailPath);
518 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
526 AppCallInfo::GetContactInfo(void)