• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kaddressbook

  • sources
  • kde-4.14
  • kdepim
  • kaddressbook
  • merge
  • job
searchpotentialduplicatecontactjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 
19 #include "searchpotentialduplicatecontactjob.h"
20 
21 #include <KABC/Addressee>
22 
23 using namespace KABMergeContacts;
24 
25 SearchPotentialDuplicateContactJob::SearchPotentialDuplicateContactJob(const Akonadi::Item::List &list, QObject *parent)
26  : QObject(parent),
27  mListItem(list)
28 {
29 }
30 
31 SearchPotentialDuplicateContactJob::~SearchPotentialDuplicateContactJob()
32 {
33 
34 }
35 
36 void SearchPotentialDuplicateContactJob::start()
37 {
38  mListDuplicate.clear();
39  Akonadi::Item::List result = mListItem;
40  while(!result.isEmpty()) {
41  result = checkList(result);
42  }
43  Q_EMIT finished(mListDuplicate);
44  deleteLater();
45 }
46 
47 QList<Akonadi::Item::List > SearchPotentialDuplicateContactJob::potentialDuplicateContacts() const
48 {
49  return mListDuplicate;
50 }
51 
52 Akonadi::Item::List SearchPotentialDuplicateContactJob::checkList(const Akonadi::Item::List &lstItem)
53 {
54  QList<Akonadi::Item> notDuplicate;
55  QList<Akonadi::Item> lst;
56  if (!lstItem.isEmpty()) {
57  Akonadi::Item firstItem = lstItem.at(0);
58  const int numberOfItems(lstItem.count());
59  for (int j = 1; j < numberOfItems; ++j) {
60  const Akonadi::Item nextItem = lstItem.at(j);
61  if (isDuplicate(firstItem, nextItem)) {
62  lst.append(nextItem);
63  } else {
64  notDuplicate.append(nextItem);
65  }
66  }
67  if (!lst.isEmpty()) {
68  lst.append(firstItem);
69  mListDuplicate.append(lst);
70  }
71  }
72  return notDuplicate;
73 }
74 
75 bool SearchPotentialDuplicateContactJob::isDuplicate(const Akonadi::Item &itemA, const Akonadi::Item &itemB)
76 {
77  if (!itemA.hasPayload<KABC::Addressee>() || !itemB.hasPayload<KABC::Addressee>()) {
78  return false;
79  }
80 
81  const KABC::Addressee addressA = itemA.payload<KABC::Addressee>();
82  const KABC::Addressee addressB = itemB.payload<KABC::Addressee>();
83  //
84  if (!addressA.name().isEmpty() && !addressB.name().isEmpty()) {
85  //qDebug()<<" addressB"<<addressB.name()<<" addressA.name()"<<addressA.name();
86  if (addressA.name() == addressB.name()) {
87  //qDebug()<<" return true;";
88  return true;
89  }
90  }
91  if (!addressA.nickName().isEmpty() && !addressB.nickName().isEmpty()) {
92  if (addressA.nickName() == addressB.nickName()) {
93  return true;
94  }
95  }
96  if (!addressA.emails().isEmpty() && !addressB.emails().isEmpty()) {
97  Q_FOREACH (const QString &email, addressA.emails()) {
98  if (addressB.emails().contains(email)) {
99  return true;
100  }
101  }
102  }
103  return false;
104 }
QList::clear
void clear()
searchpotentialduplicatecontactjob.h
KABMergeContacts::SearchPotentialDuplicateContactJob::~SearchPotentialDuplicateContactJob
~SearchPotentialDuplicateContactJob()
Definition: searchpotentialduplicatecontactjob.cpp:31
QList::at
const T & at(int i) const
KABMergeContacts::SearchPotentialDuplicateContactJob::potentialDuplicateContacts
QList< Akonadi::Item::List > potentialDuplicateContacts() const
Definition: searchpotentialduplicatecontactjob.cpp:47
QList::append
void append(const T &value)
QObject
QList::isEmpty
bool isEmpty() const
KABMergeContacts::SearchPotentialDuplicateContactJob::finished
void finished(const QList< Akonadi::Item::List > &)
QObject::deleteLater
void deleteLater()
QString
QList< Akonadi::Item::List >
KABMergeContacts::SearchPotentialDuplicateContactJob::SearchPotentialDuplicateContactJob
SearchPotentialDuplicateContactJob(const Akonadi::Item::List &list, QObject *parent=0)
Definition: searchpotentialduplicatecontactjob.cpp:25
KABMergeContacts::SearchPotentialDuplicateContactJob::start
void start()
Definition: searchpotentialduplicatecontactjob.cpp:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kaddressbook

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



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