Skip to content
Snippets Groups Projects
Commit bc5b6a62 authored by Stepan Salenikovich's avatar Stepan Salenikovich Committed by Nicolas Jager
Browse files

change getLastIdUsed to lastUsedContactMethod


Changes the function to return the pointer to the last used
ContactMethod. This is more generic than returning the id, since
the caller can then decide what info they need themselves.

Drops the "get" from the function name to follow LRC/Qt
convention: getters don't begin with "get".

Makes this getter public as its useful for other purposes as well.

Change-Id: I8eb57c8d830e84e76365311870aaaf10dc5739a6
Reviewed-by: default avatarNicolas Jäger <nicolas.jager@savoirfairelinux.com>
parent 827437d5
Branches
No related tags found
No related merge requests found
......@@ -193,19 +193,6 @@ void PersonPrivate::registerContactMethod(ContactMethod* m)
slotLastUsedTimeChanged(m->lastUsed());
}
/**
* @return the best Id for the last ContactMethod used with that person.
*/
QString
PersonPrivate::getLastIdUsed()
{
auto lastPhoneNumberUsed = std::max_element(m_Numbers.begin(), m_Numbers.end(), [](ContactMethod* a, ContactMethod* b){
return (a->lastUsed() < b->lastUsed());
});
return (*lastPhoneNumberUsed) ? (*lastPhoneNumberUsed)->bestId() : QString();
}
PersonPrivate::PersonPrivate(Person* contact) : QObject(nullptr),
m_Numbers(),m_DisplayPhoto(false),m_Active(true),m_isPlaceHolder(false),
m_LastUsed(0),m_LastUsedInit(false), q_ptr(contact)
......@@ -366,6 +353,15 @@ const QString& Person::department() const
return d_ptr->m_Department;
}
/// Get the last ContactMethod used with that person.
ContactMethod* Person::lastUsedContactMethod() const
{
auto lastUsed = std::max_element(phoneNumbers().begin(), phoneNumbers().end(),
[] (ContactMethod* a, ContactMethod* b) { return (a->lastUsed() < b->lastUsed()); }
);
return *lastUsed;
}
///Set the phone number (type and number)
void Person::setContactMethods(ContactMethods numbers)
{
......@@ -629,7 +625,10 @@ QVariant Person::roleData(int role) const
case static_cast<int>(Ring::Role::IsPresent):
return isPresent();
case static_cast<int>(Person::Role::IdOfLastCMUsed):
return d_ptr->getLastIdUsed();
{
auto cm = lastUsedContactMethod();
return cm ? cm->bestId() : QString();
}
case static_cast<int>(Ring::Role::UnreadTextMessageCount):
{
int unread = 0;
......
......@@ -142,6 +142,7 @@ public:
const QString& group () const;
const QString& department () const;
time_t lastUsedTime () const;
ContactMethod* lastUsedContactMethod() const;
Q_INVOKABLE QVariant roleData (int role) const;
Q_INVOKABLE QMimeData* mimePayload( ) const;
......
......@@ -81,7 +81,6 @@ public:
//Helper
void registerContactMethod(ContactMethod* m);
QString getLastIdUsed();
public Q_SLOTS:
void slotLastUsedTimeChanged(::time_t t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment