kaddressbook

addresseeeditorwidget.cpp
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of TQt, and distribute the resulting executable,
21 without including the source code for TQt in the source distribution.
22*/
23
24#include <tqcheckbox.h>
25#include <tqhbox.h>
26#include <tqlabel.h>
27#include <tqlayout.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>
34
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>
41#include <kdebug.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 <tdestandarddirs.h>
51
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>
57
58#include "addresseditwidget.h"
59#include "advancedcustomfields.h"
60#include "emaileditwidget.h"
61#include "imeditwidget.h"
62#include "kabprefs.h"
63#include "keywidget.h"
64#include "nameeditdialog.h"
65#include "phoneeditwidget.h"
66#include "secrecywidget.h"
67
68#include "addresseeeditorwidget.h"
69
70AddresseeEditorWidget::AddresseeEditorWidget( TQWidget *parent, const char *name )
71 : AddresseeEditorBase( parent, name ),
72 mBlockSignals( false ), mReadOnly( false )
73{
74 kdDebug(5720) << "AddresseeEditorWidget()" << endl;
75
76 initGUI();
77 mCategorySelectDialog = 0;
78 mCategoryEditDialog = 0;
79
80 // Load the empty addressee as defaults
81 load();
82
83 mDirty = false;
84}
85
86AddresseeEditorWidget::~AddresseeEditorWidget()
87{
88 kdDebug(5720) << "~AddresseeEditorWidget()" << endl;
89}
90
91void AddresseeEditorWidget::setAddressee( const TDEABC::Addressee &addr )
92{
93 if ( mAddressee.uid() == addr.uid() )
94 return;
95 mAddressee = addr;
96
97 bool readOnly = false;
98 if ( TDEABC::Resource *res = addr.resource() ) {
99 if ( res->readOnly() ) {
100 readOnly = true;
101
102 //Kolab resources have finer access control than planned in the overall design.
103 } else if ( res->inherits( "KPIM::ResourceABC" ) ) {
104 KPIM::ResourceABC *resAbc = static_cast<KPIM::ResourceABC *>( res );
105
106 TQString subresource = resAbc->uidToResourceMap()[ addr.uid() ];
107 if ( !subresource.isEmpty() )
108 readOnly |= !resAbc->subresourceWritable( subresource );
109 }
110 }
111 setReadOnly( readOnly );
112
113 load();
114}
115
116const TDEABC::Addressee &AddresseeEditorWidget::addressee()
117{
118 return mAddressee;
119}
120
121void AddresseeEditorWidget::textChanged( const TQString& )
122{
123 emitModified();
124}
125
126void AddresseeEditorWidget::initGUI()
127{
128 TQVBoxLayout *layout = new TQVBoxLayout( this );
129
130 mTabWidget = new TQTabWidget( this );
131 layout->addWidget( mTabWidget );
132
133 setupTab1();
134 setupTab2();
135 setupAdditionalTabs();
136 setupCustomFieldsTabs();
137
138 connect( mTabWidget, TQ_SIGNAL( currentChanged(TQWidget*) ),
139 TQ_SLOT( pageChanged(TQWidget*) ) );
140}
141
142void AddresseeEditorWidget::setupTab1()
143{
144 // This is the General tab
145 TQWidget *tab1 = new TQWidget( mTabWidget );
146
147 TQGridLayout *layout = new TQGridLayout( tab1, 11, 7 );
148 layout->setMargin( KDialogBase::marginHint() );
149 layout->setSpacing( KDialogBase::spacingHint() );
150
151 TQLabel *label;
152 KSeparator* bar;
153 TQPushButton *button;
154
156 // Upper left group (person info)
157
158 // Person icon
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 );
163
164 // First name
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 );
172
173 if ( KABPrefs::instance()->automaticNameParsing() ) {
174 mNameLabel->hide();
175 mNameEdit->show();
176 } else {
177 mNameEdit->hide();
178 mNameLabel->show();
179 }
180
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 );
191
192 // Organization
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 );
200
201 // File as (formatted name)
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 );
206
207 // Left hand separator. This separator doesn't go all the way
208 // across so the dialog still flows from top to bottom
209 bar = new KSeparator( KSeparator::HLine, tab1 );
210 layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
211
213 // Phone numbers (upper right)
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 );
218
219 mPhoneEditWidget = new PhoneEditWidget( tab1 );
220 connect( mPhoneEditWidget, TQ_SIGNAL( modified() ), TQ_SLOT( emitModified() ) );
221 layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 );
222
223 bar = new KSeparator( KSeparator::HLine, tab1 );
224 layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
225
227 // Addresses (lower left)
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 );
232
233 mAddressEditWidget = new AddressEditWidget( tab1 );
234 connect( mAddressEditWidget, TQ_SIGNAL( modified() ), TQ_SLOT( emitModified() ) );
235 layout->addMultiCellWidget( mAddressEditWidget, 5, 10, 1, 2 );
236
238 // Email / Web (lower right)
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 );
243
244 mEmailWidget = new EmailEditWidget( tab1 );
245 connect( mEmailWidget, TQ_SIGNAL( modified() ), TQ_SLOT( emitModified() ) );
246 layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
247
248 // add the separator
249 bar = new KSeparator( KSeparator::HLine, tab1 );
250 layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
251
252 TQHBoxLayout *homePageLayout = new TQHBoxLayout( 0, 11, 7 );
253
254 label = new TQLabel( tab1 );
255 label->setPixmap( TDEGlobal::iconLoader()->loadIcon( "homepage", TDEIcon::Desktop,
256 TDEIcon::SizeMedium ) );
257 homePageLayout->addWidget( label );
258
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 );
267
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 );
277
278 mIMWidget = new IMEditWidget( tab1, mAddressee );
279 connect( mIMWidget, TQ_SIGNAL( modified() ), TQ_SLOT( emitModified() ) );
280 layout->addMultiCellWidget( mIMWidget, 10, 10, 4, 6 );
281
282 layout->addColSpacing( 6, 50 );
283
284 bar = new KSeparator( KSeparator::HLine, tab1 );
285 layout->addMultiCellWidget( bar, 11, 11, 0, 6 );
286
288 TQHBox *categoryBox = new TQHBox( tab1 );
289 categoryBox->setSpacing( KDialogBase::spacingHint() );
290
291 // Categories
292 mCategoryButton = new TQPushButton( i18n( "Select Categories..." ), categoryBox );
293 connect( mCategoryButton, TQ_SIGNAL( clicked() ), TQ_SLOT( selectCategories() ) );
294
295 mCategoryEdit = new KLineEdit( categoryBox );
296 mCategoryEdit->setReadOnly( true );
297 connect( mCategoryEdit, TQ_SIGNAL( textChanged( const TQString& ) ),
298 TQ_SLOT( textChanged( const TQString& ) ) );
299
300 mSecrecyWidget = new SecrecyWidget( categoryBox );
301 connect( mSecrecyWidget, TQ_SIGNAL( changed() ), TQ_SLOT( emitModified() ) );
302
303 layout->addMultiCellWidget( categoryBox, 12, 12, 0, 6 );
304
305 // Build the layout and add to the tab widget
306 layout->activate(); // required
307
308 mTabWidget->addTab( tab1, i18n( "&General" ) );
309}
310
311void AddresseeEditorWidget::setupTab2()
312{
313 // This is the Details tab
314 TQWidget *tab2 = new TQWidget( mTabWidget );
315
316 TQGridLayout *layout = new TQGridLayout( tab2, 6, 6 );
317 layout->setMargin( KDialogBase::marginHint() );
318 layout->setSpacing( KDialogBase::spacingHint() );
319
320 TQLabel *label;
321 KSeparator* bar;
322
324 // Office info
325
326 // Department
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 );
331
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 );
339
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 );
347
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 );
355
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 );
363
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 );
371
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 );
379
380 bar = new KSeparator( KSeparator::HLine, tab2 );
381 layout->addMultiCellWidget( bar, 3, 3, 0, 5 );
382
384 // Personal info
385
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 );
390
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 );
398
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 );
406
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 );
416
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 );
426
427 bar = new KSeparator( KSeparator::HLine, tab2 );
428 layout->addMultiCellWidget( bar, 6, 6, 0, 5 );
429
431 // Notes
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 );
441
442 // Build the layout and add to the tab widget
443 layout->activate(); // required
444
445 mTabWidget->addTab( tab2, i18n( "&Details" ) );
446}
447
448void AddresseeEditorWidget::setupAdditionalTabs()
449{
450 ContactEditorWidgetManager *manager = ContactEditorWidgetManager::self();
451
452 // create all tab pages and add the widgets
453 for ( int i = 0; i < manager->count(); ++i ) {
454 TQString pageIdentifier = manager->factory( i )->pageIdentifier();
455 TQString pageTitle = manager->factory( i )->pageTitle();
456
457 if ( pageIdentifier == "misc" )
458 pageTitle = i18n( "Misc" );
459
460 ContactEditorTabPage *page = mTabPages[ pageIdentifier ];
461 if ( page == 0 ) { // tab not yet available, create one
462 page = new ContactEditorTabPage( mTabWidget );
463 mTabPages.insert( pageIdentifier, page );
464
465 mTabWidget->addTab( page, pageTitle );
466
467 connect( page, TQ_SIGNAL( changed() ), TQ_SLOT( emitModified() ) );
468 }
469
470 KAB::ContactEditorWidget *widget
471 = manager->factory( i )->createWidget( TDEABC::StdAddressBook::self( true ),
472 page );
473 if ( widget )
474 page->addWidget( widget );
475 }
476
477 // query the layout update
478 TQDictIterator<ContactEditorTabPage> it( mTabPages );
479 for ( ; it.current(); ++it )
480 it.current()->updateLayout();
481}
482
483void AddresseeEditorWidget::setupCustomFieldsTabs()
484{
485 TQStringList activePages = KABPrefs::instance()->advancedCustomFields();
486
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() )
490 continue;
491
492 ContactEditorTabPage *page = new ContactEditorTabPage( mTabWidget );
493 AdvancedCustomFields *wdg = new AdvancedCustomFields( *it, TDEABC::StdAddressBook::self( true ), page );
494 if ( wdg ) {
495 mTabPages.insert( wdg->pageIdentifier(), page );
496 mTabWidget->addTab( page, wdg->pageTitle() );
497
498 page->addWidget( wdg );
499 page->updateLayout();
500
501 connect( page, TQ_SIGNAL( changed() ), TQ_SLOT( emitModified() ) );
502 } else
503 delete page;
504 }
505}
506
507void AddresseeEditorWidget::load()
508{
509 kdDebug(5720) << "AddresseeEditorWidget::load()" << endl;
510
511 // Block signals in case anything tries to emit modified
512 // CS: This doesn't seem to work.
513 bool block = signalsBlocked();
514 blockSignals( true );
515 mBlockSignals = true; // used for internal signal blocking
516
517 mNameEdit->blockSignals( true );
518 mNameEdit->setText( mAddressee.assembledName() );
519 mNameEdit->blockSignals( false );
520
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 ) );
526 } else {
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;
537 else
538 mFormattedNameType = NameEditDialog::CustomName;
539 }
540
541 mFormattedNameLabel->setText( mAddressee.formattedName() );
542
543 mRoleEdit->setText( mAddressee.role() );
544 mOrgEdit->setText( mAddressee.organization() );
545 mDepartmentEdit->setText( mAddressee.department() );
546 // compatibility with older versions
547 if ( mAddressee.department().isEmpty() )
548 mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) );
549 mURLEdit->setURL( mAddressee.url() );
550 mURLEdit->home( false );
551 mBlogEdit->setURL( mAddressee.custom( "KADDRESSBOOK", "BlogFeed" ) );
552 mNoteEdit->setText( mAddressee.note() );
553 mEmailWidget->setEmails( mAddressee.emails() );
554 mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
555 mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
556 mBirthdayPicker->setDate( mAddressee.birthday().date() );
557
558 TQString anniversaryStr = mAddressee.custom( "KADDRESSBOOK", "X-Anniversary" );
559 TQDate anniversary = (anniversaryStr.isEmpty() ? TQDate() : TQDate::fromString( anniversaryStr, TQt::ISODate ));
560 mAnniversaryPicker->setDate( anniversary );
561 mNicknameEdit->setText( mAddressee.nickName() );
562 mCategoryEdit->setText( mAddressee.categories().join( "," ) );
563
564 mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
565
566 // Load customs
567 mIMWidget->setPreferredIM( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) );
568 mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) );
569 mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) );
570 mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
571 mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) );
572 mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) );
573 mTitleEdit->setText( mAddressee.title() );
574
575 TQDictIterator<ContactEditorTabPage> it( mTabPages );
576 for ( ; it.current(); ++it )
577 it.current()->loadContact( &mAddressee );
578
579 blockSignals( block );
580 mBlockSignals = false;
581
582 mDirty = false;
583}
584
585void AddresseeEditorWidget::save()
586{
587 if ( !mDirty ) return;
588
589 mAddressee.setRole( mRoleEdit->text() );
590 mAddressee.setOrganization( mOrgEdit->text() );
591 mAddressee.setDepartment( mDepartmentEdit->text() );
592
593 TQString homepage = mURLEdit->text().stripWhiteSpace();
594 if ( homepage.isEmpty() )
595 mAddressee.setUrl( KURL() );
596 else {
597 if( !homepage.startsWith("http") )
598 homepage = "http://" + homepage;
599 mAddressee.setUrl( KURL( homepage ) );
600 }
601 if ( !mBlogEdit->text().isEmpty() )
602 mAddressee.insertCustom( "KADDRESSBOOK", "BlogFeed", mBlogEdit->text() );
603 else
604 mAddressee.removeCustom( "KADDRESSBOOK", "BlogFeed" );
605
606 mAddressee.setNote( mNoteEdit->text() );
607 if ( mBirthdayPicker->date().isValid() )
608 mAddressee.setBirthday( TQDateTime( mBirthdayPicker->date() ) );
609 else
610 mAddressee.setBirthday( TQDateTime() );
611
612 mAddressee.setNickName( mNicknameEdit->text() );
613 mAddressee.setCategories( TQStringList::split( ",", mCategoryEdit->text() ) );
614
615 mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
616
617 // save custom fields
618 if ( !mIMWidget->preferredIM().isEmpty() )
619 mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMWidget->preferredIM() );
620 else
621 mAddressee.removeCustom( "KADDRESSBOOK", "X-IMAddress" );
622 if ( !mSpouseEdit->text().isEmpty() )
623 mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
624 else
625 mAddressee.removeCustom( "KADDRESSBOOK", "X-SpousesName" );
626 if ( !mManagerEdit->text().isEmpty() )
627 mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
628 else
629 mAddressee.removeCustom( "KADDRESSBOOK", "X-ManagersName" );
630 if ( !mAssistantEdit->text().isEmpty() )
631 mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
632 else
633 mAddressee.removeCustom( "KADDRESSBOOK", "X-AssistantsName" );
634
635 if ( !mOfficeEdit->text().isEmpty() )
636 mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
637 else
638 mAddressee.removeCustom( "KADDRESSBOOK", "X-Office" );
639 if ( !mProfessionEdit->text().isEmpty() )
640 mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
641 else
642 mAddressee.removeCustom( "KADDRESSBOOK", "X-Profession" );
643
644 if ( mAnniversaryPicker->date().isValid() )
645 mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
646 mAnniversaryPicker->date().toString( TQt::ISODate ) );
647 else
648 mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
649
650 mAddressee.setTitle( mTitleEdit->text() );
651
652 // Save the email addresses
653 mAddressee.setEmails( mEmailWidget->emails() );
654
655 // Save the phone numbers
656 TDEABC::PhoneNumber::List phoneNumbers;
657 TDEABC::PhoneNumber::List::ConstIterator phoneIter;
658 phoneNumbers = mAddressee.phoneNumbers();
659 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
660 ++phoneIter )
661 mAddressee.removePhoneNumber( *phoneIter );
662
663 phoneNumbers = mPhoneEditWidget->phoneNumbers();
664 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
665 ++phoneIter )
666 mAddressee.insertPhoneNumber( *phoneIter );
667
668 // Save the addresses
669 TDEABC::Address::List addresses;
670 TDEABC::Address::List::ConstIterator addressIter;
671 addresses = mAddressee.addresses();
672 for ( addressIter = addresses.begin(); addressIter != addresses.end();
673 ++addressIter )
674 mAddressee.removeAddress( *addressIter );
675
676 addresses = mAddressEditWidget->addresses();
677 for ( addressIter = addresses.begin(); addressIter != addresses.end();
678 ++addressIter )
679 mAddressee.insertAddress( *addressIter );
680
681 TQDictIterator<ContactEditorTabPage> it( mTabPages );
682 for ( ; it.current(); ++it )
683 it.current()->storeContact( &mAddressee );
684
685 mDirty = false;
686}
687
688bool AddresseeEditorWidget::dirty()
689{
690 return mDirty;
691}
692
693void AddresseeEditorWidget::nameTextChanged( const TQString &text )
694{
695 // use the addressee class to parse the name for us
696 AddresseeConfig config( mAddressee );
697 if ( config.automaticNameParsing() ) {
698 if ( !mAddressee.formattedName().isEmpty() ) {
699 TQString fn = mAddressee.formattedName();
700 mAddressee.setNameFromString( text );
701 mAddressee.setFormattedName( fn );
702 } else {
703 // use extra addressee to avoid a formatted name assignment
704 Addressee addr;
705 addr.setNameFromString( text );
706 mAddressee.setPrefix( addr.prefix() );
707 mAddressee.setGivenName( addr.givenName() );
708 mAddressee.setAdditionalName( addr.additionalName() );
709 mAddressee.setFamilyName( addr.familyName() );
710 mAddressee.setSuffix( addr.suffix() );
711 }
712 }
713
714 nameBoxChanged();
715
716 emitModified();
717}
718
719void AddresseeEditorWidget::organizationTextChanged( const TQString &text )
720{
721
722 AddresseeConfig config( mAddressee );
723 if ( config.automaticNameParsing() )
724 mAddressee.setOrganization( text );
725
726 nameBoxChanged();
727
728 mAddressEditWidget->updateAddressee( mAddressee );
729
730 emitModified();
731}
732
733void AddresseeEditorWidget::nameBoxChanged()
734{
735 TDEABC::Addressee addr;
736 AddresseeConfig config( mAddressee );
737 if ( config.automaticNameParsing() ) {
738 addr.setNameFromString( mNameEdit->text() );
739 mNameLabel->hide();
740 mNameEdit->show();
741 } else {
742 addr = mAddressee;
743 mNameEdit->hide();
744 mNameLabel->setText( mNameEdit->text() );
745 mNameLabel->show();
746 }
747
748 if ( mFormattedNameType != NameEditDialog::CustomName ) {
749 mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
750 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
751 }
752
753 mAddressEditWidget->updateAddressee( mAddressee );
754}
755
756void AddresseeEditorWidget::nameButtonClicked()
757{
758 // show the name dialog.
759 NameEditDialog dialog( mAddressee, mFormattedNameType, mReadOnly, this );
760
761 if ( dialog.exec() ) {
762 if ( dialog.changed() ) {
763 mAddressee.setFamilyName( dialog.familyName() );
764 mAddressee.setGivenName( dialog.givenName() );
765 mAddressee.setPrefix( dialog.prefix() );
766 mAddressee.setSuffix( dialog.suffix() );
767 mAddressee.setAdditionalName( dialog.additionalName() );
768 mFormattedNameType = dialog.formattedNameType();
769 if ( mFormattedNameType == NameEditDialog::CustomName ) {
770 mFormattedNameLabel->setText( dialog.customFormattedName() );
771 mAddressee.setFormattedName( dialog.customFormattedName() );
772 }
773 // Update the name edit.
774 bool block = mNameEdit->signalsBlocked();
775 mNameEdit->blockSignals( true );
776 mNameEdit->setText( mAddressee.assembledName() );
777 mNameEdit->blockSignals( block );
778
779 // Update the combo box.
780 nameBoxChanged();
781
782 emitModified();
783 }
784 }
785}
786
787void AddresseeEditorWidget::selectCategories()
788{
789 // Show the category dialog
790 if ( mCategorySelectDialog == 0 ) {
791 mCategorySelectDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
792 connect( mCategorySelectDialog, TQ_SIGNAL( categoriesSelected( const TQStringList& ) ),
793 this, TQ_SLOT( categoriesSelected( const TQStringList& ) ) );
794 connect( mCategorySelectDialog, TQ_SIGNAL( editCategories() ),
795 this, TQ_SLOT( editCategories() ) );
796 }
797
798 mCategorySelectDialog->setSelected( TQStringList::split( ",", mCategoryEdit->text() ) );
799 mCategorySelectDialog->exec();
800}
801
802void AddresseeEditorWidget::categoriesSelected( const TQStringList &list )
803{
804 mCategoryEdit->setText( list.join( "," ) );
805}
806
807void AddresseeEditorWidget::editCategories()
808{
809 if ( mCategoryEditDialog == 0 ) {
810 mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
811 connect( mCategoryEditDialog, TQ_SIGNAL( categoryConfigChanged() ),
812 mCategorySelectDialog, TQ_SLOT( updateCategoryConfig() ) );
813 }
814
815 mCategoryEditDialog->exec();
816}
817
818void AddresseeEditorWidget::emitModified()
819{
820 if ( mBlockSignals )
821 return;
822
823 mDirty = true;
824
825 emit modified();
826}
827
828void AddresseeEditorWidget::dateChanged( const TQDate& )
829{
830 emitModified();
831}
832
833void AddresseeEditorWidget::invalidDate()
834{
835 KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
836}
837
838void AddresseeEditorWidget::pageChanged( TQWidget *wdg )
839{
840 if ( wdg )
841 TDEAcceleratorManager::manage( wdg );
842}
843
844void AddresseeEditorWidget::setInitialFocus()
845{
846 mNameEdit->setFocus();
847}
848
849bool AddresseeEditorWidget::readyToClose()
850{
851 bool ok = true;
852
853 TQDate date = mBirthdayPicker->date();
854 if ( !date.isValid() && !mBirthdayPicker->currentText().isEmpty() ) {
855 KMessageBox::error( this, i18n( "You have to enter a valid birthdate." ) );
856 ok = false;
857 }
858
859 date = mAnniversaryPicker->date();
860 if ( !date.isValid() && !mAnniversaryPicker->currentText().isEmpty() ) {
861 KMessageBox::error( this, i18n( "You have to enter a valid anniversary." ) );
862 ok = false;
863 }
864
865 return ok;
866}
867
868void AddresseeEditorWidget::setReadOnly( bool readOnly )
869{
870 mReadOnly = readOnly;
871
872 mNameEdit->setReadOnly( readOnly );
873 mRoleEdit->setReadOnly( readOnly );
874 mOrgEdit->setReadOnly( readOnly );
875 mPhoneEditWidget->setReadOnly( readOnly );
876 mAddressEditWidget->setReadOnly( readOnly );
877 mEmailWidget->setReadOnly( readOnly );
878 mURLEdit->setReadOnly( readOnly );
879 mBlogEdit->setReadOnly( readOnly );
880 mIMWidget->setReadOnly( readOnly );
881 mCategoryButton->setEnabled( !readOnly );
882 mSecrecyWidget->setReadOnly( readOnly );
883 mDepartmentEdit->setReadOnly( readOnly );
884 mOfficeEdit->setReadOnly( readOnly );
885 mProfessionEdit->setReadOnly( readOnly );
886 mManagerEdit->setReadOnly( readOnly );
887 mAssistantEdit->setReadOnly( readOnly );
888 mTitleEdit->setReadOnly( readOnly );
889 mNicknameEdit->setReadOnly( readOnly );
890 mSpouseEdit->setReadOnly( readOnly );
891 mBirthdayPicker->setEnabled( !readOnly );
892 mAnniversaryPicker->setEnabled( !readOnly );
893 mNoteEdit->setReadOnly( mReadOnly );
894
895 TQDictIterator<ContactEditorTabPage> it( mTabPages );
896 for ( ; it.current(); ++it )
897 it.current()->setReadOnly( readOnly );
898}
899
900#include "addresseeeditorwidget.moc"
Editor widget for addresses.
This widget displays a list box of the email addresses as well as buttons to manipulate them (up,...
This widget displays a list box of the instant messaging addresses as well as buttons to manipulate t...
Definition: imeditwidget.h:45
Editor dialog for name details, like given name, family name etc.
Widget for editing phone numbers.