20 #include "matchessolver_p.h"
22 #include "personsmodel.h"
23 #include "personmanager_p.h"
29 MatchesSolver::MatchesSolver(
const QList<Match> &matches,
PersonsModel *model, QObject *parent)
36 void MatchesSolver::start()
38 QMetaObject::invokeMethod(
this,
"startMatching", Qt::QueuedConnection);
41 void MatchesSolver::startMatching()
44 QHash<QString, QSet<QString> > jobsData;
46 QHash<QString, QString> destinationResolver;
47 Q_FOREACH (
const Match &m, m_matches) {
48 QString urlA = m.indexA.data(PersonsModel::PersonUriRole).toString();
49 QString urlB = m.indexB.data(PersonsModel::PersonUriRole).toString();
50 Q_ASSERT(urlA != urlB);
52 const bool inA = destinationResolver.contains(urlA);
53 const bool inB = destinationResolver.contains(urlB);
56 destinationResolver[urlB] = urlA;
57 jobsData[urlA] = jobsData.take(urlB);
62 QList<QString> keys = destinationResolver.keys(urlB);
63 foreach (
const QString &key, keys) {
64 destinationResolver[key] = urlA;
72 const QString mergeUrl = destinationResolver.value(urlB, urlB);
74 QSet<QString> &jobs = jobsData[mergeUrl];
79 Q_ASSERT(urlA != mergeUrl);
80 destinationResolver.insert(urlA, mergeUrl);
81 if (urlB != mergeUrl) {
82 destinationResolver.insert(urlB, mergeUrl);
87 Q_FOREACH (
const QSet<QString> &uris, jobsData) {
88 if (PersonManager::instance()->
mergeContacts(uris.toList()).isEmpty()) {
89 qWarning() <<
"error: failing to merge contacts: " << uris;
KPEOPLE_EXPORT QString mergeContacts(const QStringList &uris)
Merge all uris into a single person.
The KPeople namespace contains all the classes for Libkpeople.
This class creates a model of all known contacts from all sources Contacts are represented as a tree ...