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., 675 Mass Ave, Cambridge, MA 02139, 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 <qtabwidget.h>
00026 #include <qlayout.h>
00027 #include <qlabel.h>
00028 #include <qpushbutton.h>
00029 #include <qtoolbutton.h>
00030 #include <qtextedit.h>
00031 #include <qtooltip.h>
00032 #include <qlistbox.h>
00033 #include <qhbox.h>
00034 
00035 #include <kaccelmanager.h>
00036 #include <kapplication.h>
00037 #include <kglobal.h>
00038 #include <kiconloader.h>
00039 #include <kconfig.h>
00040 #include <klocale.h>
00041 #include <kdialogbase.h>
00042 #include <kseparator.h>
00043 #include <kmessagebox.h>
00044 #include <klineedit.h>
00045 #include <kcombobox.h>
00046 #include <kdebug.h>
00047 #include <ksqueezedtextlabel.h>
00048 
00049 #include <libkdepim/categoryselectdialog.h>
00050 #include <libkdepim/categoryeditdialog.h>
00051 
00052 #include <libkdepim/kdateedit.h>
00053 
00054 #include "nameeditdialog.h"
00055 #include "phoneeditwidget.h"
00056 #include "addresseditwidget.h"
00057 #include "emaileditwidget.h"
00058 #include "kabprefs.h"
00059 
00060 #include "addresseeeditorwidget.h"
00061 
00062 AddresseeEditorWidget::AddresseeEditorWidget( QWidget *parent, 
00063                                             const char *name)
00064   : QWidget( parent, name )
00065 {
00066   initGUI();
00067   mCategoryDialog = 0;
00068   mCategoryEditDialog = 0;
00069   
00070   // Load the empty addressee as defaults
00071   load();
00072   
00073   mDirty = false;
00074 }
00075 
00076 AddresseeEditorWidget::~AddresseeEditorWidget()
00077 {
00078   kdDebug() << "~AddresseeEditorWidget()" << endl;
00079 }  
00080   
00081 void AddresseeEditorWidget::setAddressee(const KABC::Addressee &a)
00082 {
00083   mAddressee = a;
00084   load();
00085 }
00086 
00087 const KABC::Addressee &AddresseeEditorWidget::addressee()
00088 {
00089   return mAddressee;
00090 }
00091 
00092 void AddresseeEditorWidget::textChanged(const QString &)
00093 {
00094   emitModified();
00095 }
00096   
00097 void AddresseeEditorWidget::initGUI()
00098 {
00099   QVBoxLayout *layout = new QVBoxLayout( this );
00100 
00101   mTabWidget = new QTabWidget( this );
00102   layout->addWidget( mTabWidget );
00103 
00104   setupTab1();
00105   setupTab2();
00106   setupTab3();
00107 
00108   mNameEdit->setFocus();
00109 
00110   connect( mTabWidget, SIGNAL( currentChanged(QWidget*) ), SLOT( pageChanged(QWidget*) ) );
00111 }
00112 
00113 void AddresseeEditorWidget::setupTab1()
00114 {
00115   // This is the General tab
00116   QWidget *tab1 = new QWidget( mTabWidget );
00117 
00118   QGridLayout *layout = new QGridLayout(tab1, 11, 7);
00119   layout->setMargin(KDialogBase::marginHint());
00120   layout->setSpacing(KDialogBase::spacingHint());
00121   
00122   QLabel *label;
00123   KSeparator* bar;
00124   QPushButton *button;
00125   
00127   // Upper left group (person info)
00128   
00129   // Person icon
00130   label = new QLabel(tab1);
00131   label->setPixmap(KGlobal::iconLoader()->loadIcon("personal", KIcon::Desktop));
00132   layout->addMultiCellWidget(label, 0, 1, 0, 0);
00133   
00134   // First name
00135   button = new QPushButton( i18n("Name..."), tab1 );
00136   QToolTip::add(button, i18n("Edit the contact's name"));
00137   mNameEdit = new KLineEdit( tab1, "mNameEdit" );
00138   connect( mNameEdit, SIGNAL( textChanged(const QString & )), 
00139            SLOT( nameTextChanged(const QString & )));
00140   connect( button, SIGNAL( clicked()), this, SLOT( nameButtonClicked()));
00141   mNameLabel = new KSqueezedTextLabel( tab1 );
00142   mNameLabel->hide();
00143   layout->addWidget( button, 0, 1 );
00144   layout->addWidget( mNameEdit, 0, 2 );
00145   layout->addWidget( mNameLabel, 0, 2 );
00146   label = new QLabel( i18n("Role:"), tab1 );
00147   mRoleEdit = new KLineEdit( tab1, "mRoleEdit" );
00148   connect(mRoleEdit, SIGNAL( textChanged(const QString &) ),
00149           SLOT( textChanged(const QString &) ));
00150   label->setBuddy( mRoleEdit );
00151   layout->addWidget( label, 1, 1 );
00152   layout->addWidget( mRoleEdit, 1, 2 );
00153   
00154   // Organization
00155   label = new QLabel( i18n("Organization:"), tab1 );
00156   mOrgEdit = new KLineEdit( tab1, "mOrgEdit" );
00157   label->setBuddy( mOrgEdit );
00158   connect( mOrgEdit, SIGNAL( textChanged(const QString &) ), 
00159            SLOT( textChanged(const QString &) ));
00160   layout->addWidget( label, 2, 1 );
00161   layout->addWidget( mOrgEdit, 2, 2 );
00162   
00163   // File as (formatted name)
00164   label = new QLabel( i18n("Formatted name:"), tab1 );
00165   mFormattedNameBox = new KComboBox(true, tab1, "mFormattedNameBox");
00166   mFormattedNameBox->setDuplicatesEnabled(false);
00167   mFormattedNameBox->setAutoCompletion(true);
00168   label->setBuddy( mFormattedNameBox );
00169   connect(mFormattedNameBox, SIGNAL(activated(const QString &)),
00170           SLOT(textChanged(const QString &)));
00171   connect(mFormattedNameBox, SIGNAL(textChanged(const QString &)),
00172           SLOT(textChanged(const QString &)));
00173   connect(mFormattedNameBox, SIGNAL(textChanged(const QString &)),
00174           SLOT(formattedNameChanged(const QString &)));
00175   layout->addWidget( label, 3, 1 );
00176   layout->addWidget( mFormattedNameBox, 3, 2 );
00177   
00178   // Left hand separator. This separator doesn't go all the way
00179   // across so the dialog still flows from top to bottom
00180   bar = new KSeparator( KSeparator::HLine, tab1);
00181   layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
00182   
00184   // Phone numbers (upper right)
00185   label = new QLabel(tab1);
00186   label->setPixmap(KGlobal::iconLoader()->loadIcon("kaddressbook",
00187                                                    KIcon::Desktop));
00188   layout->addMultiCellWidget(label, 0, 1, 3, 3);
00189   
00190   mPhoneEditWidget = new PhoneEditWidget(tab1, "mPhoneEditWidget");
00191   connect(mPhoneEditWidget, SIGNAL(modified()), this,
00192           SLOT(emitModified()));
00193   layout->addMultiCellWidget(mPhoneEditWidget, 0, 3, 4, 6); 
00194   
00195   bar = new KSeparator( KSeparator::HLine, tab1);
00196   layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
00197   
00199   // Addresses (lower left)
00200   label = new QLabel(tab1);
00201   label->setPixmap(KGlobal::iconLoader()->loadIcon("gohome",
00202                                                    KIcon::Desktop));
00203   layout->addMultiCellWidget(label, 5, 6, 0, 0);
00204   
00205   mAddressEditWidget = new AddressEditWidget(tab1, "mAddressEditWidget");
00206   connect(mAddressEditWidget, SIGNAL(modified()), this, SLOT(emitModified()));
00207   layout->addMultiCellWidget(mAddressEditWidget, 5, 9, 1, 2);
00208 
00210   // Email / Web (lower right)
00211   label = new QLabel(tab1);
00212   label->setPixmap(KGlobal::iconLoader()->loadIcon("email",
00213                                                    KIcon::Desktop));
00214   layout->addMultiCellWidget(label, 5, 6, 3, 3);
00215 
00216   mEmailWidget = new EmailEditWidget(tab1, "mEmailWidget");
00217   connect(mEmailWidget, SIGNAL(modified()), this, SLOT(emitModified()));
00218   layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
00219 
00220   // add the separator
00221   bar = new KSeparator( KSeparator::HLine, tab1);
00222   layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
00223 
00224   label = new QLabel(tab1);
00225   label->setPixmap(KGlobal::iconLoader()->loadIcon("homepage",
00226                                                    KIcon::Desktop));
00227   layout->addMultiCellWidget(label, 8, 9, 3, 3);
00228 
00229   label = new QLabel( i18n("URL:"), tab1 );
00230   mURLEdit = new KLineEdit( tab1, "mURLEdit" );
00231   connect( mURLEdit, SIGNAL( textChanged(const QString & )), 
00232            SLOT( textChanged(const QString & )));
00233   label->setBuddy( mURLEdit );
00234   layout->addWidget( label, 8, 4 );
00235   layout->addMultiCellWidget( mURLEdit, 8, 8, 5, 6 );
00236 
00237   label = new QLabel( i18n( "&IM address:"), tab1 );
00238   mIMAddressEdit = new KLineEdit(tab1, "mIMAddressEdit");
00239   connect( mIMAddressEdit, SIGNAL( textChanged(const QString & )), 
00240            SLOT( textChanged(const QString & )));
00241   label->setBuddy( mIMAddressEdit );
00242   layout->addWidget( label, 9, 4 );
00243   layout->addMultiCellWidget( mIMAddressEdit, 9, 9, 5, 6 );
00244   
00245   layout->addColSpacing(6, 50); 
00246   
00247   bar = new KSeparator(KSeparator::HLine, tab1);
00248   layout->addMultiCellWidget(bar, 10, 10, 0, 6);
00249   
00251   QHBox *categoryBox = new QHBox( tab1 );
00252   categoryBox->setSpacing( KDialogBase::spacingHint() );
00253   
00254   // Categories
00255   button = new QPushButton(i18n("Categories"), categoryBox);
00256   connect(button, SIGNAL(clicked()), SLOT(categoryButtonClicked()));
00257 
00258   mCategoryEdit = new KLineEdit(categoryBox, "mCategoryEdit");
00259   mCategoryEdit->setReadOnly(true);
00260   connect(mCategoryEdit, SIGNAL(textChanged(const QString &)), 
00261           SLOT(textChanged(const QString &)));
00262 
00263   layout->addMultiCellWidget(categoryBox, 11, 11, 0, 6);
00264   
00265   // Build the layout and add to the tab widget
00266   layout->activate(); // required
00267 
00268   mTabWidget->addTab( tab1, i18n( "&General" ) );
00269 }
00270 
00271 void AddresseeEditorWidget::setupTab2()
00272 {
00273   // This is the Details tab
00274   QWidget *tab2 = new QWidget( mTabWidget );
00275 
00276   QGridLayout *layout = new QGridLayout(tab2, 6, 6);
00277   layout->setMargin(KDialogBase::marginHint());
00278   layout->setSpacing(KDialogBase::spacingHint());
00279   
00280   QLabel *label;
00281   KSeparator* bar;
00282   
00284   // Office info
00285   
00286   // Department
00287   label = new QLabel(tab2);
00288   label->setPixmap(KGlobal::iconLoader()->loadIcon("folder", KIcon::Desktop));
00289   layout->addMultiCellWidget(label, 0, 1, 0, 0);
00290   
00291   label = new QLabel(i18n("Department:"), tab2);
00292   layout->addWidget(label, 0, 1);
00293   mDepartmentEdit = new KLineEdit(tab2, "mDepartmentEdit");
00294   connect(mDepartmentEdit, SIGNAL(textChanged(const QString &)),
00295           SLOT(textChanged(const QString &)));
00296   label->setBuddy( mDepartmentEdit );
00297   layout->addWidget(mDepartmentEdit, 0, 2);
00298   
00299   label = new QLabel(i18n("Office:"), tab2);
00300   layout->addWidget(label, 1, 1);
00301   mOfficeEdit = new KLineEdit(tab2, "mOfficeEdit");
00302   connect(mOfficeEdit, SIGNAL(textChanged(const QString &)),
00303           SLOT(textChanged(const QString &)));
00304   label->setBuddy( mOfficeEdit );
00305   layout->addWidget(mOfficeEdit, 1, 2);
00306   
00307   label = new QLabel(i18n("Profession:"), tab2);
00308   layout->addWidget(label, 2, 1);
00309   mProfessionEdit = new KLineEdit(tab2, "mProfessionEdit");
00310   connect(mProfessionEdit, SIGNAL(textChanged(const QString &)),
00311           SLOT(textChanged(const QString &)));
00312   label->setBuddy( mProfessionEdit );
00313   layout->addWidget(mProfessionEdit, 2, 2);
00314   
00315   label = new QLabel(i18n("Manager\'s name:"), tab2);
00316   layout->addWidget(label, 0, 3);
00317   mManagerEdit = new KLineEdit(tab2, "mManagerEdit");
00318   connect(mManagerEdit, SIGNAL(textChanged(const QString &)),
00319           SLOT(textChanged(const QString &)));
00320   label->setBuddy( mManagerEdit );
00321   layout->addMultiCellWidget(mManagerEdit, 0, 0, 4, 5);
00322   
00323   label = new QLabel(i18n("Assistant's name:"), tab2);
00324   layout->addWidget(label, 1, 3);
00325   mAssistantEdit = new KLineEdit(tab2, "mAssistantEdit");
00326   connect(mAssistantEdit, SIGNAL(textChanged(const QString &)),
00327           SLOT(textChanged(const QString &)));
00328   label->setBuddy( mAssistantEdit );
00329   layout->addMultiCellWidget(mAssistantEdit, 1, 1, 4, 5);
00330   
00331   bar = new KSeparator(KSeparator::HLine, tab2);
00332   layout->addMultiCellWidget(bar, 3, 3, 0, 5);
00333   
00335   // Personal info
00336   
00337   label = new QLabel(tab2);
00338   label->setPixmap(KGlobal::iconLoader()->loadIcon("personal", KIcon::Desktop));
00339   layout->addMultiCellWidget(label, 4, 5, 0, 0);
00340   
00341   label = new QLabel(i18n("Nick name:"), tab2);
00342   layout->addWidget(label, 4, 1);
00343   mNicknameEdit = new KLineEdit(tab2, "mNicknameEdit");
00344   connect(mNicknameEdit, SIGNAL(textChanged(const QString &)),
00345           SLOT(textChanged(const QString &)));
00346   label->setBuddy( mNicknameEdit );
00347   layout->addWidget(mNicknameEdit, 4, 2);
00348 
00349   label = new QLabel(i18n("Spouse's name:"), tab2);
00350   layout->addWidget(label, 5, 1);
00351   mSpouseEdit = new KLineEdit(tab2, "mSpouseEdit");
00352   connect(mSpouseEdit, SIGNAL(textChanged(const QString &)),
00353           SLOT(textChanged(const QString &)));
00354   label->setBuddy( mSpouseEdit );
00355   layout->addWidget(mSpouseEdit, 5, 2);
00356 
00357   label = new QLabel(i18n("Birthday:"), tab2);
00358   layout->addWidget(label, 4, 3);
00359   mBirthdayPicker = new KDateEdit(tab2, "mBirthdayPicker");
00360   mBirthdayPicker->setHandleInvalid(true);
00361   connect(mBirthdayPicker, SIGNAL(dateChanged(QDate)),
00362           SLOT(dateChanged(QDate)));
00363   connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ),
00364            SLOT( invalidDate() ) );
00365   label->setBuddy( mBirthdayPicker );
00366   layout->addWidget(mBirthdayPicker, 4, 4);
00367   
00368   label = new QLabel(i18n("Anniversary:"), tab2);
00369   layout->addWidget(label, 5, 3);
00370   mAnniversaryPicker = new KDateEdit(tab2, "mAnniversaryPicker");
00371   mAnniversaryPicker->setHandleInvalid(true);
00372   connect(mAnniversaryPicker, SIGNAL(dateChanged(QDate)),
00373           SLOT(dateChanged(QDate)));
00374   connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ),
00375            SLOT( invalidDate() ) );
00376   label->setBuddy( mAnniversaryPicker );
00377   layout->addWidget(mAnniversaryPicker, 5, 4);
00378   
00379   bar = new KSeparator(KSeparator::HLine, tab2);
00380   layout->addMultiCellWidget(bar, 6, 6, 0, 5);
00381   
00383   // Notes
00384   label = new QLabel(i18n("Note:"), tab2);
00385   label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
00386   layout->addWidget(label, 7, 0);
00387   mNoteEdit = new QTextEdit( tab2, "mNoteEdit" );
00388   mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
00389   mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
00390   connect(mNoteEdit, SIGNAL(textChanged()),
00391           SLOT(emitModified()));
00392   label->setBuddy( mNoteEdit );
00393   layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
00394   
00395    // Build the layout and add to the tab widget
00396   layout->activate(); // required
00397 
00398   mTabWidget->addTab( tab2, i18n( "&Details" ) );
00399 }
00400 
00401 void AddresseeEditorWidget::setupTab3()
00402 {
00403 }
00404     
00405 void AddresseeEditorWidget::load()
00406 {
00407   kdDebug() << "AddresseeEditorWidget::load()" << endl;
00408 
00409   // Block signals in case anything tries to emit modified
00410   // CS: This doesn't seem to work.
00411   bool block = signalsBlocked();
00412   blockSignals(true); 
00413 
00414   mNameEdit->setText(mAddressee.assembledName());
00415   mFormattedNameBox->setCurrentText(mAddressee.formattedName());
00416 
00417   mRoleEdit->setText(mAddressee.role());
00418   mOrgEdit->setText(mAddressee.organization());
00419   mURLEdit->setURL(mAddressee.url().url());
00420   mURLEdit->home(false);
00421   mNoteEdit->setText(mAddressee.note());
00422   mEmailWidget->setEmails(mAddressee.emails());
00423   mPhoneEditWidget->setPhoneNumbers(mAddressee.phoneNumbers());
00424   mAddressEditWidget->setAddresses(mAddressee.addresses());
00425   mBirthdayPicker->setDate(mAddressee.birthday().date());
00426   mAnniversaryPicker->setDate(QDate::fromString(mAddressee.custom("KADDRESSBOOK", "X-Anniversary"), Qt::ISODate));
00427   mNicknameEdit->setText(mAddressee.nickName());
00428   mCategoryEdit->setText(mAddressee.categories().join(","));
00429   
00430   // Load customs
00431   mIMAddressEdit->setText(mAddressee.custom("KADDRESSBOOK", "X-IMAddress"));
00432   mSpouseEdit->setText(mAddressee.custom("KADDRESSBOOK", "X-SpousesName"));
00433   mManagerEdit->setText(mAddressee.custom("KADDRESSBOOK", "X-ManagersName"));
00434   mAssistantEdit->setText(mAddressee.custom("KADDRESSBOOK", "X-AssistantsName"));
00435   mDepartmentEdit->setText(mAddressee.custom("KADDRESSBOOK", "X-Department"));
00436   mOfficeEdit->setText(mAddressee.custom("KADDRESSBOOK", "X-Office"));
00437   mProfessionEdit->setText(mAddressee.custom("KADDRESSBOOK", "X-Profession"));
00438   
00439   blockSignals(block);
00440 
00441   mDirty = false;
00442 }
00443 
00444 void AddresseeEditorWidget::save()
00445 {
00446   if ( !mDirty ) return;
00447 
00448   mAddressee.setFormattedName(mFormattedNameBox->currentText());
00449   mAddressee.setRole(mRoleEdit->text());
00450   mAddressee.setOrganization(mOrgEdit->text());
00451   mAddressee.setUrl(KURL(mURLEdit->text()));
00452   mAddressee.setNote(mNoteEdit->text());
00453   if ( mBirthdayPicker->inputIsValid() )
00454     mAddressee.setBirthday(QDateTime(mBirthdayPicker->date()));
00455   else
00456     mAddressee.setBirthday(QDateTime());
00457   
00458   mAddressee.setNickName(mNicknameEdit->text());
00459   mAddressee.setCategories(QStringList::split(",", mCategoryEdit->text()));
00460   
00461   // save custom fields
00462   mAddressee.insertCustom("KADDRESSBOOK", "X-IMAddress",
00463                           mIMAddressEdit->text());
00464   mAddressee.insertCustom("KADDRESSBOOK", "X-SpousesName",
00465                           mSpouseEdit->text());
00466   mAddressee.insertCustom("KADDRESSBOOK", "X-ManagersName",
00467                           mManagerEdit->text());
00468   mAddressee.insertCustom("KADDRESSBOOK", "X-AssistantsName",
00469                           mAssistantEdit->text());
00470   mAddressee.insertCustom("KADDRESSBOOK", "X-Department",
00471                           mDepartmentEdit->text());
00472   mAddressee.insertCustom("KADDRESSBOOK", "X-Office",
00473                           mOfficeEdit->text());
00474   mAddressee.insertCustom("KADDRESSBOOK", "X-Profession",
00475                           mProfessionEdit->text());
00476   if ( mAnniversaryPicker->inputIsValid() )
00477     mAddressee.insertCustom("KADDRESSBOOK", "X-Anniversary",
00478                           mAnniversaryPicker->date().toString(Qt::ISODate));
00479   else
00480     mAddressee.removeCustom("KADDRESSBOOK", "X-Anniversary");
00481                           
00482   // Save the email addresses
00483   QStringList emails = mAddressee.emails();
00484   QStringList::Iterator iter;
00485   for (iter = emails.begin(); iter != emails.end(); ++iter)
00486     mAddressee.removeEmail(*iter);
00487   
00488   emails = mEmailWidget->emails();
00489   bool first = true;
00490   for (iter = emails.begin(); iter != emails.end(); ++iter)
00491   {
00492     mAddressee.insertEmail(*iter, first);
00493     first = false;
00494   }
00495   
00496   // Save the phone numbers
00497   KABC::PhoneNumber::List phoneNumbers;
00498   KABC::PhoneNumber::List::Iterator phoneIter;
00499   phoneNumbers = mAddressee.phoneNumbers();
00500   for (phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00501         ++phoneIter)
00502     mAddressee.removePhoneNumber(*phoneIter);
00503     
00504   phoneNumbers = mPhoneEditWidget->phoneNumbers();
00505   for (phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
00506         ++phoneIter)
00507     mAddressee.insertPhoneNumber(*phoneIter);
00508 
00509   // Save the addresses
00510   KABC::Address::List addresses;
00511   KABC::Address::List::Iterator addressIter;
00512   addresses = mAddressee.addresses();
00513   for (addressIter = addresses.begin(); addressIter != addresses.end();
00514         ++addressIter)
00515     mAddressee.removeAddress(*addressIter);
00516     
00517   addresses = mAddressEditWidget->addresses();
00518   for (addressIter = addresses.begin(); addressIter != addresses.end();
00519         ++addressIter)
00520     mAddressee.insertAddress(*addressIter);
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::nameBoxChanged()
00557 {
00558   KABC::Addressee addr;
00559   AddresseeConfig config( mAddressee );
00560   if ( config.automaticNameParsing() ) {
00561     addr.setNameFromString( mNameEdit->text() );
00562     mNameLabel->hide();
00563     mNameEdit->show();
00564   } else {
00565     addr = mAddressee;
00566     mNameEdit->hide();
00567     mNameLabel->setText( mNameEdit->text() );
00568     mNameLabel->show();
00569   }
00570 
00571   bool block = mFormattedNameBox->signalsBlocked();
00572   mFormattedNameBox->blockSignals( true );
00573 
00574   int pos = mFormattedNameBox->currentItem();
00575   mFormattedNameBox->clear();
00576   QStringList options;
00577   options << mAddressee.formattedName()
00578           << QString( addr.assembledName() ).simplifyWhiteSpace()
00579           << QString( addr.givenName() + QString(" ") + addr.familyName() ).simplifyWhiteSpace()
00580           << addr.familyName() + QString(", ") + addr.givenName();
00581   mFormattedNameBox->insertStringList(options);
00582   mFormattedNameBox->setCurrentItem( pos );
00583 
00584   mFormattedNameBox->blockSignals( block );
00585 }
00586 
00587 void AddresseeEditorWidget::nameButtonClicked()
00588 {
00589   // show the name dialog.
00590   NameEditDialog dialog( mAddressee, this );
00591   
00592   if (dialog.exec())
00593   {
00594     if ( dialog.changed() ) {
00595       mAddressee.setFamilyName(dialog.familyName());
00596       mAddressee.setGivenName(dialog.givenName());
00597       mAddressee.setPrefix(dialog.prefix());
00598       mAddressee.setSuffix(dialog.suffix());
00599       mAddressee.setAdditionalName(dialog.additionalName());
00600 
00601       // Update the name edit.
00602       bool block = mNameEdit->signalsBlocked();
00603       mNameEdit->blockSignals( true );
00604       mNameEdit->setText( mAddressee.assembledName() );
00605       mNameEdit->blockSignals( block );
00606 
00607       // Update the combo box.
00608       nameBoxChanged();
00609     
00610       emitModified();
00611     }
00612   }
00613 }
00614 
00615 void AddresseeEditorWidget::categoryButtonClicked()
00616 {
00617   // Show the category dialog
00618   if (mCategoryDialog == 0)
00619   {
00620     mCategoryDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
00621     connect(mCategoryDialog, SIGNAL(categoriesSelected(const QStringList &)),
00622             SLOT(categoriesSelected(const QStringList &)));
00623     connect(mCategoryDialog, SIGNAL(editCategories()),
00624             SLOT(editCategories()));
00625   }
00626 
00627   mCategoryDialog->setCategories();
00628   mCategoryDialog->setSelected(QStringList::split(",", mCategoryEdit->text()));
00629   mCategoryDialog->show();
00630   mCategoryDialog->raise();
00631 }
00632 
00633 void AddresseeEditorWidget::categoriesSelected(const QStringList &list)
00634 {
00635   mCategoryEdit->setText(list.join(","));
00636 }
00637 
00638 void AddresseeEditorWidget::editCategories()
00639 {
00640   if (mCategoryEditDialog == 0)
00641   {
00642     mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
00643     connect(mCategoryEditDialog, SIGNAL(categoryConfigChanged()),
00644             SLOT(categoryButtonClicked()));
00645   }
00646   
00647   mCategoryEditDialog->show();
00648   mCategoryEditDialog->raise();
00649 }
00650 
00651 void AddresseeEditorWidget::emitModified()
00652 {
00653 //  kdDebug() << "AddresseeEditorWidget::emitModified()" << endl;
00654 
00655   mDirty = true;
00656   emit modified();
00657 }
00658 
00659 
00660 void AddresseeEditorWidget::dateChanged(QDate)
00661 {
00662   emitModified();
00663 }
00664 
00665 void AddresseeEditorWidget::invalidDate()
00666 {
00667   KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
00668 }
00669 
00670 void AddresseeEditorWidget::formattedNameChanged(const QString &fn)
00671 {
00672   mAddressee.setFormattedName( fn );
00673   QLineEdit *le = mFormattedNameBox->lineEdit();
00674   int pos = 0;
00675   if ( le )
00676     pos = le->cursorPosition();
00677 
00678   nameBoxChanged();
00679 
00680   le->setCursorPosition( pos );
00681 }
00682 
00683 void AddresseeEditorWidget::pageChanged(QWidget *wdg)
00684 {
00685   if ( wdg )
00686     KAcceleratorManager::manage( wdg );
00687 }
00688 
00689 #include "addresseeeditorwidget.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:36 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001