summaryrefslogtreecommitdiff
authoreilers <eilers>2003-03-04 16:55:58 (UTC)
committer eilers <eilers>2003-03-04 16:55:58 (UTC)
commitca913d1f2035b6ddb77be497516e4dfc2371e5b3 (patch) (unidiff)
tree8783f481948e488d6103382b201a36fcd8ca2662
parentbb765b9cd286d85eb8fa1d18199dfb7a29d57fc5 (diff)
downloadopie-ca913d1f2035b6ddb77be497516e4dfc2371e5b3.zip
opie-ca913d1f2035b6ddb77be497516e4dfc2371e5b3.tar.gz
opie-ca913d1f2035b6ddb77be497516e4dfc2371e5b3.tar.bz2
Some finetuning to behave like the previous release if just one first and
lastname is used..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/contacteditor.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp
index 7bc5bde..c4a7b10 100644
--- a/core/pim/addressbook/contacteditor.cpp
+++ b/core/pim/addressbook/contacteditor.cpp
@@ -965,257 +965,260 @@ void ContactEditor::slotCmbChooser2Change( int index ) {
965 965
966void ContactEditor::slotCmbChooser3Change( int index ) { 966void ContactEditor::slotCmbChooser3Change( int index ) {
967 qWarning("ContactEditor::slotCmbChooser3Change( %d )", index); 967 qWarning("ContactEditor::slotCmbChooser3Change( %d )", index);
968 968
969 if ( !cmbChooserChange( cmbChooserField3->currentItem(), m_widgetStack3, 3) ){ 969 if ( !cmbChooserChange( cmbChooserField3->currentItem(), m_widgetStack3, 3) ){
970 970
971 txtChooserField3->setText( slChooserValues[index] ); 971 txtChooserField3->setText( slChooserValues[index] );
972 txtChooserField3->setFocus(); 972 txtChooserField3->setFocus();
973 973
974 } 974 }
975} 975}
976 976
977void ContactEditor::slotCmbChooser4Change( int index ) { 977void ContactEditor::slotCmbChooser4Change( int index ) {
978 qWarning("ContactEditor::slotCmbChooser4Change( %d )", index); 978 qWarning("ContactEditor::slotCmbChooser4Change( %d )", index);
979 979
980 if ( !cmbChooserChange( cmbChooserField4->currentItem(), m_widgetStack4, 4) ){ 980 if ( !cmbChooserChange( cmbChooserField4->currentItem(), m_widgetStack4, 4) ){
981 981
982 txtChooserField4->setText( slChooserValues[index] ); 982 txtChooserField4->setText( slChooserValues[index] );
983 txtChooserField4->setFocus(); 983 txtChooserField4->setFocus();
984 984
985 } 985 }
986} 986}
987 987
988void ContactEditor::slotAddressTypeChange( int index ) { 988void ContactEditor::slotAddressTypeChange( int index ) {
989 989
990 990
991 if ( !initializing ) 991 if ( !initializing )
992 contactfields.setFieldOrder( 4, index ); 992 contactfields.setFieldOrder( 4, index );
993 993
994 994
995 if ( index == 0 ) { 995 if ( index == 0 ) {
996 996
997 txtAddress->setText( slBusinessAddress[0] ); 997 txtAddress->setText( slBusinessAddress[0] );
998 //txtAddress2->setText( (*slBusinessAddress)[1] ); 998 //txtAddress2->setText( (*slBusinessAddress)[1] );
999 //txtPOBox->setText( (*slBusinessAddress)[2] ); 999 //txtPOBox->setText( (*slBusinessAddress)[2] );
1000 txtCity->setText( slBusinessAddress[3] ); 1000 txtCity->setText( slBusinessAddress[3] );
1001 txtState->setText( slBusinessAddress[4] ); 1001 txtState->setText( slBusinessAddress[4] );
1002 txtZip->setText( slBusinessAddress[5] ); 1002 txtZip->setText( slBusinessAddress[5] );
1003 QLineEdit *txtTmp = cmbCountry->lineEdit(); 1003 QLineEdit *txtTmp = cmbCountry->lineEdit();
1004 txtTmp->setText( slBusinessAddress[6] ); 1004 txtTmp->setText( slBusinessAddress[6] );
1005 1005
1006 } else { 1006 } else {
1007 1007
1008 txtAddress->setText( slHomeAddress[0] ); 1008 txtAddress->setText( slHomeAddress[0] );
1009 //txtAddress2->setText( (*slHomeAddress)[1] ); 1009 //txtAddress2->setText( (*slHomeAddress)[1] );
1010 //txtPOBox->setText( (*slHomeAddress)[2] ); 1010 //txtPOBox->setText( (*slHomeAddress)[2] );
1011 txtCity->setText( slHomeAddress[3] ); 1011 txtCity->setText( slHomeAddress[3] );
1012 txtState->setText( slHomeAddress[4] ); 1012 txtState->setText( slHomeAddress[4] );
1013 txtZip->setText( slHomeAddress[5] ); 1013 txtZip->setText( slHomeAddress[5] );
1014 QLineEdit *txtTmp = cmbCountry->lineEdit(); 1014 QLineEdit *txtTmp = cmbCountry->lineEdit();
1015 txtTmp->setText( slHomeAddress[6] ); 1015 txtTmp->setText( slHomeAddress[6] );
1016 1016
1017 } 1017 }
1018 1018
1019} 1019}
1020 1020
1021void ContactEditor::slotFullNameChange( const QString &textChanged ) { 1021void ContactEditor::slotFullNameChange( const QString &textChanged ) {
1022 1022
1023 qWarning( "ContactEditor::slotFullNameChange( %s )", textChanged.latin1() ); 1023 qWarning( "ContactEditor::slotFullNameChange( %s )", textChanged.latin1() );
1024 1024
1025 int index = cmbFileAs->currentItem(); 1025 int index = cmbFileAs->currentItem();
1026 1026
1027 cmbFileAs->clear(); 1027 cmbFileAs->clear();
1028 1028
1029 cmbFileAs->insertItem( parseName( textChanged, NAME_FL ) );
1030 cmbFileAs->insertItem( parseName( textChanged, NAME_FMLS ) );
1031 cmbFileAs->insertItem( parseName( textChanged, NAME_LF ) ); 1029 cmbFileAs->insertItem( parseName( textChanged, NAME_LF ) );
1032 cmbFileAs->insertItem( parseName( textChanged, NAME_LFM ) ); 1030 cmbFileAs->insertItem( parseName( textChanged, NAME_LFM ) );
1031 cmbFileAs->insertItem( parseName( textChanged, NAME_FL ) );
1032 cmbFileAs->insertItem( parseName( textChanged, NAME_FMLS ) );
1033 1033
1034 cmbFileAs->setCurrentItem( index ); 1034 cmbFileAs->setCurrentItem( index );
1035 1035
1036 useFullName = true; 1036 useFullName = true;
1037 1037
1038} 1038}
1039 1039
1040void ContactEditor::accept() { 1040void ContactEditor::accept() {
1041 1041
1042 if ( isEmpty() ) { 1042 if ( isEmpty() ) {
1043 cleanupFields(); 1043 cleanupFields();
1044 reject(); 1044 reject();
1045 } else { 1045 } else {
1046 saveEntry(); 1046 saveEntry();
1047 cleanupFields(); 1047 cleanupFields();
1048 QDialog::accept(); 1048 QDialog::accept();
1049 } 1049 }
1050 1050
1051} 1051}
1052 1052
1053void ContactEditor::slotNote() { 1053void ContactEditor::slotNote() {
1054 1054
1055 dlgNote->showMaximized(); 1055 dlgNote->showMaximized();
1056 if ( !dlgNote->exec() ) { 1056 if ( !dlgNote->exec() ) {
1057 txtNote->setText( ent.notes() ); 1057 txtNote->setText( ent.notes() );
1058 } 1058 }
1059} 1059}
1060 1060
1061void ContactEditor::slotName() { 1061void ContactEditor::slotName() {
1062 1062
1063 QString tmpName; 1063 QString tmpName;
1064 if (useFullName) { 1064 if (useFullName) {
1065 txtFirstName->setText( parseName(txtFullName->text(), NAME_F) ); 1065 txtFirstName->setText( parseName(txtFullName->text(), NAME_F) );
1066 txtMiddleName->setText( parseName(txtFullName->text(), NAME_M) ); 1066 txtMiddleName->setText( parseName(txtFullName->text(), NAME_M) );
1067 txtLastName->setText( parseName(txtFullName->text(), NAME_L) ); 1067 txtLastName->setText( parseName(txtFullName->text(), NAME_L) );
1068 // txtSuffix->setText( parseName(txtFullName->text(), NAME_S) ); 1068 // txtSuffix->setText( parseName(txtFullName->text(), NAME_S) );
1069 } 1069 }
1070 dlgName->showMaximized(); 1070 dlgName->showMaximized();
1071 if ( dlgName->exec() ) { 1071 if ( dlgName->exec() ) {
1072 1072
1073 tmpName = txtFirstName->text() + " " + txtMiddleName->text() + " " + txtLastName->text() + " " + txtSuffix->text(); 1073 tmpName = txtFirstName->text() + " " + txtMiddleName->text() + " " + txtLastName->text() + " " + txtSuffix->text();
1074 txtFullName->setText( tmpName.simplifyWhiteSpace() ); 1074 txtFullName->setText( tmpName.simplifyWhiteSpace() );
1075 slotFullNameChange( txtFullName->text() ); 1075 slotFullNameChange( txtFullName->text() );
1076 useFullName = false; 1076 useFullName = false;
1077 } 1077 }
1078 1078
1079} 1079}
1080 1080
1081void ContactEditor::setNameFocus() { 1081void ContactEditor::setNameFocus() {
1082 1082
1083 txtFullName->setFocus(); 1083 txtFullName->setFocus();
1084 1084
1085} 1085}
1086 1086
1087bool ContactEditor::isEmpty() { 1087bool ContactEditor::isEmpty() {
1088 // Test and see if the record should be saved. 1088 // Test and see if the record should be saved.
1089 // More strict than the original qtopia, needs name or fileas to save 1089 // More strict than the original qtopia, needs name or fileas to save
1090 1090
1091 QString t = txtFullName->text(); 1091 QString t = txtFullName->text();
1092 if ( !t.isEmpty() && containsAlphaNum( t ) ) 1092 if ( !t.isEmpty() && containsAlphaNum( t ) )
1093 return false; 1093 return false;
1094 1094
1095 t = cmbFileAs->currentText(); 1095 t = cmbFileAs->currentText();
1096 if ( !t.isEmpty() && containsAlphaNum( t ) ) 1096 if ( !t.isEmpty() && containsAlphaNum( t ) )
1097 return false; 1097 return false;
1098 1098
1099 return true; 1099 return true;
1100 1100
1101} 1101}
1102 1102
1103QString ContactEditor::parseName( const QString fullName, int type ) { 1103QString ContactEditor::parseName( const QString fullName, int type ) {
1104 1104
1105 QString simplifiedName( fullName.simplifyWhiteSpace() ); 1105 QString simplifiedName( fullName.simplifyWhiteSpace() );
1106 QString strFirstName; 1106 QString strFirstName;
1107 QString strMiddleName; 1107 QString strMiddleName;
1108 QString strLastName; 1108 QString strLastName;
1109 QString strSuffix; 1109 QString strSuffix;
1110 QString strTitle; 1110 QString strTitle;
1111 int commapos; 1111 int commapos;
1112 bool haveLastName = false; 1112 bool haveLastName = false;
1113 1113
1114 qWarning("Fullname: %s", simplifiedName.latin1()); 1114 qWarning("Fullname: %s", simplifiedName.latin1());
1115 1115
1116 commapos = simplifiedName.find( ',', 0, TRUE); 1116 commapos = simplifiedName.find( ',', 0, TRUE);
1117 if ( commapos >= 0 ) { 1117 if ( commapos >= 0 ) {
1118 qWarning(" Commapos: %d", commapos ); 1118 qWarning(" Commapos: %d", commapos );
1119 1119
1120 // A comma (",") separates the lastname from one or 1120 // A comma (",") separates the lastname from one or
1121 // many first names. Thus, remove the lastname from the 1121 // many first names. Thus, remove the lastname from the
1122 // String and parse the firstnames. 1122 // String and parse the firstnames.
1123 1123
1124 strLastName = simplifiedName.left( commapos ); 1124 strLastName = simplifiedName.left( commapos );
1125 simplifiedName= simplifiedName.mid( commapos + 1 ); 1125 simplifiedName= simplifiedName.mid( commapos + 1 );
1126 haveLastName = true; 1126 haveLastName = true;
1127 qWarning("Fullname without ',': %s", simplifiedName.latin1()); 1127 qWarning("Fullname without ',': %s", simplifiedName.latin1());
1128 1128
1129 // If we have any lastname, we should now split all first names. 1129 // If we have any lastname, we should now split all first names.
1130 // The first one will be the used as first, the rest as "middle names" 1130 // The first one will be the used as first, the rest as "middle names"
1131 1131
1132 QStringList allFirstNames = QStringList::split(" ", simplifiedName); 1132 QStringList allFirstNames = QStringList::split(" ", simplifiedName);
1133 QStringList::Iterator it = allFirstNames.begin(); 1133 QStringList::Iterator it = allFirstNames.begin();
1134 strFirstName = *it++; 1134 strFirstName = *it++;
1135 QStringList allSecondNames; 1135 QStringList allSecondNames;
1136 for ( ; it != allFirstNames.end(); ++it ) 1136 for ( ; it != allFirstNames.end(); ++it )
1137 allSecondNames.append( *it ); 1137 allSecondNames.append( *it );
1138 1138
1139 strMiddleName = allSecondNames.join(" "); 1139 strMiddleName = allSecondNames.join(" ");
1140 1140
1141 } else { 1141 } else {
1142 1142
1143 // No comma separator used: We use the first word as firstname, the 1143 // No comma separator used: We use the first word as firstname, the
1144 // last as second/lastname and everything in the middle as middlename 1144 // last as second/lastname and everything in the middle as middlename
1145 1145
1146 QStringList allNames = QStringList::split(" ", simplifiedName); 1146 QStringList allNames = QStringList::split(" ", simplifiedName);
1147 QStringList::Iterator it = allNames.begin(); 1147 QStringList::Iterator it = allNames.begin();
1148 strFirstName = *it++; 1148 strFirstName = *it++;
1149 QStringList allSecondNames; 1149 QStringList allSecondNames;
1150 for ( ; it != --allNames.end(); ++it ) 1150 for ( ; it != --allNames.end(); ++it )
1151 allSecondNames.append( *it ); 1151 allSecondNames.append( *it );
1152 1152
1153 strMiddleName = allSecondNames.join(" "); 1153 strMiddleName = allSecondNames.join(" ");
1154 strLastName = *(--allNames.end()); 1154 strLastName = *(--allNames.end());
1155 1155
1156 } 1156 }
1157 1157
1158 if ( strFirstName == strLastName )
1159 strFirstName = "";
1160
1158 qWarning(" strFirstName: %s", strFirstName.latin1()); 1161 qWarning(" strFirstName: %s", strFirstName.latin1());
1159 qWarning(" strMiddleName: %s", strMiddleName.latin1()); 1162 qWarning(" strMiddleName: %s", strMiddleName.latin1());
1160 qWarning(" strLastName: %s", strLastName.latin1()); 1163 qWarning(" strLastName: %s", strLastName.latin1());
1161 qWarning(" strSuffix: %s", strSuffix.latin1()); 1164 qWarning(" strSuffix: %s", strSuffix.latin1());
1162 qWarning(" strTitle: %s", strTitle.latin1()); 1165 qWarning(" strTitle: %s", strTitle.latin1());
1163 1166
1164 switch (type) { 1167 switch (type) {
1165 case NAME_FL: 1168 case NAME_FL:
1166 return strFirstName + " " + strLastName; 1169 return strFirstName + " " + strLastName;
1167 1170
1168 case NAME_LF: 1171 case NAME_LF:
1169 return strLastName + ", " + strFirstName; 1172 return strLastName + ", " + strFirstName;
1170 1173
1171 case NAME_LFM: 1174 case NAME_LFM:
1172 return strLastName + ", " + strFirstName + " " + strMiddleName; 1175 return strLastName + ", " + strFirstName + " " + strMiddleName;
1173 1176
1174 case NAME_FMLS: 1177 case NAME_FMLS:
1175 return strFirstName + " " + strMiddleName + " " + strLastName + " " + strSuffix; 1178 return strFirstName + " " + strMiddleName + " " + strLastName + " " + strSuffix;
1176 1179
1177 case NAME_F: 1180 case NAME_F:
1178 return strFirstName; 1181 return strFirstName;
1179 1182
1180 case NAME_M: 1183 case NAME_M:
1181 return strMiddleName; 1184 return strMiddleName;
1182 1185
1183 case NAME_L: 1186 case NAME_L:
1184 return strLastName; 1187 return strLastName;
1185 1188
1186 case NAME_S: 1189 case NAME_S:
1187 return strSuffix; 1190 return strSuffix;
1188 1191
1189 } 1192 }
1190 return QString::null; 1193 return QString::null;
1191} 1194}
1192 1195
1193void ContactEditor::cleanupFields() { 1196void ContactEditor::cleanupFields() {
1194 QStringList::Iterator it = slChooserValues.begin(); 1197 QStringList::Iterator it = slChooserValues.begin();
1195 1198
1196 for ( int i = 0; it != slChooserValues.end(); i++, ++it ) { 1199 for ( int i = 0; it != slChooserValues.end(); i++, ++it ) {
1197 (*it) = ""; 1200 (*it) = "";
1198 } 1201 }
1199 1202
1200 for ( int i = 0; i < 7; i++ ) { 1203 for ( int i = 0; i < 7; i++ ) {
1201 slHomeAddress[i] = ""; 1204 slHomeAddress[i] = "";
1202 slBusinessAddress[i] = ""; 1205 slBusinessAddress[i] = "";
1203 } 1206 }
1204 1207
1205 QListIterator<QLineEdit> itLV( listValue ); 1208 QListIterator<QLineEdit> itLV( listValue );
1206 for ( ; itLV.current(); ++itLV ) { 1209 for ( ; itLV.current(); ++itLV ) {
1207 (*itLV)->setText( "" ); 1210 (*itLV)->setText( "" );
1208 } 1211 }
1209 1212
1210 txtFirstName->setText(""); 1213 txtFirstName->setText("");
1211 txtMiddleName->setText(""); 1214 txtMiddleName->setText("");
1212 txtLastName->setText(""); 1215 txtLastName->setText("");
1213 txtSuffix->setText(""); 1216 txtSuffix->setText("");
1214 txtNote->setText(""); 1217 txtNote->setText("");
1215 txtFullName->setText(""); 1218 txtFullName->setText("");
1216 txtJobTitle->setText(""); 1219 txtJobTitle->setText("");
1217 txtOrganization->setText(""); 1220 txtOrganization->setText("");
1218 txtChooserField1->setText(""); 1221 txtChooserField1->setText("");
1219 txtChooserField2->setText(""); 1222 txtChooserField2->setText("");
1220 txtChooserField3->setText(""); 1223 txtChooserField3->setText("");
1221 txtAddress->setText(""); 1224 txtAddress->setText("");