• 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
mergecontactsjob.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 #include "mergecontactsjob.h"
19 #include "mergecontacts.h"
20 #include <Akonadi/ItemCreateJob>
21 #include <Akonadi/ItemDeleteJob>
22 
23 #include <KABC/Address>
24 #include <KABC/Addressee>
25 
26 #include <QDebug>
27 
28 using namespace KABMergeContacts;
29 
30 MergeContactsJob::MergeContactsJob(QObject *parent)
31  : QObject(parent)
32 {
33 }
34 
35 MergeContactsJob::~MergeContactsJob()
36 {
37 
38 }
39 
40 bool MergeContactsJob::canStart()
41 {
42  if (!mCollection.isValid()) {
43  qDebug()<<" mCollection is not valid !";
44  return false;
45  }
46  if (mNewContact.isEmpty()) {
47  if (mListItem.isEmpty()) {
48  qDebug()<<" list item is empty !";
49  return false;
50  }
51  }
52  return true;
53 
54 }
55 
56 void MergeContactsJob::start()
57 {
58  if (!canStart()) {
59  Q_EMIT finished(mCreatedContact);
60  deleteLater();
61  return;
62  }
63  generateMergedContact();
64 }
65 
66 void MergeContactsJob::generateMergedContact()
67 {
68  if (mNewContact.isEmpty()) {
69  MergeContacts mergeContact(mListItem);
70  const KABC::Addressee newContact = mergeContact.mergedContact();
71  if (newContact.isEmpty()) {
72  Q_EMIT finished(mCreatedContact);
73  deleteLater();
74  return;
75  }
76  createMergedContact(newContact);
77  } else {
78  createMergedContact(mNewContact);
79  }
80 }
81 
82 void MergeContactsJob::setNewContact(const KABC::Addressee & addr)
83 {
84  mNewContact = addr;
85 }
86 
87 void MergeContactsJob::setListItem(const Akonadi::Item::List &lstItem)
88 {
89  mListItem = lstItem;
90 }
91 
92 void MergeContactsJob::setDestination(const Akonadi::Collection &collection)
93 {
94  mCollection = collection;
95 }
96 
97 void MergeContactsJob::createMergedContact(const KABC::Addressee &addressee)
98 {
99  Akonadi::Item item;
100  item.setMimeType( KABC::Addressee::mimeType() );
101  item.setPayload<KABC::Addressee>( addressee );
102 
103  Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob(item, mCollection, this);
104  connect(job, SIGNAL(result(KJob*)), SLOT(slotCreateMergedContactFinished(KJob*)) );
105 }
106 
107 void MergeContactsJob::slotCreateMergedContactFinished(KJob *job)
108 {
109  if (job->error()) {
110  qDebug() << job->errorString();
111  Q_EMIT finished(mCreatedContact);
112  deleteLater();
113  return;
114  }
115  Akonadi::ItemCreateJob *createdJob = qobject_cast<Akonadi::ItemCreateJob *>(job);
116  mCreatedContact = createdJob->item();
117 
118  if (!mListItem.isEmpty()) {
119  Akonadi::ItemDeleteJob *deleteJob = new Akonadi::ItemDeleteJob(mListItem, this);
120  connect(deleteJob, SIGNAL(result(KJob*)), SLOT(slotDeleteContactsFinished(KJob*)) );
121  } else {
122  qDebug()<<" mListITem is empty. We can't delete it";
123  }
124 }
125 
126 void MergeContactsJob::slotDeleteContactsFinished(KJob *job)
127 {
128  if (job->error()) {
129  qDebug() << job->errorString();
130  }
131  Q_EMIT finished(mCreatedContact);
132  deleteLater();
133 }
KABMergeContacts::MergeContactsJob::setNewContact
void setNewContact(const KABC::Addressee &addr)
Definition: mergecontactsjob.cpp:82
KABMergeContacts::MergeContactsJob::finished
void finished(const Akonadi::Item &item)
KABMergeContacts::MergeContacts
Definition: mergecontacts.h:26
mergecontacts.h
QObject
KABMergeContacts::MergeContactsJob::MergeContactsJob
MergeContactsJob(QObject *parent=0)
Definition: mergecontactsjob.cpp:30
mergecontactsjob.h
KABMergeContacts::MergeContactsJob::canStart
bool canStart()
Definition: mergecontactsjob.cpp:40
KABMergeContacts::MergeContactsJob::start
void start()
Definition: mergecontactsjob.cpp:56
QObject::deleteLater
void deleteLater()
KABMergeContacts::MergeContactsJob::setListItem
void setListItem(const Akonadi::Item::List &lstItem)
Definition: mergecontactsjob.cpp:87
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KABMergeContacts::MergeContactsJob::setDestination
void setDestination(const Akonadi::Collection &collection)
Definition: mergecontactsjob.cpp:92
KABMergeContacts::MergeContactsJob::~MergeContactsJob
~MergeContactsJob()
Definition: mergecontactsjob.cpp:35
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