#define CONTACTS_UTILS_H
#include <contacts.h>
+#include "Utils/String.h"
#define CONTACTS_LIST_FOREACH(list, record) \
bool success = (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_NONE); \
namespace Contacts
{
/**
+ * @brief Convenience wrapper.
+ * @see contacts_record_get_str_p()
+ */
+ inline const char *getRecordStr(contacts_record_h record, unsigned propertyId)
+ {
+ char *str = nullptr;
+ contacts_record_get_str_p(record, propertyId, &str);
+ return str;
+ }
+
+ /**
+ * @brief Convenience wrapper.
+ * @see contacts_record_get_int()
+ */
+ inline int getRecordInt(contacts_record_h record, unsigned propertyId)
+ {
+ int value = 0;
+ contacts_record_get_int(record, propertyId, &value);
+ return value;
+ }
+
+ /**
+ * @brief Convenience wrapper.
+ * @see contacts_record_get_bool()
+ */
+ inline bool getRecordBool(contacts_record_h record, unsigned propertyId)
+ {
+ bool value = 0;
+ contacts_record_get_bool(record, propertyId, &value);
+ return value;
+ }
+
+ /**
+ * @brief Compare two records by the same string property.
+ * @param[in] record1 First record
+ * @param[in] records Second record
+ * @param[in] propertyId Property to compare by
+ * @return Whether properties are equal.
+ */
+ inline bool compareRecordsStr(contacts_record_h record1, contacts_record_h record2,
+ unsigned propertyId)
+ {
+ return Utils::safeCmp(getRecordStr(record1, propertyId), getRecordStr(record2, propertyId));
+ }
+
+ /**
+ * @brief Compare two records by the same integer property.
+ * @see compareRecordsStr()
+ */
+ inline bool compareRecordsInt(contacts_record_h record1, contacts_record_h record2,
+ unsigned propertyId)
+ {
+ return getRecordInt(record1, propertyId) == getRecordInt(record2, propertyId);
+ }
+
+ /**
* @brief Get display contact record for a person.
* @param[in] personRecord _contacts_person record
* @return Display contact's _contacts_contact record.
protected:
/**
- * @brief Get field value from the given record.
- */
- bool getValue(contacts_record_h record) const;
-
- /**
* @see ContactField::onInitialize()
*/
virtual void onInitialize(contacts_record_h record) override;
protected:
/**
- * @brief Get field value from the given record.
- */
- int getValue(contacts_record_h record) const;
-
- /**
* @brief Enum type metadata.
*/
const ContactEnumMetadata &getEnumMetadata() const;
protected:
/**
- * @brief Get field value from the given record.
- */
- const char *getValue(contacts_record_h record) const;
-
- /**
* @see ContactField::onInitialize()
*/
virtual void onInitialize(contacts_record_h record) override;
*/
#include "Contacts/List/Model/MyProfile.h"
+#include "Contacts/Utils.h"
using namespace Contacts::List::Model;
{
contacts_list_h list = nullptr;
contacts_db_get_all_records(_contacts_my_profile._uri, 0, 1, &list);
-
contacts_list_get_current_record_p(list, &m_MyProfileRecord);
-
contacts_list_destroy(list, false);
}
const int MyProfile::getId() const
{
- int id = 0;
- contacts_record_get_int(m_MyProfileRecord, _contacts_my_profile.id, &id);
- return id;
+ return getRecordInt(m_MyProfileRecord, _contacts_my_profile.id);
}
const char *MyProfile::getName() const
{
- char *name = nullptr;
- contacts_record_get_str_p(m_MyProfileRecord, _contacts_my_profile.display_name, &name);
- return name;
+ return getRecordStr(m_MyProfileRecord, _contacts_my_profile.display_name);
}
const char *MyProfile::getImagePath() const
{
- char *path = nullptr;
- contacts_record_get_str_p(m_MyProfileRecord, _contacts_my_profile.image_thumbnail_path, &path);
- return path;
+ return getRecordStr(m_MyProfileRecord, _contacts_my_profile.image_thumbnail_path);
}
const contacts_record_h MyProfile::getRecord() const
{
return m_MyProfileRecord;
}
-
*/
#include "Contacts/Model/ContactBoolField.h"
+#include "Contacts/Utils.h"
using namespace Contacts::Model;
bool ContactBoolField::getValue() const
{
- return getValue(getRecord());
+ return getRecordBool(getRecord(), getPropertyId());
}
void ContactBoolField::setValue(bool value)
contacts_record_set_bool(getRecord(), getPropertyId(), value);
}
-bool ContactBoolField::getValue(contacts_record_h record) const
-{
- bool value = false;
- contacts_record_get_bool(record, getPropertyId(), &value);
- return value;
-}
-
void ContactBoolField::onInitialize(contacts_record_h record)
{
- m_InitialValue = getValue(record);
+ m_InitialValue = getRecordBool(record, getPropertyId());
}
#include "Contacts/Model/ContactEnumField.h"
#include "Contacts/Model/ContactFieldMetadata.h"
+#include "Contacts/Utils.h"
using namespace Contacts::Model;
int ContactEnumField::getValue() const
{
- return getValue(getRecord());
+ return getRecordInt(getRecord(), getPropertyId());
}
void ContactEnumField::setValue(int value)
return getValue() == getEnumMetadata().customValue;
}
-int ContactEnumField::getValue(contacts_record_h record) const
-{
- int value = 0;
- contacts_record_get_int(record, getPropertyId(), &value);
- return value;
-}
-
const ContactEnumMetadata &ContactEnumField::getEnumMetadata() const
{
return *(const ContactEnumMetadata *) ContactField::getMetadata().typeMetadata;
void ContactEnumField::onInitialize(contacts_record_h record)
{
- m_InitialValue = getValue(record);
+ m_InitialValue = getRecordInt(record, getPropertyId());
}
#include "Contacts/Model/ContactTextField.h"
#include "Contacts/Model/ContactFieldMetadata.h"
+#include "Contacts/Utils.h"
using namespace Contacts::Model;
const char *ContactTextField::getValue() const
{
- return getValue(getRecord());
+ return getRecordStr(getRecord(), getPropertyId());
}
void ContactTextField::setValue(const char *value)
}
}
-const char *ContactTextField::getValue(contacts_record_h record) const
-{
- char *value = nullptr;
- contacts_record_get_str_p(record, getPropertyId(), &value);
- return value;
-}
-
void ContactTextField::onInitialize(contacts_record_h record)
{
- const char *value = getValue(record);
+ const char *value = getRecordStr(record, getPropertyId());
if (value) {
m_InitialValue = value;
}
#include "Logs/Model/Log.h"
#include "Logs/Model/LogGroup.h"
+#include "Contacts/Utils.h"
#include "Utils/Logger.h"
using namespace Logs::Model;
const char *Log::getNumber() const
{
- char *number = nullptr;
- contacts_record_get_str_p(m_LogRecord, _contacts_phone_log.address, &number);
- return number;
+ return Contacts::getRecordStr(m_LogRecord, _contacts_phone_log.address);
}
const char *Log::getImagePath() const
int Log::getType() const
{
- int type = CONTACTS_PLOG_TYPE_NONE;
- contacts_record_get_int(m_LogRecord, _contacts_phone_log.log_type, &type);
-
- return type;
+ return Contacts::getRecordInt(m_LogRecord, _contacts_phone_log.log_type);
}
tm Log::getTime() const
{
- int time = 0;
- contacts_record_get_int(m_LogRecord, _contacts_phone_log.log_time, &time);
-
- time_t logTime = time;
- return *localtime(&logTime);
+ time_t time = 0;
+ contacts_record_get_int(m_LogRecord, _contacts_phone_log.log_time, (int *) &time);
+ return *localtime(&time);
}
int Log::getId() const
{
- int id = 0;
- contacts_record_get_int(m_LogRecord, _contacts_phone_log.id, &id);
- return id;
+ return Contacts::getRecordInt(m_LogRecord, _contacts_phone_log.id);
}
int Log::getPersonId() const
{
- int id = 0;
- contacts_record_get_int(m_LogRecord, _contacts_phone_log.person_id, &id);
- return id;
+ return Contacts::getRecordInt(m_LogRecord, _contacts_phone_log.person_id);
}
int Log::getContactId() const
time_t Log::getDuration() const
{
- time_t duration = 0;
- contacts_record_get_int(m_LogRecord, _contacts_phone_log.extra_data1, (int *)&duration);
- return duration;
+ return (time_t) Contacts::getRecordInt(m_LogRecord, _contacts_phone_log.extra_data1);
}
contacts_record_h Log::getContactRecord()