Fix N_SE-41043
[apps/osp/Call.git] / src / CallInfo.cpp
index 8ad4df6..049bcae 100644 (file)
@@ -119,6 +119,31 @@ AppCallInfo::GetContactNumber(void)
 }
 
 void
+AppCallInfo::ResetContactNumber(String* contactNumber)
+{
+       if(contactNumber == null)
+       {
+               if (__isConfCall == false)
+               {
+                       __contactNumber = null;
+               }
+       }
+
+}
+
+void
+AppCallInfo::ResetContactInfo(const Contact* contact)
+{
+       if(contact == null)
+       {
+               if (__pContact != null)
+               {
+                       delete __pContact;
+                       __pContact = null;
+               }
+       }
+}
+void
 AppCallInfo::SetContactNumber(String& contactNumber)
 {
        if (__isConfCall == false)
@@ -323,7 +348,6 @@ String*
 AppCallInfo::FetchCallerNameN(void)
 {
        String displayName(L"");
-
        //get caller name from already fetched contact info
        if (__pContact != null)
        {
@@ -331,8 +355,8 @@ AppCallInfo::FetchCallerNameN(void)
                        String firstName(L"");
                        String lastName(L"");
                String middlename(L"");
-                       __pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
-                       __pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
+               __pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
+               __pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
                __pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
                displayName.Append(firstName + middlename + lastName);
 
@@ -345,6 +369,125 @@ AppCallInfo::FetchCallerNameN(void)
        return new (std::nothrow) String(displayName);
 }
 
+Contact*
+AppCallInfo::FetchContactN(const Tizen::Base::String& phoneNumber)
+{
+       Tizen::Social::Contact* pFoundContact = null;
+       if(__pAddressBook == null)
+       {
+               __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
+       }
+       IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumber);
+       if (pContactList == null || IsFailed(GetLastResult()))
+       {
+               return null;
+       }
+
+       //Fetch the contact's info to be displayed
+       IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
+       while (E_SUCCESS == pContactEnum->MoveNext())
+       {
+               Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
+
+               IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
+               if (pPhoneNumberList != null)
+               {
+                       IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
+                       while (E_SUCCESS == pPhoneEnum->MoveNext())
+                       {
+                               PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
+                               //Check if this is the correct contact
+                               if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumber))
+                               {
+                                       //save newly fetched contact info.
+                                       pFoundContact = new (std::nothrow) Contact(*pContact);
+                                       break;
+                               }
+                       }
+                       delete pPhoneEnum;
+                               pPhoneNumberList->RemoveAll(true);
+                               delete pPhoneNumberList;
+                       }
+               }
+               delete pContactEnum;
+               pContactList->RemoveAll(true);
+               delete pContactList;
+
+       if(pFoundContact == null)
+       {
+               return null;
+       }
+
+       return pFoundContact;
+
+}
+
+
+String*
+AppCallInfo::FetchLatestCallerNameN(const Tizen::Base::String& phoneNumber)
+{
+       String displayName(L"");
+       Tizen::Social::Contact* pContact = null;
+       //Fetch the contact for a number from address book
+       pContact = FetchContactN(phoneNumber);
+       if(pContact != null)
+       {
+               String firstName(L"");
+               String lastName(L"");
+               String middlename(L"");
+               pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
+               pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
+               pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
+               displayName.Append(firstName + middlename + lastName);
+
+               if (displayName.IsEmpty() == false)
+               {
+                       pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
+               }
+       }
+
+       return new (std::nothrow) String(displayName);
+
+
+}
+Bitmap*
+AppCallInfo::FetchLatestCallerPhotoN(const Tizen::Base::String& phoneNumber)
+{
+       result r = E_FAILURE;
+       Tizen::Social::Contact* pContact = null;
+       String thumbnailPath;
+       Bitmap* pThumbnail = null;
+       pContact = FetchContactN(phoneNumber);
+       if(pContact != null)
+       {
+               pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL,thumbnailPath);
+               if(thumbnailPath.IsEmpty() == true)
+               {
+                       IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(pContact->GetRecordId());
+                       if(pCategoryList != null && pCategoryList->GetCount() > 0)
+                       {
+                               AppLogDebug("Changes to get thumbnail group photo");
+                               Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
+                               thumbnailPath = pCategory->GetThumbnailPath();
+                       }
+               }
+               ImageBuffer thumbnailImageBuffer;
+               r = thumbnailImageBuffer.Construct(thumbnailPath);
+               if (r == E_SUCCESS)
+               {
+                       pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
+               }
+
+               if(pThumbnail != null)
+               {
+                       return pThumbnail;
+               }
+       }
+
+       return null;
+
+}
+
 Bitmap*
 AppCallInfo::FetchCallerPhotoN(void)
 {