+++ /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_CONTACT_NUMBER_DATA_H
-#define CONTACTS_MODEL_CONTACT_NUMBER_DATA_H
-
-#include "Contacts/Model/ContactData.h"
-#include <contacts.h>
-
-namespace Contacts
-{
- namespace Model
- {
- class EXPORT_API ContactNumberData : public ContactData
- {
- public:
- /**
- * @brief Create Number object
- * @param[in] contact Contact object
- * @param[in] numberRecord _contacts_number record
- */
- ContactNumberData(ContactData &contact, contacts_record_h numberRecord);
- virtual ~ContactNumberData() override;
-
- /**
- * @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;
-
- //Todo: Implement support update and delete logic
-
- private:
- ContactData &m_ContactData;
- contacts_record_h m_NumberRecord;
- };
- }
-}
-
-#endif /* CONTACTS_MODEL_CONTACT_NUMBER_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.
- *
- */
-
-#include "Contacts/Model/ContactNumberData.h"
-#include "Common/Database/RecordUtils.h"
-
-using namespace Common::Database;
-using namespace Contacts::Model;
-using namespace Utils;
-
-ContactNumberData::ContactNumberData(ContactData &contact, contacts_record_h numberRecord)
- : ContactData(TypeContactNumber),
- m_ContactData(contact), m_NumberRecord(numberRecord)
-{
-}
-
-ContactNumberData::~ContactNumberData()
-{
- contacts_record_destroy(m_NumberRecord, true);
-}
-
-int ContactNumberData::getId() const
-{
- return m_ContactData.getId();
-}
-
-const char *ContactNumberData::getName() const
-{
- return m_ContactData.getName();
-}
-
-const char *ContactNumberData::getNumber() const
-{
- return getRecordStr(m_NumberRecord, _contacts_number.number);
-}
-
-const char *ContactNumberData::getImagePath() const
-{
- return m_ContactData.getImagePath();
-}
#define CONTACTS_LIST_MODEL_PERSON_H
#include "Contacts/Model/ContactData.h"
+#include "Common/Database/ChildRecordIterator.h"
#include "Utils/UniString.h"
#include <contacts.h>
namespace Contacts
{
- namespace Model
- {
- class ContactNumberData;
- }
-
namespace List
{
namespace Model
class Person : public Contacts::Model::ContactData
{
public:
- /**
- * @brief Number objects list
- */
- typedef std::vector<Contacts::Model::ContactNumberData *> Numbers;
+ typedef std::vector<Common::Database::ChildRecordRange> ContactChildRecords;
/**
* @brief Complete ContactData::Field with person object fields
int getContactId() const;
/**
+ * @return Nickname
+ */
+ const char *getNickname() const;
+
+ /**
+ * @return Note
+ */
+ const char *getNotes() const;
+
+ /**
+ * @return Organization record
+ */
+ contacts_record_h getOrganization() const;
+
+ /**
+ * @return Person address list
+ */
+ const ContactChildRecords getAddresses() const;
+
+ /**
+ * @return Person email list
+ */
+ const ContactChildRecords getEmails() const;
+
+ /**
* @return Person number list
*/
- const Numbers &getNumbers();
+ const ContactChildRecords getNumbers() const;
/**
* @return First letter from formatted person name
private:
friend class PersonProvider;
+ template <typename Pred>
+ contacts_record_h getContactChildRecord(unsigned propertyId, Pred predicate) const;
+ const ContactChildRecords getContactChildRecords(unsigned propertyId) const;
+
const Utils::UniString &getSortValue() const;
void update(contacts_record_h personRecord);
int updateName(contacts_record_h record, unsigned sortProperty);
Utils::UniString m_IndexLetter;
mutable Utils::UniString m_SortValue;
unsigned m_SortProperty;
- Numbers m_Numbers;
};
}
}
*/
#include "Contacts/List/Model/Person.h"
-#include "Contacts/Model/ContactNumberData.h"
#include "Common/Database/Queries.h"
#include "Common/Database/RecordUtils.h"
#include "Common/Database/RecordIterator.h"
return record;
}
- contacts_record_h getNumberRecord(contacts_record_h contactRecord)
+ contacts_record_h getDefaultNumberRecord(contacts_record_h contactRecord)
{
return getChildRecord(contactRecord, _contacts_contact.number,
[](contacts_record_h record) {
Person::~Person()
{
- for (auto &&number : m_Numbers) {
- delete number;
- }
for (auto &&contact : m_ContactRecords) {
contacts_record_destroy(contact, true);
}
const char *Person::getNumber() const
{
- return getRecordStr(getNumberRecord(m_DefaultContactRecord), _contacts_number.number);
+ return getRecordStr(getDefaultNumberRecord(m_DefaultContactRecord), _contacts_number.number);
}
const char *Person::getImagePath() const
return getRecordInt(m_Record, _contacts_person.display_contact_id);
}
-const Person::Numbers &Person::getNumbers()
+const char *Person::getNickname() const
{
- unsigned projection[] = {
- _contacts_contact.number
- };
-
- if (m_Numbers.empty()) {
- contacts_list_h list = getPersonContacts(getId(), projection);
- for (auto &&contact : makeRange(list)) {
- for (auto &&number : makeRange(contact, _contacts_contact.number)) {
- m_Numbers.push_back(new ContactNumberData(*this, number));
- }
- contacts_record_destroy(contact, false);
+ contacts_record_h record = getContactChildRecord(_contacts_contact.nickname,
+ [](contacts_record_h record) {
+ return getRecordStr(record, _contacts_nickname.name) != nullptr;
}
- contacts_list_destroy(list, false);
- }
+ );
+
+ return record ? getRecordStr(record, _contacts_nickname.name) : nullptr;
+}
+
+const char *Person::getNotes() const
+{
+ contacts_record_h record = getContactChildRecord(_contacts_contact.note,
+ [](contacts_record_h record) {
+ return getRecordStr(record, _contacts_note.note) != nullptr;
+ }
+ );
- return m_Numbers;
+ return record ? getRecordStr(record, _contacts_note.note) : nullptr;
+}
+
+contacts_record_h Person::getOrganization() const
+{
+ return getContactChildRecord(_contacts_contact.company,
+ [](contacts_record_h record) {
+ return getRecordStr(record, _contacts_company.name) != nullptr
+ || getRecordStr(record, _contacts_company.job_title) != nullptr;
+ }
+ );
+}
+
+const Person::ContactChildRecords Person::getAddresses() const
+{
+ return getContactChildRecords(_contacts_contact.address);
+}
+
+const Person::ContactChildRecords Person::getEmails() const
+{
+ return getContactChildRecords(_contacts_contact.email);
+}
+
+const Person::ContactChildRecords Person::getNumbers() const
+{
+ return getContactChildRecords(_contacts_contact.number);
}
const UniString &Person::getIndexLetter() const
return m_ContactRecords.size();
}
+template <typename Pred>
+contacts_record_h Person::getContactChildRecord(unsigned propertyId, Pred predicate) const
+{
+ contacts_record_h record = getChildRecord(m_DefaultContactRecord, propertyId);
+ if (record && predicate(record)) {
+ return record;
+ }
+
+ for (auto &&contact : m_ContactRecords) {
+ record = getChildRecord(contact, propertyId);
+ if (record && predicate(record)) {
+ return record;
+ }
+ }
+
+ return nullptr;
+}
+
+const Person::ContactChildRecords Person::getContactChildRecords(unsigned propertyId) const
+{
+ ContactChildRecords records;
+ for (auto &&contact : m_ContactRecords) {
+ records.push_back(makeRange(contact, propertyId));
+ }
+
+ return records;
+}
+
const UniString &Person::getSortValue() const
{
if (m_SortValue.getI18nStr().empty()) {
#include "Contacts/List/Model/PersonSearchData.h"
#include "Contacts/List/Model/Person.h"
-#include "Contacts/Model/ContactNumberData.h"
+#include "Common/Database/RecordUtils.h"
#include <cstring>
using namespace Contacts::Model;
using namespace Contacts::List::Model;
+using namespace Common::Database;
PersonSearchData::PersonSearchData(Person &person)
: SearchData(person)
SearchResultPtr PersonSearchData::compareNumber(const std::string &str)
{
auto &person = static_cast<Person &>(getContactData());
- for (auto &&number : person.getNumbers()) {
- const char *pos = strstr(number->getNumber(), str.c_str());
- if (pos) {
- return SearchResultPtr(new SearchResult(SearchResult::MatchedNumber, number->getNumber(), { pos, str.size() }));
+ for (auto &&numberRange : person.getNumbers()) {
+ for (auto &&numberRecord : numberRange) {
+ const char *number = getRecordStr(numberRecord, _contacts_number.number);
+ const char *pos = strstr(number, str.c_str());
+
+ if (pos) {
+ return SearchResultPtr(new SearchResult(SearchResult::MatchedNumber, number, { pos, str.size() }));
+ }
+
}
}