author | eilers <eilers> | 2003-01-04 14:24:36 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-01-04 14:24:36 (UTC) |
commit | 4a9e13d7b9220b45cbbbdfab5f2ea56ea415d6a7 (patch) (side-by-side diff) | |
tree | 00babfde2cfd15687cb87d73800e75630afdab0b /core/pim/addressbook/contacteditor.cpp | |
parent | 851c182383c34fd4925677713bb5f6fd603c86a0 (diff) | |
download | opie-4a9e13d7b9220b45cbbbdfab5f2ea56ea415d6a7.zip opie-4a9e13d7b9220b45cbbbdfab5f2ea56ea415d6a7.tar.gz opie-4a9e13d7b9220b45cbbbdfab5f2ea56ea415d6a7.tar.bz2 |
Hope I fixed the default-email bugs..
Diffstat (limited to 'core/pim/addressbook/contacteditor.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/addressbook/contacteditor.cpp | 224 |
1 files changed, 182 insertions, 42 deletions
diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp index c5ad0c4..37e3a54 100644 --- a/core/pim/addressbook/contacteditor.cpp +++ b/core/pim/addressbook/contacteditor.cpp @@ -48,2 +48,3 @@ #include <qiconset.h> +#include <qmessagebox.h> @@ -646,3 +647,4 @@ void ContactEditor::init() { void ContactEditor::defaultEmailChanged(int i){ - qDebug("defaultEmailChanged"); + qDebug("defaultEmailChanged"); + int index = cmbChooserField1->currentItem(); @@ -650,2 +652,5 @@ void ContactEditor::defaultEmailChanged(int i){ + defaultEmail = cmbDefaultEmail->text(i); + qDebug ("Changed to: %s", defaultEmail.latin1()); + } @@ -653,44 +658,153 @@ void ContactEditor::defaultEmailChanged(int i){ void ContactEditor::populateDefaultEmailCmb(){ + + // if the default-email combo was not selected and therfore not created + // we get a lot of trouble.. Therfore create an invisible one.. + if ( !cmbDefaultEmail ){ + cmbDefaultEmail = new QComboBox(this); + cmbDefaultEmail -> hide(); + } cmbDefaultEmail->clear(); - cmbDefaultEmail->insertStringList(emails); + cmbDefaultEmail->insertStringList( emails ); + // cmbDefaultEmail->show(); + + // Select default email in combo.. + bool found = false; for ( int i = 0; i < cmbDefaultEmail->count(); i++){ - qDebug(" populateDefaultEmailCmb text >%s< defaultEmail >%s<",cmbDefaultEmail->text( i ).latin1(),defaultEmail.latin1()); - if ( cmbDefaultEmail->text( i ).stripWhiteSpace() == defaultEmail.stripWhiteSpace() ){ - cmbDefaultEmail->setCurrentItem( i ); - qDebug("set"); + qDebug(" populateDefaultEmailCmb text >%s< defaultEmail >%s<", + cmbDefaultEmail->text( i ).latin1(), defaultEmail.latin1()); + + if ( cmbDefaultEmail->text( i ).stripWhiteSpace() == defaultEmail.stripWhiteSpace() ){ + cmbDefaultEmail->setCurrentItem( i ); + qDebug("set"); + found = true; } } + + // If the current default email is not found in the list, we choose the + // first one.. + if ( !found ) + defaultEmail = cmbDefaultEmail->text(0); +} + +// Called when any combobox was changed. +// "true" returned if the change was chandled by this function, else it should +// be handled by something else.. +bool ContactEditor::cmbChooserChange( int index, QLineEdit *inputWid, int widgetPos ) { + QString type = slChooserNames[index]; + qWarning("ContactEditor::cmbChooserChange -> Type: %s", type.latin1() ); + + // Create and connect combobox for selecting the default email + if ( type == "Default Email"){ + qWarning("Choosing default-email "); + + // More than one defaul-email chooser is not allowed ! + if ( ( defaultEmailChooserPosition != -1 ) && + defaultEmailChooserPosition != widgetPos ){ + chooserError( widgetPos ); + return true; + } + + if ( cmbDefaultEmail ){ + delete cmbDefaultEmail; + cmbDefaultEmail = 0l; + } + cmbDefaultEmail = new QComboBox(inputWid->parentWidget()); + cmbDefaultEmail->setGeometry(inputWid->frameGeometry()); + + connect( cmbDefaultEmail,SIGNAL( activated(int) ), + SLOT( defaultEmailChanged(int) ) ); + + cmbDefaultEmail->clear(); + cmbDefaultEmail->insertStringList( emails ); + cmbDefaultEmail->show(); + + defaultEmailChooserPosition = widgetPos; + + // Set current default email + populateDefaultEmailCmb(); + + + } else { + // Something else was selected: Hide combo.. + qWarning(" Hiding default-email combo" ); + if ( defaultEmailChooserPosition == widgetPos ){ + defaultEmailChooserPosition = -1; + if ( cmbDefaultEmail ) + cmbDefaultEmail->hide(); + + } + + // Caller should initialize the responsible textfield, therefore + // "false" is returned + return false; + } + + // Everything is worked off .. + return true; + +} + +// Currently accessed when we select default-email more than once ! +void ContactEditor::chooserError( int index ) +{ + qWarning("ContactEditor::chooserError( %d )", index); + QMessageBox::warning( this, "Chooser Error", + "Multiple selection of this\n" + "Item is not allowed !\n\n" + "First deselect the previous one !", + "&OK", 0, 0, + 0, 0 ); + + // Reset the selected Chooser. Unfortunately the chooser + // generates no signal, therfore we have to + // call the cmbChooserChange function manually.. + switch( index ){ + case 1: + cmbChooserField1 -> setCurrentItem( 0 ); + slotCmbChooser1Change( 0 ); + break; + case 2: + cmbChooserField2 -> setCurrentItem( 0 ); + slotCmbChooser2Change( 0 ); + break; + case 3: + cmbChooserField3 -> setCurrentItem( 0 ); + slotCmbChooser3Change( 0 ); + break; + case 4: + cmbChooserField4 -> setCurrentItem( 0 ); + slotCmbChooser4Change( 0 ); + break; + } } -void ContactEditor::chooserChange( const QString &textChanged, int index, QLineEdit *inputWid, int widgetPos ) { +// Called when something was changed in a textfield (shouldn't it called textchanged? (se)) +void ContactEditor::chooserChange( const QString &textChanged, int index, + QLineEdit* , int widgetPos ) { + QString type = slChooserNames[index]; - qDebug("ContactEditor::chooserChange( type=>%s<, textChanged=>%s< index=%i, widgetPos=%i",type.latin1(),textChanged.latin1(), index, widgetPos ); + qDebug("ContactEditor::chooserChange( type=>%s<, textChanged=>%s< index=%i, widgetPos=%i", + type.latin1(),textChanged.latin1(), index, widgetPos ); + if ( type == "Default Email"){ - defaultEmail = textChanged; - if (cmbDefaultEmail){ - delete cmbDefaultEmail; - cmbDefaultEmail = 0l; - } - cmbDefaultEmail = new QComboBox(inputWid->parentWidget()); - cmbDefaultEmail->setGeometry(inputWid->frameGeometry()); - cmbDefaultEmail->show(); - populateDefaultEmailCmb(); - connect(cmbDefaultEmail,SIGNAL(activated(int)), - SLOT(defaultEmailChanged(int))); - defaultEmailChooserPosition = widgetPos; + qWarning ("??? Wozu??: %s", textChanged.latin1()); + defaultEmail = textChanged; + + populateDefaultEmailCmb(); + }else if (defaultEmailChooserPosition == widgetPos){ - qDebug("cmbDefaultEmail->hide()"); - if (cmbDefaultEmail) cmbDefaultEmail->hide(); - widgetPos=-1; + qDebug("cmbDefaultEmail->hide()"); + + if (cmbDefaultEmail) cmbDefaultEmail->hide(); + widgetPos=-1; + }else if (type == "Emails"){ - qDebug("emails"); - QString de; - emails = QStringList::split (",", textChanged ); + qDebug("emails"); + + QString de; + emails = QStringList::split (",", textChanged ); - if ( cmbDefaultEmail ) - populateDefaultEmailCmb(); + populateDefaultEmailCmb(); } - - slChooserValues[index] = textChanged; @@ -700,2 +814,3 @@ void ContactEditor::chooserChange( const QString &textChanged, int index, QLineE void ContactEditor::slotChooser1Change( const QString &textChanged ) { + qWarning("ContactEditor::slotChooser1Change( %s )", textChanged.latin1()); chooserChange( textChanged, cmbChooserField1->currentItem(), txtChooserField1, 1); @@ -704,2 +819,3 @@ void ContactEditor::slotChooser1Change( const QString &textChanged ) { void ContactEditor::slotChooser2Change( const QString &textChanged ) { + qWarning("ContactEditor::slotChooser2Change( %s )", textChanged.latin1()); chooserChange( textChanged, cmbChooserField2->currentItem(), txtChooserField2, 2); @@ -709,2 +825,3 @@ void ContactEditor::slotChooser2Change( const QString &textChanged ) { void ContactEditor::slotChooser3Change( const QString &textChanged ) { + qWarning("ContactEditor::slotChooser3Change( %s )", textChanged.latin1()); chooserChange( textChanged, cmbChooserField3->currentItem(), txtChooserField3, 3); @@ -713,2 +830,3 @@ void ContactEditor::slotChooser3Change( const QString &textChanged ) { void ContactEditor::slotChooser4Change( const QString &textChanged ) { + qWarning("ContactEditor::slotChooser4Change( %s )", textChanged.latin1()); chooserChange( textChanged, cmbChooserField4->currentItem(), txtChooserField4, 4); @@ -782,5 +900,11 @@ void ContactEditor::slotCountryChange( const QString &textChanged ) { void ContactEditor::slotCmbChooser1Change( int index ) { + qWarning("ContactEditor::slotCmbChooser1Change( %d )", index); + + if ( !cmbChooserChange( cmbChooserField1->currentItem(), txtChooserField1, 1) ){ + + txtChooserField1->setText( slChooserValues[index] ); + txtChooserField1->setFocus(); + + } - txtChooserField1->setText( slChooserValues[index] ); - txtChooserField1->setFocus(); } @@ -788,5 +912,10 @@ void ContactEditor::slotCmbChooser1Change( int index ) { void ContactEditor::slotCmbChooser2Change( int index ) { + qWarning("ContactEditor::slotCmbChooser2Change( %d )", index); + + if ( !cmbChooserChange( cmbChooserField2->currentItem(), txtChooserField2, 2) ){ - txtChooserField2->setText( slChooserValues[index] ); - txtChooserField2->setFocus(); + txtChooserField2->setText( slChooserValues[index] ); + txtChooserField2->setFocus(); + + } } @@ -794,6 +923,10 @@ void ContactEditor::slotCmbChooser2Change( int index ) { void ContactEditor::slotCmbChooser3Change( int index ) { + qWarning("ContactEditor::slotCmbChooser3Change( %d )", index); + + if ( !cmbChooserChange( cmbChooserField3->currentItem(), txtChooserField3, 3) ){ - txtChooserField3->setText( slChooserValues[index] ); - txtChooserField3->setFocus(); + txtChooserField3->setText( slChooserValues[index] ); + txtChooserField3->setFocus(); + } } @@ -801,6 +934,10 @@ void ContactEditor::slotCmbChooser3Change( int index ) { void ContactEditor::slotCmbChooser4Change( int index ) { + qWarning("ContactEditor::slotCmbChooser4Change( %d )", index); + + if ( !cmbChooserChange( cmbChooserField4->currentItem(), txtChooserField4, 4) ){ - txtChooserField4->setText( slChooserValues[index] ); - txtChooserField4->setFocus(); + txtChooserField4->setText( slChooserValues[index] ); + txtChooserField4->setFocus(); + } } @@ -1450,5 +1587,8 @@ void ContactEditor::saveEntry() { QString defaultmail; - parseEmailFrom( *itV, defaultmail, allemail ); - // ent.clearEmails(); -// ent.setDefaultEmail( defaultmail ); + parseEmailFrom( emails.join(","), defaultmail, allemail ); + if ( defaultEmail.isEmpty() ){ + qWarning("Default email was not set by user!"); + qWarning("Using first email in list: %s", defaultmail.latin1()); + ent.setDefaultEmail( defaultmail ); + } ent.setEmails( allemail ); @@ -1457,3 +1597,3 @@ void ContactEditor::saveEntry() { if ( *it == "Default Email") - ent.setDefaultEmail( *itV ); + ent.setDefaultEmail( defaultEmail /* *itV */ ); |