summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp32
-rw-r--r--kabc/addressee.h4
-rw-r--r--kabc/phonenumber.cpp23
-rw-r--r--kabc/phonenumber.h2
-rw-r--r--kaddressbook/kabcore.cpp23
5 files changed, 80 insertions, 4 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 25c77f6..e571980 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -270,96 +270,128 @@ void Addressee::computeCsum(const QString &dev)
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
}
uint cs = getCsum4List(l);
// qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
setCsum( dev, QString::number (cs ));
}
void Addressee::mergeContact( const Addressee& ad )
{
detach();
if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
if ( !mData->birthday.isValid() )
if ( ad.mData->birthday.isValid())
mData->birthday = ad.mData->birthday;
if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
// pending:
// merging phonenumbers
// merging addresses
// merging emails;
// merging categories;
// merging custom;
// merging keys
qDebug("merge contact %s ", ad.uid().latin1());
setUid( ad.uid() );
setRevision( ad.revision() );
}
+// removes all emails but the first
+// needed by phone sync
+void Addressee::simplifyEmails()
+{
+ if ( mData->emails.count() == 0 ) return ;
+ QString email = mData->emails.first();
+ detach();
+ mData->emails.clear();
+ mData->emails.append( email );
+}
+
+void Addressee::simplifyPhoneNumbers()
+{
+ KABC::PhoneNumber::List removeNumbers;
+ KABC::PhoneNumber::List::Iterator phoneIter;
+ for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
+ ++phoneIter ) {
+ if ( ! ( *phoneIter ).simplifyNumber() )
+ removeNumbers.append( ( *phoneIter ) );
+ }
+ for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
+ ++phoneIter ) {
+ removePhoneNumber(( *phoneIter ));
+ }
+}
+void Addressee::simplifyPhoneNumberTypes()
+{
+ KABC::PhoneNumber::List::Iterator phoneIter;
+ for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
+ ++phoneIter )
+ ( *phoneIter ).simplifyType();
+}
void Addressee::removeID(const QString &prof)
{
detach();
mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
}
void Addressee::setID( const QString & prof , const QString & id )
{
detach();
mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
//qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
}
void Addressee::setTempSyncStat( int id )
{
if ( mData->mTempSyncStat == id ) return;
detach();
mData->mTempSyncStat = id;
}
int Addressee::tempSyncStat() const
{
return mData->mTempSyncStat;
}
QString Addressee::getID( const QString & prof)
{
return KIdManager::getId ( mData->mExternalId, prof );
}
void Addressee::setCsum( const QString & prof , const QString & id )
{
detach();
//qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
//qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
}
QString Addressee::getCsum( const QString & prof)
{
return KIdManager::getCsum ( mData->mExternalId, prof );
}
void Addressee::setIDStr( const QString & s )
{
detach();
mData->mExternalId = s;
}
QString Addressee::IDStr() const
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 8baa888..4cafa86 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -72,96 +72,100 @@ class Resource;
realName() returns a fully formatted name(). It uses formattedName, if set,
otherwise it constucts the name from the name fields. As fallback, if
nothing else is set it uses name().
name() is the NAME type of RFC2426. It can be used as internal name for the
data enty, but shouldn't be used for displaying the data to the user.
*/
class Addressee
{
friend QDataStream &operator<<( QDataStream &, const Addressee & );
friend QDataStream &operator>>( QDataStream &, Addressee & );
public:
typedef QValueList<Addressee> List;
/**
Construct an empty address book entry.
*/
Addressee();
~Addressee();
Addressee( const Addressee & );
Addressee &operator=( const Addressee & );
bool operator==( const Addressee & ) const;
bool operator!=( const Addressee & ) const;
// sync stuff
void setTempSyncStat(int id);
int tempSyncStat() const;
void setIDStr( const QString & );
QString IDStr() const;
void setID( const QString &, const QString & );
QString getID( const QString & );
void setCsum( const QString &, const QString & );
QString getCsum( const QString & );
void removeID(const QString &);
void computeCsum(const QString &dev);
ulong getCsum4List( const QStringList & attList);
/**
Return, if the address book entry is empty.
*/
bool isEmpty() const;
void setExternalUID( const QString &id );
QString externalUID() const;
void setOriginalExternalUID( const QString &id );
QString originalExternalUID() const;
void mergeContact( const Addressee& ad );
+ void simplifyEmails();
+ void simplifyPhoneNumbers();
+ void simplifyPhoneNumberTypes();
+
/**
Set unique identifier.
*/
void setUid( const QString &uid );
/**
Return unique identifier.
*/
QString uid() const;
/**
Return translated label for uid field.
*/
static QString uidLabel();
/**
Set name.
*/
void setName( const QString &name );
/**
Return name.
*/
QString name() const;
/**
Return translated label for name field.
*/
static QString nameLabel();
/**
Set formatted name.
*/
void setFormattedName( const QString &formattedName );
/**
Return formatted name.
*/
QString formattedName() const;
/**
Return translated label for formattedName field.
*/
static QString formattedNameLabel();
/**
Set family name.
*/
void setFamilyName( const QString &familyName );
/**
Return family name.
*/
QString familyName() const;
/**
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 7aeb2ee..e5abc0e 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -21,96 +21,119 @@
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <kapplication.h>
#include <klocale.h>
#include "phonenumber.h"
using namespace KABC;
PhoneNumber::PhoneNumber() :
mType( Home )
{
init();
}
PhoneNumber::PhoneNumber( const QString &number, int type ) :
mType( type ), mNumber( number )
{
init();
}
PhoneNumber::~PhoneNumber()
{
}
void PhoneNumber::init()
{
mId = KApplication::randomString( 8 );
}
bool PhoneNumber::operator==( const PhoneNumber &p ) const
{
if ( mNumber != p.mNumber ) return false;
if ( mType != p.mType ) return false;
return true;
}
bool PhoneNumber::operator!=( const PhoneNumber &p ) const
{
return !( p == *this );
}
+bool PhoneNumber::simplifyNumber()
+{
+ QString Number;
+ int i;
+ Number = mNumber.stripWhiteSpace ();
+ mNumber = "";
+ if ( Number.at(0) == '+' )
+ mNumber += "+";
+ for ( i = 0; i < Number.length(); ++i) {
+ if ( Number.at(i).isDigit() )
+ mNumber += Number.at(i);
+ }
+ return ( mNumber.length() > 0 );
+}
+// make cellphone compatible
+void PhoneNumber::simplifyType()
+{
+ if ( mType & Fax ) mType = Fax;
+ else if ( mType & Cell ) mType = Cell;
+ else if ( mType & Work ) mType = Work ;
+ else if ( mType & Home ) mType = Home;
+ else mType = Pref;
+}
void PhoneNumber::setId( const QString &id )
{
mId = id;
}
QString PhoneNumber::id() const
{
return mId;
}
void PhoneNumber::setNumber( const QString &number )
{
mNumber = number;
}
QString PhoneNumber::number() const
{
return mNumber;
}
void PhoneNumber::setType( int type )
{
mType = type;
}
int PhoneNumber::type() const
{
return mType;
}
QString PhoneNumber::typeLabel() const
{
QString label;
bool first = true;
TypeList list = typeList();
TypeList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
if ( first )
first = false;
}
}
return label;
}
diff --git a/kabc/phonenumber.h b/kabc/phonenumber.h
index 1df344f..410a52f 100644
--- a/kabc/phonenumber.h
+++ b/kabc/phonenumber.h
@@ -103,64 +103,66 @@ class PhoneNumber
QString id() const;
/**
Sets the number.
*/
void setNumber( const QString & );
/**
Returns the number.
*/
QString number() const;
/**
Sets the type. Multiple types can be specified by combining them by
a logical or.
*/
void setType( int );
/**
Returns the type. Can be a multiple types combined by a logical or.
*/
int type() const;
/**
Returns a translated string of all types the address has.
*/
QString typeLabel() const;
/**
Returns the translated label for phone number depending on its type.
*/
QString label() const;
/**
Returns a list of all available types
*/
static TypeList typeList();
/**
Returns the translated label for phone number type.
*/
static QString typeLabel( int type );
/**
Returns the translated label for phone number type.
@obsolete
*/
static QString label( int type );
+ bool simplifyNumber();
+ void simplifyType();
private:
void init();
QString mId;
int mType;
QString mNumber;
};
QDataStream &operator<<( QDataStream &, const PhoneNumber & );
QDataStream &operator>>( QDataStream &, PhoneNumber & );
}
#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index c5406bf..939296f 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -654,117 +654,132 @@ void KABCore::beamMySelf()
uids << a.uid();
beamVCard(uids);
} else {
KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
}
}
void KABCore::export2phone()
{
KAex2phonePrefs ex2phone;
ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
if ( !ex2phone.exec() ) {
return;
}
KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
KPimGlobalPrefs::instance()->mEx2PhoneConnection,
KPimGlobalPrefs::instance()->mEx2PhoneModel );
QStringList uids = mViewManager->selectedUids();
if ( uids.isEmpty() )
return;
#ifdef _WIN32_
QString fileName = locateLocal("tmp", "tempfile.vcf");
#else
QString fileName = "/tmp/kdepimtemp.vcf";
#endif
KABC::VCardConverter converter;
QString description;
QString datastream;
for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
KABC::Addressee a = mAddressBook->findByUid( *it );
if ( a.isEmpty() )
continue;
+ a.simplifyEmails();
+ a.simplifyPhoneNumbers();
+ a.simplifyPhoneNumberTypes();
if (description.isEmpty())
description = a.formattedName();
-
QString vcard;
+ QString vcardnew;
converter.addresseeToVCard( a, vcard );
int start = 0;
int next;
while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
int semi = vcard.find(";", next);
int dopp = vcard.find(":", next);
int sep;
if ( semi < dopp && semi >= 0 )
sep = semi ;
else
sep = dopp;
- datastream +=vcard.mid( start, next - start);
- datastream +=vcard.mid( next+5,sep -next -5 ).upper();
+ vcardnew +=vcard.mid( start, next - start);
+ vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
start = sep;
}
- datastream += vcard.mid( start,vcard.length() );
+ vcardnew += vcard.mid( start,vcard.length() );
+ vcard = "";
+ start = 0;
+ while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
+ int sep = vcardnew.find(":", next);
+ vcard +=vcardnew.mid( start, next - start+3);
+ start = sep;
+ }
+ vcard += vcardnew.mid( start,vcardnew.length() );
+ vcard.replace ( QRegExp(";;;") , "" );
+ vcard.replace ( QRegExp(";;") , "" );
+ datastream += vcard;
+
}
QFile outFile(fileName);
if ( outFile.open(IO_WriteOnly) ) {
datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
QTextStream t( &outFile ); // use a text stream
t.setEncoding( QTextStream::UnicodeUTF8 );
t <<datastream;
outFile.close();
if ( PhoneAccess::writeToPhone( fileName ) )
qDebug("Export okay ");
else
qDebug("Error export contacts ");
} else {
qDebug("Error open temp file ");
return;
}
#if 0
setCaption( i18n("Writing to phone..."));
if ( PhoneFormat::writeToPhone( cal ) )
setCaption( i18n("Export to phone successful!"));
else
setCaption( i18n("Error exporting to phone!"));
#endif
}
void KABCore::beamVCard()
{
QStringList uids = mViewManager->selectedUids();
if ( !uids.isEmpty() )
beamVCard( uids );
}
void KABCore::beamVCard(const QStringList& uids)
{
/*US
QString beamFilename;
Opie::OPimContact c;
if ( actionPersonal->isOn() ) {
beamFilename = addressbookPersonalVCardName();
if ( !QFile::exists( beamFilename ) )
return; // can't beam a non-existent file
Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,