*
*/
-#ifndef CONTACTS_CONTACT_DATA_H
-#define CONTACTS_CONTACT_DATA_H
+#ifndef CONTACTS_MODEL_CONTACT_DATA_H
+#define CONTACTS_MODEL_CONTACT_DATA_H
#include <memory>
#include <tizen.h>
}
}
-#endif /* CONTACTS_CONTACT_DATA_H */
+#endif /* CONTACTS_MODEL_CONTACT_DATA_H */
*
*/
-#ifndef CONTACTS_CONTACT_DATA_PROVIDER_H
-#define CONTACTS_CONTACT_DATA_PROVIDER_H
+#ifndef CONTACTS_MODEL_CONTACT_DATA_PROVIDER_H
+#define CONTACTS_MODEL_CONTACT_DATA_PROVIDER_H
#include "Contacts/Model/ContactData.h"
}
}
-#endif /* CONTACTS_CONTACT_DATA_PROVIDER_H */
+#endif /* CONTACTS_MODEL_CONTACT_DATA_PROVIDER_H */
*
*/
-#ifndef CONTACTS_LIST_MODEL_CONTACT_RECORD_PROVIDER_H
-#define CONTACTS_LIST_MODEL_CONTACT_RECORD_PROVIDER_H
+#ifndef CONTACTS_MODEL_CONTACT_RECORD_PROVIDER_H
+#define CONTACTS_MODEL_CONTACT_RECORD_PROVIDER_H
#include "Contacts/Model/ContactDataProvider.h"
#include "Contacts/Model/DbChangeObserver.h"
}
}
-#endif /* CONTACTS_LIST_MODEL_CONTACT_RECORD_PROVIDER_H */
+#endif /* CONTACTS_MODEL_CONTACT_RECORD_PROVIDER_H */
*
*/
-#ifndef CONTACTS_LIST_MODEL_DB_CHANGE_OBSERVER_H
-#define CONTACTS_LIST_MODEL_DB_CHANGE_OBSERVER_H
+#ifndef CONTACTS_MODEL_DB_CHANGE_OBSERVER_H
+#define CONTACTS_MODEL_DB_CHANGE_OBSERVER_H
#include <contacts.h>
#include <functional>
}
}
-#endif /* CONTACTS_LIST_MODEL_DB_CHANGE_OBSERVER_H */
+#endif /* CONTACTS_MODEL_DB_CHANGE_OBSERVER_H */
--- /dev/null
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 CONTACTS_MODEL_SEARCH_DATA_H
+#define CONTACTS_MODEL_SEARCH_DATA_H
+
+#include "Contacts/Model/ContactData.h"
+
+namespace Contacts
+{
+ namespace Model
+ {
+ class SearchData : public ContactData
+ {
+ public:
+ SearchData(ContactData &contactData);
+
+ /**
+ * @see ContactData::getId()
+ */
+ virtual int getId() const override;
+
+ /**
+ * @see ContactData::getName()
+ */
+ virtual const char *getName() const override;
+
+ /**
+ * @see ContactData::getNumber()
+ */
+ virtual const char *getNumber() const override;
+
+ /**
+ * @see ContactData::getImagePath
+ */
+ virtual const char *getImagePath() const override;
+
+ /**
+ * @see ContactData::compare
+ */
+ virtual bool compare(const char *str) override;
+
+ private:
+ friend class SearchProvider;
+
+ ContactData &m_ContactData;
+ };
+ }
+}
+
+#endif /* CONTACTS_MODEL_SEARCH_DATA_H */
--- /dev/null
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 CONTACTS_MODEL_SEARCH_PROVIDER_H
+#define CONTACTS_MODEL_SEARCH_PROVIDER_H
+
+#include "Contacts/Model/ContactDataProvider.h"
+
+#include <unordered_map>
+
+namespace Contacts
+{
+ namespace Model
+ {
+ class SearchData;
+
+ class SearchProvider : public ContactDataProvider
+ {
+ public:
+ SearchProvider();
+ virtual ~SearchProvider() override;
+
+ /**
+ * @see ContactDataProvider::getContactDataList()
+ */
+ virtual const ContactDataList &getContactDataList() override;
+
+ /**
+ * @brief Add @a provider to search provider
+ * @param[in] provider Contact data provider
+ */
+ void addProvider(ContactDataProvider *provider);
+
+ private:
+ typedef std::unordered_map<ContactDataProvider *, ContactDataList::const_iterator> SubProviders;
+ using ContactDataProvider::onInserted;
+
+ ContactData &insertContact(ContactDataList::const_iterator position, ContactData &contact,
+ ContactDataProvider *provider);
+
+ void onInserted(ContactData &contactData, ContactDataProvider *provider);
+ void onUpdated(SearchData &searchData, int changes);
+ void onDeleted(ContactDataList::iterator contactIt, ContactDataProvider *provider);
+
+ ContactDataList m_ContactList;
+ SubProviders m_SubProviders;
+ };
+ }
+}
+
+#endif /* CONTACTS_MODEL_SEARCH_PROVIDER_H */
return strstr(getName(), str); //Todo: Compare unicode strings
}
+const contacts_record_h ContactRecordData::getContactRecord() const
+{
+ return m_Record;
+}
+
void ContactRecordData::setChangedCallback(DbChangeObserver::Callback callback)
{
int id = getContactId(m_Record);
}
}
-const contacts_record_h ContactRecordData::getContactRecord() const
-{
- return m_Record;
-}
-
void ContactRecordData::updateRecord(contacts_record_h record)
{
contacts_record_destroy(m_Record, true);
--- /dev/null
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Contacts/Model/SearchData.h"
+
+using namespace Contacts::Model;
+
+SearchData::SearchData(ContactData &contactData)
+ : ContactData(contactData.getType()), m_ContactData(contactData)
+{
+}
+
+int SearchData::getId() const
+{
+ return m_ContactData.getId();
+}
+
+const char *SearchData::getName() const
+{
+ return m_ContactData.getName();
+}
+
+const char *SearchData::getNumber() const
+{
+ return m_ContactData.getNumber();
+}
+
+const char *SearchData::getImagePath() const
+{
+ return m_ContactData.getImagePath();
+}
+
+bool SearchData::compare(const char *str)
+{
+ /* Todo: Refactor method logic to return much more informative value,
+ according to what object type we currently wrap */
+
+ return false;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Contacts/Model/SearchProvider.h"
+#include "Contacts/Model/SearchData.h"
+#include "Utils/Range.h"
+
+using namespace Contacts::Model;
+using namespace Utils;
+using namespace std::placeholders;
+
+SearchProvider::SearchProvider()
+{
+}
+
+SearchProvider::~SearchProvider()
+{
+ for (auto &&contact : m_ContactList) {
+ delete contact;
+ }
+}
+
+const ContactDataList &SearchProvider::getContactDataList()
+{
+ return m_ContactList;//Todo: Return filtered list by search engine instead of all contacts
+}
+
+void SearchProvider::addProvider(ContactDataProvider *provider)
+{
+ const ContactDataList &list = provider->getContactDataList();
+ for (auto it = list.begin(); it != list.end(); ++it) {
+ insertContact(m_ContactList.end(), **it, provider);
+ }
+
+ m_SubProviders.insert({ provider, --m_ContactList.end() });
+ provider->setInsertCallback(
+ [this, provider](ContactData &contactData) {
+ onInserted(contactData, provider);
+ });
+}
+
+ContactData &SearchProvider::insertContact(ContactDataList::const_iterator position, ContactData &contact,
+ ContactDataProvider *provider)
+{
+ auto searchData = new SearchData(contact);
+ auto newDataIt = m_ContactList.insert(position, searchData);
+
+ ContactDataList::iterator contactIt = --m_ContactList.end();
+
+ contact.setUpdateCallback(std::bind(&SearchProvider::onUpdated, this, std::ref(*searchData), _1));
+ contact.setDeleteCallback(std::bind(&SearchProvider::onDeleted, this, contactIt, provider));
+
+ if (m_SubProviders.find(provider) != m_SubProviders.end()) {
+ m_SubProviders[provider] = newDataIt;
+ }
+
+ return *searchData;
+}
+
+void SearchProvider::onInserted(ContactData &contactData, ContactDataProvider *provider)
+{
+ auto position = Utils::advance(m_SubProviders[provider], 1);
+ ContactData &searchData = insertContact(position, contactData, provider);
+ onInserted(searchData);
+}
+
+void SearchProvider::onUpdated(SearchData &searchData, int changes)
+{
+ searchData.onUpdated(changes);
+}
+
+void SearchProvider::onDeleted(ContactDataList::iterator contactIt, ContactDataProvider *provider)
+{
+ SearchData *searchData = static_cast<SearchData *>(*contactIt);
+ searchData->onDeleted();
+
+ delete searchData;
+ ContactDataList::const_iterator newBound = m_ContactList.erase(contactIt);
+
+ ContactDataList::const_iterator &oldBound = m_SubProviders[provider];
+ if (oldBound == contactIt) {
+ oldBound = Utils::advance(newBound, -1);
+ }
+}