• Skip to content
  • Skip to link menu
KDE API Documentation - match.cpp Source File (KPeople)
  • KDE Home
  • Contact Us
 

KPeople

  • frameworks
  • kpeople
  • src
match.cpp
1 /*
2  KPeople - Duplicates
3  Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #include "match_p.h"
21 #include <KLocalizedString>
22 
23 using namespace KPeople;
24 
25 Match::Match(const QList<MatchReason> &reasons, const QPersistentModelIndex &a, const QPersistentModelIndex &b)
26  : reasons(reasons), indexA(a), indexB(b)
27 {
28  if (indexB < indexA) {
29  qSwap(indexA, indexB);
30  }
31 }
32 
33 bool Match::operator==(const Match &m) const
34 {
35  return reasons == m.reasons
36  && indexA == m.indexA
37  && indexB == m.indexB;
38 }
39 
40 bool Match::operator<(const Match &m) const
41 {
42  return indexA < m.indexA
43  || (indexA == m.indexA && indexB < m.indexB);
44 }
45 
46 QStringList Match::matchReasons() const
47 {
48  QStringList ret;
49  for (MatchReason r : reasons) {
50  switch (r) {
51  case NameMatch:
52  ret += i18n("Name");
53  break;
54  case EmailMatch:
55  ret += i18n("E-mail");
56  break;
57  }
58  }
59  return ret;
60 }
61 
62 QString Match::matchValue(MatchReason r, const AbstractContact::Ptr &addr)
63 {
64  switch (r) {
65  case NameMatch:
66  return addr->customProperty(AbstractContact::NameProperty).toString();
67  case EmailMatch:
68  return addr->customProperty(AbstractContact::EmailProperty).toString();
69  }
70  Q_UNREACHABLE();
71 }
72 
73 QList<Match::MatchReason> Match::matchAt(const AbstractContact::Ptr &value, const AbstractContact::Ptr &toCompare)
74 {
75  QList<Match::MatchReason> ret;
76 
77  QVariant name = value->customProperty(AbstractContact::NameProperty);
78  if (name.isValid() && name == toCompare->customProperty(AbstractContact::NameProperty)) {
79  ret.append(Match::NameMatch);
80  }
81 
82  return ret;
83 }
KPeople
The KPeople namespace contains all the classes for Libkpeople.
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Fri Feb 13 2015 15:16:39 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPeople

Skip menu "KPeople"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal