akonadi
contacteditorwidget.cpp
00001 /* 00002 This file is part of Akonadi Contact. 00003 00004 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org> 00005 00006 This library is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU Library General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to the 00018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 02110-1301, USA. 00020 */ 00021 00022 #include "contacteditorwidget.h" 00023 00024 #include "addresseditwidget.h" 00025 #include "categorieseditwidget.h" 00026 #include "contacteditorpageplugin.h" 00027 #include "contactmetadata_p.h" 00028 #include "customfieldseditwidget.h" 00029 #include "dateeditwidget.h" 00030 #include "displaynameeditwidget.h" 00031 #include "emaileditwidget.h" 00032 #include "freebusyeditwidget.h" 00033 #include "geoeditwidget.h" 00034 #include "imagewidget.h" 00035 #include "imeditwidget.h" 00036 #include "nameeditwidget.h" 00037 #include "phoneeditwidget.h" 00038 #include "soundeditwidget.h" 00039 00040 #include <kconfig.h> 00041 #include <kconfiggroup.h> 00042 #include <klineedit.h> 00043 #include <klocale.h> 00044 #include <kstandarddirs.h> 00045 #include <ktabwidget.h> 00046 #include <ktextedit.h> 00047 #include <kurlrequester.h> 00048 00049 #include <QtCore/QDirIterator> 00050 #include <QtCore/QPluginLoader> 00051 #include <QtGui/QGroupBox> 00052 #include <QtGui/QLabel> 00053 #include <QtGui/QLayout> 00054 00055 class ContactEditorWidget::Private 00056 { 00057 public: 00058 Private( ContactEditorWidget *parent ) 00059 : mParent( parent ) 00060 { 00061 } 00062 00063 void initGui(); 00064 void initGuiContactTab(); 00065 void initGuiLocationTab(); 00066 void initGuiBusinessTab(); 00067 void initGuiPersonalTab(); 00068 void initGuiNotesTab(); 00069 void initGuiCustomFieldsTab(); 00070 00071 void loadCustomPages(); 00072 00073 QString loadCustom( const KABC::Addressee &contact, const QString &key ) const; 00074 void storeCustom( KABC::Addressee &contact, const QString &key, const QString &value ) const; 00075 00076 ContactEditorWidget *mParent; 00077 KTabWidget *mTabWidget; 00078 00079 // widgets from name group 00080 NameEditWidget *mNameWidget; 00081 ImageWidget *mPhotoWidget; 00082 DisplayNameEditWidget *mDisplayNameWidget; 00083 KLineEdit *mNickNameWidget; 00084 SoundEditWidget *mPronunciationWidget; 00085 00086 // widgets from Internet group 00087 EmailEditWidget *mEmailWidget; 00088 KLineEdit *mHomepageWidget; 00089 KLineEdit *mBlogWidget; 00090 IMEditWidget *mIMWidget; 00091 00092 // widgets from phones group 00093 PhoneEditWidget *mPhonesWidget; 00094 00095 CategoriesEditWidget *mCategoriesWidget; 00096 00097 // widgets from addresses group 00098 AddressEditWidget *mAddressesWidget; 00099 00100 // widgets from coordinates group 00101 GeoEditWidget *mCoordinatesWidget; 00102 00103 // widgets from general group 00104 ImageWidget *mLogoWidget; 00105 KLineEdit *mOrganizationWidget; 00106 KLineEdit *mProfessionWidget; 00107 KLineEdit *mTitleWidget; 00108 KLineEdit *mDepartmentWidget; 00109 KLineEdit *mOfficeWidget; 00110 KLineEdit *mManagerWidget; 00111 KLineEdit *mAssistantWidget; 00112 00113 // widgets from groupware group 00114 FreeBusyEditWidget *mFreeBusyWidget; 00115 00116 // widgets from notes group 00117 KTextEdit *mNotesWidget; 00118 00119 // widgets from dates group 00120 DateEditWidget *mBirthdateWidget; 00121 DateEditWidget *mAnniversaryWidget; 00122 00123 // widgets from family group 00124 KLineEdit *mPartnerWidget; 00125 00126 // widgets from custom fields group 00127 CustomFieldsEditWidget *mCustomFieldsWidget; 00128 00129 // custom editor pages 00130 QList<Akonadi::ContactEditorPagePlugin*> mCustomPages; 00131 }; 00132 00133 void ContactEditorWidget::Private::initGui() 00134 { 00135 QVBoxLayout *layout = new QVBoxLayout( mParent ); 00136 layout->setMargin( 0 ); 00137 00138 mTabWidget = new KTabWidget( mParent ); 00139 layout->addWidget( mTabWidget ); 00140 00141 initGuiContactTab(); 00142 initGuiLocationTab(); 00143 initGuiBusinessTab(); 00144 initGuiPersonalTab(); 00145 initGuiNotesTab(); 00146 initGuiCustomFieldsTab(); 00147 00148 loadCustomPages(); 00149 } 00150 00151 void ContactEditorWidget::Private::initGuiContactTab() 00152 { 00153 QWidget *widget = new QWidget; 00154 QGridLayout *layout = new QGridLayout( widget ); 00155 00156 mTabWidget->addTab( widget, i18nc( "@title:tab", "Contact" ) ); 00157 00158 QGroupBox *nameGroupBox = new QGroupBox( i18nc( "@title:group Name related properties of a contact", "Name" ) ); 00159 QGroupBox *internetGroupBox = new QGroupBox( i18nc( "@title:group", "Internet" ) ); 00160 QGroupBox *phonesGroupBox = new QGroupBox( i18nc( "@title:group", "Phones" ) ); 00161 00162 layout->addWidget( nameGroupBox, 0, 0 ); 00163 layout->addWidget( internetGroupBox, 0, 1 ); 00164 layout->addWidget( phonesGroupBox, 1, 0, 2, 1 ); 00165 00166 QGridLayout *nameLayout = new QGridLayout( nameGroupBox ); 00167 QGridLayout *internetLayout = new QGridLayout( internetGroupBox ); 00168 QGridLayout *phonesLayout = new QGridLayout( phonesGroupBox ); 00169 00170 QLabel *label = 0; 00171 00172 // setup name group box 00173 label = new QLabel( i18nc( "@label The name of a contact", "Name:" ) ); 00174 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00175 nameLayout->addWidget( label, 0, 0 ); 00176 00177 mNameWidget = new NameEditWidget; 00178 label->setBuddy( mNameWidget ); 00179 nameLayout->addWidget( mNameWidget, 0, 1 ); 00180 00181 mPhotoWidget = new ImageWidget( ImageWidget::Photo ); 00182 mPhotoWidget->setMinimumSize( QSize( 100, 140 ) ); 00183 nameLayout->addWidget( mPhotoWidget, 0, 2, 4, 1 ); 00184 00185 label = new QLabel( i18nc( "@label The display name of a contact", "Display:" ) ); 00186 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00187 nameLayout->addWidget( label, 1, 0 ); 00188 00189 mDisplayNameWidget = new DisplayNameEditWidget; 00190 label->setBuddy( mDisplayNameWidget ); 00191 nameLayout->addWidget( mDisplayNameWidget, 1, 1 ); 00192 00193 label = new QLabel( i18nc( "@label The nickname of a contact", "Nickname:" ) ); 00194 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00195 nameLayout->addWidget( label, 2, 0 ); 00196 00197 mNickNameWidget = new KLineEdit; 00198 label->setBuddy( mNickNameWidget ); 00199 nameLayout->addWidget( mNickNameWidget, 2, 1 ); 00200 00201 label = new QLabel( i18nc( "@label The pronunciation of a contact's name", "Pronunciation:" ) ); 00202 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00203 nameLayout->addWidget( label, 3, 0 ); 00204 00205 mPronunciationWidget = new SoundEditWidget; 00206 label->setBuddy( mPronunciationWidget ); 00207 nameLayout->addWidget( mPronunciationWidget, 3, 1 ); 00208 00209 nameLayout->setRowStretch( 4, 1 ); 00210 00211 // setup Internet group box 00212 label = new QLabel( i18nc( "@label The email address of a contact", "Email:" ) ); 00213 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00214 internetLayout->addWidget( label, 0, 0 ); 00215 00216 mEmailWidget = new EmailEditWidget; 00217 label->setBuddy( mEmailWidget ); 00218 internetLayout->addWidget( mEmailWidget, 0, 1 ); 00219 00220 label = new QLabel( i18nc( "@label The homepage URL of a contact", "Homepage:" ) ); 00221 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00222 internetLayout->addWidget( label, 1, 0 ); 00223 00224 mHomepageWidget = new KLineEdit; 00225 label->setBuddy( mHomepageWidget ); 00226 internetLayout->addWidget( mHomepageWidget, 1, 1 ); 00227 00228 label = new QLabel( i18nc( "@label The blog URL of a contact", "Blog:" ) ); 00229 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00230 internetLayout->addWidget( label, 2, 0 ); 00231 00232 mBlogWidget = new KLineEdit; 00233 label->setBuddy( mBlogWidget ); 00234 internetLayout->addWidget( mBlogWidget, 2, 1 ); 00235 00236 label = new QLabel( i18nc( "@label The instant messaging address of a contact", "Messaging:" ) ); 00237 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00238 internetLayout->addWidget( label, 3, 0 ); 00239 00240 mIMWidget = new IMEditWidget; 00241 label->setBuddy( mIMWidget ); 00242 internetLayout->addWidget( mIMWidget, 3, 1 ); 00243 00244 internetLayout->setRowStretch( 4, 1 ); 00245 00246 // setup phones group box 00247 mPhonesWidget = new PhoneEditWidget; 00248 phonesLayout->addWidget( mPhonesWidget, 0, 0 ); 00249 00250 phonesLayout->setRowStretch( 1, 1 ); 00251 00252 // setup categories section 00253 QHBoxLayout *categoriesLayout = new QHBoxLayout; 00254 label = new QLabel( i18nc( "@label The categories of a contact", "Categories:" ) ); 00255 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00256 00257 mCategoriesWidget = new CategoriesEditWidget; 00258 label->setBuddy( mCategoriesWidget ); 00259 00260 categoriesLayout->addWidget( label ); 00261 categoriesLayout->addWidget( mCategoriesWidget ); 00262 00263 layout->addLayout( categoriesLayout, 1, 1 ); 00264 layout->setRowStretch( 2, 1 ); 00265 } 00266 00267 void ContactEditorWidget::Private::initGuiLocationTab() 00268 { 00269 QWidget *widget = new QWidget; 00270 QHBoxLayout *layout = new QHBoxLayout( widget ); 00271 00272 mTabWidget->addTab( widget, i18nc( "@title:tab", "Location" ) ); 00273 00274 QGroupBox *addressesGroupBox = new QGroupBox( i18nc( "@title:group", "Addresses" ) ); 00275 QGroupBox *coordinatesGroupBox = new QGroupBox( i18nc( "@title:group", "Coordinates" ) ); 00276 00277 layout->addWidget( addressesGroupBox ); 00278 layout->addWidget( coordinatesGroupBox ); 00279 00280 QGridLayout *addressesLayout = new QGridLayout( addressesGroupBox ); 00281 QGridLayout *coordinatesLayout = new QGridLayout( coordinatesGroupBox ); 00282 00283 // setup addresses group box 00284 mAddressesWidget = new AddressEditWidget( addressesGroupBox ); 00285 mAddressesWidget->setMinimumHeight( 200 ); 00286 addressesLayout->addWidget( mAddressesWidget, 0, 0 ); 00287 addressesLayout->setRowStretch( 1, 1 ); 00288 00289 // setup coordinates group box 00290 mCoordinatesWidget = new GeoEditWidget; 00291 coordinatesLayout->addWidget( mCoordinatesWidget, 0, 0 ); 00292 coordinatesLayout->setRowStretch( 1, 1 ); 00293 } 00294 00295 void ContactEditorWidget::Private::initGuiBusinessTab() 00296 { 00297 QWidget *widget = new QWidget; 00298 QVBoxLayout *layout = new QVBoxLayout( widget ); 00299 00300 mTabWidget->addTab( widget, i18nc( "@title:tab", "Business" ) ); 00301 00302 QGroupBox *generalGroupBox = new QGroupBox( i18nc( "@title:group General properties of a contact", "General" ) ); 00303 QGroupBox *groupwareGroupBox = new QGroupBox( i18nc( "@title:group", "Groupware" ) ); 00304 00305 layout->addWidget( generalGroupBox ); 00306 layout->addWidget( groupwareGroupBox ); 00307 00308 QGridLayout *generalLayout = new QGridLayout( generalGroupBox ); 00309 QGridLayout *groupwareLayout = new QGridLayout( groupwareGroupBox ); 00310 00311 QLabel *label = 0; 00312 00313 // setup general group box 00314 mLogoWidget = new ImageWidget( ImageWidget::Logo ); 00315 generalLayout->addWidget( mLogoWidget, 0, 2, 6, 1, Qt::AlignTop ); 00316 00317 label = new QLabel( i18nc( "@label The organization of a contact", "Organization:" ) ); 00318 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00319 generalLayout->addWidget( label, 0, 0 ); 00320 00321 mOrganizationWidget = new KLineEdit; 00322 label->setBuddy( mOrganizationWidget ); 00323 generalLayout->addWidget( mOrganizationWidget, 0, 1 ); 00324 00325 label = new QLabel( i18nc( "@label The profession of a contact", "Profession:" ) ); 00326 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00327 generalLayout->addWidget( label, 1, 0 ); 00328 00329 mProfessionWidget = new KLineEdit; 00330 label->setBuddy( mProfessionWidget ); 00331 generalLayout->addWidget( mProfessionWidget, 1, 1 ); 00332 00333 label = new QLabel( i18nc( "@label The title of a contact", "Title:" ) ); 00334 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00335 generalLayout->addWidget( label, 2, 0 ); 00336 00337 mTitleWidget = new KLineEdit; 00338 label->setBuddy( mTitleWidget ); 00339 generalLayout->addWidget( mTitleWidget , 2, 1 ); 00340 00341 label = new QLabel( i18nc( "@label The department of a contact", "Department:" ) ); 00342 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00343 generalLayout->addWidget( label, 3, 0 ); 00344 00345 mDepartmentWidget = new KLineEdit; 00346 label->setBuddy( mDepartmentWidget ); 00347 generalLayout->addWidget( mDepartmentWidget, 3, 1 ); 00348 00349 label = new QLabel( i18nc( "@label The office of a contact", "Office:" ) ); 00350 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00351 generalLayout->addWidget( label, 4, 0 ); 00352 00353 mOfficeWidget = new KLineEdit; 00354 label->setBuddy( mOfficeWidget ); 00355 generalLayout->addWidget( mOfficeWidget, 4, 1 ); 00356 00357 label = new QLabel( i18nc( "@label The manager's name of a contact", "Manager's name:" ) ); 00358 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00359 generalLayout->addWidget( label, 5, 0 ); 00360 00361 mManagerWidget = new KLineEdit; 00362 label->setBuddy( mManagerWidget ); 00363 generalLayout->addWidget( mManagerWidget, 5, 1 ); 00364 00365 label = new QLabel( i18nc( "@label The assistant's name of a contact", "Assistant's name:" ) ); 00366 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00367 generalLayout->addWidget( label, 6, 0 ); 00368 00369 mAssistantWidget = new KLineEdit; 00370 label->setBuddy( mAssistantWidget ); 00371 generalLayout->addWidget( mAssistantWidget, 6, 1 ); 00372 00373 // setup groupware group box 00374 label = new QLabel( i18nc( "@label The free/busy information of a contact", "Free/Busy:" ) ); 00375 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00376 groupwareLayout->addWidget( label, 0, 0 ); 00377 00378 mFreeBusyWidget = new FreeBusyEditWidget; 00379 label->setBuddy( mFreeBusyWidget ); 00380 groupwareLayout->addWidget( mFreeBusyWidget, 0, 1 ); 00381 groupwareLayout->setRowStretch( 1, 1 ); 00382 } 00383 00384 void ContactEditorWidget::Private::initGuiPersonalTab() 00385 { 00386 QWidget *widget = new QWidget; 00387 QVBoxLayout *layout = new QVBoxLayout( widget ); 00388 00389 mTabWidget->addTab( widget, i18nc( "@title:tab Personal properties of a contact", "Personal" ) ); 00390 00391 QGroupBox *datesGroupBox = new QGroupBox( i18nc( "@title:group Date related properties of a contact", "Dates" ) ); 00392 QGroupBox *familyGroupBox = new QGroupBox( i18nc( "@title:group Family related properties of a contact", "Family" ) ); 00393 00394 layout->addWidget( datesGroupBox ); 00395 layout->addWidget( familyGroupBox ); 00396 00397 QGridLayout *datesLayout = new QGridLayout( datesGroupBox ); 00398 QGridLayout *familyLayout = new QGridLayout( familyGroupBox ); 00399 00400 QLabel *label = 0; 00401 00402 // setup dates group box 00403 label = new QLabel( i18nc( "@label The birthdate of a contact", "Birthdate:" ) ); 00404 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00405 datesLayout->addWidget( label, 0, 0 ); 00406 00407 mBirthdateWidget = new DateEditWidget( DateEditWidget::Birthday ); 00408 label->setBuddy( mBirthdateWidget ); 00409 datesLayout->addWidget( mBirthdateWidget, 0, 1 ); 00410 00411 label = new QLabel( i18nc( "@label The anniversary of a contact", "Anniversary:" ) ); 00412 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00413 datesLayout->addWidget( label, 1, 0 ); 00414 00415 mAnniversaryWidget = new DateEditWidget( DateEditWidget::Anniversary ); 00416 label->setBuddy( mAnniversaryWidget ); 00417 datesLayout->addWidget( mAnniversaryWidget, 1, 1 ); 00418 00419 datesLayout->setRowStretch( 2, 1 ); 00420 datesLayout->setColumnStretch( 1, 1 ); 00421 00422 // widgets from family group 00423 label = new QLabel( i18nc( "@label The partner's name of a contact", "Partner's name:" ) ); 00424 label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 00425 familyLayout->addWidget( label, 0, 0 ); 00426 00427 mPartnerWidget = new KLineEdit; 00428 label->setBuddy( mPartnerWidget ); 00429 familyLayout->addWidget( mPartnerWidget, 0, 1 ); 00430 00431 familyLayout->setRowStretch( 1, 1 ); 00432 } 00433 00434 void ContactEditorWidget::Private::initGuiNotesTab() 00435 { 00436 QWidget *widget = new QWidget; 00437 QVBoxLayout *layout = new QVBoxLayout( widget ); 00438 00439 mTabWidget->addTab( widget, i18nc( "@title:tab", "Notes" ) ); 00440 00441 mNotesWidget = new KTextEdit; 00442 layout->addWidget( mNotesWidget ); 00443 } 00444 00445 void ContactEditorWidget::Private::initGuiCustomFieldsTab() 00446 { 00447 QWidget *widget = new QWidget; 00448 QVBoxLayout *layout = new QVBoxLayout( widget ); 00449 00450 mTabWidget->addTab( widget, i18nc( "@title:tab", "Custom Fields" ) ); 00451 00452 mCustomFieldsWidget = new CustomFieldsEditWidget; 00453 layout->addWidget( mCustomFieldsWidget ); 00454 } 00455 00456 void ContactEditorWidget::Private::loadCustomPages() 00457 { 00458 qDeleteAll( mCustomPages ); 00459 mCustomPages.clear(); 00460 00461 const QString pluginDirectory = KStandardDirs::locate( "lib", QLatin1String( "akonadi/contact/editorpageplugins/" ) ); 00462 QDirIterator it( pluginDirectory, QDir::Files ); 00463 while ( it.hasNext() ) { 00464 QPluginLoader loader( it.next() ); 00465 if ( !loader.load() ) 00466 continue; 00467 00468 Akonadi::ContactEditorPagePlugin *plugin = qobject_cast<Akonadi::ContactEditorPagePlugin*>( loader.instance() ); 00469 if ( !plugin ) 00470 continue; 00471 00472 mCustomPages.append( plugin ); 00473 } 00474 00475 foreach ( Akonadi::ContactEditorPagePlugin *plugin, mCustomPages ) 00476 mTabWidget->addTab( plugin, plugin->title() ); 00477 } 00478 00479 QString ContactEditorWidget::Private::loadCustom( const KABC::Addressee &contact, const QString &key ) const 00480 { 00481 return contact.custom( QLatin1String( "KADDRESSBOOK" ), key ); 00482 } 00483 00484 void ContactEditorWidget::Private::storeCustom( KABC::Addressee &contact, const QString &key, const QString &value ) const 00485 { 00486 if ( value.isEmpty() ) 00487 contact.removeCustom( QLatin1String( "KADDRESSBOOK" ), key ); 00488 else 00489 contact.insertCustom( QLatin1String( "KADDRESSBOOK" ), key, value ); 00490 } 00491 00492 ContactEditorWidget::ContactEditorWidget( QWidget* ) 00493 : d( new Private( this ) ) 00494 { 00495 d->initGui(); 00496 00497 connect( d->mNameWidget, SIGNAL( nameChanged( const KABC::Addressee& ) ), 00498 d->mDisplayNameWidget, SLOT( changeName( const KABC::Addressee& ) ) ); 00499 connect( d->mOrganizationWidget, SIGNAL( textChanged( const QString& ) ), 00500 d->mDisplayNameWidget, SLOT( changeOrganization( const QString& ) ) ); 00501 } 00502 00503 ContactEditorWidget::~ContactEditorWidget() 00504 { 00505 delete d; 00506 } 00507 00508 void ContactEditorWidget::loadContact( const KABC::Addressee &contact, const Akonadi::ContactMetaData &metaData ) 00509 { 00510 // name group 00511 d->mPhotoWidget->loadContact( contact ); 00512 d->mNameWidget->loadContact( contact ); 00513 d->mDisplayNameWidget->loadContact( contact ); 00514 d->mNickNameWidget->setText( contact.nickName() ); 00515 d->mPronunciationWidget->loadContact( contact ); 00516 00517 // Internet group 00518 d->mEmailWidget->loadContact( contact ); 00519 d->mHomepageWidget->setUrl( contact.url() ); 00520 d->mBlogWidget->setText( d->loadCustom( contact, QLatin1String( "BlogFeed" ) ) ); 00521 d->mIMWidget->loadContact( contact ); 00522 00523 // phones group 00524 d->mPhonesWidget->loadContact( contact ); 00525 00526 // categories section 00527 d->mCategoriesWidget->loadContact( contact ); 00528 00529 // address group 00530 d->mAddressesWidget->loadContact( contact ); 00531 00532 // coordinates group 00533 d->mCoordinatesWidget->loadContact( contact ); 00534 00535 // general group 00536 d->mLogoWidget->loadContact( contact ); 00537 d->mOrganizationWidget->setText( contact.organization() ); 00538 d->mProfessionWidget->setText( d->loadCustom( contact, QLatin1String( "X-Profession" ) ) ); 00539 d->mTitleWidget->setText( contact.title() ); 00540 d->mDepartmentWidget->setText( contact.department() ); 00541 d->mOfficeWidget->setText( d->loadCustom( contact, QLatin1String( "X-Office" ) ) ); 00542 d->mManagerWidget->setText( d->loadCustom( contact, QLatin1String( "X-ManagersName" ) ) ); 00543 d->mAssistantWidget->setText( d->loadCustom( contact, QLatin1String( "X-AssistantsName" ) ) ); 00544 00545 // groupware group 00546 d->mFreeBusyWidget->loadContact( contact ); 00547 00548 // notes group 00549 d->mNotesWidget->setPlainText( contact.note() ); 00550 00551 // dates group 00552 d->mBirthdateWidget->setDate( contact.birthday().date() ); 00553 d->mAnniversaryWidget->setDate( QDate::fromString( d->loadCustom( contact, QLatin1String( "X-Anniversary" ) ), 00554 Qt::ISODate ) ); 00555 00556 // family group 00557 d->mPartnerWidget->setText( d->loadCustom( contact, QLatin1String( "X-SpousesName" ) ) ); 00558 00559 d->mDisplayNameWidget->setDisplayType( (DisplayNameEditWidget::DisplayType)metaData.displayNameMode() ); 00560 00561 // custom fields group 00562 d->mCustomFieldsWidget->setLocalCustomFieldDescriptions( metaData.customFieldDescriptions() ); 00563 d->mCustomFieldsWidget->loadContact( contact ); 00564 00565 // custom pages 00566 foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) 00567 plugin->loadContact( contact ); 00568 } 00569 00570 void ContactEditorWidget::storeContact( KABC::Addressee &contact, Akonadi::ContactMetaData &metaData ) const 00571 { 00572 // name group 00573 d->mPhotoWidget->storeContact( contact ); 00574 d->mNameWidget->storeContact( contact ); 00575 d->mDisplayNameWidget->storeContact( contact ); 00576 contact.setNickName( d->mNickNameWidget->text().trimmed() ); 00577 d->mPronunciationWidget->storeContact( contact ); 00578 00579 // Internet group 00580 d->mEmailWidget->storeContact( contact ); 00581 contact.setUrl( KUrl( d->mHomepageWidget->text().trimmed() ) ); 00582 d->storeCustom( contact, QLatin1String( "BlogFeed" ), d->mBlogWidget->text().trimmed() ); 00583 d->mIMWidget->storeContact( contact ); 00584 00585 // phones group 00586 d->mPhonesWidget->storeContact( contact ); 00587 00588 // categories section 00589 d->mCategoriesWidget->storeContact( contact ); 00590 00591 // address group 00592 d->mAddressesWidget->storeContact( contact ); 00593 00594 // coordinates group 00595 d->mCoordinatesWidget->storeContact( contact ); 00596 00597 // general group 00598 d->mLogoWidget->storeContact( contact ); 00599 contact.setOrganization( d->mOrganizationWidget->text() ); 00600 d->storeCustom( contact, QLatin1String( "X-Profession" ), d->mProfessionWidget->text().trimmed() ); 00601 contact.setTitle( d->mTitleWidget->text().trimmed() ); 00602 contact.setDepartment( d->mDepartmentWidget->text().trimmed() ); 00603 d->storeCustom( contact, QLatin1String( "X-Office" ), d->mOfficeWidget->text().trimmed() ); 00604 d->storeCustom( contact, QLatin1String( "X-ManagersName" ), d->mManagerWidget->text().trimmed() ); 00605 d->storeCustom( contact, QLatin1String( "X-AssistantsName" ), d->mAssistantWidget->text().trimmed() ); 00606 00607 // groupware group 00608 d->mFreeBusyWidget->storeContact( contact ); 00609 00610 // notes group 00611 contact.setNote( d->mNotesWidget->toPlainText() ); 00612 00613 // dates group 00614 contact.setBirthday( QDateTime( d->mBirthdateWidget->date(), QTime(), contact.birthday().timeSpec() ) ); 00615 d->storeCustom( contact, QLatin1String( "X-Anniversary" ), d->mAnniversaryWidget->date().toString( Qt::ISODate ) ); 00616 00617 // family group 00618 d->storeCustom( contact, QLatin1String( "X-SpousesName" ), d->mPartnerWidget->text().trimmed() ); 00619 00620 // custom fields group 00621 d->mCustomFieldsWidget->storeContact( contact ); 00622 metaData.setCustomFieldDescriptions( d->mCustomFieldsWidget->localCustomFieldDescriptions() ); 00623 00624 metaData.setDisplayNameMode( d->mDisplayNameWidget->displayType() ); 00625 00626 // custom pages 00627 foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) 00628 plugin->storeContact( contact ); 00629 } 00630 00631 void ContactEditorWidget::setReadOnly( bool readOnly ) 00632 { 00633 // widgets from name group 00634 d->mNameWidget->setReadOnly( readOnly ); 00635 d->mPhotoWidget->setReadOnly( readOnly ); 00636 d->mDisplayNameWidget->setReadOnly( readOnly ); 00637 d->mNickNameWidget->setReadOnly( readOnly ); 00638 d->mPronunciationWidget->setReadOnly( readOnly ); 00639 00640 // widgets from Internet group 00641 d->mEmailWidget->setReadOnly( readOnly ); 00642 d->mHomepageWidget->setReadOnly( readOnly ); 00643 d->mBlogWidget->setReadOnly( readOnly ); 00644 d->mIMWidget->setReadOnly( readOnly ); 00645 00646 // widgets from phones group 00647 d->mPhonesWidget->setReadOnly( readOnly ); 00648 00649 // widgets from categories section 00650 d->mCategoriesWidget->setReadOnly( readOnly ); 00651 00652 // widgets from addresses group 00653 d->mAddressesWidget->setReadOnly( readOnly ); 00654 00655 // widgets from coordinates group 00656 d->mCoordinatesWidget->setReadOnly( readOnly ); 00657 00658 // widgets from general group 00659 d->mLogoWidget->setReadOnly( readOnly ); 00660 d->mOrganizationWidget->setReadOnly( readOnly ); 00661 d->mProfessionWidget->setReadOnly( readOnly ); 00662 d->mTitleWidget->setReadOnly( readOnly ); 00663 d->mDepartmentWidget->setReadOnly( readOnly ); 00664 d->mOfficeWidget->setReadOnly( readOnly ); 00665 d->mManagerWidget->setReadOnly( readOnly ); 00666 d->mAssistantWidget->setReadOnly( readOnly ); 00667 00668 // widgets from groupware group 00669 d->mFreeBusyWidget->setReadOnly( readOnly ); 00670 00671 // widgets from notes group 00672 d->mNotesWidget->setReadOnly( readOnly ); 00673 00674 // widgets from dates group 00675 d->mBirthdateWidget->setReadOnly( readOnly ); 00676 d->mAnniversaryWidget->setReadOnly( readOnly ); 00677 00678 // widgets from family group 00679 d->mPartnerWidget->setReadOnly( readOnly ); 00680 00681 // widgets from custom fields group 00682 d->mCustomFieldsWidget->setReadOnly( readOnly ); 00683 00684 // custom pages 00685 foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) 00686 plugin->setReadOnly( readOnly ); 00687 }