summaryrefslogtreecommitdiff
path: root/library/backend/contact.cpp
Side-by-side diff
Diffstat (limited to 'library/backend/contact.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/backend/contact.cpp79
1 files changed, 47 insertions, 32 deletions
diff --git a/library/backend/contact.cpp b/library/backend/contact.cpp
index a5f10ab..b10b19a 100644
--- a/library/backend/contact.cpp
+++ b/library/backend/contact.cpp
@@ -1,44 +1,46 @@
/**********************************************************************
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of 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 "contact.h"
#include "vobject_p.h"
#include "qfiledirect_p.h"
#include <qpe/stringutil.h>
#include <qpe/timeconversion.h>
#include <qobject.h>
#include <qregexp.h>
#include <qstylesheet.h>
#include <qfileinfo.h>
#include <stdio.h>
Qtopia::UidGen Contact::sUidGen( Qtopia::UidGen::Qtopia );
Contact::Contact()
: Record(), mMap(), d( 0 )
{
}
Contact::Contact( const QMap<int, QString> &fromMap ) :
Record(), mMap( fromMap ), d( 0 )
{
@@ -365,141 +367,149 @@ void Contact::save( QString &buf ) const
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
}
QStringList Contact::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( "HomeStreet" );
- list.append( "HomeCity" );
- list.append( "HomeState" );
- list.append( "HomeZip" );
- list.append( "HomeCountry" );
list.append( "HomePhone" );
list.append( "HomeFax" );
list.append( "HomeMobile" );
- list.append( "HomeWebPage" );
- list.append( "Company" );
list.append( "BusinessStreet" );
list.append( "BusinessCity" );
list.append( "BusinessState" );
list.append( "BusinessZip" );
list.append( "BusinessCountry" );
+ list.append( "BusinessPager" );
list.append( "BusinessWebPage" );
- list.append( "JobTitle" );
- list.append( "Department" );
+
list.append( "Office" );
- list.append( "BusinessPhone" );
- list.append( "BusinessFax" );
- list.append( "BusinessMobile" );
- list.append( "BusinessPager" );
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;
}
QStringList Contact::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 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 Phone" ) );
list.append( QObject::tr( "Home Fax" ) );
list.append( QObject::tr( "Home Mobile" ) );
- list.append( QObject::tr( "Home Web Page" ) );
- list.append( QObject::tr( "Company" ) );
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( "Job Title" ) );
- list.append( QObject::tr( "Department" ) );
+
list.append( QObject::tr( "Office" ) );
- list.append( QObject::tr( "Business Phone" ) );
- list.append( QObject::tr( "Business Fax" ) );
- list.append( QObject::tr( "Business Mobile" ) );
- list.append( QObject::tr( "Business Pager" ) );
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;
}
void Contact::setEmails( const QString &v )
{
replace( Qtopia::Emails, v );
if ( v.isEmpty() )
setDefaultEmail( QString::null );
}
void Contact::setChildren( const QString &v )
{
replace( Qtopia::Children, v );
}
// vcard conversion code
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;
}
@@ -608,49 +618,49 @@ static VObject *createVObject( const Contact &c )
safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
return vcard;
}
static Contact parseVObject( VObject *obj )
{
Contact c;
bool haveDefaultEmail = FALSE;
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 = vObjectName( o );
+ 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 ) ) {
@@ -681,119 +691,119 @@ static Contact parseVObject( VObject *obj )
} 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 = vObjectName( o );
+ 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 = vObjectName( o );
+ QCString name = vObjectTypeInfo( o );
if ( name != VCInternetProp && name != VCHomeProp &&
name != VCWorkProp &&
name != VCPreferredProp )
// ### preffered should map to default email
valid = FALSE;
}
if ( valid ) {
if ( haveDefaultEmail ) {
QString str = c.emails();
if ( !str.isEmpty() )
str += ","+email;
c.setEmails( str );
} else {
c.setDefaultEmail( email );
}
}
}
else if ( name == VCURLProp ) {
VObjectIterator nit;
initPropIterator( &nit, o );
while( moreIteration( &nit ) ) {
VObject *o = nextVObject( &nit );
- QCString name = vObjectName( o );
+ 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 );
}
@@ -873,37 +883,42 @@ void Contact::writeVCard( const QString &filename, const Contact &contact)
cleanStrTbl();
}
QValueList<Contact> Contact::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<Contact> contacts;
while ( obj ) {
contacts.append( parseVObject( obj ) );
VObject *t = obj;
obj = nextVObjectInList(obj);
cleanVObject( t );
}
return contacts;
}
+bool Contact::match( const QString &regexp ) const
+{
+ return match(QRegExp(regexp));
+}
+
bool Contact::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;
}