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 #if KDE_IS_VERSION(3,5,8)
00546 mDepartmentEdit->setText( mAddressee.department() );
00547
00548 if ( mAddressee.department().isEmpty() )
00549 #endif
00550 mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) );
00551 mURLEdit->setURL( mAddressee.url() );
00552 mURLEdit->home( false );
00553 mBlogEdit->setURL( mAddressee.custom( "KADDRESSBOOK", "BlogFeed" ) );
00554 mNoteEdit->setText( mAddressee.note() );
00555 mEmailWidget->setEmails( mAddressee.emails() );
00556 mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
00557 mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
00558 mBirthdayPicker->setDate( mAddressee.birthday().date() );
00559
00560 QString anniversaryStr = mAddressee.custom( "KADDRESSBOOK", "X-Anniversary" );
00561 QDate anniversary = (anniversaryStr.isEmpty() ? QDate() : QDate::fromString( anniversaryStr, Qt::ISODate ));
00562 mAnniversaryPicker->setDate( anniversary );
00563 mNicknameEdit->setText( mAddressee.nickName() );
00564 mCategoryEdit->setText( mAddressee.categories().join( "," ) );
00565
00566 mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
00567
00568
00569 mIMWidget->setPreferredIM( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) );
00570 mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) );
00571 mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) );
00572 mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
00573 mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) );
00574 mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) );
00575 mTitleEdit->setText( mAddressee.title() );
00576
00577 QDictIterator<ContactEditorTabPage> it( mTabPages );
00578 for ( ; it.current(); ++it )
00579 it.current()->loadContact( &mAddressee );
00580
00581 blockSignals( block );
00582 mBlockSignals = false;
00583
00584 mDirty = false;
00585 }
00586
00587 void AddresseeEditorWidget::save()
00588 {
00589 if ( !mDirty ) return;
00590
00591 mAddressee.setRole( mRoleEdit->text() );
00592 mAddressee.setOrganization( mOrgEdit->text() );
00593 #if KDE_IS_VERSION(3,5,8)
00594 mAddressee.setDepartment( mDepartmentEdit->text() );
00595 #else
00596 if ( !mDepartmentEdit->text().isEmpty() )
00597 mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() );
00598 else
00599 mAddressee.removeCustom( "KADDRESSBOOK", "X-Department" );
00600 #endif
00601
00602 QString homepage = mURLEdit->text().stripWhiteSpace();
00603 if ( homepage.isEmpty() )
00604 mAddressee.setUrl( KURL() );
00605 else {
00606 if( !homepage.startsWith("http") )
00607 homepage = "http://" + homepage;
00608 mAddressee.setUrl( KURL( homepage ) );
00609 }
00610 if ( !mBlogEdit->text().isEmpty() )
00611 mAddressee.insertCustom( "KADDRESSBOOK", "BlogFeed", mBlogEdit->text() );
00612 else
00613 mAddressee.removeCustom( "KADDRESSBOOK", "BlogFeed" );
00614
00615 mAddressee.setNote( mNoteEdit->text() );
00616 if ( mBirthdayPicker->date().isValid() )
00617 mAddressee.setBirthday( QDateTime( mBirthdayPicker->date() ) );
00618 else
00619 mAddressee.setBirthday( QDateTime() );
00620
00621 mAddressee.setNickName( mNicknameEdit->text() );
00622 mAddressee.setCategories( QStringList::split( ",", mCategoryEdit->text() ) );
00623
00624 mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
00625
00626
00627 if ( !mIMWidget->preferredIM().isEmpty() )
00628 mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMWidget->preferredIM() );
00629 else
00630 mAddressee.removeCustom( "KADDRESSBOOK", "X-IMAddress" );
00631 if ( !mSpouseEdit->text().isEmpty() )
00632 mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
00633 else
00634 mAddressee.removeCustom( "KADDRESSBOOK", "X-SpousesName" );
00635 if ( !mManagerEdit->text().isEmpty() )
00636 mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
00637 else
00638 mAddressee.removeCustom( "KADDRESSBOOK", "X-ManagersName" );
00639 if ( !mAssistantEdit->text().isEmpty() )
00640 mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
00641 else
00642 mAddressee.removeCustom( "KADDRESSBOOK", "X-AssistantsName" );
00643
00644 if ( !mOfficeEdit->text().isEmpty() )
00645 mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
00646 else
00647 mAddressee.removeCustom( "KADDRESSBOOK", "X-Office" );
00648 if ( !mProfessionEdit->text().isEmpty() )
00649 mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
00650 else
00651 mAddressee.removeCustom( "KADDRESSBOOK", "X-Profession" );
00652
00653 if ( mAnniversaryPicker->date().isValid() )
00654 mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
00655 mAnniversaryPicker->date().toString( Qt::ISODate ) );
00656 else
00657 mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
00658
00659 mAddressee.setTitle( mTitleEdit->text() );
00660
00661
00662 mAddressee.setEmails( mEmailWidget->emails() );
00663
00664
00665 KABC::PhoneNumber::List phoneNumbers;
00666 KABC::PhoneNumber::List::ConstIterator phoneIter;
00667 phoneNumbers = mAddressee.phoneNumbers();
00668 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00669 ++phoneIter )
00670 mAddressee.removePhoneNumber( *phoneIter );
00671
00672 phoneNumbers = mPhoneEditWidget->phoneNumbers();
00673 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00674 ++phoneIter )
00675 mAddressee.insertPhoneNumber( *phoneIter );
00676
00677
00678 KABC::Address::List addresses;
00679 KABC::Address::List::ConstIterator addressIter;
00680 addresses = mAddressee.addresses();
00681 for ( addressIter = addresses.begin(); addressIter != addresses.end();
00682 ++addressIter )
00683 mAddressee.removeAddress( *addressIter );
00684
00685 addresses = mAddressEditWidget->addresses();
00686 for ( addressIter = addresses.begin(); addressIter != addresses.end();
00687 ++addressIter )
00688 mAddressee.insertAddress( *addressIter );
00689
00690 QDictIterator<ContactEditorTabPage> it( mTabPages );
00691 for ( ; it.current(); ++it )
00692 it.current()->storeContact( &mAddressee );
00693
00694 mDirty = false;
00695 }
00696
00697 bool AddresseeEditorWidget::dirty()
00698 {
00699 return mDirty;
00700 }
00701
00702 void AddresseeEditorWidget::nameTextChanged( const QString &text )
00703 {
00704
00705 AddresseeConfig config( mAddressee );
00706 if ( config.automaticNameParsing() ) {
00707 if ( !mAddressee.formattedName().isEmpty() ) {
00708 QString fn = mAddressee.formattedName();
00709 mAddressee.setNameFromString( text );
00710 mAddressee.setFormattedName( fn );
00711 } else {
00712
00713 Addressee addr;
00714 addr.setNameFromString( text );
00715 mAddressee.setPrefix( addr.prefix() );
00716 mAddressee.setGivenName( addr.givenName() );
00717 mAddressee.setAdditionalName( addr.additionalName() );
00718 mAddressee.setFamilyName( addr.familyName() );
00719 mAddressee.setSuffix( addr.suffix() );
00720 }
00721 }
00722
00723 nameBoxChanged();
00724
00725 emitModified();
00726 }
00727
00728 void AddresseeEditorWidget::organizationTextChanged( const QString &text )
00729 {
00730
00731 AddresseeConfig config( mAddressee );
00732 if ( config.automaticNameParsing() )
00733 mAddressee.setOrganization( text );
00734
00735 nameBoxChanged();
00736
00737 mAddressEditWidget->updateAddressee( mAddressee );
00738
00739 emitModified();
00740 }
00741
00742 void AddresseeEditorWidget::nameBoxChanged()
00743 {
00744 KABC::Addressee addr;
00745 AddresseeConfig config( mAddressee );
00746 if ( config.automaticNameParsing() ) {
00747 addr.setNameFromString( mNameEdit->text() );
00748 mNameLabel->hide();
00749 mNameEdit->show();
00750 } else {
00751 addr = mAddressee;
00752 mNameEdit->hide();
00753 mNameLabel->setText( mNameEdit->text() );
00754 mNameLabel->show();
00755 }
00756
00757 if ( mFormattedNameType != NameEditDialog::CustomName ) {
00758 mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00759 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00760 }
00761
00762 mAddressEditWidget->updateAddressee( mAddressee );
00763 }
00764
00765 void AddresseeEditorWidget::nameButtonClicked()
00766 {
00767
00768 NameEditDialog dialog( mAddressee, mFormattedNameType, mReadOnly, this );
00769
00770 if ( dialog.exec() ) {
00771 if ( dialog.changed() ) {
00772 mAddressee.setFamilyName( dialog.familyName() );
00773 mAddressee.setGivenName( dialog.givenName() );
00774 mAddressee.setPrefix( dialog.prefix() );
00775 mAddressee.setSuffix( dialog.suffix() );
00776 mAddressee.setAdditionalName( dialog.additionalName() );
00777 mFormattedNameType = dialog.formattedNameType();
00778 if ( mFormattedNameType == NameEditDialog::CustomName ) {
00779 mFormattedNameLabel->setText( dialog.customFormattedName() );
00780 mAddressee.setFormattedName( dialog.customFormattedName() );
00781 }
00782
00783 bool block = mNameEdit->signalsBlocked();
00784 mNameEdit->blockSignals( true );
00785 mNameEdit->setText( mAddressee.assembledName() );
00786 mNameEdit->blockSignals( block );
00787
00788
00789 nameBoxChanged();
00790
00791 emitModified();
00792 }
00793 }
00794 }
00795
00796 void AddresseeEditorWidget::selectCategories()
00797 {
00798
00799 if ( mCategorySelectDialog == 0 ) {
00800 mCategorySelectDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
00801 connect( mCategorySelectDialog, SIGNAL( categoriesSelected( const QStringList& ) ),
00802 this, SLOT( categoriesSelected( const QStringList& ) ) );
00803 connect( mCategorySelectDialog, SIGNAL( editCategories() ),
00804 this, SLOT( editCategories() ) );
00805 }
00806
00807 mCategorySelectDialog->setSelected( QStringList::split( ",", mCategoryEdit->text() ) );
00808 mCategorySelectDialog->exec();
00809 }
00810
00811 void AddresseeEditorWidget::categoriesSelected( const QStringList &list )
00812 {
00813 mCategoryEdit->setText( list.join( "," ) );
00814 }
00815
00816 void AddresseeEditorWidget::editCategories()
00817 {
00818 if ( mCategoryEditDialog == 0 ) {
00819 mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
00820 connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
00821 mCategorySelectDialog, SLOT( updateCategoryConfig() ) );
00822 }
00823
00824 mCategoryEditDialog->exec();
00825 }
00826
00827 void AddresseeEditorWidget::emitModified()
00828 {
00829 if ( mBlockSignals )
00830 return;
00831
00832 mDirty = true;
00833
00834 emit modified();
00835 }
00836
00837 void AddresseeEditorWidget::dateChanged( const QDate& )
00838 {
00839 emitModified();
00840 }
00841
00842 void AddresseeEditorWidget::invalidDate()
00843 {
00844 KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
00845 }
00846
00847 void AddresseeEditorWidget::pageChanged( QWidget *wdg )
00848 {
00849 if ( wdg )
00850 KAcceleratorManager::manage( wdg );
00851 }
00852
00853 void AddresseeEditorWidget::setInitialFocus()
00854 {
00855 mNameEdit->setFocus();
00856 }
00857
00858 bool AddresseeEditorWidget::readyToClose()
00859 {
00860 bool ok = true;
00861
00862 QDate date = mBirthdayPicker->date();
00863 if ( !date.isValid() && !mBirthdayPicker->currentText().isEmpty() ) {
00864 KMessageBox::error( this, i18n( "You have to enter a valid birthdate." ) );
00865 ok = false;
00866 }
00867
00868 date = mAnniversaryPicker->date();
00869 if ( !date.isValid() && !mAnniversaryPicker->currentText().isEmpty() ) {
00870 KMessageBox::error( this, i18n( "You have to enter a valid anniversary." ) );
00871 ok = false;
00872 }
00873
00874 return ok;
00875 }
00876
00877 void AddresseeEditorWidget::setReadOnly( bool readOnly )
00878 {
00879 mReadOnly = readOnly;
00880
00881 mNameEdit->setReadOnly( readOnly );
00882 mRoleEdit->setReadOnly( readOnly );
00883 mOrgEdit->setReadOnly( readOnly );
00884 mPhoneEditWidget->setReadOnly( readOnly );
00885 mAddressEditWidget->setReadOnly( readOnly );
00886 mEmailWidget->setReadOnly( readOnly );
00887 mURLEdit->setReadOnly( readOnly );
00888 mBlogEdit->setReadOnly( readOnly );
00889 mIMWidget->setReadOnly( readOnly );
00890 mCategoryButton->setEnabled( !readOnly );
00891 mSecrecyWidget->setReadOnly( readOnly );
00892 mDepartmentEdit->setReadOnly( readOnly );
00893 mOfficeEdit->setReadOnly( readOnly );
00894 mProfessionEdit->setReadOnly( readOnly );
00895 mManagerEdit->setReadOnly( readOnly );
00896 mAssistantEdit->setReadOnly( readOnly );
00897 mTitleEdit->setReadOnly( readOnly );
00898 mNicknameEdit->setReadOnly( readOnly );
00899 mSpouseEdit->setReadOnly( readOnly );
00900 mBirthdayPicker->setEnabled( !readOnly );
00901 mAnniversaryPicker->setEnabled( !readOnly );
00902 mNoteEdit->setReadOnly( mReadOnly );
00903
00904 QDictIterator<ContactEditorTabPage> it( mTabPages );
00905 for ( ; it.current(); ++it )
00906 it.current()->setReadOnly( readOnly );
00907 }
00908
00909 #include "addresseeeditorwidget.moc"