Diffstat (limited to 'kaddressbook/addresseeeditorwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/addresseeeditorwidget.cpp | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/kaddressbook/addresseeeditorwidget.cpp b/kaddressbook/addresseeeditorwidget.cpp index 3cfc1f2..826c69b 100644 --- a/kaddressbook/addresseeeditorwidget.cpp +++ b/kaddressbook/addresseeeditorwidget.cpp @@ -42,97 +42,96 @@ #include "keywidget.h" #include "geowidget.h" #include "imagewidget.h" #include "nameeditdialog.h" #include "phoneeditwidget.h" #include "secrecywidget.h" #include <qtoolbutton.h> #include <qtooltip.h> #include <kapplication.h> #include <kconfig.h> #include <kcombobox.h> #include <kdebug.h> #include <kdialogbase.h> #include <kglobal.h> #include <kiconloader.h> #include <klineedit.h> #include <klocale.h> #include <kmessagebox.h> #include <kseparator.h> #include <ksqueezedtextlabel.h> #include <libkdepim/categoryeditdialog.h> #include <libkdepim/categoryselectdialog.h> #include <libkdepim/kdateedit.h> #include "addresseditwidget.h" #include "emaileditwidget.h" #include "kabcore.h" #include "kabprefs.h" #include "addresseeeditorwidget.h" AddresseeEditorWidget::AddresseeEditorWidget( KABCore *core, bool isExtension, QWidget *parent, const char *name ) : ExtensionWidget( core, parent, name ), mIsExtension( isExtension ), mBlockSignals( false ) { mAConfig = AddresseeConfig::instance(); - kdDebug(5720) << "AddresseeEditorWidget()" << endl; mFormattedNameType = NameEditDialog::CustomName; initGUI(); mCategoryDialog = 0; mCategoryEditDialog = 0; // Load the empty addressee as defaults load(); mDirty = false; } AddresseeEditorWidget::~AddresseeEditorWidget() { kdDebug(5720) << "~AddresseeEditorWidget()" << endl; } void AddresseeEditorWidget::contactsSelectionChanged() { KABC::Addressee::List list = selectedContacts(); mAddressee = list[ 0 ]; load(); } void AddresseeEditorWidget::setAddressee( const KABC::Addressee &addr ) { mAddressee = addr; load(); } const KABC::Addressee &AddresseeEditorWidget::addressee() { return mAddressee; } void AddresseeEditorWidget::textChanged( const QString& ) { emitModified(); } void AddresseeEditorWidget::initGUI() { QVBoxLayout *layout = new QVBoxLayout( this ); mTabWidget = new QTabWidget( this ); layout->addWidget( mTabWidget ); setupTab1(); @@ -587,96 +586,97 @@ void AddresseeEditorWidget::setupTab2() label = new QLabel( i18n( "Assistant's name:" ), tab2 ); //US layout->addWidget( label, 1, 3 ); layout->addWidget( label, 4, 1 ); mAssistantEdit = new KLineEdit( tab2 ); connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mAssistantEdit ); //US layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 ); layout->addWidget( mAssistantEdit, 4, 2 ); bar = new KSeparator( KSeparator::HLine, tab2 ); //US layout->addMultiCellWidget( bar, 3, 3, 0, 5 ); layout->addMultiCellWidget( bar, 5, 5, 0, 2 ); ///////////////////////////////////////////////// // Personal info label = new QLabel( tab2 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) ); //US layout->addMultiCellWidget( label, 4, 5, 0, 0 ); layout->addMultiCellWidget( label, 6, 7, 0, 0 ); label = new QLabel( i18n( "Nick name:" ), tab2 ); //US layout->addWidget( label, 4, 1 ); layout->addWidget( label, 6, 1 ); mNicknameEdit = new KLineEdit( tab2 ); connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mNicknameEdit ); //US layout->addWidget( mNicknameEdit, 4, 2 ); layout->addWidget( mNicknameEdit, 6, 2 ); label = new QLabel( i18n( "Spouse's name:" ), tab2 ); //US layout->addWidget( label, 5, 1 ); layout->addWidget( label, 7, 1 ); mSpouseEdit = new KLineEdit( tab2 ); connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mSpouseEdit ); //US layout->addWidget( mSpouseEdit, 5, 2 ); layout->addWidget( mSpouseEdit, 7, 2 ); label = new QLabel( i18n( "Birthday:" ), tab2 ); //US layout->addWidget( label, 4, 3 ); layout->addWidget( label, 8, 1 ); mBirthdayPicker = new KDateEdit( tab2 ); + mBirthdayPicker->toggleDateFormat(); mBirthdayPicker->setHandleInvalid( true ); connect( mBirthdayPicker, SIGNAL( dateChanged( QDate ) ), SLOT( dateChanged( QDate ) ) ); #ifndef KAB_EMBEDDED //US invalid dates are handdled by the KDateEdit widget itself connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ), SLOT( invalidDate() ) ); connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ), SLOT( emitModified() ) ); #endif //KAB_EMBEDDED label->setBuddy( mBirthdayPicker ); //US layout->addWidget( mBirthdayPicker, 4, 4 ); layout->addWidget( mBirthdayPicker, 8, 2 ); label = new QLabel( i18n( "Anniversary:" ), tab2 ); //US layout->addWidget( label, 5, 3 ); layout->addWidget( label, 9, 1 ); mAnniversaryPicker = new KDateEdit( tab2 ); mAnniversaryPicker->setHandleInvalid( true ); connect( mAnniversaryPicker, SIGNAL( dateChanged( QDate ) ), SLOT( dateChanged( QDate ) ) ); #ifndef KAB_EMBEDDED //US invalid dates are handled by the KDateEdit widget itself connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ), SLOT( invalidDate() ) ); connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ), SLOT( emitModified() ) ); #endif //KAB_EMBEDDED label->setBuddy( mAnniversaryPicker ); //US layout->addWidget( mAnniversaryPicker, 5, 4 ); layout->addWidget( mAnniversaryPicker, 9, 2 ); /*US bar = new KSeparator( KSeparator::HLine, tab2 ); layout->addMultiCellWidget( bar, 6, 6, 0, 5 ); ////////////////////////////////////// // Notes label = new QLabel( i18n( "Note:" ), tab2 ); label->setAlignment( Qt::AlignTop | Qt::AlignLeft ); layout->addWidget( label, 7, 0 ); #ifndef KAB_EMBEDDED mNoteEdit = new QTextEdit( tab2 ); mNoteEdit->setWordWrap( QTextEdit::WidgetWidth ); @@ -902,319 +902,345 @@ void AddresseeEditorWidget::setupTab3_1() // This is the Misc tab QWidget *tab3 = new QWidget( mTabWidget ); //US QGridLayout *layout = new QGridLayout( tab3, 2, 3 ); QGridLayout *layout = new QGridLayout( tab3, 1, 1 ); layout->setMargin( KDialogBase::marginHint() ); layout->setSpacing( KDialogBase::spacingHint() ); //US layout->setColStretch( 2, 1 ); /*US ////////////////////////////////////// // Geo mGeoWidget = new GeoWidget( tab3 ); mGeoWidget->setMinimumSize( mGeoWidget->sizeHint() ); connect( mGeoWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mGeoWidget, 0, 0, Qt::AlignTop ); */ ////////////////////////////////////// // Sound #ifndef KAB_EMBEDDED mSoundWidget = new SoundWidget( tab3 ); mSoundWidget->setMinimumSize( mSoundWidget->sizeHint() ); connect( mSoundWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mSoundWidget, 0, 1, Qt::AlignTop ); #else //KAB_EMBEDDED //US qDebug("AddresseeEditorWidget::setupTab2 sound part is not supported = has to be changed"); #endif //KAB_EMBEDDED ////////////////////////////////////// // Images mImageWidget = new ImageWidget( tab3 ); mImageWidget->setMinimumSize( mImageWidget->sizeHint() ); connect( mImageWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mImageWidget, 0, 0, Qt::AlignTop ); /*US ////////////////////////////////////// // Keys mKeyWidget = new KeyWidget( tab3 ); mKeyWidget->setMinimumSize( mKeyWidget->sizeHint() ); connect( mKeyWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mKeyWidget, 1, 1, Qt::AlignTop ); */ mTabWidget->addTab( tab3, i18n( "&Images" ) ); } void AddresseeEditorWidget::load() { - kdDebug(5720) << "AddresseeEditorWidget::load()" << endl; // Block signals in case anything tries to emit modified // CS: This doesn't seem to work. bool block = signalsBlocked(); blockSignals( true ); mBlockSignals = true; // used for internal signal blocking mNameEdit->setText( mAddressee.assembledName() ); if ( mAddressee.formattedName().isEmpty() ) { //US KConfig config( "kaddressbookrc" ); KConfig config( locateLocal("config", "kaddressbookrc") ); config.setGroup( "General" ); mFormattedNameType = config.readNumEntry( "FormattedNameType", 1 ); mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) ); } else { if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) ) mFormattedNameType = NameEditDialog::SimpleName; else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) ) mFormattedNameType = NameEditDialog::FullName; else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) ) mFormattedNameType = NameEditDialog::ReverseName; else mFormattedNameType = NameEditDialog::CustomName; } mFormattedNameLabel->setText( mAddressee.formattedName() ); mRoleEdit->setText( mAddressee.role() ); mOrgEdit->setText( mAddressee.organization() ); //US mURLEdit->setURL( mAddressee.url().url() ); mURLEdit->setText( mAddressee.url().prettyURL() ); //US?? mURLEdit->home( false ); // mNoteEdit->setText( mAddressee.note() ); mNoteEdit->setText( mAddressee.note() ); mEmailWidget->setEmails( mAddressee.emails() ); mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() ); mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() ); mBirthdayPicker->setDate( mAddressee.birthday().date() ); //US mAnniversaryPicker->setDate( QDate::fromString( mAddressee.custom( //US "KADDRESSBOOK", "X-Anniversary" ), Qt::ISODate) ); QDate dt = KGlobal::locale()->readDate( mAddressee.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate mAnniversaryPicker->setDate( dt ); mNicknameEdit->setText( mAddressee.nickName() ); mCategoryEdit->setText( mAddressee.categories().join( "," ) ); mGeoWidget->setGeo( mAddressee.geo() ); mImageWidget->setPhoto( mAddressee.photo() ); mImageWidget->setLogo( mAddressee.logo() ); mKeyWidget->setKeys( mAddressee.keys() ); mSecrecyWidget->setSecrecy( mAddressee.secrecy() ); #ifndef KAB_EMBEDDED mSoundWidget->setSound( mAddressee.sound() ); #else //KAB_EMBEDDED //US qDebug("AddresseeEditorWidget::load has to be changed 2"); #endif //KAB_EMBEDDED // Load customs mIMAddressEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) ); mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) ); mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) ); mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) ); mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) ); mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) ); mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) ); blockSignals( block ); mBlockSignals = false; mDirty = false; } void AddresseeEditorWidget::save() { - if ( !mDirty ) return; + if ( !dirty() ) { + return; + } mAddressee.setRole( mRoleEdit->text() ); mAddressee.setOrganization( mOrgEdit->text() ); mAddressee.setUrl( KURL( mURLEdit->text() ) ); mAddressee.setNote( mNoteEdit->text() ); - if ( mBirthdayPicker->inputIsValid() ) - mAddressee.setBirthday( QDateTime( mBirthdayPicker->date() ) ); - else + if ( mBirthdayPicker->inputIsValid() ) { + QDate da = mBirthdayPicker->date(); + if ( da > QDate::currentDate() ) + da.setYMD(da.year()-100, da.month(), da.day() ); + mAddressee.setBirthday( QDateTime( da ) ); + qDebug("bday %s ",da.toString().latin1()); + } + else { mAddressee.setBirthday( QDateTime() ); - + mBirthdayPicker->clear(); + } mAddressee.setNickName( mNicknameEdit->text() ); mAddressee.setCategories( QStringList::split( ",", mCategoryEdit->text() ) ); mAddressee.setGeo( mGeoWidget->geo() ); mAddressee.setPhoto( mImageWidget->photo() ); mAddressee.setLogo( mImageWidget->logo() ); mAddressee.setKeys( mKeyWidget->keys() ); #ifndef KAB_EMBEDDED mAddressee.setSound( mSoundWidget->sound() ); #else //KAB_EMBEDDED //US qDebug("AddresseeEditorWidget::save sound not supported"); #endif //KAB_EMBEDDED mAddressee.setSecrecy( mSecrecyWidget->secrecy() ); // save custom fields mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMAddressEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() ); if ( mAnniversaryPicker->inputIsValid() ) { - -//US mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", -//US mAnniversaryPicker->date().toString( Qt::ISODate ) ); QString dt = KGlobal::locale()->formatDate(mAnniversaryPicker->date(), true, KLocale::ISODate); mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); } - else + else { mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" ); + mAnniversaryPicker->clear(); + } // Save the email addresses QStringList emails = mAddressee.emails(); QStringList::Iterator iter; for ( iter = emails.begin(); iter != emails.end(); ++iter ) mAddressee.removeEmail( *iter ); emails = mEmailWidget->emails(); bool first = true; for ( iter = emails.begin(); iter != emails.end(); ++iter ) { mAddressee.insertEmail( *iter, first ); first = false; } // Save the phone numbers KABC::PhoneNumber::List phoneNumbers; KABC::PhoneNumber::List::Iterator phoneIter; phoneNumbers = mAddressee.phoneNumbers(); for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end(); ++phoneIter ) mAddressee.removePhoneNumber( *phoneIter ); phoneNumbers = mPhoneEditWidget->phoneNumbers(); for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end(); ++phoneIter ) mAddressee.insertPhoneNumber( *phoneIter ); // Save the addresses KABC::Address::List addresses; KABC::Address::List::Iterator addressIter; addresses = mAddressee.addresses(); for ( addressIter = addresses.begin(); addressIter != addresses.end(); ++addressIter ) mAddressee.removeAddress( *addressIter ); addresses = mAddressEditWidget->addresses(); for ( addressIter = addresses.begin(); addressIter != addresses.end(); ++addressIter ) mAddressee.insertAddress( *addressIter ); mDirty = false; } bool AddresseeEditorWidget::dirty() { + + if ( ! mDirty ) { + if ( mBirthdayPicker->inputIsValid() ) { + QDate da = mBirthdayPicker->date(); + if ( !(da == mAddressee.birthday().date())) + mDirty = true; + } + else { + mBirthdayPicker->clear(); + } + if ( mAnniversaryPicker->inputIsValid() ) { + QDate da = mAnniversaryPicker->date(); + if ( da != KGlobal::locale()->readDate( mAddressee.custom("KADDRESSBOOK", "X-Anniversary" ), + "%Y-%m-%d")) + mDirty = true; + } + else { + mAnniversaryPicker->clear(); + } + } return mDirty; } void AddresseeEditorWidget::nameTextChanged( const QString &text ) { // use the addressee class to parse the name for us mAConfig->setUid( mAddressee.uid() ); if ( mAConfig->automaticNameParsing() ) { if ( !mAddressee.formattedName().isEmpty() ) { - QString fn = mAddressee.formattedName(); - mAddressee.setNameFromString( text ); - mAddressee.setFormattedName( fn ); + QString fn = mAddressee.formattedName(); + mAddressee.setNameFromString( text ); + mAddressee.setFormattedName( fn ); } else { // use extra addressee to avoid a formatted name assignment Addressee addr; addr.setNameFromString( text ); mAddressee.setPrefix( addr.prefix() ); mAddressee.setGivenName( addr.givenName() ); mAddressee.setAdditionalName( addr.additionalName() ); mAddressee.setFamilyName( addr.familyName() ); mAddressee.setSuffix( addr.suffix() ); } } nameBoxChanged(); emitModified(); } void AddresseeEditorWidget::nameBoxChanged() { KABC::Addressee addr; mAConfig->setUid( mAddressee.uid() ); if ( mAConfig->automaticNameParsing() ) { addr.setNameFromString( mNameEdit->text() ); mNameLabel->hide(); mNameEdit->show(); } else { addr = mAddressee; mNameEdit->hide(); mNameLabel->setText( mNameEdit->text() ); mNameLabel->show(); } if ( mFormattedNameType != NameEditDialog::CustomName ) { mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) ); mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) ); } } void AddresseeEditorWidget::nameButtonClicked() { // show the name dialog. NameEditDialog dialog( mAddressee, mFormattedNameType, this ); - if ( dialog.exec() ) { + if ( KApplication::execDialog( &dialog) ) { if ( dialog.changed() ) { mAddressee.setFamilyName( dialog.familyName() ); mAddressee.setGivenName( dialog.givenName() ); mAddressee.setPrefix( dialog.prefix() ); mAddressee.setSuffix( dialog.suffix() ); mAddressee.setAdditionalName( dialog.additionalName() ); mFormattedNameType = dialog.formattedNameType(); if ( mFormattedNameType == NameEditDialog::CustomName ) { mFormattedNameLabel->setText( dialog.customFormattedName() ); mAddressee.setFormattedName( dialog.customFormattedName() ); } // Update the name edit. bool block = mNameEdit->signalsBlocked(); mNameEdit->blockSignals( true ); mNameEdit->setText( mAddressee.assembledName() ); mNameEdit->blockSignals( block ); // Update the combo box. nameBoxChanged(); emitModified(); } } } void AddresseeEditorWidget::categoryButtonClicked() { // Show the category dialog if ( mCategoryDialog == 0 ) { mCategoryDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this ); connect( mCategoryDialog, SIGNAL( categoriesSelected( const QStringList& ) ), SLOT(categoriesSelected( const QStringList& ) ) ); connect( mCategoryDialog, SIGNAL( editCategories() ), SLOT( editCategories() ) ); } mCategoryDialog->setCategories(); mCategoryDialog->setSelected( QStringList::split( ",", mCategoryEdit->text() ) ); mCategoryDialog->show(); mCategoryDialog->raise(); } void AddresseeEditorWidget::categoriesSelected( const QStringList &list ) { mCategoryEdit->setText( list.join( "," ) ); } void AddresseeEditorWidget::editCategories() { |