• 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
mergecontactselectlistwidget.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 "mergecontactselectlistwidget.h"
19 #include <KABC/Addressee>
20 #include <KLocalizedString>
21 #include <KGlobal>
22 #include <KLocale>
23 #include <QLabel>
24 #include <QListWidget>
25 #include <QVBoxLayout>
26 using namespace KABMergeContacts;
27 using namespace KABC;
28 
29 MergeContactSelectListWidget::MergeContactSelectListWidget(QWidget *parent)
30  : QWidget(parent),
31  mConflictType(MergeContacts::None)
32 {
33  QVBoxLayout *vbox = new QVBoxLayout;
34  setLayout(vbox);
35  mTitle = new QLabel;
36  mTitle->setObjectName(QLatin1String("title"));
37  vbox->addWidget(mTitle);
38  mSelectListWidget = new QListWidget;
39  mSelectListWidget->setObjectName(QLatin1String("listwidget"));
40  vbox->addWidget(mSelectListWidget);
41 }
42 
43 MergeContactSelectListWidget::~MergeContactSelectListWidget()
44 {
45 
46 }
47 
48 void MergeContactSelectListWidget::setContacts(MergeContacts::ConflictInformation conflictType, const KABC::Addressee::List &lst)
49 {
50  mConflictType = conflictType;
51  if (lst.isEmpty() || ( conflictType == MergeContacts::None) ) {
52  return;
53  }
54  updateTitle();
55  fillList(lst);
56 }
57 
58 void MergeContactSelectListWidget::updateTitle()
59 {
60  QString title;
61  switch(mConflictType) {
62  case MergeContacts::None:
63  qWarning()<<" MergeContacts::None used in updateTitle. It's a bug";
64  // it's not possible.
65  break;
66  case MergeContacts::Birthday:
67  title = Addressee::birthdayLabel();
68  break;
69  case MergeContacts::Geo:
70  title = Addressee::geoLabel();
71  break;
72  case MergeContacts::Photo:
73  title = Addressee::photoLabel();
74  break;
75  case MergeContacts::Logo:
76  title = Addressee::logoLabel();
77  break;
78  case MergeContacts::Anniversary:
79  title = i18nc( "The wedding anniversary of a contact", "Anniversary" );
80  break;
81  case MergeContacts::Name:
82  title = Addressee::nameLabel();
83  break;
84  case MergeContacts::NickName:
85  title = Addressee::nickNameLabel();
86  break;
87  case MergeContacts::Blog:
88  title = i18n( "Blog Feed" );
89  break;
90  case MergeContacts::HomePage:
91  title = QLatin1String("HomePage");
92  break;
93  case MergeContacts::Organization:
94  title = Addressee::organizationLabel();
95  break;
96  case MergeContacts::Profession:
97  title = i18n( "Profession" );
98  break;
99  case MergeContacts::Title:
100  title = Addressee::titleLabel();
101  break;
102  case MergeContacts::Departement:
103  title = Addressee::departmentLabel();
104  break;
105  case MergeContacts::Office:
106  title = i18n( "Office" );
107  break;
108  case MergeContacts::ManagerName:
109  title = i18n( "Manager" );
110  break;
111  case MergeContacts::Assistant:
112  title = i18n( "Assistant" );
113  break;
114  case MergeContacts::FreeBusy:
115  title = QLatin1String("FreeBusy");
116  break;
117  case MergeContacts::FamilyName:
118  title = Addressee::familyNameLabel();
119  break;
120  case MergeContacts::PartnerName:
121  title = i18n( "Spouse" );
122  break;
123  case MergeContacts::Keys:
124  title = QLatin1String("Keys");
125  break;
126  }
127 
128  mTitle->setText(title);
129 }
130 
131 void MergeContactSelectListWidget::addItem(const QString &str, const QIcon &icon)
132 {
133  if (str.isEmpty()) {
134  QListWidgetItem * item = new QListWidgetItem(mSelectListWidget);
135  item->setFlags(Qt::NoItemFlags);
136  //KF5 add i18n
137  item->setText(QLatin1String("(Undefined)"));
138  mSelectListWidget->addItem(item);
139  } else {
140  if (!icon.isNull()) {
141  QListWidgetItem * item = new QListWidgetItem(mSelectListWidget);
142  item->setText(str);
143  item->setIcon(icon);
144  mSelectListWidget->addItem(item);
145  } else {
146  mSelectListWidget->addItem(str);
147  }
148  }
149 }
150 
151 void MergeContactSelectListWidget::fillList(const KABC::Addressee::List &lst)
152 {
153  mSelectListWidget->clear();
154  qDebug()<<"mConflictType"<<mConflictType;
155  Q_FOREACH(const KABC::Addressee &addr, lst ) {
156  switch(mConflictType) {
157  case MergeContacts::None:
158  break;
159  case MergeContacts::Birthday: {
160  const QDate birdthDt = addr.birthday().date();
161  QString birdth;
162  if ( birdthDt.isValid() ) {
163  birdth = KGlobal::locale()->formatDate( birdthDt );
164  }
165  addItem(birdth);
166  break;
167  }
168  case MergeContacts::Geo: {
169  const Geo geo = addr.geo();
170  const QString str = QString::fromLatin1("%1-%2").arg(geo.latitude(), geo.longitude());
171  addItem(str);
172  break;
173  }
174  case MergeContacts::Photo:
175  //TODO fix when it's an url
176  addItem(QString(), QIcon(QPixmap::fromImage(addr.photo().data())));
177  //FIXME add icon ?
178  break;
179  case MergeContacts::Logo:
180  addItem(QString(), QIcon(QPixmap::fromImage(addr.logo().data())));
181  //FIXME add icon ?
182  break;
183  case MergeContacts::Anniversary: {
184  QString anniversary;
185  const QDate anniversaryDt = QDate::fromString( addr.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Anniversary" ) ), Qt::ISODate );
186  if ( anniversaryDt.isValid() ) {
187  anniversary = KGlobal::locale()->formatDate( anniversaryDt );
188  }
189  addItem(anniversary);
190  break;
191  }
192  case MergeContacts::Name:
193  addItem(addr.name());
194  break;
195  case MergeContacts::NickName:
196  addItem(addr.nickName());
197  break;
198  case MergeContacts::Blog: {
199  const QString newBlog = addr.custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "BlogFeed" ));
200  addItem(newBlog);
201  break;
202  }
203  case MergeContacts::HomePage:
204  addItem(addr.url().prettyUrl());
205  break;
206  case MergeContacts::Organization:
207  addItem(addr.organization());
208  break;
209  case MergeContacts::Profession: {
210  const QString newBlog = addr.custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Profession" ));
211  addItem(newBlog);
212  break;
213  }
214  case MergeContacts::Title:
215  addItem(addr.title());
216  break;
217  case MergeContacts::Departement:
218  addItem(addr.department());
219  break;
220  case MergeContacts::Office: {
221  const QString newBlog = addr.custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Office" ));
222  addItem(newBlog);
223  break;
224  }
225  case MergeContacts::ManagerName: {
226  const QString newBlog = addr.custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-ManagersName" ));
227  addItem(newBlog);
228  break;
229  }
230  case MergeContacts::Assistant: {
231  const QString newBlog = addr.custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-AssistantsName" ));
232  addItem(newBlog);
233  break;
234  }
235  case MergeContacts::FreeBusy:
236  //FIXME
237  break;
238  case MergeContacts::FamilyName:
239  addItem(addr.familyName());
240  break;
241  case MergeContacts::PartnerName: {
242  const QString newBlog = addr.custom(QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-SpousesName" ));
243  addItem(newBlog);
244  break;
245  }
246  case MergeContacts::Keys:
247  //TODO
248  break;
249  }
250  }
251 }
252 
253 int MergeContactSelectListWidget::selectedContact() const
254 {
255  return mSelectListWidget->currentRow();
256 }
257 
258 MergeContacts::ConflictInformation MergeContactSelectListWidget::conflictType() const
259 {
260  return mConflictType;
261 }
262 
263 bool MergeContactSelectListWidget::verifySelectedInfo() const
264 {
265  return (selectedContact() != -1);
266 }
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::MergeContacts::Departement
Definition: mergecontacts.h:46
QListWidgetItem
KABMergeContacts::MergeContacts::Profession
Definition: mergecontacts.h:44
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
KABMergeContacts::MergeContacts::Blog
Definition: mergecontacts.h:41
KABMergeContacts::MergeContacts::None
Definition: mergecontacts.h:33
KABMergeContacts::MergeContactSelectListWidget::verifySelectedInfo
bool verifySelectedInfo() const
Definition: mergecontactselectlistwidget.cpp:263
QListWidget
KABMergeContacts::MergeContactSelectListWidget::conflictType
MergeContacts::ConflictInformation conflictType() const
Definition: mergecontactselectlistwidget.cpp:258
KABMergeContacts::MergeContacts
Definition: mergecontacts.h:26
QListWidget::addItem
void addItem(const QString &label)
KABMergeContacts::MergeContacts::Anniversary
Definition: mergecontacts.h:38
KABMergeContacts::MergeContacts::Organization
Definition: mergecontacts.h:43
KABMergeContacts::MergeContacts::Photo
Definition: mergecontacts.h:36
KABMergeContacts::MergeContacts::Keys
Definition: mergecontacts.h:53
QDate::fromString
QDate fromString(const QString &string, Qt::DateFormat format)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
KABMergeContacts::MergeContacts::ManagerName
Definition: mergecontacts.h:48
KABMergeContacts::MergeContacts::HomePage
Definition: mergecontacts.h:42
QWidget::setLayout
void setLayout(QLayout *layout)
mergecontactselectlistwidget.h
QListWidget::clear
void clear()
KABMergeContacts::MergeContacts::Logo
Definition: mergecontacts.h:37
QListWidgetItem::setFlags
void setFlags(QFlags< Qt::ItemFlag > flags)
QObject::setObjectName
void setObjectName(const QString &name)
QString::isEmpty
bool isEmpty() const
KABMergeContacts::MergeContacts::FamilyName
Definition: mergecontacts.h:51
QDate::isValid
bool isValid() const
KABMergeContacts::MergeContactSelectListWidget::MergeContactSelectListWidget
MergeContactSelectListWidget(QWidget *parent=0)
Definition: mergecontactselectlistwidget.cpp:29
QVBoxLayout
QDate
QLabel::setText
void setText(const QString &)
QString
QListWidget::currentRow
currentRow
QListWidgetItem::setIcon
void setIcon(const QIcon &icon)
KABMergeContacts::MergeContacts::Office
Definition: mergecontacts.h:47
KABMergeContacts::MergeContacts::Name
Definition: mergecontacts.h:39
KABMergeContacts::MergeContacts::NickName
Definition: mergecontacts.h:40
QLatin1String
QIcon::isNull
bool isNull() const
KABMergeContacts::MergeContacts::ConflictInformation
ConflictInformation
Definition: mergecontacts.h:32
KABMergeContacts::MergeContacts::Title
Definition: mergecontacts.h:45
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KABMergeContacts::MergeContacts::PartnerName
Definition: mergecontacts.h:52
KABMergeContacts::MergeContactSelectListWidget::selectedContact
int selectedContact() const
Definition: mergecontactselectlistwidget.cpp:253
KABMergeContacts::MergeContactSelectListWidget::~MergeContactSelectListWidget
~MergeContactSelectListWidget()
Definition: mergecontactselectlistwidget.cpp:43
QLabel
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
KABMergeContacts::MergeContacts::Assistant
Definition: mergecontacts.h:49
KABMergeContacts::MergeContacts::Geo
Definition: mergecontacts.h:35
KABMergeContacts::MergeContacts::Birthday
Definition: mergecontacts.h:34
QIcon
QListWidgetItem::setText
void setText(const QString &text)
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