summaryrefslogtreecommitdiff
path: root/libopie/pim/ocontact.cpp
Side-by-side diff
Diffstat (limited to 'libopie/pim/ocontact.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontact.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp
index acd65c4..cd238ef 100644
--- a/libopie/pim/ocontact.cpp
+++ b/libopie/pim/ocontact.cpp
@@ -1082,104 +1082,104 @@ static VObject *createVObject( const OContact &c )
safeAddProp( home_phone, VCCellularProp );
home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
safeAddProp( home_phone, VCHomeProp );
safeAddProp( home_phone, VCFaxProp );
VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
safeAddProp( url, VCHomeProp );
// work properties
VObject *work_adr= safeAddProp( vcard, VCAdrProp );
safeAddProp( work_adr, VCWorkProp );
safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
safeAddProp( work_phone, VCWorkProp );
work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
safeAddProp( work_phone, VCWorkProp );
safeAddProp( work_phone, VCCellularProp );
work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
safeAddProp( work_phone, VCWorkProp );
safeAddProp( work_phone, VCFaxProp );
work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
safeAddProp( work_phone, VCWorkProp );
safeAddProp( work_phone, VCPagerProp );
url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
safeAddProp( url, VCWorkProp );
VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
safeAddProp( title, VCWorkProp );
QStringList emails = c.emailList();
emails.prepend( c.defaultEmail() );
for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
safeAddProp( email, VCInternetProp );
}
safeAddPropValue( vcard, VCNoteProp, c.notes() );
// Exporting Birthday regarding RFC 2425 (5.8.4)
if ( c.birthday().isValid() ){
QString birthd_rfc2425 = QString("%1-%2-%3")
- .arg( c.birthday().year() )
+ .arg( c.birthday().year() )
.arg( c.birthday().month(), 2 )
.arg( c.birthday().day(), 2 );
// Now replace spaces with "0"...
int pos = 0;
while ( ( pos = birthd_rfc2425.find (' ') ) > 0 )
birthd_rfc2425.replace( pos, 1, "0" );
-
+
qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1());
safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() );
}
if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
VObject *org = safeAddProp( vcard, VCOrgProp );
safeAddPropValue( org, VCOrgNameProp, c.company() );
safeAddPropValue( org, VCOrgUnitProp, c.department() );
safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
}
// some values we have to export as custom fields
safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) );
safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
return vcard;
}
/*!
\internal
*/
static QDate convVCardDateToDate( const QString& datestr )
{
int monthPos = datestr.find('-');
int dayPos = datestr.find('-', monthPos+1 );
int sep_ignore = 1;
if ( monthPos == -1 || dayPos == -1 ) {
qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
// Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
if ( datestr.length() == 8 ){
monthPos = 4;
dayPos = 6;
sep_ignore = 0;
qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
} else {
return QDate();
}
}
int y = datestr.left( monthPos ).toInt();
int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
@@ -1343,311 +1343,320 @@ static OContact parseVObject( VObject *obj )
QCString name = vObjectTypeInfo( o );
if ( name == VCHomeProp )
c.setHomeWebpage( value );
else if ( name == VCWorkProp )
c.setBusinessWebpage( value );
}
}
else if ( name == VCOrgProp ) {
VObjectIterator nit;
initPropIterator( &nit, o );
while( moreIteration( &nit ) ) {
VObject *o = nextVObject( &nit );
QCString name = vObjectName( o );
QString value = vObjectStringZValue( o );
if ( name == VCOrgNameProp )
c.setCompany( value );
else if ( name == VCOrgUnitProp )
c.setDepartment( value );
else if ( name == VCOrgUnit2Prop )
c.setOffice( value );
}
}
else if ( name == VCTitleProp ) {
c.setJobTitle( value );
}
else if ( name == "X-Qtopia-Profession" ) {
c.setProfession( value );
}
else if ( name == "X-Qtopia-Manager" ) {
c.setManager( value );
}
else if ( name == "X-Qtopia-Assistant" ) {
c.setAssistant( value );
}
else if ( name == "X-Qtopia-Spouse" ) {
c.setSpouse( value );
}
else if ( name == "X-Qtopia-Gender" ) {
c.setGender( value );
}
else if ( name == "X-Qtopia-Anniversary" ) {
c.setAnniversary( TimeConversion::fromString( value ) );
}
else if ( name == "X-Qtopia-Nickname" ) {
c.setNickname( value );
}
else if ( name == "X-Qtopia-Children" ) {
c.setChildren( value );
- }
+ }
else if ( name == VCBirthDateProp ) {
// Reading Birthdate regarding RFC 2425 (5.8.4)
c.setBirthday( convVCardDateToDate( value ) );
-
+
}
#if 0
else {
printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
VObjectIterator nit;
initPropIterator( &nit, o );
while( moreIteration( &nit ) ) {
VObject *o = nextVObject( &nit );
QCString name = vObjectName( o );
QString value = vObjectStringZValue( o );
printf(" subprop: %s = %s\n", name.data(), value.latin1() );
}
}
#endif
}
c.setFileAs();
return c;
}
/*!
Writes the list of \a contacts as a set of VCards to the file \a filename.
*/
void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts)
{
QFileDirect f( filename.utf8().data() );
if ( !f.open( IO_WriteOnly ) ) {
qWarning("Unable to open vcard write");
return;
}
QValueList<OContact>::ConstIterator it;
for( it = contacts.begin(); it != contacts.end(); ++it ) {
VObject *obj = createVObject( *it );
writeVObject(f.directHandle() , obj );
cleanVObject( obj );
}
cleanStrTbl();
}
/*!
writes \a contact as a VCard to the file \a filename.
*/
void OContact::writeVCard( const QString &filename, const OContact &contact)
{
QFileDirect f( filename.utf8().data() );
if ( !f.open( IO_WriteOnly ) ) {
qWarning("Unable to open vcard write");
return;
}
VObject *obj = createVObject( contact );
writeVObject( f.directHandle() , obj );
cleanVObject( obj );
cleanStrTbl();
}
/*!
Returns the set of contacts read as VCards from the file \a filename.
*/
QValueList<OContact> OContact::readVCard( const QString &filename )
{
qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() );
VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
qDebug("vobject = %p", obj );
QValueList<OContact> contacts;
while ( obj ) {
- contacts.append( parseVObject( obj ) );
+ OContact con = parseVObject( obj );
+ /*
+ * if uid is 0 assign a new one
+ * this at least happens on
+ * Nokia6210
+ */
+ if ( con.uid() == 0 )
+ con.setUid( 1 );
+
+ contacts.append(con );
VObject *t = obj;
obj = nextVObjectInList(obj);
cleanVObject( t );
}
return contacts;
}
/*!
Returns TRUE if the contact matches the regular expression \a regexp.
Otherwise returns FALSE.
*/
bool OContact::match( const QString &regexp ) const
{
return match(QRegExp(regexp));
}
/*!
\overload
Returns TRUE if the contact matches the regular expression \a regexp.
Otherwise returns FALSE.
*/
bool OContact::match( const QRegExp &r ) const
{
bool match;
match = false;
QMap<int, QString>::ConstIterator it;
for ( it = mMap.begin(); it != mMap.end(); ++it ) {
if ( (*it).find( r ) > -1 ) {
match = true;
break;
}
}
return match;
}
QString OContact::toShortText() const
{
return ( fullName() );
}
QString OContact::type() const
{
return QString::fromLatin1( "OContact" );
}
// Definition is missing ! (se)
QMap<QString,QString> OContact::toExtraMap() const
{
qWarning ("Function not implemented: OContact::toExtraMap()");
QMap <QString,QString> useless;
return useless;
}
class QString OContact::recordField( int pos ) const
{
QStringList SLFIELDS = fields(); // ?? why this ? (se)
return SLFIELDS[pos];
}
// In future releases, we should store birthday and anniversary
-// internally as QDate instead of QString !
+// internally as QDate instead of QString !
// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
/*! \fn void OContact::setBirthday( const QDate& date )
Sets the birthday for the contact to \a date.
*/
void OContact::setBirthday( const QDate &v )
-{
+{
if ( ( !v.isNull() ) && ( v.isValid() ) )
replace( Qtopia::Birthday, TimeConversion::toString( v ) );
-
+
}
/*! \fn void OContact::setAnniversary( const QDate &date )
Sets the anniversary of the contact to \a date.
*/
void OContact::setAnniversary( const QDate &v )
{
if ( ( !v.isNull() ) && ( v.isValid() ) )
replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
}
/*! \fn QDate OContact::birthday() const
Returns the birthday of the contact.
*/
-QDate OContact::birthday() const
-{
+QDate OContact::birthday() const
+{
QString str = find( Qtopia::Birthday );
qWarning ("Birthday %s", str.latin1() );
if ( !str.isEmpty() )
return TimeConversion::fromString ( str );
else
return QDate();
}
/*! \fn QDate OContact::anniversary() const
Returns the anniversary of the contact.
*/
-QDate OContact::anniversary() const
-{
+QDate OContact::anniversary() const
+{
QDate empty;
QString str = find( Qtopia::Anniversary );
qWarning ("Anniversary %s", str.latin1() );
if ( !str.isEmpty() )
- return TimeConversion::fromString ( str );
+ return TimeConversion::fromString ( str );
else
return empty;
}
void OContact::insertEmail( const QString &v )
{
//qDebug("insertEmail %s", v.latin1());
QString e = v.simplifyWhiteSpace();
QString def = defaultEmail();
// if no default, set it as the default email and don't insert
if ( def.isEmpty() ) {
setDefaultEmail( e ); // will insert into the list for us
return;
}
// otherwise, insert assuming doesn't already exist
QString emailsStr = find( Qtopia::Emails );
if ( emailsStr.contains( e ))
return;
if ( !emailsStr.isEmpty() )
emailsStr += emailSeparator();
emailsStr += e;
replace( Qtopia::Emails, emailsStr );
}
void OContact::removeEmail( const QString &v )
{
QString e = v.simplifyWhiteSpace();
QString def = defaultEmail();
QString emailsStr = find( Qtopia::Emails );
QStringList emails = emailList();
-
+
// otherwise, must first contain it
if ( !emailsStr.contains( e ) )
return;
// remove it
//qDebug(" removing email from list %s", e.latin1());
emails.remove( e );
// reset the string
emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
replace( Qtopia::Emails, emailsStr );
// if default, then replace the default email with the first one
if ( def == e ) {
//qDebug("removeEmail is default; setting new default");
if ( !emails.count() )
clearEmails();
else // setDefaultEmail will remove e from the list
setDefaultEmail( emails.first() );
}
}
void OContact::clearEmails()
{
mMap.remove( Qtopia::DefaultEmail );
mMap.remove( Qtopia::Emails );
}
void OContact::setDefaultEmail( const QString &v )
{
QString e = v.simplifyWhiteSpace();
//qDebug("OContact::setDefaultEmail %s", e.latin1());
replace( Qtopia::DefaultEmail, e );
- if ( !e.isEmpty() )
+ if ( !e.isEmpty() )
insertEmail( e );
-
+
}
void OContact::insertEmails( const QStringList &v )
{
for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
insertEmail( *it );
}