summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-10 16:00:04 (UTC)
committer zautrix <zautrix>2004-10-10 16:00:04 (UTC)
commitee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a (patch) (side-by-side diff)
tree1d908bfc23b8a49d43a58bbeadd82c4e08faeff6
parent213a9d993e5a4751b64e18320cfbebb000681d13 (diff)
downloadkdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.zip
kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.gz
kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.bz2
many phone AB sync fixes
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
@@ -157,101 +157,101 @@ void GSM_IdentifyFileFormat(GSM_File *File)
File->Type = GSM_File_Image_JPG;
} else if (memcmp(File->Buffer, "MThd",4)==0) {
File->Type = GSM_File_Sound_MIDI;
} else if (File->Buffer[0] == 0x00 && File->Buffer[1] == 0x02) {
File->Type = GSM_File_Sound_NRT;
}
}
}
void SaveVCALDateTime(char *Buffer, int *Length, GSM_DateTime *Date, char *Start)
{
if (Start != NULL) {
*Length+=sprintf(Buffer+(*Length), "%s:",Start);
}
*Length+=sprintf(Buffer+(*Length), "%04d%02d%02dT%02d%02d%02d%c%c",
Date->Year, Date->Month, Date->Day,
Date->Hour, Date->Minute, Date->Second,13,10);
}
void ReadVCALDateTime(char *Buffer, GSM_DateTime *dt)
{
char year[5]="", month[3]="", day[3]="", hour[3]="", minute[3]="", second[3]="";
memset(dt,0,sizeof(dt));
strncpy(year, Buffer, 4);
strncpy(month, Buffer+4, 2);
strncpy(day, Buffer+6, 2);
strncpy(hour, Buffer+9, 2);
strncpy(minute, Buffer+11, 2);
strncpy(second, Buffer+13, 2);
/* FIXME: Should check ranges... */
dt->Year = atoi(year);
dt->Month = atoi(month);
dt->Day = atoi(day);
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);
strcat(buff,":");
if (!strncmp(Buffer,buff,strlen(buff))) {
EncodeUnicode(Value,Buffer+strlen(Start)+1,strlen(Buffer)-(strlen(Start)+1));
dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
return true;
}
/* SE T68i */
strcpy(buff,Start);
strcat(buff,";ENCODING=QUOTED-PRINTABLE:");
if (!strncmp(Buffer,buff,strlen(buff))) {
DecodeUTF8QuotedPrintable(Value,Buffer+strlen(Start)+27,strlen(Buffer)-(strlen(Start)+27));
dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
return true;
}
strcpy(buff,Start);
strcat(buff,";CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:");
if (!strncmp(Buffer,buff,strlen(buff))) {
DecodeUTF8QuotedPrintable(Value,Buffer+strlen(Start)+41,strlen(Buffer)-(strlen(Start)+41));
dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
return true;
}
strcpy(buff,Start);
strcat(buff,";CHARSET=UTF-8:");
if (!strncmp(Buffer,buff,strlen(buff))) {
DecodeUTF8(Value,Buffer+strlen(Start)+15,strlen(Buffer)-(strlen(Start)+15));
dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
return true;
}
strcpy(buff,Start);
strcat(buff,";CHARSET=UTF-7:");
if (!strncmp(Buffer,buff,strlen(buff))) {
DecodeUTF7(Value,Buffer+strlen(Start)+15,strlen(Buffer)-(strlen(Start)+15));
dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
return true;
}
return false;
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
@@ -86,144 +86,145 @@ void GSM_PhonebookFindDefaultNameNumberGroup(GSM_MemoryEntry *entry, int *Name,
if ((*Name) == -1) {
for (i = 0; i < entry->EntriesNum; i++) {
if (entry->Entries[i].EntryType != PBK_Text_LastName) continue;
*Name = i;
break;
}
}
if ((*Name) == -1) {
for (i = 0; i < entry->EntriesNum; i++) {
if (entry->Entries[i].EntryType != PBK_Text_FirstName) continue;
*Name = i;
break;
}
}
}
void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool header, GSM_VCardVersion Version)
{
int Name, Number, Group, i;
bool ignore;
GSM_PhonebookFindDefaultNameNumberGroup(pbk, &Name, &Number, &Group);
if (Version == Nokia_VCard10) {
if (header) *Length+=sprintf(Buffer+(*Length),"BEGIN:VCARD%c%c",13,10);
if (Name != -1) {
*Length+=sprintf(Buffer+(*Length),"N:%s%c%c",DecodeUnicodeString(pbk->Entries[Name].Text),13,10);
}
if (Number != -1) {
*Length +=sprintf(Buffer+(*Length),"TEL:%s%c%c",DecodeUnicodeString(pbk->Entries[Number].Text),13,10);
}
if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10);
} else if (Version == Nokia_VCard21) {
if (header) *Length+=sprintf(Buffer+(*Length),"BEGIN:VCARD%c%cVERSION:2.1%c%c",13,10,13,10);
if (Name != -1) {
SaveVCALText(Buffer, Length, pbk->Entries[Name].Text, "N");
}
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;
while (1) {
MyGetLine(Buffer, Pos, Line, strlen(Buffer));
if (strlen(Line) == 0) break;
switch (Level) {
case 0:
if (strstr(Line,"BEGIN:VCARD")) Level = 1;
break;
case 1:
if (strstr(Line,"END:VCARD")) {
if (Pbk->EntriesNum == 0) return ERR_EMPTY;
return ERR_NONE;
}
if (ReadVCALText(Line, "N", Buff)) {
CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Name;
Pbk->EntriesNum++;
}
if (ReadVCALText(Line, "TEL", Buff) ||
ReadVCALText(Line, "TEL;VOICE", Buff) ||
ReadVCALText(Line, "TEL;PREF", Buff) ||
ReadVCALText(Line, "TEL;PREF;VOICE", Buff)) {
CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_General;
Pbk->EntriesNum++;
}
if (ReadVCALText(Line, "TEL;CELL", Buff) ||
ReadVCALText(Line, "TEL;CELL;VOICE", Buff) ||
ReadVCALText(Line, "TEL;PREF;CELL", Buff) ||
ReadVCALText(Line, "TEL;PREF;CELL;VOICE", Buff)) {
CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Mobile;
Pbk->EntriesNum++;
}
if (ReadVCALText(Line, "TEL;WORK", Buff) ||
ReadVCALText(Line, "TEL;PREF;WORK", Buff) ||
ReadVCALText(Line, "TEL;WORK;VOICE", Buff) ||
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
@@ -4641,97 +4641,97 @@ static void Restore(int argc, char *argv[])
GSM_CalendarEntry Calendar;
GSM_Bitmap Bitmap;
GSM_Ringtone Ringtone;
GSM_MemoryEntry Pbk;
GSM_MemoryStatus MemStatus;
GSM_ToDoEntry ToDo;
GSM_ToDoStatus ToDoStatus;
GSM_Profile Profile;
GSM_MultiWAPSettings Settings;
GSM_GPRSAccessPoint GPRSPoint;
GSM_WAPBookmark Bookmark;
int i, used, max = 0;
bool Past = true;
bool Found, DoRestore;
error=GSM_ReadBackupFile(argv[2],&Backup);
if (error!=ERR_NOTIMPLEMENTED) {
Print_Error(error);
} else {
printmsgerr("WARNING: Some data not read from file. It can be damaged or restoring some settings from this file format not implemented (maybe higher Gammu required ?)\n");
}
signal(SIGINT, interrupt);
printmsgerr("Press Ctrl+C to break...\n");
if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI);
if (Backup.Creator[0]!=0) printmsgerr("File created by : %s\n",Backup.Creator);
if (Backup.MD5Calculated[0]!=0) {
dbgprintf("\"%s\"\n",Backup.MD5Original);
dbgprintf("\"%s\"\n",Backup.MD5Calculated);
if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) {
if (!answer_yes("Checksum in backup file do not match. Continue")) return;
}
}
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++;
dbgprintf("Location %i\n",Pbk.Location);
if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk);
}
}
if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk);
Print_Error(error);
printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree));
if (gshutdown) {
GSM_Terminate();
exit(0);
}
}
printmsgerr("\n");
}
DoRestore = false;
if (Backup.SIMPhonebook[0] != NULL) {
MemStatus.MemoryType = MEM_SM;
error=Phone->GetMemoryStatus(&s, &MemStatus);
if (error==ERR_NONE) {
max = 0;
while (Backup.SIMPhonebook[max]!=NULL) max++;
printmsgerr("%i entries in backup file\n",max);
if (answer_yes("Restore SIM phonebook")) DoRestore = true;
}
}
if (DoRestore) {
used = 0;
for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
Pbk.MemoryType = MEM_SM;
Pbk.Location = i + 1;
Pbk.EntriesNum = 0;
if (used<max) {
if (Backup.SIMPhonebook[used]->Location == Pbk.Location) {
Pbk = *Backup.SIMPhonebook[used];
used++;
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index d037d2f..ad0f702 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -296,349 +296,471 @@ void AddressBook::init(const QString &config, const QString &family )
addResource( res );
}
else
qDebug(" No resource available!!!");
}
setStandardResource( res );
manager->writeConfig();
}
addCustomField( i18n( "Department" ), KABC::Field::Organization,
"X-Department", "KADDRESSBOOK" );
addCustomField( i18n( "Profession" ), KABC::Field::Organization,
"X-Profession", "KADDRESSBOOK" );
addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
"X-AssistantsName", "KADDRESSBOOK" );
addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
"X-ManagersName", "KADDRESSBOOK" );
addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
"X-SpousesName", "KADDRESSBOOK" );
addCustomField( i18n( "Office" ), KABC::Field::Personal,
"X-Office", "KADDRESSBOOK" );
addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
"X-IMAddress", "KADDRESSBOOK" );
addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
"X-Anniversary", "KADDRESSBOOK" );
//US added this field to become compatible with Opie/qtopia addressbook
// values can be "female" or "male" or "". An empty field represents undefined.
addCustomField( i18n( "Gender" ), KABC::Field::Personal,
"X-Gender", "KADDRESSBOOK" );
addCustomField( i18n( "Children" ), KABC::Field::Personal,
"X-Children", "KADDRESSBOOK" );
addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
"X-FreeBusyUrl", "KADDRESSBOOK" );
addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
"X-ExternalID", "KADDRESSBOOK" );
}
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;
}
bool AddressBook::save( Ticket *ticket )
{
kdDebug(5700) << "AddressBook::save()"<< endl;
if ( ticket->resource() ) {
deleteRemovedAddressees();
return ticket->resource()->save( ticket );
}
return false;
}
void AddressBook::export2File( QString fileName )
{
QFile outFile( fileName );
if ( !outFile.open( IO_WriteOnly ) ) {
QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
KMessageBox::error( 0, text.arg( fileName ) );
return ;
}
QTextStream t( &outFile );
t.setEncoding( QTextStream::UnicodeUTF8 );
Iterator it;
KABC::VCardConverter::Version version;
version = KABC::VCardConverter::v3_0;
for ( it = begin(); it != end(); ++it ) {
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()
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
(*ait).setTagged( false );
}
}
void AddressBook::removeUntagged()
{
Iterator ait;
bool todelete = false;
Iterator todel;
for ( ait = begin(); ait != end(); ++ait ) {
if ( todelete )
removeAddressee( todel );
if (!(*ait).tagged()) {
todelete = true;
todel = ait;
} else
todelete = false;
}
if ( todelete )
removeAddressee( todel );
deleteRemovedAddressees();
}
void AddressBook::smplifyAddressees()
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
(*ait).simplifyEmails();
(*ait).simplifyPhoneNumbers();
(*ait).simplifyPhoneNumberTypes();
(*ait).simplifyAddresses();
}
}
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();
return it;
}
AddressBook::ConstIterator AddressBook::begin() const
{
ConstIterator it = ConstIterator();
it.d->mIt = d->mAddressees.begin();
return it;
}
AddressBook::Iterator AddressBook::end()
{
Iterator it = Iterator();
it.d->mIt = d->mAddressees.end();
return it;
}
AddressBook::ConstIterator AddressBook::end() const
{
ConstIterator it = ConstIterator();
it.d->mIt = d->mAddressees.end();
return it;
}
void AddressBook::clear()
{
d->mAddressees.clear();
}
Ticket *AddressBook::requestSaveTicket( Resource *resource )
{
kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
if ( !resource )
{
qDebug("AddressBook::requestSaveTicket no resource" );
resource = standardResource();
}
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() ) {
bool changed = false;
Addressee addr = a;
if ( addr != (*it) )
changed = true;
if ( takeResource ) {
Resource * res = (*it).resource();
(*it) = a;
(*it).setResource( res );
} else {
(*it) = a;
if ( (*it).resource() == 0 )
(*it).setResource( standardResource() );
}
if ( changed ) {
if ( setRev ) {
// get rid of micro seconds
QDateTime dt = QDateTime::currentDateTime();
QTime t = dt.time();
dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
(*it).setRevision( dt );
}
(*it).setChanged( true );
}
found = true;
} else {
if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
QString name = (*it).uid().mid( 19 );
Addressee b = a;
QString id = b.getID( name );
if ( ! id.isEmpty() ) {
QString des = (*it).note();
int startN;
if( (startN = des.find( id ) ) >= 0 ) {
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index cc755d1..df9048b 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -101,99 +101,101 @@ class AddressBook : public QObject
ConstIterator &operator++();
ConstIterator &operator++(int);
ConstIterator &operator--();
ConstIterator &operator--(int);
bool operator==( const ConstIterator &it );
bool operator!=( const ConstIterator &it );
struct ConstIteratorData;
ConstIteratorData *d;
};
/**
Constructs a address book object.
@param format File format class.
*/
AddressBook();
AddressBook( const QString &config );
AddressBook( const QString &config, const QString &family );
virtual ~AddressBook();
/**
Requests a ticket for saving the addressbook. Calling this function locks
the addressbook for all other processes. If the address book is already
locked the function returns 0. You need the returned @ref Ticket object
for calling the @ref save() function.
@see save()
*/
Ticket *requestSaveTicket( Resource *resource=0 );
/**
Load address book from file.
*/
bool load();
/**
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.
*/
Iterator end();
/**
Returns a const iterator for first entry of address book.
*/
ConstIterator end() const;
/**
Removes all entries from address book.
*/
void clear();
/**
Insert an Addressee object into address book. If an object with the same
unique id already exists in the address book it it replaced by the new
one. If not the new object is appended to the address book.
*/
void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
/**
Removes entry from the address book.
*/
void removeAddressee( const Addressee & );
/**
This is like @ref removeAddressee() just above, with the difference that
the first element is a iterator, returned by @ref begin().
*/
void removeAddressee( const Iterator & );
/**
Find the specified entry in address book. Returns end(), if the entry
couldn't be found.
*/
Iterator find( const Addressee & );
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 607ae26..548305a 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -258,134 +258,174 @@ void Addressee::computeCsum(const QString &dev)
l.append( t[iii] );
t = mData->categories;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->custom;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
KABC::Address::List::Iterator addressIter;
for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
++addressIter ) {
t = (*addressIter).asList();
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 ;
+ 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()
{
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 )
{
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0aa2c51..03138f6 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -77,96 +77,97 @@ class Resource;
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 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.
*/
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 e5abc0e..6e94c7e 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -27,100 +27,98 @@ $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() )
+ 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;
}
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;
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index a7967cb..cd261f6 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -140,98 +140,98 @@ $Id$
#include "undocmds.h"
#include "addresseeeditordialog.h"
#include "viewmanager.h"
#include "details/detailsviewcontainer.h"
#include "kabprefs.h"
#include "xxportmanager.h"
#include "incsearchwidget.h"
#include "jumpbuttonbar.h"
#include "extensionmanager.h"
#include "addresseeconfig.h"
#include <kcmultidialog.h>
#ifdef _WIN32_
#include "kaimportoldialog.h"
#else
#include <unistd.h>
#endif
// sync includes
#include <libkdepim/ksyncprofile.h>
#include <libkdepim/ksyncprefsdialog.h>
class KAex2phonePrefs : public QDialog
{
public:
KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
QDialog( parent, name, true )
{
setCaption( i18n("Export to phone options") );
QVBoxLayout* lay = new QVBoxLayout( this );
lay->setSpacing( 3 );
lay->setMargin( 3 );
QLabel *lab;
lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
lab->setAlignment (AlignHCenter );
QHBox* temphb;
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 );
}
public:
QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
QCheckBox* mWriteToSim;
};
bool pasteWithNewUid = true;
#ifdef KAB_EMBEDDED
KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
: QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
#else //KAB_EMBEDDED
KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
: QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
mReadWrite( readWrite ), mModified( false )
#endif //KAB_EMBEDDED
{
// syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
// syncManager->setBlockSave(false);
mExtensionBarSplitter = 0;
mIsPart = !parent->inherits( "KAddressBookMain" );
mAddressBook = KABC::StdAddressBook::self();
KABC::StdAddressBook::setAutomaticSave( false );
#ifndef KAB_EMBEDDED
mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
#endif //KAB_EMBEDDED
connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
SLOT( addressBookChanged() ) );
#if 0
// LP moved to addressbook init method
@@ -649,164 +649,109 @@ void KABCore::mailVCard( const QStringList& uids )
*/
}
/**
Beams the "WhoAmI contact.
*/
void KABCore::beamMySelf()
{
KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
if (!a.isEmpty())
{
QStringList uids;
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");
+ 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
}
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,
beamFilename );
Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
Opie::OPimContactAccess::List allList = access->allRecords();
Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
c = *it;
delete access;
} else {
unlink( beamfile ); // delete if exists
mkdir("/tmp/obex/", 0755);
c = m_abView -> currentEntry();
Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
beamfile );
Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
access->add( c );
access->save();
delete access;
@@ -2798,127 +2743,130 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
}
}
//AddressBook::Iterator it;
//QStringList vcards;
//for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
// qDebug("Name %s ", (*it).familyName().latin1());
//}
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
if ( syncOK ) {
if ( syncManager->mWriteBackFile )
{
if ( external )
abLocal.removeSyncAddressees( !isXML);
qDebug("Saving remote AB ");
if ( ! abLocal.saveAB())
qDebug("Error writing back AB to file ");
if ( isXML ) {
// afterwrite processing
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
}
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();
return syncOK;
}
//this is a overwritten callbackmethods from the syncinterface
bool KABCore::syncExternal(KSyncManager* manager, QString resource)
{
if ( resource == "phone" )
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 )
{
topLevelWidget()->setCaption( m );
QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
}
bool KABCore::syncPhone()
{
QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
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 ) {
message( i18n("Error receiving file. Nothing changed!") );
return;
}
mAddressBook->importFromFile( sentSyncFile() , false, true );
message( i18n("Pi-Sync successful!") );
mViewManager->refreshView();
}
void KABCore::syncFileRequest()
{
mAddressBook->export2File( sentSyncFile() );
}
QString KABCore::sentSyncFile()
{
#ifdef _WIN32_
return locateLocal( "tmp", "copysyncab.vcf" );
#else
return QString( "/tmp/copysyncab.vcf" );
#endif
}
void KABCore::setCaptionBack()
{
topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
}
diff --git a/libkdepim/ksyncprefsdialog.cpp b/libkdepim/ksyncprefsdialog.cpp
index 84cc448..cf8f996 100644
--- a/libkdepim/ksyncprefsdialog.cpp
+++ b/libkdepim/ksyncprefsdialog.cpp
@@ -155,97 +155,97 @@ void KSyncPrefsDialog::setupSyncAlgTab()
++iii;
QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync preferences"), topFrame);
topLayout->addMultiCellWidget(gr, iii,iii,0,1);
++iii;
loc = new QRadioButton ( i18n("Take local entry on conflict"), gr );
rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr );
newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr );
ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr );
f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr );
f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr );
// both = new QRadioButton ( i18n("Take both on conflict"), gr );
mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), topFrame );
topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1);
++iii;
mWriteBackFile = new QCheckBox( i18n("Write back synced data"), topFrame );
topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1);
++iii;
mWriteBackExisting= new QCheckBox( i18n("-- Write back (on remote) existing entries only"), topFrame );
topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1);
++iii;
mWriteBackFuture= new QCheckBox( i18n("-- Write back (calendar) entries in future only"), topFrame );
topLayout->addMultiCellWidget(mWriteBackFuture, iii,iii,0,1);
++iii;
topLayout->addMultiCellWidget(new QLabel( i18n("---- Max. weeks in future: ") , topFrame ), iii,iii,0,0);
mWriteBackFutureWeeks= new QSpinBox(1,104, 1, topFrame);
topLayout->addMultiCellWidget(mWriteBackFutureWeeks, iii,iii,1,1);
++iii;
proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), topFrame);
gr = proGr;
topLayout->addMultiCellWidget(gr, iii,iii,0,1);
++iii;
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() ) );
temphb = new QHBox( phoneWidget );
new QLabel( i18n("Model(opt.): "), temphb );
mPhoneModel = new QLineEdit( temphb);
button = new QPushButton( i18n("Help..."), temphb );
connect ( button, SIGNAL( clicked()), this, SLOT ( helpModel() ) );
// *** local
localFileWidget = new QVBox( topFrame);
topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1);
++iii;
temphb = new QHBox( localFileWidget );
lab = new QLabel( i18n("Local file Cal:"), temphb );
lab = new QLabel( i18n("Local file ABook:"), temphb );
lab = new QLabel( i18n("Local file PWMgr:"), temphb );
temphb = new QHBox( localFileWidget );
button = new QPushButton( i18n("Choose..."), temphb );
connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) );
button = new QPushButton( i18n("Choose..."), temphb );
connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFileAB() ) );
button = new QPushButton( i18n("Choose..."), temphb );
connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFilePWM() ) );
temphb = new QHBox( localFileWidget );
mRemoteFile = new QLineEdit( temphb);
mRemoteFileAB = new QLineEdit( temphb);
mRemoteFilePWM = new QLineEdit( temphb);
// *** remote
remoteFileWidget = new QVBox( topFrame);
topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1);
++iii;
temphb = new QHBox( remoteFileWidget );
new QLabel( i18n("Calendar:"), temphb);
@@ -368,97 +368,98 @@ void KSyncPrefsDialog::textChanged( const QString & s )
if ( currentSelection < 3 ) {
//KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error"));
mProfileBox->blockSignals( true );
mProfileBox->setCurrentItem(mProfileBox-> currentItem ());
mProfileBox->blockSignals( false );
return;
}
//qDebug("cur i %d ",mProfileBox-> currentItem () );
mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ;
KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ;
prof->setName( s );
mSyncProfileNames[mProfileBox-> currentItem ()] = s;
}
void KSyncPrefsDialog::profileChanged( int item )
{
//qDebug("KSyncPrefsDialog::profileChanged before %d, count %d ", item, mProfileBox->count() );
KSyncProfile* prof;
saveProfile();
currentSelection = item;
prof = mSyncProfiles.at(item) ;
mRemotePw->setText(prof->getRemotePw());
mRemoteIP->setText(prof->getRemoteIP());
mRemotePort->setText(prof->getRemotePort());
mRemotePwAB->setText(prof->getRemotePwAB());
mRemoteIPAB->setText(prof->getRemoteIPAB());
mRemotePortAB->setText(prof->getRemotePortAB());
mRemotePwPWM->setText(prof->getRemotePwPWM());
mRemoteIPPWM->setText(prof->getRemoteIPPWM());
mRemotePortPWM->setText(prof->getRemotePortPWM());
mRemotePrecommand->setText(prof->getPreSyncCommand());
mRemotePostcommand->setText(prof->getPostSyncCommand());
mLocalTempFile->setText(prof->getLocalTempFile());
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());
mWriteBackFutureWeeks->setValue( prof->getWriteBackFutureWeeks() );
switch ( prof->getSyncPrefs() ) {
case 0:
loc->setChecked( true);
break;
case 1:
rem->setChecked( true );
break;
case 2:
newest->setChecked( true);
break;
case 3:
ask->setChecked( true);
break;
case 4:
f_loc->setChecked( true);
break;
case 5:
f_rem->setChecked( true);
break;
case 6:
//both->setChecked( true);
break;
default:
break;
}
mIsLocal->setChecked(prof->getIsLocalFileSync()) ;
mIsPhone->setChecked(prof->getIsPhoneSync()) ;
mIsPi->setChecked(prof->getIsPiSync()) ;
mIsNotLocal->setChecked(!prof->getIsLocalFileSync() && !prof->getIsPhoneSync() &&!prof->getIsPiSync() );
proGr->setEnabled( item > 2 );
if ( item < 3 ) {
localFileWidget->hide();
remoteFileWidget->hide();
phoneWidget->hide();
@@ -535,98 +536,98 @@ void KSyncPrefsDialog::deleteProfile()
insertProfiles();
}
}
void KSyncPrefsDialog::saveProfile()
{
KSyncProfile* prof;
if ( currentSelection >= 0 ) {
prof = mSyncProfiles.at(currentSelection) ;
prof->setRemotePw( mRemotePw->text());
prof->setRemoteIP( mRemoteIP->text());
prof->setRemotePort( mRemotePort->text());
prof->setRemotePwAB( mRemotePwAB->text());
prof->setRemoteIPAB( mRemoteIPAB->text());
prof->setRemotePortAB( mRemotePortAB->text());
prof->setRemotePwPWM( mRemotePwPWM->text());
prof->setRemoteIPPWM( mRemoteIPPWM->text());
prof->setRemotePortPWM( mRemotePortPWM->text());
prof->setPreSyncCommand( mRemotePrecommand->text());
prof->setPostSyncCommand( mRemotePostcommand->text() );
prof->setLocalTempFile( mLocalTempFile->text());
prof->setRemoteFileName( mRemoteFile->text() );
prof->setPreSyncCommandAB( mRemotePrecommandAB->text());
prof->setPostSyncCommandAB( mRemotePostcommandAB->text() );
prof->setLocalTempFileAB( mLocalTempFileAB->text());
prof->setRemoteFileNameAB( mRemoteFileAB->text() );
prof->setPreSyncCommandPWM( mRemotePrecommandPWM->text());
prof->setPostSyncCommandPWM( mRemotePostcommandPWM->text() );
prof->setLocalTempFilePWM( mLocalTempFilePWM->text());
prof->setRemoteFileNamePWM( mRemoteFilePWM->text() );
prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() );
prof->setAskForPreferences( mAskForPreferences->isChecked());
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 );
mProfileBox->clear();
mProfileBox->insertStringList (mSyncProfileNames );
int item = mSyncProfileNames.count() -1;
if ( curItem >= 0 && mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() )
mProfileBox->setCurrentItem( curItem );
else if ( item >= 0 ) {
mProfileBox->setCurrentItem( item );
}
currentSelection = -1;
if ( mSyncProfileNames.count() > 0 ) {
//qDebug(" profileChanged( mProfileBox->currentItem() ");
profileChanged( mProfileBox->currentItem() );
currentSelection = mProfileBox->currentItem();
}
mProfileBox->blockSignals( false );
}
void KSyncPrefsDialog::addProfile ( KSyncProfile* temp )
{
saveProfile();
mSyncProfiles.append( temp );
mSyncProfileNames << temp->getName();
insertProfiles();
int last = mProfileBox->count() -1;
mProfileBox->blockSignals( true );
mProfileBox->setCurrentItem( last );
mProfileBox->blockSignals( false );
profileChanged(last);
}
void KSyncPrefsDialog::newProfile()
{
addProfile ( new KSyncProfile () );
}
void KSyncPrefsDialog::cloneProfile()
{
@@ -670,62 +671,62 @@ void KSyncPrefsDialog::usrReadConfig()
//mMyMachineName->setText(KOPrefs::instance()->mLocalMachineName );
}
void KSyncPrefsDialog::usrWriteConfig()
{
saveProfile();
if ( currentSelection >= 0 )
profileChanged(currentSelection);
//KConfig *config = KOGlobals::config();
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
KSyncProfile* prof = mSyncProfiles.first();
QStringList externalSyncProfileNames;
externalSyncProfileNames.append("Sharp_DTM");;
while ( prof ) {
prof->writeConfig(&config);
if ( prof->getIsPhoneSync( ) )
externalSyncProfileNames.append(prof->getName( ) );
prof = mSyncProfiles.next();
}
//KOPrefs::instance()->mSyncProfileNames = mSyncProfileNames;
//KOPrefs::instance()->mLocalMachineName = mMyMachineName->text();
config.setGroup("General");
config.writeEntry("SyncProfileNames",mSyncProfileNames);
config.writeEntry("ExternSyncProfiles",externalSyncProfileNames);
config.writeEntry("LocalMachineName",mMyMachineName->text());
config.sync();
}
void KSyncPrefsDialog::helpDevice()
{
QString hint = i18n("Insert device where\nphone is connected. E.g.:\n");
#ifdef _WIN32_
hint += "Leave empty for Irda.\n"
"com1:\n(first serial port)\n"
"usb not supported\n"
"???\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"));
}