author | zautrix <zautrix> | 2004-10-07 12:19:25 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-07 12:19:25 (UTC) |
commit | 826dc960353e47a60aba13916189c45ef3392c1e (patch) (unidiff) | |
tree | 52ef4058d7a1fa8d77e678391ed9165009634182 | |
parent | 43c82cc5393522d2c34f34a4339cb6a1d1c6c555 (diff) | |
download | kdepimpi-826dc960353e47a60aba13916189c45ef3392c1e.zip kdepimpi-826dc960353e47a60aba13916189c45ef3392c1e.tar.gz kdepimpi-826dc960353e47a60aba13916189c45ef3392c1e.tar.bz2 |
sync fixes
-rw-r--r-- | kabc/addressbook.cpp | 1 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 2 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 2 |
3 files changed, 2 insertions, 3 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 295cf03..03a86f9 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -33,769 +33,768 @@ $Id$ | |||
33 | 33 | ||
34 | #include <kapplication.h> | 34 | #include <kapplication.h> |
35 | #include <kinstance.h> | 35 | #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | 37 | ||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qfile.h> | 42 | #include <qfile.h> |
43 | 43 | ||
44 | #include <kglobal.h> | 44 | #include <kglobal.h> |
45 | #include <klocale.h>> | 45 | #include <klocale.h>> |
46 | #include <kmessagebox.h> | 46 | #include <kmessagebox.h> |
47 | #include <kdebug.h> | 47 | #include <kdebug.h> |
48 | #include <libkcal/syncdefines.h> | 48 | #include <libkcal/syncdefines.h> |
49 | #include "addressbook.h" | 49 | #include "addressbook.h" |
50 | #include "resource.h" | 50 | #include "resource.h" |
51 | #include "vcardconverter.h" | 51 | #include "vcardconverter.h" |
52 | #include "vcardparser/vcardtool.h" | 52 | #include "vcardparser/vcardtool.h" |
53 | 53 | ||
54 | //US #include "addressbook.moc" | 54 | //US #include "addressbook.moc" |
55 | 55 | ||
56 | using namespace KABC; | 56 | using namespace KABC; |
57 | 57 | ||
58 | struct AddressBook::AddressBookData | 58 | struct AddressBook::AddressBookData |
59 | { | 59 | { |
60 | Addressee::List mAddressees; | 60 | Addressee::List mAddressees; |
61 | Addressee::List mRemovedAddressees; | 61 | Addressee::List mRemovedAddressees; |
62 | Field::List mAllFields; | 62 | Field::List mAllFields; |
63 | KConfig *mConfig; | 63 | KConfig *mConfig; |
64 | KRES::Manager<Resource> *mManager; | 64 | KRES::Manager<Resource> *mManager; |
65 | //US ErrorHandler *mErrorHandler; | 65 | //US ErrorHandler *mErrorHandler; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct AddressBook::Iterator::IteratorData | 68 | struct AddressBook::Iterator::IteratorData |
69 | { | 69 | { |
70 | Addressee::List::Iterator mIt; | 70 | Addressee::List::Iterator mIt; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | struct AddressBook::ConstIterator::ConstIteratorData | 73 | struct AddressBook::ConstIterator::ConstIteratorData |
74 | { | 74 | { |
75 | Addressee::List::ConstIterator mIt; | 75 | Addressee::List::ConstIterator mIt; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | AddressBook::Iterator::Iterator() | 78 | AddressBook::Iterator::Iterator() |
79 | { | 79 | { |
80 | d = new IteratorData; | 80 | d = new IteratorData; |
81 | } | 81 | } |
82 | 82 | ||
83 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 83 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
84 | { | 84 | { |
85 | d = new IteratorData; | 85 | d = new IteratorData; |
86 | d->mIt = i.d->mIt; | 86 | d->mIt = i.d->mIt; |
87 | } | 87 | } |
88 | 88 | ||
89 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 89 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
90 | { | 90 | { |
91 | if( this == &i ) return *this; // guard against self assignment | 91 | if( this == &i ) return *this; // guard against self assignment |
92 | delete d; // delete the old data the Iterator was completely constructed before | 92 | delete d; // delete the old data the Iterator was completely constructed before |
93 | d = new IteratorData; | 93 | d = new IteratorData; |
94 | d->mIt = i.d->mIt; | 94 | d->mIt = i.d->mIt; |
95 | return *this; | 95 | return *this; |
96 | } | 96 | } |
97 | 97 | ||
98 | AddressBook::Iterator::~Iterator() | 98 | AddressBook::Iterator::~Iterator() |
99 | { | 99 | { |
100 | delete d; | 100 | delete d; |
101 | } | 101 | } |
102 | 102 | ||
103 | const Addressee &AddressBook::Iterator::operator*() const | 103 | const Addressee &AddressBook::Iterator::operator*() const |
104 | { | 104 | { |
105 | return *(d->mIt); | 105 | return *(d->mIt); |
106 | } | 106 | } |
107 | 107 | ||
108 | Addressee &AddressBook::Iterator::operator*() | 108 | Addressee &AddressBook::Iterator::operator*() |
109 | { | 109 | { |
110 | return *(d->mIt); | 110 | return *(d->mIt); |
111 | } | 111 | } |
112 | 112 | ||
113 | Addressee *AddressBook::Iterator::operator->() | 113 | Addressee *AddressBook::Iterator::operator->() |
114 | { | 114 | { |
115 | return &(*(d->mIt)); | 115 | return &(*(d->mIt)); |
116 | } | 116 | } |
117 | 117 | ||
118 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 118 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
119 | { | 119 | { |
120 | (d->mIt)++; | 120 | (d->mIt)++; |
121 | return *this; | 121 | return *this; |
122 | } | 122 | } |
123 | 123 | ||
124 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 124 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
125 | { | 125 | { |
126 | (d->mIt)++; | 126 | (d->mIt)++; |
127 | return *this; | 127 | return *this; |
128 | } | 128 | } |
129 | 129 | ||
130 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 130 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
131 | { | 131 | { |
132 | (d->mIt)--; | 132 | (d->mIt)--; |
133 | return *this; | 133 | return *this; |
134 | } | 134 | } |
135 | 135 | ||
136 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 136 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
137 | { | 137 | { |
138 | (d->mIt)--; | 138 | (d->mIt)--; |
139 | return *this; | 139 | return *this; |
140 | } | 140 | } |
141 | 141 | ||
142 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 142 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
143 | { | 143 | { |
144 | return ( d->mIt == it.d->mIt ); | 144 | return ( d->mIt == it.d->mIt ); |
145 | } | 145 | } |
146 | 146 | ||
147 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 147 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
148 | { | 148 | { |
149 | return ( d->mIt != it.d->mIt ); | 149 | return ( d->mIt != it.d->mIt ); |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | ||
153 | AddressBook::ConstIterator::ConstIterator() | 153 | AddressBook::ConstIterator::ConstIterator() |
154 | { | 154 | { |
155 | d = new ConstIteratorData; | 155 | d = new ConstIteratorData; |
156 | } | 156 | } |
157 | 157 | ||
158 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 158 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
159 | { | 159 | { |
160 | d = new ConstIteratorData; | 160 | d = new ConstIteratorData; |
161 | d->mIt = i.d->mIt; | 161 | d->mIt = i.d->mIt; |
162 | } | 162 | } |
163 | 163 | ||
164 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 164 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
165 | { | 165 | { |
166 | if( this == &i ) return *this; // guard for self assignment | 166 | if( this == &i ) return *this; // guard for self assignment |
167 | delete d; // delete the old data because the Iterator was really constructed before | 167 | delete d; // delete the old data because the Iterator was really constructed before |
168 | d = new ConstIteratorData; | 168 | d = new ConstIteratorData; |
169 | d->mIt = i.d->mIt; | 169 | d->mIt = i.d->mIt; |
170 | return *this; | 170 | return *this; |
171 | } | 171 | } |
172 | 172 | ||
173 | AddressBook::ConstIterator::~ConstIterator() | 173 | AddressBook::ConstIterator::~ConstIterator() |
174 | { | 174 | { |
175 | delete d; | 175 | delete d; |
176 | } | 176 | } |
177 | 177 | ||
178 | const Addressee &AddressBook::ConstIterator::operator*() const | 178 | const Addressee &AddressBook::ConstIterator::operator*() const |
179 | { | 179 | { |
180 | return *(d->mIt); | 180 | return *(d->mIt); |
181 | } | 181 | } |
182 | 182 | ||
183 | const Addressee* AddressBook::ConstIterator::operator->() const | 183 | const Addressee* AddressBook::ConstIterator::operator->() const |
184 | { | 184 | { |
185 | return &(*(d->mIt)); | 185 | return &(*(d->mIt)); |
186 | } | 186 | } |
187 | 187 | ||
188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
189 | { | 189 | { |
190 | (d->mIt)++; | 190 | (d->mIt)++; |
191 | return *this; | 191 | return *this; |
192 | } | 192 | } |
193 | 193 | ||
194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
195 | { | 195 | { |
196 | (d->mIt)++; | 196 | (d->mIt)++; |
197 | return *this; | 197 | return *this; |
198 | } | 198 | } |
199 | 199 | ||
200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
201 | { | 201 | { |
202 | (d->mIt)--; | 202 | (d->mIt)--; |
203 | return *this; | 203 | return *this; |
204 | } | 204 | } |
205 | 205 | ||
206 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 206 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
207 | { | 207 | { |
208 | (d->mIt)--; | 208 | (d->mIt)--; |
209 | return *this; | 209 | return *this; |
210 | } | 210 | } |
211 | 211 | ||
212 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 212 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
213 | { | 213 | { |
214 | return ( d->mIt == it.d->mIt ); | 214 | return ( d->mIt == it.d->mIt ); |
215 | } | 215 | } |
216 | 216 | ||
217 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 217 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
218 | { | 218 | { |
219 | return ( d->mIt != it.d->mIt ); | 219 | return ( d->mIt != it.d->mIt ); |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | AddressBook::AddressBook() | 223 | AddressBook::AddressBook() |
224 | { | 224 | { |
225 | init(0, "contact"); | 225 | init(0, "contact"); |
226 | } | 226 | } |
227 | 227 | ||
228 | AddressBook::AddressBook( const QString &config ) | 228 | AddressBook::AddressBook( const QString &config ) |
229 | { | 229 | { |
230 | init(config, "contact"); | 230 | init(config, "contact"); |
231 | } | 231 | } |
232 | 232 | ||
233 | AddressBook::AddressBook( const QString &config, const QString &family ) | 233 | AddressBook::AddressBook( const QString &config, const QString &family ) |
234 | { | 234 | { |
235 | init(config, family); | 235 | init(config, family); |
236 | 236 | ||
237 | } | 237 | } |
238 | 238 | ||
239 | // the default family is "contact" | 239 | // the default family is "contact" |
240 | void AddressBook::init(const QString &config, const QString &family ) | 240 | void AddressBook::init(const QString &config, const QString &family ) |
241 | { | 241 | { |
242 | blockLSEchange = false; | 242 | blockLSEchange = false; |
243 | d = new AddressBookData; | 243 | d = new AddressBookData; |
244 | QString fami = family; | 244 | QString fami = family; |
245 | if (config != 0) { | 245 | if (config != 0) { |
246 | if ( family == "syncContact" ) { | 246 | if ( family == "syncContact" ) { |
247 | qDebug("creating sync config "); | 247 | qDebug("creating sync config "); |
248 | fami = "contact"; | 248 | fami = "contact"; |
249 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 249 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
250 | con->setGroup( "General" ); | 250 | con->setGroup( "General" ); |
251 | con->writeEntry( "ResourceKeys", QString("sync") ); | 251 | con->writeEntry( "ResourceKeys", QString("sync") ); |
252 | con->writeEntry( "Standard", QString("sync") ); | 252 | con->writeEntry( "Standard", QString("sync") ); |
253 | con->setGroup( "Resource_sync" ); | 253 | con->setGroup( "Resource_sync" ); |
254 | con->writeEntry( "FileName", config ); | 254 | con->writeEntry( "FileName", config ); |
255 | con->writeEntry( "FileFormat", QString("vcard") ); | 255 | con->writeEntry( "FileFormat", QString("vcard") ); |
256 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 256 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
257 | con->writeEntry( "ResourceName", QString("sync_res") ); | 257 | con->writeEntry( "ResourceName", QString("sync_res") ); |
258 | if ( config.right(4) == ".xml" ) | 258 | if ( config.right(4) == ".xml" ) |
259 | con->writeEntry( "ResourceType", QString("qtopia") ); | 259 | con->writeEntry( "ResourceType", QString("qtopia") ); |
260 | else if ( config == "sharp" ) { | 260 | else if ( config == "sharp" ) { |
261 | con->writeEntry( "ResourceType", QString("sharp") ); | 261 | con->writeEntry( "ResourceType", QString("sharp") ); |
262 | } else { | 262 | } else { |
263 | con->writeEntry( "ResourceType", QString("file") ); | 263 | con->writeEntry( "ResourceType", QString("file") ); |
264 | } | 264 | } |
265 | //con->sync(); | 265 | //con->sync(); |
266 | d->mConfig = con; | 266 | d->mConfig = con; |
267 | } | 267 | } |
268 | else | 268 | else |
269 | d->mConfig = new KConfig( locateLocal("config", config) ); | 269 | d->mConfig = new KConfig( locateLocal("config", config) ); |
270 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 270 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
271 | } | 271 | } |
272 | else { | 272 | else { |
273 | d->mConfig = 0; | 273 | d->mConfig = 0; |
274 | // qDebug("AddressBook::init 1 config=0"); | 274 | // qDebug("AddressBook::init 1 config=0"); |
275 | } | 275 | } |
276 | 276 | ||
277 | //US d->mErrorHandler = 0; | 277 | //US d->mErrorHandler = 0; |
278 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 278 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
279 | d->mManager->readConfig( d->mConfig ); | 279 | d->mManager->readConfig( d->mConfig ); |
280 | if ( family == "syncContact" ) { | 280 | if ( family == "syncContact" ) { |
281 | KRES::Manager<Resource> *manager = d->mManager; | 281 | KRES::Manager<Resource> *manager = d->mManager; |
282 | KRES::Manager<Resource>::ActiveIterator it; | 282 | KRES::Manager<Resource>::ActiveIterator it; |
283 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 283 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
284 | (*it)->setAddressBook( this ); | 284 | (*it)->setAddressBook( this ); |
285 | if ( !(*it)->open() ) | 285 | if ( !(*it)->open() ) |
286 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 286 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
287 | } | 287 | } |
288 | Resource *res = standardResource(); | 288 | Resource *res = standardResource(); |
289 | if ( !res ) { | 289 | if ( !res ) { |
290 | qDebug("ERROR: no standard resource"); | 290 | qDebug("ERROR: no standard resource"); |
291 | res = manager->createResource( "file" ); | 291 | res = manager->createResource( "file" ); |
292 | if ( res ) | 292 | if ( res ) |
293 | { | 293 | { |
294 | addResource( res ); | 294 | addResource( res ); |
295 | } | 295 | } |
296 | else | 296 | else |
297 | qDebug(" No resource available!!!"); | 297 | qDebug(" No resource available!!!"); |
298 | } | 298 | } |
299 | setStandardResource( res ); | 299 | setStandardResource( res ); |
300 | manager->writeConfig(); | 300 | manager->writeConfig(); |
301 | } | 301 | } |
302 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 302 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
303 | "X-Department", "KADDRESSBOOK" ); | 303 | "X-Department", "KADDRESSBOOK" ); |
304 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
305 | "X-Profession", "KADDRESSBOOK" ); | 305 | "X-Profession", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
307 | "X-AssistantsName", "KADDRESSBOOK" ); | 307 | "X-AssistantsName", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
309 | "X-ManagersName", "KADDRESSBOOK" ); | 309 | "X-ManagersName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 310 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
311 | "X-SpousesName", "KADDRESSBOOK" ); | 311 | "X-SpousesName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
313 | "X-Office", "KADDRESSBOOK" ); | 313 | "X-Office", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
315 | "X-IMAddress", "KADDRESSBOOK" ); | 315 | "X-IMAddress", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
317 | "X-Anniversary", "KADDRESSBOOK" ); | 317 | "X-Anniversary", "KADDRESSBOOK" ); |
318 | 318 | ||
319 | //US added this field to become compatible with Opie/qtopia addressbook | 319 | //US added this field to become compatible with Opie/qtopia addressbook |
320 | // values can be "female" or "male" or "". An empty field represents undefined. | 320 | // values can be "female" or "male" or "". An empty field represents undefined. |
321 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 321 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
322 | "X-Gender", "KADDRESSBOOK" ); | 322 | "X-Gender", "KADDRESSBOOK" ); |
323 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
324 | "X-Children", "KADDRESSBOOK" ); | 324 | "X-Children", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
326 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 326 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
328 | "X-ExternalID", "KADDRESSBOOK" ); | 328 | "X-ExternalID", "KADDRESSBOOK" ); |
329 | } | 329 | } |
330 | 330 | ||
331 | AddressBook::~AddressBook() | 331 | AddressBook::~AddressBook() |
332 | { | 332 | { |
333 | delete d->mConfig; d->mConfig = 0; | 333 | delete d->mConfig; d->mConfig = 0; |
334 | delete d->mManager; d->mManager = 0; | 334 | delete d->mManager; d->mManager = 0; |
335 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 335 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
336 | delete d; d = 0; | 336 | delete d; d = 0; |
337 | } | 337 | } |
338 | 338 | ||
339 | bool AddressBook::load() | 339 | bool AddressBook::load() |
340 | { | 340 | { |
341 | 341 | ||
342 | 342 | ||
343 | clear(); | 343 | clear(); |
344 | 344 | ||
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } | 351 | } |
352 | 352 | ||
353 | // mark all addressees as unchanged | 353 | // mark all addressees as unchanged |
354 | Addressee::List::Iterator addrIt; | 354 | Addressee::List::Iterator addrIt; |
355 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 355 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
356 | (*addrIt).setChanged( false ); | 356 | (*addrIt).setChanged( false ); |
357 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 357 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
358 | if ( !id.isEmpty() ) { | 358 | if ( !id.isEmpty() ) { |
359 | //qDebug("setId aa %s ", id.latin1()); | 359 | //qDebug("setId aa %s ", id.latin1()); |
360 | (*addrIt).setIDStr(id ); | 360 | (*addrIt).setIDStr(id ); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | blockLSEchange = true; | 363 | blockLSEchange = true; |
364 | return ok; | 364 | return ok; |
365 | } | 365 | } |
366 | 366 | ||
367 | bool AddressBook::save( Ticket *ticket ) | 367 | bool AddressBook::save( Ticket *ticket ) |
368 | { | 368 | { |
369 | kdDebug(5700) << "AddressBook::save()"<< endl; | 369 | kdDebug(5700) << "AddressBook::save()"<< endl; |
370 | 370 | ||
371 | if ( ticket->resource() ) { | 371 | if ( ticket->resource() ) { |
372 | deleteRemovedAddressees(); | 372 | deleteRemovedAddressees(); |
373 | return ticket->resource()->save( ticket ); | 373 | return ticket->resource()->save( ticket ); |
374 | } | 374 | } |
375 | 375 | ||
376 | return false; | 376 | return false; |
377 | } | 377 | } |
378 | void AddressBook::export2File( QString fileName ) | 378 | void AddressBook::export2File( QString fileName ) |
379 | { | 379 | { |
380 | 380 | ||
381 | QFile outFile( fileName ); | 381 | QFile outFile( fileName ); |
382 | if ( !outFile.open( IO_WriteOnly ) ) { | 382 | if ( !outFile.open( IO_WriteOnly ) ) { |
383 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 383 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
384 | KMessageBox::error( 0, text.arg( fileName ) ); | 384 | KMessageBox::error( 0, text.arg( fileName ) ); |
385 | return ; | 385 | return ; |
386 | } | 386 | } |
387 | QTextStream t( &outFile ); | 387 | QTextStream t( &outFile ); |
388 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 388 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
389 | Iterator it; | 389 | Iterator it; |
390 | KABC::VCardConverter::Version version; | 390 | KABC::VCardConverter::Version version; |
391 | version = KABC::VCardConverter::v3_0; | 391 | version = KABC::VCardConverter::v3_0; |
392 | for ( it = begin(); it != end(); ++it ) { | 392 | for ( it = begin(); it != end(); ++it ) { |
393 | if ( !(*it).IDStr().isEmpty() ) { | 393 | if ( !(*it).IDStr().isEmpty() ) { |
394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
395 | } | 395 | } |
396 | KABC::VCardConverter converter; | 396 | KABC::VCardConverter converter; |
397 | QString vcard; | 397 | QString vcard; |
398 | //Resource *resource() const; | 398 | //Resource *resource() const; |
399 | converter.addresseeToVCard( *it, vcard, version ); | 399 | converter.addresseeToVCard( *it, vcard, version ); |
400 | t << vcard << "\r\n"; | 400 | t << vcard << "\r\n"; |
401 | } | 401 | } |
402 | outFile.close(); | 402 | outFile.close(); |
403 | } | 403 | } |
404 | void AddressBook::importFromFile( QString fileName ) | 404 | void AddressBook::importFromFile( QString fileName ) |
405 | { | 405 | { |
406 | 406 | ||
407 | KABC::Addressee::List list; | 407 | KABC::Addressee::List list; |
408 | QFile file( fileName ); | 408 | QFile file( fileName ); |
409 | 409 | ||
410 | file.open( IO_ReadOnly ); | 410 | file.open( IO_ReadOnly ); |
411 | QByteArray rawData = file.readAll(); | 411 | QByteArray rawData = file.readAll(); |
412 | file.close(); | 412 | file.close(); |
413 | 413 | ||
414 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 414 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
415 | KABC::VCardTool tool; | 415 | KABC::VCardTool tool; |
416 | list = tool.parseVCards( data ); | 416 | list = tool.parseVCards( data ); |
417 | |||
418 | KABC::Addressee::List::Iterator it; | 417 | KABC::Addressee::List::Iterator it; |
419 | for ( it = list.begin(); it != list.end(); ++it ) { | 418 | for ( it = list.begin(); it != list.end(); ++it ) { |
420 | (*it).setResource( 0 ); | 419 | (*it).setResource( 0 ); |
421 | insertAddressee( (*it), false, true ); | 420 | insertAddressee( (*it), false, true ); |
422 | } | 421 | } |
423 | 422 | ||
424 | } | 423 | } |
425 | 424 | ||
426 | bool AddressBook::saveAB() | 425 | bool AddressBook::saveAB() |
427 | { | 426 | { |
428 | bool ok = true; | 427 | bool ok = true; |
429 | 428 | ||
430 | deleteRemovedAddressees(); | 429 | deleteRemovedAddressees(); |
431 | Iterator ait; | 430 | Iterator ait; |
432 | for ( ait = begin(); ait != end(); ++ait ) { | 431 | for ( ait = begin(); ait != end(); ++ait ) { |
433 | if ( !(*ait).IDStr().isEmpty() ) { | 432 | if ( !(*ait).IDStr().isEmpty() ) { |
434 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 433 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
435 | } | 434 | } |
436 | } | 435 | } |
437 | KRES::Manager<Resource>::ActiveIterator it; | 436 | KRES::Manager<Resource>::ActiveIterator it; |
438 | KRES::Manager<Resource> *manager = d->mManager; | 437 | KRES::Manager<Resource> *manager = d->mManager; |
439 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 438 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
440 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 439 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
441 | Ticket *ticket = requestSaveTicket( *it ); | 440 | Ticket *ticket = requestSaveTicket( *it ); |
442 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 441 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
443 | if ( !ticket ) { | 442 | if ( !ticket ) { |
444 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 443 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
445 | .arg( (*it)->resourceName() ) ); | 444 | .arg( (*it)->resourceName() ) ); |
446 | return false; | 445 | return false; |
447 | } | 446 | } |
448 | 447 | ||
449 | //if ( !save( ticket ) ) | 448 | //if ( !save( ticket ) ) |
450 | if ( ticket->resource() ) { | 449 | if ( ticket->resource() ) { |
451 | if ( ! ticket->resource()->save( ticket ) ) | 450 | if ( ! ticket->resource()->save( ticket ) ) |
452 | ok = false; | 451 | ok = false; |
453 | } else | 452 | } else |
454 | ok = false; | 453 | ok = false; |
455 | 454 | ||
456 | } | 455 | } |
457 | } | 456 | } |
458 | return ok; | 457 | return ok; |
459 | } | 458 | } |
460 | 459 | ||
461 | AddressBook::Iterator AddressBook::begin() | 460 | AddressBook::Iterator AddressBook::begin() |
462 | { | 461 | { |
463 | Iterator it = Iterator(); | 462 | Iterator it = Iterator(); |
464 | it.d->mIt = d->mAddressees.begin(); | 463 | it.d->mIt = d->mAddressees.begin(); |
465 | return it; | 464 | return it; |
466 | } | 465 | } |
467 | 466 | ||
468 | AddressBook::ConstIterator AddressBook::begin() const | 467 | AddressBook::ConstIterator AddressBook::begin() const |
469 | { | 468 | { |
470 | ConstIterator it = ConstIterator(); | 469 | ConstIterator it = ConstIterator(); |
471 | it.d->mIt = d->mAddressees.begin(); | 470 | it.d->mIt = d->mAddressees.begin(); |
472 | return it; | 471 | return it; |
473 | } | 472 | } |
474 | 473 | ||
475 | AddressBook::Iterator AddressBook::end() | 474 | AddressBook::Iterator AddressBook::end() |
476 | { | 475 | { |
477 | Iterator it = Iterator(); | 476 | Iterator it = Iterator(); |
478 | it.d->mIt = d->mAddressees.end(); | 477 | it.d->mIt = d->mAddressees.end(); |
479 | return it; | 478 | return it; |
480 | } | 479 | } |
481 | 480 | ||
482 | AddressBook::ConstIterator AddressBook::end() const | 481 | AddressBook::ConstIterator AddressBook::end() const |
483 | { | 482 | { |
484 | ConstIterator it = ConstIterator(); | 483 | ConstIterator it = ConstIterator(); |
485 | it.d->mIt = d->mAddressees.end(); | 484 | it.d->mIt = d->mAddressees.end(); |
486 | return it; | 485 | return it; |
487 | } | 486 | } |
488 | 487 | ||
489 | void AddressBook::clear() | 488 | void AddressBook::clear() |
490 | { | 489 | { |
491 | d->mAddressees.clear(); | 490 | d->mAddressees.clear(); |
492 | } | 491 | } |
493 | 492 | ||
494 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 493 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
495 | { | 494 | { |
496 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 495 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
497 | 496 | ||
498 | if ( !resource ) | 497 | if ( !resource ) |
499 | { | 498 | { |
500 | qDebug("AddressBook::requestSaveTicket no resource" ); | 499 | qDebug("AddressBook::requestSaveTicket no resource" ); |
501 | resource = standardResource(); | 500 | resource = standardResource(); |
502 | } | 501 | } |
503 | 502 | ||
504 | KRES::Manager<Resource>::ActiveIterator it; | 503 | KRES::Manager<Resource>::ActiveIterator it; |
505 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 504 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
506 | if ( (*it) == resource ) { | 505 | if ( (*it) == resource ) { |
507 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 506 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
508 | return 0; | 507 | return 0; |
509 | else | 508 | else |
510 | return (*it)->requestSaveTicket(); | 509 | return (*it)->requestSaveTicket(); |
511 | } | 510 | } |
512 | } | 511 | } |
513 | 512 | ||
514 | return 0; | 513 | return 0; |
515 | } | 514 | } |
516 | 515 | ||
517 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 516 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
518 | { | 517 | { |
519 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 518 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
520 | //qDebug("block insert "); | 519 | //qDebug("block insert "); |
521 | return; | 520 | return; |
522 | } | 521 | } |
523 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 522 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
524 | bool found = false; | 523 | bool found = false; |
525 | Addressee::List::Iterator it; | 524 | Addressee::List::Iterator it; |
526 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 525 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
527 | if ( a.uid() == (*it).uid() ) { | 526 | if ( a.uid() == (*it).uid() ) { |
528 | 527 | ||
529 | bool changed = false; | 528 | bool changed = false; |
530 | Addressee addr = a; | 529 | Addressee addr = a; |
531 | if ( addr != (*it) ) | 530 | if ( addr != (*it) ) |
532 | changed = true; | 531 | changed = true; |
533 | 532 | ||
534 | if ( takeResource ) { | 533 | if ( takeResource ) { |
535 | Resource * res = (*it).resource(); | 534 | Resource * res = (*it).resource(); |
536 | (*it) = a; | 535 | (*it) = a; |
537 | (*it).setResource( res ); | 536 | (*it).setResource( res ); |
538 | } else { | 537 | } else { |
539 | (*it) = a; | 538 | (*it) = a; |
540 | if ( (*it).resource() == 0 ) | 539 | if ( (*it).resource() == 0 ) |
541 | (*it).setResource( standardResource() ); | 540 | (*it).setResource( standardResource() ); |
542 | } | 541 | } |
543 | if ( changed ) { | 542 | if ( changed ) { |
544 | if ( setRev ) { | 543 | if ( setRev ) { |
545 | 544 | ||
546 | // get rid of micro seconds | 545 | // get rid of micro seconds |
547 | QDateTime dt = QDateTime::currentDateTime(); | 546 | QDateTime dt = QDateTime::currentDateTime(); |
548 | QTime t = dt.time(); | 547 | QTime t = dt.time(); |
549 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 548 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
550 | (*it).setRevision( dt ); | 549 | (*it).setRevision( dt ); |
551 | } | 550 | } |
552 | (*it).setChanged( true ); | 551 | (*it).setChanged( true ); |
553 | } | 552 | } |
554 | 553 | ||
555 | found = true; | 554 | found = true; |
556 | } else { | 555 | } else { |
557 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 556 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
558 | QString name = (*it).uid().mid( 19 ); | 557 | QString name = (*it).uid().mid( 19 ); |
559 | Addressee b = a; | 558 | Addressee b = a; |
560 | QString id = b.getID( name ); | 559 | QString id = b.getID( name ); |
561 | if ( ! id.isEmpty() ) { | 560 | if ( ! id.isEmpty() ) { |
562 | QString des = (*it).note(); | 561 | QString des = (*it).note(); |
563 | int startN; | 562 | int startN; |
564 | if( (startN = des.find( id ) ) >= 0 ) { | 563 | if( (startN = des.find( id ) ) >= 0 ) { |
565 | int endN = des.find( ",", startN+1 ); | 564 | int endN = des.find( ",", startN+1 ); |
566 | des = des.left( startN ) + des.mid( endN+1 ); | 565 | des = des.left( startN ) + des.mid( endN+1 ); |
567 | (*it).setNote( des ); | 566 | (*it).setNote( des ); |
568 | } | 567 | } |
569 | } | 568 | } |
570 | } | 569 | } |
571 | } | 570 | } |
572 | } | 571 | } |
573 | if ( found ) | 572 | if ( found ) |
574 | return; | 573 | return; |
575 | d->mAddressees.append( a ); | 574 | d->mAddressees.append( a ); |
576 | Addressee& addr = d->mAddressees.last(); | 575 | Addressee& addr = d->mAddressees.last(); |
577 | if ( addr.resource() == 0 ) | 576 | if ( addr.resource() == 0 ) |
578 | addr.setResource( standardResource() ); | 577 | addr.setResource( standardResource() ); |
579 | 578 | ||
580 | addr.setChanged( true ); | 579 | addr.setChanged( true ); |
581 | } | 580 | } |
582 | 581 | ||
583 | void AddressBook::removeAddressee( const Addressee &a ) | 582 | void AddressBook::removeAddressee( const Addressee &a ) |
584 | { | 583 | { |
585 | Iterator it; | 584 | Iterator it; |
586 | Iterator it2; | 585 | Iterator it2; |
587 | bool found = false; | 586 | bool found = false; |
588 | for ( it = begin(); it != end(); ++it ) { | 587 | for ( it = begin(); it != end(); ++it ) { |
589 | if ( a.uid() == (*it).uid() ) { | 588 | if ( a.uid() == (*it).uid() ) { |
590 | found = true; | 589 | found = true; |
591 | it2 = it; | 590 | it2 = it; |
592 | } else { | 591 | } else { |
593 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 592 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
594 | QString name = (*it).uid().mid( 19 ); | 593 | QString name = (*it).uid().mid( 19 ); |
595 | Addressee b = a; | 594 | Addressee b = a; |
596 | QString id = b.getID( name ); | 595 | QString id = b.getID( name ); |
597 | if ( ! id.isEmpty() ) { | 596 | if ( ! id.isEmpty() ) { |
598 | QString des = (*it).note(); | 597 | QString des = (*it).note(); |
599 | if( des.find( id ) < 0 ) { | 598 | if( des.find( id ) < 0 ) { |
600 | des += id + ","; | 599 | des += id + ","; |
601 | (*it).setNote( des ); | 600 | (*it).setNote( des ); |
602 | } | 601 | } |
603 | } | 602 | } |
604 | } | 603 | } |
605 | 604 | ||
606 | } | 605 | } |
607 | } | 606 | } |
608 | 607 | ||
609 | if ( found ) | 608 | if ( found ) |
610 | removeAddressee( it2 ); | 609 | removeAddressee( it2 ); |
611 | 610 | ||
612 | } | 611 | } |
613 | 612 | ||
614 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 613 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
615 | { | 614 | { |
616 | Iterator it = begin(); | 615 | Iterator it = begin(); |
617 | Iterator it2 ; | 616 | Iterator it2 ; |
618 | QDateTime dt ( QDate( 2004,1,1) ); | 617 | QDateTime dt ( QDate( 2004,1,1) ); |
619 | while ( it != end() ) { | 618 | while ( it != end() ) { |
620 | (*it).setRevision( dt ); | 619 | (*it).setRevision( dt ); |
621 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 620 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
622 | (*it).setIDStr(""); | 621 | (*it).setIDStr(""); |
623 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 622 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
624 | it2 = it; | 623 | it2 = it; |
625 | //qDebug("removing %s ",(*it).uid().latin1() ); | 624 | //qDebug("removing %s ",(*it).uid().latin1() ); |
626 | ++it; | 625 | ++it; |
627 | removeAddressee( it2 ); | 626 | removeAddressee( it2 ); |
628 | } else { | 627 | } else { |
629 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 628 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
630 | ++it; | 629 | ++it; |
631 | } | 630 | } |
632 | } | 631 | } |
633 | deleteRemovedAddressees(); | 632 | deleteRemovedAddressees(); |
634 | } | 633 | } |
635 | 634 | ||
636 | void AddressBook::removeAddressee( const Iterator &it ) | 635 | void AddressBook::removeAddressee( const Iterator &it ) |
637 | { | 636 | { |
638 | d->mRemovedAddressees.append( (*it) ); | 637 | d->mRemovedAddressees.append( (*it) ); |
639 | d->mAddressees.remove( it.d->mIt ); | 638 | d->mAddressees.remove( it.d->mIt ); |
640 | } | 639 | } |
641 | 640 | ||
642 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 641 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
643 | { | 642 | { |
644 | Iterator it; | 643 | Iterator it; |
645 | for ( it = begin(); it != end(); ++it ) { | 644 | for ( it = begin(); it != end(); ++it ) { |
646 | if ( a.uid() == (*it).uid() ) { | 645 | if ( a.uid() == (*it).uid() ) { |
647 | return it; | 646 | return it; |
648 | } | 647 | } |
649 | } | 648 | } |
650 | return end(); | 649 | return end(); |
651 | } | 650 | } |
652 | 651 | ||
653 | Addressee AddressBook::findByUid( const QString &uid ) | 652 | Addressee AddressBook::findByUid( const QString &uid ) |
654 | { | 653 | { |
655 | Iterator it; | 654 | Iterator it; |
656 | for ( it = begin(); it != end(); ++it ) { | 655 | for ( it = begin(); it != end(); ++it ) { |
657 | if ( uid == (*it).uid() ) { | 656 | if ( uid == (*it).uid() ) { |
658 | return *it; | 657 | return *it; |
659 | } | 658 | } |
660 | } | 659 | } |
661 | return Addressee(); | 660 | return Addressee(); |
662 | } | 661 | } |
663 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 662 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
664 | { | 663 | { |
665 | //qDebug("AddressBook::preExternSync "); | 664 | //qDebug("AddressBook::preExternSync "); |
666 | AddressBook::Iterator it; | 665 | AddressBook::Iterator it; |
667 | for ( it = begin(); it != end(); ++it ) { | 666 | for ( it = begin(); it != end(); ++it ) { |
668 | (*it).setID( csd, (*it).externalUID() ); | 667 | (*it).setID( csd, (*it).externalUID() ); |
669 | (*it).computeCsum( csd ); | 668 | (*it).computeCsum( csd ); |
670 | } | 669 | } |
671 | mergeAB( aBook ,csd ); | 670 | mergeAB( aBook ,csd ); |
672 | } | 671 | } |
673 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 672 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
674 | { | 673 | { |
675 | //qDebug("AddressBook::postExternSync "); | 674 | //qDebug("AddressBook::postExternSync "); |
676 | AddressBook::Iterator it; | 675 | AddressBook::Iterator it; |
677 | for ( it = begin(); it != end(); ++it ) { | 676 | for ( it = begin(); it != end(); ++it ) { |
678 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 677 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
679 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 678 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
680 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 679 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
681 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 680 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
682 | if ( ad.isEmpty() ) { | 681 | if ( ad.isEmpty() ) { |
683 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 682 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
684 | } else { | 683 | } else { |
685 | (*it).computeCsum( csd ); | 684 | (*it).computeCsum( csd ); |
686 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 685 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
687 | ad.setID( csd, (*it).externalUID() ); | 686 | ad.setID( csd, (*it).externalUID() ); |
688 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 687 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
689 | aBook->insertAddressee( ad ); | 688 | aBook->insertAddressee( ad ); |
690 | } | 689 | } |
691 | } | 690 | } |
692 | } | 691 | } |
693 | } | 692 | } |
694 | 693 | ||
695 | bool AddressBook::containsExternalUid( const QString& uid ) | 694 | bool AddressBook::containsExternalUid( const QString& uid ) |
696 | { | 695 | { |
697 | Iterator it; | 696 | Iterator it; |
698 | for ( it = begin(); it != end(); ++it ) { | 697 | for ( it = begin(); it != end(); ++it ) { |
699 | if ( uid == (*it).externalUID( ) ) | 698 | if ( uid == (*it).externalUID( ) ) |
700 | return true; | 699 | return true; |
701 | } | 700 | } |
702 | return false; | 701 | return false; |
703 | } | 702 | } |
704 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 703 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
705 | { | 704 | { |
706 | Iterator it; | 705 | Iterator it; |
707 | for ( it = begin(); it != end(); ++it ) { | 706 | for ( it = begin(); it != end(); ++it ) { |
708 | if ( uid == (*it).getID( profile ) ) | 707 | if ( uid == (*it).getID( profile ) ) |
709 | return (*it); | 708 | return (*it); |
710 | } | 709 | } |
711 | return Addressee(); | 710 | return Addressee(); |
712 | } | 711 | } |
713 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 712 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
714 | { | 713 | { |
715 | Iterator it; | 714 | Iterator it; |
716 | Addressee ad; | 715 | Addressee ad; |
717 | for ( it = begin(); it != end(); ++it ) { | 716 | for ( it = begin(); it != end(); ++it ) { |
718 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 717 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
719 | if ( !ad.isEmpty() ) { | 718 | if ( !ad.isEmpty() ) { |
720 | (*it).mergeContact( ad ); | 719 | (*it).mergeContact( ad ); |
721 | } | 720 | } |
722 | } | 721 | } |
723 | #if 0 | 722 | #if 0 |
724 | // test only | 723 | // test only |
725 | for ( it = begin(); it != end(); ++it ) { | 724 | for ( it = begin(); it != end(); ++it ) { |
726 | 725 | ||
727 | qDebug("uid %s ", (*it).uid().latin1()); | 726 | qDebug("uid %s ", (*it).uid().latin1()); |
728 | } | 727 | } |
729 | #endif | 728 | #endif |
730 | } | 729 | } |
731 | 730 | ||
732 | #if 0 | 731 | #if 0 |
733 | Addressee::List AddressBook::getExternLastSyncAddressees() | 732 | Addressee::List AddressBook::getExternLastSyncAddressees() |
734 | { | 733 | { |
735 | Addressee::List results; | 734 | Addressee::List results; |
736 | 735 | ||
737 | Iterator it; | 736 | Iterator it; |
738 | for ( it = begin(); it != end(); ++it ) { | 737 | for ( it = begin(); it != end(); ++it ) { |
739 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 738 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
740 | if ( (*it).familyName().left(4) == "!E: " ) | 739 | if ( (*it).familyName().left(4) == "!E: " ) |
741 | results.append( *it ); | 740 | results.append( *it ); |
742 | } | 741 | } |
743 | } | 742 | } |
744 | 743 | ||
745 | return results; | 744 | return results; |
746 | } | 745 | } |
747 | #endif | 746 | #endif |
748 | void AddressBook::resetTempSyncStat() | 747 | void AddressBook::resetTempSyncStat() |
749 | { | 748 | { |
750 | Iterator it; | 749 | Iterator it; |
751 | for ( it = begin(); it != end(); ++it ) { | 750 | for ( it = begin(); it != end(); ++it ) { |
752 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 751 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
753 | } | 752 | } |
754 | 753 | ||
755 | } | 754 | } |
756 | 755 | ||
757 | QStringList AddressBook:: uidList() | 756 | QStringList AddressBook:: uidList() |
758 | { | 757 | { |
759 | QStringList results; | 758 | QStringList results; |
760 | Iterator it; | 759 | Iterator it; |
761 | for ( it = begin(); it != end(); ++it ) { | 760 | for ( it = begin(); it != end(); ++it ) { |
762 | results.append( (*it).uid() ); | 761 | results.append( (*it).uid() ); |
763 | } | 762 | } |
764 | return results; | 763 | return results; |
765 | } | 764 | } |
766 | 765 | ||
767 | 766 | ||
768 | Addressee::List AddressBook::allAddressees() | 767 | Addressee::List AddressBook::allAddressees() |
769 | { | 768 | { |
770 | return d->mAddressees; | 769 | return d->mAddressees; |
771 | 770 | ||
772 | } | 771 | } |
773 | 772 | ||
774 | Addressee::List AddressBook::findByName( const QString &name ) | 773 | Addressee::List AddressBook::findByName( const QString &name ) |
775 | { | 774 | { |
776 | Addressee::List results; | 775 | Addressee::List results; |
777 | 776 | ||
778 | Iterator it; | 777 | Iterator it; |
779 | for ( it = begin(); it != end(); ++it ) { | 778 | for ( it = begin(); it != end(); ++it ) { |
780 | if ( name == (*it).realName() ) { | 779 | if ( name == (*it).realName() ) { |
781 | results.append( *it ); | 780 | results.append( *it ); |
782 | } | 781 | } |
783 | } | 782 | } |
784 | 783 | ||
785 | return results; | 784 | return results; |
786 | } | 785 | } |
787 | 786 | ||
788 | Addressee::List AddressBook::findByEmail( const QString &email ) | 787 | Addressee::List AddressBook::findByEmail( const QString &email ) |
789 | { | 788 | { |
790 | Addressee::List results; | 789 | Addressee::List results; |
791 | QStringList mailList; | 790 | QStringList mailList; |
792 | 791 | ||
793 | Iterator it; | 792 | Iterator it; |
794 | for ( it = begin(); it != end(); ++it ) { | 793 | for ( it = begin(); it != end(); ++it ) { |
795 | mailList = (*it).emails(); | 794 | mailList = (*it).emails(); |
796 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 795 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
797 | if ( email == (*ite) ) { | 796 | if ( email == (*ite) ) { |
798 | results.append( *it ); | 797 | results.append( *it ); |
799 | } | 798 | } |
800 | } | 799 | } |
801 | } | 800 | } |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index fa80f5c..12502b0 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2477,411 +2477,411 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i | |||
2477 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2477 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2478 | { | 2478 | { |
2479 | bool syncOK = true; | 2479 | bool syncOK = true; |
2480 | int addedAddressee = 0; | 2480 | int addedAddressee = 0; |
2481 | int addedAddresseeR = 0; | 2481 | int addedAddresseeR = 0; |
2482 | int deletedAddresseeR = 0; | 2482 | int deletedAddresseeR = 0; |
2483 | int deletedAddresseeL = 0; | 2483 | int deletedAddresseeL = 0; |
2484 | int changedLocal = 0; | 2484 | int changedLocal = 0; |
2485 | int changedRemote = 0; | 2485 | int changedRemote = 0; |
2486 | 2486 | ||
2487 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2487 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2488 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2488 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2489 | 2489 | ||
2490 | //QPtrList<Addressee> el = local->rawAddressees(); | 2490 | //QPtrList<Addressee> el = local->rawAddressees(); |
2491 | Addressee addresseeR; | 2491 | Addressee addresseeR; |
2492 | QString uid; | 2492 | QString uid; |
2493 | int take; | 2493 | int take; |
2494 | Addressee addresseeL; | 2494 | Addressee addresseeL; |
2495 | Addressee addresseeRSync; | 2495 | Addressee addresseeRSync; |
2496 | Addressee addresseeLSync; | 2496 | Addressee addresseeLSync; |
2497 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2497 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2498 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2498 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2499 | bool fullDateRange = false; | 2499 | bool fullDateRange = false; |
2500 | local->resetTempSyncStat(); | 2500 | local->resetTempSyncStat(); |
2501 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2501 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2502 | QDateTime modifiedCalendar = mLastAddressbookSync;; | 2502 | QDateTime modifiedCalendar = mLastAddressbookSync;; |
2503 | addresseeLSync = getLastSyncAddressee(); | 2503 | addresseeLSync = getLastSyncAddressee(); |
2504 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2504 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2505 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2505 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2506 | if ( !addresseeR.isEmpty() ) { | 2506 | if ( !addresseeR.isEmpty() ) { |
2507 | addresseeRSync = addresseeR; | 2507 | addresseeRSync = addresseeR; |
2508 | remote->removeAddressee(addresseeR ); | 2508 | remote->removeAddressee(addresseeR ); |
2509 | 2509 | ||
2510 | } else { | 2510 | } else { |
2511 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2511 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2512 | addresseeRSync = addresseeLSync ; | 2512 | addresseeRSync = addresseeLSync ; |
2513 | } else { | 2513 | } else { |
2514 | qDebug("FULLDATE 1"); | 2514 | qDebug("FULLDATE 1"); |
2515 | fullDateRange = true; | 2515 | fullDateRange = true; |
2516 | Addressee newAdd; | 2516 | Addressee newAdd; |
2517 | addresseeRSync = newAdd; | 2517 | addresseeRSync = newAdd; |
2518 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2518 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2519 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2519 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2520 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2520 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2521 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2521 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2522 | } | 2522 | } |
2523 | } | 2523 | } |
2524 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2524 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2525 | qDebug("FULLDATE 2"); | 2525 | qDebug("FULLDATE 2"); |
2526 | fullDateRange = true; | 2526 | fullDateRange = true; |
2527 | } | 2527 | } |
2528 | if ( ! fullDateRange ) { | 2528 | if ( ! fullDateRange ) { |
2529 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2529 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2530 | 2530 | ||
2531 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2531 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2532 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2532 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2533 | fullDateRange = true; | 2533 | fullDateRange = true; |
2534 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2534 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2535 | } | 2535 | } |
2536 | } | 2536 | } |
2537 | // fullDateRange = true; // debug only! | 2537 | // fullDateRange = true; // debug only! |
2538 | if ( fullDateRange ) | 2538 | if ( fullDateRange ) |
2539 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2539 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2540 | else | 2540 | else |
2541 | mLastAddressbookSync = addresseeLSync.revision(); | 2541 | mLastAddressbookSync = addresseeLSync.revision(); |
2542 | // for resyncing if own file has changed | 2542 | // for resyncing if own file has changed |
2543 | // PENDING fixme later when implemented | 2543 | // PENDING fixme later when implemented |
2544 | #if 0 | 2544 | #if 0 |
2545 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2545 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2546 | mLastAddressbookSync = loadedFileVersion; | 2546 | mLastAddressbookSync = loadedFileVersion; |
2547 | qDebug("setting mLastAddressbookSync "); | 2547 | qDebug("setting mLastAddressbookSync "); |
2548 | } | 2548 | } |
2549 | #endif | 2549 | #endif |
2550 | 2550 | ||
2551 | //qDebug("*************************** "); | 2551 | //qDebug("*************************** "); |
2552 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2552 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2553 | QStringList er = remote->uidList(); | 2553 | QStringList er = remote->uidList(); |
2554 | Addressee inR ;//= er.first(); | 2554 | Addressee inR ;//= er.first(); |
2555 | Addressee inL; | 2555 | Addressee inL; |
2556 | 2556 | ||
2557 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2557 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2558 | 2558 | ||
2559 | int modulo = (er.count()/10)+1; | 2559 | int modulo = (er.count()/10)+1; |
2560 | int incCounter = 0; | 2560 | int incCounter = 0; |
2561 | while ( incCounter < er.count()) { | 2561 | while ( incCounter < er.count()) { |
2562 | if (syncManager->isProgressBarCanceled()) | 2562 | if (syncManager->isProgressBarCanceled()) |
2563 | return false; | 2563 | return false; |
2564 | if ( incCounter % modulo == 0 ) | 2564 | if ( incCounter % modulo == 0 ) |
2565 | syncManager->showProgressBar(incCounter); | 2565 | syncManager->showProgressBar(incCounter); |
2566 | 2566 | ||
2567 | uid = er[ incCounter ]; | 2567 | uid = er[ incCounter ]; |
2568 | bool skipIncidence = false; | 2568 | bool skipIncidence = false; |
2569 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2569 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2570 | skipIncidence = true; | 2570 | skipIncidence = true; |
2571 | QString idS,OidS; | 2571 | QString idS,OidS; |
2572 | qApp->processEvents(); | 2572 | qApp->processEvents(); |
2573 | if ( !skipIncidence ) { | 2573 | if ( !skipIncidence ) { |
2574 | inL = local->findByUid( uid ); | 2574 | inL = local->findByUid( uid ); |
2575 | inR = remote->findByUid( uid ); | 2575 | inR = remote->findByUid( uid ); |
2576 | //inL.setResource( 0 ); | 2576 | //inL.setResource( 0 ); |
2577 | //inR.setResource( 0 ); | 2577 | //inR.setResource( 0 ); |
2578 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2578 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2579 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2579 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2580 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2580 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2581 | if ( take == 3 ) | 2581 | if ( take == 3 ) |
2582 | return false; | 2582 | return false; |
2583 | if ( take == 1 ) {// take local | 2583 | if ( take == 1 ) {// take local |
2584 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2584 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2585 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2585 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2586 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2586 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2587 | local->insertAddressee( inL, false ); | 2587 | local->insertAddressee( inL, false ); |
2588 | idS = inR.externalUID(); | 2588 | idS = inR.externalUID(); |
2589 | OidS = inR.originalExternalUID(); | 2589 | OidS = inR.originalExternalUID(); |
2590 | } | 2590 | } |
2591 | else | 2591 | else |
2592 | idS = inR.IDStr(); | 2592 | idS = inR.IDStr(); |
2593 | remote->removeAddressee( inR ); | 2593 | remote->removeAddressee( inR ); |
2594 | inR = inL; | 2594 | inR = inL; |
2595 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2595 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2596 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2596 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2597 | inR.setOriginalExternalUID( OidS ); | 2597 | inR.setOriginalExternalUID( OidS ); |
2598 | inR.setExternalUID( idS ); | 2598 | inR.setExternalUID( idS ); |
2599 | } else { | 2599 | } else { |
2600 | inR.setIDStr( idS ); | 2600 | inR.setIDStr( idS ); |
2601 | } | 2601 | } |
2602 | inR.setResource( 0 ); | 2602 | inR.setResource( 0 ); |
2603 | remote->insertAddressee( inR , false); | 2603 | remote->insertAddressee( inR , false); |
2604 | ++changedRemote; | 2604 | ++changedRemote; |
2605 | } else { // take == 2 take remote | 2605 | } else { // take == 2 take remote |
2606 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2606 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2607 | if ( inR.revision().date().year() < 2004 ) | 2607 | if ( inR.revision().date().year() < 2004 ) |
2608 | inR.setRevision( modifiedCalendar ); | 2608 | inR.setRevision( modifiedCalendar ); |
2609 | } | 2609 | } |
2610 | idS = inL.IDStr(); | 2610 | idS = inL.IDStr(); |
2611 | local->removeAddressee( inL ); | 2611 | local->removeAddressee( inL ); |
2612 | inL = inR; | 2612 | inL = inR; |
2613 | inL.setIDStr( idS ); | 2613 | inL.setIDStr( idS ); |
2614 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2614 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2615 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2615 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2616 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2616 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2617 | } | 2617 | } |
2618 | inL.setResource( 0 ); | 2618 | inL.setResource( 0 ); |
2619 | local->insertAddressee( inL , false ); | 2619 | local->insertAddressee( inL , false ); |
2620 | ++changedLocal; | 2620 | ++changedLocal; |
2621 | } | 2621 | } |
2622 | } | 2622 | } |
2623 | } else { // no conflict | 2623 | } else { // no conflict |
2624 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2624 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2625 | QString des = addresseeLSync.note(); | 2625 | QString des = addresseeLSync.note(); |
2626 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2626 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2627 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2627 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2628 | remote->insertAddressee( inR, false ); | 2628 | remote->insertAddressee( inR, false ); |
2629 | ++deletedAddresseeR; | 2629 | ++deletedAddresseeR; |
2630 | } else { | 2630 | } else { |
2631 | inR.setRevision( modifiedCalendar ); | 2631 | inR.setRevision( modifiedCalendar ); |
2632 | remote->insertAddressee( inR, false ); | 2632 | remote->insertAddressee( inR, false ); |
2633 | inL = inR; | 2633 | inL = inR; |
2634 | inL.setResource( 0 ); | 2634 | inL.setResource( 0 ); |
2635 | local->insertAddressee( inL , false); | 2635 | local->insertAddressee( inL , false); |
2636 | ++addedAddressee; | 2636 | ++addedAddressee; |
2637 | } | 2637 | } |
2638 | } else { | 2638 | } else { |
2639 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2639 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2640 | inR.setRevision( modifiedCalendar ); | 2640 | inR.setRevision( modifiedCalendar ); |
2641 | remote->insertAddressee( inR, false ); | 2641 | remote->insertAddressee( inR, false ); |
2642 | inR.setResource( 0 ); | 2642 | inR.setResource( 0 ); |
2643 | local->insertAddressee( inR, false ); | 2643 | local->insertAddressee( inR, false ); |
2644 | ++addedAddressee; | 2644 | ++addedAddressee; |
2645 | } else { | 2645 | } else { |
2646 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2646 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2647 | remote->removeAddressee( inR ); | 2647 | remote->removeAddressee( inR ); |
2648 | ++deletedAddresseeR; | 2648 | ++deletedAddresseeR; |
2649 | } | 2649 | } |
2650 | } | 2650 | } |
2651 | } | 2651 | } |
2652 | } | 2652 | } |
2653 | ++incCounter; | 2653 | ++incCounter; |
2654 | } | 2654 | } |
2655 | er.clear(); | 2655 | er.clear(); |
2656 | QStringList el = local->uidList(); | 2656 | QStringList el = local->uidList(); |
2657 | modulo = (el.count()/10)+1; | 2657 | modulo = (el.count()/10)+1; |
2658 | 2658 | ||
2659 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2659 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2660 | incCounter = 0; | 2660 | incCounter = 0; |
2661 | while ( incCounter < el.count()) { | 2661 | while ( incCounter < el.count()) { |
2662 | qApp->processEvents(); | 2662 | qApp->processEvents(); |
2663 | if (syncManager->isProgressBarCanceled()) | 2663 | if (syncManager->isProgressBarCanceled()) |
2664 | return false; | 2664 | return false; |
2665 | if ( incCounter % modulo == 0 ) | 2665 | if ( incCounter % modulo == 0 ) |
2666 | syncManager->showProgressBar(incCounter); | 2666 | syncManager->showProgressBar(incCounter); |
2667 | uid = el[ incCounter ]; | 2667 | uid = el[ incCounter ]; |
2668 | bool skipIncidence = false; | 2668 | bool skipIncidence = false; |
2669 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2669 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2670 | skipIncidence = true; | 2670 | skipIncidence = true; |
2671 | if ( !skipIncidence ) { | 2671 | if ( !skipIncidence ) { |
2672 | inL = local->findByUid( uid ); | 2672 | inL = local->findByUid( uid ); |
2673 | inR = remote->findByUid( uid ); | 2673 | inR = remote->findByUid( uid ); |
2674 | if ( inR.isEmpty() ) { | 2674 | if ( inR.isEmpty() ) { |
2675 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2675 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2676 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2676 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2677 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2677 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2678 | local->removeAddressee( inL ); | 2678 | local->removeAddressee( inL ); |
2679 | ++deletedAddresseeL; | 2679 | ++deletedAddresseeL; |
2680 | } else { | 2680 | } else { |
2681 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2681 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2682 | inL.removeID(mCurrentSyncDevice ); | 2682 | inL.removeID(mCurrentSyncDevice ); |
2683 | ++addedAddresseeR; | 2683 | ++addedAddresseeR; |
2684 | inL.setRevision( modifiedCalendar ); | 2684 | inL.setRevision( modifiedCalendar ); |
2685 | local->insertAddressee( inL, false ); | 2685 | local->insertAddressee( inL, false ); |
2686 | inR = inL; | 2686 | inR = inL; |
2687 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2687 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2688 | inR.setResource( 0 ); | 2688 | inR.setResource( 0 ); |
2689 | remote->insertAddressee( inR, false ); | 2689 | remote->insertAddressee( inR, false ); |
2690 | } | 2690 | } |
2691 | } | 2691 | } |
2692 | } else { | 2692 | } else { |
2693 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2693 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2694 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2694 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2695 | local->removeAddressee( inL ); | 2695 | local->removeAddressee( inL ); |
2696 | ++deletedAddresseeL; | 2696 | ++deletedAddresseeL; |
2697 | } else { | 2697 | } else { |
2698 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2698 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2699 | ++addedAddresseeR; | 2699 | ++addedAddresseeR; |
2700 | inL.setRevision( modifiedCalendar ); | 2700 | inL.setRevision( modifiedCalendar ); |
2701 | local->insertAddressee( inL, false ); | 2701 | local->insertAddressee( inL, false ); |
2702 | inR = inL; | 2702 | inR = inL; |
2703 | inR.setResource( 0 ); | 2703 | inR.setResource( 0 ); |
2704 | remote->insertAddressee( inR, false ); | 2704 | remote->insertAddressee( inR, false ); |
2705 | } | 2705 | } |
2706 | } | 2706 | } |
2707 | } | 2707 | } |
2708 | } | 2708 | } |
2709 | } | 2709 | } |
2710 | ++incCounter; | 2710 | ++incCounter; |
2711 | } | 2711 | } |
2712 | el.clear(); | 2712 | el.clear(); |
2713 | syncManager->hideProgressBar(); | 2713 | syncManager->hideProgressBar(); |
2714 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2714 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2715 | // get rid of micro seconds | 2715 | // get rid of micro seconds |
2716 | QTime t = mLastAddressbookSync.time(); | 2716 | QTime t = mLastAddressbookSync.time(); |
2717 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2717 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2718 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2718 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2719 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2719 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2720 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2720 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2721 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2721 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2722 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2722 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2723 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2723 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2724 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2724 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2725 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2725 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2726 | addresseeRSync.setNote( "" ) ; | 2726 | addresseeRSync.setNote( "" ) ; |
2727 | addresseeLSync.setNote( "" ); | 2727 | addresseeLSync.setNote( "" ); |
2728 | 2728 | ||
2729 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2729 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2730 | remote->insertAddressee( addresseeRSync, false ); | 2730 | remote->insertAddressee( addresseeRSync, false ); |
2731 | local->insertAddressee( addresseeLSync, false ); | 2731 | local->insertAddressee( addresseeLSync, false ); |
2732 | QString mes; | 2732 | QString mes; |
2733 | 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 ); | 2733 | 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 ); |
2734 | if ( syncManager->mShowSyncSummary ) { | 2734 | if ( syncManager->mShowSyncSummary ) { |
2735 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2735 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2736 | } | 2736 | } |
2737 | qDebug( mes ); | 2737 | qDebug( mes ); |
2738 | return syncOK; | 2738 | return syncOK; |
2739 | } | 2739 | } |
2740 | 2740 | ||
2741 | 2741 | ||
2742 | //this is a overwritten callbackmethods from the syncinterface | 2742 | //this is a overwritten callbackmethods from the syncinterface |
2743 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2743 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2744 | { | 2744 | { |
2745 | 2745 | ||
2746 | //pending prepare addresseeview for output | 2746 | //pending prepare addresseeview for output |
2747 | //pending detect, if remote file has REV field. if not switch to external sync | 2747 | //pending detect, if remote file has REV field. if not switch to external sync |
2748 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2748 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2749 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2749 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2750 | 2750 | ||
2751 | AddressBook abLocal(filename,"syncContact"); | 2751 | AddressBook abLocal(filename,"syncContact"); |
2752 | bool syncOK = false; | 2752 | bool syncOK = false; |
2753 | if ( abLocal.load() ) { | 2753 | if ( abLocal.load() ) { |
2754 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2754 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2755 | bool external = false; | 2755 | bool external = false; |
2756 | bool isXML = false; | 2756 | bool isXML = false; |
2757 | if ( filename.right(4) == ".xml") { | 2757 | if ( filename.right(4) == ".xml") { |
2758 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2758 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2759 | isXML = true; | 2759 | isXML = true; |
2760 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2760 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2761 | } else { | 2761 | } else { |
2762 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2762 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2763 | if ( ! lse.isEmpty() ) { | 2763 | if ( ! lse.isEmpty() ) { |
2764 | if ( lse.familyName().left(4) == "!E: " ) | 2764 | if ( lse.familyName().left(4) == "!E: " ) |
2765 | external = true; | 2765 | external = true; |
2766 | } else { | 2766 | } else { |
2767 | bool found = false; | 2767 | bool found = false; |
2768 | AddressBook::Iterator it; | 2768 | AddressBook::Iterator it; |
2769 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2769 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2770 | if ( (*it).revision().date().year() > 2003 ) { | 2770 | if ( (*it).revision().date().year() > 2003 ) { |
2771 | found = true; | 2771 | found = true; |
2772 | break; | 2772 | break; |
2773 | } | 2773 | } |
2774 | } | 2774 | } |
2775 | external = ! found; | 2775 | external = ! found; |
2776 | } | 2776 | } |
2777 | 2777 | ||
2778 | if ( external ) { | 2778 | if ( external ) { |
2779 | qDebug("Setting vcf mode to external "); | 2779 | qDebug("Setting vcf mode to external "); |
2780 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2780 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2781 | AddressBook::Iterator it; | 2781 | AddressBook::Iterator it; |
2782 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2782 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2783 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2783 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2784 | (*it).computeCsum( mCurrentSyncDevice ); | 2784 | (*it).computeCsum( mCurrentSyncDevice ); |
2785 | } | 2785 | } |
2786 | } | 2786 | } |
2787 | } | 2787 | } |
2788 | //AddressBook::Iterator it; | 2788 | //AddressBook::Iterator it; |
2789 | //QStringList vcards; | 2789 | //QStringList vcards; |
2790 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2790 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2791 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2791 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2792 | //} | 2792 | //} |
2793 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2793 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2794 | if ( syncOK ) { | 2794 | if ( syncOK ) { |
2795 | if ( syncManager->mWriteBackFile ) | 2795 | if ( syncManager->mWriteBackFile ) |
2796 | { | 2796 | { |
2797 | if ( external ) | 2797 | if ( external ) |
2798 | abLocal.removeSyncAddressees( !isXML); | 2798 | abLocal.removeSyncAddressees( !isXML); |
2799 | qDebug("Saving remote AB "); | 2799 | qDebug("Saving remote AB "); |
2800 | abLocal.saveAB(); | 2800 | abLocal.saveAB(); |
2801 | if ( isXML ) { | 2801 | if ( isXML ) { |
2802 | // afterwrite processing | 2802 | // afterwrite processing |
2803 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2803 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2804 | } | 2804 | } |
2805 | } | 2805 | } |
2806 | } | 2806 | } |
2807 | setModified(); | 2807 | setModified(); |
2808 | 2808 | ||
2809 | } | 2809 | } |
2810 | if ( syncOK ) | 2810 | if ( syncOK ) |
2811 | mViewManager->refreshView(); | 2811 | mViewManager->refreshView(); |
2812 | return syncOK; | 2812 | return syncOK; |
2813 | #if 0 | 2813 | #if 0 |
2814 | 2814 | ||
2815 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 2815 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
2816 | getEventViewerDialog()->setSyncMode( true ); | 2816 | getEventViewerDialog()->setSyncMode( true ); |
2817 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 2817 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
2818 | getEventViewerDialog()->setSyncMode( false ); | 2818 | getEventViewerDialog()->setSyncMode( false ); |
2819 | if ( syncOK ) { | 2819 | if ( syncOK ) { |
2820 | if ( KOPrefs::instance()->mWriteBackFile ) | 2820 | if ( KOPrefs::instance()->mWriteBackFile ) |
2821 | { | 2821 | { |
2822 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 2822 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2823 | storage->save(); | 2823 | storage->save(); |
2824 | } | 2824 | } |
2825 | } | 2825 | } |
2826 | setModified(); | 2826 | setModified(); |
2827 | } | 2827 | } |
2828 | 2828 | ||
2829 | #endif | 2829 | #endif |
2830 | } | 2830 | } |
2831 | 2831 | ||
2832 | 2832 | ||
2833 | //this is a overwritten callbackmethods from the syncinterface | 2833 | //this is a overwritten callbackmethods from the syncinterface |
2834 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2834 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2835 | { | 2835 | { |
2836 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2836 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2837 | 2837 | ||
2838 | AddressBook abLocal( resource,"syncContact"); | 2838 | AddressBook abLocal( resource,"syncContact"); |
2839 | bool syncOK = false; | 2839 | bool syncOK = false; |
2840 | if ( abLocal.load() ) { | 2840 | if ( abLocal.load() ) { |
2841 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2841 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2842 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2842 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2843 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2843 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2844 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2844 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2845 | if ( syncOK ) { | 2845 | if ( syncOK ) { |
2846 | if ( syncManager->mWriteBackFile ) { | 2846 | if ( syncManager->mWriteBackFile ) { |
2847 | abLocal.saveAB(); | 2847 | abLocal.saveAB(); |
2848 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2848 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2849 | } | 2849 | } |
2850 | } | 2850 | } |
2851 | setModified(); | 2851 | setModified(); |
2852 | } | 2852 | } |
2853 | if ( syncOK ) | 2853 | if ( syncOK ) |
2854 | mViewManager->refreshView(); | 2854 | mViewManager->refreshView(); |
2855 | return syncOK; | 2855 | return syncOK; |
2856 | 2856 | ||
2857 | } | 2857 | } |
2858 | 2858 | ||
2859 | void KABCore::getFile( bool success ) | 2859 | void KABCore::getFile( bool success ) |
2860 | { | 2860 | { |
2861 | qDebug("KABCore::getFile "); | ||
2862 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); | 2861 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); |
2863 | if ( ! success ) { | 2862 | if ( ! success ) { |
2864 | setCaption( i18n("Error receiving file. Nothing changed!") ); | 2863 | setCaption( i18n("Error receiving file. Nothing changed!") ); |
2865 | return; | 2864 | return; |
2866 | } | 2865 | } |
2867 | mAddressBook->importFromFile( sentSyncFile() ); | 2866 | mAddressBook->importFromFile( sentSyncFile() ); |
2868 | topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 2867 | topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); |
2868 | mViewManager->refreshView(); | ||
2869 | } | 2869 | } |
2870 | void KABCore::syncFileRequest() | 2870 | void KABCore::syncFileRequest() |
2871 | { | 2871 | { |
2872 | mAddressBook->export2File( sentSyncFile() ); | 2872 | mAddressBook->export2File( sentSyncFile() ); |
2873 | } | 2873 | } |
2874 | QString KABCore::sentSyncFile() | 2874 | QString KABCore::sentSyncFile() |
2875 | { | 2875 | { |
2876 | #ifdef _WIN32_ | 2876 | #ifdef _WIN32_ |
2877 | return locateLocal( "tmp", "copysyncab.vcf" ); | 2877 | return locateLocal( "tmp", "copysyncab.vcf" ); |
2878 | #else | 2878 | #else |
2879 | return QString( "/tmp/copysyncab.vcf" ); | 2879 | return QString( "/tmp/copysyncab.vcf" ); |
2880 | #endif | 2880 | #endif |
2881 | } | 2881 | } |
2882 | 2882 | ||
2883 | void KABCore::setCaptionBack() | 2883 | void KABCore::setCaptionBack() |
2884 | { | 2884 | { |
2885 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 2885 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
2886 | } | 2886 | } |
2887 | 2887 | ||
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index aad48d9..32400af 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h | |||
@@ -1,227 +1,227 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
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 | $Id$ | 20 | $Id$ |
21 | */ | 21 | */ |
22 | #ifndef _KSYNCMANAGER_H | 22 | #ifndef _KSYNCMANAGER_H |
23 | #define _KSYNCMANAGER_H | 23 | #define _KSYNCMANAGER_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qsocket.h> | 27 | #include <qsocket.h> |
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qserversocket.h> | 29 | #include <qserversocket.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | 32 | ||
33 | class QPopupMenu; | 33 | class QPopupMenu; |
34 | class KSyncProfile; | 34 | class KSyncProfile; |
35 | class KPimPrefs; | 35 | class KPimPrefs; |
36 | class QWidget; | 36 | class QWidget; |
37 | class KSyncManager; | 37 | class KSyncManager; |
38 | class KSyncInterface; | 38 | class KSyncInterface; |
39 | class QProgressBar; | 39 | class QProgressBar; |
40 | 40 | ||
41 | 41 | ||
42 | class KServerSocket : public QServerSocket | 42 | class KServerSocket : public QServerSocket |
43 | { | 43 | { |
44 | Q_OBJECT | 44 | Q_OBJECT |
45 | 45 | ||
46 | public: | 46 | public: |
47 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); | 47 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); |
48 | 48 | ||
49 | void newConnection ( int socket ) ; | 49 | void newConnection ( int socket ) ; |
50 | void setFileName( QString fn ) {mFileName = fn;}; | 50 | void setFileName( QString fn ) {mFileName = fn;}; |
51 | 51 | ||
52 | signals: | 52 | signals: |
53 | void file_received( bool ); | 53 | void file_received( bool ); |
54 | void request_file(); | 54 | void request_file(); |
55 | void saveFile(); | 55 | void saveFile(); |
56 | void endConnect(); | 56 | void endConnect(); |
57 | private slots: | 57 | private slots: |
58 | void discardClient(); | 58 | void discardClient(); |
59 | void readClient(); | 59 | void readClient(); |
60 | void readBackFileFromSocket(); | 60 | void readBackFileFromSocket(); |
61 | private : | 61 | private : |
62 | bool blockRC; | 62 | bool blockRC; |
63 | void send_file(); | 63 | void send_file(); |
64 | void get_file(); | 64 | void get_file(); |
65 | void end_connect(); | 65 | void end_connect(); |
66 | QDialog* mSyncActionDialog; | 66 | QDialog* mSyncActionDialog; |
67 | QSocket* mSocket; | 67 | QSocket* mSocket; |
68 | QString mPassWord; | 68 | QString mPassWord; |
69 | QString mFileName; | 69 | QString mFileName; |
70 | QTime piTime; | 70 | QTime piTime; |
71 | QString piFileString; | 71 | QString piFileString; |
72 | }; | 72 | }; |
73 | 73 | ||
74 | class KCommandSocket : public QObject | 74 | class KCommandSocket : public QObject |
75 | { | 75 | { |
76 | Q_OBJECT | 76 | Q_OBJECT |
77 | public: | 77 | public: |
78 | enum state { successR, errorR, successW, errorW, quiet }; | 78 | enum state { successR, errorR, successW, errorW, quiet }; |
79 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); | 79 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); |
80 | void readFile( QString ); | 80 | void readFile( QString ); |
81 | void writeFile( QString ); | 81 | void writeFile( QString ); |
82 | void sendStop(); | 82 | void sendStop(); |
83 | 83 | ||
84 | 84 | ||
85 | signals: | 85 | signals: |
86 | void commandFinished( KCommandSocket*, int ); | 86 | void commandFinished( KCommandSocket*, int ); |
87 | private slots: | 87 | private slots: |
88 | void startReadFileFromSocket(); | 88 | void startReadFileFromSocket(); |
89 | void readFileFromSocket(); | 89 | void readFileFromSocket(); |
90 | void deleteSocket(); | 90 | void deleteSocket(); |
91 | void writeFileToSocket(); | 91 | void writeFileToSocket(); |
92 | private : | 92 | private : |
93 | QSocket* mSocket; | 93 | QSocket* mSocket; |
94 | QString mPassWord; | 94 | QString mPassWord; |
95 | Q_UINT16 mPort; | 95 | Q_UINT16 mPort; |
96 | QString mHost; | 96 | QString mHost; |
97 | QString mFileName; | 97 | QString mFileName; |
98 | QTimer* mTimerSocket; | 98 | QTimer* mTimerSocket; |
99 | int mRetVal; | 99 | int mRetVal; |
100 | QTime mTime; | 100 | QTime mTime; |
101 | QString mFileString; | 101 | QString mFileString; |
102 | bool mFirst; | 102 | bool mFirst; |
103 | }; | 103 | }; |
104 | 104 | ||
105 | 105 | ||
106 | class KSyncManager : public QObject | 106 | class KSyncManager : public QObject |
107 | { | 107 | { |
108 | Q_OBJECT | 108 | Q_OBJECT |
109 | 109 | ||
110 | public: | 110 | public: |
111 | enum TargetApp { | 111 | enum TargetApp { |
112 | KOPI = 0, | 112 | KOPI = 0, |
113 | KAPI = 1, | 113 | KAPI = 1, |
114 | PWMPI = 2 }; | 114 | PWMPI = 2 }; |
115 | 115 | ||
116 | 116 | ||
117 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); | 117 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); |
118 | ~KSyncManager() ; | 118 | ~KSyncManager() ; |
119 | 119 | ||
120 | bool blockSave() { return mBlockSaveFlag; } | 120 | bool blockSave() { return mBlockSaveFlag; } |
121 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } | 121 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } |
122 | void setDefaultFileName( QString s) { mDefFileName = s ;} | 122 | void setDefaultFileName( QString s) { mDefFileName = s ;} |
123 | QString defaultFileName() { return mDefFileName ;} | 123 | QString defaultFileName() { return mDefFileName ;} |
124 | QString syncFileName(); | 124 | QString syncFileName(); |
125 | void fillSyncMenu(); | ||
126 | 125 | ||
127 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } | 126 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } |
128 | QString getCurrentSyncName() { return mCurrentSyncName; } | 127 | QString getCurrentSyncName() { return mCurrentSyncName; } |
129 | 128 | ||
130 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); | 129 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); |
131 | void hideProgressBar(); | 130 | void hideProgressBar(); |
132 | bool isProgressBarCanceled(); | 131 | bool isProgressBarCanceled(); |
133 | 132 | ||
134 | // sync stuff | 133 | // sync stuff |
135 | QString mLocalMachineName; | 134 | QString mLocalMachineName; |
136 | QStringList mExternSyncProfiles; | 135 | QStringList mExternSyncProfiles; |
137 | QStringList mSyncProfileNames; | 136 | QStringList mSyncProfileNames; |
138 | bool mAskForPreferences; | 137 | bool mAskForPreferences; |
139 | bool mShowSyncSummary; | 138 | bool mShowSyncSummary; |
140 | bool mShowSyncEvents; | 139 | bool mShowSyncEvents; |
141 | bool mShowTodoInAgenda; | 140 | bool mShowTodoInAgenda; |
142 | bool mWriteBackExistingOnly; | 141 | bool mWriteBackExistingOnly; |
143 | int mSyncAlgoPrefs; | 142 | int mSyncAlgoPrefs; |
144 | int mRingSyncAlgoPrefs; | 143 | int mRingSyncAlgoPrefs; |
145 | bool mWriteBackFile; | 144 | bool mWriteBackFile; |
146 | int mWriteBackInFuture; | 145 | int mWriteBackInFuture; |
147 | QString mPhoneDevice; | 146 | QString mPhoneDevice; |
148 | QString mPhoneConnection; | 147 | QString mPhoneConnection; |
149 | QString mPhoneModel; | 148 | QString mPhoneModel; |
150 | QString mLastSyncedLocalFile; // save! | 149 | QString mLastSyncedLocalFile; // save! |
151 | QString mPassWordPiSync; | 150 | QString mPassWordPiSync; |
152 | QString mActiveSyncPort; | 151 | QString mActiveSyncPort; |
153 | QString mActiveSyncIP ; | 152 | QString mActiveSyncIP ; |
154 | 153 | ||
155 | signals: | 154 | signals: |
156 | void save(); | 155 | void save(); |
157 | void request_file(); | 156 | void request_file(); |
158 | void getFile( bool ); | 157 | void getFile( bool ); |
159 | 158 | ||
160 | public slots: | 159 | public slots: |
160 | void fillSyncMenu(); | ||
161 | void slotSyncMenu( int ); | 161 | void slotSyncMenu( int ); |
162 | void deleteCommandSocket(KCommandSocket*s, int state); | 162 | void deleteCommandSocket(KCommandSocket*s, int state); |
163 | void readFileFromSocket(); | 163 | void readFileFromSocket(); |
164 | 164 | ||
165 | private: | 165 | private: |
166 | // LR ******************************* | 166 | // LR ******************************* |
167 | // sync stuff! | 167 | // sync stuff! |
168 | void syncPi(); | 168 | void syncPi(); |
169 | KServerSocket * mServerSocket; | 169 | KServerSocket * mServerSocket; |
170 | void enableQuick(); | 170 | void enableQuick(); |
171 | KPimPrefs* mPrefs; | 171 | KPimPrefs* mPrefs; |
172 | QString mDefFileName; | 172 | QString mDefFileName; |
173 | QString mCurrentSyncDevice; | 173 | QString mCurrentSyncDevice; |
174 | QString mCurrentSyncName; | 174 | QString mCurrentSyncName; |
175 | void quickSyncLocalFile(); | 175 | void quickSyncLocalFile(); |
176 | bool syncWithFile( QString fn , bool quick ); | 176 | bool syncWithFile( QString fn , bool quick ); |
177 | void syncLocalFile(); | 177 | void syncLocalFile(); |
178 | void syncPhone(); | 178 | void syncPhone(); |
179 | void syncSharp(); | 179 | void syncSharp(); |
180 | bool syncExternalApplication(QString); | 180 | bool syncExternalApplication(QString); |
181 | void multiSync( bool askforPrefs ); | 181 | void multiSync( bool askforPrefs ); |
182 | int mCurrentSyncProfile ; | 182 | int mCurrentSyncProfile ; |
183 | void syncRemote( KSyncProfile* prof, bool ask = true); | 183 | void syncRemote( KSyncProfile* prof, bool ask = true); |
184 | void edit_sync_options(); | 184 | void edit_sync_options(); |
185 | int ringSync(); | 185 | int ringSync(); |
186 | QString getPassword( ); | 186 | QString getPassword( ); |
187 | 187 | ||
188 | private slots: | 188 | private slots: |
189 | void confSync(); | 189 | void confSync(); |
190 | // ********************* | 190 | // ********************* |
191 | 191 | ||
192 | private: | 192 | private: |
193 | bool mBlockSaveFlag; | 193 | bool mBlockSaveFlag; |
194 | 194 | ||
195 | 195 | ||
196 | QWidget* mParent; | 196 | QWidget* mParent; |
197 | KSyncInterface* mImplementation; | 197 | KSyncInterface* mImplementation; |
198 | TargetApp mTargetApp; | 198 | TargetApp mTargetApp; |
199 | QPopupMenu* mSyncMenu; | 199 | QPopupMenu* mSyncMenu; |
200 | 200 | ||
201 | QProgressBar* bar; | 201 | QProgressBar* bar; |
202 | 202 | ||
203 | 203 | ||
204 | 204 | ||
205 | 205 | ||
206 | 206 | ||
207 | }; | 207 | }; |
208 | 208 | ||
209 | 209 | ||
210 | class KSyncInterface | 210 | class KSyncInterface |
211 | { | 211 | { |
212 | 212 | ||
213 | 213 | ||
214 | public : | 214 | public : |
215 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; | 215 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; |
216 | 216 | ||
217 | virtual bool syncExternal(KSyncManager* manager, QString resource) | 217 | virtual bool syncExternal(KSyncManager* manager, QString resource) |
218 | { | 218 | { |
219 | // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. | 219 | // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. |
220 | return false; | 220 | return false; |
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | }; | 224 | }; |
225 | 225 | ||
226 | 226 | ||
227 | #endif | 227 | #endif |