-rw-r--r-- | kabc/plugins/file/file.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/file/fileE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 74 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.h | 8 |
4 files changed, 44 insertions, 42 deletions
diff --git a/kabc/plugins/file/file.pro b/kabc/plugins/file/file.pro index 32555a2..154ef2a 100644 --- a/kabc/plugins/file/file.pro +++ b/kabc/plugins/file/file.pro | |||
@@ -1,12 +1,12 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on release |
3 | #release debug | 3 | #release debug |
4 | 4 | ||
5 | TARGET = microkabc_file | 5 | TARGET = microkabc_file |
6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat | 6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat |
7 | 7 | ||
8 | DESTDIR = ../../../bin | 8 | DESTDIR = ../../../bin |
9 | #LIBS += -lmicrokde -lmicrokabc | 9 | #LIBS += -lmicrokde -lmicrokabc |
10 | #LIBS += -L$(QPEDIR)/lib | 10 | #LIBS += -L$(QPEDIR)/lib |
11 | 11 | ||
12 | INTERFACES = \ | 12 | INTERFACES = \ |
diff --git a/kabc/plugins/file/fileE.pro b/kabc/plugins/file/fileE.pro index d19a26d..3015806 100644 --- a/kabc/plugins/file/fileE.pro +++ b/kabc/plugins/file/fileE.pro | |||
@@ -1,12 +1,12 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on release |
3 | #release debug | 3 | #release debug |
4 | 4 | ||
5 | TARGET = microkabc_file | 5 | TARGET = microkabc_file |
6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat | 6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat |
7 | OBJECTS_DIR = obj/$(PLATFORM) | 7 | OBJECTS_DIR = obj/$(PLATFORM) |
8 | MOC_DIR = moc/$(PLATFORM) | 8 | MOC_DIR = moc/$(PLATFORM) |
9 | DESTDIR = $(QPEDIR)/lib | 9 | DESTDIR = $(QPEDIR)/lib |
10 | LIBS += -lmicrokde -lmicrokabc | 10 | LIBS += -lmicrokde -lmicrokabc |
11 | LIBS += -L$(QPEDIR)/lib | 11 | LIBS += -L$(QPEDIR)/lib |
12 | 12 | ||
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 1d3acec..361b36b 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -48,33 +48,35 @@ $Id$ | |||
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 | 52 | ||
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncwidget.h" | ||
55 | |||
54 | 56 | ||
55 | using namespace KABC; | 57 | using namespace KABC; |
56 | 58 | ||
57 | extern "C" | 59 | extern "C" |
58 | #ifdef _WIN32_ | 60 | #ifdef _WIN32_ |
59 | __declspec(dllexport) | 61 | __declspec(dllexport) |
60 | #else | 62 | #else |
61 | { | 63 | { |
62 | #endif | 64 | #endif |
63 | 65 | ||
64 | //US void *init_kabc_file() | 66 | //US void *init_kabc_file() |
65 | void *init_microkabc_file() | 67 | void *init_microkabc_file() |
66 | { | 68 | { |
67 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); | 69 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, KRES::SyncWidget>(); |
68 | } | 70 | } |
69 | #ifndef _WIN32_ | 71 | #ifndef _WIN32_ |
70 | } | 72 | } |
71 | #endif | 73 | #endif |
72 | 74 | ||
73 | ResourceFile::ResourceFile( const KConfig *config ) | 75 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) |
74 | : Resource( config ) , mFormat( 0 ) | 76 | : Resource( config, syncable ) , mFormat( 0 ) |
75 | { | 77 | { |
76 | QString fileName, formatName; | 78 | QString fileName, formatName; |
77 | 79 | ||
78 | KConfig *cfg = (KConfig *)config; | 80 | KConfig *cfg = (KConfig *)config; |
79 | if ( cfg ) { | 81 | if ( cfg ) { |
80 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | 82 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); |
@@ -86,15 +88,15 @@ ResourceFile::ResourceFile( const KConfig *config ) | |||
86 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); | 88 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); |
87 | } | 89 | } |
88 | 90 | ||
89 | init( fileName, formatName ); | 91 | init( fileName, formatName ); |
90 | } | 92 | } |
91 | 93 | ||
92 | ResourceFile::ResourceFile( const QString &fileName, | 94 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , |
93 | const QString &formatName ) | 95 | const QString &formatName ) |
94 | : Resource( 0 ) | 96 | : Resource( 0, syncable ) |
95 | { | 97 | { |
96 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 98 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
97 | init( fileName, formatName ); | 99 | init( fileName, formatName ); |
98 | } | 100 | } |
99 | 101 | ||
100 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 102 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
@@ -136,20 +138,20 @@ ResourceFile::~ResourceFile() | |||
136 | mFormat = 0; | 138 | mFormat = 0; |
137 | } | 139 | } |
138 | 140 | ||
139 | void ResourceFile::writeConfig( KConfig *config ) | 141 | void ResourceFile::writeConfig( KConfig *config ) |
140 | { | 142 | { |
141 | 143 | ||
142 | config->setGroup( "Resource_" + identifier() ); | 144 | config->setGroup( "Resource_" + identifier() ); |
143 | Resource::writeConfig( config ); | 145 | Resource::writeConfig( config ); |
144 | 146 | ||
145 | config->writeEntry( "FileName", mFileName ); | 147 | config->writeEntry( "FileName", mFileName ); |
146 | config->writeEntry( "FileFormat", mFormatName ); | 148 | config->writeEntry( "FileFormat", mFormatName ); |
147 | 149 | ||
148 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 150 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
149 | 151 | ||
150 | } | 152 | } |
151 | 153 | ||
152 | Ticket *ResourceFile::requestSaveTicket() | 154 | Ticket *ResourceFile::requestSaveTicket() |
153 | { | 155 | { |
154 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 156 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
155 | 157 | ||
@@ -194,94 +196,94 @@ bool ResourceFile::doOpen() | |||
194 | void ResourceFile::doClose() | 196 | void ResourceFile::doClose() |
195 | { | 197 | { |
196 | } | 198 | } |
197 | 199 | ||
198 | bool ResourceFile::load() | 200 | bool ResourceFile::load() |
199 | { | 201 | { |
200 | 202 | ||
201 | 203 | ||
202 | QFile file( mFileName ); | 204 | QFile file( mFileName ); |
203 | if ( !file.open( IO_ReadOnly ) ) { | 205 | if ( !file.open( IO_ReadOnly ) ) { |
204 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 206 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); |
205 | return false; | 207 | return false; |
206 | } | 208 | } |
207 | 209 | ||
208 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 210 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
209 | 211 | ||
210 | return mFormat->loadAll( addressBook(), this, &file ); | 212 | return mFormat->loadAll( addressBook(), this, &file ); |
211 | } | 213 | } |
212 | 214 | ||
213 | bool ResourceFile::save( Ticket *ticket ) | 215 | bool ResourceFile::save( Ticket *ticket ) |
214 | { | 216 | { |
215 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 217 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
216 | 218 | ||
217 | 219 | ||
218 | // create backup file | 220 | // create backup file |
219 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 221 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
220 | 222 | ||
221 | /*US we use a simpler method to create a backupfile | 223 | /*US we use a simpler method to create a backupfile |
222 | 224 | ||
223 | (void) KSaveFile::backupFile( mFileName, QString::null | 225 | (void) KSaveFile::backupFile( mFileName, QString::null |
224 | ,extension ); | 226 | ,extension ); |
225 | 227 | ||
226 | KSaveFile saveFile( mFileName ); | 228 | KSaveFile saveFile( mFileName ); |
227 | bool ok = false; | 229 | bool ok = false; |
228 | if ( saveFile.status() == 0 && saveFile.file() ) | 230 | if ( saveFile.status() == 0 && saveFile.file() ) |
229 | { | 231 | { |
230 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 232 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
231 | ok = saveFile.close(); | 233 | ok = saveFile.close(); |
232 | } | 234 | } |
233 | */ | 235 | */ |
234 | 236 | ||
235 | //US ToDo: write backupfile | 237 | //US ToDo: write backupfile |
236 | QFile info; | 238 | QFile info; |
237 | info.setName( mFileName ); | 239 | info.setName( mFileName ); |
238 | bool ok = info.open( IO_WriteOnly ); | 240 | bool ok = info.open( IO_WriteOnly ); |
239 | if ( ok ) { | 241 | if ( ok ) { |
240 | mFormat->saveAll( addressBook(), this, &info ); | 242 | mFormat->saveAll( addressBook(), this, &info ); |
241 | 243 | ||
242 | info.close(); | 244 | info.close(); |
243 | ok = true; | 245 | ok = true; |
244 | } | 246 | } |
245 | else { | 247 | else { |
246 | 248 | ||
247 | } | 249 | } |
248 | 250 | ||
249 | if ( !ok ) | 251 | if ( !ok ) |
250 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 252 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
251 | 253 | ||
252 | delete ticket; | 254 | delete ticket; |
253 | unlock( mFileName ); | 255 | unlock( mFileName ); |
254 | 256 | ||
255 | return ok; | 257 | return ok; |
256 | 258 | ||
257 | qDebug("ResourceFile::save has to be changed"); | 259 | qDebug("ResourceFile::save has to be changed"); |
258 | return true; | 260 | return true; |
259 | } | 261 | } |
260 | 262 | ||
261 | bool ResourceFile::lock( const QString &fileName ) | 263 | bool ResourceFile::lock( const QString &fileName ) |
262 | { | 264 | { |
263 | 265 | ||
264 | 266 | ||
265 | QString fn = fileName; | 267 | QString fn = fileName; |
266 | 268 | ||
267 | //US change the implementation how the lockfilename is getting created | 269 | //US change the implementation how the lockfilename is getting created |
268 | //US fn.replace( QRegExp("/"), "_" ); | 270 | //US fn.replace( QRegExp("/"), "_" ); |
269 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 271 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
270 | 272 | ||
271 | KURL url(fn); | 273 | KURL url(fn); |
272 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 274 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
273 | 275 | ||
274 | 276 | ||
275 | 277 | ||
276 | if (QFile::exists( lockName )) return false; | 278 | if (QFile::exists( lockName )) return false; |
277 | 279 | ||
278 | QString lockUniqueName; | 280 | QString lockUniqueName; |
279 | lockUniqueName = fn + KApplication::randomString( 8 ); | 281 | lockUniqueName = fn + KApplication::randomString( 8 ); |
280 | 282 | ||
281 | url = lockUniqueName; | 283 | url = lockUniqueName; |
282 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 284 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
283 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 285 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
284 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 286 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
285 | 287 | ||
286 | // Create unique file | 288 | // Create unique file |
287 | QFile file( mLockUniqueName ); | 289 | QFile file( mLockUniqueName ); |
@@ -308,32 +310,32 @@ void ResourceFile::unlock( const QString &fileName ) | |||
308 | { | 310 | { |
309 | QString fn = fileName; | 311 | QString fn = fileName; |
310 | //US change the implementation how the lockfilename is getting created | 312 | //US change the implementation how the lockfilename is getting created |
311 | //US fn.replace( QRegExp( "/" ), "_" ); | 313 | //US fn.replace( QRegExp( "/" ), "_" ); |
312 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 314 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
313 | //US QString lockName = fn + ".lock"; | 315 | //US QString lockName = fn + ".lock"; |
314 | KURL url(fn); | 316 | KURL url(fn); |
315 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 317 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
316 | 318 | ||
317 | QFile::remove( lockName ); | 319 | QFile::remove( lockName ); |
318 | QFile::remove( mLockUniqueName ); | 320 | QFile::remove( mLockUniqueName ); |
319 | addressBook()->emitAddressBookUnlocked(); | 321 | addressBook()->emitAddressBookUnlocked(); |
320 | } | 322 | } |
321 | 323 | ||
322 | void ResourceFile::setFileName( const QString &fileName ) | 324 | void ResourceFile::setFileName( const QString &fileName ) |
323 | { | 325 | { |
324 | mDirWatch.stopScan(); | 326 | mDirWatch.stopScan(); |
325 | mDirWatch.removeFile( mFileName ); | 327 | mDirWatch.removeFile( mFileName ); |
326 | 328 | ||
327 | mFileName = fileName; | 329 | mFileName = fileName; |
328 | 330 | ||
329 | 331 | ||
330 | mDirWatch.addFile( mFileName ); | 332 | mDirWatch.addFile( mFileName ); |
331 | mDirWatch.startScan(); | 333 | mDirWatch.startScan(); |
332 | 334 | ||
333 | //US simulate KDirWatch event | 335 | //US simulate KDirWatch event |
334 | //US fileChanged(); | 336 | //US fileChanged(); |
335 | } | 337 | } |
336 | 338 | ||
337 | QString ResourceFile::fileName() const | 339 | QString ResourceFile::fileName() const |
338 | { | 340 | { |
339 | return mFileName; | 341 | return mFileName; |
@@ -343,26 +345,26 @@ void ResourceFile::setFormat( const QString &format ) | |||
343 | { | 345 | { |
344 | mFormatName = format; | 346 | mFormatName = format; |
345 | delete mFormat; | 347 | delete mFormat; |
346 | 348 | ||
347 | FormatFactory *factory = FormatFactory::self(); | 349 | FormatFactory *factory = FormatFactory::self(); |
348 | mFormat = factory->format( mFormatName ); | 350 | mFormat = factory->format( mFormatName ); |
349 | /*US | 351 | /*US |
350 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 352 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
351 | if (mFormatName == "vcard") { | 353 | if (mFormatName == "vcard") { |
352 | mFormat = new VCardFormatPlugin2(); | 354 | mFormat = new VCardFormatPlugin2(); |
353 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 355 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
354 | } | 356 | } |
355 | else if (mFormatName == "binary") { | 357 | else if (mFormatName == "binary") { |
356 | mFormat = new BinaryFormat(); | 358 | mFormat = new BinaryFormat(); |
357 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 359 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
358 | } | 360 | } |
359 | else | 361 | else |
360 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 362 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
361 | */ | 363 | */ |
362 | 364 | ||
363 | } | 365 | } |
364 | 366 | ||
365 | QString ResourceFile::format() const | 367 | QString ResourceFile::format() const |
366 | { | 368 | { |
367 | return mFormatName; | 369 | return mFormatName; |
368 | } | 370 | } |
@@ -370,14 +372,14 @@ QString ResourceFile::format() const | |||
370 | void ResourceFile::fileChanged() | 372 | void ResourceFile::fileChanged() |
371 | { | 373 | { |
372 | // There is a small theoretical chance that KDirWatch calls us before | 374 | // There is a small theoretical chance that KDirWatch calls us before |
373 | // we are fully constructed | 375 | // we are fully constructed |
374 | if (!addressBook()) | 376 | if (!addressBook()) |
375 | return; | 377 | return; |
376 | 378 | ||
377 | 379 | ||
378 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 380 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); |
379 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 381 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
380 | load(); | 382 | load(); |
381 | addressBook()->emitAddressBookChanged(); | 383 | addressBook()->emitAddressBookChanged(); |
382 | } | 384 | } |
383 | } | 385 | } |
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h index 4522d78..0a3027c 100644 --- a/kabc/plugins/file/resourcefile.h +++ b/kabc/plugins/file/resourcefile.h | |||
@@ -55,18 +55,18 @@ public: | |||
55 | 55 | ||
56 | /** | 56 | /** |
57 | Constructor. | 57 | Constructor. |
58 | 58 | ||
59 | @param cfg The config object where custom resource settings are stored. | 59 | @param cfg The config object where custom resource settings are stored. |
60 | */ | 60 | */ |
61 | ResourceFile( const KConfig *cfg ); | 61 | ResourceFile( const KConfig *cfg, bool syncable ); |
62 | 62 | ||
63 | /** | 63 | /** |
64 | Construct file resource on file @arg fileName using format @arg formatName. | 64 | Construct file resource on file @arg fileName using format @arg formatName. |
65 | */ | 65 | */ |
66 | ResourceFile( const QString &fileName, const QString &formatName = "vcard" ); | 66 | ResourceFile( const QString &fileName, bool syncable , const QString &formatName = "vcard" ); |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Destructor. | 69 | * Destructor. |
70 | */ | 70 | */ |
71 | ~ResourceFile(); | 71 | ~ResourceFile(); |
72 | 72 | ||
@@ -82,13 +82,13 @@ public: | |||
82 | virtual bool doOpen(); | 82 | virtual bool doOpen(); |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Closes the file again. | 85 | * Closes the file again. |
86 | */ | 86 | */ |
87 | virtual void doClose(); | 87 | virtual void doClose(); |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Requests a save ticket, that is used by @ref save() | 90 | * Requests a save ticket, that is used by @ref save() |
91 | */ | 91 | */ |
92 | virtual Ticket *requestSaveTicket(); | 92 | virtual Ticket *requestSaveTicket(); |
93 | 93 | ||
94 | /** | 94 | /** |
@@ -150,13 +150,13 @@ private: | |||
150 | QString mFileName; | 150 | QString mFileName; |
151 | QString mFormatName; | 151 | QString mFormatName; |
152 | 152 | ||
153 | FormatPlugin *mFormat; | 153 | FormatPlugin *mFormat; |
154 | 154 | ||
155 | QString mLockUniqueName; | 155 | QString mLockUniqueName; |
156 | 156 | ||
157 | KDirWatch mDirWatch; | 157 | KDirWatch mDirWatch; |
158 | }; | 158 | }; |
159 | 159 | ||
160 | } | 160 | } |
161 | 161 | ||
162 | #endif | 162 | #endif |