• 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
  • searchduplicate
searchduplicateresultwidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 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 "searchduplicateresultwidget.h"
19 #include "merge/widgets/mergecontactloseinformationwarning.h"
20 #include "merge/job/mergecontactsjob.h"
21 #include "merge/job/mergecontacts.h"
22 #include "resultduplicatetreewidget.h"
23 #include <KLocalizedString>
24 #include <QHBoxLayout>
25 #include <QTreeWidget>
26 #include <QSplitter>
27 #include <QLabel>
28 #include <KPushButton>
29 #include <kaddressbookgrantlee/widget/grantleecontactviewer.h>
30 #include <akonadi/collectioncombobox.h>
31 
32 
33 namespace KABMergeContacts {
34 KADDRESSBOOK_EXPORT QAbstractItemModel *_k_searchDuplicateResultStubModel = 0;
35 }
36 
37 using namespace KABMergeContacts;
38 SearchDuplicateResultWidget::SearchDuplicateResultWidget(QWidget *parent)
39  : QWidget(parent),
40  mIndexListContact(0)
41 {
42  QVBoxLayout *mainLayout = new QVBoxLayout;
43  setLayout(mainLayout);
44 
45  QSplitter *splitter = new QSplitter;
46  splitter->setObjectName(QLatin1String("splitter"));
47  splitter->setChildrenCollapsible(false);
48  mainLayout->addWidget(splitter);
49  mResult = new ResultDuplicateTreeWidget;
50  mResult->setObjectName(QLatin1String("result_treewidget"));
51  mContactViewer = new KAddressBookGrantlee::GrantleeContactViewer;
52  mContactViewer->setObjectName(QLatin1String("contact_viewer"));
53  splitter->addWidget(mResult);
54  splitter->addWidget(mContactViewer);
55  connect(mResult, SIGNAL(showContactPreview(Akonadi::Item)), mContactViewer, SLOT(setContact(Akonadi::Item)));
56 
57  mMergeContactWarning = new MergeContactLoseInformationWarning;
58  mMergeContactWarning->setObjectName(QLatin1String("mergecontactwarning"));
59  connect(mMergeContactWarning, SIGNAL(continueMerging()), this, SLOT(slotAutomaticMerging()));
60  connect(mMergeContactWarning, SIGNAL(customizeMergingContacts()), this, SLOT(slotCustomizeMergingContacts()));
61  mainLayout->addWidget(mMergeContactWarning);
62 
63  QHBoxLayout *mergeLayout = new QHBoxLayout;
64  mainLayout->addLayout(mergeLayout);
65  mergeLayout->addStretch();
66  //KF5 add i18n
67  QLabel *lab = new QLabel(QLatin1String("Select AddressBook:"));
68  lab->setObjectName(QLatin1String("select_addressbook_label"));
69  mergeLayout->addWidget(lab);
70 
71  mCollectionCombobox = new Akonadi::CollectionComboBox(_k_searchDuplicateResultStubModel);
72  mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
73  mCollectionCombobox->setMinimumWidth(250);
74  mCollectionCombobox->setMimeTypeFilter( QStringList() << KABC::Addressee::mimeType() );
75  mCollectionCombobox->setObjectName(QLatin1String("akonadicombobox"));
76  connect(mCollectionCombobox, SIGNAL(currentIndexChanged(int)), SLOT(slotUpdateMergeButton()));
77  connect(mCollectionCombobox, SIGNAL(activated(int)), SLOT(slotUpdateMergeButton()));
78  mergeLayout->addWidget(mCollectionCombobox);
79 
80  //KF5 add i18n
81  mMergeContact = new KPushButton(QLatin1String("Merge"));
82  mMergeContact->setObjectName(QLatin1String("merge_contact_button"));
83  connect(mMergeContact, SIGNAL(clicked()), this, SLOT(slotMergeContact()));
84  mergeLayout->addWidget(mMergeContact);
85  mMergeContact->setEnabled(false);
86  //TODO make mMergeContact enable when selected item and collection valid
87 }
88 
89 SearchDuplicateResultWidget::~SearchDuplicateResultWidget()
90 {
91 
92 }
93 
94 void SearchDuplicateResultWidget::setContacts(const QList<Akonadi::Item::List> &lstItem)
95 {
96  mResult->setContacts(lstItem);
97 }
98 
99 void SearchDuplicateResultWidget::slotMergeContact()
100 {
101  mIndexListContact = 0;
102  mListContactToMerge = mResult->selectedContactsToMerge();
103  if (!mListContactToMerge.isEmpty()) {
104  KABMergeContacts::MergeContacts mergeContacts;
105  bool conflictFound = false;
106  mResultConflictList.clear();
107  Q_FOREACH(const Akonadi::Item::List & lst, mListContactToMerge) {
108  mergeContacts.setItems(lst);
109  const MergeContacts::ConflictInformations conflicts = mergeContacts.requiresManualSelectionOfInformation();
110  if (conflicts != MergeContacts::None) {
111  conflictFound = true;
112  }
113  MergeConflictResult result;
114  result.list = lst;
115  result.conflictInformation = conflicts;
116  mResultConflictList.append(result);
117  }
118 
119  mMergeContact->setEnabled(false);
120  if (!conflictFound) {
121  //Detect if conflict.
122  mergeContact();
123  } else {
124  mMergeContactWarning->animatedShow();
125  }
126  }
127 }
128 
129 void SearchDuplicateResultWidget::mergeContact()
130 {
131  if (mIndexListContact < mListContactToMerge.count()) {
132  KABMergeContacts::MergeContactsJob *job = new KABMergeContacts::MergeContactsJob(this);
133  job->setListItem(mListContactToMerge.at(mIndexListContact));
134  job->setDestination(mCollectionCombobox->currentCollection());
135  connect(job, SIGNAL(finished(Akonadi::Item)), this, SLOT(slotMergeDone(Akonadi::Item)));
136  job->start();
137  } else {
138  Q_EMIT mergeDone();
139  }
140 }
141 
142 void SearchDuplicateResultWidget::slotMergeDone(const Akonadi::Item &item)
143 {
144  ++mIndexListContact;
145  Q_EMIT contactMerged(item);
146  mergeContact();
147 }
148 
149 void SearchDuplicateResultWidget::slotUpdateMergeButton()
150 {
151  mMergeContact->setEnabled(mCollectionCombobox->currentCollection().isValid());
152 }
153 
154 void SearchDuplicateResultWidget::slotAutomaticMerging()
155 {
156  mergeContact();
157 }
158 
159 void SearchDuplicateResultWidget::slotCustomizeMergingContacts()
160 {
161  Q_EMIT customizeMergeContact(mResultConflictList, mCollectionCombobox->currentCollection());
162 }
resultduplicatetreewidget.h
QWidget
searchduplicateresultwidget.h
KABMergeContacts::SearchDuplicateResultWidget::mergeDone
void mergeDone()
KABMergeContacts::MergeContacts::setItems
void setItems(const Akonadi::Item::List &items)
Definition: mergecontacts.cpp:32
KADDRESSBOOK_EXPORT
#define KADDRESSBOOK_EXPORT
Definition: kaddressbook_export.h:35
QList::at
const T & at(int i) const
mergecontactloseinformationwarning.h
QHBoxLayout
KABMergeContacts::MergeContacts::None
Definition: mergecontacts.h:33
KABMergeContacts::MergeContacts
Definition: mergecontacts.h:26
KABMergeContacts::_k_searchDuplicateResultStubModel
KADDRESSBOOK_EXPORT QAbstractItemModel * _k_searchDuplicateResultStubModel
Definition: searchduplicateresultwidget.cpp:34
QSplitter::addWidget
void addWidget(QWidget *widget)
KABMergeContacts::MergeContactsJob
Definition: mergecontactsjob.h:26
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QList::count
int count(const T &value) const
KABMergeContacts::SearchDuplicateResultWidget::SearchDuplicateResultWidget
SearchDuplicateResultWidget(QWidget *parent=0)
Definition: searchduplicateresultwidget.cpp:38
QWidget::setLayout
void setLayout(QLayout *layout)
QSplitter::setChildrenCollapsible
void setChildrenCollapsible(bool)
KABMergeContacts::SearchDuplicateResultWidget::setContacts
void setContacts(const QList< Akonadi::Item::List > &lstItem)
Definition: searchduplicateresultwidget.cpp:94
KABMergeContacts::MergeConflictResult
Definition: searchduplicateresultwidget.h:36
KABMergeContacts::MergeContactLoseInformationWarning
Definition: mergecontactloseinformationwarning.h:24
mergecontacts.h
QList::isEmpty
bool isEmpty() const
mergecontactsjob.h
QObject::setObjectName
void setObjectName(const QString &name)
QVBoxLayout
KABMergeContacts::ResultDuplicateTreeWidget
Definition: resultduplicatetreewidget.h:44
KABMergeContacts::MergeContactsJob::start
void start()
Definition: mergecontactsjob.cpp:56
QList< Akonadi::Item::List >
KABMergeContacts::SearchDuplicateResultWidget::customizeMergeContact
void customizeMergeContact(const QVector< KABMergeContacts::MergeConflictResult > &, const Akonadi::Collection &col)
QStringList
KABMergeContacts::MergeConflictResult::conflictInformation
MergeContacts::ConflictInformations conflictInformation
Definition: searchduplicateresultwidget.h:38
KABMergeContacts::SearchDuplicateResultWidget::contactMerged
void contactMerged(const Akonadi::Item &item)
KABMergeContacts::ResultDuplicateTreeWidget::selectedContactsToMerge
QList< Akonadi::Item::List > selectedContactsToMerge() const
Definition: resultduplicatetreewidget.cpp:106
KABMergeContacts::MergeContactsJob::setListItem
void setListItem(const Akonadi::Item::List &lstItem)
Definition: mergecontactsjob.cpp:87
QSplitter
KABMergeContacts::MergeConflictResult::list
Akonadi::Item::List list
Definition: searchduplicateresultwidget.h:37
QLatin1String
QBoxLayout::addStretch
void addStretch(int stretch)
QAbstractItemModel
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KABMergeContacts::MergeContacts::requiresManualSelectionOfInformation
MergeContacts::ConflictInformations requiresManualSelectionOfInformation()
Definition: mergecontacts.cpp:186
QLabel
KABMergeContacts::ResultDuplicateTreeWidget::setContacts
void setContacts(const QList< Akonadi::Item::List > &lstItem)
Definition: resultduplicatetreewidget.cpp:88
KABMergeContacts::MergeContactsJob::setDestination
void setDestination(const Akonadi::Collection &collection)
Definition: mergecontactsjob.cpp:92
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
KABMergeContacts::SearchDuplicateResultWidget::~SearchDuplicateResultWidget
~SearchDuplicateResultWidget()
Definition: searchduplicateresultwidget.cpp:89
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