00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qcheckbox.h>
00025 #include <qhbox.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qlistbox.h>
00029 #include <qpushbutton.h>
00030 #include <qtabwidget.h>
00031 #include <qtextedit.h>
00032 #include <qtoolbutton.h>
00033 #include <qtooltip.h>
00034
00035 #include <kabc/resource.h>
00036 #include <kabc/stdaddressbook.h>
00037 #include <kaccelmanager.h>
00038 #include <kapplication.h>
00039 #include <kconfig.h>
00040 #include <kcombobox.h>
00041 #include <kdebug.h>
00042 #include <kdialogbase.h>
00043 #include <kglobal.h>
00044 #include <kiconloader.h>
00045 #include <klineedit.h>
00046 #include <klocale.h>
00047 #include <kmessagebox.h>
00048 #include <kseparator.h>
00049 #include <ksqueezedtextlabel.h>
00050 #include <kstandarddirs.h>
00051
00052 #include <libkdepim/addresseelineedit.h>
00053 #include <libkdepim/categoryeditdialog.h>
00054 #include <libkdepim/categoryselectdialog.h>
00055 #include <libkdepim/kdateedit.h>
00056 #include <libkdepim/resourceabc.h>
00057
00058 #include "addresseditwidget.h"
00059 #include "advancedcustomfields.h"
00060 #include "emaileditwidget.h"
00061 #include "imeditwidget.h"
00062 #include "kabprefs.h"
00063 #include "keywidget.h"
00064 #include "nameeditdialog.h"
00065 #include "phoneeditwidget.h"
00066 #include "secrecywidget.h"
00067
00068 #include "addresseeeditorwidget.h"
00069
00070 AddresseeEditorWidget::AddresseeEditorWidget( QWidget *parent, const char *name )
00071 : AddresseeEditorBase( parent, name ),
00072 mBlockSignals( false ), mReadOnly( false )
00073 {
00074 kdDebug(5720) << "AddresseeEditorWidget()" << endl;
00075
00076 initGUI();
00077 mCategorySelectDialog = 0;
00078 mCategoryEditDialog = 0;
00079
00080
00081 load();
00082
00083 mDirty = false;
00084 }
00085
00086 AddresseeEditorWidget::~AddresseeEditorWidget()
00087 {
00088 kdDebug(5720) << "~AddresseeEditorWidget()" << endl;
00089 }
00090
00091 void AddresseeEditorWidget::setAddressee( const KABC::Addressee &addr )
00092 {
00093 if ( mAddressee.uid() == addr.uid() )
00094 return;
00095 mAddressee = addr;
00096
00097 bool readOnly = false;
00098 if ( KABC::Resource *res = addr.resource() ) {
00099 if ( res->readOnly() ) {
00100 readOnly = true;
00101
00102
00103 } else if ( res->inherits( "KPIM::ResourceABC" ) ) {
00104 KPIM::ResourceABC *resAbc = static_cast<KPIM::ResourceABC *>( res );
00105
00106 QString subresource = resAbc->uidToResourceMap()[ addr.uid() ];
00107 if ( !subresource.isEmpty() )
00108 readOnly |= !resAbc->subresourceWritable( subresource );
00109 }
00110 }
00111 setReadOnly( readOnly );
00112
00113 load();
00114 }
00115
00116 const KABC::Addressee &AddresseeEditorWidget::addressee()
00117 {
00118 return mAddressee;
00119 }
00120
00121 void AddresseeEditorWidget::textChanged( const QString& )
00122 {
00123 emitModified();
00124 }
00125
00126 void AddresseeEditorWidget::initGUI()
00127 {
00128 QVBoxLayout *layout = new QVBoxLayout( this );
00129
00130 mTabWidget = new QTabWidget( this );
00131 layout->addWidget( mTabWidget );
00132
00133 setupTab1();
00134 setupTab2();
00135 setupAdditionalTabs();
00136 setupCustomFieldsTabs();
00137
00138 connect( mTabWidget, SIGNAL( currentChanged(QWidget*) ),
00139 SLOT( pageChanged(QWidget*) ) );
00140 }
00141
00142 void AddresseeEditorWidget::setupTab1()
00143 {
00144
00145 QWidget *tab1 = new QWidget( mTabWidget );
00146
00147 QGridLayout *layout = new QGridLayout( tab1, 11, 7 );
00148 layout->setMargin( KDialogBase::marginHint() );
00149 layout->setSpacing( KDialogBase::spacingHint() );
00150
00151 QLabel *label;
00152 KSeparator* bar;
00153 QPushButton *button;
00154
00156
00157
00158
00159 label = new QLabel( tab1 );
00160 label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop,
00161 KIcon::SizeMedium ) );
00162 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
00163
00164
00165 button = new QPushButton( i18n( "Edit Name..." ), tab1 );
00166 QToolTip::add( button, i18n( "Edit the contact's name" ) );
00167 mNameEdit = new KLineEdit( tab1, "mNameEdit" );
00168 connect( mNameEdit, SIGNAL( textChanged( const QString& ) ),
00169 SLOT( nameTextChanged( const QString& ) ) );
00170 connect( button, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) );
00171 mNameLabel = new KSqueezedTextLabel( tab1 );
00172
00173 if ( KABPrefs::instance()->automaticNameParsing() ) {
00174 mNameLabel->hide();
00175 mNameEdit->show();
00176 } else {
00177 mNameEdit->hide();
00178 mNameLabel->show();
00179 }
00180
00181 layout->addWidget( button, 0, 1 );
00182 layout->addWidget( mNameEdit, 0, 2 );
00183 layout->addWidget( mNameLabel, 0, 2 );
00184 label = new QLabel( i18n( "<roleLabel>:", "%1:" ).arg( KABC::Addressee::roleLabel() ), tab1 );
00185 mRoleEdit = new KLineEdit( tab1 );
00186 connect( mRoleEdit, SIGNAL( textChanged( const QString& ) ),
00187 SLOT( textChanged( const QString& ) ) );
00188 label->setBuddy( mRoleEdit );
00189 layout->addWidget( label, 1, 1 );
00190 layout->addWidget( mRoleEdit, 1, 2 );
00191
00192
00193 label = new QLabel( i18n( "<organizationLabel>:", "%1:" ).arg( KABC::Addressee::organizationLabel() ), tab1 );
00194 mOrgEdit = new KLineEdit( tab1 );
00195 label->setBuddy( mOrgEdit );
00196 connect( mOrgEdit, SIGNAL( textChanged( const QString& ) ),
00197 SLOT( organizationTextChanged( const QString& ) ) );
00198 layout->addWidget( label, 2, 1 );
00199 layout->addWidget( mOrgEdit, 2, 2 );
00200
00201
00202 label = new QLabel( i18n( "Formatted name:" ), tab1 );
00203 mFormattedNameLabel = new KSqueezedTextLabel( tab1 );
00204 layout->addWidget( label, 3, 1 );
00205 layout->addWidget( mFormattedNameLabel, 3, 2 );
00206
00207
00208
00209 bar = new KSeparator( KSeparator::HLine, tab1 );
00210 layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
00211
00213
00214 label = new QLabel( tab1 );
00215 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook",
00216 KIcon::Desktop, KIcon::SizeMedium ) );
00217 layout->addMultiCellWidget( label, 0, 1, 3, 3 );
00218
00219 mPhoneEditWidget = new PhoneEditWidget( tab1 );
00220 connect( mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00221 layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 );
00222
00223 bar = new KSeparator( KSeparator::HLine, tab1 );
00224 layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
00225
00227
00228 label = new QLabel( tab1 );
00229 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kfm_home", KIcon::Desktop,
00230 KIcon::SizeMedium ) );
00231 layout->addMultiCellWidget( label, 5, 6, 0, 0 );
00232
00233 mAddressEditWidget = new AddressEditWidget( tab1 );
00234 connect( mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00235 layout->addMultiCellWidget( mAddressEditWidget, 5, 10, 1, 2 );
00236
00238
00239 label = new QLabel( tab1 );
00240 label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop,
00241 KIcon::SizeMedium ) );
00242 layout->addMultiCellWidget( label, 5, 6, 3, 3 );
00243
00244 mEmailWidget = new EmailEditWidget( tab1 );
00245 connect( mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00246 layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
00247
00248
00249 bar = new KSeparator( KSeparator::HLine, tab1 );
00250 layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
00251
00252 QHBoxLayout *homePageLayout = new QHBoxLayout( 0, 11, 7 );
00253
00254 label = new QLabel( tab1 );
00255 label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop,
00256 KIcon::SizeMedium ) );
00257 homePageLayout->addWidget( label );
00258
00259 label = new QLabel( i18n( "<urlLabel>:", "%1:" ).arg( KABC::Addressee::urlLabel() ), tab1 );
00260 mURLEdit = new KLineEdit( tab1 );
00261 connect( mURLEdit, SIGNAL( textChanged( const QString& ) ),
00262 SLOT( textChanged( const QString& ) ) );
00263 label->setBuddy( mURLEdit );
00264 homePageLayout->addWidget( label );
00265 homePageLayout->addWidget( mURLEdit );
00266 layout->addMultiCellLayout( homePageLayout, 8, 8, 3, 6 );
00267
00268 QHBoxLayout *blogLayout = new QHBoxLayout( 0, 11, 7 );
00269 label = new QLabel( i18n("Blog feed:"), tab1 );
00270 blogLayout->addWidget( label );
00271 mBlogEdit = new KLineEdit( tab1 );
00272 blogLayout->addWidget( mBlogEdit );
00273 connect( mBlogEdit, SIGNAL( textChanged( const QString & ) ),
00274 SLOT( textChanged( const QString & ) ) );
00275 label->setBuddy( mBlogEdit );
00276 layout->addMultiCellLayout( blogLayout, 9, 9, 4, 6 );
00277
00278 mIMWidget = new IMEditWidget( tab1, mAddressee );
00279 connect( mIMWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00280 layout->addMultiCellWidget( mIMWidget, 10, 10, 4, 6 );
00281
00282 layout->addColSpacing( 6, 50 );
00283
00284 bar = new KSeparator( KSeparator::HLine, tab1 );
00285 layout->addMultiCellWidget( bar, 11, 11, 0, 6 );
00286
00288 QHBox *categoryBox = new QHBox( tab1 );
00289 categoryBox->setSpacing( KDialogBase::spacingHint() );
00290
00291
00292 mCategoryButton = new QPushButton( i18n( "Select Categories..." ), categoryBox );
00293 connect( mCategoryButton, SIGNAL( clicked() ), SLOT( selectCategories() ) );
00294
00295 mCategoryEdit = new KLineEdit( categoryBox );
00296 mCategoryEdit->setReadOnly( true );
00297 connect( mCategoryEdit, SIGNAL( textChanged( const QString& ) ),
00298 SLOT( textChanged( const QString& ) ) );
00299
00300 mSecrecyWidget = new SecrecyWidget( categoryBox );
00301 connect( mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
00302
00303 layout->addMultiCellWidget( categoryBox, 12, 12, 0, 6 );
00304
00305
00306 layout->activate();
00307
00308 mTabWidget->addTab( tab1, i18n( "&General" ) );
00309 }
00310
00311 void AddresseeEditorWidget::setupTab2()
00312 {
00313
00314 QWidget *tab2 = new QWidget( mTabWidget );
00315
00316 QGridLayout *layout = new QGridLayout( tab2, 6, 6 );
00317 layout->setMargin( KDialogBase::marginHint() );
00318 layout->setSpacing( KDialogBase::spacingHint() );
00319
00320 QLabel *label;
00321 KSeparator* bar;
00322
00324
00325
00326
00327 label = new QLabel( tab2 );
00328 label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop,
00329 KIcon::SizeMedium ) );
00330 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
00331
00332 label = new QLabel( i18n( "Department:" ), tab2 );
00333 layout->addWidget( label, 0, 1 );
00334 mDepartmentEdit = new KLineEdit( tab2 );
00335 connect( mDepartmentEdit, SIGNAL( textChanged( const QString& ) ),
00336 SLOT( textChanged( const QString& ) ) );
00337 label->setBuddy( mDepartmentEdit );
00338 layout->addWidget( mDepartmentEdit, 0, 2 );
00339
00340 label = new QLabel( i18n( "Office:" ), tab2 );
00341 layout->addWidget( label, 1, 1 );
00342 mOfficeEdit = new KLineEdit( tab2 );
00343 connect( mOfficeEdit, SIGNAL( textChanged( const QString& ) ),
00344 SLOT( textChanged( const QString& ) ) );
00345 label->setBuddy( mOfficeEdit );
00346 layout->addWidget( mOfficeEdit, 1, 2 );
00347
00348 label = new QLabel( i18n( "Profession:" ), tab2 );
00349 layout->addWidget( label, 2, 1 );
00350 mProfessionEdit = new KLineEdit( tab2 );
00351 connect( mProfessionEdit, SIGNAL( textChanged( const QString& ) ),
00352 SLOT( textChanged( const QString& ) ) );
00353 label->setBuddy( mProfessionEdit );
00354 layout->addWidget( mProfessionEdit, 2, 2 );
00355
00356 label = new QLabel( i18n( "Manager\'s name:" ), tab2 );
00357 layout->addWidget( label, 0, 3 );
00358 mManagerEdit = new KPIM::AddresseeLineEdit( tab2 );
00359 connect( mManagerEdit, SIGNAL( textChanged( const QString& ) ),
00360 SLOT( textChanged( const QString& ) ) );
00361 label->setBuddy( mManagerEdit );
00362 layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 );
00363
00364 label = new QLabel( i18n( "Assistant's name:" ), tab2 );
00365 layout->addWidget( label, 1, 3 );
00366 mAssistantEdit = new KPIM::AddresseeLineEdit( tab2 );
00367 connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ),
00368 SLOT( textChanged( const QString& ) ) );
00369 label->setBuddy( mAssistantEdit );
00370 layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 );
00371
00372 label = new QLabel( i18n( "<titleLabel>:", "%1:" ).arg( KABC::Addressee::titleLabel() ), tab2 );
00373 layout->addWidget( label, 2, 3 );
00374 mTitleEdit = new KLineEdit( tab2 );
00375 connect( mTitleEdit, SIGNAL( textChanged( const QString& ) ),
00376 SLOT( textChanged( const QString& ) ) );
00377 label->setBuddy( mTitleEdit );
00378 layout->addMultiCellWidget( mTitleEdit, 2, 2, 4, 5 );
00379
00380 bar = new KSeparator( KSeparator::HLine, tab2 );
00381 layout->addMultiCellWidget( bar, 3, 3, 0, 5 );
00382
00384
00385
00386 label = new QLabel( tab2 );
00387 label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop,
00388 KIcon::SizeMedium ) );
00389 layout->addMultiCellWidget( label, 4, 5, 0, 0 );
00390
00391 label = new QLabel( i18n( "Nickname:" ), tab2 );
00392 layout->addWidget( label, 4, 1 );
00393 mNicknameEdit = new KLineEdit( tab2 );
00394 connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ),
00395 SLOT( textChanged( const QString& ) ) );
00396 label->setBuddy( mNicknameEdit );
00397 layout->addWidget( mNicknameEdit, 4, 2 );
00398
00399 label = new QLabel( i18n( "Partner's name:" ), tab2 );
00400 layout->addWidget( label, 5, 1 );
00401 mSpouseEdit = new KPIM::AddresseeLineEdit( tab2 );
00402 connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ),
00403 SLOT( textChanged( const QString& ) ) );
00404 label->setBuddy( mSpouseEdit );
00405 layout->addWidget( mSpouseEdit, 5, 2 );
00406
00407 label = new QLabel( i18n( "Birthdate:" ), tab2 );
00408 layout->addWidget( label, 4, 3 );
00409 mBirthdayPicker = new KDateEdit( tab2 );
00410 connect( mBirthdayPicker, SIGNAL( dateChanged( const QDate& ) ),
00411 SLOT( dateChanged( const QDate& ) ) );
00412 connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ),
00413 SLOT( emitModified() ) );
00414 label->setBuddy( mBirthdayPicker );
00415 layout->addWidget( mBirthdayPicker, 4, 4 );
00416
00417 label = new QLabel( i18n( "Anniversary:" ), tab2 );
00418 layout->addWidget( label, 5, 3 );
00419 mAnniversaryPicker = new KDateEdit( tab2 );
00420 connect( mAnniversaryPicker, SIGNAL( dateChanged( const QDate& ) ),
00421 SLOT( dateChanged( const QDate& ) ) );
00422 connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ),
00423 SLOT( emitModified() ) );
00424 label->setBuddy( mAnniversaryPicker );
00425 layout->addWidget( mAnniversaryPicker, 5, 4 );
00426
00427 bar = new KSeparator( KSeparator::HLine, tab2 );
00428 layout->addMultiCellWidget( bar, 6, 6, 0, 5 );
00429
00431
00432 label = new QLabel( i18n( "Note:" ), tab2 );
00433 label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
00434 layout->addWidget( label, 7, 0 );
00435 mNoteEdit = new QTextEdit( tab2 );
00436 mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
00437 mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
00438 connect( mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) );
00439 label->setBuddy( mNoteEdit );
00440 layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
00441
00442
00443 layout->activate();
00444
00445 mTabWidget->addTab( tab2, i18n( "&Details" ) );
00446 }
00447
00448 void AddresseeEditorWidget::setupAdditionalTabs()
00449 {
00450 ContactEditorWidgetManager *manager = ContactEditorWidgetManager::self();
00451
00452
00453 for ( int i = 0; i < manager->count(); ++i ) {
00454 QString pageIdentifier = manager->factory( i )->pageIdentifier();
00455 QString pageTitle = manager->factory( i )->pageTitle();
00456
00457 if ( pageIdentifier == "misc" )
00458 pageTitle = i18n( "Misc" );
00459
00460 ContactEditorTabPage *page = mTabPages[ pageIdentifier ];
00461 if ( page == 0 ) {
00462 page = new ContactEditorTabPage( mTabWidget );
00463 mTabPages.insert( pageIdentifier, page );
00464
00465 mTabWidget->addTab( page, pageTitle );
00466
00467 connect( page, SIGNAL( changed() ), SLOT( emitModified() ) );
00468 }
00469
00470 KAB::ContactEditorWidget *widget
00471 = manager->factory( i )->createWidget( KABC::StdAddressBook::self( true ),
00472 page );
00473 if ( widget )
00474 page->addWidget( widget );
00475 }
00476
00477
00478 QDictIterator<ContactEditorTabPage> it( mTabPages );
00479 for ( ; it.current(); ++it )
00480 it.current()->updateLayout();
00481 }
00482
00483 void AddresseeEditorWidget::setupCustomFieldsTabs()
00484 {
00485 QStringList activePages = KABPrefs::instance()->advancedCustomFields();
00486
00487 const QStringList list = KGlobal::dirs()->findAllResources( "data", "kaddressbook/contacteditorpages/*.ui", true, true );
00488 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
00489 if ( activePages.find( (*it).mid( (*it).findRev('/') + 1 ) ) == activePages.end() )
00490 continue;
00491
00492 ContactEditorTabPage *page = new ContactEditorTabPage( mTabWidget );
00493 AdvancedCustomFields *wdg = new AdvancedCustomFields( *it, KABC::StdAddressBook::self( true ), page );
00494 if ( wdg ) {
00495 mTabPages.insert( wdg->pageIdentifier(), page );
00496 mTabWidget->addTab( page, wdg->pageTitle() );
00497
00498 page->addWidget( wdg );
00499 page->updateLayout();
00500
00501 connect( page, SIGNAL( changed() ), SLOT( emitModified() ) );
00502 } else
00503 delete page;
00504 }
00505 }
00506
00507 void AddresseeEditorWidget::load()
00508 {
00509 kdDebug(5720) << "AddresseeEditorWidget::load()" << endl;
00510
00511
00512
00513 bool block = signalsBlocked();
00514 blockSignals( true );
00515 mBlockSignals = true;
00516
00517 mNameEdit->blockSignals( true );
00518 mNameEdit->setText( mAddressee.assembledName() );
00519 mNameEdit->blockSignals( false );
00520
00521 if ( mAddressee.formattedName().isEmpty() ) {
00522 KConfig config( "kaddressbookrc" );
00523 config.setGroup( "General" );
00524 mFormattedNameType = config.readNumEntry( "FormattedNameType", 1 );
00525 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00526 } else {
00527 if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) )
00528 mFormattedNameType = NameEditDialog::SimpleName;
00529 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) )
00530 mFormattedNameType = NameEditDialog::FullName;
00531 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseNameWithComma ) )
00532 mFormattedNameType = NameEditDialog::ReverseNameWithComma;
00533 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) )
00534 mFormattedNameType = NameEditDialog::ReverseName;
00535 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::Organization ) )
00536 mFormattedNameType = NameEditDialog::Organization;
00537 else
00538 mFormattedNameType = NameEditDialog::CustomName;
00539 }
00540
00541 mFormattedNameLabel->setText( mAddressee.formattedName() );
00542
00543 mRoleEdit->setText( mAddressee.role() );
00544 mOrgEdit->setText( mAddressee.organization() );
00545 mURLEdit->setURL( mAddressee.url() );
00546 mURLEdit->home( false );
00547 mBlogEdit->setURL( mAddressee.custom( "KADDRESSBOOK", "BlogFeed" ) );
00548 mNoteEdit->setText( mAddressee.note() );
00549 mEmailWidget->setEmails( mAddressee.emails() );
00550 mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
00551 mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
00552 mBirthdayPicker->setDate( mAddressee.birthday().date() );
00553
00554 QString anniversaryStr = mAddressee.custom( "KADDRESSBOOK", "X-Anniversary" );
00555 QDate anniversary = (anniversaryStr.isEmpty() ? QDate() : QDate::fromString( anniversaryStr, Qt::ISODate ));
00556 mAnniversaryPicker->setDate( anniversary );
00557 mNicknameEdit->setText( mAddressee.nickName() );
00558 mCategoryEdit->setText( mAddressee.categories().join( "," ) );
00559
00560 mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
00561
00562
00563 mIMWidget->setPreferredIM( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) );
00564 mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) );
00565 mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) );
00566 mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
00567 mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) );
00568 mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) );
00569 mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) );
00570 mTitleEdit->setText( mAddressee.title() );
00571
00572 QDictIterator<ContactEditorTabPage> it( mTabPages );
00573 for ( ; it.current(); ++it )
00574 it.current()->loadContact( &mAddressee );
00575
00576 blockSignals( block );
00577 mBlockSignals = false;
00578
00579 mDirty = false;
00580 }
00581
00582 void AddresseeEditorWidget::save()
00583 {
00584 if ( !mDirty ) return;
00585
00586 mAddressee.setRole( mRoleEdit->text() );
00587 mAddressee.setOrganization( mOrgEdit->text() );
00588 QString homepage = mURLEdit->text().stripWhiteSpace();
00589 if ( homepage.isEmpty() )
00590 mAddressee.setUrl( KURL() );
00591 else {
00592 if( !homepage.startsWith("http") )
00593 homepage = "http://" + homepage;
00594 mAddressee.setUrl( KURL( homepage ) );
00595 }
00596 if ( !mBlogEdit->text().isEmpty() )
00597 mAddressee.insertCustom( "KADDRESSBOOK", "BlogFeed", mBlogEdit->text() );
00598 else
00599 mAddressee.removeCustom( "KADDRESSBOOK", "BlogFeed" );
00600
00601 mAddressee.setNote( mNoteEdit->text() );
00602 if ( mBirthdayPicker->date().isValid() )
00603 mAddressee.setBirthday( QDateTime( mBirthdayPicker->date() ) );
00604 else
00605 mAddressee.setBirthday( QDateTime() );
00606
00607 mAddressee.setNickName( mNicknameEdit->text() );
00608 mAddressee.setCategories( QStringList::split( ",", mCategoryEdit->text() ) );
00609
00610 mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
00611
00612
00613 if ( !mIMWidget->preferredIM().isEmpty() )
00614 mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMWidget->preferredIM() );
00615 else
00616 mAddressee.removeCustom( "KADDRESSBOOK", "X-IMAddress" );
00617 if ( !mSpouseEdit->text().isEmpty() )
00618 mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
00619 else
00620 mAddressee.removeCustom( "KADDRESSBOOK", "X-SpousesName" );
00621 if ( !mManagerEdit->text().isEmpty() )
00622 mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
00623 else
00624 mAddressee.removeCustom( "KADDRESSBOOK", "X-ManagersName" );
00625 if ( !mAssistantEdit->text().isEmpty() )
00626 mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
00627 else
00628 mAddressee.removeCustom( "KADDRESSBOOK", "X-AssistantsName" );
00629
00630 if ( !mDepartmentEdit->text().isEmpty() )
00631 mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() );
00632 else
00633 mAddressee.removeCustom( "KADDRESSBOOK", "X-Department" );
00634 if ( !mOfficeEdit->text().isEmpty() )
00635 mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
00636 else
00637 mAddressee.removeCustom( "KADDRESSBOOK", "X-Office" );
00638 if ( !mProfessionEdit->text().isEmpty() )
00639 mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
00640 else
00641 mAddressee.removeCustom( "KADDRESSBOOK", "X-Profession" );
00642
00643 if ( mAnniversaryPicker->date().isValid() )
00644 mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
00645 mAnniversaryPicker->date().toString( Qt::ISODate ) );
00646 else
00647 mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
00648
00649 mAddressee.setTitle( mTitleEdit->text() );
00650
00651
00652 mAddressee.setEmails( mEmailWidget->emails() );
00653
00654
00655 KABC::PhoneNumber::List phoneNumbers;
00656 KABC::PhoneNumber::List::ConstIterator phoneIter;
00657 phoneNumbers = mAddressee.phoneNumbers();
00658 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00659 ++phoneIter )
00660 mAddressee.removePhoneNumber( *phoneIter );
00661
00662 phoneNumbers = mPhoneEditWidget->phoneNumbers();
00663 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00664 ++phoneIter )
00665 mAddressee.insertPhoneNumber( *phoneIter );
00666
00667
00668 KABC::Address::List addresses;
00669 KABC::Address::List::ConstIterator addressIter;
00670 addresses = mAddressee.addresses();
00671 for ( addressIter = addresses.begin(); addressIter != addresses.end();
00672 ++addressIter )
00673 mAddressee.removeAddress( *addressIter );
00674
00675 addresses = mAddressEditWidget->addresses();
00676 for ( addressIter = addresses.begin(); addressIter != addresses.end();
00677 ++addressIter )
00678 mAddressee.insertAddress( *addressIter );
00679
00680 QDictIterator<ContactEditorTabPage> it( mTabPages );
00681 for ( ; it.current(); ++it )
00682 it.current()->storeContact( &mAddressee );
00683
00684 mDirty = false;
00685 }
00686
00687 bool AddresseeEditorWidget::dirty()
00688 {
00689 return mDirty;
00690 }
00691
00692 void AddresseeEditorWidget::nameTextChanged( const QString &text )
00693 {
00694
00695 AddresseeConfig config( mAddressee );
00696 if ( config.automaticNameParsing() ) {
00697 if ( !mAddressee.formattedName().isEmpty() ) {
00698 QString fn = mAddressee.formattedName();
00699 mAddressee.setNameFromString( text );
00700 mAddressee.setFormattedName( fn );
00701 } else {
00702
00703 Addressee addr;
00704 addr.setNameFromString( text );
00705 mAddressee.setPrefix( addr.prefix() );
00706 mAddressee.setGivenName( addr.givenName() );
00707 mAddressee.setAdditionalName( addr.additionalName() );
00708 mAddressee.setFamilyName( addr.familyName() );
00709 mAddressee.setSuffix( addr.suffix() );
00710 }
00711 }
00712
00713 nameBoxChanged();
00714
00715 emitModified();
00716 }
00717
00718 void AddresseeEditorWidget::organizationTextChanged( const QString &text )
00719 {
00720
00721 AddresseeConfig config( mAddressee );
00722 if ( config.automaticNameParsing() )
00723 mAddressee.setOrganization( text );
00724
00725 nameBoxChanged();
00726
00727 mAddressEditWidget->updateAddressee( mAddressee );
00728
00729 emitModified();
00730 }
00731
00732 void AddresseeEditorWidget::nameBoxChanged()
00733 {
00734 KABC::Addressee addr;
00735 AddresseeConfig config( mAddressee );
00736 if ( config.automaticNameParsing() ) {
00737 addr.setNameFromString( mNameEdit->text() );
00738 mNameLabel->hide();
00739 mNameEdit->show();
00740 } else {
00741 addr = mAddressee;
00742 mNameEdit->hide();
00743 mNameLabel->setText( mNameEdit->text() );
00744 mNameLabel->show();
00745 }
00746
00747 if ( mFormattedNameType != NameEditDialog::CustomName ) {
00748 mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00749 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00750 }
00751
00752 mAddressEditWidget->updateAddressee( mAddressee );
00753 }
00754
00755 void AddresseeEditorWidget::nameButtonClicked()
00756 {
00757
00758 NameEditDialog dialog( mAddressee, mFormattedNameType, mReadOnly, this );
00759
00760 if ( dialog.exec() ) {
00761 if ( dialog.changed() ) {
00762 mAddressee.setFamilyName( dialog.familyName() );
00763 mAddressee.setGivenName( dialog.givenName() );
00764 mAddressee.setPrefix( dialog.prefix() );
00765 mAddressee.setSuffix( dialog.suffix() );
00766 mAddressee.setAdditionalName( dialog.additionalName() );
00767 mFormattedNameType = dialog.formattedNameType();
00768 if ( mFormattedNameType == NameEditDialog::CustomName ) {
00769 mFormattedNameLabel->setText( dialog.customFormattedName() );
00770 mAddressee.setFormattedName( dialog.customFormattedName() );
00771 }
00772
00773 bool block = mNameEdit->signalsBlocked();
00774 mNameEdit->blockSignals( true );
00775 mNameEdit->setText( mAddressee.assembledName() );
00776 mNameEdit->blockSignals( block );
00777
00778
00779 nameBoxChanged();
00780
00781 emitModified();
00782 }
00783 }
00784 }
00785
00786 void AddresseeEditorWidget::selectCategories()
00787 {
00788
00789 if ( mCategorySelectDialog == 0 ) {
00790 mCategorySelectDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
00791 connect( mCategorySelectDialog, SIGNAL( categoriesSelected( const QStringList& ) ),
00792 this, SLOT( categoriesSelected( const QStringList& ) ) );
00793 connect( mCategorySelectDialog, SIGNAL( editCategories() ),
00794 this, SLOT( editCategories() ) );
00795 }
00796
00797 mCategorySelectDialog->setSelected( QStringList::split( ",", mCategoryEdit->text() ) );
00798 mCategorySelectDialog->exec();
00799 }
00800
00801 void AddresseeEditorWidget::categoriesSelected( const QStringList &list )
00802 {
00803 mCategoryEdit->setText( list.join( "," ) );
00804 }
00805
00806 void AddresseeEditorWidget::editCategories()
00807 {
00808 if ( mCategoryEditDialog == 0 ) {
00809 mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
00810 connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
00811 mCategorySelectDialog, SLOT( updateCategoryConfig() ) );
00812 }
00813
00814 mCategoryEditDialog->exec();
00815 }
00816
00817 void AddresseeEditorWidget::emitModified()
00818 {
00819 if ( mBlockSignals )
00820 return;
00821
00822 mDirty = true;
00823
00824 emit modified();
00825 }
00826
00827 void AddresseeEditorWidget::dateChanged( const QDate& )
00828 {
00829 emitModified();
00830 }
00831
00832 void AddresseeEditorWidget::invalidDate()
00833 {
00834 KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
00835 }
00836
00837 void AddresseeEditorWidget::pageChanged( QWidget *wdg )
00838 {
00839 if ( wdg )
00840 KAcceleratorManager::manage( wdg );
00841 }
00842
00843 void AddresseeEditorWidget::setInitialFocus()
00844 {
00845 mNameEdit->setFocus();
00846 }
00847
00848 bool AddresseeEditorWidget::readyToClose()
00849 {
00850 bool ok = true;
00851
00852 QDate date = mBirthdayPicker->date();
00853 if ( !date.isValid() && !mBirthdayPicker->currentText().isEmpty() ) {
00854 KMessageBox::error( this, i18n( "You have to enter a valid birthdate." ) );
00855 ok = false;
00856 }
00857
00858 date = mAnniversaryPicker->date();
00859 if ( !date.isValid() && !mAnniversaryPicker->currentText().isEmpty() ) {
00860 KMessageBox::error( this, i18n( "You have to enter a valid anniversary." ) );
00861 ok = false;
00862 }
00863
00864 return ok;
00865 }
00866
00867 void AddresseeEditorWidget::setReadOnly( bool readOnly )
00868 {
00869 mReadOnly = readOnly;
00870
00871 mNameEdit->setReadOnly( readOnly );
00872 mRoleEdit->setReadOnly( readOnly );
00873 mOrgEdit->setReadOnly( readOnly );
00874 mPhoneEditWidget->setReadOnly( readOnly );
00875 mAddressEditWidget->setReadOnly( readOnly );
00876 mEmailWidget->setReadOnly( readOnly );
00877 mURLEdit->setReadOnly( readOnly );
00878 mBlogEdit->setReadOnly( readOnly );
00879 mIMWidget->setReadOnly( readOnly );
00880 mCategoryButton->setEnabled( !readOnly );
00881 mSecrecyWidget->setReadOnly( readOnly );
00882 mDepartmentEdit->setReadOnly( readOnly );
00883 mOfficeEdit->setReadOnly( readOnly );
00884 mProfessionEdit->setReadOnly( readOnly );
00885 mManagerEdit->setReadOnly( readOnly );
00886 mAssistantEdit->setReadOnly( readOnly );
00887 mTitleEdit->setReadOnly( readOnly );
00888 mNicknameEdit->setReadOnly( readOnly );
00889 mSpouseEdit->setReadOnly( readOnly );
00890 mBirthdayPicker->setEnabled( !readOnly );
00891 mAnniversaryPicker->setEnabled( !readOnly );
00892 mNoteEdit->setReadOnly( mReadOnly );
00893
00894 QDictIterator<ContactEditorTabPage> it( mTabPages );
00895 for ( ; it.current(); ++it )
00896 it.current()->setReadOnly( readOnly );
00897 }
00898
00899 #include "addresseeeditorwidget.moc"