summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ocontact.cpp625
-rw-r--r--libopie2/opiepim/ocontact.h42
2 files changed, 40 insertions, 627 deletions
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index b0f0d7f..917eb0a 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -1,50 +1,48 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#define QTOPIA_INTERNAL_CONTACT_MRE
#include "ocontact.h"
-#include "../../library/backend/vobject_p.h"
-#include "../../library/backend/qfiledirect_p.h"
#include <qpe/stringutil.h>
#include <qpe/timeconversion.h>
#include <qpe/timestring.h>
#include <qobject.h>
#include <qregexp.h>
#include <qstylesheet.h>
#include <qfileinfo.h>
#include <qmap.h>
#include <stdio.h>
/*!
\class Contact contact.h
\brief The Contact class holds the data of an address book entry.
This data includes information the name of the person, contact
information, and business information such as deparment and job title.
\ingroup qtopiaemb
\ingroup qtopiadesktop
*/
@@ -566,48 +564,54 @@ QString OContact::toRichText() const
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().isValid() ){
str = TimeString::numberDateString( birthday() );
text += "<b>" + QObject::tr("Birthday: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
}
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>";
+ if ( categoryNames().count() ){
+ text += "<b>" + QObject::tr( "Category:") + "</b> ";
+ text += categoryNames().join(", ");
+ text += "<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 );
}
@@ -795,51 +799,54 @@ void OContact::setFileAs()
void OContact::save( QString &buf ) const
{
static const QStringList SLFIELDS = fields();
// I'm expecting "<Contact " in front of this...
for ( QMap<int, QString>::ConstIterator it = mMap.begin();
it != mMap.end(); ++it ) {
const QString &value = it.data();
int key = it.key();
if ( !value.isEmpty() ) {
if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
continue;
key -= Qtopia::AddressCategory+1;
buf += SLFIELDS[key];
buf += "=\"" + Qtopia::escapeString(value) + "\" ";
}
}
buf += customToXml();
if ( categories().count() > 0 )
buf += "Categories=\"" + idsToString( categories() ) + "\" ";
buf += "Uid=\"" + QString::number( uid() ) + "\" ";
// You need to close this yourself
}
+
/*!
\internal
Returns the list of fields belonging to a contact
+ Never change order of this list ! It has to be regarding
+ enum AddressBookFields !!
*/
QStringList OContact::fields()
{
QStringList list;
list.append( "Title" ); // Not Used!
list.append( "FirstName" );
list.append( "MiddleName" );
list.append( "LastName" );
list.append( "Suffix" );
list.append( "FileAs" );
list.append( "JobTitle" );
list.append( "Department" );
list.append( "Company" );
list.append( "BusinessPhone" );
list.append( "BusinessFax" );
list.append( "BusinessMobile" );
list.append( "DefaultEmail" );
list.append( "Emails" );
list.append( "HomePhone" );
list.append( "HomeFax" );
@@ -857,655 +864,68 @@ QStringList OContact::fields()
list.append( "Profession" );
list.append( "Assistant" );
list.append( "Manager" );
list.append( "HomeStreet" );
list.append( "HomeCity" );
list.append( "HomeState" );
list.append( "HomeZip" );
list.append( "HomeCountry" );
list.append( "HomeWebPage" );
list.append( "Spouse" );
list.append( "Gender" );
list.append( "Birthday" );
list.append( "Anniversary" );
list.append( "Nickname" );
list.append( "Children" );
list.append( "Notes" );
list.append( "Groups" );
return list;
}
-/*!
- \internal
- Returns a translated list of field names for a contact.
-*/
-QStringList OContact::trfields()
-{
- QStringList list;
-
- list.append( QObject::tr( "Name Title") );
- list.append( QObject::tr( "First Name" ) );
- list.append( QObject::tr( "Middle Name" ) );
- list.append( QObject::tr( "Last Name" ) );
- list.append( QObject::tr( "Suffix" ) );
- list.append( QObject::tr( "File As" ) );
-
- list.append( QObject::tr( "Job Title" ) );
- list.append( QObject::tr( "Department" ) );
- list.append( QObject::tr( "Company" ) );
- list.append( QObject::tr( "Business Phone" ) );
- list.append( QObject::tr( "Business Fax" ) );
- list.append( QObject::tr( "Business Mobile" ) );
-
- list.append( QObject::tr( "Default Email" ) );
- list.append( QObject::tr( "Emails" ) );
-
- list.append( QObject::tr( "Home Phone" ) );
- list.append( QObject::tr( "Home Fax" ) );
- list.append( QObject::tr( "Home Mobile" ) );
-
- list.append( QObject::tr( "Business Street" ) );
- list.append( QObject::tr( "Business City" ) );
- list.append( QObject::tr( "Business State" ) );
- list.append( QObject::tr( "Business Zip" ) );
- list.append( QObject::tr( "Business Country" ) );
- list.append( QObject::tr( "Business Pager" ) );
- list.append( QObject::tr( "Business WebPage" ) );
-
- list.append( QObject::tr( "Office" ) );
- list.append( QObject::tr( "Profession" ) );
- list.append( QObject::tr( "Assistant" ) );
- list.append( QObject::tr( "Manager" ) );
-
- list.append( QObject::tr( "Home Street" ) );
- list.append( QObject::tr( "Home City" ) );
- list.append( QObject::tr( "Home State" ) );
- list.append( QObject::tr( "Home Zip" ) );
- list.append( QObject::tr( "Home Country" ) );
- list.append( QObject::tr( "Home Web Page" ) );
-
- list.append( QObject::tr( "Spouse" ) );
- list.append( QObject::tr( "Gender" ) );
- list.append( QObject::tr( "Birthday" ) );
- list.append( QObject::tr( "Anniversary" ) );
- list.append( QObject::tr( "Nickname" ) );
- list.append( QObject::tr( "Children" ) );
-
- list.append( QObject::tr( "Notes" ) );
- list.append( QObject::tr( "Groups" ) );
-
- return list;
-}
-
-/*!
- \internal
- Returns an untranslated list of field names for a contact.
-*/
-QStringList OContact::untrfields()
-{
- QStringList list;
-
- list.append( "Name Title" );
- list.append( "First Name" );
- list.append( "Middle Name" );
- list.append( "Last Name" );
- list.append( "Suffix" );
- list.append( "File As" );
-
- list.append( "Job Title" );
- list.append( "Department" );
- list.append( "Company" );
- list.append( "Business Phone" );
- list.append( "Business Fax" );
- list.append( "Business Mobile" );
-
- list.append( "Default Email" );
- list.append( "Emails" );
-
- list.append( "Home Phone" );
- list.append( "Home Fax" );
- list.append( "Home Mobile" );
-
- list.append( "Business Street" );
- list.append( "Business City" );
- list.append( "Business State" );
- list.append( "Business Zip" );
- list.append( "Business Country" );
- list.append( "Business Pager" );
- list.append( "Business WebPage" );
-
- list.append( "Office" );
- list.append( "Profession" );
- list.append( "Assistant" );
- list.append( "Manager" );
-
- list.append( "Home Street" );
- list.append( "Home City" );
- list.append( "Home State" );
- list.append( "Home Zip" );
- list.append( "Home Country" );
- list.append( "Home Web Page" );
-
- list.append( "Spouse" );
- list.append( "Gender" );
- list.append( "Birthday" );
- list.append( "Anniversary" );
- list.append( "Nickname" );
- list.append( "Children" );
-
- list.append( "Notes" );
- list.append( "Groups" );
-
- return list;
-}
/*!
Sets the list of email address for contact to those contained in \a str.
Email address should be separated by ';'s.
*/
void OContact::setEmails( const QString &str )
{
replace( Qtopia::Emails, str );
if ( str.isEmpty() )
setDefaultEmail( QString::null );
}
/*!
Sets the list of children for the contact to those contained in \a str.
*/
void OContact::setChildren( const QString &str )
{
replace( Qtopia::Children, str );
}
-// vcard conversion code
-/*!
- \internal
-*/
-static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
-{
- VObject *ret = 0;
- 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().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() ) ); :SX
- 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();
- 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;
- else if ( name == VCVoiceProp )
- type |= VOICE;
- else if ( name == VCCellularProp )
- type |= CELL;
- else if ( name == VCFaxProp )
- type |= FAX;
- else if ( name == VCPagerProp )
- type |= PAGER;
- else if ( name == VCPreferredProp )
- ;
- else
- type |= UNKNOWN;
- }
- if ( (type & UNKNOWN) != UNKNOWN ) {
- if ( ( type & (HOME|WORK) ) == 0 ) // default
- type |= HOME;
- if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
- type |= VOICE;
-
- if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
- c.setHomePhone( value );
- if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
- c.setHomeFax( value );
- if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
- c.setHomeMobile( value );
- if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
- c.setBusinessPhone( value );
- if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
- c.setBusinessFax( value );
- if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
- c.setBusinessMobile( value );
- if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
- c.setBusinessPager( value );
- }
- }
- else if ( name == VCEmailAddressProp ) {
- QString email = vObjectStringZValue( o );
- bool valid = TRUE;
- VObjectIterator nit;
- initPropIterator( &nit, o );
- while( moreIteration( &nit ) ) {
- VObject *o = nextVObject( &nit );
- QCString name = vObjectTypeInfo( o );
- if ( name != VCInternetProp && name != VCHomeProp &&
- name != VCWorkProp &&
- name != VCPreferredProp )
- // ### preffered should map to default email
- valid = FALSE;
- }
- if ( valid ) {
- c.insertEmail( email );
- }
- }
- else if ( name == VCURLProp ) {
- VObjectIterator nit;
- initPropIterator( &nit, o );
- while( moreIteration( &nit ) ) {
- VObject *o = nextVObject( &nit );
- 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 ) ); :SX
- }
- 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 ) {
- 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 );
- qWarning("assigned new uid %d",con.uid() );
- }
-
- 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;
}
@@ -1521,64 +941,78 @@ QString OContact::toShortText() const
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 !
// 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.
+ Sets the birthday for the contact to \a date. If date is null
+ the current stored date will be removed.
*/
void OContact::setBirthday( const QDate &v )
{
- if ( ( !v.isNull() ) && ( v.isValid() ) )
+ if ( v.isNull() ){
+ qWarning( "Remove Birthday");
+ replace( Qtopia::Birthday, QString::null );
+ return;
+ }
+
+ if ( v.isValid() )
replace( Qtopia::Birthday, TimeConversion::toString( v ) );
}
/*! \fn void OContact::setAnniversary( const QDate &date )
- Sets the anniversary of the contact to \a date.
+ Sets the anniversary of the contact to \a date. If date is
+ null, the current stored date will be removed.
*/
void OContact::setAnniversary( const QDate &v )
{
- if ( ( !v.isNull() ) && ( v.isValid() ) )
+ if ( v.isNull() ){
+ qWarning( "Remove Anniversary");
+ replace( Qtopia::Anniversary, QString::null );
+ return;
+ }
+
+ if ( v.isValid() )
replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
}
/*! \fn QDate OContact::birthday() const
Returns the birthday of the contact.
*/
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 empty;
QString str = find( Qtopia::Anniversary );
@@ -1641,24 +1075,29 @@ void OContact::removeEmail( const QString &v )
}
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() )
insertEmail( e );
}
void OContact::insertEmails( const QStringList &v )
{
for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
insertEmail( *it );
}
+void OContact::setUid( int i )
+{
+ OPimRecord::setUid(i);
+ replace( Qtopia::AddressUid , QString::number(i));
+}
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h
index 9643e8b..d97af1c 100644
--- a/libopie2/opiepim/ocontact.h
+++ b/libopie2/opiepim/ocontact.h
@@ -13,71 +13,58 @@
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef __OCONTACT_H__
#define __OCONTACT_H__
#include <opie/opimrecord.h>
#include <qpe/recordfields.h>
#include <qdatetime.h>
#include <qstringlist.h>
#if defined(QPC_TEMPLATEDLL)
// MOC_SKIP_BEGIN
QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
// MOC_SKIP_END
#endif
-class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se)
- /* Stefan das ist eine forward declaration
- * dann machst du in der private section
- * ContactPrivate *d;
- *
- * und wenn du bei Opie1.1 was hinzufuegen moechtest
- * packst du es in ContactPrivate damit Opie
- * binaer kompatibel bleibt
- * -zecke
- */
+class ContactPrivate;
+
class QPC_EXPORT OContact : public OPimRecord
{
friend class DataSet;
public:
OContact();
OContact( const QMap<int, QString> &fromMap );
virtual ~OContact();
- /* VCARD stuff should vanish! -zecke */
- static void writeVCard( const QString &filename, const QValueList<OContact> &contacts);
- static void writeVCard( const QString &filename, const OContact &c );
- static QValueList<OContact> readVCard( const QString &filename );
-
enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
/*
* do we need to inline them
* if yes do we need to inline them this way?
* -zecke
*/
void setTitle( const QString &v ) { replace( Qtopia::Title, v ); }
void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); }
void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); }
void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); }
void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); }
void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); }
void setFileAs();
// default email address
void setDefaultEmail( const QString &v );
// inserts email to list and ensure's doesn't already exist
void insertEmail( const QString &v );
void removeEmail( const QString &v );
void clearEmails();
void insertEmails( const QStringList &v );
// home
@@ -185,80 +172,67 @@ public:
* Street
* City, State Zip
* Country
*/
QString displayBusinessAddress() const;
//personal
QString spouse() const { return find( Qtopia::Spouse ); }
QString gender() const { return find( Qtopia::Gender ); }
QDate birthday() const;
QDate anniversary() const;
QString nickname() const { return find( Qtopia::Nickname ); }
QString children() const { return find( Qtopia::Children ); }
QStringList childrenList() const;
// other
QString notes() const { return find( Qtopia::Notes ); }
QString groups() const { return find( Qtopia::Groups ); }
QStringList groupList() const;
// // custom
// const QString &customField( const QString &key )
// { return find( Custom- + key ); }
- static QStringList fields();
- static QStringList trfields();
- static QStringList untrfields();
QString toRichText() const;
QMap<int, QString> toMap() const;
QString field( int key ) const { return find( key ); }
- // journaling...
- /* do we still need them? Stefan your backend takes care of these -zecke */
- void saveJournal( journal_action action, const QString &key = QString::null );
- void save( QString &buf ) const;
-
- /* we shouldn't inline this one -zecke */
- void setUid( int i )
-{ OPimRecord::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); }
+ void setUid( int i );
QString toShortText()const;
QString OContact::type()const;
QMap<QString,QString> OContact::toExtraMap() const;
class QString OContact::recordField(int) const;
// Why private ? (eilers,se)
QString emailSeparator() const { return " "; }
// the emails should be seperated by a comma
void setEmails( const QString &v );
QString emails() const { return find( Qtopia::Emails ); }
private:
- /* I do not like friends ;)
- * besides that I think we do not need them
- * anymore -zecke
- */
- friend class AbEditor;
- friend class AbTable;
- friend class AddressBookAccessPrivate;
- friend class XMLIO;
+ // The XML-Backend needs some access to the private functions
+ friend class OContactAccessBackend_XML;
void insert( int key, const QString &value );
void replace( int key, const QString &value );
QString find( int key ) const;
+ static QStringList fields();
+
+ void save( QString &buf ) const;
QString displayAddress( const QString &street,
const QString &city,
const QString &state,
const QString &zip,
const QString &country ) const;
QMap<int, QString> mMap;
ContactPrivate *d;
};
#endif