summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/resourcefile.cpp3
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp48
-rw-r--r--kabc/plugins/sharpdtm/sharpdtmconverter.cpp17
-rw-r--r--kaddressbook/kabcore.cpp5
-rw-r--r--korganizer/calendarview.cpp4
5 files changed, 70 insertions, 7 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index b8c32d5..6cd63fd 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -1,408 +1,409 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#ifndef _WIN32_ 30#ifndef _WIN32_
31#include <unistd.h> 31#include <unistd.h>
32#endif 32#endif
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qregexp.h> 36#include <qregexp.h>
37#include <qtimer.h> 37#include <qtimer.h>
38 38
39#include <kapplication.h> 39#include <kapplication.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <klocale.h> 42#include <klocale.h>
43//US #include <ksavefile.h> 43//US #include <ksavefile.h>
44#include <kstandarddirs.h> 44#include <kstandarddirs.h>
45#include <kmessagebox.h> 45#include <kmessagebox.h>
46 46
47#include "formatfactory.h" 47#include "formatfactory.h"
48 48
49#include "resource.h" 49#include "resource.h"
50#include "resourcefileconfig.h" 50#include "resourcefileconfig.h"
51#include "stdaddressbook.h" 51#include "stdaddressbook.h"
52#define NO_DIRWATCH 52#define NO_DIRWATCH
53#include "resourcefile.h" 53#include "resourcefile.h"
54#include "syncprefwidget.h" 54#include "syncprefwidget.h"
55 55
56//#define ALLOW_LOCKING 56//#define ALLOW_LOCKING
57 57
58 58
59 59
60using namespace KABC; 60using namespace KABC;
61 61
62extern "C" 62extern "C"
63#ifdef _WIN32_ 63#ifdef _WIN32_
64__declspec(dllexport) 64__declspec(dllexport)
65#else 65#else
66{ 66{
67#endif 67#endif
68 68
69//US void *init_kabc_file() 69//US void *init_kabc_file()
70 void *init_microkabc_file() 70 void *init_microkabc_file()
71 { 71 {
72 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); 72 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>();
73 } 73 }
74#ifndef _WIN32_ 74#ifndef _WIN32_
75} 75}
76#endif 76#endif
77 77
78ResourceFile::ResourceFile( const KConfig *config, bool syncable ) 78ResourceFile::ResourceFile( const KConfig *config, bool syncable )
79 : Resource( config, syncable ) , mFormat( 0 ) 79 : Resource( config, syncable ) , mFormat( 0 )
80{ 80{
81 QString fileName, formatName, default_fileName; 81 QString fileName, formatName, default_fileName;
82 82
83 if (syncable == true) 83 if (syncable == true)
84 default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; 84 default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf";
85 else 85 else
86 default_fileName = StdAddressBook::fileName(); 86 default_fileName = StdAddressBook::fileName();
87 87
88 KConfig *cfg = (KConfig *)config; 88 KConfig *cfg = (KConfig *)config;
89 if ( cfg ) { 89 if ( cfg ) {
90 fileName = cfg->readEntry( "FileName", default_fileName ); 90 fileName = cfg->readEntry( "FileName", default_fileName );
91 formatName = cfg->readEntry( "FileFormat", "vcard" ); 91 formatName = cfg->readEntry( "FileFormat", "vcard" );
92 } else { 92 } else {
93 fileName = default_fileName; 93 fileName = default_fileName;
94 formatName = "vcard"; 94 formatName = "vcard";
95 } 95 }
96 96
97 init( fileName, formatName ); 97 init( fileName, formatName );
98} 98}
99 99
100ResourceFile::ResourceFile( const QString &fileName, bool syncable , 100ResourceFile::ResourceFile( const QString &fileName, bool syncable ,
101 const QString &formatName ) 101 const QString &formatName )
102 : Resource( 0, syncable ) 102 : Resource( 0, syncable )
103{ 103{
104// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 104// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
105 init( fileName, formatName ); 105 init( fileName, formatName );
106} 106}
107 107
108void ResourceFile::init( const QString &fileName, const QString &formatName ) 108void ResourceFile::init( const QString &fileName, const QString &formatName )
109{ 109{
110 mFormatName = formatName; 110 mFormatName = formatName;
111 111
112 FormatFactory *factory = FormatFactory::self(); 112 FormatFactory *factory = FormatFactory::self();
113 mFormat = factory->format( mFormatName ); 113 mFormat = factory->format( mFormatName );
114 114
115 if ( !mFormat ) { 115 if ( !mFormat ) {
116 mFormatName = "vcard"; 116 mFormatName = "vcard";
117 mFormat = factory->format( mFormatName ); 117 mFormat = factory->format( mFormatName );
118 } 118 }
119 119
120#ifndef NO_DIRWATCH 120#ifndef NO_DIRWATCH
121 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 121 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
122 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 122 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
123 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 123 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
124#endif 124#endif
125 setFileName( fileName ); 125 setFileName( fileName );
126} 126}
127 127
128ResourceFile::~ResourceFile() 128ResourceFile::~ResourceFile()
129{ 129{
130 delete mFormat; 130 delete mFormat;
131 mFormat = 0; 131 mFormat = 0;
132} 132}
133 133
134void ResourceFile::writeConfig( KConfig *config ) 134void ResourceFile::writeConfig( KConfig *config )
135{ 135{
136 136
137 config->setGroup( "Resource_" + identifier() ); 137 config->setGroup( "Resource_" + identifier() );
138 Resource::writeConfig( config ); 138 Resource::writeConfig( config );
139 139
140 config->writeEntry( "FileName", mFileName ); 140 config->writeEntry( "FileName", mFileName );
141 config->writeEntry( "FileFormat", mFormatName ); 141 config->writeEntry( "FileFormat", mFormatName );
142 142
143// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 143// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
144 144
145} 145}
146 146
147Ticket *ResourceFile::requestSaveTicket() 147Ticket *ResourceFile::requestSaveTicket()
148{ 148{
149 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 149 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
150 150
151 if ( !addressBook() ) return 0; 151 if ( !addressBook() ) return 0;
152 152
153#ifdef ALLOW_LOCKING 153#ifdef ALLOW_LOCKING
154 if ( !lock( mFileName ) ) { 154 if ( !lock( mFileName ) ) {
155 qDebug("unablt to lock file "); 155 qDebug("unablt to lock file ");
156 return 0; 156 return 0;
157 } 157 }
158#endif 158#endif
159 return createTicket( this ); 159 return createTicket( this );
160} 160}
161 161
162 162
163bool ResourceFile::doOpen() 163bool ResourceFile::doOpen()
164{ 164{
165 QFile file( mFileName ); 165 QFile file( mFileName );
166 qDebug("ResourceFile::openfile %s ", mFileName.latin1());
166 167
167 if ( !file.exists() ) { 168 if ( !file.exists() ) {
168 // try to create the file 169 // try to create the file
169 bool ok = file.open( IO_WriteOnly ); 170 bool ok = file.open( IO_WriteOnly );
170 if ( ok ) 171 if ( ok )
171 file.close(); 172 file.close();
172 173
173 return ok; 174 return ok;
174 } else { 175 } else {
175 if ( !file.open( IO_ReadWrite ) ) 176 if ( !file.open( IO_ReadWrite ) )
176 return false; 177 return false;
177 178
178 if ( file.size() == 0 ) { 179 if ( file.size() == 0 ) {
179 file.close(); 180 file.close();
180 return true; 181 return true;
181 } 182 }
182 183
183 bool ok = mFormat->checkFormat( &file ); 184 bool ok = mFormat->checkFormat( &file );
184 file.close(); 185 file.close();
185 186
186 return ok; 187 return ok;
187 } 188 }
188} 189}
189 190
190void ResourceFile::doClose() 191void ResourceFile::doClose()
191{ 192{
192} 193}
193 194
194bool ResourceFile::load() 195bool ResourceFile::load()
195{ 196{
196 197
197 198 qDebug("ResourceFile::loadfile %s ", mFileName.latin1());
198 QFile file( mFileName ); 199 QFile file( mFileName );
199 if ( !file.open( IO_ReadOnly ) ) { 200 if ( !file.open( IO_ReadOnly ) ) {
200 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); 201 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
201 return false; 202 return false;
202 } 203 }
203 204
204// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 205// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
205 206
206 return mFormat->loadAll( addressBook(), this, &file ); 207 return mFormat->loadAll( addressBook(), this, &file );
207} 208}
208 209
209bool ResourceFile::save( Ticket *ticket ) 210bool ResourceFile::save( Ticket *ticket )
210{ 211{
211// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 212// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
212 213
213 214
214 // create backup file 215 // create backup file
215 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 216 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
216 217
217/*US we use a simpler method to create a backupfile 218/*US we use a simpler method to create a backupfile
218 219
219 (void) KSaveFile::backupFile( mFileName, QString::null 220 (void) KSaveFile::backupFile( mFileName, QString::null
220 ,extension ); 221 ,extension );
221 222
222 KSaveFile saveFile( mFileName ); 223 KSaveFile saveFile( mFileName );
223 bool ok = false; 224 bool ok = false;
224 if ( saveFile.status() == 0 && saveFile.file() ) 225 if ( saveFile.status() == 0 && saveFile.file() )
225 { 226 {
226 mFormat->saveAll( addressBook(), this, saveFile.file() ); 227 mFormat->saveAll( addressBook(), this, saveFile.file() );
227 ok = saveFile.close(); 228 ok = saveFile.close();
228 } 229 }
229*/ 230*/
230 231
231//US ToDo: write backupfile 232//US ToDo: write backupfile
232#ifndef NO_DIRWATCH 233#ifndef NO_DIRWATCH
233 mDirWatch.stopScan(); 234 mDirWatch.stopScan();
234#endif 235#endif
235 QFile info; 236 QFile info;
236 info.setName( mFileName ); 237 info.setName( mFileName );
237 bool ok = info.open( IO_WriteOnly ); 238 bool ok = info.open( IO_WriteOnly );
238 if ( ok ) { 239 if ( ok ) {
239 mFormat->saveAll( addressBook(), this, &info ); 240 mFormat->saveAll( addressBook(), this, &info );
240 241
241 info.close(); 242 info.close();
242 ok = true; 243 ok = true;
243 } 244 }
244 else { 245 else {
245 246
246 } 247 }
247 248
248 if ( !ok ) 249 if ( !ok )
249 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 250 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
250#ifndef NO_DIRWATCH 251#ifndef NO_DIRWATCH
251 mDirWatch.startScan(); 252 mDirWatch.startScan();
252#endif 253#endif
253 delete ticket; 254 delete ticket;
254#ifdef ALLOW_LOCKING 255#ifdef ALLOW_LOCKING
255 unlock( mFileName ); 256 unlock( mFileName );
256#endif 257#endif
257 258
258 return ok; 259 return ok;
259} 260}
260 261
261bool ResourceFile::lock( const QString &fileName ) 262bool ResourceFile::lock( const QString &fileName )
262{ 263{
263#ifdef ALLOW_LOCKING 264#ifdef ALLOW_LOCKING
264 265
265 266
266 QString fn = fileName; 267 QString fn = fileName;
267 268
268//US change the implementation how the lockfilename is getting created 269//US change the implementation how the lockfilename is getting created
269//US fn.replace( QRegExp("/"), "_" ); 270//US fn.replace( QRegExp("/"), "_" );
270//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 271//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
271 272
272 KURL url(fn); 273 KURL url(fn);
273 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 274 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
274 275
275 276
276 277
277 if (QFile::exists( lockName )) return false; 278 if (QFile::exists( lockName )) return false;
278 279
279 QString lockUniqueName; 280 QString lockUniqueName;
280 lockUniqueName = fn + KApplication::randomString( 8 ); 281 lockUniqueName = fn + KApplication::randomString( 8 );
281 282
282 url = lockUniqueName; 283 url = lockUniqueName;
283//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 284//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
284 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 285 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
285 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 286 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
286 287
287 // Create unique file 288 // Create unique file
288 QFile file( mLockUniqueName ); 289 QFile file( mLockUniqueName );
289 file.open( IO_WriteOnly ); 290 file.open( IO_WriteOnly );
290 file.close(); 291 file.close();
291 292
292 // Create lock file 293 // Create lock file
293 int result = 0; 294 int result = 0;
294#ifndef _WIN32_ 295#ifndef _WIN32_
295 result = ::link( QFile::encodeName( mLockUniqueName ), 296 result = ::link( QFile::encodeName( mLockUniqueName ),
296 QFile::encodeName( lockName ) ); 297 QFile::encodeName( lockName ) );
297#endif 298#endif
298 if ( result == 0 ) { 299 if ( result == 0 ) {
299 addressBook()->emitAddressBookLocked(); 300 addressBook()->emitAddressBookLocked();
300 return true; 301 return true;
301 } 302 }
302 303
303 // TODO: check stat 304 // TODO: check stat
304 305
305 return false; 306 return false;
306#else 307#else
307 return true; 308 return true;
308#endif 309#endif
309} 310}
310 311
311void ResourceFile::unlock( const QString &fileName ) 312void ResourceFile::unlock( const QString &fileName )
312{ 313{
313#ifdef ALLOW_LOCKING 314#ifdef ALLOW_LOCKING
314 QString fn = fileName; 315 QString fn = fileName;
315//US change the implementation how the lockfilename is getting created 316//US change the implementation how the lockfilename is getting created
316//US fn.replace( QRegExp( "/" ), "_" ); 317//US fn.replace( QRegExp( "/" ), "_" );
317//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 318//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
318//US QString lockName = fn + ".lock"; 319//US QString lockName = fn + ".lock";
319 KURL url(fn); 320 KURL url(fn);
320 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 321 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
321 322
322 QFile::remove( lockName ); 323 QFile::remove( lockName );
323 QFile::remove( mLockUniqueName ); 324 QFile::remove( mLockUniqueName );
324 addressBook()->emitAddressBookUnlocked(); 325 addressBook()->emitAddressBookUnlocked();
325#else 326#else
326 return; 327 return;
327#endif 328#endif
328} 329}
329 330
330void ResourceFile::setFileName( const QString &fileName ) 331void ResourceFile::setFileName( const QString &fileName )
331{ 332{
332#ifndef NO_DIRWATCH 333#ifndef NO_DIRWATCH
333 mDirWatch.stopScan(); 334 mDirWatch.stopScan();
334 mDirWatch.removeFile( mFileName ); 335 mDirWatch.removeFile( mFileName );
335 mFileName = fileName; 336 mFileName = fileName;
336 337
337 338
338 mDirWatch.addFile( mFileName ); 339 mDirWatch.addFile( mFileName );
339 mDirWatch.startScan(); 340 mDirWatch.startScan();
340#else 341#else
341 mFileName = fileName; 342 mFileName = fileName;
342#endif 343#endif
343 344
344//US simulate KDirWatch event 345//US simulate KDirWatch event
345//US fileChanged(); 346//US fileChanged();
346} 347}
347 348
348QString ResourceFile::fileName() const 349QString ResourceFile::fileName() const
349{ 350{
350 return mFileName; 351 return mFileName;
351} 352}
352 353
353void ResourceFile::setFormat( const QString &format ) 354void ResourceFile::setFormat( const QString &format )
354{ 355{
355 mFormatName = format; 356 mFormatName = format;
356 delete mFormat; 357 delete mFormat;
357 358
358 FormatFactory *factory = FormatFactory::self(); 359 FormatFactory *factory = FormatFactory::self();
359 mFormat = factory->format( mFormatName ); 360 mFormat = factory->format( mFormatName );
360/*US 361/*US
361//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); 362//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
362 if (mFormatName == "vcard") { 363 if (mFormatName == "vcard") {
363 mFormat = new VCardFormatPlugin2(); 364 mFormat = new VCardFormatPlugin2();
364// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 365// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
365 } 366 }
366 else if (mFormatName == "binary") { 367 else if (mFormatName == "binary") {
367 mFormat = new BinaryFormat(); 368 mFormat = new BinaryFormat();
368// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 369// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
369 } 370 }
370 else 371 else
371 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); 372 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
372*/ 373*/
373 374
374} 375}
375 376
376QString ResourceFile::format() const 377QString ResourceFile::format() const
377{ 378{
378 return mFormatName; 379 return mFormatName;
379} 380}
380 381
381void ResourceFile::fileChanged() 382void ResourceFile::fileChanged()
382{ 383{
383 // There is a small theoretical chance that KDirWatch calls us before 384 // There is a small theoretical chance that KDirWatch calls us before
384 // we are fully constructed 385 // we are fully constructed
385 if (!addressBook()) 386 if (!addressBook())
386 return; 387 return;
387 388
388 389
389 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); 390 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) );
390 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 391 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
391 load(); 392 load();
392 addressBook()->emitAddressBookChanged(); 393 addressBook()->emitAddressBookChanged();
393 } 394 }
394} 395}
395 396
396void ResourceFile::removeAddressee( const Addressee &addr ) 397void ResourceFile::removeAddressee( const Addressee &addr )
397{ 398{
398 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); 399 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) );
399 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); 400 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) );
400 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); 401 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
401} 402}
402 403
403void ResourceFile::cleanUp() 404void ResourceFile::cleanUp()
404{ 405{
405 unlock( mFileName ); 406 unlock( mFileName );
406} 407}
407 408
408//US #include "resourcefile.moc" 409//US #include "resourcefile.moc"
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 48d3985..437bda8 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,400 +1,442 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
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 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36//US #include <qtimer.h> 36//US #include <qtimer.h>
37 37
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <klocale.h> 41#include <klocale.h>
42//US #include <ksavefile.h> 42//US #include <ksavefile.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kmessagebox.h> 44#include <kmessagebox.h>
45 45
46#include <sl/slzdb.h> 46#include <sl/slzdb.h>
47 47
48#include <libkdepim/ksyncprofile.h> 48#include <libkdepim/ksyncprofile.h>
49 49
50#include "resourcesharpdtmconfig.h" 50#include "resourcesharpdtmconfig.h"
51#include "resourcesharpdtm.h" 51#include "resourcesharpdtm.h"
52 52
53#include "syncprefwidget.h" 53#include "syncprefwidget.h"
54 54
55#include "stdaddressbook.h" 55#include "stdaddressbook.h"
56 56
57#include "sharpdtmconverter.h" 57#include "sharpdtmconverter.h"
58//#define ALLOW_LOCKING 58//#define ALLOW_LOCKING
59using namespace KABC; 59using namespace KABC;
60extern "C" 60extern "C"
61{ 61{
62 void *init_microkabc_sharpdtm() 62 void *init_microkabc_sharpdtm()
63 { 63 {
64 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); 64 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>();
65 } 65 }
66} 66}
67 67
68ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) 68ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable )
69 : Resource( config, syncable ), mConverter (0) 69 : Resource( config, syncable ), mConverter (0)
70{ 70{
71 // we can not choose the filename. Therefore use the default to display 71 // we can not choose the filename. Therefore use the default to display
72 72
73 QString fileName = SlZDataBase::addressbookFileName(); 73 QString fileName = SlZDataBase::addressbookFileName();
74 init( fileName ); 74 init( fileName );
75} 75}
76 76
77ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) 77ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable )
78 : Resource( 0, syncable ) 78 : Resource( 0, syncable )
79{ 79{
80 init( fileName ); 80 init( fileName );
81} 81}
82 82
83void ResourceSharpDTM::init( const QString &fileName ) 83void ResourceSharpDTM::init( const QString &fileName )
84{ 84{
85 85
86 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 86 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
87 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 87 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
88 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 88 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
89 89
90 setFileName( fileName ); 90 setFileName( fileName );
91} 91}
92 92
93ResourceSharpDTM::~ResourceSharpDTM() 93ResourceSharpDTM::~ResourceSharpDTM()
94{ 94{
95 if (mConverter != 0) 95 if (mConverter != 0)
96 delete mConverter; 96 delete mConverter;
97 97
98 if(mAccess != 0) 98 if(mAccess != 0)
99 delete mAccess; 99 delete mAccess;
100} 100}
101 101
102void ResourceSharpDTM::writeConfig( KConfig *config ) 102void ResourceSharpDTM::writeConfig( KConfig *config )
103{ 103{
104 Resource::writeConfig( config ); 104 Resource::writeConfig( config );
105} 105}
106 106
107Ticket *ResourceSharpDTM::requestSaveTicket() 107Ticket *ResourceSharpDTM::requestSaveTicket()
108{ 108{
109 109
110 110
111 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 111 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
112 112
113 if ( !addressBook() ) return 0; 113 if ( !addressBook() ) return 0;
114 114
115#ifdef ALLOW_LOCKING 115#ifdef ALLOW_LOCKING
116 if ( !lock( fileName() ) ) { 116 if ( !lock( fileName() ) ) {
117 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); 117 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file ");
118 return 0; 118 return 0;
119 } 119 }
120#endif 120#endif
121 return createTicket( this ); 121 return createTicket( this );
122} 122}
123 123
124 124
125bool ResourceSharpDTM::doOpen() 125bool ResourceSharpDTM::doOpen()
126{ 126{
127 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); 127 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1());
128 128
129 // the last parameter in the SlZDataBase constructor means "readonly" 129 // the last parameter in the SlZDataBase constructor means "readonly"
130 mAccess = new SlZDataBase(fileName(), 130 mAccess = new SlZDataBase(fileName(),
131 SlZDataBase::addressbookItems(), 131 SlZDataBase::addressbookItems(),
132 NULL, false); 132 NULL, false);
133 133
134 if ( !mAccess ) { 134 if ( !mAccess ) {
135 qDebug("Unable to load file() %s", fileName().latin1()); 135 qDebug("Unable to load file() %s", fileName().latin1());
136 return false; 136 return false;
137 } 137 }
138 138
139 if (mConverter == 0) 139 if (mConverter == 0)
140 { 140 {
141 mConverter = new SharpDTMConverter(); 141 mConverter = new SharpDTMConverter();
142 bool res = mConverter->init(); 142 bool res = mConverter->init();
143 if ( !res ) 143 if ( !res )
144 { 144 {
145 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); 145 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
146 146
147 qDebug(msg); 147 qDebug(msg);
148 delete mAccess; 148 delete mAccess;
149 mAccess = 0; 149 mAccess = 0;
150 return false; 150 return false;
151 } 151 }
152 } 152 }
153 153
154 return true; 154 return true;
155} 155}
156 156
157void ResourceSharpDTM::doClose() 157void ResourceSharpDTM::doClose()
158{ 158{
159 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); 159 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
160 160
161 if(mAccess) 161 if(mAccess)
162 { 162 {
163 delete mAccess; 163 delete mAccess;
164 mAccess = 0; 164 mAccess = 0;
165 } 165 }
166 // it seems so, that deletion of access deletes backend as well 166 // it seems so, that deletion of access deletes backend as well
167 //delete backend; 167 //delete backend;
168 168
169 return; 169 return;
170} 170}
171 171
172bool ResourceSharpDTM::load() 172bool ResourceSharpDTM::load()
173{ 173{
174 qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); 174 qDebug("ResourceSharpDTM::load: %s", fileName().latin1());
175 175
176 bool res = false; 176 bool res = false;
177 177
178 CardId id; 178 CardId id;
179 179
180 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 180 for (bool res=mAccess->first(); res == true; res=mAccess->next())
181 { 181 {
182 id = mAccess->cardId(); 182 id = mAccess->cardId();
183 183
184 KABC::Addressee addressee; 184 KABC::Addressee addressee;
185 185
186 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 186 res = mConverter->sharpToAddressee( id, mAccess, addressee );
187 187
188 if ( !addressee.isEmpty() && res ) 188 if ( !addressee.isEmpty() && res )
189 { 189 {
190 addressee.setResource( this ); 190 addressee.setResource( this );
191 addressBook()->insertAddressee( addressee ); 191 addressBook()->insertAddressee( addressee );
192 } 192 }
193 } 193 }
194 194
195 return true; 195 return true;
196} 196}
197 197
198bool ResourceSharpDTM::save( Ticket *ticket ) 198bool ResourceSharpDTM::save( Ticket *ticket )
199{ 199{
200 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 200 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
201 201
202 mDirWatch.stopScan(); 202 mDirWatch.stopScan();
203 203
204 KABC::AddressBook::Iterator it; 204 KABC::AddressBook::Iterator it;
205 bool res; 205 bool res;
206 KABC::Addressee::List changedAddressees; 206 KABC::Addressee::List changedAddressees;
207 typedef QMap<int,QString> AddresseeMap;
208 AddresseeMap map;
209 CardId id ;
207 210
208 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 211 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
209 212
210 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 213 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
211 QString uid = (*it).originalExternalUID(); 214 QString uid = (*it).originalExternalUID();
212 CardId id ;
213 bool res; 215 bool res;
214 if ( uid.isEmpty() ) 216 if ( uid.isEmpty() )
215 id = 0; 217 id = 0;
216 else 218 else
217 id = uid.toUInt(); 219 id = uid.toUInt();
218 KABC::Addressee addressee = (*it); 220 KABC::Addressee addressee = (*it);
219 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 221 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
220 res = mAccess->startEditCard(id); 222 res = mAccess->startEditCard(id);
221 if (res == true) 223 if (res == true)
222 { 224 {
223 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 225 res = mConverter->addresseeToSharp( (*it), mAccess, id );
224 if (res == true) 226 if (res == true)
225 { 227 {
228 res = mAccess->finishEditCard(&id);
229 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
230 //(*it).setExternalUID( QString::number( id ) );
231 //(*it).setOriginalExternalUID( QString::number( id ) );
232 map.insert(id,(*it).uid());
233
234#if 0
226 KABC::Addressee addressee; 235 KABC::Addressee addressee;
227 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 236 res = mConverter->sharpToAddressee( id, mAccess, addressee );
228 addressee.setUid((*it).uid() ); 237 addressee.setUid((*it).uid() );
229 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 238 (it*).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
230 res = mAccess->finishEditCard(&id); 239 res = mAccess->finishEditCard(&id);
231 //qDebug("2NEW id is %d", id); 240 //qDebug("2NEW id is %d", id);
232 addressee.setExternalUID( QString::number( id ) ); 241 addressee.setExternalUID( QString::number( id ) );
233 addressee.setOriginalExternalUID( QString::number( id ) ); 242 addressee.setOriginalExternalUID( QString::number( id ) );
234 changedAddressees.append( addressee ); 243 changedAddressees.append( addressee );
244#endif
235 245
236 if (res == false) 246 if (res == false)
237 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 247 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
238 248
239 } 249 }
240 else 250 else
241 { 251 {
242 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 252 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
243 mAccess->cancelEditCard(); 253 mAccess->cancelEditCard();
244 } 254 }
245 } 255 }
246 256
247 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 257 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
248 res = mAccess->deleteCard(&id); 258 res = mAccess->deleteCard(&id);
249 if ( res ) 259 if ( res )
250 qDebug("delete success "); 260 qDebug("delete success ");
251 else 261 else
252 qDebug("delete error "); 262 qDebug("delete error ");
253 263
254 264
255 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 265 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
256 //changed 266 //changed
257 qDebug("changed ****"); 267 qDebug("changed ****");
258 res = mAccess->startEditCard(id); 268 res = mAccess->startEditCard(id);
259 if (res == true) 269 if (res == true)
260 { 270 {
261 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 271 res = mConverter->addresseeToSharp( (*it), mAccess, id );
262 if (res == true) 272 if (res == true)
263 { 273 {
274 res = mAccess->finishEditCard(&id);
275 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
276 map.insert(id,(*it).uid());
277
278#if 0
264 KABC::Addressee addressee; 279 KABC::Addressee addressee;
265 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 280 res = mConverter->sharpToAddressee( id, mAccess, addressee );
266 addressee.setUid((*it).uid() ); 281 addressee.setUid((*it).uid() );
267 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); 282 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
268 changedAddressees.append( addressee ); 283 changedAddressees.append( addressee );
269 res = mAccess->finishEditCard(&id); 284 res = mAccess->finishEditCard(&id);
285#endif
270 if (res == false) 286 if (res == false)
271 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 287 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
272 288
273 } 289 }
274 else 290 else
275 { 291 {
276 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 292 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
277 mAccess->cancelEditCard(); 293 mAccess->cancelEditCard();
278 } 294 }
279 } 295 }
280 } 296 }
281 } 297 }
282 298
283 } 299 }
300 AddresseeMap::Iterator itam;
301 res;
302 for ( res=mAccess->first(); res == true; res=mAccess->next())
303 {
304 id = mAccess->cardId();
305 int idint = id;
306 itam = map.find( idint );
307 if ( itam != map.end() ) {
308 KABC::Addressee addressee;
309 qDebug("found change %d %s ", idint, itam.data().latin1());
310 res = mConverter->sharpToAddressee( id, mAccess, addressee );
311
312 if ( !addressee.isEmpty() && res )
313 {
314 addressee.setResource( this );
315 addressee.setUid( itam.data() );
316 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
317 addressBook()->insertAddressee( addressee , false );
318 }
319 }
320 }
321#if 0
284 KABC::Addressee::List::Iterator it2; 322 KABC::Addressee::List::Iterator it2;
285 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) 323 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) {
324 (*it2).computeCsum( "Sharp_DTM" );
325 qDebug("CSUM: %s ",(*it2).getCsum( "Sharp_DTM" ).latin1() );
286 addressBook()->insertAddressee((*it2)); 326 addressBook()->insertAddressee((*it2));
327 }
328#endif
287 //US mAccess->save(); 329 //US mAccess->save();
288 330
289 mDirWatch.startScan(); 331 mDirWatch.startScan();
290 delete ticket; 332 delete ticket;
291 unlock( fileName() ); 333 unlock( fileName() );
292 334
293 return true; 335 return true;
294} 336}
295 337
296bool ResourceSharpDTM::lock( const QString &lockfileName ) 338bool ResourceSharpDTM::lock( const QString &lockfileName )
297{ 339{
298#ifdef ALLOW_LOCKING 340#ifdef ALLOW_LOCKING
299 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); 341 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1());
300 342
301 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; 343 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl;
302 344
303 QString fn = lockfileName; 345 QString fn = lockfileName;
304 346
305 KURL url(fn); 347 KURL url(fn);
306 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 348 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
307 349
308 kdDebug(5700) << "-- lock name: " << lockName << endl; 350 kdDebug(5700) << "-- lock name: " << lockName << endl;
309 351
310 if (QFile::exists( lockName )) 352 if (QFile::exists( lockName ))
311 { 353 {
312 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); 354 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
313 return false; 355 return false;
314 } 356 }
315 357
316 358
317 QString lockUniqueName; 359 QString lockUniqueName;
318 lockUniqueName = fn + KApplication::randomString( 8 ); 360 lockUniqueName = fn + KApplication::randomString( 8 );
319 361
320 url = lockUniqueName; 362 url = lockUniqueName;
321//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 363//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
322 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 364 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
323 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 365 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
324 366
325 // Create unique file 367 // Create unique file
326 QFile file( mLockUniqueName ); 368 QFile file( mLockUniqueName );
327 file.open( IO_WriteOnly ); 369 file.open( IO_WriteOnly );
328 file.close(); 370 file.close();
329 371
330 // Create lock file 372 // Create lock file
331 int result = 0; 373 int result = 0;
332#ifndef _WIN32_ 374#ifndef _WIN32_
333 result = ::link( QFile::encodeName( mLockUniqueName ), 375 result = ::link( QFile::encodeName( mLockUniqueName ),
334 QFile::encodeName( lockName ) ); 376 QFile::encodeName( lockName ) );
335#endif 377#endif
336 if ( result == 0 ) { 378 if ( result == 0 ) {
337 addressBook()->emitAddressBookLocked(); 379 addressBook()->emitAddressBookLocked();
338 return true; 380 return true;
339 } 381 }
340 382
341 // TODO: check stat 383 // TODO: check stat
342 384
343 return false; 385 return false;
344#else 386#else
345 return true; 387 return true;
346#endif 388#endif
347} 389}
348 390
349void ResourceSharpDTM::unlock( const QString &fileName ) 391void ResourceSharpDTM::unlock( const QString &fileName )
350{ 392{
351#ifdef ALLOW_LOCKING 393#ifdef ALLOW_LOCKING
352 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); 394 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1());
353 395
354 QString fn = fileName; 396 QString fn = fileName;
355 KURL url(fn); 397 KURL url(fn);
356 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 398 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
357 399
358 QFile::remove( lockName ); 400 QFile::remove( lockName );
359 QFile::remove( mLockUniqueName ); 401 QFile::remove( mLockUniqueName );
360 addressBook()->emitAddressBookUnlocked(); 402 addressBook()->emitAddressBookUnlocked();
361#endif 403#endif
362} 404}
363 405
364void ResourceSharpDTM::setFileName( const QString &newFileName ) 406void ResourceSharpDTM::setFileName( const QString &newFileName )
365{ 407{
366 mDirWatch.stopScan(); 408 mDirWatch.stopScan();
367 mDirWatch.removeFile( fileName() ); 409 mDirWatch.removeFile( fileName() );
368 410
369 Resource::setFileName( newFileName ); 411 Resource::setFileName( newFileName );
370 412
371 mDirWatch.addFile( fileName() ); 413 mDirWatch.addFile( fileName() );
372 mDirWatch.startScan(); 414 mDirWatch.startScan();
373 415
374} 416}
375 417
376void ResourceSharpDTM::fileChanged() 418void ResourceSharpDTM::fileChanged()
377{ 419{
378 // There is a small theoretical chance that KDirWatch calls us before 420 // There is a small theoretical chance that KDirWatch calls us before
379 // we are fully constructed 421 // we are fully constructed
380 if (!addressBook()) 422 if (!addressBook())
381 return; 423 return;
382 424
383 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 425 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
384 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 426 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
385 load(); 427 load();
386 addressBook()->emitAddressBookChanged(); 428 addressBook()->emitAddressBookChanged();
387 } 429 }
388} 430}
389 431
390void ResourceSharpDTM::removeAddressee( const Addressee &addr ) 432void ResourceSharpDTM::removeAddressee( const Addressee &addr )
391{ 433{
392} 434}
393 435
394void ResourceSharpDTM::cleanUp() 436void ResourceSharpDTM::cleanUp()
395{ 437{
396 unlock( fileName() ); 438 unlock( fileName() );
397} 439}
398 440
399 441
400 442
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
index f3bf2c5..fccf625 100644
--- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
+++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
@@ -1,431 +1,442 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include "kglobal.h" 28#include "kglobal.h"
29#include <qregexp.h> 29#include <qregexp.h>
30 30
31 31
32#include "sharpdtmconverter.h" 32#include "sharpdtmconverter.h"
33 33
34#include <sl/slcategories.h> 34#include <sl/slcategories.h>
35#include <libkdepim/ksyncprofile.h> 35#include <libkdepim/ksyncprofile.h>
36//US #include <qpe/categoryselect.h> 36//US #include <qpe/categoryselect.h>
37 37
38 38
39using namespace KABC; 39using namespace KABC;
40using namespace SlCategory; 40using namespace SlCategory;
41 41
42SharpDTMConverter::SharpDTMConverter() : catDB(0) 42SharpDTMConverter::SharpDTMConverter() : catDB(0)
43{ 43{
44} 44}
45 45
46SharpDTMConverter::~SharpDTMConverter() 46SharpDTMConverter::~SharpDTMConverter()
47{ 47{
48 deinit(); 48 deinit();
49} 49}
50 50
51bool SharpDTMConverter::init() 51bool SharpDTMConverter::init()
52{ 52{
53 catDB = new SlCategory::SlCategories(); 53 catDB = new SlCategory::SlCategories();
54 54
55 if (!catDB) 55 if (!catDB)
56 return false; 56 return false;
57 57
58// catDB->load( categoryFileName() ); 58// catDB->load( categoryFileName() );
59 return true; 59 return true;
60} 60}
61 61
62void SharpDTMConverter::deinit() 62void SharpDTMConverter::deinit()
63{ 63{
64 if (catDB) 64 if (catDB)
65 { 65 {
66 delete catDB; 66 delete catDB;
67 catDB = 0; 67 catDB = 0;
68 } 68 }
69} 69}
70 70
71bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr ) 71bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr )
72{ 72{
73 SlZDataBase* db = (SlZDataBase*)database; 73 SlZDataBase* db = (SlZDataBase*)database;
74 74
75 // for syncing: we need setting of the two fields 75 // for syncing: we need setting of the two fields
76 addr.setExternalUID( QString::number( contact ) ); 76 addr.setExternalUID( QString::number( contact ) );
77 addr.setOriginalExternalUID( QString::number( contact ) ); 77 addr.setOriginalExternalUID( QString::number( contact ) );
78 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 78 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
79 79
80 80
81 // name 81 // name
82 //qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!"); 82 //qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!");
83 addr.setFormattedName(db->readField(ZdbAdrs::FileAs)); // needs fix 83 addr.setFormattedName(db->readField(ZdbAdrs::FileAs)); // needs fix
84 84
85 addr.setFamilyName( db->readField(ZdbAdrs::LastName) ); 85 addr.setFamilyName( db->readField(ZdbAdrs::LastName) );
86 addr.setGivenName( db->readField(ZdbAdrs::FirstName) ); 86 addr.setGivenName( db->readField(ZdbAdrs::FirstName) );
87 addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) ); 87 addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) );
88 addr.setPrefix( db->readField(ZdbAdrs::Title) ); 88 addr.setPrefix( db->readField(ZdbAdrs::Title) );
89 addr.setSuffix( db->readField(ZdbAdrs::Suffix) ); 89 addr.setSuffix( db->readField(ZdbAdrs::Suffix) );
90 90
91 91
92 QString emailstr = db->readField(ZdbAdrs::Emails); 92 QString emailstr = db->readField(ZdbAdrs::Emails);
93 emailstr.replace( QRegExp(","), " " ); 93 emailstr.replace( QRegExp(","), " " );
94 emailstr.replace( QRegExp(";"), " " ); 94 emailstr.replace( QRegExp(";"), " " );
95 emailstr.replace( QRegExp(":"), " " ); 95 emailstr.replace( QRegExp(":"), " " );
96 //qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1()); 96 //qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1());
97 QStringList emails = QStringList::split(" ", emailstr.simplifyWhiteSpace()); 97 QStringList emails = QStringList::split(" ", emailstr.simplifyWhiteSpace());
98 bool defE = false; 98 bool defE = false;
99 bool found = false; 99 bool found = false;
100 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 100 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
101 if (found ) 101 if (found )
102 defE = false; 102 defE = false;
103 else 103 else
104 found = defE = ((*it).lower() == db->readField(ZdbAdrs::DefaultEmail).lower()); 104 found = defE = ((*it).lower() == db->readField(ZdbAdrs::DefaultEmail).lower());
105 addr.insertEmail( *it, defE ); 105 addr.insertEmail( *it, defE );
106 } 106 }
107 if ( ! found ) 107 if ( ! found )
108 if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty()) 108 if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty())
109 addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true); 109 addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true);
110 110
111 // home 111 // home
112 if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) || 112 if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) ||
113 (!db->readField(ZdbAdrs::HomeCity).isEmpty()) || 113 (!db->readField(ZdbAdrs::HomeCity).isEmpty()) ||
114 (!db->readField(ZdbAdrs::HomeState).isEmpty()) || 114 (!db->readField(ZdbAdrs::HomeState).isEmpty()) ||
115 (!db->readField(ZdbAdrs::HomeZip).isEmpty()) || 115 (!db->readField(ZdbAdrs::HomeZip).isEmpty()) ||
116 (!db->readField(ZdbAdrs::HomeCountry).isEmpty())) 116 (!db->readField(ZdbAdrs::HomeCountry).isEmpty()))
117 { 117 {
118 Address homeaddress; 118 Address homeaddress;
119 homeaddress.setType(Address::Home); 119 homeaddress.setType(Address::Home);
120//US homeaddress.setPostOfficeBox( "" ); 120//US homeaddress.setPostOfficeBox( "" );
121//US homeaddress.setExtended( "" ); 121//US homeaddress.setExtended( "" );
122 homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet) ); 122 homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet) );
123 homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) ); 123 homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) );
124 homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) ); 124 homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) );
125 homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) ); 125 homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) );
126 homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) ); 126 homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) );
127 127
128 addr.insertAddress( homeaddress ); 128 addr.insertAddress( homeaddress );
129 } 129 }
130 130
131 if (!db->readField(ZdbAdrs::HomePhone).isEmpty()) 131 if (!db->readField(ZdbAdrs::HomePhone).isEmpty())
132 { 132 {
133 PhoneNumber homephone; 133 PhoneNumber homephone;
134 homephone.setType( PhoneNumber::Home ); 134 homephone.setType( PhoneNumber::Home );
135 homephone.setNumber( db->readField(ZdbAdrs::HomePhone) ); 135 homephone.setNumber( db->readField(ZdbAdrs::HomePhone) );
136 addr.insertPhoneNumber( homephone ); 136 addr.insertPhoneNumber( homephone );
137 } 137 }
138 138
139 if (!db->readField(ZdbAdrs::HomeFax).isEmpty()) 139 if (!db->readField(ZdbAdrs::HomeFax).isEmpty())
140 { 140 {
141 PhoneNumber homefax; 141 PhoneNumber homefax;
142 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); 142 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
143 homefax.setNumber( db->readField(ZdbAdrs::HomeFax) ); 143 homefax.setNumber( db->readField(ZdbAdrs::HomeFax) );
144 addr.insertPhoneNumber( homefax ); 144 addr.insertPhoneNumber( homefax );
145 } 145 }
146 146
147 if (!db->readField(ZdbAdrs::HomeMobile).isEmpty()) 147 if (!db->readField(ZdbAdrs::HomeMobile).isEmpty())
148 { 148 {
149 PhoneNumber homemobile; 149 PhoneNumber homemobile;
150 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); 150 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
151 homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) ); 151 homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) );
152 addr.insertPhoneNumber( homemobile ); 152 addr.insertPhoneNumber( homemobile );
153 } 153 }
154 154
155 addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) ); 155 addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) );
156 156
157 157
158 // business 158 // business
159 if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) || 159 if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) ||
160 (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) || 160 (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) ||
161 (!db->readField(ZdbAdrs::BusinessState).isEmpty()) || 161 (!db->readField(ZdbAdrs::BusinessState).isEmpty()) ||
162 (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) || 162 (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) ||
163 (!db->readField(ZdbAdrs::BusinessCountry).isEmpty())) 163 (!db->readField(ZdbAdrs::BusinessCountry).isEmpty()))
164 { 164 {
165 Address businessaddress; 165 Address businessaddress;
166 businessaddress.setType(Address::Work); 166 businessaddress.setType(Address::Work);
167//US businessaddress.setPostOfficeBox( "" ); 167//US businessaddress.setPostOfficeBox( "" );
168//US businessaddress.setExtended( "" ); 168//US businessaddress.setExtended( "" );
169 businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet) ); 169 businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet) );
170 businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) ); 170 businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) );
171 businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) ); 171 businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) );
172 businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) ); 172 businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) );
173 businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) ); 173 businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) );
174 174
175 addr.insertAddress( businessaddress ); 175 addr.insertAddress( businessaddress );
176 } 176 }
177 177
178 178
179 if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty()) 179 if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty())
180 { 180 {
181 PhoneNumber businessphone; 181 PhoneNumber businessphone;
182 businessphone.setType( PhoneNumber::Work ); 182 businessphone.setType( PhoneNumber::Work );
183 businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) ); 183 businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) );
184 addr.insertPhoneNumber( businessphone ); 184 addr.insertPhoneNumber( businessphone );
185 } 185 }
186 186
187 if (!db->readField(ZdbAdrs::BusinessFax).isEmpty()) 187 if (!db->readField(ZdbAdrs::BusinessFax).isEmpty())
188 { 188 {
189 PhoneNumber businessfax; 189 PhoneNumber businessfax;
190 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); 190 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
191 businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) ); 191 businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) );
192 addr.insertPhoneNumber( businessfax ); 192 addr.insertPhoneNumber( businessfax );
193 } 193 }
194 194
195 if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty()) 195 if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty())
196 { 196 {
197 PhoneNumber businessmobile; 197 PhoneNumber businessmobile;
198 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); 198 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
199 businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) ); 199 businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) );
200 addr.insertPhoneNumber( businessmobile ); 200 addr.insertPhoneNumber( businessmobile );
201 } 201 }
202 202
203 if (!db->readField(ZdbAdrs::BusinessPager).isEmpty()) 203 if (!db->readField(ZdbAdrs::BusinessPager).isEmpty())
204 { 204 {
205 PhoneNumber businesspager; 205 PhoneNumber businesspager;
206 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); 206 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
207 businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) ); 207 businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) );
208 addr.insertPhoneNumber( businesspager ); 208 addr.insertPhoneNumber( businesspager );
209 } 209 }
210 210
211 addr.setRole( db->readField(ZdbAdrs::JobTitle) ); 211 addr.setRole( db->readField(ZdbAdrs::JobTitle) );
212 addr.setOrganization( db->readField(ZdbAdrs::Company) ); 212 addr.setOrganization( db->readField(ZdbAdrs::Company) );
213 addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) ); 213 addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) );
214 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) ); 214 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) );
215 addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) ); 215 addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) );
216 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) ); 216 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) );
217 addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) ); 217 addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) );
218 218
219 //personal 219 //personal
220 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) ); 220 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) );
221 221
222 QString gen = db->readField(ZdbAdrs::Gender); 222 QString gen = db->readField(ZdbAdrs::Gender);
223 //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1()); 223 //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1());
224 //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited"); 224 //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited");
225 225
226 if (gen == "male") 226 if (gen == "male")
227 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); 227 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male");
228 else if (gen == "female") 228 else if (gen == "female")
229 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); 229 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female");
230 230
231 231
232 QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) ); 232 QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) );
233 if (ann.isValid()) { 233 if (ann.isValid()) {
234 QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); 234 QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate);
235 //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1()); 235 //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1());
236 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); 236 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
237 } 237 }
238 238
239 239
240 addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) ); 240 addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) );
241 241
242 242
243 QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) ); 243 QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) );
244 //qDebug("birtd %s ", birthd.toString().latin1()); 244 //qDebug("birtd %s ", birthd.toString().latin1());
245 if (birthd.isValid()) 245 if (birthd.isValid())
246 addr.setBirthday( birthd ); 246 addr.setBirthday( birthd );
247 247
248 addr.setNickName( db->readField(ZdbAdrs::Nickname) ); 248 addr.setNickName( db->readField(ZdbAdrs::Nickname) );
249 249
250 // others 250 // others
251 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. 251 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
252 QString notes = db->readField(ZdbAdrs::Notes); 252 QString notes = db->readField(ZdbAdrs::Notes);
253 //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n"; 253 //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n";
254 if ( addr.url().isEmpty() ) 254 if ( addr.url().isEmpty() )
255 addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) ); 255 addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) );
256 addr.setNote( db->readField(ZdbAdrs::Notes) ); 256 addr.setNote( db->readField(ZdbAdrs::Notes) );
257 257
258 258
259 259
260//US QString groups() const { return find( Qtopia::Groups ); } 260//US QString groups() const { return find( Qtopia::Groups ); }
261//US QStringList groupList() const; 261//US QStringList groupList() const;
262 262
263 //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" ); 263 //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" );
264 QArray<int> catArray = db->readCategories(); 264 QArray<int> catArray = db->readCategories();
265 QString cat; 265 QString cat;
266 266
267 for ( unsigned int i=0; i < catArray.size(); i++ ) { 267 for ( unsigned int i=0; i < catArray.size(); i++ ) {
268 cat = catDB->label(catArray[i]); 268 cat = catDB->label(catArray[i]);
269 if ( cat.isEmpty() ) 269 if ( cat.isEmpty() )
270 addr.insertCategory(QString::number(catArray[i])); 270 addr.insertCategory(QString::number(catArray[i]));
271 else 271 else
272 addr.insertCategory( cat ); 272 addr.insertCategory( cat );
273 } 273 }
274 274
275 return true; 275 return true;
276} 276}
277 277
278bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ) 278bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact )
279{ 279{
280 bool cellHome = false, cellWork = false; 280 bool cellHome = false, cellWork = false;
281 // name 281 // name
282 database->writeField(ZdbAdrs::LastName, addr.familyName()); 282 database->writeField(ZdbAdrs::LastName, addr.familyName());
283 database->writeField(ZdbAdrs::FirstName, addr.givenName()); 283 database->writeField(ZdbAdrs::FirstName, addr.givenName());
284 database->writeField(ZdbAdrs::MiddleName, addr.additionalName()); 284 database->writeField(ZdbAdrs::MiddleName, addr.additionalName());
285 database->writeField(ZdbAdrs::Title, addr.prefix()); 285 database->writeField(ZdbAdrs::Title, addr.prefix());
286 database->writeField(ZdbAdrs::Suffix, addr.suffix()); 286 database->writeField(ZdbAdrs::Suffix, addr.suffix());
287 287
288 //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() ); 288 //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() );
289 database->writeField(ZdbAdrs::FileAs, addr.formattedName()); 289 QString formattedName = addr.formattedName();
290 database->writeField(ZdbAdrs::FullName, addr.formattedName()); 290 if ( formattedName.isEmpty() ) {
291 if ( !addr.familyName().isEmpty() ) {
292 formattedName = addr.familyName();
293 if ( !addr.givenName().isEmpty() ) {
294 formattedName += ", ";
295 formattedName += addr.givenName();
296 }
297 } else
298 formattedName = addr.givenName();
299 }
300 database->writeField(ZdbAdrs::FileAs, formattedName);
301 database->writeField(ZdbAdrs::FullName, formattedName);
291 302
292 // email 303 // email
293 //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); 304 //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!");
294 //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); 305 //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee");
295 QString emails = addr.emails().join(" "); 306 QString emails = addr.emails().join(" ");
296 database->writeField(ZdbAdrs::Emails, emails ); 307 database->writeField(ZdbAdrs::Emails, emails );
297 308
298 database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); 309 database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() );
299 310
300 311
301 // home 312 // home
302 const Address homeaddress = addr.address(Address::Home); 313 const Address homeaddress = addr.address(Address::Home);
303 if (!homeaddress.isEmpty()) { 314 if (!homeaddress.isEmpty()) {
304 database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); 315 database->writeField(ZdbAdrs::HomeStreet, homeaddress.street());
305 database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); 316 database->writeField(ZdbAdrs::HomeCity, homeaddress.locality());
306 database->writeField(ZdbAdrs::HomeState, homeaddress.region()); 317 database->writeField(ZdbAdrs::HomeState, homeaddress.region());
307 database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); 318 database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode());
308 database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); 319 database->writeField(ZdbAdrs::HomeCountry, homeaddress.country());
309 } 320 }
310 321
311 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); 322 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
312 if (!homephone.number().isEmpty()) 323 if (!homephone.number().isEmpty())
313 database->writeField(ZdbAdrs::HomePhone, homephone.number()); 324 database->writeField(ZdbAdrs::HomePhone, homephone.number());
314 325
315 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); 326 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
316 if (!homefax.number().isEmpty()) 327 if (!homefax.number().isEmpty())
317 database->writeField(ZdbAdrs::HomeFax, homefax.number()); 328 database->writeField(ZdbAdrs::HomeFax, homefax.number());
318 329
319 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); 330 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
320 if (!homemobile.number().isEmpty()) { 331 if (!homemobile.number().isEmpty()) {
321 database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); 332 database->writeField(ZdbAdrs::HomeMobile, homemobile.number());
322 cellHome = true; 333 cellHome = true;
323 } 334 }
324 335
325 database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); 336 database->writeField(ZdbAdrs::HomeWebPage, addr.url().url());
326 337
327 338
328 // business 339 // business
329 const Address businessaddress = addr.address(Address::Work); 340 const Address businessaddress = addr.address(Address::Work);
330 if (!businessaddress.isEmpty()) { 341 if (!businessaddress.isEmpty()) {
331 database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); 342 database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street());
332 database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); 343 database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality());
333 database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); 344 database->writeField(ZdbAdrs::BusinessState, businessaddress.region());
334 database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); 345 database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode());
335 database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); 346 database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country());
336 } 347 }
337 348
338 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); 349 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work );
339 if (!businessphone.number().isEmpty()) 350 if (!businessphone.number().isEmpty())
340 database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); 351 database->writeField(ZdbAdrs::BusinessPhone, businessphone.number());
341 352
342 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); 353 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax );
343 if (!businessfax.number().isEmpty()) 354 if (!businessfax.number().isEmpty())
344 database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); 355 database->writeField(ZdbAdrs::BusinessFax, businessfax.number());
345 356
346 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); 357 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell );
347 if (!businessmobile.number().isEmpty()) { 358 if (!businessmobile.number().isEmpty()) {
348 cellWork = true; 359 cellWork = true;
349 database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); 360 database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number());
350 } 361 }
351 PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); 362 PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell );
352 if (!businessmobile.number().isEmpty()) { 363 if (! mobile.number().isEmpty()) {
353 if ( ! cellHome ) 364 if ( ! cellHome )
354 database->writeField(ZdbAdrs::HomeMobile, mobile.number()); 365 database->writeField(ZdbAdrs::HomeMobile, mobile.number());
355 else if (! cellWork ) 366 else if (! cellWork )
356 database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); 367 database->writeField(ZdbAdrs::BusinessMobile, mobile.number());
357 } 368 }
358 369
359 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); 370 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager );
360 if (!businesspager.number().isEmpty()) 371 if (!businesspager.number().isEmpty())
361 database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); 372 database->writeField(ZdbAdrs::BusinessPager, businesspager.number());
362 373
363 database->writeField(ZdbAdrs::JobTitle, addr.role()); 374 database->writeField(ZdbAdrs::JobTitle, addr.role());
364 database->writeField(ZdbAdrs::Company, addr.organization()); 375 database->writeField(ZdbAdrs::Company, addr.organization());
365 376
366 database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); 377 database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" ));
367 database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); 378 database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" ));
368 database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); 379 database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" ));
369 database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); 380 database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" ));
370 database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); 381 database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" ));
371 382
372 //personal 383 //personal
373 database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); 384 database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" ));
374 385
375 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); 386 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" );
376 //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1()); 387 //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1());
377 //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?"); 388 //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?");
378 //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); 389 //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee");
379 if (gt == "male") 390 if (gt == "male")
380 database->writeField(ZdbAdrs::Gender, "male"); 391 database->writeField(ZdbAdrs::Gender, "male");
381 else if (gt == "female") 392 else if (gt == "female")
382 database->writeField(ZdbAdrs::Gender, "female"); 393 database->writeField(ZdbAdrs::Gender, "female");
383 else 394 else
384 database->writeField(ZdbAdrs::Gender, ""); 395 database->writeField(ZdbAdrs::Gender, "");
385 396
386 397
387 QDate dt = KGlobal::locale()->readDate( 398 QDate dt = KGlobal::locale()->readDate(
388 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate 399 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
389 if ( dt.isValid() ) { 400 if ( dt.isValid() ) {
390 QString dateS = KGlobal::locale()->formatDate(dt, true ); 401 QString dateS = KGlobal::locale()->formatDate(dt, true );
391 database->writeField(ZdbAdrs::Anniversary, dateS ); 402 database->writeField(ZdbAdrs::Anniversary, dateS );
392 } 403 }
393 database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); 404 database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" ));
394 dt = addr.birthday().date(); 405 dt = addr.birthday().date();
395 if ( dt.isValid() ) { 406 if ( dt.isValid() ) {
396 QString dateS = KGlobal::locale()->formatDate(dt, true ); 407 QString dateS = KGlobal::locale()->formatDate(dt, true );
397 database->writeField(ZdbAdrs::Birthday, dateS); 408 database->writeField(ZdbAdrs::Birthday, dateS);
398 } 409 }
399 database->writeField(ZdbAdrs::Nickname, addr.nickName()); 410 database->writeField(ZdbAdrs::Nickname, addr.nickName());
400 411
401 // other 412 // other
402 database->writeField(ZdbAdrs::Notes, addr.note()); 413 database->writeField(ZdbAdrs::Notes, addr.note());
403 414
404//US QString groups() const { return find( Qtopia::Groups ); } 415//US QString groups() const { return find( Qtopia::Groups ); }
405//US QStringList groupList() const; 416//US QStringList groupList() const;
406 417
407 418
408 //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); 419 //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works");
409 420
410 QStringList cats = addr.categories(); 421 QStringList cats = addr.categories();
411 int ii; 422 int ii;
412 for ( ii = 0; ii < cats.count() ;++ii ) { 423 for ( ii = 0; ii < cats.count() ;++ii ) {
413 if ( !catDB->exists( cats[ii] )) 424 if ( !catDB->exists( cats[ii] ))
414 catDB->addCategory(cats[ii]); 425 catDB->addCategory(cats[ii]);
415 } 426 }
416 QArray<int> iar; 427 QArray<int> iar;
417 if ( !cats.isEmpty() ) { 428 if ( !cats.isEmpty() ) {
418 QArray<int> iar = catDB->ids(cats); 429 QArray<int> iar = catDB->ids(cats);
419 qDebug("***cat count is %d ", iar.count()); 430 qDebug("***cat count is %d ", iar.count());
420 database->updateCategories(contact, iar); 431 database->updateCategories(contact, iar);
421 } 432 }
422 433
423 return true; 434 return true;
424} 435}
425 436
426QDate SharpDTMConverter::convertDate( QString s) 437QDate SharpDTMConverter::convertDate( QString s)
427{ 438{
428 QDate dt = KGlobal::locale()->readDate( s ); 439 QDate dt = KGlobal::locale()->readDate( s );
429 return dt; 440 return dt;
430 return QDate (); 441 return QDate ();
431} 442}
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index c1ead9d..c2f031a 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2388,680 +2388,685 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask)
2388 int maxlen = 30; 2388 int maxlen = 30;
2389 if ( QApplication::desktop()->width() > 320 ) 2389 if ( QApplication::desktop()->width() > 320 )
2390 maxlen += 25; 2390 maxlen += 25;
2391 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2391 setCaption ( i18n( "Copy remote file to local machine..." ) );
2392 int fileSize = 0; 2392 int fileSize = 0;
2393 int result = system ( command ); 2393 int result = system ( command );
2394 // 0 : okay 2394 // 0 : okay
2395 // 256: no such file or dir 2395 // 256: no such file or dir
2396 // 2396 //
2397 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2397 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2398 if ( result != 0 ) { 2398 if ( result != 0 ) {
2399 int len = maxlen; 2399 int len = maxlen;
2400 while ( len < command.length() ) { 2400 while ( len < command.length() ) {
2401 command.insert( len , "\n" ); 2401 command.insert( len , "\n" );
2402 len += maxlen +2; 2402 len += maxlen +2;
2403 } 2403 }
2404 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 2404 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2405 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2405 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2406 question, 2406 question,
2407 i18n("Okay!")) ; 2407 i18n("Okay!")) ;
2408 setCaption ("KO/Pi"); 2408 setCaption ("KO/Pi");
2409 return; 2409 return;
2410 } 2410 }
2411 setCaption ( i18n( "Copying succeed." ) ); 2411 setCaption ( i18n( "Copying succeed." ) );
2412 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2412 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2413 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { 2413 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
2414// Event* e = mView->getLastSyncEvent(); 2414// Event* e = mView->getLastSyncEvent();
2415// e->setReadOnly( false ); 2415// e->setReadOnly( false );
2416// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2416// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2417// e->setReadOnly( true ); 2417// e->setReadOnly( true );
2418 if ( KABPrefs::instance()->mWriteBackFile ) { 2418 if ( KABPrefs::instance()->mWriteBackFile ) {
2419 command = prof->getPostSyncCommandAB(); 2419 command = prof->getPostSyncCommandAB();
2420 int fi; 2420 int fi;
2421 if ( (fi = command.find("$PWD$")) > 0 ) { 2421 if ( (fi = command.find("$PWD$")) > 0 ) {
2422 QString pwd = getPassword(); 2422 QString pwd = getPassword();
2423 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2423 command = command.left( fi )+ pwd + command.mid( fi+5 );
2424 2424
2425 } 2425 }
2426 setCaption ( i18n( "Writing back file ..." ) ); 2426 setCaption ( i18n( "Writing back file ..." ) );
2427 result = system ( command ); 2427 result = system ( command );
2428 qDebug("KO: Writing back file result: %d ", result); 2428 qDebug("KO: Writing back file result: %d ", result);
2429 if ( result != 0 ) { 2429 if ( result != 0 ) {
2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2431 return; 2431 return;
2432 } else { 2432 } else {
2433 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2433 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2434 } 2434 }
2435 } 2435 }
2436 } 2436 }
2437 return; 2437 return;
2438} 2438}
2439#include <qpushbutton.h> 2439#include <qpushbutton.h>
2440#include <qradiobutton.h> 2440#include <qradiobutton.h>
2441#include <qbuttongroup.h> 2441#include <qbuttongroup.h>
2442void KABCore::edit_sync_options() 2442void KABCore::edit_sync_options()
2443{ 2443{
2444 //mDialogManager->showSyncOptions(); 2444 //mDialogManager->showSyncOptions();
2445 //KABPrefs::instance()->mSyncAlgoPrefs 2445 //KABPrefs::instance()->mSyncAlgoPrefs
2446 QDialog dia( this, "dia", true ); 2446 QDialog dia( this, "dia", true );
2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2449 QVBoxLayout lay ( &dia ); 2449 QVBoxLayout lay ( &dia );
2450 lay.setSpacing( 2 ); 2450 lay.setSpacing( 2 );
2451 lay.setMargin( 3 ); 2451 lay.setMargin( 3 );
2452 lay.addWidget(&gr); 2452 lay.addWidget(&gr);
2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2459 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2459 //QRadioButton both( i18n("Take both on conflict"), &gr );
2460 QPushButton pb ( "OK", &dia); 2460 QPushButton pb ( "OK", &dia);
2461 lay.addWidget( &pb ); 2461 lay.addWidget( &pb );
2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { 2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) {
2464 case 0: 2464 case 0:
2465 loc.setChecked( true); 2465 loc.setChecked( true);
2466 break; 2466 break;
2467 case 1: 2467 case 1:
2468 rem.setChecked( true ); 2468 rem.setChecked( true );
2469 break; 2469 break;
2470 case 2: 2470 case 2:
2471 newest.setChecked( true); 2471 newest.setChecked( true);
2472 break; 2472 break;
2473 case 3: 2473 case 3:
2474 ask.setChecked( true); 2474 ask.setChecked( true);
2475 break; 2475 break;
2476 case 4: 2476 case 4:
2477 f_loc.setChecked( true); 2477 f_loc.setChecked( true);
2478 break; 2478 break;
2479 case 5: 2479 case 5:
2480 f_rem.setChecked( true); 2480 f_rem.setChecked( true);
2481 break; 2481 break;
2482 case 6: 2482 case 6:
2483 // both.setChecked( true); 2483 // both.setChecked( true);
2484 break; 2484 break;
2485 default: 2485 default:
2486 break; 2486 break;
2487 } 2487 }
2488 if ( dia.exec() ) { 2488 if ( dia.exec() ) {
2489 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2489 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2490 } 2490 }
2491 2491
2492 2492
2493} 2493}
2494QString KABCore::getPassword( ) 2494QString KABCore::getPassword( )
2495{ 2495{
2496 QString retfile = ""; 2496 QString retfile = "";
2497 QDialog dia ( this, "input-dialog", true ); 2497 QDialog dia ( this, "input-dialog", true );
2498 QLineEdit lab ( &dia ); 2498 QLineEdit lab ( &dia );
2499 lab.setEchoMode( QLineEdit::Password ); 2499 lab.setEchoMode( QLineEdit::Password );
2500 QVBoxLayout lay( &dia ); 2500 QVBoxLayout lay( &dia );
2501 lay.setMargin(7); 2501 lay.setMargin(7);
2502 lay.setSpacing(7); 2502 lay.setSpacing(7);
2503 lay.addWidget( &lab); 2503 lay.addWidget( &lab);
2504 dia.setFixedSize( 230,50 ); 2504 dia.setFixedSize( 230,50 );
2505 dia.setCaption( i18n("Enter password") ); 2505 dia.setCaption( i18n("Enter password") );
2506 QPushButton pb ( "OK", &dia); 2506 QPushButton pb ( "OK", &dia);
2507 lay.addWidget( &pb ); 2507 lay.addWidget( &pb );
2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2509 dia.show(); 2509 dia.show();
2510 int res = dia.exec(); 2510 int res = dia.exec();
2511 if ( res ) 2511 if ( res )
2512 retfile = lab.text(); 2512 retfile = lab.text();
2513 dia.hide(); 2513 dia.hide();
2514 qApp->processEvents(); 2514 qApp->processEvents();
2515 return retfile; 2515 return retfile;
2516 2516
2517} 2517}
2518#include <libkcal/syncdefines.h> 2518#include <libkcal/syncdefines.h>
2519 2519
2520KABC::Addressee KABCore::getLastSyncAddressee() 2520KABC::Addressee KABCore::getLastSyncAddressee()
2521{ 2521{
2522 Addressee lse; 2522 Addressee lse;
2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2525 if (lse.isEmpty()) { 2525 if (lse.isEmpty()) {
2526 qDebug("Creating new last-syncAddressee "); 2526 qDebug("Creating new last-syncAddressee ");
2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2528 QString sum = ""; 2528 QString sum = "";
2529 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2529 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2530 sum = "E: "; 2530 sum = "E: ";
2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2532 lse.setRevision( mLastAddressbookSync ); 2532 lse.setRevision( mLastAddressbookSync );
2533 lse.setCategories( i18n("SyncEvent") ); 2533 lse.setCategories( i18n("SyncEvent") );
2534 mAddressBook->insertAddressee( lse ); 2534 mAddressBook->insertAddressee( lse );
2535 } 2535 }
2536 return lse; 2536 return lse;
2537} 2537}
2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2539{ 2539{
2540 2540
2541 //void setZaurusId(int id); 2541 //void setZaurusId(int id);
2542 // int zaurusId() const; 2542 // int zaurusId() const;
2543 // void setZaurusUid(int id); 2543 // void setZaurusUid(int id);
2544 // int zaurusUid() const; 2544 // int zaurusUid() const;
2545 // void setZaurusStat(int id); 2545 // void setZaurusStat(int id);
2546 // int zaurusStat() const; 2546 // int zaurusStat() const;
2547 // 0 equal 2547 // 0 equal
2548 // 1 take local 2548 // 1 take local
2549 // 2 take remote 2549 // 2 take remote
2550 // 3 cancel 2550 // 3 cancel
2551 QDateTime lastSync = mLastAddressbookSync; 2551 QDateTime lastSync = mLastAddressbookSync;
2552 QDateTime localMod = local->revision(); 2552 QDateTime localMod = local->revision();
2553 QDateTime remoteMod = remote->revision(); 2553 QDateTime remoteMod = remote->revision();
2554 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2554 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2555 bool remCh, locCh; 2555 bool remCh, locCh;
2556 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2556 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2557 2557
2558 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2558 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2559 locCh = ( localMod > mLastAddressbookSync ); 2559 locCh = ( localMod > mLastAddressbookSync );
2560 if ( !remCh && ! locCh ) { 2560 if ( !remCh && ! locCh ) {
2561 qDebug("both not changed "); 2561 qDebug("both not changed ");
2562 lastSync = localMod.addDays(1); 2562 lastSync = localMod.addDays(1);
2563 if ( mode <= SYNC_PREF_ASK ) 2563 if ( mode <= SYNC_PREF_ASK )
2564 return 0; 2564 return 0;
2565 } else { 2565 } else {
2566 if ( locCh ) { 2566 if ( locCh ) {
2567 qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2567 qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2568 lastSync = localMod.addDays( -1 ); 2568 lastSync = localMod.addDays( -1 );
2569 if ( !remCh ) 2569 if ( !remCh )
2570 remoteMod =( lastSync.addDays( -1 ) ); 2570 remoteMod =( lastSync.addDays( -1 ) );
2571 } else { 2571 } else {
2572 //qDebug(" not loc changed "); 2572 //qDebug(" not loc changed ");
2573 lastSync = localMod.addDays( 1 ); 2573 lastSync = localMod.addDays( 1 );
2574 if ( remCh ) 2574 if ( remCh )
2575 remoteMod =( lastSync.addDays( 1 ) ); 2575 remoteMod =( lastSync.addDays( 1 ) );
2576 2576
2577 } 2577 }
2578 } 2578 }
2579 full = true; 2579 full = true;
2580 if ( mode < SYNC_PREF_ASK ) 2580 if ( mode < SYNC_PREF_ASK )
2581 mode = SYNC_PREF_ASK; 2581 mode = SYNC_PREF_ASK;
2582 } else { 2582 } else {
2583 if ( localMod == remoteMod ) 2583 if ( localMod == remoteMod )
2584 return 0; 2584 return 0;
2585 2585
2586 } 2586 }
2587 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2587 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2588 2588
2589 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 2589 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2590 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2590 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2591 //full = true; //debug only 2591 //full = true; //debug only
2592 if ( full ) { 2592 if ( full ) {
2593 bool equ = ( (*local) == (*remote) ); 2593 bool equ = ( (*local) == (*remote) );
2594 if ( equ ) { 2594 if ( equ ) {
2595 //qDebug("equal "); 2595 //qDebug("equal ");
2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2597 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2597 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2598 } 2598 }
2599 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2599 if ( mode < SYNC_PREF_FORCE_LOCAL )
2600 return 0; 2600 return 0;
2601 2601
2602 }//else //debug only 2602 }//else //debug only
2603 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2603 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2604 } 2604 }
2605 int result; 2605 int result;
2606 bool localIsNew; 2606 bool localIsNew;
2607 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2607 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2608 2608
2609 if ( full && mode < SYNC_PREF_NEWEST ) 2609 if ( full && mode < SYNC_PREF_NEWEST )
2610 mode = SYNC_PREF_ASK; 2610 mode = SYNC_PREF_ASK;
2611 2611
2612 switch( mode ) { 2612 switch( mode ) {
2613 case SYNC_PREF_LOCAL: 2613 case SYNC_PREF_LOCAL:
2614 if ( lastSync > remoteMod ) 2614 if ( lastSync > remoteMod )
2615 return 1; 2615 return 1;
2616 if ( lastSync > localMod ) 2616 if ( lastSync > localMod )
2617 return 2; 2617 return 2;
2618 return 1; 2618 return 1;
2619 break; 2619 break;
2620 case SYNC_PREF_REMOTE: 2620 case SYNC_PREF_REMOTE:
2621 if ( lastSync > remoteMod ) 2621 if ( lastSync > remoteMod )
2622 return 1; 2622 return 1;
2623 if ( lastSync > localMod ) 2623 if ( lastSync > localMod )
2624 return 2; 2624 return 2;
2625 return 2; 2625 return 2;
2626 break; 2626 break;
2627 case SYNC_PREF_NEWEST: 2627 case SYNC_PREF_NEWEST:
2628 if ( localMod > remoteMod ) 2628 if ( localMod > remoteMod )
2629 return 1; 2629 return 1;
2630 else 2630 else
2631 return 2; 2631 return 2;
2632 break; 2632 break;
2633 case SYNC_PREF_ASK: 2633 case SYNC_PREF_ASK:
2634 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2634 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2635 if ( lastSync > remoteMod ) 2635 if ( lastSync > remoteMod )
2636 return 1; 2636 return 1;
2637 if ( lastSync > localMod ) 2637 if ( lastSync > localMod )
2638 return 2; 2638 return 2;
2639 localIsNew = localMod >= remoteMod; 2639 localIsNew = localMod >= remoteMod;
2640 //qDebug("conflict! ************************************** "); 2640 //qDebug("conflict! ************************************** ");
2641 { 2641 {
2642 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2642 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2643 result = acd.executeD(localIsNew); 2643 result = acd.executeD(localIsNew);
2644 return result; 2644 return result;
2645 } 2645 }
2646 break; 2646 break;
2647 case SYNC_PREF_FORCE_LOCAL: 2647 case SYNC_PREF_FORCE_LOCAL:
2648 return 1; 2648 return 1;
2649 break; 2649 break;
2650 case SYNC_PREF_FORCE_REMOTE: 2650 case SYNC_PREF_FORCE_REMOTE:
2651 return 2; 2651 return 2;
2652 break; 2652 break;
2653 2653
2654 default: 2654 default:
2655 // SYNC_PREF_TAKE_BOTH not implemented 2655 // SYNC_PREF_TAKE_BOTH not implemented
2656 break; 2656 break;
2657 } 2657 }
2658 return 0; 2658 return 0;
2659} 2659}
2660bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2660bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2661{ 2661{
2662 bool syncOK = true; 2662 bool syncOK = true;
2663 int addedAddressee = 0; 2663 int addedAddressee = 0;
2664 int addedAddresseeR = 0; 2664 int addedAddresseeR = 0;
2665 int deletedAddresseeR = 0; 2665 int deletedAddresseeR = 0;
2666 int deletedAddresseeL = 0; 2666 int deletedAddresseeL = 0;
2667 int changedLocal = 0; 2667 int changedLocal = 0;
2668 int changedRemote = 0; 2668 int changedRemote = 0;
2669 //QPtrList<Addressee> el = local->rawAddressees(); 2669 //QPtrList<Addressee> el = local->rawAddressees();
2670 Addressee addresseeR; 2670 Addressee addresseeR;
2671 QString uid; 2671 QString uid;
2672 int take; 2672 int take;
2673 Addressee addresseeL; 2673 Addressee addresseeL;
2674 Addressee addresseeRSync; 2674 Addressee addresseeRSync;
2675 Addressee addresseeLSync; 2675 Addressee addresseeLSync;
2676 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2676 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2677 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2677 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2678 bool fullDateRange = false; 2678 bool fullDateRange = false;
2679 local->resetTempSyncStat(); 2679 local->resetTempSyncStat();
2680 mLastAddressbookSync = QDateTime::currentDateTime(); 2680 mLastAddressbookSync = QDateTime::currentDateTime();
2681 QDateTime modifiedCalendar = mLastAddressbookSync;; 2681 QDateTime modifiedCalendar = mLastAddressbookSync;;
2682 addresseeLSync = getLastSyncAddressee(); 2682 addresseeLSync = getLastSyncAddressee();
2683 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2683 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2684 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2684 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2685 if ( !addresseeR.isEmpty() ) { 2685 if ( !addresseeR.isEmpty() ) {
2686 addresseeRSync = addresseeR; 2686 addresseeRSync = addresseeR;
2687 remote->removeAddressee(addresseeR ); 2687 remote->removeAddressee(addresseeR );
2688 2688
2689 } else { 2689 } else {
2690 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2690 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2691 addresseeRSync = addresseeLSync ; 2691 addresseeRSync = addresseeLSync ;
2692 } else { 2692 } else {
2693 qDebug("FULLDATE 1"); 2693 qDebug("FULLDATE 1");
2694 fullDateRange = true; 2694 fullDateRange = true;
2695 Addressee newAdd; 2695 Addressee newAdd;
2696 addresseeRSync = newAdd; 2696 addresseeRSync = newAdd;
2697 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2697 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2698 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2698 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2699 addresseeRSync.setRevision( mLastAddressbookSync ); 2699 addresseeRSync.setRevision( mLastAddressbookSync );
2700 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2700 addresseeRSync.setCategories( i18n("SyncAddressee") );
2701 } 2701 }
2702 } 2702 }
2703 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2703 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2704 qDebug("FULLDATE 2"); 2704 qDebug("FULLDATE 2");
2705 fullDateRange = true; 2705 fullDateRange = true;
2706 } 2706 }
2707 if ( ! fullDateRange ) { 2707 if ( ! fullDateRange ) {
2708 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2708 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2709 2709
2710 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2710 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2711 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2711 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2712 fullDateRange = true; 2712 fullDateRange = true;
2713 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2713 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2714 } 2714 }
2715 } 2715 }
2716 // fullDateRange = true; // debug only! 2716 // fullDateRange = true; // debug only!
2717 if ( fullDateRange ) 2717 if ( fullDateRange )
2718 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2718 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2719 else 2719 else
2720 mLastAddressbookSync = addresseeLSync.revision(); 2720 mLastAddressbookSync = addresseeLSync.revision();
2721 // for resyncing if own file has changed 2721 // for resyncing if own file has changed
2722 // PENDING fixme later when implemented 2722 // PENDING fixme later when implemented
2723#if 0 2723#if 0
2724 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2724 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2725 mLastAddressbookSync = loadedFileVersion; 2725 mLastAddressbookSync = loadedFileVersion;
2726 qDebug("setting mLastAddressbookSync "); 2726 qDebug("setting mLastAddressbookSync ");
2727 } 2727 }
2728#endif 2728#endif
2729 2729
2730 //qDebug("*************************** "); 2730 //qDebug("*************************** ");
2731 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2731 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2732 QStringList er = remote->uidList(); 2732 QStringList er = remote->uidList();
2733 Addressee inR ;//= er.first(); 2733 Addressee inR ;//= er.first();
2734 Addressee inL; 2734 Addressee inL;
2735 QProgressBar bar( er.count(),0 ); 2735 QProgressBar bar( er.count(),0 );
2736 bar.setCaption (i18n("Syncing - close to abort!") ); 2736 bar.setCaption (i18n("Syncing - close to abort!") );
2737 2737
2738 int w = 300; 2738 int w = 300;
2739 if ( QApplication::desktop()->width() < 320 ) 2739 if ( QApplication::desktop()->width() < 320 )
2740 w = 220; 2740 w = 220;
2741 int h = bar.sizeHint().height() ; 2741 int h = bar.sizeHint().height() ;
2742 int dw = QApplication::desktop()->width(); 2742 int dw = QApplication::desktop()->width();
2743 int dh = QApplication::desktop()->height(); 2743 int dh = QApplication::desktop()->height();
2744 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2744 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2745 bar.show(); 2745 bar.show();
2746 int modulo = (er.count()/10)+1; 2746 int modulo = (er.count()/10)+1;
2747 int incCounter = 0; 2747 int incCounter = 0;
2748 while ( incCounter < er.count()) { 2748 while ( incCounter < er.count()) {
2749 if ( ! bar.isVisible() ) 2749 if ( ! bar.isVisible() )
2750 return false; 2750 return false;
2751 if ( incCounter % modulo == 0 ) 2751 if ( incCounter % modulo == 0 )
2752 bar.setProgress( incCounter ); 2752 bar.setProgress( incCounter );
2753 uid = er[ incCounter ]; 2753 uid = er[ incCounter ];
2754 bool skipIncidence = false; 2754 bool skipIncidence = false;
2755 if ( uid.left(19) == QString("last-syncAddressee-") ) 2755 if ( uid.left(19) == QString("last-syncAddressee-") )
2756 skipIncidence = true; 2756 skipIncidence = true;
2757 QString idS,OidS; 2757 QString idS,OidS;
2758 qApp->processEvents(); 2758 qApp->processEvents();
2759 if ( !skipIncidence ) { 2759 if ( !skipIncidence ) {
2760 inL = local->findByUid( uid ); 2760 inL = local->findByUid( uid );
2761 inR = remote->findByUid( uid ); 2761 inR = remote->findByUid( uid );
2762 //inL.setResource( 0 ); 2762 //inL.setResource( 0 );
2763 //inR.setResource( 0 ); 2763 //inR.setResource( 0 );
2764 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2764 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2765 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2765 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2766 //qDebug("take %d %s ", take, inL.summary().latin1()); 2766 //qDebug("take %d %s ", take, inL.summary().latin1());
2767 if ( take == 3 ) 2767 if ( take == 3 )
2768 return false; 2768 return false;
2769 if ( take == 1 ) {// take local 2769 if ( take == 1 ) {// take local
2770 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2770 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2771 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2771 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2772 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2772 local->insertAddressee( inL, false ); 2773 local->insertAddressee( inL, false );
2773 idS = inR.externalUID(); 2774 idS = inR.externalUID();
2774 OidS = inR.originalExternalUID(); 2775 OidS = inR.originalExternalUID();
2775 } 2776 }
2776 else 2777 else
2777 idS = inR.IDStr(); 2778 idS = inR.IDStr();
2778 remote->removeAddressee( inR ); 2779 remote->removeAddressee( inR );
2779 inR = inL; 2780 inR = inL;
2780 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2781 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2781 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2782 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2782 inR.setOriginalExternalUID( OidS ); 2783 inR.setOriginalExternalUID( OidS );
2783 inR.setExternalUID( idS ); 2784 inR.setExternalUID( idS );
2784 } else { 2785 } else {
2785 inR.setIDStr( idS ); 2786 inR.setIDStr( idS );
2786 } 2787 }
2787 inR.setResource( 0 ); 2788 inR.setResource( 0 );
2788 remote->insertAddressee( inR , false); 2789 remote->insertAddressee( inR , false);
2789 ++changedRemote; 2790 ++changedRemote;
2790 } else { // take == 2 take remote 2791 } else { // take == 2 take remote
2791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2792 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2792 if ( inR.revision().date().year() < 2004 ) 2793 if ( inR.revision().date().year() < 2004 )
2793 inR.setRevision( modifiedCalendar ); 2794 inR.setRevision( modifiedCalendar );
2794 } 2795 }
2795 idS = inL.IDStr(); 2796 idS = inL.IDStr();
2796 local->removeAddressee( inL ); 2797 local->removeAddressee( inL );
2797 inL = inR; 2798 inL = inR;
2798 inL.setIDStr( idS ); 2799 inL.setIDStr( idS );
2800 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2801 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2802 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2803 }
2799 inL.setResource( 0 ); 2804 inL.setResource( 0 );
2800 local->insertAddressee( inL , false ); 2805 local->insertAddressee( inL , false );
2801 ++changedLocal; 2806 ++changedLocal;
2802 } 2807 }
2803 } 2808 }
2804 } else { // no conflict 2809 } else { // no conflict
2805 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2810 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2806 QString des = addresseeLSync.note(); 2811 QString des = addresseeLSync.note();
2807 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2812 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2808 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2813 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2809 remote->insertAddressee( inR, false ); 2814 remote->insertAddressee( inR, false );
2810 ++deletedAddresseeR; 2815 ++deletedAddresseeR;
2811 } else { 2816 } else {
2812 inR.setRevision( modifiedCalendar ); 2817 inR.setRevision( modifiedCalendar );
2813 remote->insertAddressee( inR, false ); 2818 remote->insertAddressee( inR, false );
2814 inL = inR; 2819 inL = inR;
2815 inL.setResource( 0 ); 2820 inL.setResource( 0 );
2816 local->insertAddressee( inL , false); 2821 local->insertAddressee( inL , false);
2817 ++addedAddressee; 2822 ++addedAddressee;
2818 } 2823 }
2819 } else { 2824 } else {
2820 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2825 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2821 inR.setRevision( modifiedCalendar ); 2826 inR.setRevision( modifiedCalendar );
2822 remote->insertAddressee( inR, false ); 2827 remote->insertAddressee( inR, false );
2823 inR.setResource( 0 ); 2828 inR.setResource( 0 );
2824 local->insertAddressee( inR, false ); 2829 local->insertAddressee( inR, false );
2825 ++addedAddressee; 2830 ++addedAddressee;
2826 } else { 2831 } else {
2827 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2832 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2828 remote->removeAddressee( inR ); 2833 remote->removeAddressee( inR );
2829 ++deletedAddresseeR; 2834 ++deletedAddresseeR;
2830 } 2835 }
2831 } 2836 }
2832 } 2837 }
2833 } 2838 }
2834 ++incCounter; 2839 ++incCounter;
2835 } 2840 }
2836 er.clear(); 2841 er.clear();
2837 QStringList el = local->uidList(); 2842 QStringList el = local->uidList();
2838 modulo = (el.count()/10)+1; 2843 modulo = (el.count()/10)+1;
2839 bar.setCaption (i18n("Add / remove addressees") ); 2844 bar.setCaption (i18n("Add / remove addressees") );
2840 bar.setTotalSteps ( el.count() ) ; 2845 bar.setTotalSteps ( el.count() ) ;
2841 bar.show(); 2846 bar.show();
2842 incCounter = 0; 2847 incCounter = 0;
2843 while ( incCounter < el.count()) { 2848 while ( incCounter < el.count()) {
2844 qApp->processEvents(); 2849 qApp->processEvents();
2845 if ( ! bar.isVisible() ) 2850 if ( ! bar.isVisible() )
2846 return false; 2851 return false;
2847 if ( incCounter % modulo == 0 ) 2852 if ( incCounter % modulo == 0 )
2848 bar.setProgress( incCounter ); 2853 bar.setProgress( incCounter );
2849 uid = el[ incCounter ]; 2854 uid = el[ incCounter ];
2850 bool skipIncidence = false; 2855 bool skipIncidence = false;
2851 if ( uid.left(19) == QString("last-syncAddressee-") ) 2856 if ( uid.left(19) == QString("last-syncAddressee-") )
2852 skipIncidence = true; 2857 skipIncidence = true;
2853 if ( !skipIncidence ) { 2858 if ( !skipIncidence ) {
2854 inL = local->findByUid( uid ); 2859 inL = local->findByUid( uid );
2855 inR = remote->findByUid( uid ); 2860 inR = remote->findByUid( uid );
2856 if ( inR.isEmpty() ) { 2861 if ( inR.isEmpty() ) {
2857 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2862 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2858 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2863 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2859 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2864 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2860 local->removeAddressee( inL ); 2865 local->removeAddressee( inL );
2861 ++deletedAddresseeL; 2866 ++deletedAddresseeL;
2862 } else { 2867 } else {
2863 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2868 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2864 inL.removeID(mCurrentSyncDevice ); 2869 inL.removeID(mCurrentSyncDevice );
2865 ++addedAddresseeR; 2870 ++addedAddresseeR;
2866 inL.setRevision( modifiedCalendar ); 2871 inL.setRevision( modifiedCalendar );
2867 local->insertAddressee( inL, false ); 2872 local->insertAddressee( inL, false );
2868 inR = inL; 2873 inR = inL;
2869 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2874 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2870 inR.setResource( 0 ); 2875 inR.setResource( 0 );
2871 remote->insertAddressee( inR, false ); 2876 remote->insertAddressee( inR, false );
2872 } 2877 }
2873 } 2878 }
2874 } else { 2879 } else {
2875 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2880 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2876 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2881 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2877 local->removeAddressee( inL ); 2882 local->removeAddressee( inL );
2878 ++deletedAddresseeL; 2883 ++deletedAddresseeL;
2879 } else { 2884 } else {
2880 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2885 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2881 ++addedAddresseeR; 2886 ++addedAddresseeR;
2882 inL.setRevision( modifiedCalendar ); 2887 inL.setRevision( modifiedCalendar );
2883 local->insertAddressee( inL, false ); 2888 local->insertAddressee( inL, false );
2884 inR = inL; 2889 inR = inL;
2885 inR.setResource( 0 ); 2890 inR.setResource( 0 );
2886 remote->insertAddressee( inR, false ); 2891 remote->insertAddressee( inR, false );
2887 } 2892 }
2888 } 2893 }
2889 } 2894 }
2890 } 2895 }
2891 } 2896 }
2892 ++incCounter; 2897 ++incCounter;
2893 } 2898 }
2894 el.clear(); 2899 el.clear();
2895 bar.hide(); 2900 bar.hide();
2896 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2901 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2897 // get rid of micro seconds 2902 // get rid of micro seconds
2898 QTime t = mLastAddressbookSync.time(); 2903 QTime t = mLastAddressbookSync.time();
2899 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2904 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2900 addresseeLSync.setRevision( mLastAddressbookSync ); 2905 addresseeLSync.setRevision( mLastAddressbookSync );
2901 addresseeRSync.setRevision( mLastAddressbookSync ); 2906 addresseeRSync.setRevision( mLastAddressbookSync );
2902 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2907 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2903 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2908 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2904 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2909 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2905 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2910 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2906 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2911 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2907 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2912 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2908 addresseeRSync.setNote( "" ) ; 2913 addresseeRSync.setNote( "" ) ;
2909 addresseeLSync.setNote( "" ); 2914 addresseeLSync.setNote( "" );
2910 2915
2911 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2916 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2912 remote->insertAddressee( addresseeRSync, false ); 2917 remote->insertAddressee( addresseeRSync, false );
2913 local->insertAddressee( addresseeLSync, false ); 2918 local->insertAddressee( addresseeLSync, false );
2914 QString mes; 2919 QString mes;
2915 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 ); 2920 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 );
2916 if ( KABPrefs::instance()->mShowSyncSummary ) { 2921 if ( KABPrefs::instance()->mShowSyncSummary ) {
2917 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2922 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2918 } 2923 }
2919 qDebug( mes ); 2924 qDebug( mes );
2920 return syncOK; 2925 return syncOK;
2921} 2926}
2922 2927
2923bool KABCore::syncAB(QString filename, int mode) 2928bool KABCore::syncAB(QString filename, int mode)
2924{ 2929{
2925 2930
2926 //pending prepare addresseeview for output 2931 //pending prepare addresseeview for output
2927 //pending detect, if remote file has REV field. if not switch to external sync 2932 //pending detect, if remote file has REV field. if not switch to external sync
2928 mGlobalSyncMode = SYNC_MODE_NORMAL; 2933 mGlobalSyncMode = SYNC_MODE_NORMAL;
2929 AddressBook abLocal(filename,"syncContact"); 2934 AddressBook abLocal(filename,"syncContact");
2930 bool syncOK = false; 2935 bool syncOK = false;
2931 if ( abLocal.load() ) { 2936 if ( abLocal.load() ) {
2932 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2937 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2933 bool external = false; 2938 bool external = false;
2934 bool isXML = false; 2939 bool isXML = false;
2935 if ( filename.right(4) == ".xml") { 2940 if ( filename.right(4) == ".xml") {
2936 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2941 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2937 isXML = true; 2942 isXML = true;
2938 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2943 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2939 } else { 2944 } else {
2940 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2945 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2941 if ( ! lse.isEmpty() ) { 2946 if ( ! lse.isEmpty() ) {
2942 if ( lse.familyName().left(4) == "!E: " ) 2947 if ( lse.familyName().left(4) == "!E: " )
2943 external = true; 2948 external = true;
2944 } else { 2949 } else {
2945 bool found = false; 2950 bool found = false;
2946 AddressBook::Iterator it; 2951 AddressBook::Iterator it;
2947 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2952 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2948 if ( (*it).revision().date().year() > 2003 ) { 2953 if ( (*it).revision().date().year() > 2003 ) {
2949 found = true; 2954 found = true;
2950 break; 2955 break;
2951 } 2956 }
2952 } 2957 }
2953 external = ! found; 2958 external = ! found;
2954 } 2959 }
2955 2960
2956 if ( external ) { 2961 if ( external ) {
2957 qDebug("Setting vcf mode to external "); 2962 qDebug("Setting vcf mode to external ");
2958 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2963 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2959 AddressBook::Iterator it; 2964 AddressBook::Iterator it;
2960 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2965 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2961 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2966 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2962 (*it).computeCsum( mCurrentSyncDevice ); 2967 (*it).computeCsum( mCurrentSyncDevice );
2963 } 2968 }
2964 } 2969 }
2965 } 2970 }
2966 //AddressBook::Iterator it; 2971 //AddressBook::Iterator it;
2967 //QStringList vcards; 2972 //QStringList vcards;
2968 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2973 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2969 // qDebug("Name %s ", (*it).familyName().latin1()); 2974 // qDebug("Name %s ", (*it).familyName().latin1());
2970 //} 2975 //}
2971 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2976 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2972 if ( syncOK ) { 2977 if ( syncOK ) {
2973 if ( KABPrefs::instance()->mWriteBackFile ) 2978 if ( KABPrefs::instance()->mWriteBackFile )
2974 { 2979 {
2975 if ( external ) 2980 if ( external )
2976 abLocal.removeSyncAddressees( !isXML); 2981 abLocal.removeSyncAddressees( !isXML);
2977 qDebug("Saving remote AB "); 2982 qDebug("Saving remote AB ");
2978 abLocal.saveAB(); 2983 abLocal.saveAB();
2979 if ( isXML ) { 2984 if ( isXML ) {
2980 // afterwrite processing 2985 // afterwrite processing
2981 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2986 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2982 } 2987 }
2983 } 2988 }
2984 } 2989 }
2985 setModified(); 2990 setModified();
2986 2991
2987 } 2992 }
2988 if ( syncOK ) 2993 if ( syncOK )
2989 mViewManager->refreshView(); 2994 mViewManager->refreshView();
2990 return syncOK; 2995 return syncOK;
2991#if 0 2996#if 0
2992 2997
2993 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2998 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2994 getEventViewerDialog()->setSyncMode( true ); 2999 getEventViewerDialog()->setSyncMode( true );
2995 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 3000 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2996 getEventViewerDialog()->setSyncMode( false ); 3001 getEventViewerDialog()->setSyncMode( false );
2997 if ( syncOK ) { 3002 if ( syncOK ) {
2998 if ( KOPrefs::instance()->mWriteBackFile ) 3003 if ( KOPrefs::instance()->mWriteBackFile )
2999 { 3004 {
3000 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 3005 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
3001 storage->save(); 3006 storage->save();
3002 } 3007 }
3003 } 3008 }
3004 setModified(); 3009 setModified();
3005 } 3010 }
3006 3011
3007#endif 3012#endif
3008} 3013}
3009 3014
3010void KABCore::confSync() 3015void KABCore::confSync()
3011{ 3016{
3012 static KSyncPrefsDialog* sp = 0; 3017 static KSyncPrefsDialog* sp = 0;
3013 if ( ! sp ) { 3018 if ( ! sp ) {
3014 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 3019 sp = new KSyncPrefsDialog( this, "syncprefs", true );
3015 } 3020 }
3016 sp->usrReadConfig(); 3021 sp->usrReadConfig();
3017#ifndef DESKTOP_VERSION 3022#ifndef DESKTOP_VERSION
3018 sp->showMaximized(); 3023 sp->showMaximized();
3019#else 3024#else
3020 sp->show(); 3025 sp->show();
3021#endif 3026#endif
3022 sp->exec(); 3027 sp->exec();
3023 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 3028 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
3024 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 3029 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
3025 fillSyncMenu(); 3030 fillSyncMenu();
3026} 3031}
3027void KABCore::syncSharp() 3032void KABCore::syncSharp()
3028{ 3033{
3029 if ( ! syncExternal("sharp") ) 3034 if ( ! syncExternal("sharp") )
3030 qDebug("ERROR sync sharp ");; 3035 qDebug("ERROR sync sharp ");;
3031} 3036}
3032bool KABCore::syncExternal(QString resource) 3037bool KABCore::syncExternal(QString resource)
3033{ 3038{
3034 if ( mModified ) 3039 if ( mModified )
3035 save(); 3040 save();
3036 if ( KABPrefs::instance()->mAskForPreferences ) 3041 if ( KABPrefs::instance()->mAskForPreferences )
3037 edit_sync_options(); 3042 edit_sync_options();
3038 qDebug("syncSharp() "); 3043 qDebug("syncSharp() ");
3039 AddressBook abLocal( resource,"syncContact"); 3044 AddressBook abLocal( resource,"syncContact");
3040 bool syncOK = false; 3045 bool syncOK = false;
3041 if ( abLocal.load() ) { 3046 if ( abLocal.load() ) {
3042 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 3047 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
3043 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 3048 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
3044 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 3049 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
3045 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, KABPrefs::instance()->mSyncAlgoPrefs ); 3050 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, KABPrefs::instance()->mSyncAlgoPrefs );
3046 if ( syncOK ) { 3051 if ( syncOK ) {
3047 if ( KABPrefs::instance()->mWriteBackFile ) { 3052 if ( KABPrefs::instance()->mWriteBackFile ) {
3048 abLocal.saveAB(); 3053 abLocal.saveAB();
3049 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 3054 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
3050 } 3055 }
3051 } 3056 }
3052 setModified(); 3057 setModified();
3053 } 3058 }
3054 if ( syncOK ) 3059 if ( syncOK )
3055 mViewManager->refreshView(); 3060 mViewManager->refreshView();
3056 return syncOK; 3061 return syncOK;
3057 3062
3058} 3063}
3059void KABCore::syncPhone() 3064void KABCore::syncPhone()
3060{ 3065{
3061 if ( mModified ) 3066 if ( mModified )
3062 save(); 3067 save();
3063 qDebug("pending syncPhone(); "); 3068 qDebug("pending syncPhone(); ");
3064 //mView->syncPhone(); 3069 //mView->syncPhone();
3065 setModified(); 3070 setModified();
3066 3071
3067} 3072}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index bbed05b..7fae4a9 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -668,768 +668,772 @@ QDate CalendarView::startDate()
668 668
669QDate CalendarView::endDate() 669QDate CalendarView::endDate()
670{ 670{
671 DateList dates = mNavigator->selectedDates(); 671 DateList dates = mNavigator->selectedDates();
672 672
673 return dates.last(); 673 return dates.last();
674} 674}
675 675
676 676
677void CalendarView::createPrinter() 677void CalendarView::createPrinter()
678{ 678{
679#ifndef KORG_NOPRINTER 679#ifndef KORG_NOPRINTER
680 if (!mCalPrinter) { 680 if (!mCalPrinter) {
681 mCalPrinter = new CalPrinter(this, mCalendar); 681 mCalPrinter = new CalPrinter(this, mCalendar);
682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
683 } 683 }
684#endif 684#endif
685} 685}
686 686
687void CalendarView::confSync() 687void CalendarView::confSync()
688{ 688{
689 static KSyncPrefsDialog* sp = 0; 689 static KSyncPrefsDialog* sp = 0;
690 if ( ! sp ) { 690 if ( ! sp ) {
691 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 691 sp = new KSyncPrefsDialog( this, "syncprefs", true );
692 } 692 }
693 sp->usrReadConfig(); 693 sp->usrReadConfig();
694#ifndef DESKTOP_VERSION 694#ifndef DESKTOP_VERSION
695 sp->showMaximized(); 695 sp->showMaximized();
696#else 696#else
697 sp->show(); 697 sp->show();
698#endif 698#endif
699 sp->exec(); 699 sp->exec();
700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
702} 702}
703 703
704 704
705//KOPrefs::instance()->mWriteBackFile 705//KOPrefs::instance()->mWriteBackFile
706//KOPrefs::instance()->mWriteBackExistingOnly 706//KOPrefs::instance()->mWriteBackExistingOnly
707 707
708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
714 714
715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
716{ 716{
717 717
718 //void setZaurusId(int id); 718 //void setZaurusId(int id);
719 // int zaurusId() const; 719 // int zaurusId() const;
720 // void setZaurusUid(int id); 720 // void setZaurusUid(int id);
721 // int zaurusUid() const; 721 // int zaurusUid() const;
722 // void setZaurusStat(int id); 722 // void setZaurusStat(int id);
723 // int zaurusStat() const; 723 // int zaurusStat() const;
724 // 0 equal 724 // 0 equal
725 // 1 take local 725 // 1 take local
726 // 2 take remote 726 // 2 take remote
727 // 3 cancel 727 // 3 cancel
728 QDateTime lastSync = mLastCalendarSync; 728 QDateTime lastSync = mLastCalendarSync;
729 QDateTime localMod = local->lastModified(); 729 QDateTime localMod = local->lastModified();
730 QDateTime remoteMod = remote->lastModified(); 730 QDateTime remoteMod = remote->lastModified();
731 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 731 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
732 bool remCh, locCh; 732 bool remCh, locCh;
733 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 733 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
734 //if ( remCh ) 734 //if ( remCh )
735 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 735 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
736 locCh = ( localMod > mLastCalendarSync ); 736 locCh = ( localMod > mLastCalendarSync );
737 if ( !remCh && ! locCh ) { 737 if ( !remCh && ! locCh ) {
738 //qDebug("both not changed "); 738 //qDebug("both not changed ");
739 lastSync = localMod.addDays(1); 739 lastSync = localMod.addDays(1);
740 if ( mode <= SYNC_PREF_ASK ) 740 if ( mode <= SYNC_PREF_ASK )
741 return 0; 741 return 0;
742 } else { 742 } else {
743 if ( locCh ) { 743 if ( locCh ) {
744 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 744 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
745 lastSync = localMod.addDays( -1 ); 745 lastSync = localMod.addDays( -1 );
746 if ( !remCh ) 746 if ( !remCh )
747 remoteMod = ( lastSync.addDays( -1 ) ); 747 remoteMod = ( lastSync.addDays( -1 ) );
748 } else { 748 } else {
749 //qDebug(" not loc changed "); 749 //qDebug(" not loc changed ");
750 lastSync = localMod.addDays( 1 ); 750 lastSync = localMod.addDays( 1 );
751 if ( remCh ) 751 if ( remCh )
752 remoteMod =( lastSync.addDays( 1 ) ); 752 remoteMod =( lastSync.addDays( 1 ) );
753 753
754 } 754 }
755 } 755 }
756 full = true; 756 full = true;
757 if ( mode < SYNC_PREF_ASK ) 757 if ( mode < SYNC_PREF_ASK )
758 mode = SYNC_PREF_ASK; 758 mode = SYNC_PREF_ASK;
759 } else { 759 } else {
760 if ( localMod == remoteMod ) 760 if ( localMod == remoteMod )
761 if ( local->revision() == remote->revision() ) 761 if ( local->revision() == remote->revision() )
762 return 0; 762 return 0;
763 763
764 } 764 }
765 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 765 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
766 766
767 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 767 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
768 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 768 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
769 //full = true; //debug only 769 //full = true; //debug only
770 if ( full ) { 770 if ( full ) {
771 bool equ = false; 771 bool equ = false;
772 if ( local->type() == "Event" ) { 772 if ( local->type() == "Event" ) {
773 equ = (*((Event*) local) == *((Event*) remote)); 773 equ = (*((Event*) local) == *((Event*) remote));
774 } 774 }
775 else if ( local->type() =="Todo" ) 775 else if ( local->type() =="Todo" )
776 equ = (*((Todo*) local) == (*(Todo*) remote)); 776 equ = (*((Todo*) local) == (*(Todo*) remote));
777 else if ( local->type() =="Journal" ) 777 else if ( local->type() =="Journal" )
778 equ = (*((Journal*) local) == *((Journal*) remote)); 778 equ = (*((Journal*) local) == *((Journal*) remote));
779 if ( equ ) { 779 if ( equ ) {
780 //qDebug("equal "); 780 //qDebug("equal ");
781 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 781 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
782 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 782 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
783 } 783 }
784 if ( mode < SYNC_PREF_FORCE_LOCAL ) 784 if ( mode < SYNC_PREF_FORCE_LOCAL )
785 return 0; 785 return 0;
786 786
787 }//else //debug only 787 }//else //debug only
788 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 788 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
789 } 789 }
790 int result; 790 int result;
791 bool localIsNew; 791 bool localIsNew;
792 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 792 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
793 793
794 if ( full && mode < SYNC_PREF_NEWEST ) 794 if ( full && mode < SYNC_PREF_NEWEST )
795 mode = SYNC_PREF_ASK; 795 mode = SYNC_PREF_ASK;
796 796
797 switch( mode ) { 797 switch( mode ) {
798 case SYNC_PREF_LOCAL: 798 case SYNC_PREF_LOCAL:
799 if ( lastSync > remoteMod ) 799 if ( lastSync > remoteMod )
800 return 1; 800 return 1;
801 if ( lastSync > localMod ) 801 if ( lastSync > localMod )
802 return 2; 802 return 2;
803 return 1; 803 return 1;
804 break; 804 break;
805 case SYNC_PREF_REMOTE: 805 case SYNC_PREF_REMOTE:
806 if ( lastSync > remoteMod ) 806 if ( lastSync > remoteMod )
807 return 1; 807 return 1;
808 if ( lastSync > localMod ) 808 if ( lastSync > localMod )
809 return 2; 809 return 2;
810 return 2; 810 return 2;
811 break; 811 break;
812 case SYNC_PREF_NEWEST: 812 case SYNC_PREF_NEWEST:
813 if ( localMod > remoteMod ) 813 if ( localMod > remoteMod )
814 return 1; 814 return 1;
815 else 815 else
816 return 2; 816 return 2;
817 break; 817 break;
818 case SYNC_PREF_ASK: 818 case SYNC_PREF_ASK:
819 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 819 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
820 if ( lastSync > remoteMod ) 820 if ( lastSync > remoteMod )
821 return 1; 821 return 1;
822 if ( lastSync > localMod ) 822 if ( lastSync > localMod )
823 return 2; 823 return 2;
824 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 824 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
825 localIsNew = localMod >= remoteMod; 825 localIsNew = localMod >= remoteMod;
826 if ( localIsNew ) 826 if ( localIsNew )
827 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
828 else 828 else
829 getEventViewerDialog()->setColorMode( 2 ); 829 getEventViewerDialog()->setColorMode( 2 );
830 getEventViewerDialog()->setIncidence(local); 830 getEventViewerDialog()->setIncidence(local);
831 if ( localIsNew ) 831 if ( localIsNew )
832 getEventViewerDialog()->setColorMode( 2 ); 832 getEventViewerDialog()->setColorMode( 2 );
833 else 833 else
834 getEventViewerDialog()->setColorMode( 1 ); 834 getEventViewerDialog()->setColorMode( 1 );
835 getEventViewerDialog()->addIncidence(remote); 835 getEventViewerDialog()->addIncidence(remote);
836 getEventViewerDialog()->setColorMode( 0 ); 836 getEventViewerDialog()->setColorMode( 0 );
837 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 837 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
838 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 838 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
839 getEventViewerDialog()->showMe(); 839 getEventViewerDialog()->showMe();
840 result = getEventViewerDialog()->executeS( localIsNew ); 840 result = getEventViewerDialog()->executeS( localIsNew );
841 return result; 841 return result;
842 842
843 break; 843 break;
844 case SYNC_PREF_FORCE_LOCAL: 844 case SYNC_PREF_FORCE_LOCAL:
845 return 1; 845 return 1;
846 break; 846 break;
847 case SYNC_PREF_FORCE_REMOTE: 847 case SYNC_PREF_FORCE_REMOTE:
848 return 2; 848 return 2;
849 break; 849 break;
850 850
851 default: 851 default:
852 // SYNC_PREF_TAKE_BOTH not implemented 852 // SYNC_PREF_TAKE_BOTH not implemented
853 break; 853 break;
854 } 854 }
855 return 0; 855 return 0;
856} 856}
857Event* CalendarView::getLastSyncEvent() 857Event* CalendarView::getLastSyncEvent()
858{ 858{
859 Event* lse; 859 Event* lse;
860 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 860 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
861 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 861 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
862 if (!lse) { 862 if (!lse) {
863 lse = new Event(); 863 lse = new Event();
864 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 864 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
865 QString sum = ""; 865 QString sum = "";
866 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 866 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
867 sum = "E: "; 867 sum = "E: ";
868 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 868 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
869 lse->setDtStart( mLastCalendarSync ); 869 lse->setDtStart( mLastCalendarSync );
870 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 870 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
871 lse->setCategories( i18n("SyncEvent") ); 871 lse->setCategories( i18n("SyncEvent") );
872 lse->setReadOnly( true ); 872 lse->setReadOnly( true );
873 mCalendar->addEvent( lse ); 873 mCalendar->addEvent( lse );
874 } 874 }
875 875
876 return lse; 876 return lse;
877 877
878} 878}
879// probaly useless 879// probaly useless
880void CalendarView::setupExternSyncProfiles() 880void CalendarView::setupExternSyncProfiles()
881{ 881{
882 Event* lse; 882 Event* lse;
883 mExternLastSyncEvent.clear(); 883 mExternLastSyncEvent.clear();
884 int i; 884 int i;
885 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 885 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
886 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 886 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
887 if ( lse ) 887 if ( lse )
888 mExternLastSyncEvent.append( lse ); 888 mExternLastSyncEvent.append( lse );
889 else 889 else
890 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 890 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
891 } 891 }
892 892
893} 893}
894// we check, if the to delete event has a id for a profile 894// we check, if the to delete event has a id for a profile
895// if yes, we set this id in the profile to delete 895// if yes, we set this id in the profile to delete
896void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 896void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
897{ 897{
898 if ( lastSync.count() == 0 ) { 898 if ( lastSync.count() == 0 ) {
899 //qDebug(" lastSync.count() == 0"); 899 //qDebug(" lastSync.count() == 0");
900 return; 900 return;
901 } 901 }
902 if ( toDelete->type() == "Journal" ) 902 if ( toDelete->type() == "Journal" )
903 return; 903 return;
904 904
905 Event* eve = lastSync.first(); 905 Event* eve = lastSync.first();
906 906
907 while ( eve ) { 907 while ( eve ) {
908 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 908 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
909 if ( !id.isEmpty() ) { 909 if ( !id.isEmpty() ) {
910 QString des = eve->description(); 910 QString des = eve->description();
911 QString pref = "e"; 911 QString pref = "e";
912 if ( toDelete->type() == "Todo" ) 912 if ( toDelete->type() == "Todo" )
913 pref = "t"; 913 pref = "t";
914 des += pref+ id + ","; 914 des += pref+ id + ",";
915 eve->setReadOnly( false ); 915 eve->setReadOnly( false );
916 eve->setDescription( des ); 916 eve->setDescription( des );
917 //qDebug("setdes %s ", des.latin1()); 917 //qDebug("setdes %s ", des.latin1());
918 eve->setReadOnly( true ); 918 eve->setReadOnly( true );
919 } 919 }
920 eve = lastSync.next(); 920 eve = lastSync.next();
921 } 921 }
922 922
923} 923}
924void CalendarView::checkExternalId( Incidence * inc ) 924void CalendarView::checkExternalId( Incidence * inc )
925{ 925{
926 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 926 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
927 checkExternSyncEvent( lastSync, inc ); 927 checkExternSyncEvent( lastSync, inc );
928 928
929} 929}
930bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 930bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
931{ 931{
932 bool syncOK = true; 932 bool syncOK = true;
933 int addedEvent = 0; 933 int addedEvent = 0;
934 int addedEventR = 0; 934 int addedEventR = 0;
935 int deletedEventR = 0; 935 int deletedEventR = 0;
936 int deletedEventL = 0; 936 int deletedEventL = 0;
937 int changedLocal = 0; 937 int changedLocal = 0;
938 int changedRemote = 0; 938 int changedRemote = 0;
939 //QPtrList<Event> el = local->rawEvents(); 939 //QPtrList<Event> el = local->rawEvents();
940 Event* eventR; 940 Event* eventR;
941 QString uid; 941 QString uid;
942 int take; 942 int take;
943 Event* eventL; 943 Event* eventL;
944 Event* eventRSync; 944 Event* eventRSync;
945 Event* eventLSync; 945 Event* eventLSync;
946 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 946 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
947 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 947 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
948 bool fullDateRange = false; 948 bool fullDateRange = false;
949 local->resetTempSyncStat(); 949 local->resetTempSyncStat();
950 mLastCalendarSync = QDateTime::currentDateTime(); 950 mLastCalendarSync = QDateTime::currentDateTime();
951 QDateTime modifiedCalendar = mLastCalendarSync;; 951 QDateTime modifiedCalendar = mLastCalendarSync;;
952 eventLSync = getLastSyncEvent(); 952 eventLSync = getLastSyncEvent();
953 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 953 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
954 if ( eventR ) { 954 if ( eventR ) {
955 eventRSync = (Event*) eventR->clone(); 955 eventRSync = (Event*) eventR->clone();
956 remote->deleteEvent(eventR ); 956 remote->deleteEvent(eventR );
957 957
958 } else { 958 } else {
959 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 959 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
960 eventRSync = (Event*)eventLSync->clone(); 960 eventRSync = (Event*)eventLSync->clone();
961 } else { 961 } else {
962 fullDateRange = true; 962 fullDateRange = true;
963 eventRSync = new Event(); 963 eventRSync = new Event();
964 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 964 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
965 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 965 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
966 eventRSync->setDtStart( mLastCalendarSync ); 966 eventRSync->setDtStart( mLastCalendarSync );
967 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 967 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
968 eventRSync->setCategories( i18n("SyncEvent") ); 968 eventRSync->setCategories( i18n("SyncEvent") );
969 } 969 }
970 } 970 }
971 if ( eventLSync->dtStart() == mLastCalendarSync ) 971 if ( eventLSync->dtStart() == mLastCalendarSync )
972 fullDateRange = true; 972 fullDateRange = true;
973 973
974 if ( ! fullDateRange ) { 974 if ( ! fullDateRange ) {
975 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 975 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
976 976
977 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 977 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
978 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 978 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
979 fullDateRange = true; 979 fullDateRange = true;
980 } 980 }
981 } 981 }
982 if ( fullDateRange ) 982 if ( fullDateRange )
983 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 983 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
984 else 984 else
985 mLastCalendarSync = eventLSync->dtStart(); 985 mLastCalendarSync = eventLSync->dtStart();
986 // for resyncing if own file has changed 986 // for resyncing if own file has changed
987 if ( mCurrentSyncDevice == "deleteaftersync" ) { 987 if ( mCurrentSyncDevice == "deleteaftersync" ) {
988 mLastCalendarSync = loadedFileVersion; 988 mLastCalendarSync = loadedFileVersion;
989 qDebug("setting mLastCalendarSync "); 989 qDebug("setting mLastCalendarSync ");
990 } 990 }
991 //qDebug("*************************** "); 991 //qDebug("*************************** ");
992 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 992 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
993 QPtrList<Incidence> er = remote->rawIncidences(); 993 QPtrList<Incidence> er = remote->rawIncidences();
994 Incidence* inR = er.first(); 994 Incidence* inR = er.first();
995 Incidence* inL; 995 Incidence* inL;
996 QProgressBar bar( er.count(),0 ); 996 QProgressBar bar( er.count(),0 );
997 bar.setCaption (i18n("Syncing - close to abort!") ); 997 bar.setCaption (i18n("Syncing - close to abort!") );
998 998
999 int w = 300; 999 int w = 300;
1000 if ( QApplication::desktop()->width() < 320 ) 1000 if ( QApplication::desktop()->width() < 320 )
1001 w = 220; 1001 w = 220;
1002 int h = bar.sizeHint().height() ; 1002 int h = bar.sizeHint().height() ;
1003 int dw = QApplication::desktop()->width(); 1003 int dw = QApplication::desktop()->width();
1004 int dh = QApplication::desktop()->height(); 1004 int dh = QApplication::desktop()->height();
1005 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1005 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1006 bar.show(); 1006 bar.show();
1007 int modulo = (er.count()/10)+1; 1007 int modulo = (er.count()/10)+1;
1008 int incCounter = 0; 1008 int incCounter = 0;
1009 while ( inR ) { 1009 while ( inR ) {
1010 if ( ! bar.isVisible() ) 1010 if ( ! bar.isVisible() )
1011 return false; 1011 return false;
1012 if ( incCounter % modulo == 0 ) 1012 if ( incCounter % modulo == 0 )
1013 bar.setProgress( incCounter ); 1013 bar.setProgress( incCounter );
1014 ++incCounter; 1014 ++incCounter;
1015 uid = inR->uid(); 1015 uid = inR->uid();
1016 bool skipIncidence = false; 1016 bool skipIncidence = false;
1017 if ( uid.left(15) == QString("last-syncEvent-") ) 1017 if ( uid.left(15) == QString("last-syncEvent-") )
1018 skipIncidence = true; 1018 skipIncidence = true;
1019 QString idS; 1019 QString idS;
1020 qApp->processEvents(); 1020 qApp->processEvents();
1021 if ( !skipIncidence ) { 1021 if ( !skipIncidence ) {
1022 inL = local->incidence( uid ); 1022 inL = local->incidence( uid );
1023 if ( inL ) { // maybe conflict - same uid in both calendars 1023 if ( inL ) { // maybe conflict - same uid in both calendars
1024 int maxrev = inL->revision(); 1024 int maxrev = inL->revision();
1025 if ( maxrev < inR->revision() ) 1025 if ( maxrev < inR->revision() )
1026 maxrev = inR->revision(); 1026 maxrev = inR->revision();
1027 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1027 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1028 //qDebug("take %d %s ", take, inL->summary().latin1()); 1028 //qDebug("take %d %s ", take, inL->summary().latin1());
1029 if ( take == 3 ) 1029 if ( take == 3 )
1030 return false; 1030 return false;
1031 if ( take == 1 ) {// take local 1031 if ( take == 1 ) {// take local
1032 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1032 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1033 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1033 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1034 else 1034 else
1035 idS = inR->IDStr(); 1035 idS = inR->IDStr();
1036 remote->deleteIncidence( inR ); 1036 remote->deleteIncidence( inR );
1037 if ( inL->revision() < maxrev ) 1037 if ( inL->revision() < maxrev )
1038 inL->setRevision( maxrev ); 1038 inL->setRevision( maxrev );
1039 inR = inL->clone(); 1039 inR = inL->clone();
1040 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1040 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1041 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1041 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1042 inR->setIDStr( idS ); 1042 inR->setIDStr( idS );
1043 remote->addIncidence( inR ); 1043 remote->addIncidence( inR );
1044 ++changedRemote; 1044 ++changedRemote;
1045 } else { 1045 } else {
1046 if ( inR->revision() < maxrev ) 1046 if ( inR->revision() < maxrev )
1047 inR->setRevision( maxrev ); 1047 inR->setRevision( maxrev );
1048 idS = inL->IDStr(); 1048 idS = inL->IDStr();
1049 local->deleteIncidence( inL ); 1049 local->deleteIncidence( inL );
1050 inL = inR->clone(); 1050 inL = inR->clone();
1051 inL->setIDStr( idS ); 1051 inL->setIDStr( idS );
1052 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1053 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1054 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1055 }
1052 local->addIncidence( inL ); 1056 local->addIncidence( inL );
1053 ++changedLocal; 1057 ++changedLocal;
1054 } 1058 }
1055 } 1059 }
1056 } else { // no conflict 1060 } else { // no conflict
1057 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1061 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1058 QString des = eventLSync->description(); 1062 QString des = eventLSync->description();
1059 QString pref = "e"; 1063 QString pref = "e";
1060 if ( inR->type() == "Todo" ) 1064 if ( inR->type() == "Todo" )
1061 pref = "t"; 1065 pref = "t";
1062 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1066 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1063 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1067 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1064 //remote->deleteIncidence( inR ); 1068 //remote->deleteIncidence( inR );
1065 ++deletedEventR; 1069 ++deletedEventR;
1066 } else { 1070 } else {
1067 inR->setLastModified( modifiedCalendar ); 1071 inR->setLastModified( modifiedCalendar );
1068 inL = inR->clone(); 1072 inL = inR->clone();
1069 local->addIncidence( inL ); 1073 local->addIncidence( inL );
1070 ++addedEvent; 1074 ++addedEvent;
1071 } 1075 }
1072 } else { 1076 } else {
1073 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1077 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1074 inR->setLastModified( modifiedCalendar ); 1078 inR->setLastModified( modifiedCalendar );
1075 local->addIncidence( inR->clone() ); 1079 local->addIncidence( inR->clone() );
1076 ++addedEvent; 1080 ++addedEvent;
1077 } else { 1081 } else {
1078 checkExternSyncEvent(eventRSyncSharp, inR); 1082 checkExternSyncEvent(eventRSyncSharp, inR);
1079 remote->deleteIncidence( inR ); 1083 remote->deleteIncidence( inR );
1080 ++deletedEventR; 1084 ++deletedEventR;
1081 } 1085 }
1082 } 1086 }
1083 } 1087 }
1084 } 1088 }
1085 inR = er.next(); 1089 inR = er.next();
1086 } 1090 }
1087 QPtrList<Incidence> el = local->rawIncidences(); 1091 QPtrList<Incidence> el = local->rawIncidences();
1088 inL = el.first(); 1092 inL = el.first();
1089 modulo = (el.count()/10)+1; 1093 modulo = (el.count()/10)+1;
1090 bar.setCaption (i18n("Add / remove events") ); 1094 bar.setCaption (i18n("Add / remove events") );
1091 bar.setTotalSteps ( el.count() ) ; 1095 bar.setTotalSteps ( el.count() ) ;
1092 bar.show(); 1096 bar.show();
1093 incCounter = 0; 1097 incCounter = 0;
1094 1098
1095 while ( inL ) { 1099 while ( inL ) {
1096 1100
1097 qApp->processEvents(); 1101 qApp->processEvents();
1098 if ( ! bar.isVisible() ) 1102 if ( ! bar.isVisible() )
1099 return false; 1103 return false;
1100 if ( incCounter % modulo == 0 ) 1104 if ( incCounter % modulo == 0 )
1101 bar.setProgress( incCounter ); 1105 bar.setProgress( incCounter );
1102 ++incCounter; 1106 ++incCounter;
1103 uid = inL->uid(); 1107 uid = inL->uid();
1104 bool skipIncidence = false; 1108 bool skipIncidence = false;
1105 if ( uid.left(15) == QString("last-syncEvent-") ) 1109 if ( uid.left(15) == QString("last-syncEvent-") )
1106 skipIncidence = true; 1110 skipIncidence = true;
1107 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1111 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1108 skipIncidence = true; 1112 skipIncidence = true;
1109 if ( !skipIncidence ) { 1113 if ( !skipIncidence ) {
1110 inR = remote->incidence( uid ); 1114 inR = remote->incidence( uid );
1111 if ( ! inR ) { 1115 if ( ! inR ) {
1112 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1116 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1113 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1117 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1114 checkExternSyncEvent(eventLSyncSharp, inL); 1118 checkExternSyncEvent(eventLSyncSharp, inL);
1115 local->deleteIncidence( inL ); 1119 local->deleteIncidence( inL );
1116 ++deletedEventL; 1120 ++deletedEventL;
1117 } else { 1121 } else {
1118 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1122 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1119 inL->removeID(mCurrentSyncDevice ); 1123 inL->removeID(mCurrentSyncDevice );
1120 ++addedEventR; 1124 ++addedEventR;
1121 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1125 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1122 inL->setLastModified( modifiedCalendar ); 1126 inL->setLastModified( modifiedCalendar );
1123 inR = inL->clone(); 1127 inR = inL->clone();
1124 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1128 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1125 remote->addIncidence( inR ); 1129 remote->addIncidence( inR );
1126 } 1130 }
1127 } 1131 }
1128 } else { 1132 } else {
1129 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1133 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1130 checkExternSyncEvent(eventLSyncSharp, inL); 1134 checkExternSyncEvent(eventLSyncSharp, inL);
1131 local->deleteIncidence( inL ); 1135 local->deleteIncidence( inL );
1132 ++deletedEventL; 1136 ++deletedEventL;
1133 } else { 1137 } else {
1134 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1138 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1135 ++addedEventR; 1139 ++addedEventR;
1136 inL->setLastModified( modifiedCalendar ); 1140 inL->setLastModified( modifiedCalendar );
1137 remote->addIncidence( inL->clone() ); 1141 remote->addIncidence( inL->clone() );
1138 } 1142 }
1139 } 1143 }
1140 } 1144 }
1141 } 1145 }
1142 } 1146 }
1143 inL = el.next(); 1147 inL = el.next();
1144 } 1148 }
1145 int delFut = 0; 1149 int delFut = 0;
1146 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1150 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1147 er = remote->rawIncidences(); 1151 er = remote->rawIncidences();
1148 inR = er.first(); 1152 inR = er.first();
1149 QDateTime dt; 1153 QDateTime dt;
1150 QDateTime cur = QDateTime::currentDateTime(); 1154 QDateTime cur = QDateTime::currentDateTime();
1151 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); 1155 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
1152 while ( inR ) { 1156 while ( inR ) {
1153 if ( inR->type() == "Todo" ) { 1157 if ( inR->type() == "Todo" ) {
1154 Todo * t = (Todo*)inR; 1158 Todo * t = (Todo*)inR;
1155 if ( t->hasDueDate() ) 1159 if ( t->hasDueDate() )
1156 dt = t->dtDue(); 1160 dt = t->dtDue();
1157 else 1161 else
1158 dt = cur.addSecs( 62 ); 1162 dt = cur.addSecs( 62 );
1159 } 1163 }
1160 else if (inR->type() == "Event" ) { 1164 else if (inR->type() == "Event" ) {
1161 bool ok; 1165 bool ok;
1162 dt = inR->getNextOccurence( cur, &ok ); 1166 dt = inR->getNextOccurence( cur, &ok );
1163 if ( !ok ) 1167 if ( !ok )
1164 dt = cur.addSecs( -62 ); 1168 dt = cur.addSecs( -62 );
1165 } 1169 }
1166 else 1170 else
1167 dt = inR->dtStart(); 1171 dt = inR->dtStart();
1168 if ( dt < cur || dt > end ) { 1172 if ( dt < cur || dt > end ) {
1169 remote->deleteIncidence( inR ); 1173 remote->deleteIncidence( inR );
1170 ++delFut; 1174 ++delFut;
1171 } 1175 }
1172 inR = er.next(); 1176 inR = er.next();
1173 } 1177 }
1174 } 1178 }
1175 bar.hide(); 1179 bar.hide();
1176 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1180 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1177 eventLSync->setReadOnly( false ); 1181 eventLSync->setReadOnly( false );
1178 eventLSync->setDtStart( mLastCalendarSync ); 1182 eventLSync->setDtStart( mLastCalendarSync );
1179 eventRSync->setDtStart( mLastCalendarSync ); 1183 eventRSync->setDtStart( mLastCalendarSync );
1180 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1184 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1181 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1185 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1182 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1186 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1183 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1187 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1184 eventLSync->setReadOnly( true ); 1188 eventLSync->setReadOnly( true );
1185 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1189 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1186 remote->addEvent( eventRSync ); 1190 remote->addEvent( eventRSync );
1187 QString mes; 1191 QString mes;
1188 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1192 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1189 QString delmess; 1193 QString delmess;
1190 if ( delFut ) { 1194 if ( delFut ) {
1191 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 1195 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
1192 mes += delmess; 1196 mes += delmess;
1193 } 1197 }
1194 if ( KOPrefs::instance()->mShowSyncSummary ) { 1198 if ( KOPrefs::instance()->mShowSyncSummary ) {
1195 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1199 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1196 } 1200 }
1197 qDebug( mes ); 1201 qDebug( mes );
1198 mCalendar->checkAlarmForIncidence( 0, true ); 1202 mCalendar->checkAlarmForIncidence( 0, true );
1199 return syncOK; 1203 return syncOK;
1200} 1204}
1201 1205
1202void CalendarView::setSyncDevice( QString s ) 1206void CalendarView::setSyncDevice( QString s )
1203{ 1207{
1204 mCurrentSyncDevice= s; 1208 mCurrentSyncDevice= s;
1205} 1209}
1206void CalendarView::setSyncName( QString s ) 1210void CalendarView::setSyncName( QString s )
1207{ 1211{
1208 mCurrentSyncName= s; 1212 mCurrentSyncName= s;
1209} 1213}
1210bool CalendarView::syncCalendar(QString filename, int mode) 1214bool CalendarView::syncCalendar(QString filename, int mode)
1211{ 1215{
1212 mGlobalSyncMode = SYNC_MODE_NORMAL; 1216 mGlobalSyncMode = SYNC_MODE_NORMAL;
1213 CalendarLocal* calendar = new CalendarLocal(); 1217 CalendarLocal* calendar = new CalendarLocal();
1214 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1218 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1215 FileStorage* storage = new FileStorage( calendar ); 1219 FileStorage* storage = new FileStorage( calendar );
1216 bool syncOK = false; 1220 bool syncOK = false;
1217 storage->setFileName( filename ); 1221 storage->setFileName( filename );
1218 // qDebug("loading ... "); 1222 // qDebug("loading ... ");
1219 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1223 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1220 getEventViewerDialog()->setSyncMode( true ); 1224 getEventViewerDialog()->setSyncMode( true );
1221 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1225 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1222 getEventViewerDialog()->setSyncMode( false ); 1226 getEventViewerDialog()->setSyncMode( false );
1223 if ( syncOK ) { 1227 if ( syncOK ) {
1224 if ( KOPrefs::instance()->mWriteBackFile ) 1228 if ( KOPrefs::instance()->mWriteBackFile )
1225 { 1229 {
1226 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1230 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1227 storage->save(); 1231 storage->save();
1228 } 1232 }
1229 } 1233 }
1230 setModified( true ); 1234 setModified( true );
1231 } 1235 }
1232 delete storage; 1236 delete storage;
1233 delete calendar; 1237 delete calendar;
1234 if ( syncOK ) 1238 if ( syncOK )
1235 updateView(); 1239 updateView();
1236 return syncOK; 1240 return syncOK;
1237} 1241}
1238void CalendarView::syncPhone() 1242void CalendarView::syncPhone()
1239{ 1243{
1240 syncExternal( 1 ); 1244 syncExternal( 1 );
1241} 1245}
1242void CalendarView::syncExternal( int mode ) 1246void CalendarView::syncExternal( int mode )
1243{ 1247{
1244 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1248 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1245 //mCurrentSyncDevice = "sharp-DTM"; 1249 //mCurrentSyncDevice = "sharp-DTM";
1246 if ( KOPrefs::instance()->mAskForPreferences ) 1250 if ( KOPrefs::instance()->mAskForPreferences )
1247 edit_sync_options(); 1251 edit_sync_options();
1248 qApp->processEvents(); 1252 qApp->processEvents();
1249 CalendarLocal* calendar = new CalendarLocal(); 1253 CalendarLocal* calendar = new CalendarLocal();
1250 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1254 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1251 bool syncOK = false; 1255 bool syncOK = false;
1252 bool loadSuccess = false; 1256 bool loadSuccess = false;
1253 PhoneFormat* phoneFormat = 0; 1257 PhoneFormat* phoneFormat = 0;
1254#ifndef DESKTOP_VERSION 1258#ifndef DESKTOP_VERSION
1255 SharpFormat* sharpFormat = 0; 1259 SharpFormat* sharpFormat = 0;
1256 if ( mode == 0 ) { // sharp 1260 if ( mode == 0 ) { // sharp
1257 sharpFormat = new SharpFormat () ; 1261 sharpFormat = new SharpFormat () ;
1258 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1262 loadSuccess = sharpFormat->load( calendar, mCalendar );
1259 1263
1260 } else 1264 } else
1261#endif 1265#endif
1262 if ( mode == 1 ) { // phone 1266 if ( mode == 1 ) { // phone
1263 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1267 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1264 KOPrefs::instance()->mPhoneDevice, 1268 KOPrefs::instance()->mPhoneDevice,
1265 KOPrefs::instance()->mPhoneConnection, 1269 KOPrefs::instance()->mPhoneConnection,
1266 KOPrefs::instance()->mPhoneModel); 1270 KOPrefs::instance()->mPhoneModel);
1267 loadSuccess = phoneFormat->load( calendar,mCalendar); 1271 loadSuccess = phoneFormat->load( calendar,mCalendar);
1268 1272
1269 } else 1273 } else
1270 return; 1274 return;
1271 if ( loadSuccess ) { 1275 if ( loadSuccess ) {
1272 getEventViewerDialog()->setSyncMode( true ); 1276 getEventViewerDialog()->setSyncMode( true );
1273 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1277 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1274 getEventViewerDialog()->setSyncMode( false ); 1278 getEventViewerDialog()->setSyncMode( false );
1275 qApp->processEvents(); 1279 qApp->processEvents();
1276 if ( syncOK ) { 1280 if ( syncOK ) {
1277 if ( KOPrefs::instance()->mWriteBackFile ) 1281 if ( KOPrefs::instance()->mWriteBackFile )
1278 { 1282 {
1279 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1283 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1280 Incidence* inc = iL.first(); 1284 Incidence* inc = iL.first();
1281 if ( phoneFormat ) { 1285 if ( phoneFormat ) {
1282 while ( inc ) { 1286 while ( inc ) {
1283 inc->removeID(mCurrentSyncDevice); 1287 inc->removeID(mCurrentSyncDevice);
1284 inc = iL.next(); 1288 inc = iL.next();
1285 } 1289 }
1286 } 1290 }
1287#ifndef DESKTOP_VERSION 1291#ifndef DESKTOP_VERSION
1288 if ( sharpFormat ) 1292 if ( sharpFormat )
1289 sharpFormat->save(calendar); 1293 sharpFormat->save(calendar);
1290#endif 1294#endif
1291 if ( phoneFormat ) 1295 if ( phoneFormat )
1292 phoneFormat->save(calendar); 1296 phoneFormat->save(calendar);
1293 iL = calendar->rawIncidences(); 1297 iL = calendar->rawIncidences();
1294 inc = iL.first(); 1298 inc = iL.first();
1295 Incidence* loc; 1299 Incidence* loc;
1296 while ( inc ) { 1300 while ( inc ) {
1297 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1301 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1298 loc = mCalendar->incidence(inc->uid() ); 1302 loc = mCalendar->incidence(inc->uid() );
1299 if ( loc ) { 1303 if ( loc ) {
1300 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1304 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1301 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1305 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1302 } 1306 }
1303 } 1307 }
1304 inc = iL.next(); 1308 inc = iL.next();
1305 } 1309 }
1306 Incidence* lse = getLastSyncEvent(); 1310 Incidence* lse = getLastSyncEvent();
1307 if ( lse ) { 1311 if ( lse ) {
1308 lse->setReadOnly( false ); 1312 lse->setReadOnly( false );
1309 lse->setDescription( "" ); 1313 lse->setDescription( "" );
1310 lse->setReadOnly( true ); 1314 lse->setReadOnly( true );
1311 } 1315 }
1312 } 1316 }
1313 } 1317 }
1314 setModified( true ); 1318 setModified( true );
1315 } else { 1319 } else {
1316 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1320 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1317 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1321 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1318 question, i18n("Ok")) ; 1322 question, i18n("Ok")) ;
1319 1323
1320 } 1324 }
1321 delete calendar; 1325 delete calendar;
1322 updateView(); 1326 updateView();
1323 return ;//syncOK; 1327 return ;//syncOK;
1324 1328
1325} 1329}
1326void CalendarView::syncSharp() 1330void CalendarView::syncSharp()
1327{ 1331{
1328 syncExternal( 0 ); 1332 syncExternal( 0 );
1329 1333
1330} 1334}
1331 1335
1332 1336
1333//#include <kabc/stdaddressbook.h> 1337//#include <kabc/stdaddressbook.h>
1334bool CalendarView::importBday() 1338bool CalendarView::importBday()
1335{ 1339{
1336#if 0 1340#if 0
1337 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1341 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1338 KABC::AddressBook::Iterator it; 1342 KABC::AddressBook::Iterator it;
1339 int count = 0; 1343 int count = 0;
1340 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1344 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1341 ++count; 1345 ++count;
1342 } 1346 }
1343 QProgressBar bar(count,0 ); 1347 QProgressBar bar(count,0 );
1344 int w = 300; 1348 int w = 300;
1345 if ( QApplication::desktop()->width() < 320 ) 1349 if ( QApplication::desktop()->width() < 320 )
1346 w = 220; 1350 w = 220;
1347 int h = bar.sizeHint().height() ; 1351 int h = bar.sizeHint().height() ;
1348 int dw = QApplication::desktop()->width(); 1352 int dw = QApplication::desktop()->width();
1349 int dh = QApplication::desktop()->height(); 1353 int dh = QApplication::desktop()->height();
1350 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1354 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1351 bar.show(); 1355 bar.show();
1352 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1356 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1353 qApp->processEvents(); 1357 qApp->processEvents();
1354 count = 0; 1358 count = 0;
1355 int addCount = 0; 1359 int addCount = 0;
1356 KCal::Attendee* a = 0; 1360 KCal::Attendee* a = 0;
1357 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1361 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1358 if ( ! bar.isVisible() ) 1362 if ( ! bar.isVisible() )
1359 return false; 1363 return false;
1360 bar.setProgress( count++ ); 1364 bar.setProgress( count++ );
1361 qApp->processEvents(); 1365 qApp->processEvents();
1362 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1366 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1363 if ( (*it).birthday().date().isValid() ){ 1367 if ( (*it).birthday().date().isValid() ){
1364 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1368 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1365 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1369 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1366 ++addCount; 1370 ++addCount;
1367 } 1371 }
1368 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1372 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1369 if ( anni.isValid() ){ 1373 if ( anni.isValid() ){
1370 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1374 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1371 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1375 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1372 ++addCount; 1376 ++addCount;
1373 } 1377 }
1374 } 1378 }
1375 updateView(); 1379 updateView();
1376 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1380 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1377#endif 1381#endif
1378 return true; 1382 return true;
1379} 1383}
1380 1384
1381bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1385bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1382{ 1386{
1383 //qDebug("addAnni "); 1387 //qDebug("addAnni ");
1384 Event * ev = new Event(); 1388 Event * ev = new Event();
1385 if ( a ) { 1389 if ( a ) {
1386 ev->addAttendee( a ); 1390 ev->addAttendee( a );
1387 } 1391 }
1388 QString kind; 1392 QString kind;
1389 if ( birthday ) 1393 if ( birthday )
1390 kind = i18n( "Birthday" ); 1394 kind = i18n( "Birthday" );
1391 else 1395 else
1392 kind = i18n( "Anniversary" ); 1396 kind = i18n( "Anniversary" );
1393 ev->setSummary( name + " - " + kind ); 1397 ev->setSummary( name + " - " + kind );
1394 ev->setOrganizer( "nobody@nowhere" ); 1398 ev->setOrganizer( "nobody@nowhere" );
1395 ev->setCategories( kind ); 1399 ev->setCategories( kind );
1396 ev->setDtStart( QDateTime(date) ); 1400 ev->setDtStart( QDateTime(date) );
1397 ev->setDtEnd( QDateTime(date) ); 1401 ev->setDtEnd( QDateTime(date) );
1398 ev->setFloats( true ); 1402 ev->setFloats( true );
1399 Recurrence * rec = ev->recurrence(); 1403 Recurrence * rec = ev->recurrence();
1400 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1404 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1401 rec->addYearlyNum( date.month() ); 1405 rec->addYearlyNum( date.month() );
1402 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1406 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1403 delete ev; 1407 delete ev;
1404 return false; 1408 return false;
1405 } 1409 }
1406 return true; 1410 return true;
1407 1411
1408} 1412}
1409bool CalendarView::importQtopia( const QString &categories, 1413bool CalendarView::importQtopia( const QString &categories,
1410 const QString &datebook, 1414 const QString &datebook,
1411 const QString &todolist ) 1415 const QString &todolist )
1412{ 1416{
1413 1417
1414 QtopiaFormat qtopiaFormat; 1418 QtopiaFormat qtopiaFormat;
1415 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1419 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1416 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1420 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1417 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1421 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1418 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1422 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1419 1423
1420 updateView(); 1424 updateView();
1421 return true; 1425 return true;
1422 1426
1423#if 0 1427#if 0
1424 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1428 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1425 mCurrentSyncDevice = "qtopia-XML"; 1429 mCurrentSyncDevice = "qtopia-XML";
1426 if ( KOPrefs::instance()->mAskForPreferences ) 1430 if ( KOPrefs::instance()->mAskForPreferences )
1427 edit_sync_options(); 1431 edit_sync_options();
1428 qApp->processEvents(); 1432 qApp->processEvents();
1429 CalendarLocal* calendar = new CalendarLocal(); 1433 CalendarLocal* calendar = new CalendarLocal();
1430 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1434 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1431 bool syncOK = false; 1435 bool syncOK = false;
1432 QtopiaFormat qtopiaFormat; 1436 QtopiaFormat qtopiaFormat;
1433 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1437 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1434 bool loadOk = true; 1438 bool loadOk = true;
1435 if ( !categories.isEmpty() ) 1439 if ( !categories.isEmpty() )