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

KPeople

  • frameworks
  • kpeople
  • src
duplicatesfinder.cpp
1 /*
2  Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "duplicatesfinder_p.h"
20 #include "personsmodel.h"
21 
22 #include <QUrl>
23 #include <QDebug>
24 
25 using namespace KPeople;
26 
27 DuplicatesFinder::DuplicatesFinder(PersonsModel *model, QObject *parent)
28  : KJob(parent)
29  , m_model(model)
30 {
31 }
32 
33 void DuplicatesFinder::setSpecificPerson(const QString &personUri)
34 {
35  m_personUri = personUri;
36 }
37 
38 void DuplicatesFinder::start()
39 {
40  if (m_personUri.isEmpty()) {
41  QMetaObject::invokeMethod(this, "doSearch", Qt::QueuedConnection);
42  } else {
43  QMetaObject::invokeMethod(this, "doSpecificSearch", Qt::QueuedConnection);
44  }
45 }
46 
47 //TODO: start providing partial results so that we can start processing matches while it's not done
48 void DuplicatesFinder::doSearch()
49 {
50  //NOTE: This can probably optimized. I'm just trying to get the semantics right at the moment
51  //maybe using nepomuk for the matching would help?
52 
53  QVector<AbstractContact::Ptr> collectedValues;
54  m_matches.clear();
55 
56  if (m_model->rowCount() == 0) {
57  qWarning() << "finding duplicates on empty model!";
58  }
59 
60  for (int i = 0, rows = m_model->rowCount(); i < rows; i++) {
61  QModelIndex idx = m_model->index(i, 0);
62 
63  //we gather the values
64  AbstractContact::Ptr values = idx.data(PersonsModel::PersonVCardRole).value<AbstractContact::Ptr>();
65 
66  //we check if it matches
67  int j = 0;
68  Q_FOREACH (const AbstractContact::Ptr &valueToCompare, collectedValues) {
69  QList<Match::MatchReason> matchedRoles = Match::matchAt(values, valueToCompare);
70 
71  if (!matchedRoles.isEmpty()) {
72  QPersistentModelIndex i2(m_model->index(j, 0));
73 
74  m_matches.append(Match(matchedRoles, idx, i2));
75  }
76  j++;
77  }
78 
79  //we add our data for comparing later
80  collectedValues.append(values);
81  }
82  emitResult();
83 }
84 
85 void DuplicatesFinder::doSpecificSearch()
86 {
87  m_matches.clear();
88 
89  QModelIndex idx = m_model->indexForPersonUri(m_personUri);
90  AbstractContact::Ptr values = idx.data(PersonsModel::PersonVCardRole).value<AbstractContact::Ptr>();
91 
92  for (int i = 0, rows = m_model->rowCount(); i < rows; i++) {
93  QModelIndex idx2 = m_model->index(i, 0);
94 
95  if (idx2.data(PersonsModel::PersonUriRole) == m_personUri) {
96  continue;
97  }
98 
99  AbstractContact::Ptr values2 = idx2.data(PersonsModel::PersonVCardRole).value<AbstractContact::Ptr>();
100  QList<Match::MatchReason> matchedRoles = Match::matchAt(values, values2);
101  if (!matchedRoles.isEmpty()) {
102  m_matches.append(Match(matchedRoles, idx, idx2));
103  }
104  }
105 
106  emitResult();
107 }
108 
109 QList<Match> DuplicatesFinder::results() const
110 {
111  return m_matches;
112 }
KPeople
The KPeople namespace contains all the classes for Libkpeople.
KPeople::PersonsModel
This class creates a model of all known contacts from all sources Contacts are represented as a tree ...
Definition: personsmodel.h:42
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