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 CalllogManager.cpp
19 * @brief This class provides call log APIs
21 #include "CalllogManager.h"
24 using namespace Tizen::Base;
25 using namespace Tizen::Base::Collection;
26 using namespace Tizen::Base::Utility;
27 using namespace Tizen::System;
28 using namespace Tizen::Locales;
30 CallLogManager* CallLogManager::__pCallogManager = null;
32 CallLogManager::CallLogManager(void)
35 pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
38 CallLogManager::~CallLogManager(void)
40 __pCallogManager = null;
44 CallLogManager::GetInstance(void)
46 if(__pCallogManager == null)
50 return __pCallogManager;
54 CallLogManager::CreateInstance(void)
56 __pCallogManager = new CallLogManager();
57 result r = __pCallogManager->Construct();
60 delete __pCallogManager;
61 __pCallogManager = null;
64 std::atexit(DestroyInstance);
68 CallLogManager::Construct(void)
70 int ret = contacts_connect2();
80 CallLogManager::DestroyInstance(void)
82 contacts_disconnect2();
83 delete __pCallogManager;
87 CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
89 AppLog(" AddVoiceCallInfo Entry");
93 if(calllogInfo != null)
95 CallLogType callLogType = calllogInfo->GetCalllogType();
96 contacts_phone_log_type_e logType = CONTACTS_PLOG_TYPE_NONE;
99 case CALL_LOG_TYPE_VOICE_INCOMING:
100 logType = CONTACTS_PLOG_TYPE_VOICE_INCOMMING;
102 case CALL_LOG_TYPE_VOICE_OUTGOING:
103 logType = CONTACTS_PLOG_TYPE_VOICE_OUTGOING;
105 case CALL_LOG_TYPE_VOICE_MISSED_UNSEEN:
106 logType = CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN;
108 case CALL_LOG_TYPE_VOICE_REJECTED:
109 logType = CONTACTS_PLOG_TYPE_VOICE_REJECT;
111 case CALL_LOG_TYPE_VOICE_BLOCKED:
112 logType = CONTACTS_PLOG_TYPE_VOICE_BLOCKED;
117 startTime = calllogInfo->GetCallNotificationTime();
118 if ((logType == CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN)
119 || (logType == CONTACTS_PLOG_TYPE_VOICE_REJECT)
120 || (logType == CONTACTS_PLOG_TYPE_VOICE_BLOCKED))
126 //start time is in miliseconds . so convert to seconds and set it to time_t format.
127 long long connectTime = calllogInfo->GetCallConnectTime();
128 if(connectTime == 0 || connectTime < 0)
130 connectTime = time(null);
134 connectTime = calllogInfo->GetCallConnectTime()/ 1000;
136 duration = (int)GetDuration(connectTime);
139 String PhNumber(L"");
140 ByteBuffer* pByteBuffer = null;
142 if(calllogInfo->GetContactNumber().IsEmpty() == false)
144 PhNumber.Append(calllogInfo->GetContactNumber());
145 pByteBuffer = StringUtil::StringToUtf8N(PhNumber);
149 contacts_record_h hContactLog=0;
150 int ret = contacts_record_create(_contacts_phone_log._uri,&hContactLog);
157 int personid = GetPersonId(PhNumber);
160 if(contacts_record_set_int(hContactLog,_contacts_phone_log.person_id,personid) != CONTACTS_ERROR_NONE)
162 AppLog(" calllog_set_type personid failed");
166 if (contacts_record_set_int(hContactLog,_contacts_phone_log.log_type,logType) != CONTACTS_ERROR_NONE)
168 AppLog(" calllog_set_type is failed");
170 else if (contacts_record_set_int(hContactLog,_contacts_phone_log.log_time,startTime/1000) != CONTACTS_ERROR_NONE)
172 AppLog(" calllog_set_time is failed");
174 else if (contacts_record_set_int(hContactLog,_contacts_phone_log.extra_data1,duration) != CONTACTS_ERROR_NONE)
176 AppLog(" calllog_set_duration is failed");
178 else if ((pByteBuffer != null) && (contacts_record_set_str(hContactLog,_contacts_phone_log.address,(const char*) pByteBuffer->GetPointer()) != CONTACTS_ERROR_NONE))
180 AppLog(" calllog_set_number is failed");
182 else if (contacts_db_insert_record(hContactLog,&id) != CONTACTS_ERROR_NONE)
184 AppLog(" calllog_insert_to_db is failed");
188 AppLog(" Call log is added successfully");
192 AppLog(" AddVoiceCallInfo Exit");
197 CallLogManager::GetDuration(long long start_time)
200 unsigned long call_duration_in_sec = 50;
202 /*if(start_time != 0)
206 call_duration_in_sec = curr_time - start_time;
207 return call_duration_in_sec;
210 CallLogManager::GetPersonId(Tizen::Base::String& phoneNumber)
213 if (pAddressBook != null)
215 IList* pNumberContactsList = pAddressBook->SearchContactsByPhoneNumberN(phoneNumber);
216 if(pNumberContactsList != null)
218 Contact* pContact = static_cast<Contact*>(pNumberContactsList->GetAt(0));
221 personId = pContact->GetPersonId();