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

Skip menu "kdepimlibs-4.10.5 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