Skip to content
Snippets Groups Projects
Commit 3ce9123a authored by Emmanuel Lepage Vallée's avatar Emmanuel Lepage Vallée Committed by Stepan Salenikovich
Browse files

phonedirectory: Add `getExistingNumberIf()`


This method was added to `AccountModel` a few days ago. This adds it
to PhoneDirectoryModel too. Assuming this is the direction the
maintainer wish to go with these functional patterns.

Change-Id: Icd1998d2fe52d6675aa6a219b5db159811600af0
Reviewed-by: default avatarStepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
parent 1771e1aa
No related branches found
No related tags found
No related merge requests found
...@@ -636,6 +636,29 @@ ContactMethod* PhoneDirectoryModel::fromHash(const QString& hash) ...@@ -636,6 +636,29 @@ ContactMethod* PhoneDirectoryModel::fromHash(const QString& hash)
return nullptr; return nullptr;
} }
/** Filter the existing CMs for an URI without flooding the model with merge
* candidates.
*
* This should help reduce the number of accidental duplicates once its
* usage spread over the code. It also reduce the boilerplate code.
**/
ContactMethod* PhoneDirectoryModel::getExistingNumberIf(const URI& uri, const std::function<bool(const ContactMethod*)>& pred) const
{
// Prevent the most obvious duplicates
const URI strippedUri(uri);
//See if the number is already loaded
const NumberWrapper* w = d_ptr->m_hDirectory[strippedUri];
if (!w)
return nullptr;
const auto iter = std::find_if(std::begin(w->numbers), std::end(w->numbers), pred);
return (iter != std::end(w->numbers)) ? *iter : nullptr;
}
QVector<ContactMethod*> PhoneDirectoryModel::getNumbersByPopularity() const QVector<ContactMethod*> PhoneDirectoryModel::getNumbersByPopularity() const
{ {
return d_ptr->m_lPopularityIndex; return d_ptr->m_lPopularityIndex;
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#include "typedefs.h" #include "typedefs.h"
// STD
#include <functional>
//Qt //Qt
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QAbstractTableModel> #include <QtCore/QAbstractTableModel>
...@@ -83,6 +86,8 @@ public: ...@@ -83,6 +86,8 @@ public:
Q_INVOKABLE ContactMethod* fromHash (const QString& hash); Q_INVOKABLE ContactMethod* fromHash (const QString& hash);
Q_INVOKABLE ContactMethod* fromTemporary(const TemporaryContactMethod* number); Q_INVOKABLE ContactMethod* fromTemporary(const TemporaryContactMethod* number);
ContactMethod* getExistingNumberIf(const URI& uri, const std::function<bool(const ContactMethod*)>& pred) const;
//Getter //Getter
int count() const; int count() const;
bool callWithAccount() const; bool callWithAccount() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment