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#if KDE_IS_VERSION(3,5,8)
546 mDepartmentEdit->setText( mAddressee.department() );
547 // compatibility with older versions
548 if ( mAddressee.department().isEmpty() )
549#endif
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() );
559
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( "," ) );
565
566 mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
567
568 // Load customs
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() );
576
577 TQDictIterator<ContactEditorTabPage> it( mTabPages );
578 for ( ; it.current(); ++it )
579 it.current()->loadContact( &mAddressee );
580
581 blockSignals( block );
582 mBlockSignals = false;
583
584 mDirty = false;
585}
586
587void AddresseeEditorWidget::save()
588{
589 if ( !mDirty ) return;
590
591 mAddressee.setRole( mRoleEdit->text() );
592 mAddressee.setOrganization( mOrgEdit->text() );
593#if KDE_IS_VERSION(3,5,8)
594 mAddressee.setDepartment( mDepartmentEdit->text() );
595#else
596 if ( !mDepartmentEdit->text().isEmpty() )
597 mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() );
598 else
599 mAddressee.removeCustom( "KADDRESSBOOK", "X-Department" );
600#endif
601
602 TQString homepage = mURLEdit->text().stripWhiteSpace();
603 if ( homepage.isEmpty() )
604 mAddressee.setUrl( KURL() );
605 else {
606 if( !homepage.startsWith("http") )
607 homepage = "http://" + homepage;
608 mAddressee.setUrl( KURL( homepage ) );
609 }
610 if ( !mBlogEdit->text().isEmpty() )
611 mAddressee.insertCustom( "KADDRESSBOOK", "BlogFeed", mBlogEdit->text() );
612 else
613 mAddressee.removeCustom( "KADDRESSBOOK", "BlogFeed" );
614
615 mAddressee.setNote( mNoteEdit->text() );
616 if ( mBirthdayPicker->date().isValid() )
617 mAddressee.setBirthday( TQDateTime( mBirthdayPicker->date() ) );
618 else
619 mAddressee.setBirthday( TQDateTime() );
620
621 mAddressee.setNickName( mNicknameEdit->text() );
622 mAddressee.setCategories( TQStringList::split( ",", mCategoryEdit->text() ) );
623
624 mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
625
626 // save custom fields
627 if ( !mIMWidget->preferredIM().isEmpty() )
628 mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMWidget->preferredIM() );
629 else
630 mAddressee.removeCustom( "KADDRESSBOOK", "X-IMAddress" );
631 if ( !mSpouseEdit->text().isEmpty() )
632 mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
633 else
634 mAddressee.removeCustom( "KADDRESSBOOK", "X-SpousesName" );
635 if ( !mManagerEdit->text().isEmpty() )
636 mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
637 else
638 mAddressee.removeCustom( "KADDRESSBOOK", "X-ManagersName" );
639 if ( !mAssistantEdit->text().isEmpty() )
640 mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
641 else
642 mAddressee.removeCustom( "KADDRESSBOOK", "X-AssistantsName" );
643
644 if ( !mOfficeEdit->text().isEmpty() )
645 mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
646 else
647 mAddressee.removeCustom( "KADDRESSBOOK", "X-Office" );
648 if ( !mProfessionEdit->text().isEmpty() )
649 mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
650 else
651 mAddressee.removeCustom( "KADDRESSBOOK", "X-Profession" );
652
653 if ( mAnniversaryPicker->date().isValid() )
654 mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
655 mAnniversaryPicker->date().toString( TQt::ISODate ) );
656 else
657 mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
658
659 mAddressee.setTitle( mTitleEdit->text() );
660
661 // Save the email addresses
662 mAddressee.setEmails( mEmailWidget->emails() );
663
664 // Save the phone numbers
665 TDEABC::PhoneNumber::List phoneNumbers;
666 TDEABC::PhoneNumber::List::ConstIterator phoneIter;
667 phoneNumbers = mAddressee.phoneNumbers();
668 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
669 ++phoneIter )
670 mAddressee.removePhoneNumber( *phoneIter );
671
672 phoneNumbers = mPhoneEditWidget->phoneNumbers();
673 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
674 ++phoneIter )
675 mAddressee.insertPhoneNumber( *phoneIter );
676
677 // Save the addresses
678 TDEABC::Address::List addresses;
679 TDEABC::Address::List::ConstIterator addressIter;
680 addresses = mAddressee.addresses();
681 for ( addressIter = addresses.begin(); addressIter != addresses.end();
682 ++addressIter )
683 mAddressee.removeAddress( *addressIter );
684
685 addresses = mAddressEditWidget->addresses();
686 for ( addressIter = addresses.begin(); addressIter != addresses.end();
687 ++addressIter )
688 mAddressee.insertAddress( *addressIter );
689
690 TQDictIterator<ContactEditorTabPage> it( mTabPages );
691 for ( ; it.current(); ++it )
692 it.current()->storeContact( &mAddressee );
693
694 mDirty = false;
695}
696
697bool AddresseeEditorWidget::dirty()
698{
699 return mDirty;
700}
701
702void AddresseeEditorWidget::nameTextChanged( const TQString &text )
703{
704 // use the addressee class to parse the name for us
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 );
711 } else {
712 // use extra addressee to avoid a formatted name assignment
713 Addressee addr;
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() );
720 }
721 }
722
723 nameBoxChanged();
724
725 emitModified();
726}
727
728void AddresseeEditorWidget::organizationTextChanged( const TQString &text )
729{
730
731 AddresseeConfig config( mAddressee );
732 if ( config.automaticNameParsing() )
733 mAddressee.setOrganization( text );
734
735 nameBoxChanged();
736
737 mAddressEditWidget->updateAddressee( mAddressee );
738
739 emitModified();
740}
741
742void AddresseeEditorWidget::nameBoxChanged()
743{
744 TDEABC::Addressee addr;
745 AddresseeConfig config( mAddressee );
746 if ( config.automaticNameParsing() ) {
747 addr.setNameFromString( mNameEdit->text() );
748 mNameLabel->hide();
749 mNameEdit->show();
750 } else {
751 addr = mAddressee;
752 mNameEdit->hide();
753 mNameLabel->setText( mNameEdit->text() );
754 mNameLabel->show();
755 }
756
757 if ( mFormattedNameType != NameEditDialog::CustomName ) {
758 mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
759 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
760 }
761
762 mAddressEditWidget->updateAddressee( mAddressee );
763}
764
765void AddresseeEditorWidget::nameButtonClicked()
766{
767 // show the name dialog.
768 NameEditDialog dialog( mAddressee, mFormattedNameType, mReadOnly, this );
769
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() );
781 }
782 // Update the name edit.
783 bool block = mNameEdit->signalsBlocked();
784 mNameEdit->blockSignals( true );
785 mNameEdit->setText( mAddressee.assembledName() );
786 mNameEdit->blockSignals( block );
787
788 // Update the combo box.
789 nameBoxChanged();
790
791 emitModified();
792 }
793 }
794}
795
796void AddresseeEditorWidget::selectCategories()
797{
798 // Show the category dialog
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() ) );
805 }
806
807 mCategorySelectDialog->setSelected( TQStringList::split( ",", mCategoryEdit->text() ) );
808 mCategorySelectDialog->exec();
809}
810
811void AddresseeEditorWidget::categoriesSelected( const TQStringList &list )
812{
813 mCategoryEdit->setText( list.join( "," ) );
814}
815
816void AddresseeEditorWidget::editCategories()
817{
818 if ( mCategoryEditDialog == 0 ) {
819 mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
820 connect( mCategoryEditDialog, TQ_SIGNAL( categoryConfigChanged() ),
821 mCategorySelectDialog, TQ_SLOT( updateCategoryConfig() ) );
822 }
823
824 mCategoryEditDialog->exec();
825}
826
827void AddresseeEditorWidget::emitModified()
828{
829 if ( mBlockSignals )
830 return;
831
832 mDirty = true;
833
834 emit modified();
835}
836
837void AddresseeEditorWidget::dateChanged( const TQDate& )
838{
839 emitModified();
840}
841
842void AddresseeEditorWidget::invalidDate()
843{
844 KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
845}
846
847void AddresseeEditorWidget::pageChanged( TQWidget *wdg )
848{
849 if ( wdg )
850 TDEAcceleratorManager::manage( wdg );
851}
852
853void AddresseeEditorWidget::setInitialFocus()
854{
855 mNameEdit->setFocus();
856}
857
858bool AddresseeEditorWidget::readyToClose()
859{
860 bool ok = true;
861
862 TQDate date = mBirthdayPicker->date();
863 if ( !date.isValid() && !mBirthdayPicker->currentText().isEmpty() ) {
864 KMessageBox::error( this, i18n( "You have to enter a valid birthdate." ) );
865 ok = false;
866 }
867
868 date = mAnniversaryPicker->date();
869 if ( !date.isValid() && !mAnniversaryPicker->currentText().isEmpty() ) {
870 KMessageBox::error( this, i18n( "You have to enter a valid anniversary." ) );
871 ok = false;
872 }
873
874 return ok;
875}
876
877void AddresseeEditorWidget::setReadOnly( bool readOnly )
878{
879 mReadOnly = readOnly;
880
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 );
903
904 TQDictIterator<ContactEditorTabPage> it( mTabPages );
905 for ( ; it.current(); ++it )
906 it.current()->setReadOnly( readOnly );
907}
908
909#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.