• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

addresseeeditorwidget.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 <QtGui/QCheckBox>
00025 #include <QtGui/QGridLayout>
00026 #include <QtGui/QLabel>
00027 #include <QtGui/QPushButton>
00028 #include <QtGui/QTabWidget>
00029 #include <QtGui/QTextEdit>
00030 #include <QtGui/QVBoxLayout>
00031 
00032 #include <kabc/resource.h>
00033 #include <kabc/resourceabc.h>
00034 #include <kabc/stdaddressbook.h>
00035 #include <kacceleratormanager.h>
00036 #include <kconfig.h>
00037 #include <kcombobox.h>
00038 #include <kdebug.h>
00039 #include <kglobal.h>
00040 #include <kiconloader.h>
00041 #include <klineedit.h>
00042 #include <klocale.h>
00043 #include <kmessagebox.h>
00044 #include <kseparator.h>
00045 #include <ksqueezedtextlabel.h>
00046 #include <kstandarddirs.h>
00047 
00048 #include <libkdepim/addresseelineedit.h>
00049 #include <libkdepim/categoryeditdialog.h>
00050 #include <libkdepim/categoryselectdialog.h>
00051 #include <libkdepim/kdateedit.h>
00052 #include <kvbox.h>
00053 
00054 #include "addresseditwidget.h"
00055 #include "advancedcustomfields.h"
00056 #include "emaileditwidget.h"
00057 #include "imeditwidget.h"
00058 #include "kabprefs.h"
00059 #include "keywidget.h"
00060 #include "nameeditdialog.h"
00061 #include "phoneeditwidget.h"
00062 #include "secrecywidget.h"
00063 
00064 #include "addresseeeditorwidget.h"
00065 
00066 AddresseeEditorWidget::AddresseeEditorWidget( QWidget *parent )
00067   : AddresseeEditorBase( parent ),
00068     mBlockSignals( false ), mReadOnly( false )
00069 {
00070   kDebug(5720) <<"AddresseeEditorWidget()";
00071 
00072   initGUI();
00073   mCategorySelectDialog = 0;
00074   mCategoryEditDialog = 0;
00075 
00076   // Load the empty addressee as defaults
00077   load();
00078 
00079   mDirty = false;
00080 }
00081 
00082 AddresseeEditorWidget::~AddresseeEditorWidget()
00083 {
00084   kDebug(5720) <<"~AddresseeEditorWidget()";
00085 }
00086 
00087 void AddresseeEditorWidget::setAddressee( const KABC::Addressee &addr )
00088 {
00089   if ( mAddressee.uid() == addr.uid() )
00090     return;
00091   mAddressee = addr;
00092 
00093   bool readOnly = false;
00094   if ( KABC::Resource *res = addr.resource() ) {
00095     if ( res->readOnly() ) {
00096       readOnly = true;
00097 
00098     //HACK: some resources have finer access control than "generic" resources
00099     } else if ( res->inherits( "KPIM::ResourceAbc" ) ) {
00100       KABC::ResourceABC *resAbc = static_cast<KABC::ResourceABC *>( res );
00101 
00102       QString subresource = resAbc->uidToResourceMap()[ addr.uid() ];
00103       if ( !subresource.isEmpty() )
00104         readOnly |= !resAbc->subresourceWritable( subresource );
00105     }
00106   }
00107   setReadOnly( readOnly );
00108 
00109   load();
00110 }
00111 
00112 const KABC::Addressee &AddresseeEditorWidget::addressee()
00113 {
00114   return mAddressee;
00115 }
00116 
00117 void AddresseeEditorWidget::textChanged( const QString& )
00118 {
00119   emitModified();
00120 }
00121 
00122 void AddresseeEditorWidget::initGUI()
00123 {
00124   QVBoxLayout *layout = new QVBoxLayout( this );
00125   layout->setMargin( 0 );
00126   layout->setSpacing( KDialog::spacingHint() );
00127 
00128   mTabWidget = new QTabWidget( this );
00129   layout->addWidget( mTabWidget );
00130 
00131   setupTab1();
00132   setupTab2();
00133   setupAdditionalTabs();
00134   setupCustomFieldsTabs();
00135 
00136   connect( mTabWidget, SIGNAL( currentChanged(QWidget*) ),
00137            SLOT( pageChanged(QWidget*) ) );
00138 }
00139 
00140 void AddresseeEditorWidget::setupTab1()
00141 {
00142   // This is the General tab
00143   QWidget *page = new QWidget( mTabWidget );
00144   tab1.setupUi( page );
00145   //tab1.setMainWidget( page );
00146 
00148   // Upper left group (person info)
00149 
00150   // Person icon
00151   tab1.mUserLabel->setPixmap( KIconLoader::global()->loadIcon( "user-identity", KIconLoader::Desktop,
00152                                                       KIconLoader::SizeMedium ) );
00153 
00154   // First name
00155   connect( tab1.mNameEdit, SIGNAL( textChanged( const QString& ) ),
00156            SLOT( nameTextChanged( const QString& ) ) );
00157   connect( tab1.mNameButton, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) );
00158   mNameLabel = new KSqueezedTextLabel( page );
00159 
00160   if ( KABPrefs::instance()->automaticNameParsing() ) {
00161     mNameLabel->hide();
00162     tab1.mNameEdit->show();
00163   } else {
00164     tab1.mNameEdit->hide();
00165     mNameLabel->show();
00166   }
00167 
00168   tab1.layout->addWidget( mNameLabel, 0, 2 );
00169   tab1.mRoleLabel->setText( i18nc( "<roleLabel>:", "%1:", KABC::Addressee::roleLabel() ) );
00170   connect( tab1.mRoleEdit, SIGNAL( textChanged( const QString& ) ),
00171            SLOT( textChanged( const QString& ) ) );
00172 
00173   // Organization
00174   tab1.mOrgLabel->setText( i18nc( "<organizationLabel>:", "%1:", KABC::Addressee::organizationLabel() ) );
00175   connect( tab1.mOrgEdit, SIGNAL( textChanged( const QString& ) ),
00176            SLOT( organizationTextChanged( const QString& ) ) );
00177 
00179   // Phone numbers (upper right)
00180   tab1.mPhoneLabel->setPixmap( KIconLoader::global()->loadIcon( "x-office-contact",
00181                     KIconLoader::Desktop, KIconLoader::SizeMedium ) );
00182 
00183   connect( tab1.mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00184 
00186   // Addresses (lower left)
00187   tab1.mAddressLabel->setPixmap( KIconLoader::global()->loadIcon( "go-home", KIconLoader::Desktop,
00188                                                      KIconLoader::SizeMedium ) );
00189 
00190   connect( tab1.mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00191 
00193   // Email / Web (lower right)
00194   tab1.mEmailLabel->setPixmap( KIconLoader::global()->loadIcon( "mail-message", KIconLoader::Desktop,
00195                                                      KIconLoader::SizeMedium ) );
00196 
00197   tab1.mEmailWidget = new EmailEditWidget( page );
00198   connect( tab1.mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00199   tab1.layout->addWidget( tab1.mEmailWidget, 5, 4, 1, 2 );
00200 
00201   // add the separator
00202 
00203   tab1.mInternetLabel->setPixmap( KIconLoader::global()->loadIcon( "internet-web-browser", KIconLoader::Desktop,
00204                                                      KIconLoader::SizeMedium ) );
00205 
00206   tab1.mURLLabel->setText( i18nc( "<urlLabel>:", "%1:", KABC::Addressee::urlLabel() ) );
00207 
00208   connect( tab1.mURLEdit, SIGNAL( textChanged( const QString& ) ),
00209            SLOT( textChanged( const QString& ) ) );
00210 
00211   connect( tab1.mBlogEdit, SIGNAL( textChanged( const QString & ) ),
00212            SLOT( textChanged( const QString & ) ) );
00213 
00214   mIMWidget = new IMEditWidget( page, mAddressee, tab1.mInetLayout );
00215   connect( mIMWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
00216   tab1.layout->addWidget( mIMWidget, 7, 4, 3, 2 );
00217 
00218   // Categories
00219   connect( tab1.mCategoryButton, SIGNAL( clicked() ), SLOT( selectCategories() ) );
00220 
00221   connect( tab1.mCategoryEdit, SIGNAL( textChanged( const QString& ) ),
00222            SLOT( textChanged( const QString& ) ) );
00223 
00224   connect( tab1.mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
00225 
00226   // Build the layout and add to the tab widget
00227   //layout->activate(); // required
00228 
00229   mTabWidget->addTab( page, i18n( "&General" ) );
00230 }
00231 
00232 void AddresseeEditorWidget::setupTab2()
00233 {
00234   // This is the Details tab
00235   QWidget *page = new QWidget( mTabWidget );
00236   tab2.setupUi( page );
00237 
00239   // Office info
00240 
00241   // Department
00242   tab2.mDepartmentIcon->setPixmap( KIconLoader::global()->loadIcon( "folder", KIconLoader::Desktop,
00243                                                      KIconLoader::SizeMedium ) );
00244   connect( tab2.mDepartmentEdit, SIGNAL( textChanged( const QString& ) ),
00245            SLOT( textChanged( const QString& ) ) );
00246   connect( tab2.mOfficeEdit, SIGNAL( textChanged( const QString& ) ),
00247            SLOT( textChanged( const QString& ) ) );
00248   connect( tab2.mProfessionEdit, SIGNAL( textChanged( const QString& ) ),
00249            SLOT( textChanged( const QString& ) ) );
00250   connect( tab2.mManagerEdit, SIGNAL( textChanged( const QString& ) ),
00251            SLOT( textChanged( const QString& ) ) );
00252   connect( tab2.mAssistantEdit, SIGNAL( textChanged( const QString& ) ),
00253            SLOT( textChanged( const QString& ) ) );
00254   tab2.mTitleLabel->setText( i18nc( "<titleLabel>:", "%1:", KABC::Addressee::titleLabel() ) );
00255   connect( tab2.mTitleEdit, SIGNAL( textChanged( const QString& ) ),
00256            SLOT( textChanged( const QString& ) ) );
00257 
00259   // Personal info
00260 
00261   tab2.mPersonalIcon->setPixmap( KIconLoader::global()->loadIcon( "user-identity", KIconLoader::Desktop,
00262                                                      KIconLoader::SizeMedium ) );
00263   connect( tab2.mNicknameEdit, SIGNAL( textChanged( const QString& ) ),
00264            SLOT( textChanged( const QString& ) ) );
00265   tab2.mSpouseLabel->setText( i18nc( "Wife/Husband/...", "Partner's name:" ) );
00266   connect( tab2.mSpouseEdit, SIGNAL( textChanged( const QString& ) ),
00267            SLOT( textChanged( const QString& ) ) );
00268   connect( tab2.mBirthdayPicker, SIGNAL( dateChanged( const QDate& ) ),
00269            SLOT( dateChanged( const QDate& ) ) );
00270   connect( tab2.mBirthdayPicker, SIGNAL( textChanged( const QString& ) ),
00271            SLOT( emitModified() ) );
00272   connect( tab2.mAnniversaryPicker, SIGNAL( dateChanged( const QDate& ) ),
00273            SLOT( dateChanged( const QDate& ) ) );
00274   connect( tab2.mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ),
00275            SLOT( emitModified() ) );
00277   // Notes
00278   tab2.mNoteEdit->setWordWrapMode ( QTextOption::WrapAnywhere );
00279   tab2.mNoteEdit->setMinimumSize( tab2.mNoteEdit->sizeHint() );
00280   connect( tab2.mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) );
00281 
00282   mTabWidget->addTab( page, i18n( "&Details" ) );
00283 }
00284 
00285 void AddresseeEditorWidget::setupAdditionalTabs()
00286 {
00287   ContactEditorWidgetManager *manager = ContactEditorWidgetManager::self();
00288 
00289   // create all tab pages and add the widgets
00290   for ( int i = 0; i < manager->count(); ++i ) {
00291     QString pageIdentifier = manager->factory( i )->pageIdentifier();
00292     QString pageTitle = manager->factory( i )->pageTitle();
00293 
00294     if ( pageIdentifier == "misc" )
00295       pageTitle = i18n( "Misc" );
00296 
00297     ContactEditorTabPage *page = mTabPages[ pageIdentifier ];
00298     if ( page == 0 ) { // tab not yet available, create one
00299       page = new ContactEditorTabPage( mTabWidget );
00300       mTabPages.insert( pageIdentifier, page );
00301 
00302       mTabWidget->addTab( page, pageTitle );
00303 
00304       connect( page, SIGNAL( changed() ), SLOT( emitModified() ) );
00305     }
00306 
00307     KAB::ContactEditorWidget *widget
00308               = manager->factory( i )->createWidget( KABC::StdAddressBook::self( true ),
00309                                                      page );
00310     if ( widget )
00311       page->addWidget( widget );
00312   }
00313 
00314   // query the layout update
00315   QHashIterator<QString, ContactEditorTabPage*> it( mTabPages );
00316   while ( it.hasNext() ) {
00317     it.next();
00318     it.value()->updateLayout();
00319   }
00320 }
00321 
00322 void AddresseeEditorWidget::setupCustomFieldsTabs()
00323 {
00324   QStringList activePages = KABPrefs::instance()->advancedCustomFields();
00325 
00326   const QStringList list = KGlobal::dirs()->findAllResources( "data", "kaddressbook/contacteditorpages/*.ui",
00327                                                               KStandardDirs::Recursive |
00328                                                               KStandardDirs::NoDuplicates );
00329   for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
00330     if ( !activePages.contains( (*it).mid( (*it).lastIndexOf('/') + 1 ) )  )
00331       continue;
00332 
00333     ContactEditorTabPage *page = new ContactEditorTabPage( mTabWidget );
00334     AdvancedCustomFields *wdg = new AdvancedCustomFields( *it, KABC::StdAddressBook::self( true ), page );
00335     if ( wdg ) {
00336       mTabPages.insert( wdg->pageIdentifier(), page );
00337       mTabWidget->addTab( page, wdg->pageTitle() );
00338 
00339       page->addWidget( wdg );
00340       page->updateLayout();
00341 
00342       connect( page, SIGNAL( changed() ), SLOT( emitModified() ) );
00343     } else
00344       delete page;
00345   }
00346 }
00347 
00348 void AddresseeEditorWidget::load()
00349 {
00350   kDebug(5720) <<"AddresseeEditorWidget::load()";
00351 
00352   // Block signals in case anything tries to emit modified
00353   // CS: This doesn't seem to work.
00354   bool block = signalsBlocked();
00355   blockSignals( true );
00356   mBlockSignals = true; // used for internal signal blocking
00357 
00358   tab1.mNameEdit->blockSignals( true );
00359   tab1.mNameEdit->setText( mAddressee.assembledName() );
00360   tab1.mNameEdit->blockSignals( false );
00361 
00362   if ( mAddressee.formattedName().isEmpty() ) {
00363     KConfig _config( "kaddressbookrc" );
00364     KConfigGroup config(&_config, "General" );
00365     mFormattedNameType = config.readEntry( "FormattedNameType", 1 );
00366     mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00367   } else {
00368     if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) )
00369       mFormattedNameType = NameEditDialog::SimpleName;
00370     else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) )
00371       mFormattedNameType = NameEditDialog::FullName;
00372     else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseNameWithComma ) )
00373       mFormattedNameType = NameEditDialog::ReverseNameWithComma;
00374     else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) )
00375       mFormattedNameType = NameEditDialog::ReverseName;
00376     else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::Organization ) )
00377       mFormattedNameType = NameEditDialog::Organization;
00378     else
00379       mFormattedNameType = NameEditDialog::CustomName;
00380   }
00381 
00382   tab1.mFormattedNameLabel->setText( mAddressee.formattedName() );
00383 
00384   tab1.mRoleEdit->setText( mAddressee.role() );
00385   tab1.mOrgEdit->setText( mAddressee.organization() );
00386   tab2.mDepartmentEdit->setText( mAddressee.department() );
00387   // compatibility with older versions
00388   if ( mAddressee.department().isEmpty() )
00389     tab2.mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) );
00390   tab1.mURLEdit->setUrl( mAddressee.url() );
00391   tab1.mURLEdit->home( false );
00392   tab1.mBlogEdit->setUrl( mAddressee.custom( "KADDRESSBOOK", "BlogFeed" ) );
00393   tab2.mNoteEdit->setText( mAddressee.note() );
00394   tab1.mEmailWidget->setEmails( mAddressee.emails() );
00395   tab1.mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
00396   tab1.mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
00397   tab2.mBirthdayPicker->setDate( mAddressee.birthday().date() );
00398 
00399   QString anniversaryStr = mAddressee.custom( "KADDRESSBOOK", "X-Anniversary" );
00400   QDate anniversary = (anniversaryStr.isEmpty() ? QDate() : QDate::fromString( anniversaryStr, Qt::ISODate ));
00401   tab2.mAnniversaryPicker->setDate( anniversary );
00402   tab2.mNicknameEdit->setText( mAddressee.nickName() );
00403   tab1.mCategoryEdit->setText( mAddressee.categories().join( "," ) );
00404 
00405   tab1.mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
00406 
00407   // Load customs
00408   mIMWidget->setPreferredIM( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) );
00409   tab2.mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) );
00410   tab2.mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) );
00411   tab2.mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
00412   tab2.mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) );
00413   tab2.mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) );
00414   tab2.mTitleEdit->setText( mAddressee.title() );
00415 
00416   QHashIterator<QString, ContactEditorTabPage*> it( mTabPages );
00417   while ( it.hasNext() ) {
00418     it.next();
00419     it.value()->loadContact( &mAddressee );
00420   }
00421 
00422   blockSignals( block );
00423   mBlockSignals = false;
00424 
00425   mDirty = false;
00426 }
00427 
00428 void AddresseeEditorWidget::save()
00429 {
00430   if ( !mDirty ) return;
00431 
00432   mAddressee.setRole( tab1.mRoleEdit->text() );
00433   mAddressee.setOrganization( tab1.mOrgEdit->text() );
00434   mAddressee.setDepartment( tab2.mDepartmentEdit->text() );
00435   mAddressee.setUrl( KUrl( tab1.mURLEdit->text().trimmed() ) );
00436   if ( !tab1.mBlogEdit->text().isEmpty() )
00437     mAddressee.insertCustom( "KADDRESSBOOK", "BlogFeed", tab1.mBlogEdit->text() );
00438   else
00439     mAddressee.removeCustom( "KADDRESSBOOK", "BlogFeed" );
00440 
00441   mAddressee.setNote( tab2.mNoteEdit->toPlainText() );
00442   if ( tab2.mBirthdayPicker->date().isValid() )
00443     mAddressee.setBirthday( QDateTime( tab2.mBirthdayPicker->date() ) );
00444   else
00445     mAddressee.setBirthday( QDateTime() );
00446 
00447   mAddressee.setNickName( tab2.mNicknameEdit->text() );
00448   mAddressee.setCategories( tab1.mCategoryEdit->text().split( ",", QString::SkipEmptyParts ) );
00449 
00450   mAddressee.setSecrecy( tab1.mSecrecyWidget->secrecy() );
00451 
00452   // save custom fields
00453   if ( !mIMWidget->preferredIM().isEmpty() )
00454     mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMWidget->preferredIM() );
00455   else
00456     mAddressee.removeCustom( "KADDRESSBOOK", "X-IMAddress" );
00457   if ( !tab2.mSpouseEdit->text().isEmpty() )
00458     mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", tab2.mSpouseEdit->text() );
00459   else
00460     mAddressee.removeCustom( "KADDRESSBOOK", "X-SpousesName" );
00461   if ( !tab2.mManagerEdit->text().isEmpty() )
00462     mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", tab2.mManagerEdit->text() );
00463   else
00464     mAddressee.removeCustom( "KADDRESSBOOK", "X-ManagersName" );
00465   if ( !tab2.mAssistantEdit->text().isEmpty() )
00466     mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", tab2.mAssistantEdit->text() );
00467   else
00468     mAddressee.removeCustom( "KADDRESSBOOK", "X-AssistantsName" );
00469 
00470   if ( !tab2.mOfficeEdit->text().isEmpty() )
00471     mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", tab2.mOfficeEdit->text() );
00472   else
00473     mAddressee.removeCustom( "KADDRESSBOOK", "X-Office" );
00474   if ( !tab2.mProfessionEdit->text().isEmpty() )
00475     mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", tab2.mProfessionEdit->text() );
00476   else
00477     mAddressee.removeCustom( "KADDRESSBOOK", "X-Profession" );
00478 
00479   if ( tab2.mAnniversaryPicker->date().isValid() )
00480     mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
00481                              tab2.mAnniversaryPicker->date().toString( Qt::ISODate ) );
00482   else
00483     mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
00484 
00485   mAddressee.setTitle( tab2.mTitleEdit->text() );
00486 
00487   // Save the email addresses
00488   mAddressee.setEmails( tab1.mEmailWidget->emails() );
00489 
00490   // Save the phone numbers
00491   KABC::PhoneNumber::List phoneNumbers;
00492   KABC::PhoneNumber::List::ConstIterator phoneIter;
00493   phoneNumbers = mAddressee.phoneNumbers();
00494   for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00495         ++phoneIter )
00496     mAddressee.removePhoneNumber( *phoneIter );
00497 
00498   phoneNumbers = tab1.mPhoneEditWidget->phoneNumbers();
00499   for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00500         ++phoneIter )
00501     mAddressee.insertPhoneNumber( *phoneIter );
00502 
00503   // Save the addresses
00504   KABC::Address::List addresses;
00505   KABC::Address::List::ConstIterator addressIter;
00506   addresses = mAddressee.addresses();
00507   for ( addressIter = addresses.begin(); addressIter != addresses.end();
00508         ++addressIter )
00509     mAddressee.removeAddress( *addressIter );
00510 
00511   addresses = tab1.mAddressEditWidget->addresses();
00512   for ( addressIter = addresses.begin(); addressIter != addresses.end();
00513         ++addressIter )
00514     mAddressee.insertAddress( *addressIter );
00515 
00516   QHashIterator<QString, ContactEditorTabPage*> it( mTabPages );
00517   while ( it.hasNext() ) {
00518     it.next();
00519     it.value()->storeContact( &mAddressee );
00520   }
00521 
00522   mDirty = false;
00523 }
00524 
00525 bool AddresseeEditorWidget::dirty()
00526 {
00527   return mDirty;
00528 }
00529 
00530 void AddresseeEditorWidget::nameTextChanged( const QString &text )
00531 {
00532   // use the addressee class to parse the name for us
00533   AddresseeConfig config( mAddressee );
00534   if ( config.automaticNameParsing() ) {
00535     if ( !mAddressee.formattedName().isEmpty() ) {
00536       QString fn = mAddressee.formattedName();
00537       mAddressee.setNameFromString( text );
00538       mAddressee.setFormattedName( fn );
00539     } else {
00540       // use extra addressee to avoid a formatted name assignment
00541       Addressee addr;
00542       addr.setNameFromString( text );
00543       mAddressee.setPrefix( addr.prefix() );
00544       mAddressee.setGivenName( addr.givenName() );
00545       mAddressee.setAdditionalName( addr.additionalName() );
00546       mAddressee.setFamilyName( addr.familyName() );
00547       mAddressee.setSuffix( addr.suffix() );
00548     }
00549   }
00550 
00551   nameBoxChanged();
00552 
00553   emitModified();
00554 }
00555 
00556 void AddresseeEditorWidget::organizationTextChanged( const QString &text )
00557 {
00558 
00559   AddresseeConfig config( mAddressee );
00560   if ( config.automaticNameParsing() )
00561     mAddressee.setOrganization( text );
00562 
00563   nameBoxChanged();
00564 
00565   tab1.mAddressEditWidget->updateAddressee( mAddressee );
00566 
00567   emitModified();
00568 }
00569 
00570 void AddresseeEditorWidget::nameBoxChanged()
00571 {
00572   KABC::Addressee addr;
00573   AddresseeConfig config( mAddressee );
00574   if ( config.automaticNameParsing() ) {
00575     addr.setNameFromString( tab1.mNameEdit->text() );
00576     mNameLabel->hide();
00577     tab1.mNameEdit->show();
00578   } else {
00579     addr = mAddressee;
00580     tab1.mNameEdit->hide();
00581     mNameLabel->setText( tab1.mNameEdit->text() );
00582     mNameLabel->show();
00583   }
00584 
00585   if ( mFormattedNameType != NameEditDialog::CustomName ) {
00586     tab1.mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00587     mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
00588   }
00589 
00590   tab1.mAddressEditWidget->updateAddressee( mAddressee );
00591 }
00592 
00593 void AddresseeEditorWidget::nameButtonClicked()
00594 {
00595   // show the name dialog.
00596   NameEditDialog dialog( mAddressee, mFormattedNameType, mReadOnly, this );
00597 
00598   if ( dialog.exec() ) {
00599     if ( dialog.changed() ) {
00600       mAddressee.setFamilyName( dialog.familyName() );
00601       mAddressee.setGivenName( dialog.givenName() );
00602       mAddressee.setPrefix( dialog.prefix() );
00603       mAddressee.setSuffix( dialog.suffix() );
00604       mAddressee.setAdditionalName( dialog.additionalName() );
00605       mFormattedNameType = dialog.formattedNameType();
00606       if ( mFormattedNameType == NameEditDialog::CustomName ) {
00607         tab1.mFormattedNameLabel->setText( dialog.customFormattedName() );
00608         mAddressee.setFormattedName( dialog.customFormattedName() );
00609       }
00610       // Update the name edit.
00611       bool block = tab1.mNameEdit->signalsBlocked();
00612       tab1.mNameEdit->blockSignals( true );
00613       tab1.mNameEdit->setText( mAddressee.assembledName() );
00614       tab1.mNameEdit->blockSignals( block );
00615 
00616       // Update the combo box.
00617       nameBoxChanged();
00618 
00619       emitModified();
00620     }
00621   }
00622 }
00623 
00624 void AddresseeEditorWidget::selectCategories()
00625 {
00626   // Show the category dialog
00627   if ( mCategorySelectDialog == 0 ) {
00628     mCategorySelectDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
00629     connect( mCategorySelectDialog, SIGNAL( categoriesSelected( const QStringList& ) ),
00630              this, SLOT( categoriesSelected( const QStringList& ) ) );
00631     connect( mCategorySelectDialog, SIGNAL( editCategories() ),
00632              this, SLOT( editCategories() ) );
00633   }
00634 
00635   mCategorySelectDialog->setSelected( tab1.mCategoryEdit->text().split( ",", QString::SkipEmptyParts) );
00636   mCategorySelectDialog->show();
00637   mCategorySelectDialog->raise();
00638 }
00639 
00640 void AddresseeEditorWidget::categoriesSelected( const QStringList &list )
00641 {
00642   tab1.mCategoryEdit->setText( list.join( "," ) );
00643 }
00644 
00645 void AddresseeEditorWidget::editCategories()
00646 {
00647   if ( mCategoryEditDialog == 0 ) {
00648     mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
00649     connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
00650              mCategorySelectDialog, SLOT( updateCategoryConfig() ) );
00651   }
00652 
00653   mCategoryEditDialog->show();
00654   mCategoryEditDialog->raise();
00655 }
00656 
00657 void AddresseeEditorWidget::emitModified()
00658 {
00659   if ( mBlockSignals )
00660     return;
00661 
00662   mDirty = true;
00663 
00664   emit modified();
00665 }
00666 
00667 void AddresseeEditorWidget::dateChanged( const QDate& )
00668 {
00669   emitModified();
00670 }
00671 
00672 void AddresseeEditorWidget::invalidDate()
00673 {
00674   KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
00675 }
00676 
00677 void AddresseeEditorWidget::pageChanged( QWidget *wdg )
00678 {
00679   if ( wdg )
00680     KAcceleratorManager::manage( wdg );
00681 }
00682 
00683 void AddresseeEditorWidget::setInitialFocus()
00684 {
00685   tab1.mNameEdit->setFocus();
00686 }
00687 
00688 bool AddresseeEditorWidget::readyToClose()
00689 {
00690   bool ok = true;
00691 
00692   QDate date = tab2.mBirthdayPicker->date();
00693   if ( !date.isValid() && !tab2.mBirthdayPicker->currentText().isEmpty() ) {
00694     KMessageBox::error( this, i18n( "You have to enter a valid birthdate." ) );
00695     ok = false;
00696   }
00697 
00698   date = tab2.mAnniversaryPicker->date();
00699   if ( !date.isValid() && !tab2.mAnniversaryPicker->currentText().isEmpty() ) {
00700     KMessageBox::error( this, i18n( "You have to enter a valid anniversary." ) );
00701     ok = false;
00702   }
00703 
00704   return ok;
00705 }
00706 
00707 void AddresseeEditorWidget::setReadOnly( bool readOnly )
00708 {
00709   mReadOnly = readOnly;
00710 
00711   tab1.mNameEdit->setReadOnly( readOnly );
00712   tab1.mRoleEdit->setReadOnly( readOnly );
00713   tab1.mOrgEdit->setReadOnly( readOnly );
00714   tab1.mPhoneEditWidget->setReadOnly( readOnly );
00715   tab1.mAddressEditWidget->setReadOnly( readOnly );
00716   tab1.mEmailWidget->setReadOnly( readOnly );
00717   tab1.mURLEdit->setReadOnly( readOnly );
00718   tab1.mBlogEdit->setReadOnly( readOnly );
00719   mIMWidget->setReadOnly( readOnly );
00720   tab1.mCategoryButton->setEnabled( !readOnly );
00721   tab1.mSecrecyWidget->setReadOnly( readOnly );
00722   tab2.mDepartmentEdit->setReadOnly( readOnly );
00723   tab2.mOfficeEdit->setReadOnly( readOnly );
00724   tab2.mProfessionEdit->setReadOnly( readOnly );
00725   tab2.mManagerEdit->setReadOnly( readOnly );
00726   tab2.mAssistantEdit->setReadOnly( readOnly );
00727   tab2.mTitleEdit->setReadOnly( readOnly );
00728   tab2.mNicknameEdit->setReadOnly( readOnly );
00729   tab2.mSpouseEdit->setReadOnly( readOnly );
00730   tab2.mBirthdayPicker->setEnabled( !readOnly );
00731   tab2.mAnniversaryPicker->setEnabled( !readOnly );
00732   tab2.mNoteEdit->setReadOnly( mReadOnly );
00733 
00734   QHashIterator<QString, ContactEditorTabPage*> it( mTabPages );
00735   while ( it.hasNext() ) {
00736     it.next();
00737     it.value()->setReadOnly( readOnly );
00738   }
00739 }
00740 
00741 #include "addresseeeditorwidget.moc"

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal