author | eilers <eilers> | 2003-03-04 16:31:18 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-03-04 16:31:18 (UTC) |
commit | 628a783e5d7ec07b5c073c94a77b614439d937ba (patch) (side-by-side diff) | |
tree | 30e64e15b94051b185b4c4eecb849e3767d7610b | |
parent | 8642232f4435bc5341037527d1eb12d1f39781f4 (diff) | |
download | opie-628a783e5d7ec07b5c073c94a77b614439d937ba.zip opie-628a783e5d7ec07b5c073c94a77b614439d937ba.tar.gz opie-628a783e5d7ec07b5c073c94a77b614439d937ba.tar.bz2 |
Name parser completely rewritten ! It is now possible to have as much middle
names as your parents payed for ;)
If you have a lastname which was build out of words like "Klara Anne Marie Freifrau von Lichtenstein" or
"Carlos Marcos del los Rios" you have to use a "," to separate between first andd last names like
this: "del los Rios, Carlos Marcos" or "Freifrau von Lichtenstein, Klara Anne Marie"..
-rw-r--r-- | core/pim/addressbook/TODO | 2 | ||||
-rw-r--r-- | core/pim/addressbook/contacteditor.cpp | 235 | ||||
-rw-r--r-- | core/pim/addressbook/version.h | 4 |
3 files changed, 79 insertions, 162 deletions
diff --git a/core/pim/addressbook/TODO b/core/pim/addressbook/TODO index a0d50a3..106747e 100644 --- a/core/pim/addressbook/TODO +++ b/core/pim/addressbook/TODO @@ -24,17 +24,16 @@ Bugs but not in addressbook: - VCARD: If umlaut (äöüß) in address, the parser gets confused.. Urgent: -------- - Category is on the wrong position after changing to personal and back to normal ( Temporarily workaround: Category is never deactivated.. :S ) -- Fix handling of 3 Firstnames Important: ---------- - "What's this" should be added (Deleyed after Feature Freeze) Less important: --------------- @@ -109,8 +108,9 @@ Fixed/Ready: - Plugin for Today for Birthdays and Anniversaries - Implement a picker/combo for the default email. - Overview window cleanup needed.. - Store last settings of combo-boxes - Personal and Business Web-page is not editable - Default Email-button: A lot of problems: If on second tab: The combo chooser is on the top left of the screen ! :( - Default Email-Button: Sometimes not hiding the textfields completely +- Fix handling of 3 Firstnames diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp index d1338f6..7bc5bde 100644 --- a/core/pim/addressbook/contacteditor.cpp +++ b/core/pim/addressbook/contacteditor.cpp @@ -152,71 +152,76 @@ void ContactEditor::init() { txtFullName = new QLineEdit( container ); gl->addWidget( txtFullName, 0, 1 ); QLabel *l = new QLabel( tr( "Job Title" ), container ); gl->addWidget( l, 1, 0 ); txtJobTitle = new QLineEdit( container ); gl->addWidget( txtJobTitle, 1, 1 ); - l = new QLabel( tr( "Organization" ), container ); + l = new QLabel( tr("Suffix"), container ); gl->addWidget( l, 2, 0 ); + txtSuffix = new QLineEdit( container ); + gl->addWidget( txtSuffix, 2, 1 ); + + l = new QLabel( tr( "Organization" ), container ); + gl->addWidget( l, 3, 0 ); txtOrganization = new QLineEdit( container ); - gl->addWidget( txtOrganization, 2, 1 ); + gl->addWidget( txtOrganization, 3, 1 ); // Chooser 1 cmbChooserField1 = new QComboBox( FALSE, container ); cmbChooserField1->setMaximumWidth( 90 ); - gl->addWidget( cmbChooserField1, 3, 0 ); + gl->addWidget( cmbChooserField1, 4, 0 ); // Textfield for chooser 1. // Now use Widgetstack to contain the textfield and the default-email combo ! m_widgetStack1 = new QWidgetStack( container ); txtChooserField1 = new QLineEdit( m_widgetStack1 ); m_widgetStack1 -> addWidget( txtChooserField1, TextField ); - gl->addWidget( m_widgetStack1, 3, 1 ); + gl->addWidget( m_widgetStack1, 4, 1 ); m_widgetStack1 -> raiseWidget( TextField ); // Chooser 2 cmbChooserField2 = new QComboBox( FALSE, container ); cmbChooserField2->setMaximumWidth( 90 ); - gl->addWidget( cmbChooserField2, 4, 0 ); + gl->addWidget( cmbChooserField2, 5, 0 ); // Textfield for chooser 2 // Now use WidgetStack to contain the textfield and the default-email combo! m_widgetStack2 = new QWidgetStack( container ); txtChooserField2 = new QLineEdit( m_widgetStack2 ); m_widgetStack2 -> addWidget( txtChooserField2, TextField ); - gl->addWidget( m_widgetStack2, 4, 1 ); + gl->addWidget( m_widgetStack2, 5, 1 ); m_widgetStack2 -> raiseWidget( TextField ); // Chooser 3 cmbChooserField3 = new QComboBox( FALSE, container ); cmbChooserField3->setMaximumWidth( 90 ); - gl->addWidget( cmbChooserField3, 5, 0 ); + gl->addWidget( cmbChooserField3, 6, 0 ); // Textfield for chooser 2 // Now use WidgetStack to contain the textfield and the default-email combo! m_widgetStack3 = new QWidgetStack( container ); txtChooserField3 = new QLineEdit( m_widgetStack3 ); m_widgetStack3 -> addWidget( txtChooserField3, TextField ); - gl->addWidget( m_widgetStack3, 5, 1 ); + gl->addWidget( m_widgetStack3, 6, 1 ); m_widgetStack3 -> raiseWidget( TextField ); l = new QLabel( tr( "File As" ), container ); - gl->addWidget( l, 6, 0 ); + gl->addWidget( l, 7, 0 ); cmbFileAs = new QComboBox( TRUE, container ); - gl->addWidget( cmbFileAs, 6, 1 ); + gl->addWidget( cmbFileAs, 7, 1 ); labCat = new QLabel( tr( "Category" ), container ); - gl->addWidget( labCat, 7, 0 ); + gl->addWidget( labCat, 8, 0 ); cmbCat = new CategorySelect( container ); - gl->addWidget( cmbCat, 7, 1 ); + gl->addWidget( cmbCat, 8, 1 ); labCat->show(); cmbCat->show(); btnNote = new QPushButton( tr( "Notes..." ), container ); - gl->addWidget( btnNote, 8, 1 ); + gl->addWidget( btnNote, 9, 1 ); tabMain->insertTab( tabViewport, tr( "General" ) ); tabViewport = new QWidget ( tabMain ); vb = new QVBoxLayout( tabViewport ); svAddress = new QScrollView( tabViewport ); @@ -613,20 +618,20 @@ void ContactEditor::init() { txtMiddleName = new QLineEdit( dlgName ); gl->addWidget( txtMiddleName, 1, 1 ); l = new QLabel( tr("Last Name"), dlgName ); gl->addWidget( l, 2, 0 ); txtLastName = new QLineEdit( dlgName ); gl->addWidget( txtLastName, 2, 1 ); - l = new QLabel( tr("Suffix"), dlgName ); - gl->addWidget( l, 3, 0 ); - txtSuffix = new QLineEdit( dlgName ); - gl->addWidget( txtSuffix, 3, 1 ); +// l = new QLabel( tr("Suffix"), dlgName ); +// gl->addWidget( l, 3, 0 ); +// txtSuffix = new QLineEdit( dlgName ); +// gl->addWidget( txtSuffix, 3, 1 ); space = new QSpacerItem(1,1, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ); gl->addItem( space, 4, 0 ); cmbChooserField1->insertStringList( trlChooserNames ); cmbChooserField2->insertStringList( trlChooserNames ); cmbChooserField3->insertStringList( trlChooserNames ); @@ -1010,24 +1015,26 @@ void ContactEditor::slotAddressTypeChange( int index ) { txtTmp->setText( slHomeAddress[6] ); } } void ContactEditor::slotFullNameChange( const QString &textChanged ) { + qWarning( "ContactEditor::slotFullNameChange( %s )", textChanged.latin1() ); + int index = cmbFileAs->currentItem(); cmbFileAs->clear(); - cmbFileAs->insertItem( parseName( textChanged, 0 ) ); - cmbFileAs->insertItem( parseName( textChanged, 1 ) ); - cmbFileAs->insertItem( parseName( textChanged, 2 ) ); - cmbFileAs->insertItem( parseName( textChanged, 3 ) ); + cmbFileAs->insertItem( parseName( textChanged, NAME_FL ) ); + cmbFileAs->insertItem( parseName( textChanged, NAME_FMLS ) ); + cmbFileAs->insertItem( parseName( textChanged, NAME_LF ) ); + cmbFileAs->insertItem( parseName( textChanged, NAME_LFM ) ); cmbFileAs->setCurrentItem( index ); useFullName = true; } void ContactEditor::accept() { @@ -1053,17 +1060,17 @@ void ContactEditor::slotNote() { void ContactEditor::slotName() { QString tmpName; if (useFullName) { txtFirstName->setText( parseName(txtFullName->text(), NAME_F) ); txtMiddleName->setText( parseName(txtFullName->text(), NAME_M) ); txtLastName->setText( parseName(txtFullName->text(), NAME_L) ); - txtSuffix->setText( parseName(txtFullName->text(), NAME_S) ); + // txtSuffix->setText( parseName(txtFullName->text(), NAME_S) ); } dlgName->showMaximized(); if ( dlgName->exec() ) { tmpName = txtFirstName->text() + " " + txtMiddleName->text() + " " + txtLastName->text() + " " + txtSuffix->text(); txtFullName->setText( tmpName.simplifyWhiteSpace() ); slotFullNameChange( txtFullName->text() ); useFullName = false; @@ -1097,163 +1104,68 @@ QString ContactEditor::parseName( const QString fullName, int type ) { QString simplifiedName( fullName.simplifyWhiteSpace() ); QString strFirstName; QString strMiddleName; QString strLastName; QString strSuffix; QString strTitle; int commapos; - int spCount; - int spPos; - int spPos2; + bool haveLastName = false; + qWarning("Fullname: %s", simplifiedName.latin1()); commapos = simplifiedName.find( ',', 0, TRUE); - spCount = simplifiedName.contains( ' ', TRUE ); + if ( commapos >= 0 ) { + qWarning(" Commapos: %d", commapos ); - if ( commapos == -1 ) { - - switch (spCount) { - case 0: - //return simplifiedName; - if (txtLastName->text() != "") { - strLastName = simplifiedName; - break; - } - if (txtMiddleName->text() != "") { - strMiddleName = simplifiedName; - break; - } - if (txtSuffix->text() != "") { - strSuffix = simplifiedName; - break; - } - strFirstName = simplifiedName; - break; + // A comma (",") separates the lastname from one or + // many first names. Thus, remove the lastname from the + // String and parse the firstnames. - case 1: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strFirstName = simplifiedName.left( spPos ); - strLastName = simplifiedName.mid( spPos + 1 ); - break; + strLastName = simplifiedName.left( commapos ); + simplifiedName= simplifiedName.mid( commapos + 1 ); + haveLastName = true; + qWarning("Fullname without ',': %s", simplifiedName.latin1()); - case 2: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strFirstName = simplifiedName.left( spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - strLastName = simplifiedName.mid( spPos2 + 1 ); - break; + // If we have any lastname, we should now split all first names. + // The first one will be the used as first, the rest as "middle names" - case 3: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strFirstName = simplifiedName.left( spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE ); - strLastName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 ); - strSuffix = simplifiedName.mid( spPos + 1 ); - break; + QStringList allFirstNames = QStringList::split(" ", simplifiedName); + QStringList::Iterator it = allFirstNames.begin(); + strFirstName = *it++; + QStringList allSecondNames; + for ( ; it != allFirstNames.end(); ++it ) + allSecondNames.append( *it ); - case 4: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strTitle = simplifiedName.left( spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE ); - strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strLastName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - strSuffix = simplifiedName.mid( spPos2 + 1 ); - break; + strMiddleName = allSecondNames.join(" "); - default: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strTitle = simplifiedName.left( spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE ); - strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strLastName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - strSuffix = simplifiedName.mid( spPos2 + 1 ); - break; - } } else { - simplifiedName.replace( commapos, 1, " " ); - simplifiedName = simplifiedName.simplifyWhiteSpace(); - - switch (spCount) { - case 0: - //return simplifiedName; - if (txtLastName->text() != "") { - strLastName = simplifiedName; - break; - } - if (txtMiddleName->text() != "") { - strMiddleName = simplifiedName; - break; - } - if (txtSuffix->text() != "") { - strSuffix = simplifiedName; - break; - } - strFirstName = simplifiedName; - break; - - case 1: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strLastName = simplifiedName.left( spPos ); - strFirstName = simplifiedName.mid( spPos + 1 ); - break; - case 2: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strLastName = simplifiedName.left( spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - strMiddleName = simplifiedName.mid( spPos2 + 1 ); - break; + // No comma separator used: We use the first word as firstname, the + // last as second/lastname and everything in the middle as middlename - case 3: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strLastName = simplifiedName.left( spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE ); - strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 ); - strSuffix = simplifiedName.mid( spPos + 1 ); - break; + QStringList allNames = QStringList::split(" ", simplifiedName); + QStringList::Iterator it = allNames.begin(); + strFirstName = *it++; + QStringList allSecondNames; + for ( ; it != --allNames.end(); ++it ) + allSecondNames.append( *it ); - case 4: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strLastName = simplifiedName.left( spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strTitle = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE ); - strFirstName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - strSuffix = simplifiedName.mid( spPos2 + 1 ); - break; + strMiddleName = allSecondNames.join(" "); + strLastName = *(--allNames.end()); - default: - spPos = simplifiedName.find( ' ', 0, TRUE ); - strLastName = simplifiedName.left( spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strTitle = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE ); - strFirstName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos ); - spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE ); - strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos ); - strSuffix = simplifiedName.mid( spPos2 + 1 ); - break; - } } + + qWarning(" strFirstName: %s", strFirstName.latin1()); + qWarning(" strMiddleName: %s", strMiddleName.latin1()); + qWarning(" strLastName: %s", strLastName.latin1()); + qWarning(" strSuffix: %s", strSuffix.latin1()); + qWarning(" strTitle: %s", strTitle.latin1()); + switch (type) { case NAME_FL: return strFirstName + " " + strLastName; case NAME_LF: return strLastName + ", " + strFirstName; case NAME_LFM: @@ -1331,21 +1243,26 @@ void ContactEditor::setEntry( const OContact &entry ) { qDebug("default email=%s",defaultEmail.latin1()); useFullName = false; txtFirstName->setText( ent.firstName() ); txtMiddleName->setText( ent.middleName() ); txtLastName->setText( ent.lastName() ); txtSuffix->setText( ent.suffix() ); - QString *tmpString = new QString; - *tmpString = ent.firstName() + " " + ent.middleName() + - + " " + ent.lastName() + " " + ent.suffix(); +// QString *tmpString = new QString; +// *tmpString = ent.firstName() + " " + ent.middleName() + +// + " " + ent.lastName() + " " + ent.suffix(); +// txtFullName->setText( tmpString->simplifyWhiteSpace() ); - txtFullName->setText( tmpString->simplifyWhiteSpace() ); + // Lastnames with multiple words need to be protected by a comma ! + if ( ent.lastName().contains( ' ', TRUE ) ) + txtFullName->setText( ent.lastName() + ", " + ent.firstName() + " " + ent.middleName() ); + else + txtFullName->setText( ent.firstName() + " " + ent.middleName() + " " + ent.lastName() ); cmbFileAs->setEditText( ent.fileAs() ); // if (hasTitle) txtJobTitle->setText( ent.jobTitle() ); // if (hasCompany) txtOrganization->setText( ent.company() ); @@ -1546,17 +1463,17 @@ void ContactEditor::saveEntry() { // Store current combo into contact contactfields.saveToRecord( ent ); if ( useFullName ) { txtFirstName->setText( parseName( txtFullName->text(), NAME_F ) ); txtMiddleName->setText( parseName( txtFullName->text(), NAME_M ) ); txtLastName->setText( parseName( txtFullName->text(), NAME_L ) ); - txtSuffix->setText( parseName( txtFullName->text(), NAME_S ) ); + // txtSuffix->setText( parseName( txtFullName->text(), NAME_S ) ); useFullName = false; } ent.setFirstName( txtFirstName->text() ); ent.setLastName( txtLastName->text() ); ent.setMiddleName( txtMiddleName->text() ); ent.setSuffix( txtSuffix->text() ); diff --git a/core/pim/addressbook/version.h b/core/pim/addressbook/version.h index 3becfdc..c2ead05 100644 --- a/core/pim/addressbook/version.h +++ b/core/pim/addressbook/version.h @@ -1,10 +1,10 @@ #ifndef _VERSION_H_ #define _VERSION_H_ #define MAINVERSION "0" -#define SUBVERSION "2" -#define PATCHVERSION "2" +#define SUBVERSION "3" +#define PATCHVERSION "0" #define APPNAME "OPIE_ADDRESSBOOK" #endif |