summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontact.cpp5
-rw-r--r--libopie2/opiepim/ocontact.cpp5
2 files changed, 6 insertions, 4 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp
index 8a0930b..b0f0d7f 100644
--- a/libopie/pim/ocontact.cpp
+++ b/libopie/pim/ocontact.cpp
@@ -1027,485 +1027,486 @@ void OContact::setChildren( const QString &str )
1027*/ 1027*/
1028static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 1028static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
1029{ 1029{
1030 VObject *ret = 0; 1030 VObject *ret = 0;
1031 if ( o && !value.isEmpty() ) 1031 if ( o && !value.isEmpty() )
1032 ret = addPropValue( o, prop, value.latin1() ); 1032 ret = addPropValue( o, prop, value.latin1() );
1033 return ret; 1033 return ret;
1034} 1034}
1035 1035
1036/*! 1036/*!
1037 \internal 1037 \internal
1038*/ 1038*/
1039static inline VObject *safeAddProp( VObject *o, const char *prop) 1039static inline VObject *safeAddProp( VObject *o, const char *prop)
1040{ 1040{
1041 VObject *ret = 0; 1041 VObject *ret = 0;
1042 if ( o ) 1042 if ( o )
1043 ret = addProp( o, prop ); 1043 ret = addProp( o, prop );
1044 return ret; 1044 return ret;
1045} 1045}
1046 1046
1047/*! 1047/*!
1048 \internal 1048 \internal
1049*/ 1049*/
1050static VObject *createVObject( const OContact &c ) 1050static VObject *createVObject( const OContact &c )
1051{ 1051{
1052 VObject *vcard = newVObject( VCCardProp ); 1052 VObject *vcard = newVObject( VCCardProp );
1053 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 1053 safeAddPropValue( vcard, VCVersionProp, "2.1" );
1054 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 1054 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
1055 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 1055 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
1056 1056
1057 // full name 1057 // full name
1058 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 1058 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
1059 1059
1060 // name properties 1060 // name properties
1061 VObject *name = safeAddProp( vcard, VCNameProp ); 1061 VObject *name = safeAddProp( vcard, VCNameProp );
1062 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 1062 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
1063 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 1063 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
1064 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 1064 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
1065 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 1065 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
1066 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 1066 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
1067 1067
1068 // home properties 1068 // home properties
1069 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 1069 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
1070 safeAddProp( home_adr, VCHomeProp ); 1070 safeAddProp( home_adr, VCHomeProp );
1071 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 1071 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
1072 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 1072 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
1073 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 1073 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
1074 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 1074 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
1075 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 1075 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
1076 1076
1077 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 1077 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
1078 safeAddProp( home_phone, VCHomeProp ); 1078 safeAddProp( home_phone, VCHomeProp );
1079 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 1079 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
1080 safeAddProp( home_phone, VCHomeProp ); 1080 safeAddProp( home_phone, VCHomeProp );
1081 safeAddProp( home_phone, VCCellularProp ); 1081 safeAddProp( home_phone, VCCellularProp );
1082 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 1082 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
1083 safeAddProp( home_phone, VCHomeProp ); 1083 safeAddProp( home_phone, VCHomeProp );
1084 safeAddProp( home_phone, VCFaxProp ); 1084 safeAddProp( home_phone, VCFaxProp );
1085 1085
1086 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 1086 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
1087 safeAddProp( url, VCHomeProp ); 1087 safeAddProp( url, VCHomeProp );
1088 1088
1089 // work properties 1089 // work properties
1090 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 1090 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
1091 safeAddProp( work_adr, VCWorkProp ); 1091 safeAddProp( work_adr, VCWorkProp );
1092 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 1092 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
1093 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 1093 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
1094 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 1094 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
1095 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 1095 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
1096 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 1096 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
1097 1097
1098 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 1098 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
1099 safeAddProp( work_phone, VCWorkProp ); 1099 safeAddProp( work_phone, VCWorkProp );
1100 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 1100 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
1101 safeAddProp( work_phone, VCWorkProp ); 1101 safeAddProp( work_phone, VCWorkProp );
1102 safeAddProp( work_phone, VCCellularProp ); 1102 safeAddProp( work_phone, VCCellularProp );
1103 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 1103 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
1104 safeAddProp( work_phone, VCWorkProp ); 1104 safeAddProp( work_phone, VCWorkProp );
1105 safeAddProp( work_phone, VCFaxProp ); 1105 safeAddProp( work_phone, VCFaxProp );
1106 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 1106 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
1107 safeAddProp( work_phone, VCWorkProp ); 1107 safeAddProp( work_phone, VCWorkProp );
1108 safeAddProp( work_phone, VCPagerProp ); 1108 safeAddProp( work_phone, VCPagerProp );
1109 1109
1110 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 1110 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
1111 safeAddProp( url, VCWorkProp ); 1111 safeAddProp( url, VCWorkProp );
1112 1112
1113 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 1113 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
1114 safeAddProp( title, VCWorkProp ); 1114 safeAddProp( title, VCWorkProp );
1115 1115
1116 1116
1117 QStringList emails = c.emailList(); 1117 QStringList emails = c.emailList();
1118 emails.prepend( c.defaultEmail() ); 1118 emails.prepend( c.defaultEmail() );
1119 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 1119 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
1120 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 1120 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
1121 safeAddProp( email, VCInternetProp ); 1121 safeAddProp( email, VCInternetProp );
1122 } 1122 }
1123 1123
1124 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 1124 safeAddPropValue( vcard, VCNoteProp, c.notes() );
1125 1125
1126 // Exporting Birthday regarding RFC 2425 (5.8.4) 1126 // Exporting Birthday regarding RFC 2425 (5.8.4)
1127 if ( c.birthday().isValid() ){ 1127 if ( c.birthday().isValid() ){
1128 QString birthd_rfc2425 = QString("%1-%2-%3") 1128 QString birthd_rfc2425 = QString("%1-%2-%3")
1129 .arg( c.birthday().year() ) 1129 .arg( c.birthday().year() )
1130 .arg( c.birthday().month(), 2 ) 1130 .arg( c.birthday().month(), 2 )
1131 .arg( c.birthday().day(), 2 ); 1131 .arg( c.birthday().day(), 2 );
1132 // Now replace spaces with "0"... 1132 // Now replace spaces with "0"...
1133 int pos = 0; 1133 int pos = 0;
1134 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) 1134 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 )
1135 birthd_rfc2425.replace( pos, 1, "0" ); 1135 birthd_rfc2425.replace( pos, 1, "0" );
1136 1136
1137 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); 1137 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1());
1138 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); 1138 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() );
1139 } 1139 }
1140 1140
1141 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 1141 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
1142 VObject *org = safeAddProp( vcard, VCOrgProp ); 1142 VObject *org = safeAddProp( vcard, VCOrgProp );
1143 safeAddPropValue( org, VCOrgNameProp, c.company() ); 1143 safeAddPropValue( org, VCOrgNameProp, c.company() );
1144 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 1144 safeAddPropValue( org, VCOrgUnitProp, c.department() );
1145 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 1145 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
1146 } 1146 }
1147 1147
1148 // some values we have to export as custom fields 1148 // some values we have to export as custom fields
1149 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 1149 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
1150 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 1150 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
1151 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 1151 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
1152 1152
1153 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 1153 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
1154 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 1154 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
1155 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); 1155 // safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); :SX
1156 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 1156 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
1157 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 1157 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
1158 1158
1159 return vcard; 1159 return vcard;
1160} 1160}
1161 1161
1162 1162
1163/*! 1163/*!
1164 \internal 1164 \internal
1165*/ 1165*/
1166static QDate convVCardDateToDate( const QString& datestr ) 1166static QDate convVCardDateToDate( const QString& datestr )
1167{ 1167{
1168 int monthPos = datestr.find('-'); 1168 int monthPos = datestr.find('-');
1169 int dayPos = datestr.find('-', monthPos+1 ); 1169 int dayPos = datestr.find('-', monthPos+1 );
1170 int sep_ignore = 1; 1170 int sep_ignore = 1;
1171 if ( monthPos == -1 || dayPos == -1 ) { 1171 if ( monthPos == -1 || dayPos == -1 ) {
1172 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1172 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1173 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 1173 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
1174 if ( datestr.length() == 8 ){ 1174 if ( datestr.length() == 8 ){
1175 monthPos = 4; 1175 monthPos = 4;
1176 dayPos = 6; 1176 dayPos = 6;
1177 sep_ignore = 0; 1177 sep_ignore = 0;
1178 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1178 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1179 } else { 1179 } else {
1180 return QDate(); 1180 return QDate();
1181 } 1181 }
1182 } 1182 }
1183 int y = datestr.left( monthPos ).toInt(); 1183 int y = datestr.left( monthPos ).toInt();
1184 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 1184 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
1185 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 1185 int d = datestr.mid( dayPos + sep_ignore ).toInt();
1186 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 1186 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos);
1187 QDate date ( y,m,d ); 1187 QDate date ( y,m,d );
1188 return date; 1188 return date;
1189} 1189}
1190 1190
1191static OContact parseVObject( VObject *obj ) 1191static OContact parseVObject( VObject *obj )
1192{ 1192{
1193 OContact c; 1193 OContact c;
1194 1194
1195 VObjectIterator it; 1195 VObjectIterator it;
1196 initPropIterator( &it, obj ); 1196 initPropIterator( &it, obj );
1197 while( moreIteration( &it ) ) { 1197 while( moreIteration( &it ) ) {
1198 VObject *o = nextVObject( &it ); 1198 VObject *o = nextVObject( &it );
1199 QCString name = vObjectName( o ); 1199 QCString name = vObjectName( o );
1200 QCString value = vObjectStringZValue( o ); 1200 QCString value = vObjectStringZValue( o );
1201 if ( name == VCNameProp ) { 1201 if ( name == VCNameProp ) {
1202 VObjectIterator nit; 1202 VObjectIterator nit;
1203 initPropIterator( &nit, o ); 1203 initPropIterator( &nit, o );
1204 while( moreIteration( &nit ) ) { 1204 while( moreIteration( &nit ) ) {
1205 VObject *o = nextVObject( &nit ); 1205 VObject *o = nextVObject( &nit );
1206 QCString name = vObjectTypeInfo( o ); 1206 QCString name = vObjectTypeInfo( o );
1207 QString value = vObjectStringZValue( o ); 1207 QString value = vObjectStringZValue( o );
1208 if ( name == VCNamePrefixesProp ) 1208 if ( name == VCNamePrefixesProp )
1209 c.setTitle( value ); 1209 c.setTitle( value );
1210 else if ( name == VCNameSuffixesProp ) 1210 else if ( name == VCNameSuffixesProp )
1211 c.setSuffix( value ); 1211 c.setSuffix( value );
1212 else if ( name == VCFamilyNameProp ) 1212 else if ( name == VCFamilyNameProp )
1213 c.setLastName( value ); 1213 c.setLastName( value );
1214 else if ( name == VCGivenNameProp ) 1214 else if ( name == VCGivenNameProp )
1215 c.setFirstName( value ); 1215 c.setFirstName( value );
1216 else if ( name == VCAdditionalNamesProp ) 1216 else if ( name == VCAdditionalNamesProp )
1217 c.setMiddleName( value ); 1217 c.setMiddleName( value );
1218 } 1218 }
1219 } 1219 }
1220 else if ( name == VCAdrProp ) { 1220 else if ( name == VCAdrProp ) {
1221 bool work = TRUE; // default address is work address 1221 bool work = TRUE; // default address is work address
1222 QString street; 1222 QString street;
1223 QString city; 1223 QString city;
1224 QString region; 1224 QString region;
1225 QString postal; 1225 QString postal;
1226 QString country; 1226 QString country;
1227 1227
1228 VObjectIterator nit; 1228 VObjectIterator nit;
1229 initPropIterator( &nit, o ); 1229 initPropIterator( &nit, o );
1230 while( moreIteration( &nit ) ) { 1230 while( moreIteration( &nit ) ) {
1231 VObject *o = nextVObject( &nit ); 1231 VObject *o = nextVObject( &nit );
1232 QCString name = vObjectName( o ); 1232 QCString name = vObjectName( o );
1233 QString value = vObjectStringZValue( o ); 1233 QString value = vObjectStringZValue( o );
1234
1234 if ( name == VCHomeProp ) 1235 if ( name == VCHomeProp )
1235 work = FALSE; 1236 work = FALSE;
1236 else if ( name == VCWorkProp ) 1237 else if ( name == VCWorkProp )
1237 work = TRUE; 1238 work = TRUE;
1238 else if ( name == VCStreetAddressProp ) 1239 else if ( name == VCStreetAddressProp )
1239 street = value; 1240 street = value;
1240 else if ( name == VCCityProp ) 1241 else if ( name == VCCityProp )
1241 city = value; 1242 city = value;
1242 else if ( name == VCRegionProp ) 1243 else if ( name == VCRegionProp )
1243 region = value; 1244 region = value;
1244 else if ( name == VCPostalCodeProp ) 1245 else if ( name == VCPostalCodeProp )
1245 postal = value; 1246 postal = value;
1246 else if ( name == VCCountryNameProp ) 1247 else if ( name == VCCountryNameProp )
1247 country = value; 1248 country = value;
1248 } 1249 }
1249 if ( work ) { 1250 if ( work ) {
1250 c.setBusinessStreet( street ); 1251 c.setBusinessStreet( street );
1251 c.setBusinessCity( city ); 1252 c.setBusinessCity( city );
1252 c.setBusinessCountry( country ); 1253 c.setBusinessCountry( country );
1253 c.setBusinessZip( postal ); 1254 c.setBusinessZip( postal );
1254 c.setBusinessState( region ); 1255 c.setBusinessState( region );
1255 } else { 1256 } else {
1256 c.setHomeStreet( street ); 1257 c.setHomeStreet( street );
1257 c.setHomeCity( city ); 1258 c.setHomeCity( city );
1258 c.setHomeCountry( country ); 1259 c.setHomeCountry( country );
1259 c.setHomeZip( postal ); 1260 c.setHomeZip( postal );
1260 c.setHomeState( region ); 1261 c.setHomeState( region );
1261 } 1262 }
1262 } 1263 }
1263 else if ( name == VCTelephoneProp ) { 1264 else if ( name == VCTelephoneProp ) {
1264 enum { 1265 enum {
1265 HOME = 0x01, 1266 HOME = 0x01,
1266 WORK = 0x02, 1267 WORK = 0x02,
1267 VOICE = 0x04, 1268 VOICE = 0x04,
1268 CELL = 0x08, 1269 CELL = 0x08,
1269 FAX = 0x10, 1270 FAX = 0x10,
1270 PAGER = 0x20, 1271 PAGER = 0x20,
1271 UNKNOWN = 0x80 1272 UNKNOWN = 0x80
1272 }; 1273 };
1273 int type = 0; 1274 int type = 0;
1274 1275
1275 VObjectIterator nit; 1276 VObjectIterator nit;
1276 initPropIterator( &nit, o ); 1277 initPropIterator( &nit, o );
1277 while( moreIteration( &nit ) ) { 1278 while( moreIteration( &nit ) ) {
1278 VObject *o = nextVObject( &nit ); 1279 VObject *o = nextVObject( &nit );
1279 QCString name = vObjectTypeInfo( o ); 1280 QCString name = vObjectTypeInfo( o );
1280 if ( name == VCHomeProp ) 1281 if ( name == VCHomeProp )
1281 type |= HOME; 1282 type |= HOME;
1282 else if ( name == VCWorkProp ) 1283 else if ( name == VCWorkProp )
1283 type |= WORK; 1284 type |= WORK;
1284 else if ( name == VCVoiceProp ) 1285 else if ( name == VCVoiceProp )
1285 type |= VOICE; 1286 type |= VOICE;
1286 else if ( name == VCCellularProp ) 1287 else if ( name == VCCellularProp )
1287 type |= CELL; 1288 type |= CELL;
1288 else if ( name == VCFaxProp ) 1289 else if ( name == VCFaxProp )
1289 type |= FAX; 1290 type |= FAX;
1290 else if ( name == VCPagerProp ) 1291 else if ( name == VCPagerProp )
1291 type |= PAGER; 1292 type |= PAGER;
1292 else if ( name == VCPreferredProp ) 1293 else if ( name == VCPreferredProp )
1293 ; 1294 ;
1294 else 1295 else
1295 type |= UNKNOWN; 1296 type |= UNKNOWN;
1296 } 1297 }
1297 if ( (type & UNKNOWN) != UNKNOWN ) { 1298 if ( (type & UNKNOWN) != UNKNOWN ) {
1298 if ( ( type & (HOME|WORK) ) == 0 ) // default 1299 if ( ( type & (HOME|WORK) ) == 0 ) // default
1299 type |= HOME; 1300 type |= HOME;
1300 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 1301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
1301 type |= VOICE; 1302 type |= VOICE;
1302 1303
1303 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 1304 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
1304 c.setHomePhone( value ); 1305 c.setHomePhone( value );
1305 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 1306 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
1306 c.setHomeFax( value ); 1307 c.setHomeFax( value );
1307 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 1308 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
1308 c.setHomeMobile( value ); 1309 c.setHomeMobile( value );
1309 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 1310 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
1310 c.setBusinessPhone( value ); 1311 c.setBusinessPhone( value );
1311 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 1312 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
1312 c.setBusinessFax( value ); 1313 c.setBusinessFax( value );
1313 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 1314 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
1314 c.setBusinessMobile( value ); 1315 c.setBusinessMobile( value );
1315 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 1316 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
1316 c.setBusinessPager( value ); 1317 c.setBusinessPager( value );
1317 } 1318 }
1318 } 1319 }
1319 else if ( name == VCEmailAddressProp ) { 1320 else if ( name == VCEmailAddressProp ) {
1320 QString email = vObjectStringZValue( o ); 1321 QString email = vObjectStringZValue( o );
1321 bool valid = TRUE; 1322 bool valid = TRUE;
1322 VObjectIterator nit; 1323 VObjectIterator nit;
1323 initPropIterator( &nit, o ); 1324 initPropIterator( &nit, o );
1324 while( moreIteration( &nit ) ) { 1325 while( moreIteration( &nit ) ) {
1325 VObject *o = nextVObject( &nit ); 1326 VObject *o = nextVObject( &nit );
1326 QCString name = vObjectTypeInfo( o ); 1327 QCString name = vObjectTypeInfo( o );
1327 if ( name != VCInternetProp && name != VCHomeProp && 1328 if ( name != VCInternetProp && name != VCHomeProp &&
1328 name != VCWorkProp && 1329 name != VCWorkProp &&
1329 name != VCPreferredProp ) 1330 name != VCPreferredProp )
1330 // ### preffered should map to default email 1331 // ### preffered should map to default email
1331 valid = FALSE; 1332 valid = FALSE;
1332 } 1333 }
1333 if ( valid ) { 1334 if ( valid ) {
1334 c.insertEmail( email ); 1335 c.insertEmail( email );
1335 } 1336 }
1336 } 1337 }
1337 else if ( name == VCURLProp ) { 1338 else if ( name == VCURLProp ) {
1338 VObjectIterator nit; 1339 VObjectIterator nit;
1339 initPropIterator( &nit, o ); 1340 initPropIterator( &nit, o );
1340 while( moreIteration( &nit ) ) { 1341 while( moreIteration( &nit ) ) {
1341 VObject *o = nextVObject( &nit ); 1342 VObject *o = nextVObject( &nit );
1342 QCString name = vObjectTypeInfo( o ); 1343 QCString name = vObjectTypeInfo( o );
1343 if ( name == VCHomeProp ) 1344 if ( name == VCHomeProp )
1344 c.setHomeWebpage( value ); 1345 c.setHomeWebpage( value );
1345 else if ( name == VCWorkProp ) 1346 else if ( name == VCWorkProp )
1346 c.setBusinessWebpage( value ); 1347 c.setBusinessWebpage( value );
1347 } 1348 }
1348 } 1349 }
1349 else if ( name == VCOrgProp ) { 1350 else if ( name == VCOrgProp ) {
1350 VObjectIterator nit; 1351 VObjectIterator nit;
1351 initPropIterator( &nit, o ); 1352 initPropIterator( &nit, o );
1352 while( moreIteration( &nit ) ) { 1353 while( moreIteration( &nit ) ) {
1353 VObject *o = nextVObject( &nit ); 1354 VObject *o = nextVObject( &nit );
1354 QCString name = vObjectName( o ); 1355 QCString name = vObjectName( o );
1355 QString value = vObjectStringZValue( o ); 1356 QString value = vObjectStringZValue( o );
1356 if ( name == VCOrgNameProp ) 1357 if ( name == VCOrgNameProp )
1357 c.setCompany( value ); 1358 c.setCompany( value );
1358 else if ( name == VCOrgUnitProp ) 1359 else if ( name == VCOrgUnitProp )
1359 c.setDepartment( value ); 1360 c.setDepartment( value );
1360 else if ( name == VCOrgUnit2Prop ) 1361 else if ( name == VCOrgUnit2Prop )
1361 c.setOffice( value ); 1362 c.setOffice( value );
1362 } 1363 }
1363 } 1364 }
1364 else if ( name == VCTitleProp ) { 1365 else if ( name == VCTitleProp ) {
1365 c.setJobTitle( value ); 1366 c.setJobTitle( value );
1366 } 1367 }
1367 else if ( name == "X-Qtopia-Profession" ) { 1368 else if ( name == "X-Qtopia-Profession" ) {
1368 c.setProfession( value ); 1369 c.setProfession( value );
1369 } 1370 }
1370 else if ( name == "X-Qtopia-Manager" ) { 1371 else if ( name == "X-Qtopia-Manager" ) {
1371 c.setManager( value ); 1372 c.setManager( value );
1372 } 1373 }
1373 else if ( name == "X-Qtopia-Assistant" ) { 1374 else if ( name == "X-Qtopia-Assistant" ) {
1374 c.setAssistant( value ); 1375 c.setAssistant( value );
1375 } 1376 }
1376 else if ( name == "X-Qtopia-Spouse" ) { 1377 else if ( name == "X-Qtopia-Spouse" ) {
1377 c.setSpouse( value ); 1378 c.setSpouse( value );
1378 } 1379 }
1379 else if ( name == "X-Qtopia-Gender" ) { 1380 else if ( name == "X-Qtopia-Gender" ) {
1380 c.setGender( value ); 1381 c.setGender( value );
1381 } 1382 }
1382 else if ( name == "X-Qtopia-Anniversary" ) { 1383 else if ( name == "X-Qtopia-Anniversary" ) {
1383 c.setAnniversary( TimeConversion::fromString( value ) ); 1384 // c.setAnniversary( TimeConversion::fromString( value ) ); :SX
1384 } 1385 }
1385 else if ( name == "X-Qtopia-Nickname" ) { 1386 else if ( name == "X-Qtopia-Nickname" ) {
1386 c.setNickname( value ); 1387 c.setNickname( value );
1387 } 1388 }
1388 else if ( name == "X-Qtopia-Children" ) { 1389 else if ( name == "X-Qtopia-Children" ) {
1389 c.setChildren( value ); 1390 c.setChildren( value );
1390 } 1391 }
1391 else if ( name == VCBirthDateProp ) { 1392 else if ( name == VCBirthDateProp ) {
1392 // Reading Birthdate regarding RFC 2425 (5.8.4) 1393 // Reading Birthdate regarding RFC 2425 (5.8.4)
1393 c.setBirthday( convVCardDateToDate( value ) ); 1394 c.setBirthday( convVCardDateToDate( value ) );
1394 1395
1395 } 1396 }
1396 1397
1397#if 0 1398#if 0
1398 else { 1399 else {
1399 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1400 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
1400 VObjectIterator nit; 1401 VObjectIterator nit;
1401 initPropIterator( &nit, o ); 1402 initPropIterator( &nit, o );
1402 while( moreIteration( &nit ) ) { 1403 while( moreIteration( &nit ) ) {
1403 VObject *o = nextVObject( &nit ); 1404 VObject *o = nextVObject( &nit );
1404 QCString name = vObjectName( o ); 1405 QCString name = vObjectName( o );
1405 QString value = vObjectStringZValue( o ); 1406 QString value = vObjectStringZValue( o );
1406 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 1407 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
1407 } 1408 }
1408 } 1409 }
1409#endif 1410#endif
1410 } 1411 }
1411 c.setFileAs(); 1412 c.setFileAs();
1412 return c; 1413 return c;
1413} 1414}
1414 1415
1415/*! 1416/*!
1416 Writes the list of \a contacts as a set of VCards to the file \a filename. 1417 Writes the list of \a contacts as a set of VCards to the file \a filename.
1417*/ 1418*/
1418void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts) 1419void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts)
1419{ 1420{
1420 QFileDirect f( filename.utf8().data() ); 1421 QFileDirect f( filename.utf8().data() );
1421 if ( !f.open( IO_WriteOnly ) ) { 1422 if ( !f.open( IO_WriteOnly ) ) {
1422 qWarning("Unable to open vcard write"); 1423 qWarning("Unable to open vcard write");
1423 return; 1424 return;
1424 } 1425 }
1425 1426
1426 QValueList<OContact>::ConstIterator it; 1427 QValueList<OContact>::ConstIterator it;
1427 for( it = contacts.begin(); it != contacts.end(); ++it ) { 1428 for( it = contacts.begin(); it != contacts.end(); ++it ) {
1428 VObject *obj = createVObject( *it ); 1429 VObject *obj = createVObject( *it );
1429 writeVObject(f.directHandle() , obj ); 1430 writeVObject(f.directHandle() , obj );
1430 cleanVObject( obj ); 1431 cleanVObject( obj );
1431 } 1432 }
1432 cleanStrTbl(); 1433 cleanStrTbl();
1433} 1434}
1434 1435
1435/*! 1436/*!
1436 writes \a contact as a VCard to the file \a filename. 1437 writes \a contact as a VCard to the file \a filename.
1437*/ 1438*/
1438void OContact::writeVCard( const QString &filename, const OContact &contact) 1439void OContact::writeVCard( const QString &filename, const OContact &contact)
1439{ 1440{
1440 QFileDirect f( filename.utf8().data() ); 1441 QFileDirect f( filename.utf8().data() );
1441 if ( !f.open( IO_WriteOnly ) ) { 1442 if ( !f.open( IO_WriteOnly ) ) {
1442 qWarning("Unable to open vcard write"); 1443 qWarning("Unable to open vcard write");
1443 return; 1444 return;
1444 } 1445 }
1445 1446
1446 VObject *obj = createVObject( contact ); 1447 VObject *obj = createVObject( contact );
1447 writeVObject( f.directHandle() , obj ); 1448 writeVObject( f.directHandle() , obj );
1448 cleanVObject( obj ); 1449 cleanVObject( obj );
1449 1450
1450 cleanStrTbl(); 1451 cleanStrTbl();
1451} 1452}
1452 1453
1453/*! 1454/*!
1454 Returns the set of contacts read as VCards from the file \a filename. 1455 Returns the set of contacts read as VCards from the file \a filename.
1455*/ 1456*/
1456QValueList<OContact> OContact::readVCard( const QString &filename ) 1457QValueList<OContact> OContact::readVCard( const QString &filename )
1457{ 1458{
1458 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); 1459 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() );
1459 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); 1460 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
1460 1461
1461 qDebug("vobject = %p", obj ); 1462 qDebug("vobject = %p", obj );
1462 1463
1463 QValueList<OContact> contacts; 1464 QValueList<OContact> contacts;
1464 1465
1465 while ( obj ) { 1466 while ( obj ) {
1466 OContact con = parseVObject( obj ); 1467 OContact con = parseVObject( obj );
1467 /* 1468 /*
1468 * if uid is 0 assign a new one 1469 * if uid is 0 assign a new one
1469 * this at least happens on 1470 * this at least happens on
1470 * Nokia6210 1471 * Nokia6210
1471 */ 1472 */
1472 if ( con.uid() == 0 ){ 1473 if ( con.uid() == 0 ){
1473 con.setUid( 1 ); 1474 con.setUid( 1 );
1474 qWarning("assigned new uid %d",con.uid() ); 1475 qWarning("assigned new uid %d",con.uid() );
1475 } 1476 }
1476 1477
1477 contacts.append(con ); 1478 contacts.append(con );
1478 1479
1479 VObject *t = obj; 1480 VObject *t = obj;
1480 obj = nextVObjectInList(obj); 1481 obj = nextVObjectInList(obj);
1481 cleanVObject( t ); 1482 cleanVObject( t );
1482 } 1483 }
1483 1484
1484 return contacts; 1485 return contacts;
1485} 1486}
1486 1487
1487/*! 1488/*!
1488 Returns TRUE if the contact matches the regular expression \a regexp. 1489 Returns TRUE if the contact matches the regular expression \a regexp.
1489 Otherwise returns FALSE. 1490 Otherwise returns FALSE.
1490*/ 1491*/
1491bool OContact::match( const QString &regexp ) const 1492bool OContact::match( const QString &regexp ) const
1492{ 1493{
1493 return match(QRegExp(regexp)); 1494 return match(QRegExp(regexp));
1494} 1495}
1495 1496
1496/*! 1497/*!
1497 \overload 1498 \overload
1498 Returns TRUE if the contact matches the regular expression \a regexp. 1499 Returns TRUE if the contact matches the regular expression \a regexp.
1499 Otherwise returns FALSE. 1500 Otherwise returns FALSE.
1500*/ 1501*/
1501bool OContact::match( const QRegExp &r ) const 1502bool OContact::match( const QRegExp &r ) const
1502{ 1503{
1503 bool match; 1504 bool match;
1504 match = false; 1505 match = false;
1505 QMap<int, QString>::ConstIterator it; 1506 QMap<int, QString>::ConstIterator it;
1506 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 1507 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
1507 if ( (*it).find( r ) > -1 ) { 1508 if ( (*it).find( r ) > -1 ) {
1508 match = true; 1509 match = true;
1509 break; 1510 break;
1510 } 1511 }
1511 } 1512 }
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index 8a0930b..b0f0d7f 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -1027,485 +1027,486 @@ void OContact::setChildren( const QString &str )
1027*/ 1027*/
1028static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 1028static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
1029{ 1029{
1030 VObject *ret = 0; 1030 VObject *ret = 0;
1031 if ( o && !value.isEmpty() ) 1031 if ( o && !value.isEmpty() )
1032 ret = addPropValue( o, prop, value.latin1() ); 1032 ret = addPropValue( o, prop, value.latin1() );
1033 return ret; 1033 return ret;
1034} 1034}
1035 1035
1036/*! 1036/*!
1037 \internal 1037 \internal
1038*/ 1038*/
1039static inline VObject *safeAddProp( VObject *o, const char *prop) 1039static inline VObject *safeAddProp( VObject *o, const char *prop)
1040{ 1040{
1041 VObject *ret = 0; 1041 VObject *ret = 0;
1042 if ( o ) 1042 if ( o )
1043 ret = addProp( o, prop ); 1043 ret = addProp( o, prop );
1044 return ret; 1044 return ret;
1045} 1045}
1046 1046
1047/*! 1047/*!
1048 \internal 1048 \internal
1049*/ 1049*/
1050static VObject *createVObject( const OContact &c ) 1050static VObject *createVObject( const OContact &c )
1051{ 1051{
1052 VObject *vcard = newVObject( VCCardProp ); 1052 VObject *vcard = newVObject( VCCardProp );
1053 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 1053 safeAddPropValue( vcard, VCVersionProp, "2.1" );
1054 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 1054 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
1055 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 1055 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
1056 1056
1057 // full name 1057 // full name
1058 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 1058 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
1059 1059
1060 // name properties 1060 // name properties
1061 VObject *name = safeAddProp( vcard, VCNameProp ); 1061 VObject *name = safeAddProp( vcard, VCNameProp );
1062 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 1062 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
1063 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 1063 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
1064 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 1064 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
1065 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 1065 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
1066 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 1066 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
1067 1067
1068 // home properties 1068 // home properties
1069 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 1069 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
1070 safeAddProp( home_adr, VCHomeProp ); 1070 safeAddProp( home_adr, VCHomeProp );
1071 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 1071 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
1072 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 1072 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
1073 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 1073 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
1074 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 1074 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
1075 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 1075 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
1076 1076
1077 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 1077 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
1078 safeAddProp( home_phone, VCHomeProp ); 1078 safeAddProp( home_phone, VCHomeProp );
1079 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 1079 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
1080 safeAddProp( home_phone, VCHomeProp ); 1080 safeAddProp( home_phone, VCHomeProp );
1081 safeAddProp( home_phone, VCCellularProp ); 1081 safeAddProp( home_phone, VCCellularProp );
1082 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 1082 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
1083 safeAddProp( home_phone, VCHomeProp ); 1083 safeAddProp( home_phone, VCHomeProp );
1084 safeAddProp( home_phone, VCFaxProp ); 1084 safeAddProp( home_phone, VCFaxProp );
1085 1085
1086 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 1086 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
1087 safeAddProp( url, VCHomeProp ); 1087 safeAddProp( url, VCHomeProp );
1088 1088
1089 // work properties 1089 // work properties
1090 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 1090 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
1091 safeAddProp( work_adr, VCWorkProp ); 1091 safeAddProp( work_adr, VCWorkProp );
1092 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 1092 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
1093 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 1093 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
1094 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 1094 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
1095 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 1095 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
1096 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 1096 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
1097 1097
1098 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 1098 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
1099 safeAddProp( work_phone, VCWorkProp ); 1099 safeAddProp( work_phone, VCWorkProp );
1100 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 1100 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
1101 safeAddProp( work_phone, VCWorkProp ); 1101 safeAddProp( work_phone, VCWorkProp );
1102 safeAddProp( work_phone, VCCellularProp ); 1102 safeAddProp( work_phone, VCCellularProp );
1103 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 1103 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
1104 safeAddProp( work_phone, VCWorkProp ); 1104 safeAddProp( work_phone, VCWorkProp );
1105 safeAddProp( work_phone, VCFaxProp ); 1105 safeAddProp( work_phone, VCFaxProp );
1106 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 1106 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
1107 safeAddProp( work_phone, VCWorkProp ); 1107 safeAddProp( work_phone, VCWorkProp );
1108 safeAddProp( work_phone, VCPagerProp ); 1108 safeAddProp( work_phone, VCPagerProp );
1109 1109
1110 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 1110 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
1111 safeAddProp( url, VCWorkProp ); 1111 safeAddProp( url, VCWorkProp );
1112 1112
1113 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 1113 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
1114 safeAddProp( title, VCWorkProp ); 1114 safeAddProp( title, VCWorkProp );
1115 1115
1116 1116
1117 QStringList emails = c.emailList(); 1117 QStringList emails = c.emailList();
1118 emails.prepend( c.defaultEmail() ); 1118 emails.prepend( c.defaultEmail() );
1119 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 1119 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
1120 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 1120 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
1121 safeAddProp( email, VCInternetProp ); 1121 safeAddProp( email, VCInternetProp );
1122 } 1122 }
1123 1123
1124 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 1124 safeAddPropValue( vcard, VCNoteProp, c.notes() );
1125 1125
1126 // Exporting Birthday regarding RFC 2425 (5.8.4) 1126 // Exporting Birthday regarding RFC 2425 (5.8.4)
1127 if ( c.birthday().isValid() ){ 1127 if ( c.birthday().isValid() ){
1128 QString birthd_rfc2425 = QString("%1-%2-%3") 1128 QString birthd_rfc2425 = QString("%1-%2-%3")
1129 .arg( c.birthday().year() ) 1129 .arg( c.birthday().year() )
1130 .arg( c.birthday().month(), 2 ) 1130 .arg( c.birthday().month(), 2 )
1131 .arg( c.birthday().day(), 2 ); 1131 .arg( c.birthday().day(), 2 );
1132 // Now replace spaces with "0"... 1132 // Now replace spaces with "0"...
1133 int pos = 0; 1133 int pos = 0;
1134 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) 1134 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 )
1135 birthd_rfc2425.replace( pos, 1, "0" ); 1135 birthd_rfc2425.replace( pos, 1, "0" );
1136 1136
1137 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); 1137 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1());
1138 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); 1138 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() );
1139 } 1139 }
1140 1140
1141 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 1141 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
1142 VObject *org = safeAddProp( vcard, VCOrgProp ); 1142 VObject *org = safeAddProp( vcard, VCOrgProp );
1143 safeAddPropValue( org, VCOrgNameProp, c.company() ); 1143 safeAddPropValue( org, VCOrgNameProp, c.company() );
1144 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 1144 safeAddPropValue( org, VCOrgUnitProp, c.department() );
1145 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 1145 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
1146 } 1146 }
1147 1147
1148 // some values we have to export as custom fields 1148 // some values we have to export as custom fields
1149 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 1149 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
1150 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 1150 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
1151 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 1151 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
1152 1152
1153 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 1153 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
1154 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 1154 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
1155 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); 1155 // safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); :SX
1156 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 1156 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
1157 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 1157 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
1158 1158
1159 return vcard; 1159 return vcard;
1160} 1160}
1161 1161
1162 1162
1163/*! 1163/*!
1164 \internal 1164 \internal
1165*/ 1165*/
1166static QDate convVCardDateToDate( const QString& datestr ) 1166static QDate convVCardDateToDate( const QString& datestr )
1167{ 1167{
1168 int monthPos = datestr.find('-'); 1168 int monthPos = datestr.find('-');
1169 int dayPos = datestr.find('-', monthPos+1 ); 1169 int dayPos = datestr.find('-', monthPos+1 );
1170 int sep_ignore = 1; 1170 int sep_ignore = 1;
1171 if ( monthPos == -1 || dayPos == -1 ) { 1171 if ( monthPos == -1 || dayPos == -1 ) {
1172 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1172 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1173 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 1173 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
1174 if ( datestr.length() == 8 ){ 1174 if ( datestr.length() == 8 ){
1175 monthPos = 4; 1175 monthPos = 4;
1176 dayPos = 6; 1176 dayPos = 6;
1177 sep_ignore = 0; 1177 sep_ignore = 0;
1178 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1178 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1179 } else { 1179 } else {
1180 return QDate(); 1180 return QDate();
1181 } 1181 }
1182 } 1182 }
1183 int y = datestr.left( monthPos ).toInt(); 1183 int y = datestr.left( monthPos ).toInt();
1184 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 1184 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
1185 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 1185 int d = datestr.mid( dayPos + sep_ignore ).toInt();
1186 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 1186 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos);
1187 QDate date ( y,m,d ); 1187 QDate date ( y,m,d );
1188 return date; 1188 return date;
1189} 1189}
1190 1190
1191static OContact parseVObject( VObject *obj ) 1191static OContact parseVObject( VObject *obj )
1192{ 1192{
1193 OContact c; 1193 OContact c;
1194 1194
1195 VObjectIterator it; 1195 VObjectIterator it;
1196 initPropIterator( &it, obj ); 1196 initPropIterator( &it, obj );
1197 while( moreIteration( &it ) ) { 1197 while( moreIteration( &it ) ) {
1198 VObject *o = nextVObject( &it ); 1198 VObject *o = nextVObject( &it );
1199 QCString name = vObjectName( o ); 1199 QCString name = vObjectName( o );
1200 QCString value = vObjectStringZValue( o ); 1200 QCString value = vObjectStringZValue( o );
1201 if ( name == VCNameProp ) { 1201 if ( name == VCNameProp ) {
1202 VObjectIterator nit; 1202 VObjectIterator nit;
1203 initPropIterator( &nit, o ); 1203 initPropIterator( &nit, o );
1204 while( moreIteration( &nit ) ) { 1204 while( moreIteration( &nit ) ) {
1205 VObject *o = nextVObject( &nit ); 1205 VObject *o = nextVObject( &nit );
1206 QCString name = vObjectTypeInfo( o ); 1206 QCString name = vObjectTypeInfo( o );
1207 QString value = vObjectStringZValue( o ); 1207 QString value = vObjectStringZValue( o );
1208 if ( name == VCNamePrefixesProp ) 1208 if ( name == VCNamePrefixesProp )
1209 c.setTitle( value ); 1209 c.setTitle( value );
1210 else if ( name == VCNameSuffixesProp ) 1210 else if ( name == VCNameSuffixesProp )
1211 c.setSuffix( value ); 1211 c.setSuffix( value );
1212 else if ( name == VCFamilyNameProp ) 1212 else if ( name == VCFamilyNameProp )
1213 c.setLastName( value ); 1213 c.setLastName( value );
1214 else if ( name == VCGivenNameProp ) 1214 else if ( name == VCGivenNameProp )
1215 c.setFirstName( value ); 1215 c.setFirstName( value );
1216 else if ( name == VCAdditionalNamesProp ) 1216 else if ( name == VCAdditionalNamesProp )
1217 c.setMiddleName( value ); 1217 c.setMiddleName( value );
1218 } 1218 }
1219 } 1219 }
1220 else if ( name == VCAdrProp ) { 1220 else if ( name == VCAdrProp ) {
1221 bool work = TRUE; // default address is work address 1221 bool work = TRUE; // default address is work address
1222 QString street; 1222 QString street;
1223 QString city; 1223 QString city;
1224 QString region; 1224 QString region;
1225 QString postal; 1225 QString postal;
1226 QString country; 1226 QString country;
1227 1227
1228 VObjectIterator nit; 1228 VObjectIterator nit;
1229 initPropIterator( &nit, o ); 1229 initPropIterator( &nit, o );
1230 while( moreIteration( &nit ) ) { 1230 while( moreIteration( &nit ) ) {
1231 VObject *o = nextVObject( &nit ); 1231 VObject *o = nextVObject( &nit );
1232 QCString name = vObjectName( o ); 1232 QCString name = vObjectName( o );
1233 QString value = vObjectStringZValue( o ); 1233 QString value = vObjectStringZValue( o );
1234
1234 if ( name == VCHomeProp ) 1235 if ( name == VCHomeProp )
1235 work = FALSE; 1236 work = FALSE;
1236 else if ( name == VCWorkProp ) 1237 else if ( name == VCWorkProp )
1237 work = TRUE; 1238 work = TRUE;
1238 else if ( name == VCStreetAddressProp ) 1239 else if ( name == VCStreetAddressProp )
1239 street = value; 1240 street = value;
1240 else if ( name == VCCityProp ) 1241 else if ( name == VCCityProp )
1241 city = value; 1242 city = value;
1242 else if ( name == VCRegionProp ) 1243 else if ( name == VCRegionProp )
1243 region = value; 1244 region = value;
1244 else if ( name == VCPostalCodeProp ) 1245 else if ( name == VCPostalCodeProp )
1245 postal = value; 1246 postal = value;
1246 else if ( name == VCCountryNameProp ) 1247 else if ( name == VCCountryNameProp )
1247 country = value; 1248 country = value;
1248 } 1249 }
1249 if ( work ) { 1250 if ( work ) {
1250 c.setBusinessStreet( street ); 1251 c.setBusinessStreet( street );
1251 c.setBusinessCity( city ); 1252 c.setBusinessCity( city );
1252 c.setBusinessCountry( country ); 1253 c.setBusinessCountry( country );
1253 c.setBusinessZip( postal ); 1254 c.setBusinessZip( postal );
1254 c.setBusinessState( region ); 1255 c.setBusinessState( region );
1255 } else { 1256 } else {
1256 c.setHomeStreet( street ); 1257 c.setHomeStreet( street );
1257 c.setHomeCity( city ); 1258 c.setHomeCity( city );
1258 c.setHomeCountry( country ); 1259 c.setHomeCountry( country );
1259 c.setHomeZip( postal ); 1260 c.setHomeZip( postal );
1260 c.setHomeState( region ); 1261 c.setHomeState( region );
1261 } 1262 }
1262 } 1263 }
1263 else if ( name == VCTelephoneProp ) { 1264 else if ( name == VCTelephoneProp ) {
1264 enum { 1265 enum {
1265 HOME = 0x01, 1266 HOME = 0x01,
1266 WORK = 0x02, 1267 WORK = 0x02,
1267 VOICE = 0x04, 1268 VOICE = 0x04,
1268 CELL = 0x08, 1269 CELL = 0x08,
1269 FAX = 0x10, 1270 FAX = 0x10,
1270 PAGER = 0x20, 1271 PAGER = 0x20,
1271 UNKNOWN = 0x80 1272 UNKNOWN = 0x80
1272 }; 1273 };
1273 int type = 0; 1274 int type = 0;
1274 1275
1275 VObjectIterator nit; 1276 VObjectIterator nit;
1276 initPropIterator( &nit, o ); 1277 initPropIterator( &nit, o );
1277 while( moreIteration( &nit ) ) { 1278 while( moreIteration( &nit ) ) {
1278 VObject *o = nextVObject( &nit ); 1279 VObject *o = nextVObject( &nit );
1279 QCString name = vObjectTypeInfo( o ); 1280 QCString name = vObjectTypeInfo( o );
1280 if ( name == VCHomeProp ) 1281 if ( name == VCHomeProp )
1281 type |= HOME; 1282 type |= HOME;
1282 else if ( name == VCWorkProp ) 1283 else if ( name == VCWorkProp )
1283 type |= WORK; 1284 type |= WORK;
1284 else if ( name == VCVoiceProp ) 1285 else if ( name == VCVoiceProp )
1285 type |= VOICE; 1286 type |= VOICE;
1286 else if ( name == VCCellularProp ) 1287 else if ( name == VCCellularProp )
1287 type |= CELL; 1288 type |= CELL;
1288 else if ( name == VCFaxProp ) 1289 else if ( name == VCFaxProp )
1289 type |= FAX; 1290 type |= FAX;
1290 else if ( name == VCPagerProp ) 1291 else if ( name == VCPagerProp )
1291 type |= PAGER; 1292 type |= PAGER;
1292 else if ( name == VCPreferredProp ) 1293 else if ( name == VCPreferredProp )
1293 ; 1294 ;
1294 else 1295 else
1295 type |= UNKNOWN; 1296 type |= UNKNOWN;
1296 } 1297 }
1297 if ( (type & UNKNOWN) != UNKNOWN ) { 1298 if ( (type & UNKNOWN) != UNKNOWN ) {
1298 if ( ( type & (HOME|WORK) ) == 0 ) // default 1299 if ( ( type & (HOME|WORK) ) == 0 ) // default
1299 type |= HOME; 1300 type |= HOME;
1300 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 1301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
1301 type |= VOICE; 1302 type |= VOICE;
1302 1303
1303 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 1304 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
1304 c.setHomePhone( value ); 1305 c.setHomePhone( value );
1305 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 1306 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
1306 c.setHomeFax( value ); 1307 c.setHomeFax( value );
1307 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 1308 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
1308 c.setHomeMobile( value ); 1309 c.setHomeMobile( value );
1309 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 1310 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
1310 c.setBusinessPhone( value ); 1311 c.setBusinessPhone( value );
1311 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 1312 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
1312 c.setBusinessFax( value ); 1313 c.setBusinessFax( value );
1313 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 1314 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
1314 c.setBusinessMobile( value ); 1315 c.setBusinessMobile( value );
1315 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 1316 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
1316 c.setBusinessPager( value ); 1317 c.setBusinessPager( value );
1317 } 1318 }
1318 } 1319 }
1319 else if ( name == VCEmailAddressProp ) { 1320 else if ( name == VCEmailAddressProp ) {
1320 QString email = vObjectStringZValue( o ); 1321 QString email = vObjectStringZValue( o );
1321 bool valid = TRUE; 1322 bool valid = TRUE;
1322 VObjectIterator nit; 1323 VObjectIterator nit;
1323 initPropIterator( &nit, o ); 1324 initPropIterator( &nit, o );
1324 while( moreIteration( &nit ) ) { 1325 while( moreIteration( &nit ) ) {
1325 VObject *o = nextVObject( &nit ); 1326 VObject *o = nextVObject( &nit );
1326 QCString name = vObjectTypeInfo( o ); 1327 QCString name = vObjectTypeInfo( o );
1327 if ( name != VCInternetProp && name != VCHomeProp && 1328 if ( name != VCInternetProp && name != VCHomeProp &&
1328 name != VCWorkProp && 1329 name != VCWorkProp &&
1329 name != VCPreferredProp ) 1330 name != VCPreferredProp )
1330 // ### preffered should map to default email 1331 // ### preffered should map to default email
1331 valid = FALSE; 1332 valid = FALSE;
1332 } 1333 }
1333 if ( valid ) { 1334 if ( valid ) {
1334 c.insertEmail( email ); 1335 c.insertEmail( email );
1335 } 1336 }
1336 } 1337 }
1337 else if ( name == VCURLProp ) { 1338 else if ( name == VCURLProp ) {
1338 VObjectIterator nit; 1339 VObjectIterator nit;
1339 initPropIterator( &nit, o ); 1340 initPropIterator( &nit, o );
1340 while( moreIteration( &nit ) ) { 1341 while( moreIteration( &nit ) ) {
1341 VObject *o = nextVObject( &nit ); 1342 VObject *o = nextVObject( &nit );
1342 QCString name = vObjectTypeInfo( o ); 1343 QCString name = vObjectTypeInfo( o );
1343 if ( name == VCHomeProp ) 1344 if ( name == VCHomeProp )
1344 c.setHomeWebpage( value ); 1345 c.setHomeWebpage( value );
1345 else if ( name == VCWorkProp ) 1346 else if ( name == VCWorkProp )
1346 c.setBusinessWebpage( value ); 1347 c.setBusinessWebpage( value );
1347 } 1348 }
1348 } 1349 }
1349 else if ( name == VCOrgProp ) { 1350 else if ( name == VCOrgProp ) {
1350 VObjectIterator nit; 1351 VObjectIterator nit;
1351 initPropIterator( &nit, o ); 1352 initPropIterator( &nit, o );
1352 while( moreIteration( &nit ) ) { 1353 while( moreIteration( &nit ) ) {
1353 VObject *o = nextVObject( &nit ); 1354 VObject *o = nextVObject( &nit );
1354 QCString name = vObjectName( o ); 1355 QCString name = vObjectName( o );
1355 QString value = vObjectStringZValue( o ); 1356 QString value = vObjectStringZValue( o );
1356 if ( name == VCOrgNameProp ) 1357 if ( name == VCOrgNameProp )
1357 c.setCompany( value ); 1358 c.setCompany( value );
1358 else if ( name == VCOrgUnitProp ) 1359 else if ( name == VCOrgUnitProp )
1359 c.setDepartment( value ); 1360 c.setDepartment( value );
1360 else if ( name == VCOrgUnit2Prop ) 1361 else if ( name == VCOrgUnit2Prop )
1361 c.setOffice( value ); 1362 c.setOffice( value );
1362 } 1363 }
1363 } 1364 }
1364 else if ( name == VCTitleProp ) { 1365 else if ( name == VCTitleProp ) {
1365 c.setJobTitle( value ); 1366 c.setJobTitle( value );
1366 } 1367 }
1367 else if ( name == "X-Qtopia-Profession" ) { 1368 else if ( name == "X-Qtopia-Profession" ) {
1368 c.setProfession( value ); 1369 c.setProfession( value );
1369 } 1370 }
1370 else if ( name == "X-Qtopia-Manager" ) { 1371 else if ( name == "X-Qtopia-Manager" ) {
1371 c.setManager( value ); 1372 c.setManager( value );
1372 } 1373 }
1373 else if ( name == "X-Qtopia-Assistant" ) { 1374 else if ( name == "X-Qtopia-Assistant" ) {
1374 c.setAssistant( value ); 1375 c.setAssistant( value );
1375 } 1376 }
1376 else if ( name == "X-Qtopia-Spouse" ) { 1377 else if ( name == "X-Qtopia-Spouse" ) {
1377 c.setSpouse( value ); 1378 c.setSpouse( value );
1378 } 1379 }
1379 else if ( name == "X-Qtopia-Gender" ) { 1380 else if ( name == "X-Qtopia-Gender" ) {
1380 c.setGender( value ); 1381 c.setGender( value );
1381 } 1382 }
1382 else if ( name == "X-Qtopia-Anniversary" ) { 1383 else if ( name == "X-Qtopia-Anniversary" ) {
1383 c.setAnniversary( TimeConversion::fromString( value ) ); 1384 // c.setAnniversary( TimeConversion::fromString( value ) ); :SX
1384 } 1385 }
1385 else if ( name == "X-Qtopia-Nickname" ) { 1386 else if ( name == "X-Qtopia-Nickname" ) {
1386 c.setNickname( value ); 1387 c.setNickname( value );
1387 } 1388 }
1388 else if ( name == "X-Qtopia-Children" ) { 1389 else if ( name == "X-Qtopia-Children" ) {
1389 c.setChildren( value ); 1390 c.setChildren( value );
1390 } 1391 }
1391 else if ( name == VCBirthDateProp ) { 1392 else if ( name == VCBirthDateProp ) {
1392 // Reading Birthdate regarding RFC 2425 (5.8.4) 1393 // Reading Birthdate regarding RFC 2425 (5.8.4)
1393 c.setBirthday( convVCardDateToDate( value ) ); 1394 c.setBirthday( convVCardDateToDate( value ) );
1394 1395
1395 } 1396 }
1396 1397
1397#if 0 1398#if 0
1398 else { 1399 else {
1399 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1400 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
1400 VObjectIterator nit; 1401 VObjectIterator nit;
1401 initPropIterator( &nit, o ); 1402 initPropIterator( &nit, o );
1402 while( moreIteration( &nit ) ) { 1403 while( moreIteration( &nit ) ) {
1403 VObject *o = nextVObject( &nit ); 1404 VObject *o = nextVObject( &nit );
1404 QCString name = vObjectName( o ); 1405 QCString name = vObjectName( o );
1405 QString value = vObjectStringZValue( o ); 1406 QString value = vObjectStringZValue( o );
1406 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 1407 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
1407 } 1408 }
1408 } 1409 }
1409#endif 1410#endif
1410 } 1411 }
1411 c.setFileAs(); 1412 c.setFileAs();
1412 return c; 1413 return c;
1413} 1414}
1414 1415
1415/*! 1416/*!
1416 Writes the list of \a contacts as a set of VCards to the file \a filename. 1417 Writes the list of \a contacts as a set of VCards to the file \a filename.
1417*/ 1418*/
1418void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts) 1419void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts)
1419{ 1420{
1420 QFileDirect f( filename.utf8().data() ); 1421 QFileDirect f( filename.utf8().data() );
1421 if ( !f.open( IO_WriteOnly ) ) { 1422 if ( !f.open( IO_WriteOnly ) ) {
1422 qWarning("Unable to open vcard write"); 1423 qWarning("Unable to open vcard write");
1423 return; 1424 return;
1424 } 1425 }
1425 1426
1426 QValueList<OContact>::ConstIterator it; 1427 QValueList<OContact>::ConstIterator it;
1427 for( it = contacts.begin(); it != contacts.end(); ++it ) { 1428 for( it = contacts.begin(); it != contacts.end(); ++it ) {
1428 VObject *obj = createVObject( *it ); 1429 VObject *obj = createVObject( *it );
1429 writeVObject(f.directHandle() , obj ); 1430 writeVObject(f.directHandle() , obj );
1430 cleanVObject( obj ); 1431 cleanVObject( obj );
1431 } 1432 }
1432 cleanStrTbl(); 1433 cleanStrTbl();
1433} 1434}
1434 1435
1435/*! 1436/*!
1436 writes \a contact as a VCard to the file \a filename. 1437 writes \a contact as a VCard to the file \a filename.
1437*/ 1438*/
1438void OContact::writeVCard( const QString &filename, const OContact &contact) 1439void OContact::writeVCard( const QString &filename, const OContact &contact)
1439{ 1440{
1440 QFileDirect f( filename.utf8().data() ); 1441 QFileDirect f( filename.utf8().data() );
1441 if ( !f.open( IO_WriteOnly ) ) { 1442 if ( !f.open( IO_WriteOnly ) ) {
1442 qWarning("Unable to open vcard write"); 1443 qWarning("Unable to open vcard write");
1443 return; 1444 return;
1444 } 1445 }
1445 1446
1446 VObject *obj = createVObject( contact ); 1447 VObject *obj = createVObject( contact );
1447 writeVObject( f.directHandle() , obj ); 1448 writeVObject( f.directHandle() , obj );
1448 cleanVObject( obj ); 1449 cleanVObject( obj );
1449 1450
1450 cleanStrTbl(); 1451 cleanStrTbl();
1451} 1452}
1452 1453
1453/*! 1454/*!
1454 Returns the set of contacts read as VCards from the file \a filename. 1455 Returns the set of contacts read as VCards from the file \a filename.
1455*/ 1456*/
1456QValueList<OContact> OContact::readVCard( const QString &filename ) 1457QValueList<OContact> OContact::readVCard( const QString &filename )
1457{ 1458{
1458 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); 1459 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() );
1459 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); 1460 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
1460 1461
1461 qDebug("vobject = %p", obj ); 1462 qDebug("vobject = %p", obj );
1462 1463
1463 QValueList<OContact> contacts; 1464 QValueList<OContact> contacts;
1464 1465
1465 while ( obj ) { 1466 while ( obj ) {
1466 OContact con = parseVObject( obj ); 1467 OContact con = parseVObject( obj );
1467 /* 1468 /*
1468 * if uid is 0 assign a new one 1469 * if uid is 0 assign a new one
1469 * this at least happens on 1470 * this at least happens on
1470 * Nokia6210 1471 * Nokia6210
1471 */ 1472 */
1472 if ( con.uid() == 0 ){ 1473 if ( con.uid() == 0 ){
1473 con.setUid( 1 ); 1474 con.setUid( 1 );
1474 qWarning("assigned new uid %d",con.uid() ); 1475 qWarning("assigned new uid %d",con.uid() );
1475 } 1476 }
1476 1477
1477 contacts.append(con ); 1478 contacts.append(con );
1478 1479
1479 VObject *t = obj; 1480 VObject *t = obj;
1480 obj = nextVObjectInList(obj); 1481 obj = nextVObjectInList(obj);
1481 cleanVObject( t ); 1482 cleanVObject( t );
1482 } 1483 }
1483 1484
1484 return contacts; 1485 return contacts;
1485} 1486}
1486 1487
1487/*! 1488/*!
1488 Returns TRUE if the contact matches the regular expression \a regexp. 1489 Returns TRUE if the contact matches the regular expression \a regexp.
1489 Otherwise returns FALSE. 1490 Otherwise returns FALSE.
1490*/ 1491*/
1491bool OContact::match( const QString &regexp ) const 1492bool OContact::match( const QString &regexp ) const
1492{ 1493{
1493 return match(QRegExp(regexp)); 1494 return match(QRegExp(regexp));
1494} 1495}
1495 1496
1496/*! 1497/*!
1497 \overload 1498 \overload
1498 Returns TRUE if the contact matches the regular expression \a regexp. 1499 Returns TRUE if the contact matches the regular expression \a regexp.
1499 Otherwise returns FALSE. 1500 Otherwise returns FALSE.
1500*/ 1501*/
1501bool OContact::match( const QRegExp &r ) const 1502bool OContact::match( const QRegExp &r ) const
1502{ 1503{
1503 bool match; 1504 bool match;
1504 match = false; 1505 match = false;
1505 QMap<int, QString>::ConstIterator it; 1506 QMap<int, QString>::ConstIterator it;
1506 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 1507 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
1507 if ( (*it).find( r ) > -1 ) { 1508 if ( (*it).find( r ) > -1 ) {
1508 match = true; 1509 match = true;
1509 break; 1510 break;
1510 } 1511 }
1511 } 1512 }