summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp13
-rw-r--r--kabc/addressee.h2
-rw-r--r--kabc/plugins/qtopia/qtopiaE.pro2
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp7
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.h1
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp78
-rw-r--r--kaddressbook/kabcore.cpp87
-rw-r--r--libkcal/sharpformat.cpp6
-rw-r--r--libkcal/syncdefines.h2
9 files changed, 141 insertions, 57 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3a2dc5f..fda62f1 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -22,96 +22,97 @@
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46 46
47struct Addressee::AddresseeData : public KShared 47struct Addressee::AddresseeData : public KShared
48{ 48{
49 QString uid; 49 QString uid;
50 QString name; 50 QString name;
51 QString formattedName; 51 QString formattedName;
52 QString familyName; 52 QString familyName;
53 QString givenName; 53 QString givenName;
54 QString additionalName; 54 QString additionalName;
55 QString prefix; 55 QString prefix;
56 QString suffix; 56 QString suffix;
57 QString nickName; 57 QString nickName;
58 QDateTime birthday; 58 QDateTime birthday;
59 QString mailer; 59 QString mailer;
60 TimeZone timeZone; 60 TimeZone timeZone;
61 Geo geo; 61 Geo geo;
62 QString title; 62 QString title;
63 QString role; 63 QString role;
64 QString organization; 64 QString organization;
65 QString note; 65 QString note;
66 QString productId; 66 QString productId;
67 QDateTime revision; 67 QDateTime revision;
68 QString sortString; 68 QString sortString;
69 QString externalUID; 69 QString externalUID;
70 QString originalExternalUID;
70 KURL url; 71 KURL url;
71 Secrecy secrecy; 72 Secrecy secrecy;
72 Picture logo; 73 Picture logo;
73 Picture photo; 74 Picture photo;
74 Sound sound; 75 Sound sound;
75 Agent agent; 76 Agent agent;
76 QString mExternalId; 77 QString mExternalId;
77 PhoneNumber::List phoneNumbers; 78 PhoneNumber::List phoneNumbers;
78 Address::List addresses; 79 Address::List addresses;
79 Key::List keys; 80 Key::List keys;
80 QStringList emails; 81 QStringList emails;
81 QStringList categories; 82 QStringList categories;
82 QStringList custom; 83 QStringList custom;
83 int mTempSyncStat; 84 int mTempSyncStat;
84 Resource *resource; 85 Resource *resource;
85 86
86 bool empty :1; 87 bool empty :1;
87 bool changed :1; 88 bool changed :1;
88}; 89};
89 90
90Addressee::Addressee() 91Addressee::Addressee()
91{ 92{
92 mData = new AddresseeData; 93 mData = new AddresseeData;
93 mData->empty = true; 94 mData->empty = true;
94 mData->changed = false; 95 mData->changed = false;
95 mData->resource = 0; 96 mData->resource = 0;
96 mData->mExternalId = ":"; 97 mData->mExternalId = ":";
97 mData->revision = QDateTime ( QDate( 2004,1,1)); 98 mData->revision = QDateTime ( QDate( 2004,1,1));
98 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 99 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
99} 100}
100 101
101Addressee::~Addressee() 102Addressee::~Addressee()
102{ 103{
103} 104}
104 105
105Addressee::Addressee( const Addressee &a ) 106Addressee::Addressee( const Addressee &a )
106{ 107{
107 mData = a.mData; 108 mData = a.mData;
108} 109}
109 110
110Addressee &Addressee::operator=( const Addressee &a ) 111Addressee &Addressee::operator=( const Addressee &a )
111{ 112{
112 mData = a.mData; 113 mData = a.mData;
113 return (*this); 114 return (*this);
114} 115}
115 116
116Addressee Addressee::copy() 117Addressee Addressee::copy()
117{ 118{
@@ -328,96 +329,108 @@ void Addressee::setTempSyncStat( int id )
328 mData->mTempSyncStat = id; 329 mData->mTempSyncStat = id;
329} 330}
330int Addressee::tempSyncStat() const 331int Addressee::tempSyncStat() const
331{ 332{
332 return mData->mTempSyncStat; 333 return mData->mTempSyncStat;
333} 334}
334 335
335QString Addressee::getID( const QString & prof) 336QString Addressee::getID( const QString & prof)
336{ 337{
337 return KIdManager::getId ( mData->mExternalId, prof ); 338 return KIdManager::getId ( mData->mExternalId, prof );
338} 339}
339 340
340void Addressee::setCsum( const QString & prof , const QString & id ) 341void Addressee::setCsum( const QString & prof , const QString & id )
341{ 342{
342 detach(); 343 detach();
343 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 344 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
344 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 345 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
345 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 346 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
346} 347}
347 348
348QString Addressee::getCsum( const QString & prof) 349QString Addressee::getCsum( const QString & prof)
349{ 350{
350 return KIdManager::getCsum ( mData->mExternalId, prof ); 351 return KIdManager::getCsum ( mData->mExternalId, prof );
351} 352}
352 353
353void Addressee::setIDStr( const QString & s ) 354void Addressee::setIDStr( const QString & s )
354{ 355{
355 detach(); 356 detach();
356 mData->mExternalId = s; 357 mData->mExternalId = s;
357} 358}
358 359
359QString Addressee::IDStr() const 360QString Addressee::IDStr() const
360{ 361{
361 return mData->mExternalId; 362 return mData->mExternalId;
362} 363}
363 364
364void Addressee::setExternalUID( const QString &id ) 365void Addressee::setExternalUID( const QString &id )
365{ 366{
366 if ( id == mData->externalUID ) return; 367 if ( id == mData->externalUID ) return;
367 detach(); 368 detach();
368 mData->empty = false; 369 mData->empty = false;
369 mData->externalUID = id; 370 mData->externalUID = id;
370} 371}
371 372
372QString Addressee::externalUID() const 373QString Addressee::externalUID() const
373{ 374{
374 return mData->externalUID; 375 return mData->externalUID;
375} 376}
377void Addressee::setOriginalExternalUID( const QString &id )
378{
379 if ( id == mData->originalExternalUID ) return;
380 detach();
381 mData->empty = false;
382 mData->originalExternalUID = id;
383}
384
385QString Addressee::originalExternalUID() const
386{
387 return mData->originalExternalUID;
388}
376 389
377void Addressee::setUid( const QString &id ) 390void Addressee::setUid( const QString &id )
378{ 391{
379 if ( id == mData->uid ) return; 392 if ( id == mData->uid ) return;
380 detach(); 393 detach();
381 mData->empty = false; 394 mData->empty = false;
382 mData->uid = id; 395 mData->uid = id;
383} 396}
384 397
385QString Addressee::uid() const 398QString Addressee::uid() const
386{ 399{
387 if ( mData->uid.isEmpty() ) 400 if ( mData->uid.isEmpty() )
388 mData->uid = KApplication::randomString( 10 ); 401 mData->uid = KApplication::randomString( 10 );
389 402
390 return mData->uid; 403 return mData->uid;
391} 404}
392 405
393QString Addressee::uidLabel() 406QString Addressee::uidLabel()
394{ 407{
395 return i18n("Unique Identifier"); 408 return i18n("Unique Identifier");
396} 409}
397 410
398void Addressee::setName( const QString &name ) 411void Addressee::setName( const QString &name )
399{ 412{
400 if ( name == mData->name ) return; 413 if ( name == mData->name ) return;
401 detach(); 414 detach();
402 mData->empty = false; 415 mData->empty = false;
403 mData->name = name; 416 mData->name = name;
404} 417}
405 418
406QString Addressee::name() const 419QString Addressee::name() const
407{ 420{
408 return mData->name; 421 return mData->name;
409} 422}
410 423
411QString Addressee::nameLabel() 424QString Addressee::nameLabel()
412{ 425{
413 return i18n("Name"); 426 return i18n("Name");
414} 427}
415 428
416 429
417void Addressee::setFormattedName( const QString &formattedName ) 430void Addressee::setFormattedName( const QString &formattedName )
418{ 431{
419 if ( formattedName == mData->formattedName ) return; 432 if ( formattedName == mData->formattedName ) return;
420 detach(); 433 detach();
421 mData->empty = false; 434 mData->empty = false;
422 mData->formattedName = formattedName; 435 mData->formattedName = formattedName;
423} 436}
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 3ba7777..8baa888 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -69,96 +69,98 @@ class Resource;
69 naming. formattedName() is the full name with the correct formatting. 69 naming. formattedName() is the full name with the correct formatting.
70 It is used as an override, when the correct formatting can't be generated 70 It is used as an override, when the correct formatting can't be generated
71 from the other name fields automatically. 71 from the other name fields automatically.
72 72
73 realName() returns a fully formatted name(). It uses formattedName, if set, 73 realName() returns a fully formatted name(). It uses formattedName, if set,
74 otherwise it constucts the name from the name fields. As fallback, if 74 otherwise it constucts the name from the name fields. As fallback, if
75 nothing else is set it uses name(). 75 nothing else is set it uses name().
76 76
77 name() is the NAME type of RFC2426. It can be used as internal name for the 77 name() is the NAME type of RFC2426. It can be used as internal name for the
78 data enty, but shouldn't be used for displaying the data to the user. 78 data enty, but shouldn't be used for displaying the data to the user.
79 */ 79 */
80class Addressee 80class Addressee
81{ 81{
82 friend QDataStream &operator<<( QDataStream &, const Addressee & ); 82 friend QDataStream &operator<<( QDataStream &, const Addressee & );
83 friend QDataStream &operator>>( QDataStream &, Addressee & ); 83 friend QDataStream &operator>>( QDataStream &, Addressee & );
84 84
85 public: 85 public:
86 typedef QValueList<Addressee> List; 86 typedef QValueList<Addressee> List;
87 87
88 /** 88 /**
89 Construct an empty address book entry. 89 Construct an empty address book entry.
90 */ 90 */
91 Addressee(); 91 Addressee();
92 ~Addressee(); 92 ~Addressee();
93 93
94 Addressee( const Addressee & ); 94 Addressee( const Addressee & );
95 Addressee &operator=( const Addressee & ); 95 Addressee &operator=( const Addressee & );
96 96
97 bool operator==( const Addressee & ) const; 97 bool operator==( const Addressee & ) const;
98 bool operator!=( const Addressee & ) const; 98 bool operator!=( const Addressee & ) const;
99 // sync stuff 99 // sync stuff
100 void setTempSyncStat(int id); 100 void setTempSyncStat(int id);
101 int tempSyncStat() const; 101 int tempSyncStat() const;
102 void setIDStr( const QString & ); 102 void setIDStr( const QString & );
103 QString IDStr() const; 103 QString IDStr() const;
104 void setID( const QString &, const QString & ); 104 void setID( const QString &, const QString & );
105 QString getID( const QString & ); 105 QString getID( const QString & );
106 void setCsum( const QString &, const QString & ); 106 void setCsum( const QString &, const QString & );
107 QString getCsum( const QString & ); 107 QString getCsum( const QString & );
108 void removeID(const QString &); 108 void removeID(const QString &);
109 void computeCsum(const QString &dev); 109 void computeCsum(const QString &dev);
110 ulong getCsum4List( const QStringList & attList); 110 ulong getCsum4List( const QStringList & attList);
111 /** 111 /**
112 Return, if the address book entry is empty. 112 Return, if the address book entry is empty.
113 */ 113 */
114 bool isEmpty() const; 114 bool isEmpty() const;
115 void setExternalUID( const QString &id ); 115 void setExternalUID( const QString &id );
116 QString externalUID() const; 116 QString externalUID() const;
117 void setOriginalExternalUID( const QString &id );
118 QString originalExternalUID() const;
117 void mergeContact( const Addressee& ad ); 119 void mergeContact( const Addressee& ad );
118 /** 120 /**
119 Set unique identifier. 121 Set unique identifier.
120 */ 122 */
121 void setUid( const QString &uid ); 123 void setUid( const QString &uid );
122 /** 124 /**
123 Return unique identifier. 125 Return unique identifier.
124 */ 126 */
125 QString uid() const; 127 QString uid() const;
126 /** 128 /**
127 Return translated label for uid field. 129 Return translated label for uid field.
128 */ 130 */
129 static QString uidLabel(); 131 static QString uidLabel();
130 132
131 /** 133 /**
132 Set name. 134 Set name.
133 */ 135 */
134 void setName( const QString &name ); 136 void setName( const QString &name );
135 /** 137 /**
136 Return name. 138 Return name.
137 */ 139 */
138 QString name() const; 140 QString name() const;
139 /** 141 /**
140 Return translated label for name field. 142 Return translated label for name field.
141 */ 143 */
142 static QString nameLabel(); 144 static QString nameLabel();
143 145
144 /** 146 /**
145 Set formatted name. 147 Set formatted name.
146 */ 148 */
147 void setFormattedName( const QString &formattedName ); 149 void setFormattedName( const QString &formattedName );
148 /** 150 /**
149 Return formatted name. 151 Return formatted name.
150 */ 152 */
151 QString formattedName() const; 153 QString formattedName() const;
152 /** 154 /**
153 Return translated label for formattedName field. 155 Return translated label for formattedName field.
154 */ 156 */
155 static QString formattedNameLabel(); 157 static QString formattedNameLabel();
156 158
157 /** 159 /**
158 Set family name. 160 Set family name.
159 */ 161 */
160 void setFamilyName( const QString &familyName ); 162 void setFamilyName( const QString &familyName );
161 /** 163 /**
162 Return family name. 164 Return family name.
163 */ 165 */
164 QString familyName() const; 166 QString familyName() const;
diff --git a/kabc/plugins/qtopia/qtopiaE.pro b/kabc/plugins/qtopia/qtopiaE.pro
index 148da2a..c0aa960 100644
--- a/kabc/plugins/qtopia/qtopiaE.pro
+++ b/kabc/plugins/qtopia/qtopiaE.pro
@@ -1,27 +1,27 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3 3
4TARGET = microkabc_qtopia 4TARGET = microkabc_qtopia
5 5
6INCLUDEPATH += $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include 6INCLUDEPATH += $(KDEPIMDIR) $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include
7 7
8OBJECTS_DIR = obj/$(PLATFORM) 8OBJECTS_DIR = obj/$(PLATFORM)
9MOC_DIR = moc/$(PLATFORM) 9MOC_DIR = moc/$(PLATFORM)
10DESTDIR = $(QPEDIR)/lib 10DESTDIR = $(QPEDIR)/lib
11LIBS += -lmicrokde 11LIBS += -lmicrokde
12LIBS += -lmicrokabc 12LIBS += -lmicrokabc
13LIBS += -L$(QPEDIR)/lib 13LIBS += -L$(QPEDIR)/lib
14LIBS += -lqpepim 14LIBS += -lqpepim
15LIBS += -lqpe 15LIBS += -lqpe
16 16
17INTERFACES = \ 17INTERFACES = \
18 18
19HEADERS = \ 19HEADERS = \
20 resourceqtopia.h \ 20 resourceqtopia.h \
21 resourceqtopiaconfig.h \ 21 resourceqtopiaconfig.h \
22 qtopiaconverter.h 22 qtopiaconverter.h
23 23
24SOURCES = \ 24SOURCES = \
25 resourceqtopia.cpp \ 25 resourceqtopia.cpp \
26 resourceqtopiaconfig.cpp \ 26 resourceqtopiaconfig.cpp \
27 qtopiaconverter.cpp 27 qtopiaconverter.cpp
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index 7d00a3f..de45e63 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -1,126 +1,130 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28//US 28//US
29#include "kglobal.h" 29#include "kglobal.h"
30 30
31 31
32#include "qtopiaconverter.h" 32#include "qtopiaconverter.h"
33 33
34#include <qpe/categories.h> 34#include <qpe/categories.h>
35#include <libkdepim/ksyncprofile.h>
35//US #include <qpe/categoryselect.h> 36//US #include <qpe/categoryselect.h>
36 37
37 38
38using namespace KABC; 39using namespace KABC;
39 40
40QtopiaConverter::QtopiaConverter() : catDB(0) 41QtopiaConverter::QtopiaConverter() : catDB(0)
41{ 42{
42} 43}
43 44
44QtopiaConverter::~QtopiaConverter() 45QtopiaConverter::~QtopiaConverter()
45{ 46{
46 deinit(); 47 deinit();
47} 48}
48 49
49bool QtopiaConverter::init() 50bool QtopiaConverter::init()
50{ 51{
51 catDB = new Categories(); 52 catDB = new Categories();
52 53
53 if (!catDB) 54 if (!catDB)
54 return false; 55 return false;
55 56
56 catDB->load( categoryFileName() ); 57 catDB->load( categoryFileName() );
57 return true; 58 return true;
58} 59}
59 60
60void QtopiaConverter::deinit() 61void QtopiaConverter::deinit()
61{ 62{
62 if (catDB) 63 if (catDB)
63 { 64 {
64 delete catDB; 65 delete catDB;
65 catDB = 0; 66 catDB = 0;
66 } 67 }
67} 68}
68 69
69bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) 70bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr )
70{ 71{
71 // name 72 // name
72 addr.setFormattedName(contact.fileAs()); 73 addr.setFormattedName(contact.fileAs());
73 addr.setFamilyName( contact.lastName() ); 74 addr.setFamilyName( contact.lastName() );
74 addr.setGivenName( contact.firstName() ); 75 addr.setGivenName( contact.firstName() );
75 addr.setAdditionalName( contact.middleName() ); 76 addr.setAdditionalName( contact.middleName() );
76 addr.setPrefix( contact.nameTitle() ); 77 addr.setPrefix( contact.nameTitle() );
77 addr.setSuffix( contact.suffix() ); 78 addr.setSuffix( contact.suffix() );
79
80 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
78 QString exuid = contact.uid().toString(); 81 QString exuid = contact.uid().toString();
82 addr.setOriginalExternalUID( exuid );
79 int ente = exuid.find( "-0000"); 83 int ente = exuid.find( "-0000");
80 if ( exuid.left(1) == "{" ) 84 if ( exuid.left(1) == "{" )
81 exuid = exuid.mid(1); 85 exuid = exuid.mid(1);
82 if ( ente > -1 ) 86 if ( ente > -1 )
83 exuid = exuid.left( ente-1 ); 87 exuid = exuid.left( ente-1 );
84 addr.setExternalUID( exuid ); 88 addr.setExternalUID( exuid );
85 //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); 89 //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() );
86 90
87 // email 91 // email
88 QStringList emails = contact.emailList(); 92 QStringList emails = contact.emailList();
89 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 93 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
90 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); 94 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
91 } 95 }
92 96
93 if (!contact.defaultEmail().isEmpty()) 97 if (!contact.defaultEmail().isEmpty())
94 addr.insertEmail(contact.defaultEmail(), true); 98 addr.insertEmail(contact.defaultEmail(), true);
95 99
96 // home 100 // home
97 if ((!contact.homeStreet().isEmpty()) || 101 if ((!contact.homeStreet().isEmpty()) ||
98 (!contact.homeCity().isEmpty()) || 102 (!contact.homeCity().isEmpty()) ||
99 (!contact.homeState().isEmpty()) || 103 (!contact.homeState().isEmpty()) ||
100 (!contact.homeZip().isEmpty()) || 104 (!contact.homeZip().isEmpty()) ||
101 (!contact.homeCountry().isEmpty())) 105 (!contact.homeCountry().isEmpty()))
102 { 106 {
103 Address homeaddress; 107 Address homeaddress;
104 homeaddress.setType(Address::Home); 108 homeaddress.setType(Address::Home);
105//US homeaddress.setPostOfficeBox( "" ); 109//US homeaddress.setPostOfficeBox( "" );
106//US homeaddress.setExtended( "" ); 110//US homeaddress.setExtended( "" );
107 homeaddress.setStreet( contact.homeStreet() ); 111 homeaddress.setStreet( contact.homeStreet() );
108 homeaddress.setLocality( contact.homeCity() ); 112 homeaddress.setLocality( contact.homeCity() );
109 homeaddress.setRegion( contact.homeState() ); 113 homeaddress.setRegion( contact.homeState() );
110 homeaddress.setPostalCode( contact.homeZip() ); 114 homeaddress.setPostalCode( contact.homeZip() );
111 homeaddress.setCountry( contact.homeCountry() ); 115 homeaddress.setCountry( contact.homeCountry() );
112 116
113 addr.insertAddress( homeaddress ); 117 addr.insertAddress( homeaddress );
114 } 118 }
115 119
116 if (!contact.homePhone().isEmpty()) 120 if (!contact.homePhone().isEmpty())
117 { 121 {
118 PhoneNumber homephone; 122 PhoneNumber homephone;
119 homephone.setType( PhoneNumber::Home ); 123 homephone.setType( PhoneNumber::Home );
120 homephone.setNumber( contact.homePhone() ); 124 homephone.setNumber( contact.homePhone() );
121 addr.insertPhoneNumber( homephone ); 125 addr.insertPhoneNumber( homephone );
122 } 126 }
123 127
124 if (!contact.homeFax().isEmpty()) 128 if (!contact.homeFax().isEmpty())
125 { 129 {
126 PhoneNumber homefax; 130 PhoneNumber homefax;
@@ -206,96 +210,99 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a
206 // qtopia uses this categorization: 210 // qtopia uses this categorization:
207 // enum GenderType { UnspecifiedGender=0, Male, Female }; 211 // enum GenderType { UnspecifiedGender=0, Male, Female };
208 if (contact.gender() == PimContact::Male) 212 if (contact.gender() == PimContact::Male)
209 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); 213 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male");
210 else if (contact.gender() == PimContact::Female) 214 else if (contact.gender() == PimContact::Female)
211 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); 215 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female");
212 216
213 if (contact.anniversary().isValid()) { 217 if (contact.anniversary().isValid()) {
214 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); 218 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate);
215//US 219//US
216// qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); 220// qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1());
217 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); 221 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
218 } 222 }
219 223
220 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); 224 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
221 if (contact.birthday().isValid()) 225 if (contact.birthday().isValid())
222 addr.setBirthday( contact.birthday() ); 226 addr.setBirthday( contact.birthday() );
223 227
224 addr.setNickName( contact.nickname() ); 228 addr.setNickName( contact.nickname() );
225 229
226 // others 230 // others
227 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. 231 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
228 QString notes = contact.notes(); 232 QString notes = contact.notes();
229 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; 233 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n";
230 234
231 addr.setNote( contact.notes() ); 235 addr.setNote( contact.notes() );
232 236
233 237
234 238
235//US QString groups() const { return find( Qtopia::Groups ); } 239//US QString groups() const { return find( Qtopia::Groups ); }
236//US QStringList groupList() const; 240//US QStringList groupList() const;
237 241
238 QArray<int> catArray = contact.categories(); 242 QArray<int> catArray = contact.categories();
239 QString cat; 243 QString cat;
240 244
241 for ( unsigned int i=0; i < catArray.size(); i++ ) { 245 for ( unsigned int i=0; i < catArray.size(); i++ ) {
242 cat = catDB->label("contact", catArray[i]); 246 cat = catDB->label("contact", catArray[i]);
243 if ( cat.isEmpty() ) 247 if ( cat.isEmpty() )
244 addr.insertCategory(QString::number(catArray[i])); 248 addr.insertCategory(QString::number(catArray[i]));
245 else 249 else
246 addr.insertCategory( cat ); 250 addr.insertCategory( cat );
247 } 251 }
248 252
249 return true; 253 return true;
250} 254}
251 255
252bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) 256bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact )
253{ 257{
258
259
260
254 // name 261 // name
255 contact.setLastName(addr.familyName()); 262 contact.setLastName(addr.familyName());
256 contact.setFirstName(addr.givenName()); 263 contact.setFirstName(addr.givenName());
257 contact.setMiddleName(addr.additionalName()); 264 contact.setMiddleName(addr.additionalName());
258 contact.setNameTitle(addr.prefix()); 265 contact.setNameTitle(addr.prefix());
259 contact.setSuffix(addr.suffix()); 266 contact.setSuffix(addr.suffix());
260 contact.setFileAs(); 267 contact.setFileAs();
261 268
262 269
263 // email 270 // email
264 QStringList emails = addr.emails(); 271 QStringList emails = addr.emails();
265 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 272 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
266 contact.insertEmail(*it); 273 contact.insertEmail(*it);
267 } 274 }
268 contact.setDefaultEmail( addr.preferredEmail() ); 275 contact.setDefaultEmail( addr.preferredEmail() );
269 276
270 277
271 // home 278 // home
272 const Address homeaddress = addr.address(Address::Home); 279 const Address homeaddress = addr.address(Address::Home);
273 if (!homeaddress.isEmpty()) { 280 if (!homeaddress.isEmpty()) {
274 contact.setHomeStreet(homeaddress.street()); 281 contact.setHomeStreet(homeaddress.street());
275 contact.setHomeCity(homeaddress.locality()); 282 contact.setHomeCity(homeaddress.locality());
276 contact.setHomeState(homeaddress.region()); 283 contact.setHomeState(homeaddress.region());
277 contact.setHomeZip(homeaddress.postalCode()); 284 contact.setHomeZip(homeaddress.postalCode());
278 contact.setHomeCountry(homeaddress.country()); 285 contact.setHomeCountry(homeaddress.country());
279 } 286 }
280 287
281 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); 288 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
282 if (!homephone.number().isEmpty()) 289 if (!homephone.number().isEmpty())
283 contact.setHomePhone(homephone.number()); 290 contact.setHomePhone(homephone.number());
284 291
285 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); 292 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
286 if (!homefax.number().isEmpty()) 293 if (!homefax.number().isEmpty())
287 contact.setHomeFax(homefax.number()); 294 contact.setHomeFax(homefax.number());
288 295
289 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); 296 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
290 if (!homemobile.number().isEmpty()) 297 if (!homemobile.number().isEmpty())
291 contact.setHomeMobile(homemobile.number()); 298 contact.setHomeMobile(homemobile.number());
292 299
293 contact.setHomeWebpage(addr.url().url()); 300 contact.setHomeWebpage(addr.url().url());
294 301
295 302
296 // business 303 // business
297 const Address businessaddress = addr.address(Address::Work); 304 const Address businessaddress = addr.address(Address::Work);
298 if (!businessaddress.isEmpty()) { 305 if (!businessaddress.isEmpty()) {
299 contact.setBusinessStreet(businessaddress.street()); 306 contact.setBusinessStreet(businessaddress.street());
300 contact.setBusinessCity(businessaddress.locality()); 307 contact.setBusinessCity(businessaddress.locality());
301 contact.setBusinessState(businessaddress.region()); 308 contact.setBusinessState(businessaddress.region());
diff --git a/kabc/plugins/qtopia/qtopiaconverter.h b/kabc/plugins/qtopia/qtopiaconverter.h
index 8f4c698..012a6e2 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.h
+++ b/kabc/plugins/qtopia/qtopiaconverter.h
@@ -1,79 +1,80 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24$Id$ 24$Id$
25*/ 25*/
26 26
27#ifndef KABC_QTOPIACONVERTER_H 27#ifndef KABC_QTOPIACONVERTER_H
28#define KABC_QTOPIACONVERTER_H 28#define KABC_QTOPIACONVERTER_H
29 29
30#include <qstring.h> 30#include <qstring.h>
31 31
32#include "addressee.h" 32#include "addressee.h"
33#include <qpe/pim/contact.h> 33#include <qpe/pim/contact.h>
34#include <qpe/quuid.h>
34 35
35class Categories; 36class Categories;
36 37
37namespace KABC { 38namespace KABC {
38 39
39class QtopiaConverter 40class QtopiaConverter
40{ 41{
41public: 42public:
42 43
43 /** 44 /**
44 * Constructor. 45 * Constructor.
45 */ 46 */
46 QtopiaConverter(); 47 QtopiaConverter();
47 48
48 /** 49 /**
49 * Destructor. 50 * Destructor.
50 */ 51 */
51 virtual ~QtopiaConverter(); 52 virtual ~QtopiaConverter();
52 53
53 bool init(); 54 bool init();
54 void deinit(); 55 void deinit();
55 56
56 /** 57 /**
57 * Converts a vcard string to an addressee. 58 * Converts a vcard string to an addressee.
58 * 59 *
59 * @param contact The qtopia contact. 60 * @param contact The qtopia contact.
60 * @param addr The addressee. 61 * @param addr The addressee.
61 */ 62 */
62 bool qtopiaToAddressee( const PimContact &contact, Addressee &addr ); 63 bool qtopiaToAddressee( const PimContact &contact, Addressee &addr );
63 64
64 /** 65 /**
65 * Converts an addressee to a vcard string. 66 * Converts an addressee to a vcard string.
66 * 67 *
67 * @param addr The addressee. 68 * @param addr The addressee.
68 * @param contact The qtopia contact. 69 * @param contact The qtopia contact.
69 */ 70 */
70 bool addresseeToQtopia( const Addressee &addr, PimContact &contact ); 71 bool addresseeToQtopia( const Addressee &addr, PimContact &contact );
71 72
72 private: 73 private:
73 Categories* catDB; 74 Categories* catDB;
74 75
75 76
76}; 77};
77 78
78} 79}
79#endif 80#endif
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 48a9f22..935a1cf 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -7,96 +7,98 @@
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <qdir.h> 31#include <qdir.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qregexp.h> 34#include <qregexp.h>
35//US #include <qtimer.h> 35//US #include <qtimer.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45#include <qpe/pim/addressbookaccess.h> 45#include <qpe/pim/addressbookaccess.h>
46 46
47 47
48#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
49#include "stdaddressbook.h" 49#include "stdaddressbook.h"
50 50
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52#include "syncprefwidget.h" 52#include "syncprefwidget.h"
53 53
54#include "resourceqtopia.h" 54#include "resourceqtopia.h"
55#include <libkdepim/ksyncprofile.h>
56#include <qpe/quuid.h>
55 57
56using namespace KABC; 58using namespace KABC;
57extern "C" 59extern "C"
58{ 60{
59 void *init_microkabc_qtopia() 61 void *init_microkabc_qtopia()
60 { 62 {
61 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); 63 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>();
62 } 64 }
63} 65}
64 66
65ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) 67ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable )
66 : Resource( config, syncable ), mConverter (0) 68 : Resource( config, syncable ), mConverter (0)
67{ 69{
68 // we can not choose the filename. Therefore use the default to display 70 // we can not choose the filename. Therefore use the default to display
69 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
70 init( fileName ); 72 init( fileName );
71} 73}
72 74
73ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) 75ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable )
74 : Resource( 0, syncable ) 76 : Resource( 0, syncable )
75{ 77{
76 init( fileName ); 78 init( fileName );
77} 79}
78 80
79void ResourceQtopia::init( const QString &fileName ) 81void ResourceQtopia::init( const QString &fileName )
80{ 82{
81 83
82 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
83 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
84 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
85 87
86 setFileName( fileName ); 88 setFileName( fileName );
87} 89}
88 90
89ResourceQtopia::~ResourceQtopia() 91ResourceQtopia::~ResourceQtopia()
90{ 92{
91 if (mConverter != 0) 93 if (mConverter != 0)
92 delete mConverter; 94 delete mConverter;
93 95
94 if(mAccess != 0) 96 if(mAccess != 0)
95 delete mAccess; 97 delete mAccess;
96} 98}
97 99
98void ResourceQtopia::writeConfig( KConfig *config ) 100void ResourceQtopia::writeConfig( KConfig *config )
99{ 101{
100 Resource::writeConfig( config ); 102 Resource::writeConfig( config );
101} 103}
102 104
@@ -144,128 +146,150 @@ bool ResourceQtopia::doOpen()
144 } 146 }
145 147
146 return true; 148 return true;
147} 149}
148 150
149void ResourceQtopia::doClose() 151void ResourceQtopia::doClose()
150{ 152{
151 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 153 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
152 154
153 if(mAccess) 155 if(mAccess)
154 { 156 {
155 delete mAccess; 157 delete mAccess;
156 mAccess = 0; 158 mAccess = 0;
157 } 159 }
158 // it seems so, that deletion of access deletes backend as well 160 // it seems so, that deletion of access deletes backend as well
159 //delete backend; 161 //delete backend;
160 162
161 return; 163 return;
162} 164}
163 165
164bool ResourceQtopia::load() 166bool ResourceQtopia::load()
165{ 167{
166 qDebug("ResourceQtopia::load: %s", fileName().latin1()); 168 qDebug("ResourceQtopia::load: %s", fileName().latin1());
167 169
168 AddressBookIterator it(*mAccess); 170 AddressBookIterator it(*mAccess);
169 const PimContact* contact; 171 const PimContact* contact;
170 bool res; 172 bool res;
171 173
172 for (contact=it.toFirst(); it.current(); ++it) 174 for (contact=it.toFirst(); it.current(); ++it)
173 { 175 {
174 contact = it.current(); 176 contact = it.current();
175 177
176 KABC::Addressee addressee; 178 KABC::Addressee addressee;
177 179
178 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 180 res = mConverter->qtopiaToAddressee( (*contact), addressee );
179 181
180 if ( !addressee.isEmpty() && res ) 182 if ( !addressee.isEmpty() && res )
181 { 183 {
182 addressee.setResource( this ); 184 addressee.setResource( this );
183 addressBook()->insertAddressee( addressee ); 185 addressBook()->insertAddressee( addressee );
184 } 186 }
185 } 187 }
186 188
187 return true; 189 return true;
188} 190}
189 191
190bool ResourceQtopia::save( Ticket *ticket ) 192bool ResourceQtopia::save( Ticket *ticket )
191{ 193{
192 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 194 qDebug("ResourceQtopia::save: %s", fileName().latin1());
193 195
194 mDirWatch.stopScan(); 196 mDirWatch.stopScan();
195 197
196 KABC::AddressBook::Iterator it; 198 KABC::AddressBook::Iterator it;
197 bool res; 199 bool res;
198 200
199 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 201 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
200 PimContact c; 202 //KABC::Addressee addressee = (*it);
201 KABC::Addressee addressee = (*it); 203 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
202 204 QUuid uid( (*it).originalExternalUID() );
203 res = mConverter->addresseeToQtopia( *it, c ); 205 bool ok;
204 if (res == true) 206 PimContact c = mAccess->contactForId( uid, &ok );
205 { 207 res = mConverter->addresseeToQtopia( *it, c );
206 mAccess->addContact(c); 208 if (res == true) {
207// if (res == false) 209 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
208// qDebug("Unable to append Contact %s", c.fullName().latin1()); 210 mAccess->addContact(c);
211 KABC::Addressee addressee;
212 mConverter->qtopiaToAddressee( c, addressee );
213 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
214 addressBook()->insertAddressee( addressee );
215
216 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
217 if ( ok )
218 mAccess->removeContact(c);
219 else
220 qDebug("Error revoe contact from qtopia ");
221 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
222 if ( ok ) {
223 mAccess->updateContact(c);
224 KABC::Addressee addressee;
225 mConverter->qtopiaToAddressee( c, addressee );
226 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
227 addressBook()->insertAddressee( addressee );
228 }
229 else
230 qDebug("Error update contact from qtopia ");
231
232 }
233
234 } else {
235 qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1());
236 }
237 }
209 } 238 }
210 else
211 {
212 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
213 }
214 }
215 239
216// mAccess->addressBookUpdated(); 240 // mAccess->addressBookUpdated();
217 241
218 mDirWatch.startScan(); 242 mDirWatch.startScan();
219 243
220 delete ticket; 244 delete ticket;
221 unlock( fileName() ); 245 unlock( fileName() );
222 246
223 return true; 247 return true;
224} 248}
225 249
226bool ResourceQtopia::lock( const QString &lockfileName ) 250bool ResourceQtopia::lock( const QString &lockfileName )
227{ 251{
228 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 252 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
229 253
230 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 254 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
231 255
232 QString fn = lockfileName; 256 QString fn = lockfileName;
233 257
234 KURL url(fn); 258 KURL url(fn);
235 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 259 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
236 260
237 kdDebug(5700) << "-- lock name: " << lockName << endl; 261 kdDebug(5700) << "-- lock name: " << lockName << endl;
238 262
239 if (QFile::exists( lockName )) 263 if (QFile::exists( lockName ))
240 { 264 {
241 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 265 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
242 return false; 266 return false;
243 } 267 }
244 268
245 QString lockUniqueName; 269 QString lockUniqueName;
246 lockUniqueName = fn + KApplication::randomString( 8 ); 270 lockUniqueName = fn + KApplication::randomString( 8 );
247 271
248 url = lockUniqueName; 272 url = lockUniqueName;
249//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 273//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
250 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 274 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
251 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 275 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
252 276
253 // Create unique file 277 // Create unique file
254 QFile file( mLockUniqueName ); 278 QFile file( mLockUniqueName );
255 file.open( IO_WriteOnly ); 279 file.open( IO_WriteOnly );
256 file.close(); 280 file.close();
257 281
258 // Create lock file 282 // Create lock file
259 int result = 0; 283 int result = 0;
260#ifndef _WIN32_ 284#ifndef _WIN32_
261 result = ::link( QFile::encodeName( mLockUniqueName ), 285 result = ::link( QFile::encodeName( mLockUniqueName ),
262 QFile::encodeName( lockName ) ); 286 QFile::encodeName( lockName ) );
263#endif 287#endif
264 if ( result == 0 ) { 288 if ( result == 0 ) {
265 addressBook()->emitAddressBookLocked(); 289 addressBook()->emitAddressBookLocked();
266 return true; 290 return true;
267 } 291 }
268 292
269 // TODO: check stat 293 // TODO: check stat
270 294
271 return false; 295 return false;
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index d6482fb..b3d88de 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2707,304 +2707,339 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2707 2707
2708 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2708 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2709 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2709 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2710 fullDateRange = true; 2710 fullDateRange = true;
2711 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2711 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2712 } 2712 }
2713 } 2713 }
2714 // fullDateRange = true; // debug only! 2714 // fullDateRange = true; // debug only!
2715 if ( fullDateRange ) 2715 if ( fullDateRange )
2716 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2716 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2717 else 2717 else
2718 mLastAddressbookSync = addresseeLSync.revision(); 2718 mLastAddressbookSync = addresseeLSync.revision();
2719 // for resyncing if own file has changed 2719 // for resyncing if own file has changed
2720 // PENDING fixme later when implemented 2720 // PENDING fixme later when implemented
2721#if 0 2721#if 0
2722 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2722 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2723 mLastAddressbookSync = loadedFileVersion; 2723 mLastAddressbookSync = loadedFileVersion;
2724 qDebug("setting mLastAddressbookSync "); 2724 qDebug("setting mLastAddressbookSync ");
2725 } 2725 }
2726#endif 2726#endif
2727 2727
2728 //qDebug("*************************** "); 2728 //qDebug("*************************** ");
2729 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2729 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2730 QStringList er = remote->uidList(); 2730 QStringList er = remote->uidList();
2731 Addressee inR ;//= er.first(); 2731 Addressee inR ;//= er.first();
2732 Addressee inL; 2732 Addressee inL;
2733 QProgressBar bar( er.count(),0 ); 2733 QProgressBar bar( er.count(),0 );
2734 bar.setCaption (i18n("Syncing - close to abort!") ); 2734 bar.setCaption (i18n("Syncing - close to abort!") );
2735 2735
2736 int w = 300; 2736 int w = 300;
2737 if ( QApplication::desktop()->width() < 320 ) 2737 if ( QApplication::desktop()->width() < 320 )
2738 w = 220; 2738 w = 220;
2739 int h = bar.sizeHint().height() ; 2739 int h = bar.sizeHint().height() ;
2740 int dw = QApplication::desktop()->width(); 2740 int dw = QApplication::desktop()->width();
2741 int dh = QApplication::desktop()->height(); 2741 int dh = QApplication::desktop()->height();
2742 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2742 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2743 bar.show(); 2743 bar.show();
2744 int modulo = (er.count()/10)+1; 2744 int modulo = (er.count()/10)+1;
2745 int incCounter = 0; 2745 int incCounter = 0;
2746 while ( incCounter < er.count()) { 2746 while ( incCounter < er.count()) {
2747 if ( ! bar.isVisible() ) 2747 if ( ! bar.isVisible() )
2748 return false; 2748 return false;
2749 if ( incCounter % modulo == 0 ) 2749 if ( incCounter % modulo == 0 )
2750 bar.setProgress( incCounter ); 2750 bar.setProgress( incCounter );
2751 uid = er[ incCounter ]; 2751 uid = er[ incCounter ];
2752 bool skipIncidence = false; 2752 bool skipIncidence = false;
2753 if ( uid.left(19) == QString("last-syncAddressee-") ) 2753 if ( uid.left(19) == QString("last-syncAddressee-") )
2754 skipIncidence = true; 2754 skipIncidence = true;
2755 QString idS; 2755 QString idS,OidS;
2756 qApp->processEvents(); 2756 qApp->processEvents();
2757 if ( !skipIncidence ) { 2757 if ( !skipIncidence ) {
2758 inL = local->findByUid( uid ); 2758 inL = local->findByUid( uid );
2759 inR = remote->findByUid( uid ); 2759 inR = remote->findByUid( uid );
2760 //inL.setResource( 0 ); 2760 //inL.setResource( 0 );
2761 //inR.setResource( 0 ); 2761 //inR.setResource( 0 );
2762 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2762 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2763 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2763 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2764 //qDebug("take %d %s ", take, inL.summary().latin1()); 2764 //qDebug("take %d %s ", take, inL.summary().latin1());
2765 if ( take == 3 ) 2765 if ( take == 3 )
2766 return false; 2766 return false;
2767 if ( take == 1 ) {// take local 2767 if ( take == 1 ) {// take local
2768 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2768 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2769 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2769 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2770 local->insertAddressee( inL, false ); 2770 local->insertAddressee( inL, false );
2771 idS = inR.externalUID();
2772 OidS = inR.originalExternalUID();
2771 } 2773 }
2772 else 2774 else
2773 idS = inR.IDStr(); 2775 idS = inR.IDStr();
2774 remote->removeAddressee( inR ); 2776 remote->removeAddressee( inR );
2775 inR = inL; 2777 inR = inL;
2776 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2778 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2777 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 2779 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2780 inR.setOriginalExternalUID( OidS );
2781 inR.setExternalUID( idS );
2782 } else {
2778 inR.setIDStr( idS ); 2783 inR.setIDStr( idS );
2784 }
2779 inR.setResource( 0 ); 2785 inR.setResource( 0 );
2780 remote->insertAddressee( inR , false); 2786 remote->insertAddressee( inR , false);
2781 ++changedRemote; 2787 ++changedRemote;
2782 } else { 2788 } else { // take == 2 take remote
2783 idS = inL.IDStr(); 2789 idS = inL.IDStr();
2784 local->removeAddressee( inL ); 2790 local->removeAddressee( inL );
2785 inL = inR; 2791 inL = inR;
2786 inL.setIDStr( idS ); 2792 inL.setIDStr( idS );
2787 inL.setResource( 0 ); 2793 inL.setResource( 0 );
2788 local->insertAddressee( inL , false ); 2794 local->insertAddressee( inL , false );
2789 ++changedLocal; 2795 ++changedLocal;
2790 } 2796 }
2791 } 2797 }
2792 } else { // no conflict 2798 } else { // no conflict
2793 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2799 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2794 QString des = addresseeLSync.note(); 2800 QString des = addresseeLSync.note();
2795 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2801 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2796 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2802 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2797 remote->insertAddressee( inR, false ); 2803 remote->insertAddressee( inR, false );
2798 ++deletedAddresseeR; 2804 ++deletedAddresseeR;
2799 } else { 2805 } else {
2800 inR.setRevision( modifiedCalendar ); 2806 inR.setRevision( modifiedCalendar );
2801 remote->insertAddressee( inR, false ); 2807 remote->insertAddressee( inR, false );
2802 inL = inR; 2808 inL = inR;
2803 inL.setResource( 0 ); 2809 inL.setResource( 0 );
2804 local->insertAddressee( inL , false); 2810 local->insertAddressee( inL , false);
2805 ++addedAddressee; 2811 ++addedAddressee;
2806 } 2812 }
2807 } else { 2813 } else {
2808 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2814 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2809 inR.setRevision( modifiedCalendar ); 2815 inR.setRevision( modifiedCalendar );
2810 remote->insertAddressee( inR, false ); 2816 remote->insertAddressee( inR, false );
2811 inR.setResource( 0 ); 2817 inR.setResource( 0 );
2812 local->insertAddressee( inR, false ); 2818 local->insertAddressee( inR, false );
2813 ++addedAddressee; 2819 ++addedAddressee;
2814 } else { 2820 } else {
2815 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2821 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2816 remote->removeAddressee( inR ); 2822 remote->removeAddressee( inR );
2817 ++deletedAddresseeR; 2823 ++deletedAddresseeR;
2818 } 2824 }
2819 } 2825 }
2820 } 2826 }
2821 } 2827 }
2822 ++incCounter; 2828 ++incCounter;
2823 } 2829 }
2824 er.clear(); 2830 er.clear();
2825 QStringList el = local->uidList(); 2831 QStringList el = local->uidList();
2826 modulo = (el.count()/10)+1; 2832 modulo = (el.count()/10)+1;
2827 bar.setCaption (i18n("Add / remove addressees") ); 2833 bar.setCaption (i18n("Add / remove addressees") );
2828 bar.setTotalSteps ( el.count() ) ; 2834 bar.setTotalSteps ( el.count() ) ;
2829 bar.show(); 2835 bar.show();
2830 incCounter = 0; 2836 incCounter = 0;
2831 while ( incCounter < el.count()) { 2837 while ( incCounter < el.count()) {
2832 qApp->processEvents(); 2838 qApp->processEvents();
2833 if ( ! bar.isVisible() ) 2839 if ( ! bar.isVisible() )
2834 return false; 2840 return false;
2835 if ( incCounter % modulo == 0 ) 2841 if ( incCounter % modulo == 0 )
2836 bar.setProgress( incCounter ); 2842 bar.setProgress( incCounter );
2837 uid = el[ incCounter ]; 2843 uid = el[ incCounter ];
2838 bool skipIncidence = false; 2844 bool skipIncidence = false;
2839 if ( uid.left(19) == QString("last-syncAddressee-") ) 2845 if ( uid.left(19) == QString("last-syncAddressee-") )
2840 skipIncidence = true; 2846 skipIncidence = true;
2841 if ( !skipIncidence ) { 2847 if ( !skipIncidence ) {
2842 inL = local->findByUid( uid ); 2848 inL = local->findByUid( uid );
2843 inR = remote->findByUid( uid ); 2849 inR = remote->findByUid( uid );
2844 if ( inR.isEmpty() ) { 2850 if ( inR.isEmpty() ) {
2845 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2851 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2846 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2852 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2847 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2853 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2848 local->removeAddressee( inL ); 2854 local->removeAddressee( inL );
2849 ++deletedAddresseeL; 2855 ++deletedAddresseeL;
2850 } else { 2856 } else {
2851 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2857 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2852 inL.removeID(mCurrentSyncDevice ); 2858 inL.removeID(mCurrentSyncDevice );
2853 ++addedAddresseeR; 2859 ++addedAddresseeR;
2854 inL.setRevision( modifiedCalendar ); 2860 inL.setRevision( modifiedCalendar );
2855 local->insertAddressee( inL, false ); 2861 local->insertAddressee( inL, false );
2856 inR = inL; 2862 inR = inL;
2857 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2863 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2858 inR.setResource( 0 ); 2864 inR.setResource( 0 );
2859 remote->insertAddressee( inR, false ); 2865 remote->insertAddressee( inR, false );
2860 } 2866 }
2861 } 2867 }
2862 } else { 2868 } else {
2863 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2869 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2864 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2870 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2865 local->removeAddressee( inL ); 2871 local->removeAddressee( inL );
2866 ++deletedAddresseeL; 2872 ++deletedAddresseeL;
2867 } else { 2873 } else {
2868 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2874 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2869 ++addedAddresseeR; 2875 ++addedAddresseeR;
2870 inL.setRevision( modifiedCalendar ); 2876 inL.setRevision( modifiedCalendar );
2871 local->insertAddressee( inL, false ); 2877 local->insertAddressee( inL, false );
2872 inR = inL; 2878 inR = inL;
2873 inR.setResource( 0 ); 2879 inR.setResource( 0 );
2874 remote->insertAddressee( inR, false ); 2880 remote->insertAddressee( inR, false );
2875 } 2881 }
2876 } 2882 }
2877 } 2883 }
2878 } 2884 }
2879 } 2885 }
2880 ++incCounter; 2886 ++incCounter;
2881 } 2887 }
2882 el.clear(); 2888 el.clear();
2883 bar.hide(); 2889 bar.hide();
2884 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2890 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2885 // get rid of micro seconds 2891 // get rid of micro seconds
2886 QTime t = mLastAddressbookSync.time(); 2892 QTime t = mLastAddressbookSync.time();
2887 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2893 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2888 addresseeLSync.setRevision( mLastAddressbookSync ); 2894 addresseeLSync.setRevision( mLastAddressbookSync );
2889 addresseeRSync.setRevision( mLastAddressbookSync ); 2895 addresseeRSync.setRevision( mLastAddressbookSync );
2890 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2896 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2891 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2897 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2892 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2898 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2893 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2899 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2894 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2900 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2895 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2901 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2896 addresseeRSync.setNote( "" ) ; 2902 addresseeRSync.setNote( "" ) ;
2897 addresseeLSync.setNote( "" ); 2903 addresseeLSync.setNote( "" );
2898 2904
2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2905 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2900 remote->insertAddressee( addresseeRSync, false ); 2906 remote->insertAddressee( addresseeRSync, false );
2901 local->insertAddressee( addresseeLSync, false ); 2907 local->insertAddressee( addresseeLSync, false );
2902 QString mes; 2908 QString mes;
2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2909 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2904 if ( KABPrefs::instance()->mShowSyncSummary ) { 2910 if ( KABPrefs::instance()->mShowSyncSummary ) {
2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2911 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2906 } 2912 }
2907 qDebug( mes ); 2913 qDebug( mes );
2908 return syncOK; 2914 return syncOK;
2909} 2915}
2910 2916
2911bool KABCore::syncAB(QString filename, int mode) 2917bool KABCore::syncAB(QString filename, int mode)
2912{ 2918{
2913 2919
2914 //pending prepare addresseeview for output 2920 //pending prepare addresseeview for output
2915 //pending detect, if remote file has REV field. if not switch to external sync 2921 //pending detect, if remote file has REV field. if not switch to external sync
2916 mGlobalSyncMode = SYNC_MODE_NORMAL; 2922 mGlobalSyncMode = SYNC_MODE_NORMAL;
2917 AddressBook abLocal(filename,"syncContact"); 2923 AddressBook abLocal(filename,"syncContact");
2918 bool syncOK = false; 2924 bool syncOK = false;
2919 if ( abLocal.load() ) { 2925 if ( abLocal.load() ) {
2920 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2926 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2921 bool external = false; 2927 bool external = false;
2922 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2923 if ( ! lse.isEmpty() ) {
2924 if ( lse.familyName().left(4) == "!E: " )
2925 external = true;
2926 } else {
2927 bool found = false;
2928 QDateTime dt( QDate( 2004,1,1));
2929 AddressBook::Iterator it;
2930 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2931 if ( (*it).revision() != dt ) {
2932 found = true;
2933 break;
2934 }
2935 }
2936 external = ! found;
2937 }
2938 2928
2939 if ( external ) { 2929 if ( filename.right(4) == ".xml") {
2940 qDebug("Setting vcf mode to external ");
2941 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2930 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2942 AddressBook::Iterator it; 2931 AddressBook::Iterator it;
2943 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2932 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2944 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2933 (*it).setID( mCurrentSyncDevice, (*it).externalUID() );
2945 (*it).computeCsum( mCurrentSyncDevice ); 2934 (*it).computeCsum( mCurrentSyncDevice );
2946 } 2935 }
2936 abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice );
2937
2938 } else {
2939 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2940 if ( ! lse.isEmpty() ) {
2941 if ( lse.familyName().left(4) == "!E: " )
2942 external = true;
2943 } else {
2944 bool found = false;
2945 QDateTime dt( QDate( 2004,1,1));
2946 AddressBook::Iterator it;
2947 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2948 if ( (*it).revision() != dt ) {
2949 found = true;
2950 break;
2951 }
2952 }
2953 external = ! found;
2954 }
2955
2956 if ( external ) {
2957 qDebug("Setting vcf mode to external ");
2958 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2959 AddressBook::Iterator it;
2960 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2961 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2962 (*it).computeCsum( mCurrentSyncDevice );
2963 }
2964 }
2947 } 2965 }
2948 //AddressBook::Iterator it; 2966 //AddressBook::Iterator it;
2949 //QStringList vcards; 2967 //QStringList vcards;
2950 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2968 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2951 // qDebug("Name %s ", (*it).familyName().latin1()); 2969 // qDebug("Name %s ", (*it).familyName().latin1());
2952 //} 2970 //}
2953 if ( filename.right(4) == ".xml")
2954 abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice );
2955 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2971 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2956 if ( syncOK ) { 2972 if ( syncOK ) {
2957 if ( KABPrefs::instance()->mWriteBackFile ) 2973 if ( KABPrefs::instance()->mWriteBackFile )
2958 { 2974 {
2959 if ( external ) 2975 if ( external && filename.right(4) != ".xml")
2960 abLocal.removeDeletedAddressees(); 2976 abLocal.removeDeletedAddressees();
2961 qDebug("Saving remote AB "); 2977 qDebug("Saving remote AB ");
2962 abLocal.saveAB(); 2978 abLocal.saveAB();
2979 if ( external && filename.right(4) == ".xml") {
2980 // afterwrite processing
2981 AddressBook::Iterator it;
2982 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2983 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
2984 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
2985 Addressee ad = mAddressBook->findByUid( ( (*it).uid() ));
2986 if ( ad.isEmpty() ) {
2987 qDebug("ERROR ad empty ");
2988 } else {
2989 (*it).computeCsum( mCurrentSyncDevice );
2990 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
2991 ad.setID( mCurrentSyncDevice, (*it).externalUID() );
2992 ad.setCsum( mCurrentSyncDevice, (*it).getCsum( mCurrentSyncDevice ) );
2993 mAddressBook->insertAddressee( ad );
2994 }
2995 }
2996 }
2997 }
2963 } 2998 }
2964 } 2999 }
2965 setModified(); 3000 setModified();
2966 3001
2967 } 3002 }
2968 if ( syncOK ) 3003 if ( syncOK )
2969 mViewManager->refreshView(); 3004 mViewManager->refreshView();
2970 return syncOK; 3005 return syncOK;
2971#if 0 3006#if 0
2972 3007
2973 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 3008 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2974 getEventViewerDialog()->setSyncMode( true ); 3009 getEventViewerDialog()->setSyncMode( true );
2975 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 3010 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2976 getEventViewerDialog()->setSyncMode( false ); 3011 getEventViewerDialog()->setSyncMode( false );
2977 if ( syncOK ) { 3012 if ( syncOK ) {
2978 if ( KOPrefs::instance()->mWriteBackFile ) 3013 if ( KOPrefs::instance()->mWriteBackFile )
2979 { 3014 {
2980 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 3015 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2981 storage->save(); 3016 storage->save();
2982 } 3017 }
2983 } 3018 }
2984 setModified(); 3019 setModified();
2985 } 3020 }
2986 3021
2987#endif 3022#endif
2988} 3023}
2989 3024
2990void KABCore::confSync() 3025void KABCore::confSync()
2991{ 3026{
2992 static KSyncPrefsDialog* sp = 0; 3027 static KSyncPrefsDialog* sp = 0;
2993 if ( ! sp ) { 3028 if ( ! sp ) {
2994 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 3029 sp = new KSyncPrefsDialog( this, "syncprefs", true );
2995 } 3030 }
2996 sp->usrReadConfig(); 3031 sp->usrReadConfig();
2997#ifndef DESKTOP_VERSION 3032#ifndef DESKTOP_VERSION
2998 sp->showMaximized(); 3033 sp->showMaximized();
2999#else 3034#else
3000 sp->show(); 3035 sp->show();
3001#endif 3036#endif
3002 sp->exec(); 3037 sp->exec();
3003 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 3038 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
3004 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 3039 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
3005 fillSyncMenu(); 3040 fillSyncMenu();
3006} 3041}
3007void KABCore::syncSharp() 3042void KABCore::syncSharp()
3008{ 3043{
3009 if ( mModified ) 3044 if ( mModified )
3010 save(); 3045 save();
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index e7fc670..d56eab6 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -501,99 +501,99 @@ bool SharpFormat::save( Calendar *calendar)
501 status.setCaption(i18n("Writing DTM Data") ); 501 status.setCaption(i18n("Writing DTM Data") );
502 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 502 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
503 status.show(); 503 status.show();
504 status.raise(); 504 status.raise();
505 qApp->processEvents(); 505 qApp->processEvents();
506 bool debug = DEBUGMODE; 506 bool debug = DEBUGMODE;
507 QString codec = "utf8"; 507 QString codec = "utf8";
508 QString answer; 508 QString answer;
509 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 509 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
510 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 510 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
511 QString command; 511 QString command;
512 QPtrList<Event> er = calendar->rawEvents(); 512 QPtrList<Event> er = calendar->rawEvents();
513 Event* ev = er.first(); 513 Event* ev = er.first();
514 QString fileName = "/tmp/kopitempout"; 514 QString fileName = "/tmp/kopitempout";
515 int i = 0; 515 int i = 0;
516 QString changeString = ePrefix; 516 QString changeString = ePrefix;
517 QString deleteString = ePrefix; 517 QString deleteString = ePrefix;
518 bool deleteEnt = false; 518 bool deleteEnt = false;
519 bool changeEnt = false; 519 bool changeEnt = false;
520 QString message = i18n("Processing event # "); 520 QString message = i18n("Processing event # ");
521 int procCount = 0; 521 int procCount = 0;
522 while ( ev ) { 522 while ( ev ) {
523 //qDebug("i %d ", ++i); 523 //qDebug("i %d ", ++i);
524 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 524 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
525 status.setText ( message + QString::number ( ++procCount ) ); 525 status.setText ( message + QString::number ( ++procCount ) );
526 qApp->processEvents(); 526 qApp->processEvents();
527 QString eString = getEventString( ev ); 527 QString eString = getEventString( ev );
528 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 528 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
529 // deleting empty strings does not work. 529 // deleting empty strings does not work.
530 // we write first and x and then delete the record with the x 530 // we write first and x and then delete the record with the x
531 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 531 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
532 changeString += eString + "\n"; 532 changeString += eString + "\n";
533 deleteString += eString + "\n"; 533 deleteString += eString + "\n";
534 deleteEnt = true; 534 deleteEnt = true;
535 changeEnt = true; 535 changeEnt = true;
536 } 536 }
537 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 537 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
538 QString fileNameIn = "/tmp/kopitempin"; 538 QString fileNameIn = "/tmp/kopitempin";
539 QFile fileIn( fileNameIn ); 539 QFile fileIn( fileNameIn );
540 if (!fileIn.open( IO_WriteOnly ) ) { 540 if (!fileIn.open( IO_WriteOnly ) ) {
541 return false; 541 return false;
542 } 542 }
543 QTextStream tsIn( &fileIn ); 543 QTextStream tsIn( &fileIn );
544 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 544 tsIn.setCodec( QTextCodec::codecForName("utf8") );
545 tsIn << ePrefix << eString ; 545 tsIn << ePrefix << eString ;
546 fileIn.close(); 546 fileIn.close();
547 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 547 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
548 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; 548 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName;
549 qDebug("command ++++++++ "); 549 //qDebug("command ++++++++ ");
550 qDebug("%s ",command.latin1()); 550 //qDebug("%s ",command.latin1());
551 qDebug("command -------- "); 551 //qDebug("command -------- ");
552 system ( command.utf8() ); 552 system ( command.utf8() );
553 QFile file( fileName ); 553 QFile file( fileName );
554 if (!file.open( IO_ReadOnly ) ) { 554 if (!file.open( IO_ReadOnly ) ) {
555 return false; 555 return false;
556 556
557 } 557 }
558 QTextStream ts( &file ); 558 QTextStream ts( &file );
559 ts.setCodec( QTextCodec::codecForName("utf8") ); 559 ts.setCodec( QTextCodec::codecForName("utf8") );
560 answer = ts.read(); 560 answer = ts.read();
561 file.close(); 561 file.close();
562 //qDebug("answer \n%s ", answer.latin1()); 562 //qDebug("answer \n%s ", answer.latin1());
563 getNumFromRecord( answer, ev ) ; 563 getNumFromRecord( answer, ev ) ;
564 564
565 } 565 }
566 else { // change existing 566 else { // change existing
567 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 567 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
568 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 568 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
569 changeString += eString + "\n"; 569 changeString += eString + "\n";
570 changeEnt = true; 570 changeEnt = true;
571 571
572 } 572 }
573 } 573 }
574 ev = er.next(); 574 ev = er.next();
575 } 575 }
576 status.setText ( i18n("Changing events ...") ); 576 status.setText ( i18n("Changing events ...") );
577 qApp->processEvents(); 577 qApp->processEvents();
578 //qDebug("changing... "); 578 //qDebug("changing... ");
579 if ( changeEnt ) { 579 if ( changeEnt ) {
580 QFile file( fileName ); 580 QFile file( fileName );
581 if (!file.open( IO_WriteOnly ) ) { 581 if (!file.open( IO_WriteOnly ) ) {
582 return false; 582 return false;
583 583
584 } 584 }
585 QTextStream ts( &file ); 585 QTextStream ts( &file );
586 ts.setCodec( QTextCodec::codecForName("utf8") ); 586 ts.setCodec( QTextCodec::codecForName("utf8") );
587 ts << changeString ; 587 ts << changeString ;
588 file.close(); 588 file.close();
589 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 589 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
590 system ( command.latin1() ); 590 system ( command.latin1() );
591 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 591 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
592 592
593 } 593 }
594 status.setText ( i18n("Deleting events ...") ); 594 status.setText ( i18n("Deleting events ...") );
595 qApp->processEvents(); 595 qApp->processEvents();
596 //qDebug("deleting... "); 596 //qDebug("deleting... ");
597 if ( deleteEnt ) { 597 if ( deleteEnt ) {
598 QFile file( fileName ); 598 QFile file( fileName );
599 if (!file.open( IO_WriteOnly ) ) { 599 if (!file.open( IO_WriteOnly ) ) {
diff --git a/libkcal/syncdefines.h b/libkcal/syncdefines.h
index 57642ec..704a670 100644
--- a/libkcal/syncdefines.h
+++ b/libkcal/syncdefines.h
@@ -1,22 +1,24 @@
1 1
2#ifndef _KSYNC_DEFINES_H_ 2#ifndef _KSYNC_DEFINES_H_
3#define _KSYNC_DEFINES_H_ 3#define _KSYNC_DEFINES_H_
4 4
5#define SYNC_PREF_LOCAL 0 5#define SYNC_PREF_LOCAL 0
6#define SYNC_PREF_REMOTE 1 6#define SYNC_PREF_REMOTE 1
7#define SYNC_PREF_NEWEST 2 7#define SYNC_PREF_NEWEST 2
8#define SYNC_PREF_ASK 3 8#define SYNC_PREF_ASK 3
9#define SYNC_PREF_FORCE_LOCAL 4 9#define SYNC_PREF_FORCE_LOCAL 4
10#define SYNC_PREF_FORCE_REMOTE 5 10#define SYNC_PREF_FORCE_REMOTE 5
11#define SYNC_PREF_TAKE_BOTH 6 11#define SYNC_PREF_TAKE_BOTH 6
12 12
13#define SYNC_MODE_NORMAL 0 13#define SYNC_MODE_NORMAL 0
14#define SYNC_MODE_EXTERNAL 1 14#define SYNC_MODE_EXTERNAL 1
15 15
16#define SYNC_TEMPSTATE_INITIAL 0 16#define SYNC_TEMPSTATE_INITIAL 0
17#define SYNC_TEMPSTATE_ADDED_EXTERNAL -1
17#define SYNC_TEMPSTATE_NEW_EXTERNAL -2 18#define SYNC_TEMPSTATE_NEW_EXTERNAL -2
18#define SYNC_TEMPSTATE_DELETE -3 19#define SYNC_TEMPSTATE_DELETE -3
19#define SYNC_TEMPSTATE_NEW_ID -4 20#define SYNC_TEMPSTATE_NEW_ID -4
21#define SYNC_TEMPSTATE_NEW_CSUM -5
20 22
21 23
22#endif 24#endif