summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/service/gsmmisc.c4
-rw-r--r--gammu/emb/common/service/gsmpbk.c17
-rw-r--r--gammu/emb/gammu/gammu.c2
-rw-r--r--kabc/addressbook.cpp148
-rw-r--r--kabc/addressbook.h2
-rw-r--r--kabc/addressee.cpp46
-rw-r--r--kabc/addressee.h1
-rw-r--r--kabc/phonenumber.cpp4
-rw-r--r--kaddressbook/kabcore.cpp86
-rw-r--r--libkdepim/ksyncprefsdialog.cpp11
10 files changed, 217 insertions, 104 deletions
diff --git a/gammu/emb/common/service/gsmmisc.c b/gammu/emb/common/service/gsmmisc.c
index 6959a22..1c6ec8b 100644
--- a/gammu/emb/common/service/gsmmisc.c
+++ b/gammu/emb/common/service/gsmmisc.c
@@ -193,29 +193,29 @@ void ReadVCALDateTime(char *Buffer, GSM_DateTime *dt)
dt->Hour = atoi(hour);
dt->Minute = atoi(minute);
dt->Second = atoi(second);
/* FIXME */
dt->Timezone = 0;
}
void SaveVCALText(char *Buffer, int *Length, char *Text, char *Start)
{
char buffer[1000];
if (UnicodeLength(Text) != 0) {
- EncodeUTF8QuotedPrintable(buffer,Text);
+ EncodeUTF8(buffer,Text);
if (UnicodeLength(Text)==strlen(buffer)) {
*Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,DecodeUnicodeString(Text),13,10);
} else {
- *Length+=sprintf(Buffer+(*Length), "%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:%s%c%c",Start,buffer,13,10);
+ *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,buffer,13,10);
}
}
}
bool ReadVCALText(char *Buffer, char *Start, char *Value)
{
unsigned char buff[200];
Value[0] = 0x00;
Value[1] = 0x00;
strcpy(buff,Start);
diff --git a/gammu/emb/common/service/gsmpbk.c b/gammu/emb/common/service/gsmpbk.c
index 05e5cb9..f7cf7d7 100644
--- a/gammu/emb/common/service/gsmpbk.c
+++ b/gammu/emb/common/service/gsmpbk.c
@@ -122,72 +122,73 @@ void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool heade
}
for (i=0; i < pbk->EntriesNum; i++) {
if (i != Name) {
ignore = false;
switch(pbk->Entries[i].EntryType) {
case PBK_Text_Name :
case PBK_Date :
case PBK_Caller_Group :
ignore = true;
break;
case PBK_Number_General :
*Length+=sprintf(Buffer+(*Length),"TEL");
- if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
+ (*Length)+=sprintf(Buffer+(*Length),";PREF");
break;
case PBK_Number_Mobile :
*Length+=sprintf(Buffer+(*Length),"TEL");
- if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
+ //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
*Length+=sprintf(Buffer+(*Length),";CELL");
break;
case PBK_Number_Work :
*Length+=sprintf(Buffer+(*Length),"TEL");
- if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
- *Length+=sprintf(Buffer+(*Length),";WORK;VOICE");
+ //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
+ *Length+=sprintf(Buffer+(*Length),";WORK");
break;
case PBK_Number_Fax :
*Length+=sprintf(Buffer+(*Length),"TEL");
- if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
+ //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
*Length+=sprintf(Buffer+(*Length),";FAX");
break;
case PBK_Number_Home :
*Length+=sprintf(Buffer+(*Length),"TEL");
- if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
- *Length+=sprintf(Buffer+(*Length),";HOME;VOICE");
+ //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
+ *Length+=sprintf(Buffer+(*Length),";HOME");
break;
case PBK_Text_Note :
*Length+=sprintf(Buffer+(*Length),"NOTE");
break;
case PBK_Text_Postal :
/* Don't ask why. Nokia phones save postal address
* double - once like LABEL, second like ADR
*/
- SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "LABEL");
+ //SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "LABEL");
*Length+=sprintf(Buffer+(*Length),"ADR");
break;
case PBK_Text_Email :
case PBK_Text_Email2 :
*Length+=sprintf(Buffer+(*Length),"EMAIL");
break;
case PBK_Text_URL :
*Length+=sprintf(Buffer+(*Length),"URL");
break;
default :
ignore = true;
break;
}
if (!ignore) {
SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "");
}
}
}
+ *Length+=sprintf(Buffer+(*Length), "X-KADDRESSBOOK-X-ExternalID:%d%c%c",pbk->Location,13,10);
if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10);
}
}
GSM_Error GSM_DecodeVCARD(unsigned char *Buffer, int *Pos, GSM_MemoryEntry *Pbk, GSM_VCardVersion Version)
{
unsigned char Line[2000],Buff[2000];
int Level = 0;
Buff[0] = 0;
Pbk->EntriesNum = 0;
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c
index 8db9afb..684e67c 100644
--- a/gammu/emb/gammu/gammu.c
+++ b/gammu/emb/gammu/gammu.c
@@ -4677,25 +4677,25 @@ static void Restore(int argc, char *argv[])
}
GSM_Init(true);
DoRestore = false;
if (Backup.PhonePhonebook[0] != NULL) {
MemStatus.MemoryType = MEM_ME;
error=Phone->GetMemoryStatus(&s, &MemStatus);
if (error==ERR_NONE) {
max = 0;
while (Backup.PhonePhonebook[max]!=NULL) max++;
printmsgerr("%i entries in backup file\n",max);
- if (answer_yes("Restore phone phonebook")) DoRestore = true;
+ /* LR if (answer_yes("Restore phone phonebook")) */DoRestore = true;
}
}
if (DoRestore) {
used = 0;
for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
Pbk.MemoryType = MEM_ME;
Pbk.Location = i + 1;
Pbk.EntriesNum = 0;
if (used<max) {
if (Backup.PhonePhonebook[used]->Location == Pbk.Location) {
Pbk = *Backup.PhonePhonebook[used];
used++;
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index d037d2f..ad0f702 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -332,35 +332,34 @@ void AddressBook::init(const QString &config, const QString &family )
AddressBook::~AddressBook()
{
delete d->mConfig; d->mConfig = 0;
delete d->mManager; d->mManager = 0;
//US delete d->mErrorHandler; d->mErrorHandler = 0;
delete d; d = 0;
}
bool AddressBook::load()
{
-
clear();
-
KRES::Manager<Resource>::ActiveIterator it;
bool ok = true;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
if ( !(*it)->load() ) {
- error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
+ qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
ok = false;
+ } else {
+ qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
}
-
// mark all addressees as unchanged
Addressee::List::Iterator addrIt;
for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
(*addrIt).setChanged( false );
QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
if ( !id.isEmpty() ) {
//qDebug("setId aa %s ", id.latin1());
(*addrIt).setIDStr(id );
}
}
blockLSEchange = true;
return ok;
@@ -395,45 +394,117 @@ void AddressBook::export2File( QString fileName )
if ( !(*it).IDStr().isEmpty() ) {
(*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
}
KABC::VCardConverter converter;
QString vcard;
//Resource *resource() const;
converter.addresseeToVCard( *it, vcard, version );
t << vcard << "\r\n";
}
t << "\r\n\r\n";
outFile.close();
}
+// if QStringList uids is empty, all are exported
+bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
+{
+ KABC::VCardConverter converter;
+ QString datastream;
+ Iterator it;
+ bool all = uids.isEmpty();
+ for ( it = begin(); it != end(); ++it ) {
+ // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
+ if ( ! all ) {
+ if ( ! ( uids.contains((*it).uid() ) ))
+ continue;
+ }
+ KABC::Addressee a = ( *it );
+ if ( a.isEmpty() )
+ continue;
+ a.simplifyEmails();
+ a.simplifyPhoneNumbers();
+ a.simplifyPhoneNumberTypes();
+ a.simplifyAddresses();
+
+ 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;
+ vcardnew +=vcard.mid( start, next - start);
+ vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
+ start = sep;
+ }
+ 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;
+ t << "\r\n\r\n";
+ outFile.close();
+
+ } else {
+ qDebug("Error open temp file ");
+ return false;
+ }
+ return true;
+
+}
void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
{
if ( removeOld )
setUntagged();
KABC::Addressee::List list;
QFile file( fileName );
file.open( IO_ReadOnly );
QByteArray rawData = file.readAll();
file.close();
QString data;
if ( replaceLabel ) {
data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
data.replace ( QRegExp("LABEL") , "ADR" );
data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
} else
data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
KABC::VCardTool tool;
list = tool.parseVCards( data );
KABC::Addressee::List::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
+ QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
+ if ( !id.isEmpty() )
+ (*it).setIDStr(id );
(*it).setResource( 0 );
if ( replaceLabel )
(*it).removeVoice();
if ( removeOld )
(*it).setTagged( true );
insertAddressee( (*it), false, true );
}
if ( removeOld )
removeUntagged();
}
void AddressBook::setUntagged()
{
@@ -471,74 +542,125 @@ void AddressBook::smplifyAddressees()
}
}
void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
QString id = (*ait).IDStr();
(*ait).setIDStr( ":");
(*ait).setExternalUID( id );
(*ait).setOriginalExternalUID( id );
if ( isPreSync )
(*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
- else
+ else {
(*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+ (*ait).setID( currentSyncDevice,id );
+
+ }
+ }
+}
+void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
+{
+
+ setUntagged();
+ KABC::Addressee::List list;
+ QFile file( fileName );
+ file.open( IO_ReadOnly );
+ QByteArray rawData = file.readAll();
+ file.close();
+ QString data;
+
+ data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
+ KABC::VCardTool tool;
+ list = tool.parseVCards( data );
+ KABC::Addressee::List::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ Iterator ait;
+ for ( ait = begin(); ait != end(); ++ait ) {
+ if ( !(*ait).tagged() ) {
+ if ( (*ait).containsAdr(*it)) {
+ (*ait).setTagged(true);
+ QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
+ (*it).setIDStr( ":");
+ (*it).setID( currentSyncDevice,id );
+ (*it).setExternalUID( id );
+ (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+ (*it).setUid( ( (*ait).uid() ));
+ break;
+ }
+ }
+
+ }
+ if ( ait == end() )
+ qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
+ }
+ clear();
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ insertAddressee( (*it) );
}
}
+
bool AddressBook::saveABphone( QString fileName )
{
- smplifyAddressees();
+ //smplifyAddressees();
qDebug("saveABphone:: saving AB... ");
- if ( ! saveAB() )
+ if ( ! export2PhoneFormat( QStringList() ,fileName ) )
return false;
qDebug("saveABphone:: writing to phone... ");
if ( !PhoneAccess::writeToPhone( fileName) ) {
return false;
}
qDebug("saveABphone:: re-reading from phone... ");
if ( !PhoneAccess::readFromPhone( fileName) ) {
return false;
}
- qDebug("reloading phone book... ");
- if ( !load() )
- return false;
return true;
}
bool AddressBook::saveAB()
{
bool ok = true;
deleteRemovedAddressees();
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
if ( !(*ait).IDStr().isEmpty() ) {
(*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
}
}
KRES::Manager<Resource>::ActiveIterator it;
KRES::Manager<Resource> *manager = d->mManager;
+ qDebug("SaveAB::saving..." );
for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
+ qDebug("SaveAB::checking resource..." );
+ if ( (*it)->readOnly() )
+ qDebug("readonly." );
+ if ( (*it)->isOpen() )
+ qDebug("open" );
+
if ( !(*it)->readOnly() && (*it)->isOpen() ) {
Ticket *ticket = requestSaveTicket( *it );
-// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
+ qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
if ( !ticket ) {
- error( i18n( "Unable to save to resource '%1'. It is locked." )
+ qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
.arg( (*it)->resourceName() ) );
return false;
}
//if ( !save( ticket ) )
if ( ticket->resource() ) {
if ( ! ticket->resource()->save( ticket ) )
ok = false;
+ else
+ qDebug("StdAddressBook::saved '%s'", ticket->resource()->resourceName().latin1() );
+
} else
ok = false;
}
}
return ok;
}
AddressBook::Iterator AddressBook::begin()
{
Iterator it = Iterator();
it.d->mIt = d->mAddressees.begin();
@@ -584,25 +706,25 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
KRES::Manager<Resource>::ActiveIterator it;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
if ( (*it) == resource ) {
if ( (*it)->readOnly() || !(*it)->isOpen() )
return 0;
else
return (*it)->requestSaveTicket();
}
}
return 0;
}
-
+//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
{
if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
//qDebug("block insert ");
return;
}
//qDebug("inserting.... %s ",a.uid().latin1() );
bool found = false;
Addressee::List::Iterator it;
for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index cc755d1..df9048b 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -137,27 +137,29 @@ class AddressBook : public QObject
/**
Save address book. The address book is saved to the file, the Ticket
object has been requested for by @ref requestSaveTicket().
@param ticket a ticket object returned by @ref requestSaveTicket()
*/
bool save( Ticket *ticket );
bool saveAB( );
bool saveABphone( QString fileName );
void smplifyAddressees();
void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
void export2File( QString fileName );
+ bool export2PhoneFormat( QStringList uids ,QString fileName );
void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
void setUntagged();
void removeUntagged();
+ void findNewExtIds( QString fileName, QString currentSyncDevice );
/**
Returns a iterator for first entry of address book.
*/
Iterator begin();
/**
Returns a const iterator for first entry of address book.
*/
ConstIterator begin() const;
/**
Returns a iterator for first entry of address book.
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 607ae26..548305a 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -294,62 +294,102 @@ void Addressee::mergeContact( const Addressee& ad )
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 ;
+ PhoneNumber::List phoneAD = phoneNumbers();
+ PhoneNumber::List::Iterator phoneItAD;
+ bool found = false;
+ for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
+
+ }
// pending:
// merging phonenumbers
// merging addresses
// merging emails;
// merging categories;
// merging custom;
// merging keys
- qDebug("merge contact %s ", ad.uid().latin1());
+ //qDebug("merge contact %s ", ad.uid().latin1());
setUid( ad.uid() );
setRevision( ad.revision() );
}
bool Addressee::removeVoice()
{
PhoneNumber::List phoneN = phoneNumbers();
PhoneNumber::List::Iterator phoneIt;
bool found = false;
for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
if ((*phoneIt).type() - PhoneNumber::Voice ) {
(*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
insertPhoneNumber( (*phoneIt) );
found = true;
}
}
}
return found;
}
+
+bool Addressee::containsAdr(const Addressee& ad )
+{
+ if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
+ if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
+ if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
+ if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
+ if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
+ if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
+ if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
+
+ // compare phone numbers
+ PhoneNumber::List phoneN = ad.phoneNumbers();
+ PhoneNumber::List::Iterator phoneIt;
+ bool found = false;
+ for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
+ bool found = false;
+ PhoneNumber::List phoneL = ad.phoneNumbers();
+ PhoneNumber::List::Iterator phoneItL;
+ for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
+ if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
+ found = true;
+ break;
+ }
+ }
+ if ( ! found )
+ return false;
+ }
+ return true;
+
+}
void Addressee::simplifyAddresses()
{
- if ( mData->addresses.count() < 3 ) return ;
+ int max = 2;
+ if ( mData->url.isValid() )
+ max = 1;
+ if ( mData->addresses.count() <= max ) return ;
int count = 0;
Address::List list;
Address::List::Iterator it;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
- if ( count > 1 )
+ if ( count >= max )
list.append( *it );
++count;
}
for( it = list.begin(); it != list.end(); ++it ) {
removeAddress( (*it) );
}
}
// removes all emails but the first
// needed by phone sync
void Addressee::simplifyEmails()
{
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0aa2c51..03138f6 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -113,24 +113,25 @@ class Addressee
*/
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 simplifyAddresses();
void simplifyPhoneNumbers();
void simplifyPhoneNumberTypes();
bool removeVoice();
+ bool containsAdr(const Addressee& addr );
/**
Set unique identifier.
*/
void setUid( const QString &uid );
/**
Return unique identifier.
*/
QString uid() const;
/**
Return translated label for uid field.
*/
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index e5abc0e..6e94c7e 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -63,28 +63,26 @@ bool PhoneNumber::operator==( const PhoneNumber &p ) const
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() )
+ if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' )
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;
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index a7967cb..cd261f6 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -176,26 +176,26 @@ class KAex2phonePrefs : public QDialog
temphb = new QHBox( this );
new QLabel( i18n("I/O device: "), temphb );
mPhoneDevice = new QLineEdit( temphb);
lay->addWidget( temphb );
temphb = new QHBox( this );
new QLabel( i18n("Connection: "), temphb );
mPhoneConnection = new QLineEdit( temphb);
lay->addWidget( temphb );
temphb = new QHBox( this );
new QLabel( i18n("Model(opt.): "), temphb );
mPhoneModel = new QLineEdit( temphb);
lay->addWidget( temphb );
- mWriteToSim= new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
- lay->addWidget( mWriteToSim );
+ // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
+ // lay->addWidget( mWriteToSim );
lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
lab->setAlignment (AlignHCenter );
QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
lay->addWidget( ok );
QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
lay->addWidget( cancel );
connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
resize( 220, 240 );
}
@@ -685,92 +685,37 @@ void KABCore::export2phone()
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");
+ QString fileName = locateLocal("tmp", "phonefile.vcf");
#else
- QString fileName = "/tmp/kdepimtemp.vcf";
+ QString fileName = "/tmp/phonefile.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();
- a.simplifyAddresses();
-
- 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;
- vcardnew +=vcard.mid( start, next - start);
- vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
- start = sep;
- }
- 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 ");
+ if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) )
return;
- }
-
+
+ if ( PhoneAccess::writeToPhone( fileName ) )
+ qDebug("Export okay ");
+ else
+ qDebug("Error export contacts ");
+
#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
}
@@ -2834,24 +2779,25 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource)
return syncPhone();
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
AddressBook abLocal( resource,"syncContact");
bool syncOK = false;
if ( abLocal.load() ) {
qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
if ( syncOK ) {
if ( syncManager->mWriteBackFile ) {
+ abLocal.removeSyncAddressees( false );
abLocal.saveAB();
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();
return syncOK;
}
void KABCore::message( QString m )
@@ -2866,35 +2812,37 @@ bool KABCore::syncPhone()
QString fileName;
#ifdef _WIN32_
fileName = locateLocal("tmp", "phonefile.vcf");
#else
fileName = "/tmp/phonefile.vcf";
#endif
if ( !PhoneAccess::readFromPhone( fileName) ) {
message(i18n("Phone access failed!"));
return false;
}
AddressBook abLocal( fileName,"syncContact");
bool syncOK = false;
- if ( abLocal.load() ) {
+ {
+ abLocal.importFromFile( fileName );
qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
abLocal.preparePhoneSync( mCurrentSyncDevice, true );
abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
if ( syncOK ) {
if ( syncManager->mWriteBackFile ) {
+ abLocal.removeSyncAddressees( true );
abLocal.saveABphone( fileName );
- abLocal.preparePhoneSync( mCurrentSyncDevice, false );
- abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
+ abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
+ //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();
return syncOK;
}
void KABCore::getFile( bool success )
{
if ( ! success ) {
diff --git a/libkdepim/ksyncprefsdialog.cpp b/libkdepim/ksyncprefsdialog.cpp
index 84cc448..cf8f996 100644
--- a/libkdepim/ksyncprefsdialog.cpp
+++ b/libkdepim/ksyncprefsdialog.cpp
@@ -191,25 +191,25 @@ void KSyncPrefsDialog::setupSyncAlgTab()
mIsLocal = new QRadioButton ( i18n("Local file"), gr );
mIsPi = new QRadioButton ( i18n("Pi-Sync ( direct Kx/Pi to Kx/Pi sync )"), gr );
connect (mIsPi, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) );
mIsNotLocal = new QRadioButton ( i18n("Remote file (w down/upload command)"), gr );
connect (mIsLocal, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) );
mIsPhone = new QRadioButton ( i18n("Mobile device (cell phone)"), gr );
connect (mIsPhone, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) );
phoneWidget = new QVBox( topFrame);
topLayout->addMultiCellWidget(phoneWidget, iii,iii,0,1);
++iii;
- mWriteContactToSIM= new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget );
+ mWriteContactToSIM = 0;//new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget );
QHBox* temphb = new QHBox( phoneWidget );
new QLabel( i18n("I/O device: "), temphb );
mPhoneDevice = new QLineEdit( temphb);
button = new QPushButton( i18n("Help..."), temphb );
connect ( button, SIGNAL( clicked()), this, SLOT ( helpDevice() ) );
temphb = new QHBox( phoneWidget );
new QLabel( i18n("Connection: "), temphb );
mPhoneConnection = new QLineEdit( temphb);
button = new QPushButton( i18n("Help..."), temphb );
connect ( button, SIGNAL( clicked()), this, SLOT ( helpConnection() ) );
@@ -404,25 +404,26 @@ void KSyncPrefsDialog::profileChanged( int item )
mRemoteFile->setText(prof->getRemoteFileName()) ;
mRemotePrecommandAB->setText(prof->getPreSyncCommandAB());
mRemotePostcommandAB->setText(prof->getPostSyncCommandAB());
mLocalTempFileAB->setText(prof->getLocalTempFileAB());
mRemoteFileAB->setText(prof->getRemoteFileNameAB()) ;
mRemotePrecommandPWM->setText(prof->getPreSyncCommandPWM());
mRemotePostcommandPWM->setText(prof->getPostSyncCommandPWM());
mLocalTempFilePWM->setText(prof->getLocalTempFilePWM());
mRemoteFilePWM->setText(prof->getRemoteFileNamePWM()) ;
- mWriteContactToSIM->setChecked( prof->getWriteContactToSIM());
+ if ( mWriteContactToSIM )
+ mWriteContactToSIM->setChecked( prof->getWriteContactToSIM());
mPhoneDevice->setText(prof->getPhoneDevice());
mPhoneConnection->setText(prof->getPhoneConnection());
mPhoneModel->setText(prof->getPhoneModel());
mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync());
mAskForPreferences->setChecked( prof->getAskForPreferences());
mWriteBackExisting->setChecked( prof->getWriteBackExisting() );
mWriteBackFile->setChecked( prof->getWriteBackFile());
mIncludeInRing->setChecked( prof->getIncludeInRingSync() );
mIncludeInRingAB->setChecked( prof->getIncludeInRingSyncAB() );
mIncludeInRingPWM->setChecked( prof->getIncludeInRingSyncPWM() );
mWriteBackFuture->setChecked( prof->getWriteBackFuture());
@@ -571,26 +572,26 @@ void KSyncPrefsDialog::saveProfile()
prof->setWriteBackExisting(mWriteBackExisting->isChecked() );
prof->setWriteBackFile( mWriteBackFile->isChecked());
prof->setIncludeInRingSync( mIncludeInRing->isChecked() );
prof->setIncludeInRingSyncAB( mIncludeInRingAB->isChecked() );
prof->setIncludeInRingSyncPWM( mIncludeInRingPWM->isChecked() );
int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ;
prof->setSyncPrefs( syncprefs);
prof->setIsLocalFileSync( mIsLocal->isChecked() );
prof->setIsPhoneSync( mIsPhone->isChecked() );
prof->setIsPiSync( mIsPi->isChecked() );
prof->setWriteBackFuture(mWriteBackFuture->isChecked());
prof->setWriteBackFutureWeeks(mWriteBackFutureWeeks->value());
-
- prof->setWriteContactToSIM(mWriteContactToSIM->isChecked());
+ if ( mWriteContactToSIM )
+ prof->setWriteContactToSIM(mWriteContactToSIM->isChecked());
prof->setPhoneDevice( mPhoneDevice->text() );
prof->setPhoneConnection( mPhoneConnection->text() );
prof->setPhoneModel( mPhoneModel->text() );
}
}
void KSyncPrefsDialog::insertProfiles()
{
int curItem = mProfileBox->currentItem();
mProfileBox->blockSignals( true );
@@ -706,25 +707,25 @@ void KSyncPrefsDialog::helpDevice()
"???\n(bluetooth device address)\n";
#else
hint += "/dev/ircomm\n(Irda)\n"
"/dev/ttyS0\n(first serial port)\n"
"/dev/ttyUSB0\n(first device usb port)\n"
"???\n(bluetooth device address)\n";
#endif
KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));
}
void KSyncPrefsDialog::helpModel()
{
- QString hint = i18n("Leave empty or\ninsert name of phone model:\n");
+ QString hint = i18n("Recommended: Leave empty!\n(Such that model can\nbe auto detected)\nOr insert name of model:\n");
hint += "E.g. for Nokia 6310i:\n6310i\nAlso possible:\nobex\nfor Obex connection";
KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));
}
void KSyncPrefsDialog::helpConnection()
{
QString hint = i18n("Insert kind of connection,e.g.:\n");
hint += "irda | Nokia FBUS over infrared\n"
"irdaat | AT commands infrared\n(for Siemens/Sony-Erricsson)\n"
"irdaobex | set also model as obex\n"
"fbus | Nokia FBUS2 serial\n";
KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));