summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/dir/resourcedir.cpp
Unidiff
Diffstat (limited to 'kabc/plugins/dir/resourcedir.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/dir/resourcedir.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
index 52863d5..d978e61 100644
--- a/kabc/plugins/dir/resourcedir.cpp
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -54,33 +54,34 @@ $Id$
54#include "stdaddressbook.h" 54#include "stdaddressbook.h"
55 55
56//US 56//US
57#include <qdir.h> 57#include <qdir.h>
58 58
59#include "resourcedir.h" 59#include "resourcedir.h"
60#include "syncwidget.h"
60 61
61using namespace KABC; 62using namespace KABC;
62 63
63extern "C" 64extern "C"
64#ifdef _WIN32_ 65#ifdef _WIN32_
65__declspec(dllexport) 66__declspec(dllexport)
66#else 67#else
67{ 68{
68#endif 69#endif
69 70
70//US void *init_kabc_dir() 71//US void *init_kabc_dir()
71 void *init_microkabc_dir() 72 void *init_microkabc_dir()
72 { 73 {
73 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>(); 74 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, KRES::SyncWidget>();
74 } 75 }
75#ifndef _WIN32_ 76#ifndef _WIN32_
76} 77}
77#endif 78#endif
78 79
79ResourceDir::ResourceDir( const KConfig *config ) 80ResourceDir::ResourceDir( const KConfig *config, bool syncable )
80 : Resource( config ) 81 : Resource( config, syncable )
81{ 82{
82 QString path; 83 QString path;
83 84
84 KConfig *cfg = (KConfig *)config; 85 KConfig *cfg = (KConfig *)config;
85 if ( cfg ) { 86 if ( cfg ) {
86//US path = config->readEntry( "FilePath" ); 87//US path = config->readEntry( "FilePath" );
@@ -98,22 +99,22 @@ ResourceDir::ResourceDir( const KConfig *config )
98 99
99 if ( !mFormat ) { 100 if ( !mFormat ) {
100 mFormatName = "vcard"; 101 mFormatName = "vcard";
101 mFormat = factory->format( mFormatName ); 102 mFormat = factory->format( mFormatName );
102 } 103 }
103 104
104/*US 105/*US
105//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); 106//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1());
106 if (mFormatName == "vcard") 107 if (mFormatName == "vcard")
107 mFormat = new VCardFormatPlugin2(); 108 mFormat = new VCardFormatPlugin2();
108 else if (mFormatName == "binary") 109 else if (mFormatName == "binary")
109 mFormat = new BinaryFormat(); 110 mFormat = new BinaryFormat();
110 else 111 else
111 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); 112 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1());
112*/ 113*/
113 114
114 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); 115 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) );
115 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); 116 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) );
116 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); 117 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) );
117 118
118 setPath( path ); 119 setPath( path );
119} 120}
@@ -122,14 +123,14 @@ ResourceDir::~ResourceDir()
122{ 123{
123 delete mFormat; 124 delete mFormat;
124 mFormat = 0; 125 mFormat = 0;
125} 126}
126 127
127void ResourceDir::writeConfig( KConfig *config ) 128void ResourceDir::writeConfig( KConfig *config )
128{ 129{
129 config->setGroup( "Resource_" + identifier() ); 130 config->setGroup( "Resource_" + identifier() );
130 Resource::writeConfig( config ); 131 Resource::writeConfig( config );
131 132
132 config->writeEntry( "FilePath", mPath ); 133 config->writeEntry( "FilePath", mPath );
133 config->writeEntry( "FileFormat", mFormatName ); 134 config->writeEntry( "FileFormat", mFormatName );
134} 135}
135 136
@@ -238,27 +239,27 @@ bool ResourceDir::lock( const QString &path )
238 kdDebug(5700) << "ResourceDir::lock()" << endl; 239 kdDebug(5700) << "ResourceDir::lock()" << endl;
239 240
240 QString p = path; 241 QString p = path;
241//US change the implementation how the lockfilename is getting created 242//US change the implementation how the lockfilename is getting created
242//US p.replace( QRegExp("/"), "_" ); 243//US p.replace( QRegExp("/"), "_" );
243//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); 244//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" );
244 KURL url(p); 245 KURL url(p);
245 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 246 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
246 247
247 248
248 kdDebug(5700) << "-- lock name: " << lockName << endl; 249 kdDebug(5700) << "-- lock name: " << lockName << endl;
249 250
250 if ( QFile::exists( lockName ) ) return false; 251 if ( QFile::exists( lockName ) ) return false;
251 252
252 QString lockUniqueName; 253 QString lockUniqueName;
253 lockUniqueName = p + KApplication::randomString( 8 ); 254 lockUniqueName = p + KApplication::randomString( 8 );
254 255
255 url = lockUniqueName; 256 url = lockUniqueName;
256//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 257//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
257 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 258 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
258 259
259 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 260 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
260 261
261 // Create unique file 262 // Create unique file
262 QFile file( mLockUniqueName ); 263 QFile file( mLockUniqueName );
263 file.open( IO_WriteOnly ); 264 file.open( IO_WriteOnly );
264 file.close(); 265 file.close();
@@ -282,31 +283,31 @@ bool ResourceDir::lock( const QString &path )
282void ResourceDir::unlock( const QString &path ) 283void ResourceDir::unlock( const QString &path )
283{ 284{
284 QString p = path; 285 QString p = path;
285//US change the implementation how the lockfilename is getting created 286//US change the implementation how the lockfilename is getting created
286//US p.replace( QRegExp( "/" ), "_" ); 287//US p.replace( QRegExp( "/" ), "_" );
287//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); 288//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" );
288 KURL url(p); 289 KURL url(p);
289 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); 290 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" );
290 291
291 ::unlink( QFile::encodeName( lockName ) ); 292 ::unlink( QFile::encodeName( lockName ) );
292 QFile::remove( mLockUniqueName ); 293 QFile::remove( mLockUniqueName );
293 addressBook()->emitAddressBookUnlocked(); 294 addressBook()->emitAddressBookUnlocked();
294} 295}
295 296
296void ResourceDir::setPath( const QString &path ) 297void ResourceDir::setPath( const QString &path )
297{ 298{
298 mDirWatch.stopScan(); 299 mDirWatch.stopScan();
299 mDirWatch.removeDir( mPath ); 300 mDirWatch.removeDir( mPath );
300 301
301 mPath = path; 302 mPath = path;
302 303
303 mDirWatch.addDir( mPath, true ); 304 mDirWatch.addDir( mPath, true );
304 mDirWatch.startScan(); 305 mDirWatch.startScan();
305 306
306//US simulate KDirWatch event 307//US simulate KDirWatch event
307//US pathChanged(); 308//US pathChanged();
308 309
309} 310}
310 311
311QString ResourceDir::path() const 312QString ResourceDir::path() const
312{ 313{
@@ -319,13 +320,13 @@ void ResourceDir::setFormat( const QString &format )
319 320
320 if ( mFormat ) 321 if ( mFormat )
321 delete mFormat; 322 delete mFormat;
322 323
323 FormatFactory *factory = FormatFactory::self(); 324 FormatFactory *factory = FormatFactory::self();
324 mFormat = factory->format( mFormatName ); 325 mFormat = factory->format( mFormatName );
325/*US 326/*US
326qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); 327qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1());
327 if (mFormatName == "vcard") 328 if (mFormatName == "vcard")
328 mFormat = new VCardFormatPlugin2(); 329 mFormat = new VCardFormatPlugin2();
329 else if (mFormatName == "binary") 330 else if (mFormatName == "binary")
330 mFormat = new BinaryFormat(); 331 mFormat = new BinaryFormat();
331 else 332 else