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 CallCallSettingDataService.cpp
19 * @brief Call Database class
25 #include "CallSettingDataService.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Io;
30 using namespace Tizen::App;
31 using namespace Tizen::Social;
33 static const wchar_t* REJECT_DATABASE_PATH = L"/opt/usr/apps/zktdpemtmw/";
35 CallSettingDataService* CallSettingDataService::__pCallSettingDataService = null;
36 Database* CallSettingDataService::__pDatabase = null;
38 CallSettingDataService::CallSettingDataService(void)
39 : __strDbName(String(REJECT_DATABASE_PATH) + L"data/CallRejectInfoListDataBase")
47 CallSettingDataService::~CallSettingDataService(void)
49 if (__pDatabase != null)
54 __pCallSettingDataService = null;
58 CallSettingDataService*
59 CallSettingDataService::CreateInstance(void)
61 if (__pCallSettingDataService == null)
63 __pCallSettingDataService = new (std::nothrow) CallSettingDataService();
65 return __pCallSettingDataService;
68 CallSettingDataService::OpenDatabase(void)
72 // create the database if it doesn't exist
73 if (__pDatabase != null)
75 return E_OBJ_ALREADY_EXIST;
77 __pDatabase = new (std::nothrow) Database();
78 r = __pDatabase->Construct(__strDbName, true);
79 TryCatch(r == E_SUCCESS, , "CallSettingDataService::OpenDatabase() database construct failed");
81 r = CreateCallRejectTableDatabase();
82 // TryCatch(r == E_SUCCESS, , "CallSettingDataService::OpenDatabase() call reject Create Table failed");
83 r = CreateSpeedDialTableDatabase();
84 // TryCatch(r == E_SUCCESS, , "CallSettingDataService::OpenDatabase() speed dial Create Table failed");
95 CallSettingDataService::CreateCallRejectTableDatabase(void)
100 sqlQuery.Append(L"CREATE TABLE IF NOT EXISTS CallRejectInfoTable(id INTEGER PRIMARY KEY AUTOINCREMENT,phonenumber TEXT,rejectcondition INT,activated INT)");
102 r = __pDatabase->ExecuteSql(sqlQuery, true);
103 TryCatch(r == E_SUCCESS, , "CallSettingDataService::CreateCallRejectInfoTableDatabase() Create Table failed");
112 CallSettingDataService::CreateSpeedDialTableDatabase(void)
115 result r = E_SUCCESS;
117 sqlQuery.Append(L"CREATE TABLE IF NOT EXISTS SpeedDialTable(id INTEGER PRIMARY KEY AUTOINCREMENT,contactInfo TEXT,keyMappedTo INT)");
119 r = __pDatabase->ExecuteSql(sqlQuery, true);
120 TryCatch(r == E_SUCCESS, , "CallSettingDataService::CreateCallRejectInfoTableDatabase() Create Table failed");
129 CallSettingDataService::CloseDatabase(void)
141 if (__pDatabase != null)
152 CallSettingDataService::IsCallToBeRejected(String& phoneNumber)
154 AppLogDebug("Enter");
155 bool isCallToBeRejected = false;
159 result r = E_SUCCESS;
160 __pDatabase->BeginTransaction();
162 //statement.Append(L"SELECT * FROM CallRejectInfoTable WHERE phonenumber LIKE ?");
163 statement.Append(L"SELECT * FROM CallRejectInfoTable WHERE activated=?");
165 __pStmt = __pDatabase->CreateStatementN(statement);
167 TryCatch(r == E_SUCCESS, , "CallSettingDataService::SearchFromDataBase CreateStatementN failed");
169 //__pStmt->BindString(0, phoneNumber);
172 __pStmt->BindInt(0,(int)true);
173 __pEnum = __pDatabase->ExecuteStatementN(*__pStmt);
176 TryCatch(r == E_SUCCESS, , "CallSettingDataService::SearchFromDataBaseN search failed");
178 //check if the query returned any result and then iterate through the results
181 while (__pEnum->MoveNext() == E_SUCCESS)
183 CallRejectInfo* pCallRejectInfoItem = new (std::nothrow) CallRejectInfo;
186 __pEnum->GetIntAt(0, pCallRejectInfoItem->rowId);
187 __pEnum->GetStringAt(1, pCallRejectInfoItem->phoneNumber);
188 __pEnum->GetIntAt(2, rejectCondition);
189 __pEnum->GetIntAt(3, activateflag);
190 pCallRejectInfoItem->rejectCondition = (CallRejectMatchCondition)rejectCondition;
191 pCallRejectInfoItem->isActivated = (bool)activateflag;
192 if (CheckRejectCondition(phoneNumber, *pCallRejectInfoItem) == true)
194 delete pCallRejectInfoItem;
195 isCallToBeRejected = true;
198 delete pCallRejectInfoItem;
201 __pDatabase->CommitTransaction();
213 AppLogDebug("%d",isCallToBeRejected);
214 return isCallToBeRejected;
217 return isCallToBeRejected;
221 CallSettingDataService::CheckRejectCondition(String& phoneNumber, CallRejectInfo& callRejectInfo)
223 bool isCallToBeRejected = false;
224 switch (callRejectInfo.rejectCondition)
226 case CALL_REJECT_MATCH_EXACTLY:
228 if (callRejectInfo.phoneNumber.CompareTo(phoneNumber) == 0)
230 isCallToBeRejected = true;
234 case CALL_REJECT_MATCH_START:
236 isCallToBeRejected = phoneNumber.StartsWith(callRejectInfo.phoneNumber, 0);
239 case CALL_REJECT_MATCH_END:
241 isCallToBeRejected = phoneNumber.EndsWith(callRejectInfo.phoneNumber);
244 case CALL_REJECT_MATCH_INCLUDE:
246 isCallToBeRejected = phoneNumber.Contains(callRejectInfo.phoneNumber);
253 return isCallToBeRejected;