friend class ContactManager;
public:
+ ContactList(contacts_list_h list)
+ : m_List(list)
+ , m_Record(false)
+ {
+ }
+
+ ~ContactList()
+ {
+ if(m_List)
+ contacts_list_destroy(m_List, true);
+ }
bool next()
{
return contacts_list_prev(m_List) == 0;
}
- T get()
+ T &get()
{
contacts_record_h rec = nullptr;
contacts_list_get_current_record_p(m_List, &rec);
- return T(rec);
+ m_Record.set(rec);
+ return m_Record;
}
int getCount() const
return count;
}
- void release(bool releaseChildren = true)
- {
- if(m_List)
- {
- contacts_list_destroy(m_List, releaseChildren);
- m_List = nullptr;
- }
- }
-
- bool isValid()
- {
- return m_List != nullptr;
- }
-
- private:
- ContactList()
- : m_List()
- {
- }
-
- ContactList(contacts_list_h list)
- : m_List(list)
- {
- }
-
private:
contacts_list_h m_List;
+ T m_Record;
};
}
#include <list>
#include <vector>
#include <contacts.h>
+#include <memory>
#include "ContactList.h"
#include "ContactPersonPhoneLog.h"
* @param keyword - search keyword
*/
template<typename T>
- ContactList<T> search(const std::string &keyword);
+ std::shared_ptr<ContactList<T>> search(const std::string &keyword);
/**
*@brief search for contacts-id, name, phone-number and thumbnail path based on phone-number
*@param[in] number - contact person number
*@return ContactPersonNumber
*/
- ContactPersonNumber getContactPersonNumber(const std::string &number) const;
+ ContactPersonNumberRef getContactPersonNumber(const std::string &number) const;
/**
*@brief Search for contacts-id, name, phone-number and thumbnail path based on phone-number id
*@param[in] phoneId - identifier of phone-number in contacts-database
*@return ContactPersonNumber
*/
- ContactPersonNumber getContactPersonNumber(int phoneId) const;
+ ContactPersonNumberRef getContactPersonNumber(int phoneId) const;
/**
*@brief Add listener on contacts database
* @brief Generic search for basic contact attributes based on custom filter passed from above
* @param[in] filter to be used for db-request. DO NOT destroy filter manually, it will be destroyed insithe this method.
*/
- ContactPersonNumber getContactPersonNumber(contacts_filter_h filter) const;
+ ContactPersonNumberRef getContactPersonNumber(contacts_filter_h filter) const;
private:
std::list<IContactDbChangeListener *> m_Listeners;
--- /dev/null
+/*
+ * Copyright (c) 2009-2015 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 __ContactPersonAddress_h__
+#define __ContactPersonAddress_h__
+
+#include "ContactRecord.h"
+
+namespace Msg
+{
+ class ContactPersonAddress;
+ typedef std::shared_ptr<ContactPersonAddress> ContactPersonAddressRef;
+
+ class ContactPersonAddress
+ : public ContactRecord
+ {
+ public:
+ enum AddressType
+ {
+ EmailType,
+ NumberType,
+ };
+
+ public:
+ ContactPersonAddress(bool release, contacts_record_h record = nullptr);
+
+ virtual AddressType getAddressType() const = 0;
+ virtual int getPersonId() const = 0;
+ virtual std::string getDispName() const = 0;
+ virtual std::string getAddress() const = 0;
+ virtual std::string getThumbnailPath() const = 0;
+ };
+
+ inline ContactPersonAddress::ContactPersonAddress(bool release, contacts_record_h record)
+ : ContactRecord(release, record)
+ {
+ }
+}
+
+#endif /* __ContactPersonAddress_h__ */
#ifndef __ContactPersonEmail_h__
#define __ContactPersonEmail_h__
-#include <ContactRecord.h>
+#include "ContactPersonAddress.h"
namespace Msg
{
+ class ContactPersonEmail;
+ typedef std::shared_ptr<ContactPersonEmail> ContactPersonEmailRef;
+
class ContactPersonEmail
- : public ContactRecord
+ : public ContactPersonAddress
{
public:
- ContactPersonEmail(contacts_record_h record);
+ ContactPersonEmail(bool release, contacts_record_h record = nullptr);
static const char *getUri();
- int getId() const;
- int getPersonId() const;
- std::string getDispName() const;
- std::string getEmail() const;
- std::string getThumbnailPath() const;
+ virtual int getId() const;
+ virtual AddressType getAddressType() const;
+ virtual int getPersonId() const;
+ virtual std::string getDispName() const;
+ virtual std::string getAddress() const;
+ virtual std::string getThumbnailPath() const;
};
- inline ContactPersonEmail::ContactPersonEmail(contacts_record_h record)
- : ContactRecord(record)
+ inline ContactPersonEmail::ContactPersonEmail(bool release, contacts_record_h record)
+ : ContactPersonAddress(release, record)
{
}
return getStr(_contacts_person_email.display_name);
}
- inline std::string ContactPersonEmail::getEmail() const
+ inline std::string ContactPersonEmail::getAddress() const
{
return getStr(_contacts_person_email.email);
}
{
return _contacts_person_email._uri;
}
+
+ inline ContactPersonEmail::AddressType ContactPersonEmail::getAddressType() const
+ {
+ return EmailType;
+ }
}
#ifndef __ContactPersonNumber_h__
#define __ContactPersonNumber_h__
-#include <ContactRecord.h>
+#include "ContactPersonAddress.h"
namespace Msg
{
- class ContactManager;
+ class ContactPersonNumber;
+ typedef std::shared_ptr<ContactPersonNumber> ContactPersonNumberRef;
class ContactPersonNumber
- : public ContactRecord
+ : public ContactPersonAddress
{
public:
- ContactPersonNumber(contacts_record_h record);
+ ContactPersonNumber(bool release, contacts_record_h record = nullptr);
static const char *getUri();
- int getId() const;
- int getPersonId() const;
- std::string getDispName() const;
- std::string getNumber() const;
- std::string getThumbnailPath() const;
+ virtual int getId() const;
+ virtual AddressType getAddressType() const;
+ virtual int getPersonId() const;
+ virtual std::string getDispName() const;
+ virtual std::string getAddress() const;
+ virtual std::string getThumbnailPath() const;
};
- inline ContactPersonNumber::ContactPersonNumber(contacts_record_h record)
- : ContactRecord(record)
+ inline ContactPersonNumber::ContactPersonNumber(bool release, contacts_record_h record)
+ : ContactPersonAddress(release, record)
{
}
return getStr(_contacts_person_number.display_name);
}
- inline std::string ContactPersonNumber::getNumber() const
+ inline std::string ContactPersonNumber::getAddress() const
{
return getStr(_contacts_person_number.number);
}
{
return _contacts_person_number._uri;
}
+
+ inline ContactPersonNumber::AddressType ContactPersonNumber::getAddressType() const
+ {
+ return NumberType;
+ }
}
#ifndef __ContactPersonPhoneLog_h__
#define __ContactPersonPhoneLog_h__
-#include <ContactRecord.h>
+#include "ContactRecord.h"
namespace Msg
{
- class ContactManager;
+ class ContactPersonPhoneLog;
+ typedef std::shared_ptr<ContactPersonPhoneLog> ContactPersonPhoneLogRef;
class ContactPersonPhoneLog
: public ContactRecord
{
public:
- ContactPersonPhoneLog(contacts_record_h record);
+ ContactPersonPhoneLog(bool release, contacts_record_h record = nullptr);
static const char *getUri();
- int getId() const;
+ virtual int getId() const;
int getPersonId() const;
- std::string getDispName() const;
std::string getAddress() const;
+ std::string getDispName() const;
};
- inline ContactPersonPhoneLog::ContactPersonPhoneLog(contacts_record_h record)
- : ContactRecord(record)
+ inline ContactPersonPhoneLog::ContactPersonPhoneLog(bool release, contacts_record_h record)
+ : ContactRecord(release, record)
{
}
#define __ContactRecord_h__
#include <contacts.h>
-#include <vector>
#include <string>
+#include <memory>
namespace Msg
{
+ class ContactRecord;
+ typedef std::shared_ptr<ContactRecord> ContactRecordRef;
+
class ContactRecord
{
public:
- inline void release(bool releaseChildren = true);
- inline bool isValid() const;
+ ContactRecord(bool release, contacts_record_h record = nullptr);
+ virtual ~ContactRecord();
+ ContactRecord(ContactRecord&) = delete;
+ ContactRecord& operator=(ContactRecord&) = delete;
+
+ virtual int getId() const = 0;
+ void set(contacts_record_h record);
protected:
- ContactRecord(contacts_record_h record);
- virtual ~ContactRecord();
std::string getStr(unsigned propertyId) const;
int getInt(unsigned propertyId) const;
- protected:
+ private:
contacts_record_h m_Record;
+ bool m_Release;
};
- inline bool ContactRecord::isValid() const
+ inline void ContactRecord::set(contacts_record_h record)
{
- return m_Record != nullptr;
- }
-
- inline void ContactRecord::release(bool releaseChildren)
- {
- if(m_Record)
- {
- contacts_record_destroy(m_Record, releaseChildren);
- m_Record = nullptr;
- }
+ m_Record = record;
}
inline std::string ContactRecord::getStr(unsigned propertyId) const
contacts_record_get_int(m_Record, propertyId, &val);
return val;
}
+
}
#endif /* __ContactRecord_h__ */
template <>
- ContactList<ContactPersonPhoneLog> ContactManager::search<ContactPersonPhoneLog>(const std::string &keyword)
+ std::shared_ptr<ContactList<ContactPersonPhoneLog>> ContactManager::search<ContactPersonPhoneLog>(const std::string &keyword)
{
contacts_query_h query = nullptr;
contacts_filter_h filter = nullptr;
{
_contacts_person_phone_log.person_id,
_contacts_person_phone_log.address,
+ _contacts_person_phone_log.display_name
};
contacts_query_set_projection(query, numberProjection, sizeof(numberProjection)/sizeof(unsigned int));
contacts_filter_destroy(filter);
contacts_query_destroy(query);
- return ContactList<ContactPersonPhoneLog>(list);
+ return list ? std::make_shared<ContactList<ContactPersonPhoneLog>>(list) : nullptr;
}
template<>
- ContactList<ContactPersonNumber> ContactManager::search<ContactPersonNumber>(const std::string &keyword)
+ std::shared_ptr<ContactList<ContactPersonNumber>> ContactManager::search<ContactPersonNumber>(const std::string &keyword)
{
contacts_list_h list = nullptr;
contacts_db_search_records_with_range(ContactPersonNumber::getUri(), keyword.c_str(),
0, 0, CONTACTS_SEARCH_RANGE_NAME | CONTACTS_SEARCH_RANGE_NUMBER, &list);
- ContactList<ContactPersonNumber> resultList(list);
- return resultList;
+ return list ? std::make_shared<ContactList<ContactPersonNumber>>(list) : nullptr;
}
template<>
- ContactList<ContactPersonEmail> ContactManager::search<ContactPersonEmail>(const std::string &keyword)
+ std::shared_ptr<ContactList<ContactPersonEmail>> ContactManager::search<ContactPersonEmail>(const std::string &keyword)
{
contacts_list_h list = nullptr;
contacts_db_search_records_with_range(ContactPersonEmail::getUri(), keyword.c_str(),
0, 0, CONTACTS_SEARCH_RANGE_NAME | CONTACTS_SEARCH_RANGE_EMAIL, &list);
- ContactList<ContactPersonEmail> resultList(list);
- return resultList;
+ return list ? std::make_shared<ContactList<ContactPersonEmail>>(list) : nullptr;
}
- ContactPersonNumber ContactManager::getContactPersonNumber(int phoneNumId) const
+ ContactPersonNumberRef ContactManager::getContactPersonNumber(int phoneNumId) const
{
contacts_filter_h filter = nullptr;
contacts_filter_create(_contacts_contact_number._uri, &filter);
contacts_filter_add_int(filter, _contacts_person_number.number_id, CONTACTS_MATCH_EQUAL, phoneNumId);
- return getContactPersonNumber(filter);
+ return filter ? getContactPersonNumber(filter) : nullptr;
}
- ContactPersonNumber ContactManager::getContactPersonNumber(const std::string &number) const
+ ContactPersonNumberRef ContactManager::getContactPersonNumber(const std::string &number) const
{
contacts_filter_h filter = nullptr;
contacts_filter_create(_contacts_contact_number._uri, &filter);
contacts_filter_add_str(filter, _contacts_person_number.number_filter, CONTACTS_MATCH_EXACTLY, number.c_str());
- return getContactPersonNumber(filter);
+ return filter ? getContactPersonNumber(filter) : nullptr;
}
void ContactManager::contactChangedCb(const char *view_uri, void *user_data)
}
}
- ContactPersonNumber ContactManager::getContactPersonNumber(contacts_filter_h filter) const
+ ContactPersonNumberRef ContactManager::getContactPersonNumber(contacts_filter_h filter) const
{
contacts_query_h query = nullptr;
contacts_list_h list = nullptr;
}
contacts_list_destroy(list, false);
- return ContactPersonNumber(cResValue);
+ return cResValue ? std::make_shared<ContactPersonNumber>(true, cResValue) : nullptr;
}
}
using namespace Msg;
-ContactRecord::ContactRecord(contacts_record_h record)
+ContactRecord::ContactRecord(bool release, contacts_record_h record)
: m_Record(record)
+ , m_Release(release)
{
}
ContactRecord::~ContactRecord()
{
-
+ if(m_Record && m_Release)
+ {
+ contacts_record_destroy(m_Record, true);
+ m_Record = nullptr;
+ }
}
-
#include "ContactListViewItem.h"
#include "ContactPersonPhoneLog.h"
-#include "ContactPersonNumber.h"
-#include "ContactPersonEmail.h"
+#include "ContactPersonAddress.h"
namespace Msg
{
{
public:
ContactListItem(const ContactPersonPhoneLog &rec, const std::string &searchWord);
- ContactListItem(const ContactPersonNumber &rec, const std::string &searchWord);
- ContactListItem(const ContactPersonEmail &rec, const std::string &searchWord);
+ ContactListItem(const ContactPersonAddress &rec, const std::string &searchWord);
virtual ~ContactListItem();
const std::string &getRecipient() const;
m_MainText = TextDecorator::highlightKeyword(rec.getAddress(), searchWord);
}
-ContactListItem::ContactListItem(const ContactPersonNumber &rec, const std::string &searchWord)
+ContactListItem::ContactListItem(const ContactPersonAddress &rec, const std::string &searchWord)
{
setStyle(ContactListViewItem::nameOrEmailStyle);
m_MainText = TextDecorator::highlightKeyword(rec.getDispName(), searchWord);
- m_SubText = TextDecorator::highlightKeyword(rec.getNumber(), searchWord);
- m_Recipient = rec.getNumber();
- m_ImagePath = rec.getThumbnailPath();
-}
-
-ContactListItem::ContactListItem(const ContactPersonEmail &rec, const std::string &searchWord)
-{
- setStyle(ContactListViewItem::nameOrEmailStyle);
-
- m_MainText = TextDecorator::highlightKeyword(rec.getDispName(), searchWord);
- m_SubText = TextDecorator::highlightKeyword(rec.getEmail(), searchWord);
- m_Recipient = rec.getEmail();
+ m_SubText = TextDecorator::highlightKeyword(rec.getAddress(), searchWord);
+ m_Recipient = rec.getAddress();
m_ImagePath = rec.getThumbnailPath();
}
namespace
{
- inline bool isValid(const ContactPersonNumber &rec)
+ inline bool isValid(const ContactPersonAddress &rec)
{
- return !rec.getNumber().empty();
- }
-
- inline bool isValid(const ContactPersonEmail &rec)
- {
- return !rec.getEmail().empty();
+ return !rec.getAddress().empty();
}
inline bool isValid(const ContactPersonPhoneLog &rec)
void ConvContactList::search()
{
auto list = m_ContactManager.search<ContactRecord>(m_SearchWord);
- if(list.isValid())
+ if(list)
{
do
{
- auto rec = list.get();
+ auto &rec = list->get();
if(isValid(rec))
{
ContactListItem *item = new ContactListItem(rec, m_SearchWord);
{
MSG_LOG("Skip invalid contact");
}
- } while(list.next());
- list.release();
+ } while(list->next());
}
}
MSG_LOG("");
// TODO: impl for email
m_SelectedAddress = address;
- ContactPersonNumber contactPersonNumber = getApp().getContactManager().getContactPersonNumber(address);
- if(contactPersonNumber.isValid())
- ContactViewer::launch(contactPersonNumber.getPersonId());
+ ContactPersonNumberRef contactPersonNumber = getApp().getContactManager().getContactPersonNumber(address);
+ if(contactPersonNumber)
+ ContactViewer::launch(contactPersonNumber->getPersonId());
else
showRecipPopup(address);
}
{
std::string conversationName;
std::string firstNumber = addressList->at(0).getAddress();
- ContactPersonNumber contactPersonNumber = getApp().getContactManager().getContactPersonNumber(firstNumber);
- if(contactPersonNumber.isValid())
- {
- conversationName = contactPersonNumber.getDispName();
- contactPersonNumber.release();
- }
+ ContactPersonNumberRef contactPersonNumber = getApp().getContactManager().getContactPersonNumber(firstNumber);
+ if(contactPersonNumber)
+ conversationName = contactPersonNumber->getDispName();
if(conversationName.empty())
conversationName = firstNumber;
RecipientsPanel::AppendItemStatus RecipientsPanel::appendItem(const std::string &address, MsgAddress::AddressType addressType)
{
- ContactPersonNumber num = m_App.getContactManager().getContactPersonNumber(address);
-
std::string dispName;
- if(num.isValid())
- dispName = num.getDispName();
-
- num.release();
+ ContactPersonNumberRef num = m_App.getContactManager().getContactPersonNumber(address);
+ if(num)
+ dispName = num->getDispName();
if(dispName.empty())
dispName = address;
bool duplicateFound = false;
for(auto phoneNumId : numberIdList)
{
- ContactPersonNumber num = m_App.getContactManager().getContactPersonNumber(phoneNumId);
- if(num.isValid())
- {
- duplicateFound |= appendItem(num.getNumber(), num.getDispName(), MsgAddress::Phone) == DuplicatedStatus;
- num.release();
- }
+ ContactPersonNumberRef num = m_App.getContactManager().getContactPersonNumber(phoneNumId);
+ if(num)
+ duplicateFound |= appendItem(num->getAddress(), num->getDispName(), MsgAddress::Phone) == DuplicatedStatus;
}
if(duplicateFound)
void BaseThreadListItem::updateThumbnail(const MsgAddress &addr)
{
- ContactPersonNumber contactNumber = m_App.getContactManager().getContactPersonNumber(addr.getAddress());
- m_ThumbPath = contactNumber.getThumbnailPath();
+ ContactPersonNumberRef contactNumber = m_App.getContactManager().getContactPersonNumber(addr.getAddress());
+
+ if(contactNumber)
+ m_ThumbPath = contactNumber->getThumbnailPath();
if(m_ThumbPath.empty())
m_ThumbPath = PathUtils::getResourcePath(THUMB_CONTACT_IMG_PATH);
else
m_ThumbType = ThumbnailMaker::UserType;
-
- contactNumber.release();
}
void BaseThreadListItem::updateTime(time_t time)