Update change log and spec for wrt-plugins-tizen_0.4.46
[platform/framework/web/wrt-plugins-tizen.git] / src / Callhistory / CallHistoryEntry.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "CallHistoryEntry.h"
19 #include <Commons/Exception.h>
20 #include <dpl/shared_ptr.h>
21 #include <contacts.h>
22 #include <Logger.h>
23
24 using namespace DeviceAPI::Tizen;
25 using namespace WrtDeviceApis;
26 using namespace WrtDeviceApis::Commons;
27
28
29 namespace DeviceAPI {
30 namespace CallHistory {
31
32 CallHistoryEntry::CallHistoryEntry()
33 {
34         if (contacts_connect2() == CONTACTS_ERROR_NONE) {
35                 LoggerD("Successful to connect Call history DB ");
36         } else {
37                 LoggerD("Failed to connect Call history DB ");
38         }
39 }
40
41 CallHistoryEntry::~CallHistoryEntry()
42 {
43         if (contacts_disconnect2()  == CONTACTS_ERROR_NONE) {
44                 LoggerD("Successful to disconnect Call history DB ");
45         } else {
46                 LoggerD("Failed to disconnect Call history DB ");
47         }
48 }
49
50 void CallHistoryEntry::setMarkSeen(const unsigned long entryId)
51 {
52         contacts_record_h record = NULL;
53         int ret = -1;
54         int logType = 0;
55
56         ret = contacts_db_get_record (_contacts_phone_log._uri, (int)entryId, &record);
57
58         if (ret != CONTACTS_ERROR_NONE) {
59                 ThrowMsg(Commons::ConversionException, "Type missmatch error");
60                 return;
61         }
62
63         contacts_record_get_int (record, _contacts_phone_log.log_type, &logType);
64
65         if (logType == 5) {
66                 contacts_record_set_int (record, _contacts_phone_log.log_type, 6);
67         } else if (logType == 7) {
68                 contacts_record_set_int (record, _contacts_phone_log.log_type, 8);
69         } else {
70                 contacts_record_destroy(record, true);
71                 ThrowMsg(Commons::ConversionException, "Type missmatch error");
72                 return;
73         }
74
75         ret = contacts_db_update_record (record);
76
77         if (ret != CONTACTS_ERROR_NONE) {
78                 contacts_record_destroy(record, true);
79                 ThrowMsg(Commons::ConversionException, "Type missmatch error");
80                 return;
81         }
82
83         contacts_record_destroy(record, true);
84 }
85
86 }
87 }