File indexing completed on 2024-04-21 15:02:47

0001 /*
0002     KPeople - Duplicates
0003     SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 
0008 #include "match_p.h"
0009 #include <KLocalizedString>
0010 
0011 using namespace KPeople;
0012 
0013 Match::Match(const QList<MatchReason> &reasons, const QPersistentModelIndex &a, const QPersistentModelIndex &b)
0014     : reasons(reasons)
0015     , indexA(a)
0016     , indexB(b)
0017 {
0018     if (indexB < indexA) {
0019         qSwap(indexA, indexB);
0020     }
0021 }
0022 
0023 bool Match::operator==(const Match &m) const
0024 {
0025     /* clang-format off */
0026     return reasons == m.reasons
0027         && indexA == m.indexA
0028         && indexB == m.indexB;
0029     /* clang-format on */
0030 }
0031 
0032 bool Match::operator<(const Match &m) const
0033 {
0034     /* clang-format off */
0035     return indexA < m.indexA
0036         || (indexA == m.indexA && indexB < m.indexB);
0037     /* clang-format on */
0038 }
0039 
0040 QStringList Match::matchReasons() const
0041 {
0042     QStringList ret;
0043     for (MatchReason r : reasons) {
0044         switch (r) {
0045         case NameMatch:
0046             ret += i18nc("@title:column", "Name");
0047             break;
0048         case EmailMatch:
0049             ret += i18nc("@title:column", "E-mail");
0050             break;
0051         }
0052     }
0053     return ret;
0054 }
0055 
0056 QString Match::matchValue(MatchReason r, const AbstractContact::Ptr &addr)
0057 {
0058     switch (r) {
0059     case NameMatch:
0060         return addr->customProperty(AbstractContact::NameProperty).toString();
0061     case EmailMatch:
0062         return addr->customProperty(AbstractContact::EmailProperty).toString();
0063     }
0064     Q_UNREACHABLE();
0065 }
0066 
0067 QList<Match::MatchReason> Match::matchAt(const AbstractContact::Ptr &value, const AbstractContact::Ptr &toCompare)
0068 {
0069     QList<Match::MatchReason> ret;
0070 
0071     QVariant name = value->customProperty(AbstractContact::NameProperty);
0072     if (name.isValid() && name == toCompare->customProperty(AbstractContact::NameProperty)) {
0073         ret.append(Match::NameMatch);
0074     }
0075 
0076     return ret;
0077 }
0078 
0079 #include "moc_match_p.cpp"