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.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp
index 734f5a2..bf27d0f 100644
--- a/libopie/pim/ocontact.cpp
+++ b/libopie/pim/ocontact.cpp
@@ -478,198 +478,198 @@ QString OContact::toRichText() const
if ( !(value = businessCountry()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
// home address
if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
!homeZip().isEmpty() || !homeCountry().isEmpty() ) {
text += "<br>";
text += QObject::tr( "<b>Home Address:</b>" );
text += "<br>";
}
if ( !(value = homeStreet()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
state = homeState();
if ( !(value = homeCity()).isEmpty() ) {
text += Qtopia::escapeString(value);
if ( !state.isEmpty() )
text += ", " + Qtopia::escapeString(state);
text += "<br>";
} else if (!state.isEmpty())
text += Qtopia::escapeString(state) + "<br>";
if ( !(value = homeZip()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
if ( !(value = homeCountry()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
// the others...
QString str;
str = emails();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Email Addresses: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = homePhone();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Home Phone: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = homeFax();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Home Fax: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = homeMobile();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Home Mobile: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = homeWebpage();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Home Web Page: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = businessWebpage();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Business Web Page: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = office();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Office: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = businessPhone();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Business Phone: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = businessFax();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Business Fax: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = businessMobile();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Business Mobile: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = businessPager();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Business Pager: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = profession();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Profession: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = assistant();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Assistant: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = manager();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Manager: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = gender();
if ( !str.isEmpty() && str.toInt() != 0 ) {
if ( str.toInt() == 1 )
str = QObject::tr( "Male" );
else if ( str.toInt() == 2 )
str = QObject::tr( "Female" );
text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>";
}
str = spouse();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Spouse: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
- if ( !birthday().isNull() ){
+ if ( !birthday().isValid() ){
str = TimeString::numberDateString( birthday() );
text += "<b>" + QObject::tr("Birthday: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
}
- if ( !anniversary().isNull() ){
+ if ( !anniversary().isValid() ){
str = TimeString::numberDateString( anniversary() );
text += "<b>" + QObject::tr("Anniversary: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
}
str = nickname();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Nickname: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
// notes last
if ( (value = notes()) ) {
QRegExp reg("\n");
//QString tmp = Qtopia::escapeString(value);
QString tmp = QStyleSheet::convertFromPlainText(value);
//tmp.replace( reg, "<br>" );
text += "<br>" + tmp + "<br>";
}
return text;
}
/*!
\internal
*/
void OContact::insert( int key, const QString &v )
{
QString value = v.stripWhiteSpace();
if ( value.isEmpty() )
mMap.remove( key );
else
mMap.insert( key, value );
}
/*!
\internal
*/
void OContact::replace( int key, const QString & v )
{
QString value = v.stripWhiteSpace();
if ( value.isEmpty() )
mMap.remove( key );
else
mMap.replace( key, value );
}
/*!
\internal
*/
QString OContact::find( int key ) const
{
return mMap[key];
}
/*!
\internal
*/
QString OContact::displayAddress( const QString &street,
const QString &city,
const QString &state,
const QString &zip,
const QString &country ) const
{
QString s = street;
if ( !street.isEmpty() )
s+= "\n";
s += city;
if ( !city.isEmpty() && !state.isEmpty() )
s += ", ";
s += state;
if ( !state.isEmpty() && !zip.isEmpty() )
s += " ";
s += zip;
if ( !country.isEmpty() && !s.isEmpty() )
s += "\n";
s += country;
return s;
}
/*!
\internal
*/
QString OContact::displayBusinessAddress() const
{
return displayAddress( businessStreet(), businessCity(),
businessState(), businessZip(),
businessCountry() );
}
/*!
\internal
*/
QString OContact::displayHomeAddress() const
{
return displayAddress( homeStreet(), homeCity(),
homeState(), homeZip(),
homeCountry() );
@@ -1030,236 +1030,249 @@ static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QSt
if ( o && !value.isEmpty() )
ret = addPropValue( o, prop, value.latin1() );
return ret;
}
/*!
\internal
*/
static inline VObject *safeAddProp( VObject *o, const char *prop)
{
VObject *ret = 0;
if ( o )
ret = addProp( o, prop );
return ret;
}
/*!
\internal
*/
static VObject *createVObject( const OContact &c )
{
VObject *vcard = newVObject( VCCardProp );
safeAddPropValue( vcard, VCVersionProp, "2.1" );
safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
// full name
safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
// name properties
VObject *name = safeAddProp( vcard, VCNameProp );
safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
safeAddPropValue( name, VCGivenNameProp, c.firstName() );
safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
safeAddPropValue( name, VCNamePrefixesProp, c.title() );
safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
// home properties
VObject *home_adr= safeAddProp( vcard, VCAdrProp );
safeAddProp( home_adr, VCHomeProp );
safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
safeAddProp( home_phone, VCHomeProp );
home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
safeAddProp( home_phone, VCHomeProp );
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().isNull() ){
- QString birthd_rfc2425 = c.birthday().year() + QString( "-" ) + c.birthday().month() + QString( "-" ) + c.birthday().day();
+ if ( !c.birthday().isValid() ){
+ QString birthd_rfc2425 = QString("%1-%2-%3")
+ .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 );
- return QDate();
+ // Ok.. Outlook is violating ISO 8601, therefore we will try to read their format ( YYYYMMDD )
+ monthPos = 4;
+ dayPos = 6;
+ sep_ignore = 0;
+ qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
}
int y = datestr.left( monthPos ).toInt();
- int m = datestr.mid( monthPos+1, dayPos - monthPos - 1 ).toInt();
- int d = datestr.mid( dayPos+1 ).toInt();
- QDate date ( y,m,d );
+ int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
+ int d = datestr.mid( dayPos + sep_ignore ).toInt();
qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos);
+ QDate date ( y,m,d );
return date;
}
static OContact parseVObject( VObject *obj )
{
OContact c;
VObjectIterator it;
initPropIterator( &it, obj );
while( moreIteration( &it ) ) {
VObject *o = nextVObject( &it );
QCString name = vObjectName( o );
QCString value = vObjectStringZValue( o );
if ( name == VCNameProp ) {
VObjectIterator nit;
initPropIterator( &nit, o );
while( moreIteration( &nit ) ) {
VObject *o = nextVObject( &nit );
QCString name = vObjectTypeInfo( o );
QString value = vObjectStringZValue( o );
if ( name == VCNamePrefixesProp )
c.setTitle( value );
else if ( name == VCNameSuffixesProp )
c.setSuffix( value );
else if ( name == VCFamilyNameProp )
c.setLastName( value );
else if ( name == VCGivenNameProp )
c.setFirstName( value );
else if ( name == VCAdditionalNamesProp )
c.setMiddleName( value );
}
}
else if ( name == VCAdrProp ) {
bool work = TRUE; // default address is work address
QString street;
QString city;
QString region;
QString postal;
QString country;
VObjectIterator nit;
initPropIterator( &nit, o );
while( moreIteration( &nit ) ) {
VObject *o = nextVObject( &nit );
QCString name = vObjectName( o );
QString value = vObjectStringZValue( o );
if ( name == VCHomeProp )
work = FALSE;
else if ( name == VCWorkProp )
work = TRUE;
else if ( name == VCStreetAddressProp )
street = value;
else if ( name == VCCityProp )
city = value;
else if ( name == VCRegionProp )
region = value;
else if ( name == VCPostalCodeProp )
postal = value;
else if ( name == VCCountryNameProp )
country = value;
}
if ( work ) {
c.setBusinessStreet( street );
c.setBusinessCity( city );
c.setBusinessCountry( country );
c.setBusinessZip( postal );
c.setBusinessState( region );
} else {
c.setHomeStreet( street );
c.setHomeCity( city );
c.setHomeCountry( country );
c.setHomeZip( postal );
c.setHomeState( region );
}
}
else if ( name == VCTelephoneProp ) {
enum {
HOME = 0x01,
WORK = 0x02,
VOICE = 0x04,
CELL = 0x08,
FAX = 0x10,
PAGER = 0x20,
UNKNOWN = 0x80
};
int type = 0;
VObjectIterator nit;
initPropIterator( &nit, o );
while( moreIteration( &nit ) ) {
VObject *o = nextVObject( &nit );
QCString name = vObjectTypeInfo( o );
if ( name == VCHomeProp )
type |= HOME;
else if ( name == VCWorkProp )
type |= WORK;