summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/dir/resourcedir.cpp33
-rw-r--r--kabc/plugins/file/resourcefile.cpp36
2 files changed, 32 insertions, 37 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
index f354a9e..be19821 100644
--- a/kabc/plugins/dir/resourcedir.cpp
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -42,37 +42,36 @@ $Id$
42//US #include <kgenericfactory.h> 42//US #include <kgenericfactory.h>
43#include <kglobal.h> 43#include <kglobal.h>
44#include <klocale.h> 44#include <klocale.h>
45#include <kstandarddirs.h> 45#include <kstandarddirs.h>
46#include <kurlrequester.h> 46#include <kurlrequester.h>
47 47
48#include "addressbook.h" 48#include "addressbook.h"
49 49
50//US #include "formatfactory.h" 50#include "formatfactory.h"
51 51
52#include "resourcedirconfig.h" 52#include "resourcedirconfig.h"
53#include "stdaddressbook.h" 53#include "stdaddressbook.h"
54 54
55//US 55//US
56#include <qdir.h> 56#include <qdir.h>
57#include <formats/vcardformatplugin2.h> 57//US #include "../../formats/vcardformatplugin2.h"
58#include <formats/binaryformat.h> 58//US #include "../../formats/binaryformat.h"
59 59
60#include "resourcedir.h" 60#include "resourcedir.h"
61 61
62using namespace KABC; 62using namespace KABC;
63 63
64extern "C" 64extern "C"
65{ 65{
66 void *init_kabc_dir() 66//US void *init_kabc_dir()
67 void *init_microkabc_dir()
67 { 68 {
68 qDebug("resourcedir.cpp : init_kabc_dir has to be changed"); 69 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>();
69//US return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>();
70 return 0;
71 } 70 }
72} 71}
73 72
74 73
75ResourceDir::ResourceDir( const KConfig *config ) 74ResourceDir::ResourceDir( const KConfig *config )
76 : Resource( config ) 75 : Resource( config )
77{ 76{
78 QString path; 77 QString path;
@@ -84,33 +83,33 @@ ResourceDir::ResourceDir( const KConfig *config )
84//US mFormatName = config->readEntry( "FileFormat" ); 83//US mFormatName = config->readEntry( "FileFormat" );
85 mFormatName = cfg->readEntry( "FileFormat", "vcard" ); 84 mFormatName = cfg->readEntry( "FileFormat", "vcard" );
86 } else { 85 } else {
87 path = StdAddressBook::directoryName(); 86 path = StdAddressBook::directoryName();
88 mFormatName = "vcard"; 87 mFormatName = "vcard";
89 } 88 }
90 89
91 90
92/*US FormatFactory *factory = FormatFactory::self(); 91 FormatFactory *factory = FormatFactory::self();
93 mFormat = factory->format( mFormatName ); 92 mFormat = factory->format( mFormatName );
94 93
95 if ( !mFormat ) { 94 if ( !mFormat ) {
96 mFormatName = "vcard"; 95 mFormatName = "vcard";
97 mFormat = factory->format( mFormatName ); 96 mFormat = factory->format( mFormatName );
98 } 97 }
99*/
100 98
99/*US
101//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); 100//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1());
102 if (mFormatName == "vcard") 101 if (mFormatName == "vcard")
103 mFormat = new VCardFormatPlugin2(); 102 mFormat = new VCardFormatPlugin2();
104 else if (mFormatName == "binary") 103 else if (mFormatName == "binary")
105 mFormat = new BinaryFormat(); 104 mFormat = new BinaryFormat();
106 else 105 else
107 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); 106 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1());
108 107*/
109 108
110/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods 109/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods
111 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); 110 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) );
112 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); 111 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) );
113 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); 112 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) );
114*/ 113*/
115 114
116 setPath( path ); 115 setPath( path );
@@ -256,23 +255,19 @@ bool ResourceDir::lock( const QString &path )
256 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 255 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
257 256
258 // Create unique file 257 // Create unique file
259 QFile file( mLockUniqueName ); 258 QFile file( mLockUniqueName );
260 file.open( IO_WriteOnly ); 259 file.open( IO_WriteOnly );
261 file.close(); 260 file.close();
262 261
263 // Create lock file 262 // Create lock file
264#ifdef _WIN32_
265 int result = 0;
266 qDebug("WARNING: ResourceDir::lock cannot link ");
267#else
268 int result = ::link( QFile::encodeName( mLockUniqueName ), 263 int result = ::link( QFile::encodeName( mLockUniqueName ),
269 QFile::encodeName( lockName ) ); 264 QFile::encodeName( lockName ) );
270#endif 265
271 if ( result == 0 ) { 266 if ( result == 0 ) {
272 addressBook()->emitAddressBookLocked(); 267 addressBook()->emitAddressBookLocked();
273 return true; 268 return true;
274 } 269 }
275 270
276 // TODO: check stat 271 // TODO: check stat
277 272
278 return false; 273 return false;
@@ -317,27 +312,27 @@ QString ResourceDir::path() const
317 312
318void ResourceDir::setFormat( const QString &format ) 313void ResourceDir::setFormat( const QString &format )
319{ 314{
320 mFormatName = format; 315 mFormatName = format;
321 316
322 if ( mFormat ) 317 if ( mFormat )
323 delete mFormat; 318 delete mFormat;
324 319
325//US FormatFactory *factory = FormatFactory::self(); 320 FormatFactory *factory = FormatFactory::self();
326//US mFormat = factory->format( mFormatName ); 321 mFormat = factory->format( mFormatName );
327 322/*US
328qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); 323qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1());
329 if (mFormatName == "vcard") 324 if (mFormatName == "vcard")
330 mFormat = new VCardFormatPlugin2(); 325 mFormat = new VCardFormatPlugin2();
331 else if (mFormatName == "binary") 326 else if (mFormatName == "binary")
332 mFormat = new BinaryFormat(); 327 mFormat = new BinaryFormat();
333 else 328 else
334 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); 329 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1());
335 330*/
336 331
337} 332}
338 333
339QString ResourceDir::format() const 334QString ResourceDir::format() const
340{ 335{
341 return mFormatName; 336 return mFormatName;
342} 337}
343 338
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index d30ed2f..80af841 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -38,37 +38,36 @@ $Id$
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 45
46//US #include "formatfactory.h" 46#include "formatfactory.h"
47 47
48#include "resource.h" 48#include "resource.h"
49#include "resourcefileconfig.h" 49#include "resourcefileconfig.h"
50#include "stdaddressbook.h" 50#include "stdaddressbook.h"
51 51
52#include <formats/vcardformatplugin2.h> 52//US #include "../../formats/vcardformatplugin2.h"
53#include <formats/binaryformat.h> 53//US #include "../../formats/binaryformat.h"
54 54
55 55
56#include "resourcefile.h" 56#include "resourcefile.h"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60extern "C" 60extern "C"
61{ 61{
62 void *init_kabc_file() 62//US void *init_kabc_file()
63 void *init_microkabc_file()
63 { 64 {
64 qDebug("!!!resourcefile.cpp : init_kabc_file has to be changed"); 65 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
65//US return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
66 return 0;
67 } 66 }
68} 67}
69 68
70 69
71ResourceFile::ResourceFile( const KConfig *config ) 70ResourceFile::ResourceFile( const KConfig *config )
72 : Resource( config ) , mFormat( 0 ) 71 : Resource( config ) , mFormat( 0 )
73{ 72{
74 QString fileName, formatName; 73 QString fileName, formatName;
@@ -94,36 +93,37 @@ ResourceFile::ResourceFile( const QString &fileName,
94// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 93// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
95 init( fileName, formatName ); 94 init( fileName, formatName );
96} 95}
97 96
98void ResourceFile::init( const QString &fileName, const QString &formatName ) 97void ResourceFile::init( const QString &fileName, const QString &formatName )
99{ 98{
100 mFormatName = formatName; 99 mFormatName = formatName;
101 100
102/*US FormatFactory *factory = FormatFactory::self(); 101 FormatFactory *factory = FormatFactory::self();
103 mFormat = factory->format( mFormatName ); 102 mFormat = factory->format( mFormatName );
104 103
105 if ( !mFormat ) { 104 if ( !mFormat ) {
106 mFormatName = "vcard"; 105 mFormatName = "vcard";
107 mFormat = factory->format( mFormatName ); 106 mFormat = factory->format( mFormatName );
108 } 107 }
109*/
110 108
109/*US
111//US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); 110//US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1());
112 if (mFormatName == "vcard") { 111 if (mFormatName == "vcard") {
113 mFormat = new VCardFormatPlugin2(); 112 mFormat = new VCardFormatPlugin2();
114// qDebug("ResourceFile::init format VCardFormatPlugin2"); 113// qDebug("ResourceFile::init format VCardFormatPlugin2");
115 } 114 }
116 else if (mFormatName == "binary") { 115 else if (mFormatName == "binary") {
117 mFormat = new BinaryFormat(); 116 mFormat = new BinaryFormat();
118// qDebug("ResourceFile::init format BinaryFormat"); 117// qDebug("ResourceFile::init format BinaryFormat");
119 } 118 }
120 else 119 else
121 qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); 120 qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1());
121*/
122 122
123/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods 123/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods
124 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 124 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
125 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 125 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
126 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 126 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
127*/ 127*/
128 128
129 setFileName( fileName ); 129 setFileName( fileName );
@@ -212,18 +212,18 @@ bool ResourceFile::save( Ticket *ticket )
212// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 212// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
213 kdDebug(5700) << "ResourceFile::save()" << endl; 213 kdDebug(5700) << "ResourceFile::save()" << endl;
214 214
215 // create backup file 215 // create backup file
216 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 216 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
217 217
218/*US we use a simpler method to create a backupfile 218/*US we use a simpler method to create a backupfile
219 219
220 (void) KSaveFile::backupFile( mFileName, QString::null /*directory*/ 220 (void) KSaveFile::backupFile( mFileName, QString::null
221/*US ,extension ); 221 ,extension );
222 222
223 KSaveFile saveFile( mFileName ); 223 KSaveFile saveFile( mFileName );
224 bool ok = false; 224 bool ok = false;
225 if ( saveFile.status() == 0 && saveFile.file() ) 225 if ( saveFile.status() == 0 && saveFile.file() )
226 { 226 {
227 mFormat->saveAll( addressBook(), this, saveFile.file() ); 227 mFormat->saveAll( addressBook(), this, saveFile.file() );
228 ok = saveFile.close(); 228 ok = saveFile.close();
229 } 229 }
@@ -281,19 +281,18 @@ bool ResourceFile::lock( const QString &fileName )
281 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 281 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
282 282
283 // Create unique file 283 // Create unique file
284 QFile file( mLockUniqueName ); 284 QFile file( mLockUniqueName );
285 file.open( IO_WriteOnly ); 285 file.open( IO_WriteOnly );
286 file.close(); 286 file.close();
287 287
288 // Create lock file 288 // Create lock file
289 int result = 0;//::link( QFile::encodeName( mLockUniqueName ), 289 int result = ::link( QFile::encodeName( mLockUniqueName ),
290 // QFile::encodeName( lockName ) ); 290 QFile::encodeName( lockName ) );
291 qDebug("lock files %s, %s needs to be fixed", mLockUniqueName.latin1(), lockName.latin1() );
292 291
293 if ( result == 0 ) { 292 if ( result == 0 ) {
294 addressBook()->emitAddressBookLocked(); 293 addressBook()->emitAddressBookLocked();
295 return true; 294 return true;
296 } 295 }
297 296
298 // TODO: check stat 297 // TODO: check stat
299 298
@@ -337,30 +336,31 @@ QString ResourceFile::fileName() const
337 return mFileName; 336 return mFileName;
338} 337}
339 338
340void ResourceFile::setFormat( const QString &format ) 339void ResourceFile::setFormat( const QString &format )
341{ 340{
342 mFormatName = format; 341 mFormatName = format;
343 delete mFormat; 342 delete mFormat;
344 343
345//US FormatFactory *factory = FormatFactory::self(); 344 FormatFactory *factory = FormatFactory::self();
346//US mFormat = factory->format( mFormatName ); 345 mFormat = factory->format( mFormatName );
347 346/*US
348//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); 347//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
349 if (mFormatName == "vcard") { 348 if (mFormatName == "vcard") {
350 mFormat = new VCardFormatPlugin2(); 349 mFormat = new VCardFormatPlugin2();
351// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 350// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
352 } 351 }
353 else if (mFormatName == "binary") { 352 else if (mFormatName == "binary") {
354 mFormat = new BinaryFormat(); 353 mFormat = new BinaryFormat();
355// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 354// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
356 } 355 }
357 else 356 else
358 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); 357 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
358*/
359 359
360} 360}
361 361
362QString ResourceFile::format() const 362QString ResourceFile::format() const
363{ 363{
364 return mFormatName; 364 return mFormatName;
365} 365}
366 366