summaryrefslogtreecommitdiff
path: root/lib/dialer/Search/DbDataProvider.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dialer/Search/DbDataProvider.cpp')
-rw-r--r--lib/dialer/Search/DbDataProvider.cpp327
1 files changed, 0 insertions, 327 deletions
diff --git a/lib/dialer/Search/DbDataProvider.cpp b/lib/dialer/Search/DbDataProvider.cpp
deleted file mode 100644
index 91906f3..0000000
--- a/lib/dialer/Search/DbDataProvider.cpp
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Copyright 2012-2013 Samsung Electronics Co., Ltd
- *
- * 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
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Search/DbDataProvider.h"
-
-#include "phone.h"
-#include "phone-common.h"
-#include "Search/ContactLogRecord.h"
-#include "Search/ContactNumberRecord.h"
-
-namespace Phone
-{
- namespace Dialer
- {
- namespace Search
- {
- using Database::Database;
-
- DbDataProvider::DbDataProvider()
- : m_Initialized(false)
- {
- PH_TRACE;
- }
-
- DbDataProvider::~DbDataProvider()
- {
- PH_TRACE;
- contacts_db_remove_changed_cb(_contacts_number._uri, onContactNumberChange, this);
- Database::getInstance().removeListener(_contacts_phone_log._uri, this);
- }
-
- bool DbDataProvider::initialize()
- {
- PH_TRACE;
- if(!m_Initialized)
- {
- bool success = fetchNumbers() && fetchLogs();
-
- if(success)
- {
- success = Database::isSuccess(
- contacts_db_add_changed_cb(_contacts_number._uri, onContactNumberChange, this));
- }
-
- if(success)
- {
- success = Database::getInstance().addListener(_contacts_phone_log._uri, this);
- }
- else
- {
- contacts_db_remove_changed_cb(_contacts_number._uri, onContactNumberChange, this);
- }
-
- if(!success)
- {
- m_Numbers.clear();
- m_Logs.clear();
- }
- else
- {
- m_Initialized = true;
- }
- }
-
- return m_Initialized;
- }
-
- size_t DbDataProvider::getCount() const
- {
- return m_Numbers.size() + m_Logs.size();
- }
-
- ContactPtr DbDataProvider::getData(size_t index) const
- {
- if(index < m_Numbers.size())
- {
- return m_Numbers[index];
- }
- else
- {
- index -= m_Numbers.size();
- if (index < m_Logs.size())
- {
- return m_Logs[index];
- }
- else
- {
- return ContactPtr();
- }
- }
- }
-
- bool DbDataProvider::fetchNumbers()
- {
- PH_TRACE;
- contacts_query_h query = NULL;
- contacts_list_h numbers = NULL;
- unsigned count = 0;
- unsigned ids[] = {
- _contacts_contact_number.display_name,
- _contacts_contact_number.number,
- _contacts_contact_number.image_thumbnail_path
- };
-
- bool success = Database::isSuccess(
- contacts_query_create(_contacts_contact_number._uri, &query))
- && Database::isSuccess(
- contacts_query_set_projection(query, ids, sizeof(ids) / sizeof(*ids)))
- && Database::isSuccess(
- contacts_db_get_records_with_query(query, 0, 0, &numbers))
- && Database::isSuccess(
- contacts_list_get_count(numbers, &count));
-
- if(query)
- {
- contacts_query_destroy(query);
- }
-
- m_Numbers.clear();
- DBG("count: %d", count);
- while(success && count--)
- {
- contacts_record_h record = NULL;
- success = Database::isSuccess(contacts_list_get_current_record_p(numbers, &record));
-
- if(success)
- {
- ContactNumberRecord *contactNumber = new ContactNumberRecord();
- success = contactNumber->initialize(record);
- if(success)
- {
- m_Numbers.push_back(contactNumber);
- }
- else
- {
- delete contactNumber;
- }
-
- if(count)
- {
- success = Database::isSuccess(contacts_list_next(numbers));
- }
- }
- }
-
- if(numbers)
- {
- contacts_list_destroy(numbers, true);
- }
-
- return success;
- }
-
- bool DbDataProvider::fetchLogs()
- {
- PH_TRACE;
- bool success = true;
- unsigned ids[] = {
- _contacts_person_phone_log.person_id,
- _contacts_person_phone_log.address,
- };
- contacts_query_h query = NULL;
- contacts_list_h logs = NULL;
- unsigned count = 0;
-
- success = Database::isSuccess(
- contacts_query_create(_contacts_person_phone_log._uri, &query))
- && Database::isSuccess(
- contacts_query_set_projection(query, ids, sizeof(ids) / sizeof(*ids)))
- && Database::isSuccess(
- contacts_query_set_distinct(query, true))
- && Database::isSuccess(
- contacts_db_get_records_with_query(query, 0, 0, &logs))
- && Database::isSuccess(
- contacts_list_get_count(logs, &count));
-
- if(query)
- {
- contacts_query_destroy(query);
- }
-
- DBG("count: %d", count);
- while(success && count--)
- {
- int id = 0;
- contacts_record_h record = NULL;
-
- success = Database::isSuccess(
- contacts_list_get_current_record_p(logs, &record))
- && Database::isSuccess(
- contacts_record_get_int(record, _contacts_person_phone_log.person_id, &id));
-
- if(success)
- {
- if(id == 0)
- {
- ContactLogRecord *contactLog = new ContactLogRecord();
- success = contactLog->initialize(record);
- if(success)
- {
- m_Logs.push_back(contactLog);
- }
- else
- {
- delete contactLog;
- }
- }
-
- if(count)
- {
- success = Database::isSuccess(contacts_list_next(logs));
- }
- }
- }
-
- if(logs)
- {
- contacts_list_destroy(logs, true);
- }
-
- return success;
- }
-
- void DbDataProvider::onRecordInsert(const char *uri, int id)
- {
- PH_TRACE;
- if(!uri)
- {
- return;
- }
-
- if(strcmp(uri, _contacts_phone_log._uri) == 0)
- {
- onLogInsert(id);
- }
- }
-
- void DbDataProvider::onNumberInsert(int id)
- {
- PH_TRACE;
- ContactNumberRecord *contactNumber = new ContactNumberRecord();
- if(contactNumber->initialize(id))
- {
- m_Numbers.push_back(contactNumber);
- }
- else
- {
- delete contactNumber;
- }
- }
-
- void DbDataProvider::onLogInsert(int id)
- {
- PH_TRACE;
- ContactLogRecord *contactLog = new ContactLogRecord();
-
- if(contactLog->initialize(id))
- {
- bool exists = false;
-
- //check if it's an unsaved number
- if(contactLog->getPersonId() == 0)
- {
- //check if number wasn't already added
- for(Contacts::iterator
- it = m_Logs.begin();
- it != m_Logs.end(); ++it)
- {
- if(contactLog->getNumber().compare((*it)->getNumber()) == 0)
- {
- exists = true;
- break;
- }
- }
- }
- else
- {
- exists = true;
- }
-
- if(!exists)
- {
- m_Logs.push_back(contactLog);
- }
- else
- {
- delete contactLog;
- }
- }
- else
- {
- delete contactLog;
- }
- }
-
-
- void DbDataProvider::onContactNumberChange(const char *uri, void *data)
- {
- PH_TRACE;
- DbDataProvider *dbDataProvider = static_cast<DbDataProvider*>(data);
- if (!uri || !dbDataProvider)
- {
- return;
- }
-
- DBG("uri = %s", uri);
- if (strcmp(uri,_contacts_number._uri) == 0)
- {
- dbDataProvider->fetchNumbers();
- }
- }
- }
- }
-}