• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi/contact

  • akonadi
  • contact
  • editor
contacteditorwidget.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "contacteditorwidget.h"
23 
24 #include "addresseditwidget.h"
25 #include "categorieseditwidget.h"
26 #include "contacteditorpageplugin.h"
27 #include "contactmetadata_p.h"
28 #include "customfieldseditwidget.h"
29 #include "dateeditwidget.h"
30 #include "displaynameeditwidget.h"
31 #include "emaileditwidget.h"
32 #include "freebusyeditwidget.h"
33 #include "geoeditwidget.h"
34 #include "imagewidget.h"
35 #include "imeditwidget.h"
36 #include "nameeditwidget.h"
37 #include "phoneeditwidget.h"
38 #include "soundeditwidget.h"
39 
40 #include <kconfig.h>
41 #include <kconfiggroup.h>
42 #include <klineedit.h>
43 #include <klocalizedstring.h>
44 #include <kstandarddirs.h>
45 #include <ktabwidget.h>
46 #include <ktextedit.h>
47 
48 #include <QtCore/QDirIterator>
49 #include <QtCore/QPluginLoader>
50 #include <QGroupBox>
51 #include <QLabel>
52 #include <QCheckBox>
53 #include <QVBoxLayout>
54 
55 class ContactEditorWidget::Private
56 {
57  public:
58  Private( ContactEditorWidget::DisplayMode displayMode, ContactEditorWidget *parent )
59  : mDisplayMode(displayMode), mParent( parent ), mCustomFieldsWidget(0)
60  {
61  }
62 
63  void initGui();
64  void initGuiContactTab();
65  void initGuiLocationTab();
66  void initGuiBusinessTab();
67  void initGuiPersonalTab();
68  void initGuiNotesTab();
69  void initGuiCustomFieldsTab();
70 
71  void loadCustomPages();
72 
73  QString loadCustom( const KABC::Addressee &contact, const QString &key ) const;
74  void storeCustom( KABC::Addressee &contact, const QString &key, const QString &value ) const;
75 
76  ContactEditorWidget::DisplayMode mDisplayMode;
77  ContactEditorWidget *mParent;
78  KTabWidget *mTabWidget;
79 
80  // widgets from name group
81  NameEditWidget *mNameWidget;
82  ImageWidget *mPhotoWidget;
83  DisplayNameEditWidget *mDisplayNameWidget;
84  KLineEdit *mNickNameWidget;
85  SoundEditWidget *mPronunciationWidget;
86 
87  // widgets from Internet group
88  EmailEditWidget *mEmailWidget;
89  KLineEdit *mHomepageWidget;
90  KLineEdit *mBlogWidget;
91  IMEditWidget *mIMWidget;
92 
93  // widgets from phones group
94  PhoneEditWidget *mPhonesWidget;
95 
96  CategoriesEditWidget *mCategoriesWidget;
97 
98  KComboBox* mMailPreferFormatting;
99  QCheckBox *mAllowRemoteContent;
100 
101  // widgets from addresses group
102  AddressEditWidget *mAddressesWidget;
103 
104  // widgets from coordinates group
105  GeoEditWidget *mCoordinatesWidget;
106 
107  // widgets from general group
108  ImageWidget *mLogoWidget;
109  KLineEdit *mOrganizationWidget;
110  KLineEdit *mProfessionWidget;
111  KLineEdit *mTitleWidget;
112  KLineEdit *mDepartmentWidget;
113  KLineEdit *mOfficeWidget;
114  KLineEdit *mManagerWidget;
115  KLineEdit *mAssistantWidget;
116 
117  // widgets from groupware group
118  FreeBusyEditWidget *mFreeBusyWidget;
119 
120  // widgets from notes group
121  KTextEdit *mNotesWidget;
122 
123  // widgets from dates group
124  DateEditWidget *mBirthdateWidget;
125  DateEditWidget *mAnniversaryWidget;
126 
127  // widgets from family group
128  KLineEdit *mPartnerWidget;
129 
130  // widgets from custom fields group
131  CustomFieldsEditWidget *mCustomFieldsWidget;
132 
133  // custom editor pages
134  QList<Akonadi::ContactEditorPagePlugin*> mCustomPages;
135 };
136 
137 void ContactEditorWidget::Private::initGui()
138 {
139  QVBoxLayout *layout = new QVBoxLayout( mParent );
140  layout->setMargin( 0 );
141 
142  mTabWidget = new KTabWidget( mParent );
143  layout->addWidget( mTabWidget );
144 
145  initGuiContactTab();
146  initGuiLocationTab();
147  initGuiBusinessTab();
148  initGuiPersonalTab();
149  initGuiNotesTab();
150  if (mDisplayMode == FullMode) {
151  initGuiCustomFieldsTab();
152  loadCustomPages();
153  }
154 }
155 
156 void ContactEditorWidget::Private::initGuiContactTab()
157 {
158  QWidget *widget = new QWidget;
159  QGridLayout *layout = new QGridLayout( widget );
160 
161  mTabWidget->addTab( widget, i18nc( "@title:tab", "Contact" ) );
162 
163  QGroupBox *nameGroupBox = new QGroupBox( i18nc( "@title:group Name related properties of a contact", "Name" ) );
164  QGroupBox *internetGroupBox = new QGroupBox( i18nc( "@title:group", "Internet" ) );
165  QGroupBox *phonesGroupBox = new QGroupBox( i18nc( "@title:group", "Phones" ) );
166 
167  nameGroupBox->setMinimumSize(320,200);
168  layout->addWidget( nameGroupBox, 0, 0 );
169  layout->addWidget( internetGroupBox, 0, 1 );
170  layout->addWidget( phonesGroupBox, 1, 0, 4, 1 );
171 
172  QGridLayout *nameLayout = new QGridLayout( nameGroupBox );
173  QGridLayout *internetLayout = new QGridLayout( internetGroupBox );
174  QGridLayout *phonesLayout = new QGridLayout( phonesGroupBox );
175 
176  QLabel *label = 0;
177 
178  // setup name group box
179  label = new QLabel( i18nc( "@label The name of a contact", "Name:" ) );
180  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
181  nameLayout->addWidget( label, 0, 0 );
182 
183  mNameWidget = new NameEditWidget;
184  label->setBuddy( mNameWidget );
185  nameLayout->addWidget( mNameWidget, 0, 1 );
186 
187  mPhotoWidget = new ImageWidget( ImageWidget::Photo );
188  nameLayout->addWidget( mPhotoWidget, 0, 2, 4, 1 );
189 
190  label = new QLabel( i18nc( "@label The display name of a contact", "Display:" ) );
191  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
192  nameLayout->addWidget( label, 1, 0 );
193 
194  mDisplayNameWidget = new DisplayNameEditWidget;
195  label->setBuddy( mDisplayNameWidget );
196  nameLayout->addWidget( mDisplayNameWidget, 1, 1 );
197 
198  label = new QLabel( i18nc( "@label The nickname of a contact", "Nickname:" ) );
199  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
200  nameLayout->addWidget( label, 2, 0 );
201 
202  mNickNameWidget = new KLineEdit;
203  label->setBuddy( mNickNameWidget );
204  nameLayout->addWidget( mNickNameWidget, 2, 1 );
205 
206  label = new QLabel( i18nc( "@label The pronunciation of a contact's name", "Pronunciation:" ) );
207  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
208  nameLayout->addWidget( label, 3, 0 );
209 
210  mPronunciationWidget = new SoundEditWidget;
211  label->setBuddy( mPronunciationWidget );
212  nameLayout->addWidget( mPronunciationWidget, 3, 1 );
213 
214  nameLayout->setRowStretch( 4, 1 );
215 
216  // setup Internet group box
217  label = new QLabel( i18nc( "@label The email address of a contact", "Email:" ) );
218  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
219  internetLayout->addWidget( label, 0, 0 );
220 
221  mEmailWidget = new EmailEditWidget;
222  label->setBuddy( mEmailWidget );
223  internetLayout->addWidget( mEmailWidget, 0, 1 );
224 
225  label = new QLabel( i18nc( "@label The homepage URL of a contact", "Homepage:" ) );
226  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
227  internetLayout->addWidget( label, 1, 0 );
228 
229  mHomepageWidget = new KLineEdit;
230  label->setBuddy( mHomepageWidget );
231  internetLayout->addWidget( mHomepageWidget, 1, 1 );
232 
233  label = new QLabel( i18nc( "@label The blog URL of a contact", "Blog:" ) );
234  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
235  internetLayout->addWidget( label, 2, 0 );
236 
237  mBlogWidget = new KLineEdit;
238  label->setBuddy( mBlogWidget );
239  internetLayout->addWidget( mBlogWidget, 2, 1 );
240 
241  label = new QLabel( i18nc( "@label The instant messaging address of a contact", "Messaging:" ) );
242  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
243  internetLayout->addWidget( label, 3, 0 );
244 
245  mIMWidget = new IMEditWidget;
246  label->setBuddy( mIMWidget );
247  internetLayout->addWidget( mIMWidget, 3, 1 );
248 
249  internetLayout->setRowStretch( 4, 1 );
250 
251  // setup phones group box
252  mPhonesWidget = new PhoneEditWidget;
253  phonesLayout->addWidget( mPhonesWidget, 0, 0 );
254 
255  //phonesLayout->setRowStretch( 1, 1 );
256 
257  // setup categories section
258  QHBoxLayout *categoriesLayout = new QHBoxLayout;
259  label = new QLabel( i18nc( "@label The categories of a contact", "Categories:" ) );
260  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
261 
262  mCategoriesWidget = new CategoriesEditWidget;
263  label->setBuddy( mCategoriesWidget );
264 
265  categoriesLayout->addWidget( label );
266  categoriesLayout->addWidget( mCategoriesWidget );
267 
268  layout->addLayout( categoriesLayout, 1, 1 );
269 
270  QGroupBox *receivedMessageGroupBox = new QGroupBox( i18n("Messages") );
271  layout->addWidget( receivedMessageGroupBox, 2, 1 );
272 
273  QVBoxLayout *vbox = new QVBoxLayout(receivedMessageGroupBox);
274 
275  QHBoxLayout *mailPreferFormattingLayout = new QHBoxLayout;
276  label = new QLabel( i18n( "Show messages received from this contact as:" ) );
277  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
278  mMailPreferFormatting = new KComboBox;
279  label->setBuddy( mMailPreferFormatting );
280  QStringList listFormat;
281  listFormat << i18n( "Default" ) << i18n( "Plain Text" ) << i18n( "HTML" );
282  mMailPreferFormatting->addItems( listFormat );
283  mailPreferFormattingLayout->addWidget( label );
284  mailPreferFormattingLayout->addWidget( mMailPreferFormatting );
285 
286 
287  vbox->addLayout( mailPreferFormattingLayout );
288 
289  mAllowRemoteContent = new QCheckBox( i18n( "Allow remote content in received HTML messages" ) );
290  vbox->addWidget( mAllowRemoteContent );
291 
292  layout->setRowStretch( 4,1 );
293 }
294 
295 void ContactEditorWidget::Private::initGuiLocationTab()
296 {
297  QWidget *widget = new QWidget;
298  QHBoxLayout *layout = new QHBoxLayout( widget );
299 
300  mTabWidget->addTab( widget, i18nc( "@title:tab", "Location" ) );
301 
302  QGroupBox *addressesGroupBox = new QGroupBox( i18nc( "@title:group", "Addresses" ) );
303  QGroupBox *coordinatesGroupBox = new QGroupBox( i18nc( "@title:group", "Coordinates" ) );
304 
305  layout->addWidget( addressesGroupBox );
306  layout->addWidget( coordinatesGroupBox );
307 
308  QGridLayout *addressesLayout = new QGridLayout( addressesGroupBox );
309  QGridLayout *coordinatesLayout = new QGridLayout( coordinatesGroupBox );
310 
311  // setup addresses group box
312  mAddressesWidget = new AddressEditWidget( addressesGroupBox );
313  mAddressesWidget->setMinimumHeight( 200 );
314  addressesLayout->addWidget( mAddressesWidget, 0, 0 );
315  addressesLayout->setRowStretch( 1, 1 );
316 
317  // setup coordinates group box
318  mCoordinatesWidget = new GeoEditWidget;
319  coordinatesLayout->addWidget( mCoordinatesWidget, 0, 0 );
320  coordinatesLayout->setRowStretch( 1, 1 );
321 }
322 
323 void ContactEditorWidget::Private::initGuiBusinessTab()
324 {
325  QWidget *widget = new QWidget;
326  QVBoxLayout *layout = new QVBoxLayout( widget );
327 
328  mTabWidget->addTab( widget, i18nc( "@title:tab", "Business" ) );
329 
330  QGroupBox *generalGroupBox = new QGroupBox( i18nc( "@title:group General properties of a contact", "General" ) );
331  QGroupBox *groupwareGroupBox = new QGroupBox( i18nc( "@title:group", "Groupware" ) );
332 
333  layout->addWidget( generalGroupBox );
334  layout->addWidget( groupwareGroupBox );
335 
336  QGridLayout *generalLayout = new QGridLayout( generalGroupBox );
337  QGridLayout *groupwareLayout = new QGridLayout( groupwareGroupBox );
338 
339  QLabel *label = 0;
340 
341  // setup general group box
342  mLogoWidget = new ImageWidget( ImageWidget::Logo );
343  generalLayout->addWidget( mLogoWidget, 0, 2, 6, 1, Qt::AlignTop );
344 
345  label = new QLabel( i18nc( "@label The organization of a contact", "Organization:" ) );
346  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
347  generalLayout->addWidget( label, 0, 0 );
348 
349  mOrganizationWidget = new KLineEdit;
350  label->setBuddy( mOrganizationWidget );
351  generalLayout->addWidget( mOrganizationWidget, 0, 1 );
352 
353  label = new QLabel( i18nc( "@label The profession of a contact", "Profession:" ) );
354  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
355  generalLayout->addWidget( label, 1, 0 );
356 
357  mProfessionWidget = new KLineEdit;
358  label->setBuddy( mProfessionWidget );
359  generalLayout->addWidget( mProfessionWidget, 1, 1 );
360 
361  label = new QLabel( i18nc( "@label The title of a contact", "Title:" ) );
362  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
363  generalLayout->addWidget( label, 2, 0 );
364 
365  mTitleWidget = new KLineEdit;
366  label->setBuddy( mTitleWidget );
367  generalLayout->addWidget( mTitleWidget , 2, 1 );
368 
369  label = new QLabel( i18nc( "@label The department of a contact", "Department:" ) );
370  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
371  generalLayout->addWidget( label, 3, 0 );
372 
373  mDepartmentWidget = new KLineEdit;
374  label->setBuddy( mDepartmentWidget );
375  generalLayout->addWidget( mDepartmentWidget, 3, 1 );
376 
377  label = new QLabel( i18nc( "@label The office of a contact", "Office:" ) );
378  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
379  generalLayout->addWidget( label, 4, 0 );
380 
381  mOfficeWidget = new KLineEdit;
382  label->setBuddy( mOfficeWidget );
383  generalLayout->addWidget( mOfficeWidget, 4, 1 );
384 
385  label = new QLabel( i18nc( "@label The manager's name of a contact", "Manager's name:" ) );
386  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
387  generalLayout->addWidget( label, 5, 0 );
388 
389  mManagerWidget = new KLineEdit;
390  label->setBuddy( mManagerWidget );
391  generalLayout->addWidget( mManagerWidget, 5, 1 );
392 
393  label = new QLabel( i18nc( "@label The assistant's name of a contact", "Assistant's name:" ) );
394  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
395  generalLayout->addWidget( label, 6, 0 );
396 
397  mAssistantWidget = new KLineEdit;
398  label->setBuddy( mAssistantWidget );
399  generalLayout->addWidget( mAssistantWidget, 6, 1 );
400 
401  // setup groupware group box
402  label = new QLabel( i18nc( "@label The free/busy information of a contact", "Free/Busy:" ) );
403  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
404  groupwareLayout->addWidget( label, 0, 0 );
405 
406  mFreeBusyWidget = new FreeBusyEditWidget;
407  label->setBuddy( mFreeBusyWidget );
408  groupwareLayout->addWidget( mFreeBusyWidget, 0, 1 );
409  groupwareLayout->setRowStretch( 1, 1 );
410 }
411 
412 void ContactEditorWidget::Private::initGuiPersonalTab()
413 {
414  QWidget *widget = new QWidget;
415  QVBoxLayout *layout = new QVBoxLayout( widget );
416 
417  mTabWidget->addTab( widget, i18nc( "@title:tab Personal properties of a contact", "Personal" ) );
418 
419  QGroupBox *datesGroupBox = new QGroupBox( i18nc( "@title:group Date related properties of a contact", "Dates" ) );
420  QGroupBox *familyGroupBox = new QGroupBox( i18nc( "@title:group Family related properties of a contact", "Family" ) );
421 
422  layout->addWidget( datesGroupBox );
423  layout->addWidget( familyGroupBox );
424 
425  QGridLayout *datesLayout = new QGridLayout( datesGroupBox );
426  QGridLayout *familyLayout = new QGridLayout( familyGroupBox );
427 
428  QLabel *label = 0;
429 
430  // setup dates group box
431  label = new QLabel( i18nc( "@label The birthdate of a contact", "Birthdate:" ) );
432  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
433  datesLayout->addWidget( label, 0, 0 );
434 
435  mBirthdateWidget = new DateEditWidget( DateEditWidget::Birthday );
436  label->setBuddy( mBirthdateWidget );
437  datesLayout->addWidget( mBirthdateWidget, 0, 1 );
438 
439  label = new QLabel( i18nc( "@label The wedding anniversary of a contact", "Anniversary:" ) );
440  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
441  datesLayout->addWidget( label, 1, 0 );
442 
443  mAnniversaryWidget = new DateEditWidget( DateEditWidget::Anniversary );
444  label->setBuddy( mAnniversaryWidget );
445  datesLayout->addWidget( mAnniversaryWidget, 1, 1 );
446 
447  datesLayout->setRowStretch( 2, 1 );
448  datesLayout->setColumnStretch( 1, 1 );
449 
450  // widgets from family group
451  label = new QLabel( i18nc( "@label The partner's name of a contact", "Partner's name:" ) );
452  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
453  familyLayout->addWidget( label, 0, 0 );
454 
455  mPartnerWidget = new KLineEdit;
456  label->setBuddy( mPartnerWidget );
457  familyLayout->addWidget( mPartnerWidget, 0, 1 );
458 
459  familyLayout->setRowStretch( 1, 1 );
460 }
461 
462 void ContactEditorWidget::Private::initGuiNotesTab()
463 {
464  QWidget *widget = new QWidget;
465  QVBoxLayout *layout = new QVBoxLayout( widget );
466 
467  mTabWidget->addTab( widget, i18nc( "@title:tab", "Notes" ) );
468 
469  mNotesWidget = new KTextEdit;
470  mNotesWidget->setAcceptRichText(false);
471  layout->addWidget( mNotesWidget );
472 }
473 
474 void ContactEditorWidget::Private::initGuiCustomFieldsTab()
475 {
476  QWidget *widget = new QWidget;
477  QVBoxLayout *layout = new QVBoxLayout( widget );
478 
479  mTabWidget->addTab( widget, i18nc( "@title:tab", "Custom Fields" ) );
480 
481  mCustomFieldsWidget = new CustomFieldsEditWidget;
482  layout->addWidget( mCustomFieldsWidget );
483 }
484 
485 void ContactEditorWidget::Private::loadCustomPages()
486 {
487  qDeleteAll( mCustomPages );
488  mCustomPages.clear();
489 
490  const QString pluginDirectory = KStandardDirs::locate( "lib", QLatin1String( "akonadi/contact/editorpageplugins/" ) );
491  QDirIterator it( pluginDirectory, QDir::Files );
492  while ( it.hasNext() ) {
493  QPluginLoader loader( it.next() );
494  if ( !loader.load() ) {
495  continue;
496  }
497 
498  Akonadi::ContactEditorPagePlugin *plugin = qobject_cast<Akonadi::ContactEditorPagePlugin*>( loader.instance() );
499  if ( !plugin ) {
500  continue;
501  }
502 
503  mCustomPages.append( plugin );
504  }
505 
506  foreach ( Akonadi::ContactEditorPagePlugin *plugin, mCustomPages ) {
507  mTabWidget->addTab( plugin, plugin->title() );
508  }
509 }
510 
511 QString ContactEditorWidget::Private::loadCustom( const KABC::Addressee &contact, const QString &key ) const
512 {
513  return contact.custom( QLatin1String( "KADDRESSBOOK" ), key );
514 }
515 
516 void ContactEditorWidget::Private::storeCustom( KABC::Addressee &contact, const QString &key, const QString &value ) const
517 {
518  if ( value.isEmpty() ) {
519  contact.removeCustom( QLatin1String( "KADDRESSBOOK" ), key );
520  } else {
521  contact.insertCustom( QLatin1String( "KADDRESSBOOK" ), key, value );
522  }
523 }
524 
525 ContactEditorWidget::ContactEditorWidget( QWidget* )
526  : d( new Private( FullMode, this ) )
527 {
528  d->initGui();
529 
530  connect( d->mNameWidget, SIGNAL(nameChanged(KABC::Addressee)),
531  d->mDisplayNameWidget, SLOT(changeName(KABC::Addressee)) );
532  connect( d->mOrganizationWidget, SIGNAL(textChanged(QString)),
533  d->mDisplayNameWidget, SLOT(changeOrganization(QString)) );
534 }
535 
536 ContactEditorWidget::ContactEditorWidget( ContactEditorWidget::DisplayMode displayMode, QWidget * )
537  : d( new Private( displayMode, this ) )
538 {
539  d->initGui();
540 
541  connect( d->mNameWidget, SIGNAL(nameChanged(KABC::Addressee)),
542  d->mDisplayNameWidget, SLOT(changeName(KABC::Addressee)) );
543  connect( d->mOrganizationWidget, SIGNAL(textChanged(QString)),
544  d->mDisplayNameWidget, SLOT(changeOrganization(QString)) );
545 }
546 
547 ContactEditorWidget::~ContactEditorWidget()
548 {
549  delete d;
550 }
551 
552 void ContactEditorWidget::loadContact( const KABC::Addressee &contact, const Akonadi::ContactMetaData &metaData )
553 {
554  // name group
555  d->mPhotoWidget->loadContact( contact );
556  d->mNameWidget->loadContact( contact );
557  d->mDisplayNameWidget->loadContact( contact );
558  d->mNickNameWidget->setText( contact.nickName() );
559  d->mPronunciationWidget->loadContact( contact );
560 
561  // Internet group
562  d->mEmailWidget->loadContact( contact );
563  d->mHomepageWidget->setUrl( contact.url() );
564  d->mBlogWidget->setText( d->loadCustom( contact, QLatin1String( "BlogFeed" ) ) );
565  d->mIMWidget->loadContact( contact );
566 
567  // phones group
568  d->mPhonesWidget->loadContact( contact );
569 
570  // categories section
571  d->mCategoriesWidget->loadContact( contact );
572 
573  const QString mailPreferedFormatting = d->loadCustom( contact, QLatin1String( "MailPreferedFormatting" ) );
574  if ( mailPreferedFormatting.isEmpty() ) {
575  d->mMailPreferFormatting->setCurrentIndex( 0 );
576  } else if ( mailPreferedFormatting == QLatin1String( "TEXT" ) ) {
577  d->mMailPreferFormatting->setCurrentIndex( 1 );
578  } else if ( mailPreferedFormatting == QLatin1String( "HTML" ) ) {
579  d->mMailPreferFormatting->setCurrentIndex( 2 );
580  } else {
581  d->mMailPreferFormatting->setCurrentIndex( 0 );
582  }
583 
584  const QString mailAllowToRemoteContent = d->loadCustom( contact, QLatin1String( "MailAllowToRemoteContent" ) );
585  d->mAllowRemoteContent->setChecked( mailAllowToRemoteContent == QLatin1String( "TRUE" ) );
586 
587  // address group
588  d->mAddressesWidget->loadContact( contact );
589 
590  // coordinates group
591  d->mCoordinatesWidget->loadContact( contact );
592 
593  // general group
594  d->mLogoWidget->loadContact( contact );
595  d->mOrganizationWidget->setText( contact.organization() );
596  d->mProfessionWidget->setText( d->loadCustom( contact, QLatin1String( "X-Profession" ) ) );
597  d->mTitleWidget->setText( contact.title() );
598  d->mDepartmentWidget->setText( contact.department() );
599  d->mOfficeWidget->setText( d->loadCustom( contact, QLatin1String( "X-Office" ) ) );
600  d->mManagerWidget->setText( d->loadCustom( contact, QLatin1String( "X-ManagersName" ) ) );
601  d->mAssistantWidget->setText( d->loadCustom( contact, QLatin1String( "X-AssistantsName" ) ) );
602 
603  // groupware group
604  d->mFreeBusyWidget->loadContact( contact );
605 
606  // notes group
607  d->mNotesWidget->setPlainText( contact.note() );
608 
609  // dates group
610  d->mBirthdateWidget->setDate( contact.birthday().date() );
611  d->mAnniversaryWidget->setDate( QDate::fromString( d->loadCustom( contact, QLatin1String( "X-Anniversary" ) ),
612  Qt::ISODate ) );
613 
614  // family group
615  d->mPartnerWidget->setText( d->loadCustom( contact, QLatin1String( "X-SpousesName" ) ) );
616 
617  d->mDisplayNameWidget->setDisplayType( (DisplayNameEditWidget::DisplayType)metaData.displayNameMode() );
618 
619  if (d->mDisplayMode == FullMode) {
620  // custom fields group
621  d->mCustomFieldsWidget->setLocalCustomFieldDescriptions( metaData.customFieldDescriptions() );
622  d->mCustomFieldsWidget->loadContact( contact );
623 
624  // custom pages
625  foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) {
626  plugin->loadContact( contact );
627  }
628  }
629 }
630 
631 void ContactEditorWidget::storeContact( KABC::Addressee &contact, Akonadi::ContactMetaData &metaData ) const
632 {
633  // name group
634  d->mPhotoWidget->storeContact( contact );
635  d->mNameWidget->storeContact( contact );
636  d->mDisplayNameWidget->storeContact( contact );
637  contact.setNickName( d->mNickNameWidget->text().trimmed() );
638  d->mPronunciationWidget->storeContact( contact );
639 
640  // Internet group
641  d->mEmailWidget->storeContact( contact );
642  contact.setUrl( KUrl( d->mHomepageWidget->text().trimmed() ) );
643  d->storeCustom( contact, QLatin1String( "BlogFeed" ), d->mBlogWidget->text().trimmed() );
644  d->mIMWidget->storeContact( contact );
645 
646  // phones group
647  d->mPhonesWidget->storeContact( contact );
648 
649  // categories section
650  d->mCategoriesWidget->storeContact( contact );
651 
652  QString mailPreferedFormatting;
653  const int index = d->mMailPreferFormatting->currentIndex();
654  if ( index == 0 ) {
655  //Nothing => remove custom variable
656  } else if ( index == 1 ) {
657  mailPreferedFormatting = QLatin1String( "TEXT" );
658  } else if ( index == 2 ) {
659  mailPreferedFormatting = QLatin1String( "HTML" );
660  }
661  d->storeCustom( contact, QLatin1String( "MailPreferedFormatting" ), mailPreferedFormatting );
662 
663  QString mailAllowToRemoteContent;
664  if ( d->mAllowRemoteContent->isChecked() ) {
665  mailAllowToRemoteContent = QLatin1String( "TRUE" );
666  }
667  d->storeCustom( contact, QLatin1String( "MailAllowToRemoteContent" ), mailAllowToRemoteContent );
668 
669  // address group
670  d->mAddressesWidget->storeContact( contact );
671 
672  // coordinates group
673  d->mCoordinatesWidget->storeContact( contact );
674 
675  // general group
676  d->mLogoWidget->storeContact( contact );
677  contact.setOrganization( d->mOrganizationWidget->text() );
678  d->storeCustom( contact, QLatin1String( "X-Profession" ), d->mProfessionWidget->text().trimmed() );
679  contact.setTitle( d->mTitleWidget->text().trimmed() );
680  contact.setDepartment( d->mDepartmentWidget->text().trimmed() );
681  d->storeCustom( contact, QLatin1String( "X-Office" ), d->mOfficeWidget->text().trimmed() );
682  d->storeCustom( contact, QLatin1String( "X-ManagersName" ), d->mManagerWidget->text().trimmed() );
683  d->storeCustom( contact, QLatin1String( "X-AssistantsName" ), d->mAssistantWidget->text().trimmed() );
684 
685  // groupware group
686  d->mFreeBusyWidget->storeContact( contact );
687 
688  // notes group
689  contact.setNote( d->mNotesWidget->toPlainText() );
690 
691  // dates group
692  QDateTime birthday = QDateTime( d->mBirthdateWidget->date(), QTime(), contact.birthday().timeSpec() );
693  // This is needed because the constructor above sets the time component
694  // of the QDateTime to midnight. We want it to stay invalid.
695  birthday.setTime( QTime() );
696 
697  contact.setBirthday( birthday );
698  d->storeCustom( contact, QLatin1String( "X-Anniversary" ), d->mAnniversaryWidget->date().toString( Qt::ISODate ) );
699 
700  // family group
701  d->storeCustom( contact, QLatin1String( "X-SpousesName" ), d->mPartnerWidget->text().trimmed() );
702 
703  if (d->mDisplayMode == FullMode) {
704  // custom fields group
705  d->mCustomFieldsWidget->storeContact( contact );
706  metaData.setCustomFieldDescriptions( d->mCustomFieldsWidget->localCustomFieldDescriptions() );
707 
708  metaData.setDisplayNameMode( d->mDisplayNameWidget->displayType() );
709 
710  // custom pages
711  foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) {
712  plugin->storeContact( contact );
713  }
714  }
715 }
716 
717 void ContactEditorWidget::setReadOnly( bool readOnly )
718 {
719  // widgets from name group
720  d->mNameWidget->setReadOnly( readOnly );
721  d->mPhotoWidget->setReadOnly( readOnly );
722  d->mDisplayNameWidget->setReadOnly( readOnly );
723  d->mNickNameWidget->setReadOnly( readOnly );
724  d->mPronunciationWidget->setReadOnly( readOnly );
725 
726  // widgets from Internet group
727  d->mEmailWidget->setReadOnly( readOnly );
728  d->mHomepageWidget->setReadOnly( readOnly );
729  d->mBlogWidget->setReadOnly( readOnly );
730  d->mIMWidget->setReadOnly( readOnly );
731 
732  // widgets from phones group
733  d->mPhonesWidget->setReadOnly( readOnly );
734 
735  // widgets from categories section
736  d->mCategoriesWidget->setReadOnly( readOnly );
737 
738  // Preferred Mail formatting option
739  d->mMailPreferFormatting->setEnabled( !readOnly );
740  d->mAllowRemoteContent->setEnabled( !readOnly );
741 
742  // widgets from addresses group
743  d->mAddressesWidget->setReadOnly( readOnly );
744 
745  // widgets from coordinates group
746  d->mCoordinatesWidget->setReadOnly( readOnly );
747 
748  // widgets from general group
749  d->mLogoWidget->setReadOnly( readOnly );
750  d->mOrganizationWidget->setReadOnly( readOnly );
751  d->mProfessionWidget->setReadOnly( readOnly );
752  d->mTitleWidget->setReadOnly( readOnly );
753  d->mDepartmentWidget->setReadOnly( readOnly );
754  d->mOfficeWidget->setReadOnly( readOnly );
755  d->mManagerWidget->setReadOnly( readOnly );
756  d->mAssistantWidget->setReadOnly( readOnly );
757 
758  // widgets from groupware group
759  d->mFreeBusyWidget->setReadOnly( readOnly );
760 
761  // widgets from notes group
762  d->mNotesWidget->setReadOnly( readOnly );
763 
764  // widgets from dates group
765  d->mBirthdateWidget->setReadOnly( readOnly );
766  d->mAnniversaryWidget->setReadOnly( readOnly );
767 
768  // widgets from family group
769  d->mPartnerWidget->setReadOnly( readOnly );
770 
771  if (d->mDisplayMode == FullMode) {
772  // widgets from custom fields group
773  d->mCustomFieldsWidget->setReadOnly( readOnly );
774 
775  // custom pages
776  foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) {
777  plugin->setReadOnly( readOnly );
778  }
779  }
780 }
Akonadi::ContactEditorPagePlugin::loadContact
virtual void loadContact(const KABC::Addressee &contact)=0
This method is called to fill the editor widget with the data from contact.
ContactEditorWidget::setReadOnly
void setReadOnly(bool readOnly)
Sets whether the contact in the editor allows the user to edit the contact or not.
Definition: contacteditorwidget.cpp:717
ContactEditorWidget
A widget for editing a contact.
Definition: contacteditorwidget.h:37
DisplayNameEditWidget
A widget for editing the display name of a contact.
Definition: displaynameeditwidget.h:37
ContactEditorWidget::~ContactEditorWidget
~ContactEditorWidget()
Destroys the contact editor widget.
Definition: contacteditorwidget.cpp:547
Akonadi::ContactEditorPagePlugin
The base class for custom ContactEditor page plugins.
Definition: contacteditorpageplugin.h:40
Akonadi::ContactMetaData::customFieldDescriptions
QVariantList customFieldDescriptions() const
Returns the descriptions of the custom fields of the contact.
Definition: contactmetadata.cpp:101
Akonadi::ContactMetaData::setCustomFieldDescriptions
void setCustomFieldDescriptions(const QVariantList &descriptions)
Sets the descriptions of the custom fields of that contact.
Definition: contactmetadata.cpp:96
CategoriesEditWidget
A widget for editing the categories of a contact.
Definition: categorieseditwidget.h:36
Akonadi::ContactMetaData
A helper class for storing contact specific settings.
Definition: contactmetadata_p.h:36
DisplayNameEditWidget::DisplayType
DisplayType
Describes what the display name should look like.
Definition: displaynameeditwidget.h:45
Akonadi::ContactEditorPagePlugin::storeContact
virtual void storeContact(KABC::Addressee &contact) const =0
This method is called to store the data from the editor widget into contact.
PhoneEditWidget
A widget for editing phone numbers of a contact.
Definition: phoneeditwidget.h:190
IMEditWidget
This widget displays an input field for changing the instant messaging id of a contact.
Definition: imeditwidget.h:38
Akonadi::ContactMetaData::setDisplayNameMode
void setDisplayNameMode(int mode)
Sets the mode that is used for the display name of that contact.
Definition: contactmetadata.cpp:86
AddressEditWidget
An editor widget for addresses.
Definition: addresseditwidget.h:139
ContactEditorWidget::FullMode
Show all pages.
Definition: contacteditorwidget.h:41
Akonadi::ContactEditorPagePlugin::title
virtual QString title() const =0
Returns the i18n'd page title.
ContactEditorWidget::storeContact
void storeContact(KABC::Addressee &contact, Akonadi::ContactMetaData &metaData) const
Stores back the fields of the contact editor into the given contact.
Definition: contacteditorwidget.cpp:631
Akonadi::ContactMetaData::displayNameMode
int displayNameMode() const
Returns the mode that is used for the display name of that contact.
Definition: contactmetadata.cpp:91
ContactEditorWidget::DisplayMode
DisplayMode
Definition: contacteditorwidget.h:40
ContactEditorWidget::loadContact
void loadContact(const KABC::Addressee &contact, const Akonadi::ContactMetaData &metaData)
Initializes the fields of the contact editor with the values from a contact.
Definition: contacteditorwidget.cpp:552
Akonadi::ContactEditorPagePlugin::setReadOnly
virtual void setReadOnly(bool readOnly)=0
This method is called to set the editor widget readOnly.
NameEditWidget
A widget for editing the name of a contact.
Definition: nameeditwidget.h:38
EmailEditWidget
A widget for editing email addresses.
Definition: emaileditwidget.h:42
ContactEditorWidget::ContactEditorWidget
ContactEditorWidget(QWidget *parent=0)
Creates a new contact editor widget.
Definition: contacteditorwidget.cpp:525
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Thu Nov 13 2014 13:30:06 by doxygen 1.8.8 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.3 API Reference

Skip menu "kdepimlibs-4.14.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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