summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/file/resourcefile.cpp
Unidiff
Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/resourcefile.cpp74
1 files changed, 38 insertions, 36 deletions
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
@@ -52,4 +52,6 @@ $Id$
52 52
53#include "resourcefile.h" 53#include "resourcefile.h"
54#include "syncwidget.h"
55
54 56
55using namespace KABC; 57using namespace KABC;
@@ -57,5 +59,5 @@ using namespace KABC;
57extern "C" 59extern "C"
58#ifdef _WIN32_ 60#ifdef _WIN32_
59__declspec(dllexport) 61__declspec(dllexport)
60#else 62#else
61{ 63{
@@ -65,5 +67,5 @@ __declspec(dllexport)
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_
@@ -71,6 +73,6 @@ __declspec(dllexport)
71#endif 73#endif
72 74
73ResourceFile::ResourceFile( const KConfig *config ) 75ResourceFile::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;
@@ -90,7 +92,7 @@ ResourceFile::ResourceFile( const KConfig *config )
90} 92}
91 93
92ResourceFile::ResourceFile( const QString &fileName, 94ResourceFile::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());
@@ -140,12 +142,12 @@ 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
@@ -198,5 +200,5 @@ void ResourceFile::doClose()
198bool ResourceFile::load() 200bool ResourceFile::load()
199{ 201{
200 202
201 203
202 QFile file( mFileName ); 204 QFile file( mFileName );
@@ -207,5 +209,5 @@ bool ResourceFile::load()
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}
@@ -214,11 +216,11 @@ 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 );
@@ -233,5 +235,5 @@ bool ResourceFile::save( Ticket *ticket )
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 );
@@ -239,18 +241,18 @@ bool ResourceFile::save( Ticket *ticket )
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
@@ -261,5 +263,5 @@ bool ResourceFile::save( Ticket *ticket )
261bool ResourceFile::lock( const QString &fileName ) 263bool ResourceFile::lock( const QString &fileName )
262{ 264{
263 265
264 266
265 QString fn = fileName; 267 QString fn = fileName;
@@ -268,9 +270,9 @@ bool ResourceFile::lock( const QString &fileName )
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;
@@ -278,6 +280,6 @@ bool ResourceFile::lock( const QString &fileName )
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() );
@@ -312,7 +314,7 @@ void ResourceFile::unlock( const QString &fileName )
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 );
@@ -324,12 +326,12 @@ void ResourceFile::setFileName( const QString &fileName )
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}
@@ -347,5 +349,5 @@ void ResourceFile::setFormat( const QString &format )
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") {
@@ -360,5 +362,5 @@ void ResourceFile::setFormat( const QString &format )
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
@@ -374,6 +376,6 @@ void ResourceFile::fileChanged()
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 ) {