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

akonadi

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

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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