author | zautrix <zautrix> | 2004-09-15 10:22:55 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-15 10:22:55 (UTC) |
commit | d4adafe41cf399585b8e35cb600ff35706d55ae0 (patch) (unidiff) | |
tree | 1becc87f6c40390fd73082996d18f71fb5e9c772 /kabc | |
parent | 8889ffd6f6958c3a1d07bafedcc8af5d786a1660 (diff) | |
download | kdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.zip kdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.tar.gz kdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.tar.bz2 |
fixes for desktop version
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 17 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.h | 3 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 20 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.h | 3 |
4 files changed, 28 insertions, 15 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index 7d96cb7..e58e4f7 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -51,16 +51,17 @@ $Id$ | |||
51 | #include "formatfactory.h" | 51 | #include "formatfactory.h" |
52 | 52 | ||
53 | #include "resourcedirconfig.h" | 53 | #include "resourcedirconfig.h" |
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 | #define NO_DIRWATCH | ||
59 | #include "resourcedir.h" | 60 | #include "resourcedir.h" |
60 | #include "syncprefwidget.h" | 61 | #include "syncprefwidget.h" |
61 | 62 | ||
62 | //#define ALLOW_LOCKING | 63 | //#define ALLOW_LOCKING |
63 | 64 | ||
64 | using namespace KABC; | 65 | using namespace KABC; |
65 | 66 | ||
66 | extern "C" | 67 | extern "C" |
@@ -108,21 +109,21 @@ ResourceDir::ResourceDir( const KConfig *config, bool syncable ) | |||
108 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); | 109 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); |
109 | if (mFormatName == "vcard") | 110 | if (mFormatName == "vcard") |
110 | mFormat = new VCardFormatPlugin2(); | 111 | mFormat = new VCardFormatPlugin2(); |
111 | else if (mFormatName == "binary") | 112 | else if (mFormatName == "binary") |
112 | mFormat = new BinaryFormat(); | 113 | mFormat = new BinaryFormat(); |
113 | else | 114 | else |
114 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); | 115 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); |
115 | */ | 116 | */ |
116 | 117 | #ifndef NO_DIRWATCH | |
117 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); | 118 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); |
118 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); | 119 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); |
119 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); | 120 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); |
120 | 121 | #endif | |
121 | setPath( path ); | 122 | setPath( path ); |
122 | } | 123 | } |
123 | 124 | ||
124 | ResourceDir::~ResourceDir() | 125 | ResourceDir::~ResourceDir() |
125 | { | 126 | { |
126 | delete mFormat; | 127 | delete mFormat; |
127 | mFormat = 0; | 128 | mFormat = 0; |
128 | } | 129 | } |
@@ -203,19 +204,19 @@ bool ResourceDir::load() | |||
203 | 204 | ||
204 | return ok; | 205 | return ok; |
205 | } | 206 | } |
206 | 207 | ||
207 | bool ResourceDir::save( Ticket *ticket ) | 208 | bool ResourceDir::save( Ticket *ticket ) |
208 | { | 209 | { |
209 | AddressBook::Iterator it; | 210 | AddressBook::Iterator it; |
210 | bool ok = true; | 211 | bool ok = true; |
211 | 212 | #ifndef NO_DIRWATCH | |
212 | mDirWatch.stopScan(); | 213 | mDirWatch.stopScan(); |
213 | 214 | #endif | |
214 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 215 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
215 | if ( (*it).resource() != this || !(*it).changed() ) | 216 | if ( (*it).resource() != this || !(*it).changed() ) |
216 | continue; | 217 | continue; |
217 | 218 | ||
218 | QFile file( mPath + "/" + (*it).uid() ); | 219 | QFile file( mPath + "/" + (*it).uid() ); |
219 | if ( !file.open( IO_WriteOnly ) ) { | 220 | if ( !file.open( IO_WriteOnly ) ) { |
220 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); | 221 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); |
221 | continue; | 222 | continue; |
@@ -223,18 +224,19 @@ bool ResourceDir::save( Ticket *ticket ) | |||
223 | 224 | ||
224 | mFormat->save( *it, &file ); | 225 | mFormat->save( *it, &file ); |
225 | 226 | ||
226 | // mark as unchanged | 227 | // mark as unchanged |
227 | (*it).setChanged( false ); | 228 | (*it).setChanged( false ); |
228 | 229 | ||
229 | file.close(); | 230 | file.close(); |
230 | } | 231 | } |
232 | #ifndef NO_DIRWATCH | ||
231 | mDirWatch.startScan(); | 233 | mDirWatch.startScan(); |
232 | 234 | #endif | |
233 | delete ticket; | 235 | delete ticket; |
234 | #ifdef ALLOW_LOCKING | 236 | #ifdef ALLOW_LOCKING |
235 | unlock( mPath ); | 237 | unlock( mPath ); |
236 | #endif | 238 | #endif |
237 | return ok; | 239 | return ok; |
238 | } | 240 | } |
239 | 241 | ||
240 | bool ResourceDir::lock( const QString &path ) | 242 | bool ResourceDir::lock( const QString &path ) |
@@ -296,24 +298,27 @@ void ResourceDir::unlock( const QString &path ) | |||
296 | addressBook()->emitAddressBookUnlocked(); | 298 | addressBook()->emitAddressBookUnlocked(); |
297 | #else | 299 | #else |
298 | return; | 300 | return; |
299 | #endif | 301 | #endif |
300 | } | 302 | } |
301 | 303 | ||
302 | void ResourceDir::setPath( const QString &path ) | 304 | void ResourceDir::setPath( const QString &path ) |
303 | { | 305 | { |
306 | #ifndef NO_DIRWATCH | ||
304 | mDirWatch.stopScan(); | 307 | mDirWatch.stopScan(); |
305 | mDirWatch.removeDir( mPath ); | 308 | mDirWatch.removeDir( mPath ); |
306 | 309 | ||
307 | mPath = path; | 310 | mPath = path; |
308 | 311 | ||
309 | mDirWatch.addDir( mPath, true ); | 312 | mDirWatch.addDir( mPath, true ); |
310 | mDirWatch.startScan(); | 313 | mDirWatch.startScan(); |
311 | 314 | #else | |
315 | mPath = path; | ||
316 | #endif | ||
312 | //US simulate KDirWatch event | 317 | //US simulate KDirWatch event |
313 | //US pathChanged(); | 318 | //US pathChanged(); |
314 | 319 | ||
315 | } | 320 | } |
316 | 321 | ||
317 | QString ResourceDir::path() const | 322 | QString ResourceDir::path() const |
318 | { | 323 | { |
319 | return mPath; | 324 | return mPath; |
diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h index c2aedad..77cd18c 100644 --- a/kabc/plugins/dir/resourcedir.h +++ b/kabc/plugins/dir/resourcedir.h | |||
@@ -99,17 +99,18 @@ protected slots: | |||
99 | 99 | ||
100 | protected: | 100 | protected: |
101 | bool lock( const QString &path ); | 101 | bool lock( const QString &path ); |
102 | void unlock( const QString &path ); | 102 | void unlock( const QString &path ); |
103 | 103 | ||
104 | private: | 104 | private: |
105 | FormatPlugin *mFormat; | 105 | FormatPlugin *mFormat; |
106 | 106 | ||
107 | #ifndef NO_DIRWATCH | ||
107 | KDirWatch mDirWatch; | 108 | KDirWatch mDirWatch; |
108 | 109 | #endif | |
109 | QString mPath; | 110 | QString mPath; |
110 | QString mFormatName; | 111 | QString mFormatName; |
111 | QString mLockUniqueName; | 112 | QString mLockUniqueName; |
112 | }; | 113 | }; |
113 | 114 | ||
114 | } | 115 | } |
115 | #endif | 116 | #endif |
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 17263ae..b8c32d5 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -44,22 +44,24 @@ $Id$ | |||
44 | #include <kstandarddirs.h> | 44 | #include <kstandarddirs.h> |
45 | #include <kmessagebox.h> | 45 | #include <kmessagebox.h> |
46 | 46 | ||
47 | #include "formatfactory.h" | 47 | #include "formatfactory.h" |
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 | #define NO_DIRWATCH | |
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncprefwidget.h" | 54 | #include "syncprefwidget.h" |
55 | 55 | ||
56 | //#define ALLOW_LOCKING | 56 | //#define ALLOW_LOCKING |
57 | 57 | ||
58 | |||
59 | |||
58 | using namespace KABC; | 60 | using namespace KABC; |
59 | 61 | ||
60 | extern "C" | 62 | extern "C" |
61 | #ifdef _WIN32_ | 63 | #ifdef _WIN32_ |
62 | __declspec(dllexport) | 64 | __declspec(dllexport) |
63 | #else | 65 | #else |
64 | { | 66 | { |
65 | #endif | 67 | #endif |
@@ -110,21 +112,21 @@ void ResourceFile::init( const QString &fileName, const QString &formatName ) | |||
110 | FormatFactory *factory = FormatFactory::self(); | 112 | FormatFactory *factory = FormatFactory::self(); |
111 | mFormat = factory->format( mFormatName ); | 113 | mFormat = factory->format( mFormatName ); |
112 | 114 | ||
113 | if ( !mFormat ) { | 115 | if ( !mFormat ) { |
114 | mFormatName = "vcard"; | 116 | mFormatName = "vcard"; |
115 | mFormat = factory->format( mFormatName ); | 117 | mFormat = factory->format( mFormatName ); |
116 | } | 118 | } |
117 | 119 | ||
118 | 120 | #ifndef NO_DIRWATCH | |
119 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 121 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
120 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 122 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
121 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 123 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
122 | 124 | #endif | |
123 | setFileName( fileName ); | 125 | setFileName( fileName ); |
124 | } | 126 | } |
125 | 127 | ||
126 | ResourceFile::~ResourceFile() | 128 | ResourceFile::~ResourceFile() |
127 | { | 129 | { |
128 | delete mFormat; | 130 | delete mFormat; |
129 | mFormat = 0; | 131 | mFormat = 0; |
130 | } | 132 | } |
@@ -222,36 +224,37 @@ bool ResourceFile::save( Ticket *ticket ) | |||
222 | if ( saveFile.status() == 0 && saveFile.file() ) | 224 | if ( saveFile.status() == 0 && saveFile.file() ) |
223 | { | 225 | { |
224 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 226 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
225 | ok = saveFile.close(); | 227 | ok = saveFile.close(); |
226 | } | 228 | } |
227 | */ | 229 | */ |
228 | 230 | ||
229 | //US ToDo: write backupfile | 231 | //US ToDo: write backupfile |
232 | #ifndef NO_DIRWATCH | ||
230 | mDirWatch.stopScan(); | 233 | mDirWatch.stopScan(); |
231 | 234 | #endif | |
232 | QFile info; | 235 | QFile info; |
233 | info.setName( mFileName ); | 236 | info.setName( mFileName ); |
234 | bool ok = info.open( IO_WriteOnly ); | 237 | bool ok = info.open( IO_WriteOnly ); |
235 | if ( ok ) { | 238 | if ( ok ) { |
236 | mFormat->saveAll( addressBook(), this, &info ); | 239 | mFormat->saveAll( addressBook(), this, &info ); |
237 | 240 | ||
238 | info.close(); | 241 | info.close(); |
239 | ok = true; | 242 | ok = true; |
240 | } | 243 | } |
241 | else { | 244 | else { |
242 | 245 | ||
243 | } | 246 | } |
244 | 247 | ||
245 | if ( !ok ) | 248 | if ( !ok ) |
246 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 249 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
247 | 250 | #ifndef NO_DIRWATCH | |
248 | mDirWatch.startScan(); | 251 | mDirWatch.startScan(); |
249 | 252 | #endif | |
250 | delete ticket; | 253 | delete ticket; |
251 | #ifdef ALLOW_LOCKING | 254 | #ifdef ALLOW_LOCKING |
252 | unlock( mFileName ); | 255 | unlock( mFileName ); |
253 | #endif | 256 | #endif |
254 | 257 | ||
255 | return ok; | 258 | return ok; |
256 | } | 259 | } |
257 | 260 | ||
@@ -321,24 +324,27 @@ void ResourceFile::unlock( const QString &fileName ) | |||
321 | addressBook()->emitAddressBookUnlocked(); | 324 | addressBook()->emitAddressBookUnlocked(); |
322 | #else | 325 | #else |
323 | return; | 326 | return; |
324 | #endif | 327 | #endif |
325 | } | 328 | } |
326 | 329 | ||
327 | void ResourceFile::setFileName( const QString &fileName ) | 330 | void ResourceFile::setFileName( const QString &fileName ) |
328 | { | 331 | { |
332 | #ifndef NO_DIRWATCH | ||
329 | mDirWatch.stopScan(); | 333 | mDirWatch.stopScan(); |
330 | mDirWatch.removeFile( mFileName ); | 334 | mDirWatch.removeFile( mFileName ); |
331 | |||
332 | mFileName = fileName; | 335 | mFileName = fileName; |
333 | 336 | ||
334 | 337 | ||
335 | mDirWatch.addFile( mFileName ); | 338 | mDirWatch.addFile( mFileName ); |
336 | mDirWatch.startScan(); | 339 | mDirWatch.startScan(); |
340 | #else | ||
341 | mFileName = fileName; | ||
342 | #endif | ||
337 | 343 | ||
338 | //US simulate KDirWatch event | 344 | //US simulate KDirWatch event |
339 | //US fileChanged(); | 345 | //US fileChanged(); |
340 | } | 346 | } |
341 | 347 | ||
342 | QString ResourceFile::fileName() const | 348 | QString ResourceFile::fileName() const |
343 | { | 349 | { |
344 | return mFileName; | 350 | return mFileName; |
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h index 0a3027c..8339340 100644 --- a/kabc/plugins/file/resourcefile.h +++ b/kabc/plugins/file/resourcefile.h | |||
@@ -148,15 +148,16 @@ protected: | |||
148 | 148 | ||
149 | private: | 149 | 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 | #ifndef NO_DIRWATCH | |
157 | KDirWatch mDirWatch; | 157 | KDirWatch mDirWatch; |
158 | #endif | ||
158 | }; | 159 | }; |
159 | 160 | ||
160 | } | 161 | } |
161 | 162 | ||
162 | #endif | 163 | #endif |