--- /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 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);
+
+ /**
+ * @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 */
#define CONTACTS_MODEL_CONTACT_RECORD_DATA_H
#include "Contacts/Model/ContactData.h"
+#include "Contacts/Model/ContactNumberData.h"
#include "Contacts/Model/DbChangeObserver.h"
#include <contacts.h>
#include <vector>
class EXPORT_API ContactRecordData : public ContactData
{
public:
+ /**
+ * @brief Number objects list
+ */
+ typedef std::vector<ContactNumberData *> Numbers;
+
/**
* @brief Create ContactRecordData object
* @param[in] type ContactRecordData type
*/
virtual const char *getImagePath() const override;
+ /**
+ * @return Contact number list
+ */
+ virtual const Numbers &getNumbers();
+
/**
* @return contact record
*/
*/
void clearChangedHandles();
+ /**
+ * @brief Fill contact numbers from DB
+ * @param[in] record _contacts_contact record
+ */
+ void fillContactNumbers(contacts_record_h record);
+
+ /**
+ * @return Contact numbers
+ */
+ const Numbers &getContactNumbers() const;
+
+ /**
+ * @param[in] newContact New contact record
+ * @return Changes between current and new contacts
+ */
+ int getChanges(contacts_record_h newContact);
+
/**
* @param[in] record Contact record
* @return Contact ID
*/
static const char *getValue(contacts_record_h record, Field field);
- /**
- * @param[in] newContact New contact record
- * @return Changes between current and new contacts
- */
- int getChanges(contacts_record_h newContact);
-
private:
friend class ContactRecordProvider;
virtual void onUpdate(contacts_record_h record);
contacts_record_h m_Record;
+ Numbers m_Numbers;
std::vector<DbChangeObserver::CallbackHandle> m_Handles;
};
}
--- /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 "Contacts/Utils.h"
+
+using namespace Contacts::Model;
+using namespace Utils;
+
+ContactNumberData::ContactNumberData(ContactData &contact, contacts_record_h numberRecord)
+ : ContactData(TypeContactNumber),
+ m_ContactData(contact), m_NumberRecord(numberRecord)
+{
+}
+
+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();
+}
return getValue(m_Record, FieldImage);
}
+const ContactRecordData::Numbers &ContactRecordData::getNumbers()
+{
+ if (m_Numbers.empty()) {
+ fillContactNumbers(m_Record);
+ }
+
+ return m_Numbers;
+}
+
const contacts_record_h ContactRecordData::getContactRecord() const
{
return m_Record;
m_Handles.clear();
}
+void ContactRecordData::fillContactNumbers(contacts_record_h record)
+{
+ auto numberRecords = makeRange(record, _contacts_contact.number);
+ for (auto &&numberRecord : numberRecords) {
+ auto number = new ContactNumberData(*this, numberRecord);
+ m_Numbers.push_back(number);
+ }
+}
+
+const ContactRecordData::Numbers &ContactRecordData::getContactNumbers() const
+{
+ return m_Numbers;
+}
+
+int ContactRecordData::getChanges(contacts_record_h newContact)
+{
+ int changes = ChangedNone;
+
+ for (int i = FieldName; i < FieldMax; ++i) {
+ auto fieldId = static_cast<Field>(i);
+ const char *oldValue = getValue(m_Record, fieldId);
+ const char *newValue = getValue(newContact, fieldId);
+
+ if (!Utils::safeCmp(oldValue, newValue)) {
+ changes |= (1 << fieldId);
+ }
+ }
+
+ return changes;
+}
+
int ContactRecordData::getContactId(contacts_record_h record)
{
int value = 0;
return value;
}
-int ContactRecordData::getChanges(contacts_record_h newContact)
-{
- int changes = ChangedNone;
-
- for (int i = FieldName; i < FieldMax; ++i) {
- auto fieldId = static_cast<Field>(i);
- const char *oldValue = getValue(m_Record, fieldId);
- const char *newValue = getValue(newContact, fieldId);
-
- if (!Utils::safeCmp(oldValue, newValue)) {
- changes |= (1 << fieldId);
- }
- }
-
- return changes;
-}
-
void ContactRecordData::onUpdate(contacts_record_h record)
{
int changes = getChanges(record);
+
+ m_Numbers.clear();//Todo: Here should be ContactNumberData update/delete
+ fillContactNumbers(m_Record);
updateRecord(record);
onUpdated(changes);
virtual int getId() const override;
/**
- * @see Update record from the database
+ * @brief Update record from the database
*/
void updateDbRecord();
+ /**
+ * @see ContactRecordData::getNumbers()
+ */
+ virtual const Numbers &getNumbers() override;
+
/**
* @return Displayed by default contact ID
*/
*/
#include "Contacts/List/Model/Person.h"
+#include "Contacts/RecordListIterator.h"
#include "Contacts/Utils.h"
#include "Utils/String.h"
#include <cstring>
+using namespace Contacts;
using namespace Contacts::Model;
using namespace Contacts::List::Model;
using namespace Utils;
onUpdate(record);
}
+const Person::Numbers &Person::getNumbers()
+{
+ unsigned projection[] = {
+ _contacts_contact.number
+ };
+
+ if (getContactNumbers().empty()) {
+ contacts_list_h list = getContacts(m_PersonRecord, projection);
+ auto contacts = makeRange(list);
+ for (auto &&contact : contacts) {
+ fillContactNumbers(contact);
+ }
+
+ contacts_list_destroy(list, false);
+ }
+
+ return getContactNumbers();
+}
+
int Person::getDisplayContactId() const
{
int id = 0;