Fix for N_SE-47477
[apps/osp/Call.git] / src / CalllogManager.cpp
index 6f1f749..98dc827 100644 (file)
@@ -1,7 +1,7 @@
 //
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
@@ -18,8 +18,9 @@
  * @file       CalllogManager.cpp
  * @brief      This class provides call log APIs
  */
-#include "CalllogManager.h"
 #include <FLocales.h>
+#include "CallApp.h"
+#include "CalllogManager.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -32,6 +33,7 @@ CallLogManager*       CallLogManager::__pCallogManager = null;
 CallLogManager::CallLogManager(void)
 {
 
+       pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
 }
 
 CallLogManager::~CallLogManager(void)
@@ -83,7 +85,7 @@ CallLogManager::DestroyInstance(void)
 }
 
 result
-CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
+CallLogManager::AddCallogInfoToDatabase(AppCallInfo* calllogInfo)
 {
        AppLog(" AddVoiceCallInfo Entry");
        int duration = 0;
@@ -101,7 +103,7 @@ CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
                case CALL_LOG_TYPE_VOICE_OUTGOING:
                        logType = CONTACTS_PLOG_TYPE_VOICE_OUTGOING;
                        break;
-               case CALL_LOG_TYPE_VOICE_MISSED:
+               case CALL_LOG_TYPE_VOICE_MISSED_UNSEEN:
                        logType = CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN;
                        break;
                case CALL_LOG_TYPE_VOICE_REJECTED:
@@ -123,14 +125,17 @@ CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
                else
                {
                        //start time is in miliseconds . so convert to seconds and set it to time_t format.
-                       long long connectTime = calllogInfo->GetCallConnectTime();
+                       long long connectTime = calllogInfo->GetDurationTime();
                        if(connectTime == 0 || connectTime < 0)
                        {
-                               connectTime = time(null);
+                               //connectTime = time(null);
+                               CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
+                               connectTime = pPhoneApp->GetCallAppTicks();
+                               connectTime /=1000;
                        }
                        else
                        {
-                               connectTime = calllogInfo->GetCallConnectTime()/ 1000;
+                               connectTime = calllogInfo->GetDurationTime()/ 1000;
                        }
                        duration = (int)GetDuration(connectTime);
                }
@@ -153,6 +158,14 @@ CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
                }
                int id;
 
+               int personid = GetPersonId(PhNumber);
+               if (personid != -1)
+               {
+                       if(contacts_record_set_int(hContactLog,_contacts_phone_log.person_id,personid) != CONTACTS_ERROR_NONE)
+                       {
+                               AppLog(" calllog_set_type personid failed");
+                       }
+               }
 
                if (contacts_record_set_int(hContactLog,_contacts_phone_log.log_type,logType) != CONTACTS_ERROR_NONE)
                {
@@ -187,9 +200,12 @@ CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
 unsigned long
 CallLogManager::GetDuration(long long start_time)
 {
-       time_t curr_time;
+       long long curr_time;
        unsigned long call_duration_in_sec = 50;
-       curr_time = time(0);
+//     curr_time = time(0);
+       CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
+       curr_time = pPhoneApp->GetCallAppTicks();
+       curr_time /=1000;
        /*if(start_time != 0)
        {
                start_time /= 1000;
@@ -197,4 +213,22 @@ CallLogManager::GetDuration(long long start_time)
        call_duration_in_sec = curr_time - start_time;
        return call_duration_in_sec;
 }
+int
+CallLogManager::GetPersonId(Tizen::Base::String& phoneNumber)
+{
+       int personId = -1;
+       if (pAddressBook != null)
+       {
+               IList* pNumberContactsList = pAddressBook->SearchContactsByPhoneNumberN(phoneNumber);
+               if(pNumberContactsList != null)
+               {
+                       Contact* pContact = static_cast<Contact*>(pNumberContactsList->GetAt(0));
+                       if(pContact != null)
+                       {
+                               personId = pContact->GetPersonId();
+                       }
+               }
+       }
+       return personId;
+}