summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp36
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.h7
2 files changed, 36 insertions, 7 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index 43e530a..5bb21c7 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -3,97 +3,99 @@
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
* VCard Backend for the OPIE-Contact Database.
*/
#include <opie2/private/vobject_p.h>
/* OPIE */
#include <opie2/ocontactaccessbackend_vcard.h>
#include <opie2/odebug.h>
#include <qpe/timeconversion.h>
//FIXME: Hack to allow direct access to FILE* fh. Rewrite this!
#define protected public
#include <qfile.h>
#undef protected
namespace Opie {
OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ):
m_dirty( false ),
- m_file( filename )
+ m_file( filename ),
+ version_major( 1 ),
+ version_minor( 0 )
{
load();
}
bool OPimContactAccessBackend_VCard::load ()
{
m_map.clear();
m_dirty = false;
VObject* obj = 0l;
if ( QFile::exists(m_file) ){
obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
if ( !obj )
return false;
}else{
odebug << "File \"" << m_file << "\" not found !" << oendl;
return false;
}
while ( obj ) {
OPimContact con = parseVObject( obj );
/*
* if uid is 0 assign a new one
* this at least happens on
* Nokia6210
*/
if ( con.uid() == 0 ){
con.setUid( 1 );
owarn << "assigned new uid " << con.uid() << "" << oendl;
}
m_map.insert( con.uid(), con );
VObject *t = obj;
obj = nextVObjectInList(obj);
cleanVObject( t );
}
return true;
}
bool OPimContactAccessBackend_VCard::reload()
{
return load();
}
bool OPimContactAccessBackend_VCard::save()
@@ -141,236 +143,254 @@ bool OPimContactAccessBackend_VCard::remove ( int uid )
m_map.remove( uid );
m_dirty = true;
return true;
}
bool OPimContactAccessBackend_VCard::replace ( const OPimContact &contact )
{
m_map.replace( contact.uid(), contact );
m_dirty = true;
return true;
}
OPimContact OPimContactAccessBackend_VCard::find ( int uid ) const
{
return m_map[uid];
}
QArray<int> OPimContactAccessBackend_VCard::allRecords() const
{
QArray<int> ar( m_map.count() );
QMap<int, OPimContact>::ConstIterator it;
int i = 0;
for ( it = m_map.begin(); it != m_map.end(); ++it ) {
ar[i] = it.key();
i++;
}
return ar;
}
const uint OPimContactAccessBackend_VCard::querySettings()
{
return 0; // No search possible
}
bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const
{
return false; // No search possible, therefore all settings invalid ;)
}
bool OPimContactAccessBackend_VCard::wasChangedExternally()
{
return false; // Don't expect concurrent access
}
// *** Private stuff ***
OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
{
OPimContact c;
-
VObjectIterator it;
initPropIterator( &it, obj );
while( moreIteration( &it ) ) {
VObject *o = nextVObject( &it );
QCString name = vObjectName( o );
QString value = QString::fromUtf8( vObjectStringZValue( o ) );
- odebug << "(1)Read: %s" << QString( value ).latin1() << oendl;
- if ( name == VCNameProp ) {
+ odebug << "(1)Read: " << name << " " << QString( value ).latin1() << oendl;
+ if ( name == VCVersionProp ) {
+
+ odebug << "Version: " << value << oendl;
+ QStringList version = QStringList::split( ".", value );
+ version_major = version[0].toUInt();
+ version_minor = version[1].toUInt();
+ odebug << "Major: "<< version_major << " Minor: " << version_minor << oendl;
+
+ }
+ else if ( name == VCNameProp ) {
VObjectIterator nit;
initPropIterator( &nit, o );
while( moreIteration( &nit ) ) {
VObject *o = nextVObject( &nit );
QCString name = vObjectTypeInfo( o );
QString value = QString::fromUtf8( vObjectStringZValue( o ) );
- odebug << "(2)Read: %s" << value.latin1() << oendl;
+ odebug << "Nametype is: "<< name << " Value: " << value.latin1() << oendl;
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 );
+ QCString name = vObjectTypeInfo( o );
QString value = QString::fromUtf8( vObjectStringZValue( o ) );
+ odebug << "AddressType is: "<< name << " Value: " << value.latin1() << oendl;
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 );
+ odebug << "Telephonetype is: "<< name << " Value: " << value.latin1() << oendl;
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 if ( name.left( 2 ) == "X-" || name.left( 2 ) == "x-" )
+ ; // Ignore
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;
+ odebug << "value %s %d" << value.data() << type << oendl;
+
if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|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) && (type & (CELL|WORK) ) != (CELL|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 = QString::fromUtf8( vObjectStringZValue( o ) );
bool valid = TRUE;
VObjectIterator nit;
initPropIterator( &nit, o );
while( moreIteration( &nit ) ) {
VObject *o = nextVObject( &nit );
QCString name = vObjectTypeInfo( o );
+ odebug << "Emailtype is: "<< name << " Value: " << value.latin1() << oendl;
if ( name != VCInternetProp && name != VCHomeProp &&
name != VCWorkProp &&
- name != VCPreferredProp )
+ name != VCPreferredProp &&
+ name.left( 2 ) != "X-" && name.left( 2 ) != "x-" ){
// ### preffered should map to default email
valid = FALSE;
+ odebug << "Email was detected as invalid!" << oendl;
+ }
}
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 = QString::fromUtf8( 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" ) {
@@ -537,49 +557,51 @@ QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) co
int pos = 0;
while ( ( pos = str_rfc2425.find (' ') ) > 0 )
str_rfc2425.replace( pos, 1, "0" );
return str_rfc2425;
}
QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr )
{
int monthPos = datestr.find('-');
int dayPos = datestr.find('-', monthPos+1 );
int sep_ignore = 1;
if ( monthPos == -1 || dayPos == -1 ) {
odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
// Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
if ( datestr.length() == 8 ){
monthPos = 4;
dayPos = 6;
sep_ignore = 0;
odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
} 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();
odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
QDate date ( y,m,d );
return date;
}
VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value )
{
VObject *ret = 0;
if ( o && !value.isEmpty() )
ret = addPropValue( o, prop, value.utf8() );
return ret;
}
VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop)
{
VObject *ret = 0;
if ( o )
ret = addProp( o, prop );
return ret;
}
+
+
}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
index 1faf747..b734530 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
@@ -30,53 +30,60 @@
* VCard Backend for the OPIE-Contact Database.
*/
#ifndef __OCONTACTACCESSBACKEND_VCARD_H_
#define __OCONTACTACCESSBACKEND_VCARD_H_
#include <opie2/opimcontact.h>
#include <opie2/ocontactaccessbackend.h>
class VObject;
namespace Opie {
/**
* This is the vCard 2.1 implementation of the Contact Storage
* @see OPimContactAccessBackend_XML
* @see OPimAccessBackend
*/
class OPimContactAccessBackend_VCard : public OPimContactAccessBackend {
public:
OPimContactAccessBackend_VCard ( const QString& appname, const QString& filename = QString::null );
bool load ();
bool reload();
bool save();
void clear ();
bool add ( const OPimContact& newcontact );
bool remove ( int uid );
bool replace ( const OPimContact& contact );
OPimContact find ( int uid ) const;
QArray<int> allRecords() const;
const uint querySettings();
bool hasQuerySettings (uint querySettings) const;
bool wasChangedExternally();
private:
OPimContact parseVObject( VObject* obj );
VObject* createVObject( const OPimContact& c );
QString convDateToVCardDate( const QDate& c ) const;
QDate convVCardDateToDate( const QString& datestr );
VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value );
VObject *safeAddProp( VObject* o, const char* prop);
bool m_dirty : 1;
QString m_file;
QMap<int, OPimContact> m_map;
+
+ /**
+ * Version of parsed VCard
+ */
+ uint version_major;
+ uint version_minor;
+
};
}
#endif