kaddressbook Library API Documentation

addresseeeditorwidget.cpp

00001 /*
00002     This file is part of KAddressBook.                                  
00003     Copyright (c) 2002 Mike Pilone <mpilone@slac.com>                   
00004                                                                         
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or   
00008     (at your option) any later version.                                 
00009                                                                         
00010     This program is distributed in the hope that it will be useful,     
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of      
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the        
00013     GNU General Public License for more details.                        
00014                                                                         
00015     You should have received a copy of the GNU General Public License   
00016     along with this program; if not, write to the Free Software         
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           
00018                                                                         
00019     As a special exception, permission is given to link this program    
00020     with any edition of Qt, and distribute the resulting executable,    
00021     without including the source code for Qt in the source distribution.
00022 */                                                                      
00023 
00024 #include <qcheckbox.h>
00025 #include <qhbox.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qlistbox.h>
00029 #include <qpushbutton.h>
00030 #include <qtabwidget.h>
00031 #include <qtextedit.h>
00032 #include <qtoolbutton.h>
00033 #include <qtooltip.h>
00034 
00035 #include <kabc/resource.h>
00036 #include <kaccelmanager.h>
00037 #include <kapplication.h>
00038 #include <kconfig.h>
00039 #include <kcombobox.h>
00040 #include <kdebug.h>
00041 #include <kdialogbase.h>
00042 #include <kglobal.h>
00043 #include <kiconloader.h>
00044 #include <klineedit.h>
00045 #include <klocale.h>
00046 #include <kmessagebox.h>
00047 #include <kseparator.h>
00048 #include <ksqueezedtextlabel.h>
00049 
00050 #include <libkdepim/categoryeditdialog.h>
00051 #include <libkdepim/categoryselectdialog.h>
00052 
00053 #include <libkdepim/kdateedit.h>
00054 
00055 #include "addresseditwidget.h"
00056 #include "core.h"
00057 #include "emaileditwidget.h"
00058 #include "geowidget.h"
00059 #include "imagewidget.h"
00060 #include "kabprefs.h"
00061 #include "keywidget.h"
00062 #include "nameeditdialog.h"
00063 #include "phoneeditwidget.h"
00064 #include "secrecywidget.h"
00065 #include "soundwidget.h"
00066 
00067 #include "addresseeeditorwidget.h"
00068 
00069 AddresseeEditorWidget::AddresseeEditorWidget( KAB::Core *core, bool isExtension, 
00070                                               QWidget *parent, const char *name )
00071   : KAB::ExtensionWidget( core, parent, name ), mIsExtension( isExtension ),
00072     mBlockSignals( false ), mReadOnly( false )
00073 {
00074   kdDebug(5720) << "AddresseeEditorWidget()" << endl;
00075 
00076   initGUI();
00077   mCategoryDialog = 0;
00078   mCategoryEditDialog = 0;
00079   
00080   // Load the empty addressee as defaults
00081   load();
00082   
00083   mDirty = false;
00084 }
00085 
00086 AddresseeEditorWidget::~AddresseeEditorWidget()
00087 {
00088   kdDebug(5720) << "~AddresseeEditorWidget()" << endl;
00089 }  
00090   
00091 void AddresseeEditorWidget::contactsSelectionChanged()
00092 {
00093   KABC::Addressee::List list = selectedContacts();
00094 
00095   setAddressee( list[ 0 ] );
00096 }
00097 
00098 void AddresseeEditorWidget::setAddressee( const KABC::Addressee &addr )
00099 {
00100   mAddressee = addr;
00101 
00102   bool readOnly = ( !addr.resource() ? false : addr.resource()->readOnly() );
00103   setReadOnly( readOnly );
00104 
00105   load();
00106 }
00107 
00108 const KABC::Addressee &AddresseeEditorWidget::addressee()
00109 {
00110   return mAddressee;
00111 }
00112 
00113 void AddresseeEditorWidget::textChanged( const QString& )
00114 {
00115   emitModified();
00116 }
00117   
00118 void AddresseeEditorWidget::initGUI()
00119 {
00120   QVBoxLayout *layout = new QVBoxLayout( this );
00121 
00122   mTabWidget = new QTabWidget( this );
00123   layout->addWidget( mTabWidget );
00124 
00125   setupTab1();
00126   setupTab2();
00127   setupTab3();
00128 
00129   mNameEdit->setFocus();
00130 
00131   connect( mTabWidget, SIGNAL( currentChanged(QWidget*) ),
00132            SLOT( pageChanged(QWidget*) ) );
00133 }
00134 
00135 void AddresseeEditorWidget::setupTab1()
00136 {
00137   // This is the General tab
00138   QWidget *tab1 = new QWidget( mTabWidget );
00139 
00140   QGridLayout *layout = new QGridLayout( tab1, 11, 7 );
00141   layout->setMargin( KDialogBase::marginHint() );
00142   layout->setSpacing( KDialogBase::spacingHint() );
00143   
00144   QLabel *label;
00145   KSeparator* bar;
00146   QPushButton *button;
00147   
00149   // Upper left group (person info)
00150   
00151   // Person icon
00152   label = new QLabel( tab1 );
00153   label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop,
00154                                                       KIcon::SizeMedium ) );
00155   layout->addMultiCellWidget( label, 0, 1, 0, 0 );
00156   
00157   // First name
00158   button = new QPushButton( i18n( "Edit Name..." ), tab1 );
00159   QToolTip::add( button, i18n( "Edit the contact's name" ) );
00160   mNameEdit = new KLineEdit( tab1, "mNameEdit" );
00161   connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), 
00162            SLOT( nameTextChanged( const QString& ) ) );
00163   connect( button, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) );
00164   mNameLabel = new KSqueezedTextLabel( tab1 );
00165   mNameLabel->hide();
00166   layout->addWidget( button, 0, 1 );
00167   layout->addWidget( mNameEdit, 0, 2 );
00168   layout->addWidget( mNameLabel, 0, 2 );
00169   label = new QLabel( i18n( "Role:" ), tab1 );
00170   mRoleEdit = new KLineEdit( tab1 );
00171   connect( mRoleEdit, SIGNAL( textChanged( const QString& ) ),
00172            SLOT( textChanged( const QString& ) ) );
00173   label->setBuddy( mRoleEdit );
00174   layout->addWidget( label, 1, 1 );
00175   layout->addWidget( mRoleEdit, 1, 2 );
00176   
00177   // Organization
00178   label = new QLabel( i18n( "Organization:" ), tab1 );
00179   mOrgEdit = new KLineEdit( tab1 );
00180   label->setBuddy( mOrgEdit );
00181   connect( mOrgEdit, SIGNAL( textChanged( const QString& ) ), 
00182            SLOT( textChanged( const QString& ) ) );
00183   layout->addWidget( label, 2, 1 );
00184   layout->addWidget( mOrgEdit, 2, 2 );
00185   
00186   // File as (formatted name)
00187   label = new QLabel( i18n( "Formatted name:" ), tab1 );
00188   mFormattedNameLabel = new KSqueezedTextLabel( tab1 );
00189   layout->addWidget( label, 3, 1 );
00190   layout->addWidget( mFormattedNameLabel, 3, 2 );
00191   
00192   // Left hand separator. This separator doesn't go all the way
00193   // across so the dialog still flows from top to bottom
00194   bar = new KSeparator( KSeparator::HLine, tab1 );
00195   layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
00196   
00198   // Phone numbers (upper right)
00199   label = new QLabel( tab1 );
00200   label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook",
00201                     KIcon::Desktop, KIcon::SizeMedium ) );
00202   layout->addMultiCellWidget( label, 0, 1, 3, 3 );
00203   
00204   mPhoneEditWidget = new PhoneEditWidget( tab1 );
00205   connect( mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00206   layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 ); 
00207 
00208   bar = new KSeparator( KSeparator::HLine, tab1 );
00209   layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
00210   
00212   // Addresses (lower left)
00213   label = new QLabel( tab1 );
00214   label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop,
00215                                                      KIcon::SizeMedium ) );
00216   layout->addMultiCellWidget( label, 5, 6, 0, 0 );
00217   
00218   mAddressEditWidget = new AddressEditWidget( tab1 );
00219   connect( mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00220   layout->addMultiCellWidget( mAddressEditWidget, 5, 9, 1, 2 );
00221 
00223   // Email / Web (lower right)
00224   label = new QLabel( tab1 );
00225   label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop,
00226                                                      KIcon::SizeMedium ) );
00227   layout->addMultiCellWidget( label, 5, 6, 3, 3 );
00228 
00229   mEmailWidget = new EmailEditWidget( tab1 );
00230   connect( mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00231   layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
00232 
00233   // add the separator
00234   bar = new KSeparator( KSeparator::HLine, tab1 );
00235   layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
00236 
00237   label = new QLabel( tab1 );
00238   label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop,
00239                                                      KIcon::SizeMedium ) );
00240   layout->addMultiCellWidget( label, 8, 9, 3, 3 );
00241 
00242   label = new QLabel( i18n( "URL:" ), tab1 );
00243   mURLEdit = new KLineEdit( tab1 );
00244   connect( mURLEdit, SIGNAL( textChanged( const QString& ) ), 
00245            SLOT( textChanged( const QString& ) ) );
00246   label->setBuddy( mURLEdit );
00247   layout->addWidget( label, 8, 4 );
00248   layout->addMultiCellWidget( mURLEdit, 8, 8, 5, 6 );
00249 
00250   label = new QLabel( i18n( "&IM address:" ), tab1 );
00251   mIMAddressEdit = new KLineEdit( tab1 );
00252   connect( mIMAddressEdit, SIGNAL( textChanged( const QString& ) ), 
00253            SLOT( textChanged( const QString& ) ) );
00254   label->setBuddy( mIMAddressEdit );
00255   layout->addWidget( label, 9, 4 );
00256   layout->addMultiCellWidget( mIMAddressEdit, 9, 9, 5, 6 );
00257   
00258   layout->addColSpacing( 6, 50 );
00259   
00260   bar = new KSeparator( KSeparator::HLine, tab1 );
00261   layout->addMultiCellWidget( bar, 10, 10, 0, 6 );
00262   
00264   QHBox *categoryBox = new QHBox( tab1 );
00265   categoryBox->setSpacing( KDialogBase::spacingHint() );
00266   
00267   // Categories
00268   mCategoryButton = new QPushButton( i18n( "Select Categories..." ), categoryBox );
00269   connect( mCategoryButton, SIGNAL( clicked() ), SLOT( categoryButtonClicked() ) );
00270 
00271   mCategoryEdit = new KLineEdit( categoryBox );
00272   mCategoryEdit->setReadOnly( true );
00273   connect( mCategoryEdit, SIGNAL( textChanged( const QString& ) ), 
00274            SLOT( textChanged( const QString& ) ) );
00275 
00276   mSecrecyWidget = new SecrecyWidget( categoryBox );
00277   connect( mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
00278 
00279   layout->addMultiCellWidget( categoryBox, 11, 11, 0, 6 );
00280   
00281   // Build the layout and add to the tab widget
00282   layout->activate(); // required
00283 
00284   mTabWidget->addTab( tab1, i18n( "&General" ) );
00285 }
00286 
00287 void AddresseeEditorWidget::setupTab2()
00288 {
00289   // This is the Details tab
00290   QWidget *tab2 = new QWidget( mTabWidget );
00291 
00292   QGridLayout *layout = new QGridLayout( tab2, 6, 6 );
00293   layout->setMargin( KDialogBase::marginHint() );
00294   layout->setSpacing( KDialogBase::spacingHint() );
00295   
00296   QLabel *label;
00297   KSeparator* bar;
00298   
00300   // Office info
00301   
00302   // Department
00303   label = new QLabel( tab2 );
00304   label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop,
00305                                                      KIcon::SizeMedium ) );
00306   layout->addMultiCellWidget( label, 0, 1, 0, 0 );
00307   
00308   label = new QLabel( i18n( "Department:" ), tab2 );
00309   layout->addWidget( label, 0, 1 );
00310   mDepartmentEdit = new KLineEdit( tab2 );
00311   connect( mDepartmentEdit, SIGNAL( textChanged( const QString& ) ),
00312            SLOT( textChanged( const QString& ) ) );
00313   label->setBuddy( mDepartmentEdit );
00314   layout->addWidget( mDepartmentEdit, 0, 2 );
00315   
00316   label = new QLabel( i18n( "Office:" ), tab2 );
00317   layout->addWidget( label, 1, 1 );
00318   mOfficeEdit = new KLineEdit( tab2 );
00319   connect( mOfficeEdit, SIGNAL( textChanged( const QString& ) ),
00320            SLOT( textChanged( const QString& ) ) );
00321   label->setBuddy( mOfficeEdit );
00322   layout->addWidget( mOfficeEdit, 1, 2 );
00323   
00324   label = new QLabel( i18n( "Profession:" ), tab2 );
00325   layout->addWidget( label, 2, 1 );
00326   mProfessionEdit = new KLineEdit( tab2 );
00327   connect( mProfessionEdit, SIGNAL( textChanged( const QString& ) ),
00328            SLOT( textChanged( const QString& ) ) );
00329   label->setBuddy( mProfessionEdit );
00330   layout->addWidget( mProfessionEdit, 2, 2 );
00331   
00332   label = new QLabel( i18n( "Manager\'s name:" ), tab2 );
00333   layout->addWidget( label, 0, 3 );
00334   mManagerEdit = new KLineEdit( tab2 );
00335   connect( mManagerEdit, SIGNAL( textChanged( const QString& ) ),
00336            SLOT( textChanged( const QString& ) ) );
00337   label->setBuddy( mManagerEdit );
00338   layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 );
00339   
00340   label = new QLabel( i18n( "Assistant's name:" ), tab2 );
00341   layout->addWidget( label, 1, 3 );
00342   mAssistantEdit = new KLineEdit( tab2 );
00343   connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ),
00344            SLOT( textChanged( const QString& ) ) );
00345   label->setBuddy( mAssistantEdit );
00346   layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 );
00347   
00348   bar = new KSeparator( KSeparator::HLine, tab2 );
00349   layout->addMultiCellWidget( bar, 3, 3, 0, 5 );
00350   
00352   // Personal info
00353   
00354   label = new QLabel( tab2 );
00355   label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop,
00356                                                      KIcon::SizeMedium ) );
00357   layout->addMultiCellWidget( label, 4, 5, 0, 0 );
00358   
00359   label = new QLabel( i18n( "Nick name:" ), tab2 );
00360   layout->addWidget( label, 4, 1 );
00361   mNicknameEdit = new KLineEdit( tab2 );
00362   connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ),
00363            SLOT( textChanged( const QString& ) ) );
00364   label->setBuddy( mNicknameEdit );
00365   layout->addWidget( mNicknameEdit, 4, 2 );
00366 
00367   label = new QLabel( i18n( "Spouse's name:" ), tab2 );
00368   layout->addWidget( label, 5, 1 );
00369   mSpouseEdit = new KLineEdit( tab2 );
00370   connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ),
00371            SLOT( textChanged( const QString& ) ) );
00372   label->setBuddy( mSpouseEdit );
00373   layout->addWidget( mSpouseEdit, 5, 2 );
00374 
00375   label = new QLabel( i18n( "Birthday:" ), tab2 );
00376   layout->addWidget( label, 4, 3 );
00377   mBirthdayPicker = new KDateEdit( tab2 );
00378   mBirthdayPicker->setHandleInvalid( true );
00379   connect( mBirthdayPicker, SIGNAL( dateChanged( QDate ) ),
00380            SLOT( dateChanged( QDate ) ) );
00381   connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ),
00382            SLOT( invalidDate() ) );
00383   connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ),
00384            SLOT( emitModified() ) );
00385   label->setBuddy( mBirthdayPicker );
00386   layout->addWidget( mBirthdayPicker, 4, 4 );
00387   
00388   label = new QLabel( i18n( "Anniversary:" ), tab2 );
00389   layout->addWidget( label, 5, 3 );
00390   mAnniversaryPicker = new KDateEdit( tab2 );
00391   mAnniversaryPicker->setHandleInvalid( true );
00392   connect( mAnniversaryPicker, SIGNAL( dateChanged( QDate ) ),
00393            SLOT( dateChanged( QDate ) ) );
00394   connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ),
00395            SLOT( invalidDate() ) );
00396   connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ),
00397            SLOT( emitModified() ) );
00398   label->setBuddy( mAnniversaryPicker );
00399   layout->addWidget( mAnniversaryPicker, 5, 4 );
00400   
00401   bar = new KSeparator( KSeparator::HLine, tab2 );
00402   layout->addMultiCellWidget( bar, 6, 6, 0, 5 );
00403   
00405   // Notes
00406   label = new QLabel( i18n( "Note:" ), tab2 );
00407   label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
00408   layout->addWidget( label, 7, 0 );
00409   mNoteEdit = new QTextEdit( tab2 );
00410   mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
00411   mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
00412   connect( mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) );
00413   label->setBuddy( mNoteEdit );
00414   layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
00415 
00416    // Build the layout and add to the tab widget
00417   layout->activate(); // required
00418 
00419   mTabWidget->addTab( tab2, i18n( "&Details" ) );
00420 }
00421 
00422 void AddresseeEditorWidget::setupTab3()
00423 {
00424   // This is the Misc tab
00425   QWidget *tab3 = new QWidget( mTabWidget );
00426 
00427   QGridLayout *layout = new QGridLayout( tab3, 3, 2 );
00428   layout->setMargin( KDialogBase::marginHint() );
00429   layout->setSpacing( KDialogBase::spacingHint() );
00430   
00432   // Geo
00433   mGeoWidget = new GeoWidget( tab3 );
00434   mGeoWidget->setMinimumSize( mGeoWidget->sizeHint() );
00435   connect( mGeoWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
00436   layout->addWidget( mGeoWidget, 0, 0, Qt::AlignTop );
00437 
00439   // Sound
00440   mSoundWidget = new SoundWidget( tab3 );
00441   mSoundWidget->setMinimumSize( mSoundWidget->sizeHint() );
00442   connect( mSoundWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
00443   layout->addWidget( mSoundWidget, 0, 1, Qt::AlignTop );
00444 
00445   QFrame *separator = new QFrame( tab3 );
00446   separator->setFrameShape( QFrame::HLine );
00447   separator->setFrameShadow( QFrame::Sunken );
00448   layout->addMultiCellWidget( separator, 1, 1, 0, 1 );
00449 
00451   // Images
00452   mPhotoWidget = new ImageWidget( KABC::Addressee::photoLabel(), tab3 );
00453   mPhotoWidget->setMinimumSize( mPhotoWidget->sizeHint() );
00454   connect( mPhotoWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
00455   layout->addWidget( mPhotoWidget, 2, 0 );
00456 
00457   mLogoWidget = new ImageWidget( KABC::Addressee::logoLabel(), tab3 );
00458   mLogoWidget->setMinimumSize( mLogoWidget->sizeHint() );
00459   connect( mLogoWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
00460   layout->addWidget( mLogoWidget, 2, 1 );
00461 
00462 /* FIXME: will be enabled again when kgpg support is in kdelibs
00464   // Keys
00465   mKeyWidget = new KeyWidget( mReadOnly, tab3 );
00466   mKeyWidget->setMinimumSize( mKeyWidget->sizeHint() );
00467   connect( mKeyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
00468   layout->addWidget( mKeyWidget, 1, 1, Qt::AlignTop );
00469 */
00470   mTabWidget->addTab( tab3, i18n( "&Misc" ) );
00471 }
00472     
00473 void AddresseeEditorWidget::load()
00474 {
00475   kdDebug(5720) << "AddresseeEditorWidget::load()" << endl;
00476 
00477   // Block signals in case anything tries to emit modified
00478   // CS: This doesn't seem to work.
00479   bool block = signalsBlocked();
00480   blockSignals( true ); 
00481   mBlockSignals = true; // used for internal signal blocking
00482 
00483   mNameEdit->blockSignals( true );
00484   mNameEdit->setText( mAddressee.assembledName() );
00485   mNameEdit->blockSignals( false );
00486 
00487   if ( mAddressee.formattedName().isEmpty() ) {
00488     KConfig config( "kaddressbookrc" );
00489     config.setGroup( "General" );
00490     mFormattedNameType = config.readNumEntry( "FormattedNameType", 1 );
00491     mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00492   } else {
00493     if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) )
00494       mFormattedNameType = NameEditDialog::SimpleName;
00495     else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) )
00496       mFormattedNameType = NameEditDialog::FullName;
00497     else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) )
00498       mFormattedNameType = NameEditDialog::ReverseName;
00499     else
00500       mFormattedNameType = NameEditDialog::CustomName;
00501   }
00502 
00503   mFormattedNameLabel->setText( mAddressee.formattedName() );
00504 
00505   mRoleEdit->setText( mAddressee.role() );
00506   mOrgEdit->setText( mAddressee.organization() );
00507   mURLEdit->setURL( KURL( mAddressee.url().url() ) );
00508   mURLEdit->home( false );
00509   mNoteEdit->setText( mAddressee.note() );
00510   mEmailWidget->setEmails( mAddressee.emails() );
00511   mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
00512   mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
00513   mBirthdayPicker->setDate( mAddressee.birthday().date() );
00514   mAnniversaryPicker->setDate( QDate::fromString( mAddressee.custom(
00515                                "KADDRESSBOOK", "X-Anniversary" ), Qt::ISODate) );
00516   mNicknameEdit->setText( mAddressee.nickName() );
00517   mCategoryEdit->setText( mAddressee.categories().join( "," ) );
00518 
00519   mGeoWidget->setGeo( mAddressee.geo() );
00520   mPhotoWidget->setImage( mAddressee.photo() );
00521   mLogoWidget->setImage( mAddressee.logo() );
00522 //  mKeyWidget->setKeys( mAddressee.keys() );
00523   mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
00524   mSoundWidget->setSound( mAddressee.sound() );
00525 
00526   // Load customs
00527   mIMAddressEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) );
00528   mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) );
00529   mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) );
00530   mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
00531   mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) );
00532   mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) );
00533   mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) );
00534   
00535   blockSignals( block );
00536   mBlockSignals = false;
00537 
00538   mDirty = false;
00539 }
00540 
00541 void AddresseeEditorWidget::save()
00542 {
00543   if ( !mDirty ) return;
00544 
00545   mAddressee.setRole( mRoleEdit->text() );
00546   mAddressee.setOrganization( mOrgEdit->text() );
00547   mAddressee.setUrl( KURL( mURLEdit->text() ) );
00548   mAddressee.setNote( mNoteEdit->text() );
00549   if ( mBirthdayPicker->inputIsValid() )
00550     mAddressee.setBirthday( QDateTime( mBirthdayPicker->date() ) );
00551   else
00552     mAddressee.setBirthday( QDateTime() );
00553   
00554   mAddressee.setNickName( mNicknameEdit->text() );
00555   mAddressee.setCategories( QStringList::split( ",", mCategoryEdit->text() ) );
00556 
00557   mAddressee.setGeo( mGeoWidget->geo() );
00558   mAddressee.setPhoto( mPhotoWidget->image() );
00559   mAddressee.setLogo( mLogoWidget->image() );
00560 //  mAddressee.setKeys( mKeyWidget->keys() );
00561   mAddressee.setSound( mSoundWidget->sound() );
00562   mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
00563 
00564   // save custom fields
00565   mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMAddressEdit->text() );
00566   mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
00567   mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
00568   mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
00569   mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() );
00570   mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
00571   mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
00572   if ( mAnniversaryPicker->inputIsValid() )
00573     mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
00574                              mAnniversaryPicker->date().toString( Qt::ISODate ) );
00575   else
00576     mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
00577                           
00578   // Save the email addresses
00579   QStringList emails = mAddressee.emails();
00580   QStringList::Iterator iter;
00581   for ( iter = emails.begin(); iter != emails.end(); ++iter )
00582     mAddressee.removeEmail( *iter );
00583   
00584   emails = mEmailWidget->emails();
00585   bool first = true;
00586   for ( iter = emails.begin(); iter != emails.end(); ++iter ) {
00587     mAddressee.insertEmail( *iter, first );
00588     first = false;
00589   }
00590   
00591   // Save the phone numbers
00592   KABC::PhoneNumber::List phoneNumbers;
00593   KABC::PhoneNumber::List::Iterator phoneIter;
00594   phoneNumbers = mAddressee.phoneNumbers();
00595   for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00596         ++phoneIter )
00597     mAddressee.removePhoneNumber( *phoneIter );
00598     
00599   phoneNumbers = mPhoneEditWidget->phoneNumbers();
00600   for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00601         ++phoneIter )
00602     mAddressee.insertPhoneNumber( *phoneIter );
00603 
00604   // Save the addresses
00605   KABC::Address::List addresses;
00606   KABC::Address::List::Iterator addressIter;
00607   addresses = mAddressee.addresses();
00608   for ( addressIter = addresses.begin(); addressIter != addresses.end();
00609         ++addressIter )
00610     mAddressee.removeAddress( *addressIter );
00611     
00612   addresses = mAddressEditWidget->addresses();
00613   for ( addressIter = addresses.begin(); addressIter != addresses.end();
00614         ++addressIter )
00615     mAddressee.insertAddress( *addressIter );
00616 
00617   mDirty = false;
00618 }
00619 
00620 bool AddresseeEditorWidget::dirty()
00621 {
00622   return mDirty;
00623 }
00624 
00625 void AddresseeEditorWidget::nameTextChanged( const QString &text )
00626 {
00627   // use the addressee class to parse the name for us
00628   AddresseeConfig config( mAddressee );
00629   if ( config.automaticNameParsing() ) {
00630     if ( !mAddressee.formattedName().isEmpty() ) {
00631       QString fn = mAddressee.formattedName();
00632       mAddressee.setNameFromString( text );
00633       mAddressee.setFormattedName( fn );
00634     } else {
00635       // use extra addressee to avoid a formatted name assignment
00636       Addressee addr;
00637       addr.setNameFromString( text );
00638       mAddressee.setPrefix( addr.prefix() );
00639       mAddressee.setGivenName( addr.givenName() );
00640       mAddressee.setAdditionalName( addr.additionalName() );
00641       mAddressee.setFamilyName( addr.familyName() );
00642       mAddressee.setSuffix( addr.suffix() );
00643     }
00644   }
00645 
00646   nameBoxChanged();
00647 
00648   emitModified();
00649 }
00650 
00651 void AddresseeEditorWidget::nameBoxChanged()
00652 {
00653   KABC::Addressee addr;
00654   AddresseeConfig config( mAddressee );
00655   if ( config.automaticNameParsing() ) {
00656     addr.setNameFromString( mNameEdit->text() );
00657     mNameLabel->hide();
00658     mNameEdit->show();
00659   } else {
00660     addr = mAddressee;
00661     mNameEdit->hide();
00662     mNameLabel->setText( mNameEdit->text() );
00663     mNameLabel->show();
00664   }
00665 
00666   if ( mFormattedNameType != NameEditDialog::CustomName ) {
00667     mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00668     mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00669   }
00670 }
00671 
00672 void AddresseeEditorWidget::nameButtonClicked()
00673 {
00674   // show the name dialog.
00675   NameEditDialog dialog( mAddressee, mFormattedNameType, mReadOnly, this );
00676   
00677   if ( dialog.exec() ) {
00678     if ( dialog.changed() ) {
00679       mAddressee.setFamilyName( dialog.familyName() );
00680       mAddressee.setGivenName( dialog.givenName() );
00681       mAddressee.setPrefix( dialog.prefix() );
00682       mAddressee.setSuffix( dialog.suffix() );
00683       mAddressee.setAdditionalName( dialog.additionalName() );
00684       mFormattedNameType = dialog.formattedNameType();
00685       if ( mFormattedNameType == NameEditDialog::CustomName ) {
00686         mFormattedNameLabel->setText( dialog.customFormattedName() );
00687         mAddressee.setFormattedName( dialog.customFormattedName() );
00688       }
00689       // Update the name edit.
00690       bool block = mNameEdit->signalsBlocked();
00691       mNameEdit->blockSignals( true );
00692       mNameEdit->setText( mAddressee.assembledName() );
00693       mNameEdit->blockSignals( block );
00694 
00695       // Update the combo box.
00696       nameBoxChanged();
00697     
00698       emitModified();
00699     }
00700   }
00701 }
00702 
00703 void AddresseeEditorWidget::categoryButtonClicked()
00704 {
00705   // Show the category dialog
00706   if ( mCategoryDialog == 0 ) {
00707     mCategoryDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
00708     connect( mCategoryDialog, SIGNAL( categoriesSelected( const QStringList& ) ),
00709              SLOT(categoriesSelected( const QStringList& ) ) );
00710     connect( mCategoryDialog, SIGNAL( editCategories() ), SLOT( editCategories() ) );
00711   }
00712 
00713   mCategoryDialog->setCategories();
00714   mCategoryDialog->setSelected( QStringList::split( ",", mCategoryEdit->text() ) );
00715   mCategoryDialog->show();
00716   mCategoryDialog->raise();
00717 }
00718 
00719 void AddresseeEditorWidget::categoriesSelected( const QStringList &list )
00720 {
00721   mCategoryEdit->setText( list.join( "," ) );
00722 }
00723 
00724 void AddresseeEditorWidget::editCategories()
00725 {
00726   if ( mCategoryEditDialog == 0 ) {
00727     mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
00728     connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
00729              SLOT( categoryButtonClicked() ) );
00730   }
00731   
00732   mCategoryEditDialog->show();
00733   mCategoryEditDialog->raise();
00734 }
00735 
00736 void AddresseeEditorWidget::emitModified()
00737 {
00738   mDirty = true;
00739 
00740   KABC::Addressee::List list;
00741 
00742   if ( mIsExtension && !mBlockSignals ) {
00743     save();
00744     list.append( mAddressee );
00745   }
00746 
00747   emit modified( list );
00748 }
00749 
00750 void AddresseeEditorWidget::dateChanged( QDate )
00751 {
00752   emitModified();
00753 }
00754 
00755 void AddresseeEditorWidget::invalidDate()
00756 {
00757   KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
00758 }
00759 
00760 void AddresseeEditorWidget::pageChanged( QWidget *wdg )
00761 {
00762   if ( wdg )
00763     KAcceleratorManager::manage( wdg );
00764 }
00765 
00766 QString AddresseeEditorWidget::title() const
00767 {
00768   return i18n( "Contact Editor" );
00769 }
00770 
00771 QString AddresseeEditorWidget::identifier() const
00772 {
00773   return i18n( "contact_editor" );
00774 }
00775 
00776 void AddresseeEditorWidget::setReadOnly( bool readOnly )
00777 {
00778   mReadOnly = readOnly;
00779 
00780   mNameEdit->setReadOnly( readOnly );
00781   mRoleEdit->setReadOnly( readOnly );
00782   mOrgEdit->setReadOnly( readOnly );
00783   mPhoneEditWidget->setReadOnly( readOnly );
00784   mAddressEditWidget->setReadOnly( readOnly );
00785   mEmailWidget->setReadOnly( readOnly );
00786   mURLEdit->setReadOnly( readOnly );
00787   mIMAddressEdit->setReadOnly( readOnly );
00788   mCategoryButton->setEnabled( !readOnly );
00789   mSecrecyWidget->setReadOnly( readOnly );
00790   mDepartmentEdit->setReadOnly( readOnly );
00791   mOfficeEdit->setReadOnly( readOnly );
00792   mProfessionEdit->setReadOnly( readOnly );
00793   mManagerEdit->setReadOnly( readOnly );
00794   mAssistantEdit->setReadOnly( readOnly );
00795   mNicknameEdit->setReadOnly( readOnly );
00796   mSpouseEdit->setReadOnly( readOnly );
00797   mBirthdayPicker->setEnabled( !readOnly );
00798   mAnniversaryPicker->setEnabled( !readOnly );
00799   mNoteEdit->setReadOnly( mReadOnly );
00800   mGeoWidget->setReadOnly( readOnly );
00801   mSoundWidget->setReadOnly( readOnly );
00802   mPhotoWidget->setReadOnly( readOnly );
00803   mLogoWidget->setReadOnly( readOnly );
00804 }
00805 
00806 #include "addresseeeditorwidget.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:50 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003