author | ulf69 <ulf69> | 2004-08-02 18:32:08 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-02 18:32:08 (UTC) |
commit | 863c4c3678e59ef125c08c00e9532ded5b540f67 (patch) (unidiff) | |
tree | 449428c45689ffe10ff1ce4caa18f959c4dfe402 /kabc/plugins/file | |
parent | 983127ce46c9ff6663d08dedd450da3fe7dd549b (diff) | |
download | kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.zip kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.tar.gz kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.tar.bz2 |
added support for syncprofiles for resources and export/import capabilities
-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 | |||
@@ -3,7 +3,7 @@ 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 |
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 | |||
@@ -3,7 +3,7 @@ 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 |
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 | |||
@@ -51,12 +51,14 @@ $Id$ | |||
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 |
@@ -64,14 +66,14 @@ __declspec(dllexport) | |||
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 | ||
@@ -89,9 +91,9 @@ ResourceFile::ResourceFile( const KConfig *config ) | |||
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 ); |
@@ -139,14 +141,14 @@ ResourceFile::~ResourceFile() | |||
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() |
@@ -197,7 +199,7 @@ void ResourceFile::doClose() | |||
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 ) ) { |
@@ -206,20 +208,20 @@ bool ResourceFile::load() | |||
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 | ||
@@ -232,26 +234,26 @@ bool ResourceFile::save( Ticket *ticket ) | |||
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"); |
@@ -260,25 +262,25 @@ bool ResourceFile::save( Ticket *ticket ) | |||
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; |
@@ -311,9 +313,9 @@ void ResourceFile::unlock( const QString &fileName ) | |||
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(); |
@@ -323,14 +325,14 @@ 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 | ||
@@ -346,7 +348,7 @@ void ResourceFile::setFormat( const QString &format ) | |||
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(); |
@@ -359,7 +361,7 @@ void ResourceFile::setFormat( const QString &format ) | |||
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 |
@@ -373,8 +375,8 @@ void ResourceFile::fileChanged() | |||
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(); |
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 | |||
@@ -58,12 +58,12 @@ public: | |||
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. |
@@ -85,7 +85,7 @@ public: | |||
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 | */ |
@@ -153,7 +153,7 @@ private: | |||
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 | ||