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)
37 CallLogManager::~CallLogManager(void)
39 __pCallogManager = null;
43 CallLogManager::GetInstance(void)
45 if(__pCallogManager == null)
49 return __pCallogManager;
53 CallLogManager::CreateInstance(void)
55 __pCallogManager = new CallLogManager();
56 result r = __pCallogManager->Construct();
59 delete __pCallogManager;
60 __pCallogManager = null;
63 std::atexit(DestroyInstance);
67 CallLogManager::Construct(void)
69 int ret = contacts_connect2();
79 CallLogManager::DestroyInstance(void)
81 contacts_disconnect2();
82 delete __pCallogManager;
86 CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
88 AppLog(" AddVoiceCallInfo Entry");
92 if(calllogInfo != null)
94 CallLogType callLogType = calllogInfo->GetCalllogType();
95 contacts_phone_log_type_e logType = CONTACTS_PLOG_TYPE_NONE;
98 case CALL_LOG_TYPE_VOICE_INCOMING:
99 logType = CONTACTS_PLOG_TYPE_VOICE_INCOMMING;
101 case CALL_LOG_TYPE_VOICE_OUTGOING:
102 logType = CONTACTS_PLOG_TYPE_VOICE_OUTGOING;
104 case CALL_LOG_TYPE_VOICE_MISSED:
105 logType = CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN;
107 case CALL_LOG_TYPE_VOICE_REJECTED:
108 logType = CONTACTS_PLOG_TYPE_VOICE_REJECT;
110 case CALL_LOG_TYPE_VOICE_BLOCKED:
111 logType = CONTACTS_PLOG_TYPE_VOICE_BLOCKED;
116 startTime = calllogInfo->GetCallNotificationTime();
117 if ((logType == CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN)
118 || (logType == CONTACTS_PLOG_TYPE_VOICE_REJECT)
119 || (logType == CONTACTS_PLOG_TYPE_VOICE_BLOCKED))
125 //start time is in miliseconds . so convert to seconds and set it to time_t format.
126 long long connectTime = calllogInfo->GetCallConnectTime();
127 if(connectTime == 0 || connectTime < 0)
129 connectTime = time(null);
133 connectTime = calllogInfo->GetCallConnectTime()/ 1000;
135 duration = (int)GetDuration(connectTime);
138 String PhNumber(L"");
139 ByteBuffer* pByteBuffer = null;
141 if(calllogInfo->GetContactNumber().IsEmpty() == false)
143 PhNumber.Append(calllogInfo->GetContactNumber());
144 pByteBuffer = StringUtil::StringToUtf8N(PhNumber);
148 contacts_record_h hContactLog=0;
149 int ret = contacts_record_create(_contacts_phone_log._uri,&hContactLog);
157 if (contacts_record_set_int(hContactLog,_contacts_phone_log.log_type,logType) != CONTACTS_ERROR_NONE)
159 AppLog(" calllog_set_type is failed");
161 else if (contacts_record_set_int(hContactLog,_contacts_phone_log.log_time,startTime/1000) != CONTACTS_ERROR_NONE)
163 AppLog(" calllog_set_time is failed");
165 else if (contacts_record_set_int(hContactLog,_contacts_phone_log.extra_data1,duration) != CONTACTS_ERROR_NONE)
167 AppLog(" calllog_set_duration is failed");
169 else if ((pByteBuffer != null) && (contacts_record_set_str(hContactLog,_contacts_phone_log.address,(const char*) pByteBuffer->GetPointer()) != CONTACTS_ERROR_NONE))
171 AppLog(" calllog_set_number is failed");
173 else if (contacts_db_insert_record(hContactLog,&id) != CONTACTS_ERROR_NONE)
175 AppLog(" calllog_insert_to_db is failed");
179 AppLog(" Call log is added successfully");
183 AppLog(" AddVoiceCallInfo Exit");
188 CallLogManager::GetDuration(long long start_time)
191 unsigned long call_duration_in_sec = 50;
193 /*if(start_time != 0)
197 call_duration_in_sec = curr_time - start_time;
198 return call_duration_in_sec;