diff options
Diffstat (limited to 'lib/dialer/Search')
23 files changed, 0 insertions, 2668 deletions
diff --git a/lib/dialer/Search/ContactData.cpp b/lib/dialer/Search/ContactData.cpp deleted file mode 100644 index 7ad0d7e..0000000 --- a/lib/dialer/Search/ContactData.cpp +++ /dev/null @@ -1,63 +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/ContactData.h" - -#include "phone.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - ContactData::ContactData() - { - PH_TRACE; - } - - ContactData::ContactData(const ContactData &other) - { - PH_TRACE; - *this = other; - } - - const std::string & ContactData::getName() const - { - return m_Name; - } - - const std::string & ContactData::getNumber() const - { - return m_Number; - } - - const std::string & ContactData::getImagePath() const - { - return m_ImagePath; - } - - ContactData & ContactData::operator=(const ContactData &other) - { - PH_TRACE; - m_Name = other.m_Name; - m_Number = other.m_Number; - m_ImagePath = other.m_ImagePath; - return *this; - } - } - } -} diff --git a/lib/dialer/Search/ContactData.h b/lib/dialer/Search/ContactData.h deleted file mode 100644 index 57e41bf..0000000 --- a/lib/dialer/Search/ContactData.h +++ /dev/null @@ -1,63 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_CONTACT_DATA_H__ -#define __PHONE_DIALER_SEARCH_CONTACT_DATA_H__ - -#include "Contact.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Contact data storage class - */ - class ContactData : public Common::Contact - { - public: - ContactData(); - ContactData(const ContactData &other); - - /* - * @see Contact::getName - */ - virtual const std::string & getName() const; - - /* - * @see Contact::getNumber - */ - virtual const std::string & getNumber() const; - - /* - * @see Contact::getImagePath - */ - virtual const std::string & getImagePath() const; - - ContactData & operator=(const ContactData &other); - - protected: - std::string m_Name; - std::string m_Number; - std::string m_ImagePath; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_CONTACT_DATA_H__ */ diff --git a/lib/dialer/Search/ContactItem.cpp b/lib/dialer/Search/ContactItem.cpp deleted file mode 100644 index d492df2..0000000 --- a/lib/dialer/Search/ContactItem.cpp +++ /dev/null @@ -1,60 +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/ContactItem.h" -#include "phone.h" -#include "phone-common.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - ContactItem::ContactItem(const Result &result) - : ResultItem(result) - { - PH_TRACE; - } - - char * ContactItem::getText(const char *part) const - { - PH_TRACE; - if(strcmp(part, "elm.text.1") == 0) - { - if(getResult().getMatchType() == Result::ByName) - { - return strdup(getMatch()); - } - else - { - return strdup(getResult().getContact()->getName().c_str()); - } - } - else - { - return ResultItem::getText(part); - } - } - - Elm_Genlist_Item_Class * ContactItem::getClass() const - { - static Elm_Genlist_Item_Class *itemClass = createClass("2text.1icon.4.tb"); - return itemClass; - } - } - } -} diff --git a/lib/dialer/Search/ContactItem.h b/lib/dialer/Search/ContactItem.h deleted file mode 100644 index a2fcad9..0000000 --- a/lib/dialer/Search/ContactItem.h +++ /dev/null @@ -1,54 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_CONTACT_ITEM_H__ -#define __PHONE_DIALER_SEARCH_CONTACT_ITEM_H__ - -#include "Search/ResultItem.h" - -namespace Phone -{ - namespace Dialer - { - /* - * @brief Search results list item with Contact name - * @displays Contact name and number and highlights the match. - */ - namespace Search - { - class ContactItem : public ResultItem - { - public: - /* - * @param result Search result associated with the item - */ - ContactItem(const Result &result); - - /* - * @see Genlist::Item::getText - */ - char * getText(const char *part) const; - - /* - * @see Genlist::Item::getClass - */ - Elm_Genlist_Item_Class * getClass() const; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_CONTACT_ITEM_H__ */ diff --git a/lib/dialer/Search/ContactLogRecord.cpp b/lib/dialer/Search/ContactLogRecord.cpp deleted file mode 100644 index d2d70a1..0000000 --- a/lib/dialer/Search/ContactLogRecord.cpp +++ /dev/null @@ -1,125 +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/ContactLogRecord.h" - -#include "phone.h" -#include "phone-common.h" -#include "Database/Database.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - using Database::Database; - - ContactLogRecord::ContactLogRecord() - { - PH_TRACE; - } - - ContactLogRecord::ContactLogRecord(const ContactLogRecord &other) - : ContactData(other) - { - PH_TRACE; - } - - bool ContactLogRecord::initialize(int id) - { - PH_TRACE; - contacts_query_h query = NULL; - contacts_filter_h filter = NULL; - contacts_list_h list = NULL; - contacts_record_h record = NULL; - unsigned ids[] = { - _contacts_person_phone_log.person_id, - _contacts_person_phone_log.address, - }; - - bool success = Database::isSuccess( - contacts_filter_create(_contacts_person_phone_log._uri, &filter)) - && Database::isSuccess( - contacts_filter_add_int(filter, _contacts_person_phone_log.log_id, CONTACTS_MATCH_EQUAL, id)) - && Database::isSuccess( - contacts_query_create(_contacts_person_phone_log._uri, &query)) - && Database::isSuccess( - contacts_query_set_filter(query, filter)) - && Database::isSuccess( - contacts_query_set_projection(query, ids, sizeof(ids) / sizeof(*ids))) - && Database::isSuccess( - contacts_db_get_records_with_query(query, 0, 0, &list)) - && Database::isSuccess( - contacts_list_get_current_record_p(list, &record)) - && initialize(record); - - if(filter) - { - contacts_filter_destroy(filter); - } - - if(query) - { - contacts_query_destroy(query); - } - - if(list) - { - contacts_list_destroy(list, true); - } - - return success; - } - - bool ContactLogRecord::initialize(contacts_record_h record) - { - PH_TRACE; - char *number = NULL; - int id = 0; - - bool success = Database::isSuccess( - contacts_record_get_str_p(record, _contacts_person_phone_log.address, &number)) - && Database::isSuccess( - contacts_record_get_int(record, _contacts_person_phone_log.person_id, &id)); - - if(success) - { - m_Number.clear(); - if(number) - { - m_Number = number; - } - m_PersonId = id; - } - - return success; - } - - int ContactLogRecord::getPersonId() const - { - return m_PersonId; - } - - ContactLogRecord & ContactLogRecord::operator=(const ContactLogRecord &other) - { - PH_TRACE; - ContactData::operator=(other); - return *this; - } - } - } -} diff --git a/lib/dialer/Search/ContactLogRecord.h b/lib/dialer/Search/ContactLogRecord.h deleted file mode 100644 index b64446c..0000000 --- a/lib/dialer/Search/ContactLogRecord.h +++ /dev/null @@ -1,67 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_CONTACT_LOG_RECORD_H__ -#define __PHONE_DIALER_SEARCH_CONTACT_LOG_RECORD_H__ - -#include <contacts.h> -#include "ContactData.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Contact data access object based on database record - * from _contacts_person_phone_log view. - */ - class ContactLogRecord : public ContactData - { - public: - ContactLogRecord(); - ContactLogRecord(const ContactLogRecord &other); - - /* - * @brief Initialize by fetching contact data from database by Log ID - * @param id Log ID from _contacts_phone_log view - * @return true on success, false otherwise - */ - bool initialize(int id); - - /* - * @brief Initialize with data from database log record - * @param record Record from _contacts_person_phone_log view - */ - bool initialize(contacts_record_h record); - - /* - * @brief Get person ID associated with log record - * @return Person ID or 0 for unsaved number - */ - int getPersonId() const; - - ContactLogRecord & operator=(const ContactLogRecord &other); - - private: - int m_PersonId; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_CONTACT_LOG_RECORD_H__ */ diff --git a/lib/dialer/Search/ContactNumberRecord.cpp b/lib/dialer/Search/ContactNumberRecord.cpp deleted file mode 100644 index 0a399ad..0000000 --- a/lib/dialer/Search/ContactNumberRecord.cpp +++ /dev/null @@ -1,135 +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/ContactNumberRecord.h" - -#include "phone.h" -#include "phone-common.h" -#include "Database/Database.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - using Database::Database; - - ContactNumberRecord::ContactNumberRecord() - { - PH_TRACE; - } - - ContactNumberRecord::ContactNumberRecord(const ContactNumberRecord &other) - : ContactData(other) - { - PH_TRACE; - } - - bool ContactNumberRecord::initialize(int id) - { - PH_TRACE; - contacts_query_h query = NULL; - contacts_filter_h filter = NULL; - contacts_list_h list = NULL; - contacts_record_h record = NULL; - unsigned ids[] = { - _contacts_contact_number.display_name, - _contacts_contact_number.number, - _contacts_contact_number.image_thumbnail_path - }; - - bool success = Database::isSuccess( - contacts_filter_create(_contacts_contact_number._uri, &filter)) - && Database::isSuccess( - contacts_filter_add_int(filter, _contacts_contact_number.number_id, CONTACTS_MATCH_EQUAL, id)) - && Database::isSuccess( - contacts_query_create(_contacts_contact_number._uri, &query)) - && Database::isSuccess( - contacts_query_set_filter(query, filter)) - && Database::isSuccess( - contacts_query_set_projection(query, ids, sizeof(ids) / sizeof(*ids))) - && Database::isSuccess( - contacts_db_get_records_with_query(query, 0, 0, &list)) - && Database::isSuccess( - contacts_list_get_current_record_p(list, &record)) - && initialize(record); - - if(filter) - { - contacts_filter_destroy(filter); - } - - if(query) - { - contacts_query_destroy(query); - } - - if(list) - { - contacts_list_destroy(list, true); - } - - return success; - } - - bool ContactNumberRecord::initialize(contacts_record_h record) - { - PH_TRACE; - char *name = NULL; - char *number = NULL; - char *image = NULL; - - bool success = Database::isSuccess( - contacts_record_get_str_p(record, _contacts_contact_number.display_name, &name)) - && Database::isSuccess( - contacts_record_get_str_p(record, _contacts_contact_number.number, &number)) - && Database::isSuccess( - contacts_record_get_str_p(record, _contacts_contact_number.image_thumbnail_path, &image)); - - if(success) - { - m_Name.clear(); - if(name) - { - m_Name = name; - } - - m_Number.clear(); - if(number) - { - m_Number = number; - } - - m_ImagePath.clear(); - if(image) - { - m_ImagePath = image; - } - } - - return success; - } - - ContactNumberRecord & ContactNumberRecord::operator=(const ContactNumberRecord &other) - { - PH_TRACE; - ContactData::operator=(other); - return *this; - } - } - } -} diff --git a/lib/dialer/Search/ContactNumberRecord.h b/lib/dialer/Search/ContactNumberRecord.h deleted file mode 100644 index bb4eb35..0000000 --- a/lib/dialer/Search/ContactNumberRecord.h +++ /dev/null @@ -1,58 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_CONTACT_NUMBER_RECORD_H__ -#define __PHONE_DIALER_SEARCH_CONTACT_NUMBER_RECORD_H__ - -#include <contacts.h> -#include "Search/ContactData.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Contact data access object based on database record - * from _contacts_contact_number view. - */ - class ContactNumberRecord : public ContactData - { - public: - ContactNumberRecord(); - ContactNumberRecord(const ContactNumberRecord &other); - - /* - * @brief Initialize by fetching contact data from database by number ID - * @param id Number ID from _contacts_number view - * @return true on success, false otherwise - */ - bool initialize(int id); - - /* - * @brief Initialize with data from database number record - * @param record Record from _contacts_contact_number view - */ - bool initialize(contacts_record_h record); - - ContactNumberRecord & operator=(const ContactNumberRecord &other); - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_CONTACT_NUMBER_RECORD_H__ */ diff --git a/lib/dialer/Search/Controller.cpp b/lib/dialer/Search/Controller.cpp deleted file mode 100644 index 0d55fae..0000000 --- a/lib/dialer/Search/Controller.cpp +++ /dev/null @@ -1,128 +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/Controller.h" - -#include "phone.h" -#include "phone-dialer.h" -#include "ph-dialer-view.h" -#include "ph-dialer-utils.h" -#include "Search/ContactItem.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - Controller::Controller() - : m_DialerView(NULL) - { - PH_TRACE; - } - - Controller::~Controller() - { - PH_TRACE; - } - - bool Controller::initialize(DialerView *dialer) - { - PH_TRACE; - if(!dialer) - { - return false; - } - - bool success = m_DataProvider.initialize() - && m_Engine.initialize(m_DataProvider) - && m_ResultWidget.initialize(dialer->layout) - && m_ResultPopup.initialize(dialer->navi); - - if(success) - { - m_DialerView = dialer; - m_Engine.setListener(this); - m_ResultWidget.setListener(this); - m_ResultPopup.setListener(this); - evas_object_smart_callback_priority_add(m_DialerView->entry, "changed", EVAS_CALLBACK_PRIORITY_AFTER, onTextChange, this); - } - - return success; - } - - void Controller::onSearchResultsChange(const Results &results) - { - PH_TRACE; - if(!m_Engine.getQuery().empty()) - { - const Results &results = m_Engine.getResults(); - DBG("count: %d", results.size()); - - if(!results.empty()) - { - m_ResultWidget.setResult(results.front()); - } - m_ResultWidget.setResultCount(results.size()); - } - else - { - m_ResultWidget.hide(); - } - } - - void Controller::onSearchResultSelect(const Result &result) - { - PH_TRACE; - ph_dialer_entry_set_number(*m_DialerView, result.getContact()->getNumber(), CURSOR_END); - } - - void Controller::onAddToContacts() - { - PH_TRACE; - dialer_add_contact(m_DialerView); - } - - void Controller::onTopResultSelect() - { - PH_TRACE; - onSearchResultSelect(m_Engine.getResults().front()); - } - - void Controller::onShowMoreResults() - { - PH_TRACE; - m_ResultPopup.setResults(m_Engine.getResults()); - m_ResultPopup.show(); - m_DialerView->popup = m_ResultPopup.getPopup(); - } - - void Controller::onTextChange(void *data, Evas_Object *obj, void *event_info) - { - PH_TRACE; - if(!data || !obj) - { - return; - } - - Controller *pthis = static_cast<Controller*>(data); - char text[PH_TEXT_MAX_LEN]; - ph_dialer_util_get_pure_numstr_with_plus(pthis->m_DialerView, text); - pthis->m_Engine.setQuery(text); - } - } - } -} diff --git a/lib/dialer/Search/Controller.h b/lib/dialer/Search/Controller.h deleted file mode 100644 index eac5f0f..0000000 --- a/lib/dialer/Search/Controller.h +++ /dev/null @@ -1,76 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_CONTROLLER_H__ -#define __PHONE_DIALER_SEARCH_CONTROLLER_H__ - -#include "Search/Engine.h" -#include "Search/DbDataProvider.h" -#include "Search/ResultWidget.h" -#include "Search/ResultPopup.h" - -struct DialerView; - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Dialer search controller - * @details Controls search result widget and popup, - * initializes data provider and search engine. - * Handles widget events and initiates the search - * using search engine whenever dialer's text is changed. - */ - class Controller : - public EngineListener, - public ResultWidgetListener, - public ResultPopupListener - { - public: - Controller(); - ~Controller(); - - /* - * @brief Initialize dialer search controller - * @param dialer Dialer view - */ - bool initialize(DialerView *dialer); - - private: - void onSearchResultsChange(const Results &results); - void onSearchResultSelect(const Result &result); - - void onAddToContacts(); - void onTopResultSelect(); - void onShowMoreResults(); - - static void onTextChange(void *data, Evas_Object *obj, void *event_info); - - Engine m_Engine; - DbDataProvider m_DataProvider; - - DialerView *m_DialerView; - ResultWidget m_ResultWidget; - ResultPopup m_ResultPopup; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_CONTROLLER_H__ */ diff --git a/lib/dialer/Search/DataProvider.h b/lib/dialer/Search/DataProvider.h deleted file mode 100644 index 576a3f6..0000000 --- a/lib/dialer/Search/DataProvider.h +++ /dev/null @@ -1,56 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_DATA_PROVIDER_H__ -#define __PHONE_DIALER_SEARCH_DATA_PROVIDER_H__ - -#include "Contact.h" -#include "NonCopyable.h" -#include "SharedPtr.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - typedef Utils::SharedPtr<Common::Contact> ContactPtr; - - /* - * @brief Data provider interface for dialer search engine - */ - class DataProvider : public Utils::NonCopyable - { - public: - virtual ~DataProvider() { } - - /* - * @return The current count of data items that can be provided - */ - virtual size_t getCount() const = 0; - - /* - * @brief Get contact data item by index - * @param index Index of data item - * @return Shared pointer to contact data or NULL if out of range - */ - virtual ContactPtr getData(size_t index) const = 0; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_DATA_PROVIDER_H__ */ 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(); - } - } - } - } -} diff --git a/lib/dialer/Search/DbDataProvider.h b/lib/dialer/Search/DbDataProvider.h deleted file mode 100644 index 1d52082..0000000 --- a/lib/dialer/Search/DbDataProvider.h +++ /dev/null @@ -1,84 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_DB_DATA_PROVIDER_H__ -#define __PHONE_DIALER_SEARCH_DB_DATA_PROVIDER_H__ - -#include <vector> -#include <contacts.h> - -#include "Contact.h" -#include "Database/Database.h" -#include "Database/Listener.h" -#include "Search/DataProvider.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Database data provider for dialer search engine - * @details The provider fetches numbers from the address book - * and unsaved numbers from call logs and provides - * encapsulated access to this data. - * Provider updates its data based on changes made to the database. - */ - class DbDataProvider : - public DataProvider, - public Database::Listener - { - public: - DbDataProvider(); - virtual ~DbDataProvider(); - - /* - * @brief Initialize data provider and fetch initial data - * @return true on success, false otherwise - */ - bool initialize(); - - /* - * @see DataProvider::getCount - */ - virtual size_t getCount() const; - - /* - * @see DataProvider::getData - */ - virtual ContactPtr getData(size_t index) const; - - private: - bool fetchNumbers(); - bool fetchLogs(); - - void onRecordInsert(const char *uri, int id); - void onNumberInsert(int id); - void onLogInsert(int id); - static void onContactNumberChange(const char *uri, void *data); - - bool m_Initialized; - - typedef std::vector<ContactPtr> Contacts; - Contacts m_Numbers; - Contacts m_Logs; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_DB_DATA_PROVIDER_H__ */ diff --git a/lib/dialer/Search/Engine.cpp b/lib/dialer/Search/Engine.cpp deleted file mode 100644 index a1b1d5d..0000000 --- a/lib/dialer/Search/Engine.cpp +++ /dev/null @@ -1,265 +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/Engine.h" - -#include "phone.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - Engine::Engine() - : m_DataProvider(NULL), m_Listener(NULL) - { - PH_TRACE; - } - - Engine::~Engine() - { - PH_TRACE; - clearQuery(); - } - - bool Engine::initialize(const DataProvider &provider) - { - PH_TRACE; - m_DataProvider = &provider; - m_History.resize(1); - return true; - } - - void Engine::setListener(EngineListener *listener) - { - PH_TRACE; - m_Listener = listener; - } - - const std::string & Engine::getQuery() const - { - return m_Query; - } - - void Engine::setQuery(const std::string &query) - { - PH_TRACE; - DBG("old query: %s", m_Query.c_str()); - DBG("new query: %s", query.c_str()); - - std::string::const_iterator it1 = m_Query.begin(); - std::string::const_iterator it2 = query.begin(); - - //find first position where old and new query mismatch - while(it1 != m_Query.end() - && it2 != query.end() - && *it1 == *it2) - { - ++it1; - ++it2; - } - - if(it1 != m_Query.end()) - { - truncateQuery(m_Query.end() - it1); - } - - if(it2 != query.end()) - { - appendQuery(query.substr(it2 - query.begin())); - } - } - - void Engine::appendQuery(const std::string &str) - { - PH_TRACE; - DBG("old query: %s", m_Query.c_str()); - m_Query.append(str); - DBG("new query: %s", m_Query.c_str()); - - //if there are no previous results - if(m_HistoryIndex.empty()) - { - searchInContacts(); - } - else - { - //use previous results for search - int prev = m_HistoryIndex.back(); - if(!m_History.at(prev).empty()) - { - m_History.resize(m_History.size() + 1); - searchInResults(m_History.at(prev)); - } - } - - m_HistoryIndex.resize(m_Query.length(), -1); - m_HistoryIndex.back() = m_History.size() - 1; - } - - void Engine::truncateQuery(unsigned count) - { - PH_TRACE; - DBG("old query: %s", m_Query.c_str()); - - if(count >= m_Query.length()) - { - clearQuery(); - } - else - { - m_Query.erase(m_Query.length() - count); - DBG("new query: %s", m_Query.c_str()); - m_HistoryIndex.resize(m_Query.length(), -1); - - int prev = -1; - //find nearest previous results - for(HistoryIndex::reverse_iterator - it = m_HistoryIndex.rbegin(); - it != m_HistoryIndex.rend(); ++it) - { - if(*it > -1) - { - prev = *it; - break; - } - } - - //previous results found - if(prev > -1) - { - DBG("prev: %d", prev); - //remove all results after found results - m_History.erase(m_History.begin() + prev + 1, m_History.end()); - - //if found results correspond exactly to the new query - if(prev == m_HistoryIndex.back()) - { - notifyChange(); - } - else - { - m_History.resize(m_History.size() + 1); - searchInResults(m_History[prev]); - } - } - else - { - //no previous results found - m_History.back().clear(); - searchInContacts(); - } - - m_HistoryIndex.back() = m_History.size() - 1; - } - } - - void Engine::clearQuery() - { - PH_TRACE; - m_Query.clear(); - m_HistoryIndex.clear(); - m_History.resize(1); - m_History.back().clear(); - notifyChange(); - } - - const Results & Engine::getResults() const - { - return m_History.back(); - } - - bool Engine::match(const ContactPtr &contact, Result &result) - { - return matchByNumber(contact, result) || matchByName(contact, result); - } - - bool Engine::matchByNumber(const ContactPtr &contact, Result &result) - { - PH_TRACE; - size_t pos = contact->getNumber().find(m_Query); - - if(pos != std::string::npos) - { - result = Result(contact, Result::ByNumber, pos, m_Query.length()); - DBG("matched: %s", contact->getNumber().c_str()); - return true; - } - else - { - return false; - } - } - - bool Engine::matchByName(const ContactPtr &contact, Result &result) - { - PH_TRACE; - //TODO: implement match by name - return false; - } - - void Engine::notifyChange() - { - PH_TRACE; - if(m_Listener) - { - m_Listener->onSearchResultsChange(m_History.back()); - } - } - - void Engine::searchInContacts() - { - PH_TRACE; - Result result; - Results ¤t = m_History.back(); - - size_t count = m_DataProvider->getCount(); - for(size_t i = 0; i < count; ++i) - { - const ContactPtr &contact = m_DataProvider->getData(i); - if(contact && match(contact, result)) - { - current.push_back(result); - } - } - - DBG("count: %d", current.size()); - notifyChange(); - } - - void Engine::searchInResults(const Results &results) - { - PH_TRACE; - Result result; - Results ¤t = m_History.back(); - - for(Results::const_iterator - it = results.begin(); - it != results.end(); ++it) - { - if(match(it->getContact(), result)) - { - current.push_back(result); - } - } - - DBG("count: %d", current.size()); - notifyChange(); - } - } - } -} diff --git a/lib/dialer/Search/Engine.h b/lib/dialer/Search/Engine.h deleted file mode 100644 index 0374953..0000000 --- a/lib/dialer/Search/Engine.h +++ /dev/null @@ -1,202 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_ENGINE_H__ -#define __PHONE_DIALER_SEARCH_ENGINE_H__ - -#include <vector> -#include <string> - -#include "NonCopyable.h" -#include "Search/DataProvider.h" -#include "Search/Result.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Dialer search engine event listener - */ - class EngineListener - { - public: - virtual ~EngineListener() { } - - /* - * @brief Called whenever search results were changed - * @param results Search results - */ - virtual void onSearchResultsChange(const Results &results) = 0; - }; - - /* - * @brief Dialer incremental search engine - * @details Implements incremental search through provided contact data. - * Maintains incremental result history allowing to narrow the search - * for each next input into query and to fall back to previous results - * on query truncation. - */ - class Engine : public Utils::NonCopyable - { - public: - Engine(); - ~Engine(); - - /* - * @brief Initialize search engine - * @param provider Input data provider - * @see DataProvider - */ - bool initialize(const DataProvider &provider); - - /* - * @brief Set listener for search events - * @see EngineListener - */ - void setListener(EngineListener *listener); - - /* - * @return Current search query string - */ - const std::string & getQuery() const; - - /* - * @brief Set new query string and begin search - * @details Calculates the difference between the current query - * and the new query and uses appendQuery and truncateQuery - * as needed - * @param query Query string - */ - void setQuery(const std::string &query); - - /* - * @brief Append string to the current query string - * and begin search - * @details Search is performed through previous results if any - * or data provider is used - * @param str String to append to current query - */ - void appendQuery(const std::string &str); - - /* - * @brief Remove character from the end of current query string - * and begin search - * @details Falls back to previous results and performs search if necessary - * or uses data provider if there are no results to fall back to - * @param count Number of character to remove form the end of query string - */ - void truncateQuery(unsigned count); - - /* - * @brief Clear query string and remove all results - */ - void clearQuery(); - - /* - * @return Current search results - */ - const Results & getResults() const; - - private: - bool match(const ContactPtr &contact, Result &result); - bool matchByNumber(const ContactPtr &contact, Result &result); - bool matchByName(const ContactPtr &contact, Result &result); - - void notifyChange(); - - /* - * @brief Search through contact data using data provider - * @remarks Results are saved into m_History.back() - */ - void searchInContacts(); - - /* - * @brief Search through provided results - * @remarks Results are saved into m_History.back() - * @param results Results to use as input data - */ - void searchInResults(const Results &results); - - typedef std::vector<Results> History; - typedef std::vector<int> HistoryIndex; - - /* - * @brief Current search query - */ - std::string m_Query; - - - /* - * @brief Incremental search history, maintains sets of results - * @details Each call to appendQuery adds one set of results - * to the history if previous results weren't empty. - * Each call to truncateQuery removes one or more - * result sets from the history. - */ - History m_History; - - /* - * @brief Maps each substring of the query string that begins at 0 - * to the corresponding result set in result history. - * @details History index is always the same size as search query. - * Each substring of the query string that begins at 0 - * and ends at N (subquery) has a corresponding element - * in history index at position N that contains the index - * of the result set for this subquery in search history. - * - * If there are no results for a subquery in search history - * then the value of corresponding element in history index - * is -1. - * @example - * @code - * - * DataProvider *provider = new SomeProvider(); - * Engine engine; - * engine.initialize(*provider); - * - * engine.appendQuery("0"); - * engine.appendQuery("9"); - * engine.appendQuery("1"); - * engine.setQuery("0913051032"); - * - * @endcode - * - * Given the appropriate data provided by SomeProvider - * the engine will be in the following internal state: - * - * | 0| 9| 1| 3| 0| 5| 1| 0| 3| 2| <- m_Query - * | 0| 1| 2|-1|-1|-1|-1|-1|-1| 3| <- m_HistoryIndex - * - * | 0| 1| 2| 3| <- m_History indices - * ^ ^ ^ ^ - * | | | 1 result (0913051032) - * | | 10 results - * | 16 results - * 23 results - */ - HistoryIndex m_HistoryIndex; - - const DataProvider *m_DataProvider; - EngineListener *m_Listener; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_ENGINE_H__ */ diff --git a/lib/dialer/Search/Result.cpp b/lib/dialer/Search/Result.cpp deleted file mode 100644 index 60a565a..0000000 --- a/lib/dialer/Search/Result.cpp +++ /dev/null @@ -1,113 +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/Result.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - Result::Result() - : m_MatchType(ByNumber), m_MatchPos(0), m_MatchLength(0) - { - PH_TRACE; - } - - Result::Result(const Result &result) - { - PH_TRACE; - *this = result; - } - - Result::Result(const ContactPtr &contact, MatchType matchType, - size_t matchPos, size_t matchLength) - : m_Contact(contact), m_MatchType(matchType), - m_MatchPos(matchPos), m_MatchLength(matchLength) - { - PH_TRACE; - } - - Result::MatchType Result::getMatchType() const - { - return m_MatchType; - } - - const ContactPtr & Result::getContact() const - { - return m_Contact; - } - - size_t Result::getMatchPos() const - { - return m_MatchPos; - } - - size_t Result::getMatchLength() const - { - return m_MatchLength; - } - - bool Result::formatMatch(std::string &formattedMatch, - const std::string &matchBegin, - const std::string &matchEnd) const - { - PH_TRACE; - const std::string *match = NULL; - if(m_MatchType == ByNumber) - { - match = &getContact()->getNumber(); - } - else - { - match = &getContact()->getName(); - } - - if(match && match->length() >= m_MatchPos + m_MatchLength) - { - formattedMatch.clear(); - if(m_MatchPos > 0) - { - formattedMatch.append(match->c_str(), m_MatchPos); - } - - formattedMatch - .append(matchBegin) - .append(match->c_str() + m_MatchPos, m_MatchLength) - .append(matchEnd) - .append(match->c_str() + m_MatchPos + m_MatchLength); - - return true; - } - else - { - return false; - } - } - - Result & Result::operator=(const Result &result) - { - PH_TRACE; - m_MatchType = result.m_MatchType; - m_Contact = result.m_Contact; - m_MatchPos = result.m_MatchPos; - m_MatchLength = result.m_MatchLength; - return *this; - } - } - } -} diff --git a/lib/dialer/Search/Result.h b/lib/dialer/Search/Result.h deleted file mode 100644 index 6bc8b1a..0000000 --- a/lib/dialer/Search/Result.h +++ /dev/null @@ -1,112 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_RESULT_H__ -#define __PHONE_DIALER_SEARCH_RESULT_H__ - -#include <vector> -#include <string> - -#include "Contact.h" -#include "SharedPtr.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - typedef Utils::SharedPtr<Common::Contact> ContactPtr; - - /* - * @brief Dialer search result data - */ - class Result - { - public: - /* - * @brief Specifies by which field contact data matches search query - */ - enum MatchType - { - ByNumber, - ByName - }; - - Result(); - Result(const Result &result); - Result(const ContactPtr &contact, MatchType matchType, - size_t matchPos, size_t matchLength); - - /* - * @return Type of the result - * @see Result::MatchType - */ - MatchType getMatchType() const; - - /* - * @return Contact data associated with result - */ - const ContactPtr & getContact() const; - - /* - * @return Start position of the match in matched string - */ - size_t getMatchPos() const; - - /* - * @return Length of matched substring (i.e. length of search query) - */ - size_t getMatchLength() const; - - /* - * @brief Format matched field by prepending matchBegin - * and appending matchEnd strings to the matching substring. - * @par example - * If contact's number is "1234567" and search query is "34" - * then the following code: - * - * @code - * std::string match; - * result.formatMatch(match, "<match>", "</>"); - * @endcode - * - * will write "12<match>34</>567" in "match" string - * - * @param[out] formattedMatch Formatted match string - * @param[in] matchBegin String to prepend matching substring with - * @param[in] matchEnd String to append to matching substring - * @return true on success, false otherwise - */ - bool formatMatch(std::string &formattedMatch, - const std::string &matchBegin, - const std::string &matchEnd) const; - - Result & operator=(const Result &result); - - private: - ContactPtr m_Contact; - MatchType m_MatchType; - size_t m_MatchPos; - size_t m_MatchLength; - }; - - typedef std::vector<Result> Results; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_RESULT_H__ */ diff --git a/lib/dialer/Search/ResultItem.cpp b/lib/dialer/Search/ResultItem.cpp deleted file mode 100644 index f002fb8..0000000 --- a/lib/dialer/Search/ResultItem.cpp +++ /dev/null @@ -1,95 +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/ResultItem.h" -#include "phone.h" -#include "phone-common.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - ResultItem::ResultItem(const Result &result) - : m_Result(result) - { - PH_TRACE; - getResult().formatMatch(m_Match, "<match>", "</>"); - } - - char * ResultItem::getText(const char *part) const - { - PH_TRACE; - if(getResult().getMatchType() == Result::ByNumber) - { - return strdup(getMatch()); - } - else - { - return strdup(getResult().getContact()->getNumber().c_str()); - } - } - - Evas_Object * ResultItem::getContent(const char *part, Evas_Object *parent) const - { - PH_TRACE; - Evas_Object *icon = elm_icon_add(parent); - if(icon) - { - const char *path = NULL; - if(getResult().getContact()->getImagePath().empty()) - { - path = IMG_DEFAULT; - } - else - { - path = getResult().getContact()->getImagePath().c_str(); - } - - Eina_Bool success = elm_image_file_set(icon, path, NULL); - if(!success) - { - evas_object_del(icon); - ERR("elm_image_file_set failed, path: %s", path); - } - } - else - { - ERR("elm_icon_add failed"); - } - - return icon; - } - - Elm_Genlist_Item_Class * ResultItem::getClass() const - { - static Elm_Genlist_Item_Class *itemClass = createClass("1text.1icon.2.tb"); - return itemClass; - } - - const Result & ResultItem::getResult() const - { - return m_Result; - } - - const char * ResultItem::getMatch() const - { - return m_Match.c_str(); - } - } - } -} diff --git a/lib/dialer/Search/ResultItem.h b/lib/dialer/Search/ResultItem.h deleted file mode 100644 index fcb1ed8..0000000 --- a/lib/dialer/Search/ResultItem.h +++ /dev/null @@ -1,76 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_RESULT_ITEM_H__ -#define __PHONE_DIALER_SEARCH_RESULT_ITEM_H__ - -#include <string> -#include "Item.h" -#include "Search/Result.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Search results list item without Contact name - * @details Displays matched number and highlights the match. - */ - class ResultItem : public Ui::Genlist::Item - { - public: - /* - * @param result Search result associated with the item - */ - ResultItem(const Result &result); - - /* - * @see Genlist::Item::getText - */ - char * getText(const char *part) const; - - /* - * @see Genlist::Item::getContent - */ - Evas_Object * getContent(const char *part, Evas_Object *parent) const; - - /* - * @see Genlist::Item::getClass - */ - Elm_Genlist_Item_Class * getClass() const; - - /* - * @return Search result associated with item - */ - const Result & getResult() const; - - protected: - /* - * @return Search match string with textblock markup - */ - const char * getMatch() const; - - private: - Result m_Result; - std::string m_Match; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_RESULT_ITEM_H__ */ diff --git a/lib/dialer/Search/ResultPopup.cpp b/lib/dialer/Search/ResultPopup.cpp deleted file mode 100644 index fa06be8..0000000 --- a/lib/dialer/Search/ResultPopup.cpp +++ /dev/null @@ -1,159 +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/ResultPopup.h" - -#include "phone.h" -#include "phone-common.h" -#include "Search/ContactItem.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - ResultPopup::ResultPopup() - : m_Popup(NULL), m_Listener(NULL) - { - PH_TRACE; - } - - ResultPopup::~ResultPopup() - { - PH_TRACE; - if(m_Popup) - { - evas_object_del(m_Popup); - m_Popup = NULL; - } - } - - bool ResultPopup::initialize(Evas_Object *parent) - { - PH_TRACE; - m_Popup = elm_popup_add(parent); - if(!m_Popup) - { - return false; - } - - elm_object_style_set(m_Popup, "min_menustyle"); - evas_object_smart_callback_add(m_Popup, "block,clicked", onHide, this); - evas_object_size_hint_weight_set(m_Popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - - Evas_Object *button = elm_button_add(m_Popup); - if(!button) - { - evas_object_del(m_Popup); - m_Popup = NULL; - return false; - } - - elm_object_text_set(button, S_(PH_SYS_SK_CANCEL)); - elm_object_part_content_set(m_Popup, "button1", button); - evas_object_smart_callback_add(button, "clicked", onHide, this); - - if(!m_ResultList.create(m_Popup)) - { - evas_object_del(m_Popup); - m_Popup = NULL; - return false; - } - - elm_object_content_set(m_Popup, m_ResultList.getObject()); - evas_object_smart_callback_add(m_ResultList.getObject(), "selected", onResultSelect, this); - return true; - } - - void ResultPopup::setListener(ResultPopupListener *listener) - { - m_Listener = listener; - } - - Evas_Object * ResultPopup::getPopup() const - { - return m_Popup; - } - - void ResultPopup::setResults(const Results &results) - { - PH_TRACE; - elm_genlist_clear(m_ResultList.getObject()); - for(Results::const_iterator - it = results.begin(); - it != results.end(); ++it) - { - if(!it->getContact()->getName().empty()) - { - m_ResultList.append(new ContactItem(*it)); - } - else - { - m_ResultList.append(new ResultItem(*it)); - } - } - } - - void ResultPopup::show() - { - PH_TRACE; - if(m_Popup) - { - evas_object_show(m_Popup); - } - } - - void ResultPopup::hide() - { - PH_TRACE; - if(m_Popup) - { - evas_object_hide(m_Popup); - } - } - - void ResultPopup::onHide(void *data, Evas_Object *obj, void *event) - { - PH_TRACE; - if(data) - { - static_cast<ResultPopup*>(data)->hide(); - } - } - - void ResultPopup::onResultSelect(void *data, Evas_Object *obj, void *event_info) - { - PH_TRACE; - if(!data || !event_info) - { - return; - } - - ResultPopup *popup = static_cast<ResultPopup*>(data); - Elm_Object_Item *objItem = static_cast<Elm_Object_Item*>(event_info); - ResultItem *item = static_cast<ResultItem*>(elm_object_item_data_get(objItem)); - - popup->hide(); - if(popup->m_Listener) - { - popup->m_Listener->onSearchResultSelect(item->getResult()); - } - } - } - } -} - diff --git a/lib/dialer/Search/ResultPopup.h b/lib/dialer/Search/ResultPopup.h deleted file mode 100644 index e4500c3..0000000 --- a/lib/dialer/Search/ResultPopup.h +++ /dev/null @@ -1,96 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_RESULT_POPUP_H__ -#define __PHONE_DIALER_SEARCH_RESULT_POPUP_H__ - -#include <Elementary.h> -#include "NonCopyable.h" -#include "Genlist.h" -#include "Search/Result.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Dialer search result popup event listener - */ - class ResultPopupListener - { - public: - virtual ~ResultPopupListener() { } - - /* - * @brief Called when result is selected from result list - * @param result Selected result - */ - virtual void onSearchResultSelect(const Result &result) = 0; - }; - - class ResultPopup : public Utils::NonCopyable - { - public: - ResultPopup(); - ~ResultPopup(); - - /* - * @brief Initialize popup. - * @param parent Parent Evas object for popup - */ - bool initialize(Evas_Object *parent); - - /* - * @param listener Popup events listener - */ - void setListener(ResultPopupListener *listener); - - /* - * @return Popup Evas object - */ - Evas_Object * getPopup() const; - - /* - * @brief Set search results to be displayed in popup. - * @param results Search results - */ - void setResults(const Results &results); - - /* - * @brief Show popup. - */ - void show(); - - /* - * @brief Hide popup. - */ - void hide(); - - private: - static void onHide(void *data, Evas_Object *obj, void *event_info); - static void onResultSelect(void *data, Evas_Object *obj, void *event_info); - - Evas_Object *m_Popup; - Ui::Genlist::Genlist m_ResultList; - ResultPopupListener *m_Listener; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_RESULT_POPUP_H__ */ diff --git a/lib/dialer/Search/ResultWidget.cpp b/lib/dialer/Search/ResultWidget.cpp deleted file mode 100644 index ab89fc2..0000000 --- a/lib/dialer/Search/ResultWidget.cpp +++ /dev/null @@ -1,151 +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/ResultWidget.h" - -#include "phone.h" -#include "phone-common.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - ResultWidget::ResultWidget() - : m_Layout(NULL), m_Icon(NULL), m_Listener(NULL) - { - PH_TRACE; - } - - ResultWidget::~ResultWidget() - { - PH_TRACE; - if(m_Icon) - { - evas_object_del(m_Icon); - m_Icon = NULL; - } - } - - bool ResultWidget::initialize(Evas_Object *layout) - { - PH_TRACE; - if(!layout) - { - return false; - } - - m_Icon = elm_icon_add(layout); - if(!m_Icon) - { - return false; - } - elm_object_part_content_set(layout, "icon", m_Icon); - edje_object_signal_callback_add(_EDJ(layout), "softkey_clicked", "*", onLayoutEvent, this); - - m_Layout = layout; - return true; - } - - void ResultWidget::setListener(ResultWidgetListener *listener) - { - m_Listener = listener; - } - - void ResultWidget::setResult(const Result &result) - { - PH_TRACE; - - std::string number; - result.formatMatch(number, "<mark>", "</mark>"); - - elm_object_part_text_set(m_Layout, "textName", result.getContact()->getName().c_str()); - elm_object_part_text_set(m_Layout, "textNumber", number.c_str()); - - const char *path = NULL; - if(result.getContact()->getImagePath().empty()) - { - path = IMG_DEFAULT; - } - else - { - path = result.getContact()->getImagePath().c_str(); - } - - elm_image_file_set(m_Icon, path, NULL); - } - - void ResultWidget::setResultCount(unsigned count) - { - PH_TRACE; - if(count == 0) - { - char buffer[PH_TEXT_MAX_LEN] = { 0 }; - sprintf(buffer, "+ %s", T_(PH_GET_TEXT_BASIC, PHTEXT_ADD_TO_CONTACTS)); - elm_object_part_text_set(m_Layout, "textAddToContacts", buffer); - edje_object_signal_emit(_EDJ(m_Layout), "suggestion/showAddToContacts", "suggestion"); - } - else if(count == 1) - { - edje_object_signal_emit(_EDJ(m_Layout), "suggestion/showSingleItemView", "suggestion"); - } - else - { - char matchCount[16]; - sprintf(matchCount, "%d", count); - elm_object_part_text_set(m_Layout, "textNumberOfMatches", matchCount); - edje_object_signal_emit(_EDJ(m_Layout), "suggestion/showMultiItemView", "suggestion"); - } - } - - void ResultWidget::hide() - { - PH_TRACE; - edje_object_signal_emit(_EDJ(m_Layout), "suggestion/hide", "suggestion"); - } - - void ResultWidget::onLayoutEvent(void *data, Evas_Object *obj, const char *emission, const char *source) - { - PH_TRACE; - if(!data || !source) - { - return; - } - - ResultWidgetListener *listener = static_cast<ResultWidget*>(data)->m_Listener; - if(!listener) - { - DBG("no listener"); - return; - } - - if(strcmp(source, "suggestion") == 0) - { - listener->onAddToContacts(); - } - else if(strcmp(source, "suggestionListTopItem") == 0) - { - listener->onTopResultSelect(); - } - else if(strcmp(source, "suggestionListButton") == 0) - { - listener->onShowMoreResults(); - } - } - } - } -} diff --git a/lib/dialer/Search/ResultWidget.h b/lib/dialer/Search/ResultWidget.h deleted file mode 100644 index fda0d2b..0000000 --- a/lib/dialer/Search/ResultWidget.h +++ /dev/null @@ -1,103 +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. - */ - -#ifndef __PHONE_DIALER_SEARCH_RESULT_WIDGET_H__ -#define __PHONE_DIALER_SEARCH_RESULT_WIDGET_H__ - -#include <Elementary.h> -#include "Search/Result.h" - -namespace Phone -{ - namespace Dialer - { - namespace Search - { - /* - * @brief Listener for search result widget events - */ - class ResultWidgetListener - { - public: - virtual ~ResultWidgetListener() { } - - /* - * @brief Called when "Add to Contact" button is pressed - */ - virtual void onAddToContacts() = 0; - - /* - * @brief Called when displayed top search result is selected - */ - virtual void onTopResultSelect() = 0; - - /* - * @brief Called when show more results button is pressed - */ - virtual void onShowMoreResults() = 0; - }; - - /* - * @brief Displays information about last search - * @details Displays top search result and number of results - * on More Results button or "Add to Contacts" button if no results - */ - class ResultWidget - { - public: - ResultWidget(); - ~ResultWidget(); - - /* - * @brief Initialize widget. - * @param layout Widget Edje layout - */ - bool initialize(Evas_Object *layout); - - /* - * @param listener Widget event listener - */ - void setListener(ResultWidgetListener *listener); - - /* - * @brief Set search result to be displayed by widget. - * @param result Top search result - */ - void setResult(const Result &result); - - /* - * @brief Set search results count to be displayed on More Results button. - * @param count Results count - */ - void setResultCount(unsigned count); - - /* - * @brief Hide widget - */ - void hide(); - - private: - static void onLayoutEvent(void *data, Evas_Object *obj, const char *emission, const char *source); - - Evas_Object *m_Layout; - Evas_Object *m_Icon; - ResultWidgetListener *m_Listener; - }; - } - } -} - -#endif /* __PHONE_DIALER_SEARCH_RESULT_WIDGET_H__ */ |