24 #include <tqcheckbox.h>
28 #include <tqlistbox.h>
29 #include <tqpushbutton.h>
30 #include <tqtabwidget.h>
31 #include <tqtextedit.h>
32 #include <tqtoolbutton.h>
33 #include <tqtooltip.h>
35 #include <tdeabc/resource.h>
36 #include <tdeabc/stdaddressbook.h>
37 #include <tdeaccelmanager.h>
38 #include <tdeapplication.h>
39 #include <tdeconfig.h>
40 #include <kcombobox.h>
42 #include <kdialogbase.h>
43 #include <tdeglobal.h>
44 #include <kiconloader.h>
45 #include <klineedit.h>
46 #include <tdelocale.h>
47 #include <tdemessagebox.h>
48 #include <kseparator.h>
49 #include <ksqueezedtextlabel.h>
50 #include <kstandarddirs.h>
52 #include <libtdepim/addresseelineedit.h>
53 #include <libtdepim/categoryeditdialog.h>
54 #include <libtdepim/categoryselectdialog.h>
55 #include <libtdepim/kdateedit.h>
56 #include <libtdepim/resourceabc.h>
58 #include "addresseditwidget.h"
59 #include "advancedcustomfields.h"
60 #include "emaileditwidget.h"
61 #include "imeditwidget.h"
63 #include "keywidget.h"
64 #include "nameeditdialog.h"
65 #include "phoneeditwidget.h"
66 #include "secrecywidget.h"
68 #include "addresseeeditorwidget.h"
70 AddresseeEditorWidget::AddresseeEditorWidget( TQWidget *parent,
const char *name )
71 : AddresseeEditorBase( parent, name ),
72 mBlockSignals( false ), mReadOnly( false )
74 kdDebug(5720) <<
"AddresseeEditorWidget()" << endl;
77 mCategorySelectDialog = 0;
78 mCategoryEditDialog = 0;
86 AddresseeEditorWidget::~AddresseeEditorWidget()
88 kdDebug(5720) <<
"~AddresseeEditorWidget()" << endl;
91 void AddresseeEditorWidget::setAddressee(
const TDEABC::Addressee &addr )
93 if ( mAddressee.uid() == addr.uid() )
97 bool readOnly =
false;
98 if ( TDEABC::Resource *res = addr.resource() ) {
99 if ( res->readOnly() ) {
103 }
else if ( res->inherits(
"KPIM::ResourceABC" ) ) {
104 KPIM::ResourceABC *resAbc =
static_cast<KPIM::ResourceABC *
>( res );
106 TQString subresource = resAbc->uidToResourceMap()[ addr.uid() ];
107 if ( !subresource.isEmpty() )
108 readOnly |= !resAbc->subresourceWritable( subresource );
111 setReadOnly( readOnly );
116 const TDEABC::Addressee &AddresseeEditorWidget::addressee()
121 void AddresseeEditorWidget::textChanged(
const TQString& )
126 void AddresseeEditorWidget::initGUI()
128 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
130 mTabWidget =
new TQTabWidget(
this );
131 layout->addWidget( mTabWidget );
135 setupAdditionalTabs();
136 setupCustomFieldsTabs();
138 connect( mTabWidget, TQ_SIGNAL( currentChanged(TQWidget*) ),
139 TQ_SLOT( pageChanged(TQWidget*) ) );
142 void AddresseeEditorWidget::setupTab1()
145 TQWidget *tab1 =
new TQWidget( mTabWidget );
147 TQGridLayout *layout =
new TQGridLayout( tab1, 11, 7 );
148 layout->setMargin( KDialogBase::marginHint() );
149 layout->setSpacing( KDialogBase::spacingHint() );
153 TQPushButton *button;
159 label =
new TQLabel( tab1 );
160 label->setPixmap( TDEGlobal::iconLoader()->loadIcon(
"preferences-desktop-personal", TDEIcon::Desktop,
161 TDEIcon::SizeMedium ) );
162 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
165 button =
new TQPushButton( i18n(
"Edit Name..." ), tab1 );
166 TQToolTip::add( button, i18n(
"Edit the contact's name" ) );
167 mNameEdit =
new KLineEdit( tab1,
"mNameEdit" );
168 connect( mNameEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
169 TQ_SLOT( nameTextChanged(
const TQString& ) ) );
170 connect( button, TQ_SIGNAL( clicked() ), TQ_SLOT( nameButtonClicked() ) );
171 mNameLabel =
new KSqueezedTextLabel( tab1 );
173 if ( KABPrefs::instance()->automaticNameParsing() ) {
181 layout->addWidget( button, 0, 1 );
182 layout->addWidget( mNameEdit, 0, 2 );
183 layout->addWidget( mNameLabel, 0, 2 );
184 label =
new TQLabel( i18n(
"<roleLabel>:",
"%1:" ).arg( TDEABC::Addressee::roleLabel() ), tab1 );
185 mRoleEdit =
new KLineEdit( tab1 );
186 connect( mRoleEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
187 TQ_SLOT( textChanged(
const TQString& ) ) );
188 label->setBuddy( mRoleEdit );
189 layout->addWidget( label, 1, 1 );
190 layout->addWidget( mRoleEdit, 1, 2 );
193 label =
new TQLabel( i18n(
"<organizationLabel>:",
"%1:" ).arg( TDEABC::Addressee::organizationLabel() ), tab1 );
194 mOrgEdit =
new KLineEdit( tab1 );
195 label->setBuddy( mOrgEdit );
196 connect( mOrgEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
197 TQ_SLOT( organizationTextChanged(
const TQString& ) ) );
198 layout->addWidget( label, 2, 1 );
199 layout->addWidget( mOrgEdit, 2, 2 );
202 label =
new TQLabel( i18n(
"Formatted name:" ), tab1 );
203 mFormattedNameLabel =
new KSqueezedTextLabel( tab1 );
204 layout->addWidget( label, 3, 1 );
205 layout->addWidget( mFormattedNameLabel, 3, 2 );
209 bar =
new KSeparator( KSeparator::HLine, tab1 );
210 layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
214 label =
new TQLabel( tab1 );
215 label->setPixmap( TDEGlobal::iconLoader()->loadIcon(
"kaddressbook",
216 TDEIcon::Desktop, TDEIcon::SizeMedium ) );
217 layout->addMultiCellWidget( label, 0, 1, 3, 3 );
220 connect( mPhoneEditWidget, TQ_SIGNAL( modified() ), TQ_SLOT( emitModified() ) );
221 layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 );
223 bar =
new KSeparator( KSeparator::HLine, tab1 );
224 layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
228 label =
new TQLabel( tab1 );
229 label->setPixmap( TDEGlobal::iconLoader()->loadIcon(
"kfm_home", TDEIcon::Desktop,
230 TDEIcon::SizeMedium ) );
231 layout->addMultiCellWidget( label, 5, 6, 0, 0 );
234 connect( mAddressEditWidget, TQ_SIGNAL( modified() ), TQ_SLOT( emitModified() ) );
235 layout->addMultiCellWidget( mAddressEditWidget, 5, 10, 1, 2 );
239 label =
new TQLabel( tab1 );
240 label->setPixmap( TDEGlobal::iconLoader()->loadIcon(
"email", TDEIcon::Desktop,
241 TDEIcon::SizeMedium ) );
242 layout->addMultiCellWidget( label, 5, 6, 3, 3 );
245 connect( mEmailWidget, TQ_SIGNAL( modified() ), TQ_SLOT( emitModified() ) );
246 layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
249 bar =
new KSeparator( KSeparator::HLine, tab1 );
250 layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
252 TQHBoxLayout *homePageLayout =
new TQHBoxLayout( 0, 11, 7 );
254 label =
new TQLabel( tab1 );
255 label->setPixmap( TDEGlobal::iconLoader()->loadIcon(
"homepage", TDEIcon::Desktop,
256 TDEIcon::SizeMedium ) );
257 homePageLayout->addWidget( label );
259 label =
new TQLabel( i18n(
"<urlLabel>:",
"%1:" ).arg( TDEABC::Addressee::urlLabel() ), tab1 );
260 mURLEdit =
new KLineEdit( tab1 );
261 connect( mURLEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
262 TQ_SLOT( textChanged(
const TQString& ) ) );
263 label->setBuddy( mURLEdit );
264 homePageLayout->addWidget( label );
265 homePageLayout->addWidget( mURLEdit );
266 layout->addMultiCellLayout( homePageLayout, 8, 8, 3, 6 );
268 TQHBoxLayout *blogLayout =
new TQHBoxLayout( 0, 11, 7 );
269 label =
new TQLabel( i18n(
"Blog feed:"), tab1 );
270 blogLayout->addWidget( label );
271 mBlogEdit =
new KLineEdit( tab1 );
272 blogLayout->addWidget( mBlogEdit );
273 connect( mBlogEdit, TQ_SIGNAL( textChanged(
const TQString & ) ),
274 TQ_SLOT( textChanged(
const TQString & ) ) );
275 label->setBuddy( mBlogEdit );
276 layout->addMultiCellLayout( blogLayout, 9, 9, 4, 6 );
279 connect( mIMWidget, TQ_SIGNAL( modified() ), TQ_SLOT( emitModified() ) );
280 layout->addMultiCellWidget( mIMWidget, 10, 10, 4, 6 );
282 layout->addColSpacing( 6, 50 );
284 bar =
new KSeparator( KSeparator::HLine, tab1 );
285 layout->addMultiCellWidget( bar, 11, 11, 0, 6 );
288 TQHBox *categoryBox =
new TQHBox( tab1 );
289 categoryBox->setSpacing( KDialogBase::spacingHint() );
292 mCategoryButton =
new TQPushButton( i18n(
"Select Categories..." ), categoryBox );
293 connect( mCategoryButton, TQ_SIGNAL( clicked() ), TQ_SLOT( selectCategories() ) );
295 mCategoryEdit =
new KLineEdit( categoryBox );
296 mCategoryEdit->setReadOnly(
true );
297 connect( mCategoryEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
298 TQ_SLOT( textChanged(
const TQString& ) ) );
300 mSecrecyWidget =
new SecrecyWidget( categoryBox );
301 connect( mSecrecyWidget, TQ_SIGNAL( changed() ), TQ_SLOT( emitModified() ) );
303 layout->addMultiCellWidget( categoryBox, 12, 12, 0, 6 );
308 mTabWidget->addTab( tab1, i18n(
"&General" ) );
311 void AddresseeEditorWidget::setupTab2()
314 TQWidget *tab2 =
new TQWidget( mTabWidget );
316 TQGridLayout *layout =
new TQGridLayout( tab2, 6, 6 );
317 layout->setMargin( KDialogBase::marginHint() );
318 layout->setSpacing( KDialogBase::spacingHint() );
327 label =
new TQLabel( tab2 );
328 label->setPixmap( TDEGlobal::iconLoader()->loadIcon(
"folder", TDEIcon::Desktop,
329 TDEIcon::SizeMedium ) );
330 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
332 label =
new TQLabel( i18n(
"Department:" ), tab2 );
333 layout->addWidget( label, 0, 1 );
334 mDepartmentEdit =
new KLineEdit( tab2 );
335 connect( mDepartmentEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
336 TQ_SLOT( textChanged(
const TQString& ) ) );
337 label->setBuddy( mDepartmentEdit );
338 layout->addWidget( mDepartmentEdit, 0, 2 );
340 label =
new TQLabel( i18n(
"Office:" ), tab2 );
341 layout->addWidget( label, 1, 1 );
342 mOfficeEdit =
new KLineEdit( tab2 );
343 connect( mOfficeEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
344 TQ_SLOT( textChanged(
const TQString& ) ) );
345 label->setBuddy( mOfficeEdit );
346 layout->addWidget( mOfficeEdit, 1, 2 );
348 label =
new TQLabel( i18n(
"Profession:" ), tab2 );
349 layout->addWidget( label, 2, 1 );
350 mProfessionEdit =
new KLineEdit( tab2 );
351 connect( mProfessionEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
352 TQ_SLOT( textChanged(
const TQString& ) ) );
353 label->setBuddy( mProfessionEdit );
354 layout->addWidget( mProfessionEdit, 2, 2 );
356 label =
new TQLabel( i18n(
"Manager\'s name:" ), tab2 );
357 layout->addWidget( label, 0, 3 );
358 mManagerEdit =
new KPIM::AddresseeLineEdit( tab2 );
359 connect( mManagerEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
360 TQ_SLOT( textChanged(
const TQString& ) ) );
361 label->setBuddy( mManagerEdit );
362 layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 );
364 label =
new TQLabel( i18n(
"Assistant's name:" ), tab2 );
365 layout->addWidget( label, 1, 3 );
366 mAssistantEdit =
new KPIM::AddresseeLineEdit( tab2 );
367 connect( mAssistantEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
368 TQ_SLOT( textChanged(
const TQString& ) ) );
369 label->setBuddy( mAssistantEdit );
370 layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 );
372 label =
new TQLabel( i18n(
"<titleLabel>:",
"%1:" ).arg( TDEABC::Addressee::titleLabel() ), tab2 );
373 layout->addWidget( label, 2, 3 );
374 mTitleEdit =
new KLineEdit( tab2 );
375 connect( mTitleEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
376 TQ_SLOT( textChanged(
const TQString& ) ) );
377 label->setBuddy( mTitleEdit );
378 layout->addMultiCellWidget( mTitleEdit, 2, 2, 4, 5 );
380 bar =
new KSeparator( KSeparator::HLine, tab2 );
381 layout->addMultiCellWidget( bar, 3, 3, 0, 5 );
386 label =
new TQLabel( tab2 );
387 label->setPixmap( TDEGlobal::iconLoader()->loadIcon(
"preferences-desktop-personal", TDEIcon::Desktop,
388 TDEIcon::SizeMedium ) );
389 layout->addMultiCellWidget( label, 4, 5, 0, 0 );
391 label =
new TQLabel( i18n(
"Nickname:" ), tab2 );
392 layout->addWidget( label, 4, 1 );
393 mNicknameEdit =
new KLineEdit( tab2 );
394 connect( mNicknameEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
395 TQ_SLOT( textChanged(
const TQString& ) ) );
396 label->setBuddy( mNicknameEdit );
397 layout->addWidget( mNicknameEdit, 4, 2 );
399 label =
new TQLabel( i18n(
"Partner's name:" ), tab2 );
400 layout->addWidget( label, 5, 1 );
401 mSpouseEdit =
new KPIM::AddresseeLineEdit( tab2 );
402 connect( mSpouseEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
403 TQ_SLOT( textChanged(
const TQString& ) ) );
404 label->setBuddy( mSpouseEdit );
405 layout->addWidget( mSpouseEdit, 5, 2 );
407 label =
new TQLabel( i18n(
"Birthdate:" ), tab2 );
408 layout->addWidget( label, 4, 3 );
409 mBirthdayPicker =
new KDateEdit( tab2 );
410 connect( mBirthdayPicker, TQ_SIGNAL( dateChanged(
const TQDate& ) ),
411 TQ_SLOT( dateChanged(
const TQDate& ) ) );
412 connect( mBirthdayPicker, TQ_SIGNAL( textChanged(
const TQString& ) ),
413 TQ_SLOT( emitModified() ) );
414 label->setBuddy( mBirthdayPicker );
415 layout->addWidget( mBirthdayPicker, 4, 4 );
417 label =
new TQLabel( i18n(
"Anniversary:" ), tab2 );
418 layout->addWidget( label, 5, 3 );
419 mAnniversaryPicker =
new KDateEdit( tab2 );
420 connect( mAnniversaryPicker, TQ_SIGNAL( dateChanged(
const TQDate& ) ),
421 TQ_SLOT( dateChanged(
const TQDate& ) ) );
422 connect( mAnniversaryPicker, TQ_SIGNAL( textChanged(
const TQString& ) ),
423 TQ_SLOT( emitModified() ) );
424 label->setBuddy( mAnniversaryPicker );
425 layout->addWidget( mAnniversaryPicker, 5, 4 );
427 bar =
new KSeparator( KSeparator::HLine, tab2 );
428 layout->addMultiCellWidget( bar, 6, 6, 0, 5 );
432 label =
new TQLabel( i18n(
"Note:" ), tab2 );
433 label->setAlignment( TQt::AlignTop | TQt::AlignLeft );
434 layout->addWidget( label, 7, 0 );
435 mNoteEdit =
new TQTextEdit( tab2 );
436 mNoteEdit->setWordWrap( TQTextEdit::WidgetWidth );
437 mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
438 connect( mNoteEdit, TQ_SIGNAL( textChanged() ), TQ_SLOT( emitModified() ) );
439 label->setBuddy( mNoteEdit );
440 layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
445 mTabWidget->addTab( tab2, i18n(
"&Details" ) );
448 void AddresseeEditorWidget::setupAdditionalTabs()
450 ContactEditorWidgetManager *manager = ContactEditorWidgetManager::self();
453 for (
int i = 0; i < manager->count(); ++i ) {
454 TQString pageIdentifier = manager->factory( i )->pageIdentifier();
455 TQString pageTitle = manager->factory( i )->pageTitle();
457 if ( pageIdentifier ==
"misc" )
458 pageTitle = i18n(
"Misc" );
460 ContactEditorTabPage *page = mTabPages[ pageIdentifier ];
462 page =
new ContactEditorTabPage( mTabWidget );
463 mTabPages.insert( pageIdentifier, page );
465 mTabWidget->addTab( page, pageTitle );
467 connect( page, TQ_SIGNAL( changed() ), TQ_SLOT( emitModified() ) );
470 KAB::ContactEditorWidget *widget
471 = manager->factory( i )->createWidget( TDEABC::StdAddressBook::self(
true ),
474 page->addWidget( widget );
478 TQDictIterator<ContactEditorTabPage> it( mTabPages );
479 for ( ; it.current(); ++it )
480 it.current()->updateLayout();
483 void AddresseeEditorWidget::setupCustomFieldsTabs()
485 TQStringList activePages = KABPrefs::instance()->advancedCustomFields();
487 const TQStringList list = TDEGlobal::dirs()->findAllResources(
"data",
"kaddressbook/contacteditorpages/*.ui",
true,
true );
488 for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
489 if ( activePages.find( (*it).mid( (*it).findRev(
'/') + 1 ) ) == activePages.end() )
492 ContactEditorTabPage *page =
new ContactEditorTabPage( mTabWidget );
493 AdvancedCustomFields *wdg =
new AdvancedCustomFields( *it, TDEABC::StdAddressBook::self(
true ), page );
495 mTabPages.insert( wdg->pageIdentifier(), page );
496 mTabWidget->addTab( page, wdg->pageTitle() );
498 page->addWidget( wdg );
499 page->updateLayout();
501 connect( page, TQ_SIGNAL( changed() ), TQ_SLOT( emitModified() ) );
507 void AddresseeEditorWidget::load()
509 kdDebug(5720) <<
"AddresseeEditorWidget::load()" << endl;
513 bool block = signalsBlocked();
514 blockSignals(
true );
515 mBlockSignals =
true;
517 mNameEdit->blockSignals(
true );
518 mNameEdit->setText( mAddressee.assembledName() );
519 mNameEdit->blockSignals(
false );
521 if ( mAddressee.formattedName().isEmpty() ) {
522 TDEConfig config(
"kaddressbookrc" );
523 config.setGroup(
"General" );
524 mFormattedNameType = config.readNumEntry(
"FormattedNameType", 1 );
525 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
527 if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) )
528 mFormattedNameType = NameEditDialog::SimpleName;
529 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) )
530 mFormattedNameType = NameEditDialog::FullName;
531 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseNameWithComma ) )
532 mFormattedNameType = NameEditDialog::ReverseNameWithComma;
533 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) )
534 mFormattedNameType = NameEditDialog::ReverseName;
535 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::Organization ) )
536 mFormattedNameType = NameEditDialog::Organization;
538 mFormattedNameType = NameEditDialog::CustomName;
541 mFormattedNameLabel->setText( mAddressee.formattedName() );
543 mRoleEdit->setText( mAddressee.role() );
544 mOrgEdit->setText( mAddressee.organization() );
545 #if KDE_IS_VERSION(3,5,8)
546 mDepartmentEdit->setText( mAddressee.department() );
548 if ( mAddressee.department().isEmpty() )
550 mDepartmentEdit->setText( mAddressee.custom(
"KADDRESSBOOK",
"X-Department" ) );
551 mURLEdit->setURL( mAddressee.url() );
552 mURLEdit->home(
false );
553 mBlogEdit->setURL( mAddressee.custom(
"KADDRESSBOOK",
"BlogFeed" ) );
554 mNoteEdit->setText( mAddressee.note() );
555 mEmailWidget->setEmails( mAddressee.emails() );
556 mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
557 mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
558 mBirthdayPicker->setDate( mAddressee.birthday().date() );
560 TQString anniversaryStr = mAddressee.custom(
"KADDRESSBOOK",
"X-Anniversary" );
561 TQDate anniversary = (anniversaryStr.isEmpty() ? TQDate() : TQDate::fromString( anniversaryStr, TQt::ISODate ));
562 mAnniversaryPicker->setDate( anniversary );
563 mNicknameEdit->setText( mAddressee.nickName() );
564 mCategoryEdit->setText( mAddressee.categories().join(
"," ) );
566 mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
569 mIMWidget->setPreferredIM( mAddressee.custom(
"KADDRESSBOOK",
"X-IMAddress" ) );
570 mSpouseEdit->setText( mAddressee.custom(
"KADDRESSBOOK",
"X-SpousesName" ) );
571 mManagerEdit->setText( mAddressee.custom(
"KADDRESSBOOK",
"X-ManagersName" ) );
572 mAssistantEdit->setText( mAddressee.custom(
"KADDRESSBOOK",
"X-AssistantsName" ) );
573 mOfficeEdit->setText( mAddressee.custom(
"KADDRESSBOOK",
"X-Office" ) );
574 mProfessionEdit->setText( mAddressee.custom(
"KADDRESSBOOK",
"X-Profession" ) );
575 mTitleEdit->setText( mAddressee.title() );
577 TQDictIterator<ContactEditorTabPage> it( mTabPages );
578 for ( ; it.current(); ++it )
579 it.current()->loadContact( &mAddressee );
581 blockSignals( block );
582 mBlockSignals =
false;
587 void AddresseeEditorWidget::save()
589 if ( !mDirty )
return;
591 mAddressee.setRole( mRoleEdit->text() );
592 mAddressee.setOrganization( mOrgEdit->text() );
593 #if KDE_IS_VERSION(3,5,8)
594 mAddressee.setDepartment( mDepartmentEdit->text() );
596 if ( !mDepartmentEdit->text().isEmpty() )
597 mAddressee.insertCustom(
"KADDRESSBOOK",
"X-Department", mDepartmentEdit->text() );
599 mAddressee.removeCustom(
"KADDRESSBOOK",
"X-Department" );
602 TQString homepage = mURLEdit->text().stripWhiteSpace();
603 if ( homepage.isEmpty() )
604 mAddressee.setUrl( KURL() );
606 if( !homepage.startsWith(
"http") )
607 homepage =
"http://" + homepage;
608 mAddressee.setUrl( KURL( homepage ) );
610 if ( !mBlogEdit->text().isEmpty() )
611 mAddressee.insertCustom(
"KADDRESSBOOK",
"BlogFeed", mBlogEdit->text() );
613 mAddressee.removeCustom(
"KADDRESSBOOK",
"BlogFeed" );
615 mAddressee.setNote( mNoteEdit->text() );
616 if ( mBirthdayPicker->date().isValid() )
617 mAddressee.setBirthday( TQDateTime( mBirthdayPicker->date() ) );
619 mAddressee.setBirthday( TQDateTime() );
621 mAddressee.setNickName( mNicknameEdit->text() );
622 mAddressee.setCategories( TQStringList::split(
",", mCategoryEdit->text() ) );
624 mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
627 if ( !mIMWidget->preferredIM().isEmpty() )
628 mAddressee.insertCustom(
"KADDRESSBOOK",
"X-IMAddress", mIMWidget->preferredIM() );
630 mAddressee.removeCustom(
"KADDRESSBOOK",
"X-IMAddress" );
631 if ( !mSpouseEdit->text().isEmpty() )
632 mAddressee.insertCustom(
"KADDRESSBOOK",
"X-SpousesName", mSpouseEdit->text() );
634 mAddressee.removeCustom(
"KADDRESSBOOK",
"X-SpousesName" );
635 if ( !mManagerEdit->text().isEmpty() )
636 mAddressee.insertCustom(
"KADDRESSBOOK",
"X-ManagersName", mManagerEdit->text() );
638 mAddressee.removeCustom(
"KADDRESSBOOK",
"X-ManagersName" );
639 if ( !mAssistantEdit->text().isEmpty() )
640 mAddressee.insertCustom(
"KADDRESSBOOK",
"X-AssistantsName", mAssistantEdit->text() );
642 mAddressee.removeCustom(
"KADDRESSBOOK",
"X-AssistantsName" );
644 if ( !mOfficeEdit->text().isEmpty() )
645 mAddressee.insertCustom(
"KADDRESSBOOK",
"X-Office", mOfficeEdit->text() );
647 mAddressee.removeCustom(
"KADDRESSBOOK",
"X-Office" );
648 if ( !mProfessionEdit->text().isEmpty() )
649 mAddressee.insertCustom(
"KADDRESSBOOK",
"X-Profession", mProfessionEdit->text() );
651 mAddressee.removeCustom(
"KADDRESSBOOK",
"X-Profession" );
653 if ( mAnniversaryPicker->date().isValid() )
654 mAddressee.insertCustom(
"KADDRESSBOOK",
"X-Anniversary",
655 mAnniversaryPicker->date().toString( TQt::ISODate ) );
657 mAddressee.removeCustom(
"KADDRESSBOOK",
"X-Anniversary" );
659 mAddressee.setTitle( mTitleEdit->text() );
662 mAddressee.setEmails( mEmailWidget->emails() );
665 TDEABC::PhoneNumber::List phoneNumbers;
666 TDEABC::PhoneNumber::List::ConstIterator phoneIter;
667 phoneNumbers = mAddressee.phoneNumbers();
668 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
670 mAddressee.removePhoneNumber( *phoneIter );
672 phoneNumbers = mPhoneEditWidget->phoneNumbers();
673 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
675 mAddressee.insertPhoneNumber( *phoneIter );
678 TDEABC::Address::List addresses;
679 TDEABC::Address::List::ConstIterator addressIter;
680 addresses = mAddressee.addresses();
681 for ( addressIter = addresses.begin(); addressIter != addresses.end();
683 mAddressee.removeAddress( *addressIter );
685 addresses = mAddressEditWidget->addresses();
686 for ( addressIter = addresses.begin(); addressIter != addresses.end();
688 mAddressee.insertAddress( *addressIter );
690 TQDictIterator<ContactEditorTabPage> it( mTabPages );
691 for ( ; it.current(); ++it )
692 it.current()->storeContact( &mAddressee );
697 bool AddresseeEditorWidget::dirty()
702 void AddresseeEditorWidget::nameTextChanged(
const TQString &text )
705 AddresseeConfig config( mAddressee );
706 if ( config.automaticNameParsing() ) {
707 if ( !mAddressee.formattedName().isEmpty() ) {
708 TQString fn = mAddressee.formattedName();
709 mAddressee.setNameFromString( text );
710 mAddressee.setFormattedName( fn );
714 addr.setNameFromString( text );
715 mAddressee.setPrefix( addr.prefix() );
716 mAddressee.setGivenName( addr.givenName() );
717 mAddressee.setAdditionalName( addr.additionalName() );
718 mAddressee.setFamilyName( addr.familyName() );
719 mAddressee.setSuffix( addr.suffix() );
728 void AddresseeEditorWidget::organizationTextChanged(
const TQString &text )
731 AddresseeConfig config( mAddressee );
732 if ( config.automaticNameParsing() )
733 mAddressee.setOrganization( text );
737 mAddressEditWidget->updateAddressee( mAddressee );
742 void AddresseeEditorWidget::nameBoxChanged()
744 TDEABC::Addressee addr;
745 AddresseeConfig config( mAddressee );
746 if ( config.automaticNameParsing() ) {
747 addr.setNameFromString( mNameEdit->text() );
753 mNameLabel->setText( mNameEdit->text() );
757 if ( mFormattedNameType != NameEditDialog::CustomName ) {
758 mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
759 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
762 mAddressEditWidget->updateAddressee( mAddressee );
765 void AddresseeEditorWidget::nameButtonClicked()
768 NameEditDialog dialog( mAddressee, mFormattedNameType, mReadOnly,
this );
770 if ( dialog.exec() ) {
771 if ( dialog.changed() ) {
772 mAddressee.setFamilyName( dialog.familyName() );
773 mAddressee.setGivenName( dialog.givenName() );
774 mAddressee.setPrefix( dialog.prefix() );
775 mAddressee.setSuffix( dialog.suffix() );
776 mAddressee.setAdditionalName( dialog.additionalName() );
777 mFormattedNameType = dialog.formattedNameType();
778 if ( mFormattedNameType == NameEditDialog::CustomName ) {
779 mFormattedNameLabel->setText( dialog.customFormattedName() );
780 mAddressee.setFormattedName( dialog.customFormattedName() );
783 bool block = mNameEdit->signalsBlocked();
784 mNameEdit->blockSignals(
true );
785 mNameEdit->setText( mAddressee.assembledName() );
786 mNameEdit->blockSignals( block );
796 void AddresseeEditorWidget::selectCategories()
799 if ( mCategorySelectDialog == 0 ) {
800 mCategorySelectDialog =
new KPIM::CategorySelectDialog( KABPrefs::instance(),
this );
801 connect( mCategorySelectDialog, TQ_SIGNAL( categoriesSelected(
const TQStringList& ) ),
802 this, TQ_SLOT( categoriesSelected(
const TQStringList& ) ) );
803 connect( mCategorySelectDialog, TQ_SIGNAL( editCategories() ),
804 this, TQ_SLOT( editCategories() ) );
807 mCategorySelectDialog->setSelected( TQStringList::split(
",", mCategoryEdit->text() ) );
808 mCategorySelectDialog->exec();
811 void AddresseeEditorWidget::categoriesSelected(
const TQStringList &list )
813 mCategoryEdit->setText( list.join(
"," ) );
816 void AddresseeEditorWidget::editCategories()
818 if ( mCategoryEditDialog == 0 ) {
819 mCategoryEditDialog =
new KPIM::CategoryEditDialog( KABPrefs::instance(),
this );
820 connect( mCategoryEditDialog, TQ_SIGNAL( categoryConfigChanged() ),
821 mCategorySelectDialog, TQ_SLOT( updateCategoryConfig() ) );
824 mCategoryEditDialog->exec();
827 void AddresseeEditorWidget::emitModified()
837 void AddresseeEditorWidget::dateChanged(
const TQDate& )
842 void AddresseeEditorWidget::invalidDate()
844 KMessageBox::sorry(
this, i18n(
"You must specify a valid date" ) );
847 void AddresseeEditorWidget::pageChanged( TQWidget *wdg )
850 TDEAcceleratorManager::manage( wdg );
853 void AddresseeEditorWidget::setInitialFocus()
855 mNameEdit->setFocus();
858 bool AddresseeEditorWidget::readyToClose()
862 TQDate date = mBirthdayPicker->date();
863 if ( !date.isValid() && !mBirthdayPicker->currentText().isEmpty() ) {
864 KMessageBox::error(
this, i18n(
"You have to enter a valid birthdate." ) );
868 date = mAnniversaryPicker->date();
869 if ( !date.isValid() && !mAnniversaryPicker->currentText().isEmpty() ) {
870 KMessageBox::error(
this, i18n(
"You have to enter a valid anniversary." ) );
877 void AddresseeEditorWidget::setReadOnly(
bool readOnly )
879 mReadOnly = readOnly;
881 mNameEdit->setReadOnly( readOnly );
882 mRoleEdit->setReadOnly( readOnly );
883 mOrgEdit->setReadOnly( readOnly );
884 mPhoneEditWidget->setReadOnly( readOnly );
885 mAddressEditWidget->setReadOnly( readOnly );
886 mEmailWidget->setReadOnly( readOnly );
887 mURLEdit->setReadOnly( readOnly );
888 mBlogEdit->setReadOnly( readOnly );
889 mIMWidget->setReadOnly( readOnly );
890 mCategoryButton->setEnabled( !readOnly );
891 mSecrecyWidget->setReadOnly( readOnly );
892 mDepartmentEdit->setReadOnly( readOnly );
893 mOfficeEdit->setReadOnly( readOnly );
894 mProfessionEdit->setReadOnly( readOnly );
895 mManagerEdit->setReadOnly( readOnly );
896 mAssistantEdit->setReadOnly( readOnly );
897 mTitleEdit->setReadOnly( readOnly );
898 mNicknameEdit->setReadOnly( readOnly );
899 mSpouseEdit->setReadOnly( readOnly );
900 mBirthdayPicker->setEnabled( !readOnly );
901 mAnniversaryPicker->setEnabled( !readOnly );
902 mNoteEdit->setReadOnly( mReadOnly );
904 TQDictIterator<ContactEditorTabPage> it( mTabPages );
905 for ( ; it.current(); ++it )
906 it.current()->setReadOnly( readOnly );
909 #include "addresseeeditorwidget.moc"
Editor dialog for name details, like given name, family name etc.