• 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
  • widgets
mergecontactselectinformationwidget.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 "mergecontactselectinformationwidget.h"
19 #include "merge/widgets/mergecontactselectlistwidget.h"
20 #include <KLocalizedString>
21 #include <QVBoxLayout>
22 #include <QLabel>
23 #include <QTreeWidget>
24 
25 using namespace KABMergeContacts;
26 MergeContactSelectInformationWidget::MergeContactSelectInformationWidget(QWidget *parent)
27  : QWidget(parent)
28 {
29  QVBoxLayout *mainLayout = new QVBoxLayout;
30  mainLayout->setMargin(0);
31  setLayout(mainLayout);
32 }
33 
34 MergeContactSelectInformationWidget::~MergeContactSelectInformationWidget()
35 {
36 
37 }
38 
39 void MergeContactSelectInformationWidget::setContacts(MergeContacts::ConflictInformations conflictTypes, const Akonadi::Item::List &listItem)
40 {
41  Q_FOREACH(const Akonadi::Item &item, listItem) {
42  if (item.hasPayload<KABC::Addressee>()) {
43  const KABC::Addressee address = item.payload<KABC::Addressee>();
44  mAddressList.append(address);
45  }
46  }
47  if (conflictTypes & MergeContacts::Birthday) {
48  addInformationWidget(MergeContacts::Birthday);
49  }
50  if (conflictTypes & MergeContacts::Geo) {
51  addInformationWidget(MergeContacts::Geo);
52  }
53  if (conflictTypes & MergeContacts::Photo) {
54  addInformationWidget(MergeContacts::Photo);
55  }
56  if (conflictTypes & MergeContacts::Logo) {
57  addInformationWidget(MergeContacts::Logo);
58  }
59  if (conflictTypes & MergeContacts::Anniversary) {
60  addInformationWidget(MergeContacts::Anniversary);
61  }
62  if (conflictTypes & MergeContacts::Name) {
63  addInformationWidget(MergeContacts::Name);
64  }
65  if (conflictTypes & MergeContacts::NickName) {
66  addInformationWidget(MergeContacts::NickName);
67  }
68  if (conflictTypes & MergeContacts::Blog) {
69  addInformationWidget(MergeContacts::Blog);
70  }
71  if (conflictTypes & MergeContacts::HomePage) {
72  addInformationWidget(MergeContacts::HomePage);
73  }
74  if (conflictTypes & MergeContacts::Organization) {
75  addInformationWidget(MergeContacts::Organization);
76  }
77  if (conflictTypes & MergeContacts::Profession) {
78  addInformationWidget(MergeContacts::Profession);
79  }
80  if (conflictTypes & MergeContacts::Title) {
81  addInformationWidget(MergeContacts::Title);
82  }
83  if (conflictTypes & MergeContacts::Departement) {
84  addInformationWidget(MergeContacts::Departement);
85  }
86  if (conflictTypes & MergeContacts::Office) {
87  addInformationWidget(MergeContacts::Office);
88  }
89  if (conflictTypes & MergeContacts::ManagerName) {
90  addInformationWidget(MergeContacts::ManagerName);
91  }
92  if (conflictTypes & MergeContacts::Assistant) {
93  addInformationWidget(MergeContacts::Assistant);
94  }
95  if (conflictTypes & MergeContacts::FreeBusy) {
96  addInformationWidget(MergeContacts::FreeBusy);
97  }
98  if (conflictTypes & MergeContacts::FamilyName) {
99  addInformationWidget(MergeContacts::FamilyName);
100  }
101  if (conflictTypes & MergeContacts::PartnerName) {
102  addInformationWidget(MergeContacts::PartnerName);
103  }
104  if (conflictTypes & MergeContacts::Keys) {
105  addInformationWidget(MergeContacts::Keys);
106  }
107 }
108 
109 void MergeContactSelectInformationWidget::addInformationWidget(MergeContacts::ConflictInformation conflictType)
110 {
111  MergeContactSelectListWidget *widget = new MergeContactSelectListWidget;
112  widget->setContacts(conflictType, mAddressList);
113  layout()->addWidget(widget);
114  mListMergeSelectInformation.append(widget);
115 }
116 
117 bool MergeContactSelectInformationWidget::verifySelectedInfo() const
118 {
119  bool result = true;
120  Q_FOREACH(MergeContactSelectListWidget *listWidget, mListMergeSelectInformation) {
121  result = listWidget->verifySelectedInfo();
122  if (!result) {
123  break;
124  }
125  }
126  return result;
127 }
128 
129 void MergeContactSelectInformationWidget::createContact(KABC::Addressee &addr)
130 {
131  Q_FOREACH(MergeContactSelectListWidget *listWidget, mListMergeSelectInformation) {
132  const int selectedContactIndex = listWidget->selectedContact();
133  const MergeContacts::ConflictInformation conflictType = listWidget->conflictType();
134  if (selectedContactIndex != -1) {
135  switch(conflictType) {
136  case MergeContacts::None:
137  break;
138  case MergeContacts::Birthday:
139  addr.setBirthday(mAddressList.at(selectedContactIndex).birthday());
140  break;
141  case MergeContacts::Geo:
142  addr.setGeo(mAddressList.at(selectedContactIndex).geo());
143  break;
144  case MergeContacts::Photo:
145  addr.setPhoto(mAddressList.at(selectedContactIndex).photo());
146  break;
147  case MergeContacts::Logo:
148  addr.setLogo(mAddressList.at(selectedContactIndex).logo());
149  break;
150  case MergeContacts::Anniversary:
151  addr.setBirthday(mAddressList.at(selectedContactIndex).birthday());
152  break;
153  case MergeContacts::Name:
154  addr.setName(mAddressList.at(selectedContactIndex).name());
155  break;
156  case MergeContacts::NickName:
157  addr.setNickName(mAddressList.at(selectedContactIndex).nickName());
158  break;
159  case MergeContacts::Blog: {
160  const QString newBlog = mAddressList.at(selectedContactIndex).custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "BlogFeed" ));
161  addr.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "BlogFeed" ), newBlog );
162  break;
163  }
164  case MergeContacts::HomePage:
165  addr.setUrl(mAddressList.at(selectedContactIndex).url());
166  break;
167  case MergeContacts::Organization:
168  addr.setOrganization(mAddressList.at(selectedContactIndex).organization());
169  break;
170  case MergeContacts::Profession: {
171  const QString newValue = mAddressList.at(selectedContactIndex).custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Profession" ));
172  addr.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Profession" ), newValue );
173  break;
174  }
175  case MergeContacts::Title:
176  addr.setTitle(mAddressList.at(selectedContactIndex).title());
177  break;
178  case MergeContacts::Departement:
179  addr.setDepartment(mAddressList.at(selectedContactIndex).department());
180  break;
181  case MergeContacts::Office:{
182  const QString newValue = mAddressList.at(selectedContactIndex).custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Office" ));
183  addr.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Office" ), newValue );
184  break;
185  }
186  case MergeContacts::ManagerName: {
187  const QString newValue = mAddressList.at(selectedContactIndex).custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-ManagersName" ));
188  addr.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-ManagersName" ), newValue );
189  break;
190  }
191  case MergeContacts::Assistant: {
192  const QString newValue = mAddressList.at(selectedContactIndex).custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-AssistantsName" ));
193  addr.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-AssistantsName" ), newValue );
194  break;
195  }
196  case MergeContacts::FreeBusy:
197  //TODO
198  break;
199  case MergeContacts::FamilyName:
200  addr.setFamilyName(mAddressList.at(selectedContactIndex).familyName());
201  break;
202  case MergeContacts::PartnerName: {
203  const QString newValue = mAddressList.at(selectedContactIndex).custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-SpousesName" ));
204  addr.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-SpousesName" ), newValue );
205  break;
206  }
207  case MergeContacts::Keys:
208  addr.setKeys(mAddressList.at(selectedContactIndex).keys());
209  break;
210  }
211  }
212  }
213 }
QWidget::layout
QLayout * layout() const
KABMergeContacts::MergeContacts::FreeBusy
Definition: mergecontacts.h:50
QWidget
KABMergeContacts::MergeContactSelectListWidget::setContacts
void setContacts(MergeContacts::ConflictInformation conflictType, const KABC::Addressee::List &lst)
Definition: mergecontactselectlistwidget.cpp:48
KABMergeContacts::MergeContactSelectInformationWidget::MergeContactSelectInformationWidget
MergeContactSelectInformationWidget(QWidget *parent=0)
Definition: mergecontactselectinformationwidget.cpp:26
KABMergeContacts::MergeContacts::Departement
Definition: mergecontacts.h:46
KABMergeContacts::MergeContacts::Profession
Definition: mergecontacts.h:44
KABMergeContacts::MergeContactSelectInformationWidget::~MergeContactSelectInformationWidget
~MergeContactSelectInformationWidget()
Definition: mergecontactselectinformationwidget.cpp:34
KABMergeContacts::MergeContacts::Blog
Definition: mergecontacts.h:41
KABMergeContacts::MergeContacts::None
Definition: mergecontacts.h:33
KABMergeContacts::MergeContactSelectListWidget::verifySelectedInfo
bool verifySelectedInfo() const
Definition: mergecontactselectlistwidget.cpp:263
KABMergeContacts::MergeContactSelectListWidget::conflictType
MergeContacts::ConflictInformation conflictType() const
Definition: mergecontactselectlistwidget.cpp:258
KABMergeContacts::MergeContacts::Anniversary
Definition: mergecontacts.h:38
KABMergeContacts::MergeContactSelectListWidget
Definition: mergecontactselectlistwidget.h:32
KABMergeContacts::MergeContacts::Organization
Definition: mergecontacts.h:43
KABMergeContacts::MergeContacts::Photo
Definition: mergecontacts.h:36
KABMergeContacts::MergeContacts::Keys
Definition: mergecontacts.h:53
KABMergeContacts::MergeContactSelectInformationWidget::setContacts
void setContacts(MergeContacts::ConflictInformations conflictTypes, const Akonadi::Item::List &listItem)
Definition: mergecontactselectinformationwidget.cpp:39
KABMergeContacts::MergeContacts::ManagerName
Definition: mergecontacts.h:48
KABMergeContacts::MergeContacts::HomePage
Definition: mergecontacts.h:42
QWidget::setLayout
void setLayout(QLayout *layout)
mergecontactselectlistwidget.h
KABMergeContacts::MergeContacts::Logo
Definition: mergecontacts.h:37
KABMergeContacts::MergeContactSelectInformationWidget::createContact
void createContact(KABC::Addressee &addr)
Definition: mergecontactselectinformationwidget.cpp:129
KABMergeContacts::MergeContacts::FamilyName
Definition: mergecontacts.h:51
QVBoxLayout
QString
QLayout::setMargin
void setMargin(int margin)
QLayout::addWidget
void addWidget(QWidget *w)
KABMergeContacts::MergeContacts::Office
Definition: mergecontacts.h:47
KABMergeContacts::MergeContacts::Name
Definition: mergecontacts.h:39
KABMergeContacts::MergeContacts::NickName
Definition: mergecontacts.h:40
QLatin1String
KABMergeContacts::MergeContacts::ConflictInformation
ConflictInformation
Definition: mergecontacts.h:32
mergecontactselectinformationwidget.h
KABMergeContacts::MergeContactSelectInformationWidget::verifySelectedInfo
bool verifySelectedInfo() const
Definition: mergecontactselectinformationwidget.cpp:117
KABMergeContacts::MergeContacts::Title
Definition: mergecontacts.h:45
KABMergeContacts::MergeContacts::PartnerName
Definition: mergecontacts.h:52
KABMergeContacts::MergeContactSelectListWidget::selectedContact
int selectedContact() const
Definition: mergecontactselectlistwidget.cpp:253
KABMergeContacts::MergeContacts::Assistant
Definition: mergecontacts.h:49
KABMergeContacts::MergeContacts::Geo
Definition: mergecontacts.h:35
KABMergeContacts::MergeContacts::Birthday
Definition: mergecontacts.h:34
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