From bc5b6a62d680fe3b49c646fd12ae2896bf11bacd Mon Sep 17 00:00:00 2001 From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> Date: Thu, 11 May 2017 16:46:46 -0400 Subject: [PATCH] change getLastIdUsed to lastUsedContactMethod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> --- src/person.cpp | 27 +++++++++++++-------------- src/person.h | 1 + src/private/person_p.h | 1 - 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/person.cpp b/src/person.cpp index f2dee319..c127629c 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -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; diff --git a/src/person.h b/src/person.h index 78b72daa..a96b1570 100644 --- a/src/person.h +++ b/src/person.h @@ -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; diff --git a/src/private/person_p.h b/src/private/person_p.h index eebc63cf..9ed62aaf 100644 --- a/src/private/person_p.h +++ b/src/private/person_p.h @@ -81,7 +81,6 @@ public: //Helper void registerContactMethod(ContactMethod* m); - QString getLastIdUsed(); public Q_SLOTS: void slotLastUsedTimeChanged(::time_t t); -- GitLab