-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 32 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 16 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 15 | ||||
-rw-r--r-- | kmicromail/accountitem.h | 2 |
4 files changed, 44 insertions, 21 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index fac06a1..7d96cb7 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -50,24 +50,26 @@ $Id$ | |||
50 | 50 | ||
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 | #include "resourcedir.h" | 59 | #include "resourcedir.h" |
60 | #include "syncprefwidget.h" | 60 | #include "syncprefwidget.h" |
61 | 61 | ||
62 | //#define ALLOW_LOCKING | ||
63 | |||
62 | using namespace KABC; | 64 | using namespace KABC; |
63 | 65 | ||
64 | extern "C" | 66 | extern "C" |
65 | #ifdef _WIN32_ | 67 | #ifdef _WIN32_ |
66 | __declspec(dllexport) | 68 | __declspec(dllexport) |
67 | #else | 69 | #else |
68 | { | 70 | { |
69 | #endif | 71 | #endif |
70 | 72 | ||
71 | //US void *init_kabc_dir() | 73 | //US void *init_kabc_dir() |
72 | void *init_microkabc_dir() | 74 | void *init_microkabc_dir() |
73 | { | 75 | { |
@@ -127,34 +129,35 @@ ResourceDir::~ResourceDir() | |||
127 | 129 | ||
128 | void ResourceDir::writeConfig( KConfig *config ) | 130 | void ResourceDir::writeConfig( KConfig *config ) |
129 | { | 131 | { |
130 | config->setGroup( "Resource_" + identifier() ); | 132 | config->setGroup( "Resource_" + identifier() ); |
131 | Resource::writeConfig( config ); | 133 | Resource::writeConfig( config ); |
132 | 134 | ||
133 | config->writeEntry( "FilePath", mPath ); | 135 | config->writeEntry( "FilePath", mPath ); |
134 | config->writeEntry( "FileFormat", mFormatName ); | 136 | config->writeEntry( "FileFormat", mFormatName ); |
135 | } | 137 | } |
136 | 138 | ||
137 | Ticket *ResourceDir::requestSaveTicket() | 139 | Ticket *ResourceDir::requestSaveTicket() |
138 | { | 140 | { |
139 | kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; | 141 | |
140 | 142 | ||
141 | if ( !addressBook() ) return 0; | 143 | if ( !addressBook() ) return 0; |
142 | 144 | #ifdef ALLOW_LOCKING | |
143 | if ( !lock( mPath ) ) { | 145 | if ( !lock( mPath ) ) { |
144 | kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" | 146 | |
145 | << mPath << "'" << endl; | ||
146 | return 0; | 147 | return 0; |
147 | } | 148 | } |
149 | #endif | ||
148 | return createTicket( this ); | 150 | return createTicket( this ); |
151 | |||
149 | } | 152 | } |
150 | 153 | ||
151 | 154 | ||
152 | bool ResourceDir::doOpen() | 155 | bool ResourceDir::doOpen() |
153 | { | 156 | { |
154 | QDir dir( mPath ); | 157 | QDir dir( mPath ); |
155 | if ( !dir.exists() ) { // no directory available | 158 | if ( !dir.exists() ) { // no directory available |
156 | return dir.mkdir( dir.path() ); | 159 | return dir.mkdir( dir.path() ); |
157 | } else { | 160 | } else { |
158 | QString testName = dir.entryList( QDir::Files )[0]; | 161 | QString testName = dir.entryList( QDir::Files )[0]; |
159 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory | 162 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory |
160 | return true; | 163 | return true; |
@@ -169,26 +172,24 @@ bool ResourceDir::doOpen() | |||
169 | bool ok = mFormat->checkFormat( &file ); | 172 | bool ok = mFormat->checkFormat( &file ); |
170 | file.close(); | 173 | file.close(); |
171 | return ok; | 174 | return ok; |
172 | } | 175 | } |
173 | } | 176 | } |
174 | 177 | ||
175 | void ResourceDir::doClose() | 178 | void ResourceDir::doClose() |
176 | { | 179 | { |
177 | } | 180 | } |
178 | 181 | ||
179 | bool ResourceDir::load() | 182 | bool ResourceDir::load() |
180 | { | 183 | { |
181 | kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; | ||
182 | |||
183 | QDir dir( mPath ); | 184 | QDir dir( mPath ); |
184 | QStringList files = dir.entryList( QDir::Files ); | 185 | QStringList files = dir.entryList( QDir::Files ); |
185 | 186 | ||
186 | QStringList::Iterator it; | 187 | QStringList::Iterator it; |
187 | bool ok = true; | 188 | bool ok = true; |
188 | for ( it = files.begin(); it != files.end(); ++it ) { | 189 | for ( it = files.begin(); it != files.end(); ++it ) { |
189 | QFile file( mPath + "/" + (*it) ); | 190 | QFile file( mPath + "/" + (*it) ); |
190 | 191 | ||
191 | if ( !file.open( IO_ReadOnly ) ) { | 192 | if ( !file.open( IO_ReadOnly ) ) { |
192 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); | 193 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); |
193 | ok = false; | 194 | ok = false; |
194 | continue; | 195 | continue; |
@@ -196,26 +197,24 @@ bool ResourceDir::load() | |||
196 | 197 | ||
197 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) | 198 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) |
198 | ok = false; | 199 | ok = false; |
199 | 200 | ||
200 | file.close(); | 201 | file.close(); |
201 | } | 202 | } |
202 | 203 | ||
203 | return ok; | 204 | return ok; |
204 | } | 205 | } |
205 | 206 | ||
206 | bool ResourceDir::save( Ticket *ticket ) | 207 | bool ResourceDir::save( Ticket *ticket ) |
207 | { | 208 | { |
208 | kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; | ||
209 | |||
210 | AddressBook::Iterator it; | 209 | AddressBook::Iterator it; |
211 | bool ok = true; | 210 | bool ok = true; |
212 | 211 | ||
213 | mDirWatch.stopScan(); | 212 | mDirWatch.stopScan(); |
214 | 213 | ||
215 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 214 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
216 | if ( (*it).resource() != this || !(*it).changed() ) | 215 | if ( (*it).resource() != this || !(*it).changed() ) |
217 | continue; | 216 | continue; |
218 | 217 | ||
219 | QFile file( mPath + "/" + (*it).uid() ); | 218 | QFile file( mPath + "/" + (*it).uid() ); |
220 | if ( !file.open( IO_WriteOnly ) ) { | 219 | if ( !file.open( IO_WriteOnly ) ) { |
221 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); | 220 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); |
@@ -223,87 +222,90 @@ bool ResourceDir::save( Ticket *ticket ) | |||
223 | } | 222 | } |
224 | 223 | ||
225 | mFormat->save( *it, &file ); | 224 | mFormat->save( *it, &file ); |
226 | 225 | ||
227 | // mark as unchanged | 226 | // mark as unchanged |
228 | (*it).setChanged( false ); | 227 | (*it).setChanged( false ); |
229 | 228 | ||
230 | file.close(); | 229 | file.close(); |
231 | } | 230 | } |
232 | mDirWatch.startScan(); | 231 | mDirWatch.startScan(); |
233 | 232 | ||
234 | delete ticket; | 233 | delete ticket; |
234 | #ifdef ALLOW_LOCKING | ||
235 | unlock( mPath ); | 235 | unlock( mPath ); |
236 | 236 | #endif | |
237 | return ok; | 237 | return ok; |
238 | } | 238 | } |
239 | 239 | ||
240 | bool ResourceDir::lock( const QString &path ) | 240 | bool ResourceDir::lock( const QString &path ) |
241 | { | 241 | { |
242 | kdDebug(5700) << "ResourceDir::lock()" << endl; | 242 | #ifdef ALLOW_LOCKING |
243 | |||
244 | QString p = path; | 243 | QString p = path; |
245 | //US change the implementation how the lockfilename is getting created | 244 | //US change the implementation how the lockfilename is getting created |
246 | //US p.replace( QRegExp("/"), "_" ); | 245 | //US p.replace( QRegExp("/"), "_" ); |
247 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); | 246 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); |
248 | KURL url(p); | 247 | KURL url(p); |
249 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 248 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
250 | 249 | ||
251 | 250 | ||
252 | kdDebug(5700) << "-- lock name: " << lockName << endl; | ||
253 | |||
254 | if ( QFile::exists( lockName ) ) return false; | 251 | if ( QFile::exists( lockName ) ) return false; |
255 | 252 | ||
256 | QString lockUniqueName; | 253 | QString lockUniqueName; |
257 | lockUniqueName = p + KApplication::randomString( 8 ); | 254 | lockUniqueName = p + KApplication::randomString( 8 ); |
258 | 255 | ||
259 | url = lockUniqueName; | 256 | url = lockUniqueName; |
260 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 257 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
261 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 258 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
262 | 259 | ||
263 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | ||
264 | |||
265 | // Create unique file | 260 | // Create unique file |
266 | QFile file( mLockUniqueName ); | 261 | QFile file( mLockUniqueName ); |
267 | file.open( IO_WriteOnly ); | 262 | file.open( IO_WriteOnly ); |
268 | file.close(); | 263 | file.close(); |
269 | 264 | ||
270 | // Create lock file | 265 | // Create lock file |
271 | int result = 0; | 266 | int result = 0; |
272 | #ifndef _WIN32_ | 267 | #ifndef _WIN32_ |
273 | result = ::link( QFile::encodeName( mLockUniqueName ), | 268 | result = ::link( QFile::encodeName( mLockUniqueName ), |
274 | QFile::encodeName( lockName ) ); | 269 | QFile::encodeName( lockName ) ); |
275 | #endif | 270 | #endif |
276 | if ( result == 0 ) { | 271 | if ( result == 0 ) { |
277 | addressBook()->emitAddressBookLocked(); | 272 | addressBook()->emitAddressBookLocked(); |
278 | return true; | 273 | return true; |
279 | } | 274 | } |
280 | 275 | ||
281 | // TODO: check stat | 276 | // TODO: check stat |
282 | 277 | ||
283 | return false; | 278 | return false; |
279 | #else | ||
280 | return true; | ||
281 | #endif | ||
284 | } | 282 | } |
285 | 283 | ||
286 | void ResourceDir::unlock( const QString &path ) | 284 | void ResourceDir::unlock( const QString &path ) |
287 | { | 285 | { |
286 | #ifdef ALLOW_LOCKING | ||
288 | QString p = path; | 287 | QString p = path; |
289 | //US change the implementation how the lockfilename is getting created | 288 | //US change the implementation how the lockfilename is getting created |
290 | //US p.replace( QRegExp( "/" ), "_" ); | 289 | //US p.replace( QRegExp( "/" ), "_" ); |
291 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); | 290 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); |
292 | KURL url(p); | 291 | KURL url(p); |
293 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 292 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
294 | 293 | ||
295 | ::unlink( QFile::encodeName( lockName ) ); | 294 | ::unlink( QFile::encodeName( lockName ) ); |
296 | QFile::remove( mLockUniqueName ); | 295 | QFile::remove( mLockUniqueName ); |
297 | addressBook()->emitAddressBookUnlocked(); | 296 | addressBook()->emitAddressBookUnlocked(); |
297 | #else | ||
298 | return; | ||
299 | #endif | ||
298 | } | 300 | } |
299 | 301 | ||
300 | void ResourceDir::setPath( const QString &path ) | 302 | void ResourceDir::setPath( const QString &path ) |
301 | { | 303 | { |
302 | mDirWatch.stopScan(); | 304 | mDirWatch.stopScan(); |
303 | mDirWatch.removeDir( mPath ); | 305 | mDirWatch.removeDir( mPath ); |
304 | 306 | ||
305 | mPath = path; | 307 | mPath = path; |
306 | 308 | ||
307 | mDirWatch.addDir( mPath, true ); | 309 | mDirWatch.addDir( mPath, true ); |
308 | mDirWatch.startScan(); | 310 | mDirWatch.startScan(); |
309 | 311 | ||
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index fa6bc49..17263ae 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -44,24 +44,25 @@ $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 | ||
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncprefwidget.h" | 54 | #include "syncprefwidget.h" |
55 | 55 | ||
56 | //#define ALLOW_LOCKING | ||
56 | 57 | ||
57 | using namespace KABC; | 58 | using namespace KABC; |
58 | 59 | ||
59 | extern "C" | 60 | extern "C" |
60 | #ifdef _WIN32_ | 61 | #ifdef _WIN32_ |
61 | __declspec(dllexport) | 62 | __declspec(dllexport) |
62 | #else | 63 | #else |
63 | { | 64 | { |
64 | #endif | 65 | #endif |
65 | 66 | ||
66 | //US void *init_kabc_file() | 67 | //US void *init_kabc_file() |
67 | void *init_microkabc_file() | 68 | void *init_microkabc_file() |
@@ -138,29 +139,30 @@ void ResourceFile::writeConfig( KConfig *config ) | |||
138 | config->writeEntry( "FileFormat", mFormatName ); | 139 | config->writeEntry( "FileFormat", mFormatName ); |
139 | 140 | ||
140 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 141 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
141 | 142 | ||
142 | } | 143 | } |
143 | 144 | ||
144 | Ticket *ResourceFile::requestSaveTicket() | 145 | Ticket *ResourceFile::requestSaveTicket() |
145 | { | 146 | { |
146 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 147 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
147 | 148 | ||
148 | if ( !addressBook() ) return 0; | 149 | if ( !addressBook() ) return 0; |
149 | 150 | ||
151 | #ifdef ALLOW_LOCKING | ||
150 | if ( !lock( mFileName ) ) { | 152 | if ( !lock( mFileName ) ) { |
151 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" | 153 | qDebug("unablt to lock file "); |
152 | << mFileName << "'" << endl; | ||
153 | return 0; | 154 | return 0; |
154 | } | 155 | } |
156 | #endif | ||
155 | return createTicket( this ); | 157 | return createTicket( this ); |
156 | } | 158 | } |
157 | 159 | ||
158 | 160 | ||
159 | bool ResourceFile::doOpen() | 161 | bool ResourceFile::doOpen() |
160 | { | 162 | { |
161 | QFile file( mFileName ); | 163 | QFile file( mFileName ); |
162 | 164 | ||
163 | if ( !file.exists() ) { | 165 | if ( !file.exists() ) { |
164 | // try to create the file | 166 | // try to create the file |
165 | bool ok = file.open( IO_WriteOnly ); | 167 | bool ok = file.open( IO_WriteOnly ); |
166 | if ( ok ) | 168 | if ( ok ) |
@@ -237,31 +239,34 @@ bool ResourceFile::save( Ticket *ticket ) | |||
237 | ok = true; | 239 | ok = true; |
238 | } | 240 | } |
239 | else { | 241 | else { |
240 | 242 | ||
241 | } | 243 | } |
242 | 244 | ||
243 | if ( !ok ) | 245 | if ( !ok ) |
244 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 246 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
245 | 247 | ||
246 | mDirWatch.startScan(); | 248 | mDirWatch.startScan(); |
247 | 249 | ||
248 | delete ticket; | 250 | delete ticket; |
251 | #ifdef ALLOW_LOCKING | ||
249 | unlock( mFileName ); | 252 | unlock( mFileName ); |
253 | #endif | ||
250 | 254 | ||
251 | return ok; | 255 | return ok; |
252 | } | 256 | } |
253 | 257 | ||
254 | bool ResourceFile::lock( const QString &fileName ) | 258 | bool ResourceFile::lock( const QString &fileName ) |
255 | { | 259 | { |
260 | #ifdef ALLOW_LOCKING | ||
256 | 261 | ||
257 | 262 | ||
258 | QString fn = fileName; | 263 | QString fn = fileName; |
259 | 264 | ||
260 | //US change the implementation how the lockfilename is getting created | 265 | //US change the implementation how the lockfilename is getting created |
261 | //US fn.replace( QRegExp("/"), "_" ); | 266 | //US fn.replace( QRegExp("/"), "_" ); |
262 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 267 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
263 | 268 | ||
264 | KURL url(fn); | 269 | KURL url(fn); |
265 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 270 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
266 | 271 | ||
267 | 272 | ||
@@ -286,39 +291,46 @@ bool ResourceFile::lock( const QString &fileName ) | |||
286 | #ifndef _WIN32_ | 291 | #ifndef _WIN32_ |
287 | result = ::link( QFile::encodeName( mLockUniqueName ), | 292 | result = ::link( QFile::encodeName( mLockUniqueName ), |
288 | QFile::encodeName( lockName ) ); | 293 | QFile::encodeName( lockName ) ); |
289 | #endif | 294 | #endif |
290 | if ( result == 0 ) { | 295 | if ( result == 0 ) { |
291 | addressBook()->emitAddressBookLocked(); | 296 | addressBook()->emitAddressBookLocked(); |
292 | return true; | 297 | return true; |
293 | } | 298 | } |
294 | 299 | ||
295 | // TODO: check stat | 300 | // TODO: check stat |
296 | 301 | ||
297 | return false; | 302 | return false; |
303 | #else | ||
304 | return true; | ||
305 | #endif | ||
298 | } | 306 | } |
299 | 307 | ||
300 | void ResourceFile::unlock( const QString &fileName ) | 308 | void ResourceFile::unlock( const QString &fileName ) |
301 | { | 309 | { |
310 | #ifdef ALLOW_LOCKING | ||
302 | QString fn = fileName; | 311 | QString fn = fileName; |
303 | //US change the implementation how the lockfilename is getting created | 312 | //US change the implementation how the lockfilename is getting created |
304 | //US fn.replace( QRegExp( "/" ), "_" ); | 313 | //US fn.replace( QRegExp( "/" ), "_" ); |
305 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 314 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
306 | //US QString lockName = fn + ".lock"; | 315 | //US QString lockName = fn + ".lock"; |
307 | KURL url(fn); | 316 | KURL url(fn); |
308 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 317 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
309 | 318 | ||
310 | QFile::remove( lockName ); | 319 | QFile::remove( lockName ); |
311 | QFile::remove( mLockUniqueName ); | 320 | QFile::remove( mLockUniqueName ); |
312 | addressBook()->emitAddressBookUnlocked(); | 321 | addressBook()->emitAddressBookUnlocked(); |
322 | #else | ||
323 | return; | ||
324 | #endif | ||
313 | } | 325 | } |
314 | 326 | ||
315 | void ResourceFile::setFileName( const QString &fileName ) | 327 | void ResourceFile::setFileName( const QString &fileName ) |
316 | { | 328 | { |
317 | mDirWatch.stopScan(); | 329 | mDirWatch.stopScan(); |
318 | mDirWatch.removeFile( mFileName ); | 330 | mDirWatch.removeFile( mFileName ); |
319 | 331 | ||
320 | mFileName = fileName; | 332 | mFileName = fileName; |
321 | 333 | ||
322 | 334 | ||
323 | mDirWatch.addFile( mFileName ); | 335 | mDirWatch.addFile( mFileName ); |
324 | mDirWatch.startScan(); | 336 | mDirWatch.startScan(); |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 8a795e9..867bc07 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -45,25 +45,25 @@ $Id$ | |||
45 | 45 | ||
46 | #include <sl/slzdb.h> | 46 | #include <sl/slzdb.h> |
47 | 47 | ||
48 | 48 | ||
49 | #include "resourcesharpdtmconfig.h" | 49 | #include "resourcesharpdtmconfig.h" |
50 | #include "resourcesharpdtm.h" | 50 | #include "resourcesharpdtm.h" |
51 | 51 | ||
52 | #include "syncprefwidget.h" | 52 | #include "syncprefwidget.h" |
53 | 53 | ||
54 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
55 | 55 | ||
56 | #include "sharpdtmconverter.h" | 56 | #include "sharpdtmconverter.h" |
57 | 57 | //#define ALLOW_LOCKING | |
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | extern "C" | 59 | extern "C" |
60 | { | 60 | { |
61 | void *init_microkabc_sharpdtm() | 61 | void *init_microkabc_sharpdtm() |
62 | { | 62 | { |
63 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); | 63 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) | 67 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) |
68 | : Resource( config, syncable ), mConverter (0) | 68 | : Resource( config, syncable ), mConverter (0) |
69 | { | 69 | { |
@@ -96,35 +96,36 @@ ResourceSharpDTM::~ResourceSharpDTM() | |||
96 | 96 | ||
97 | if(mAccess != 0) | 97 | if(mAccess != 0) |
98 | delete mAccess; | 98 | delete mAccess; |
99 | } | 99 | } |
100 | 100 | ||
101 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 101 | void ResourceSharpDTM::writeConfig( KConfig *config ) |
102 | { | 102 | { |
103 | Resource::writeConfig( config ); | 103 | Resource::writeConfig( config ); |
104 | } | 104 | } |
105 | 105 | ||
106 | Ticket *ResourceSharpDTM::requestSaveTicket() | 106 | Ticket *ResourceSharpDTM::requestSaveTicket() |
107 | { | 107 | { |
108 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket()" << endl; | 108 | |
109 | 109 | ||
110 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | 110 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); |
111 | 111 | ||
112 | if ( !addressBook() ) return 0; | 112 | if ( !addressBook() ) return 0; |
113 | 113 | ||
114 | #ifdef ALLOW_LOCKING | ||
114 | if ( !lock( fileName() ) ) { | 115 | if ( !lock( fileName() ) ) { |
115 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket(): Unable to lock file '" | 116 | qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); |
116 | << fileName() << "'" << endl; | ||
117 | return 0; | 117 | return 0; |
118 | } | 118 | } |
119 | #endif | ||
119 | return createTicket( this ); | 120 | return createTicket( this ); |
120 | } | 121 | } |
121 | 122 | ||
122 | 123 | ||
123 | bool ResourceSharpDTM::doOpen() | 124 | bool ResourceSharpDTM::doOpen() |
124 | { | 125 | { |
125 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); | 126 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); |
126 | 127 | ||
127 | // the last parameter in the SlZDataBase constructor means "readonly" | 128 | // the last parameter in the SlZDataBase constructor means "readonly" |
128 | mAccess = new SlZDataBase(fileName(), | 129 | mAccess = new SlZDataBase(fileName(), |
129 | SlZDataBase::addressbookItems(), | 130 | SlZDataBase::addressbookItems(), |
130 | NULL, true); | 131 | NULL, true); |
@@ -231,24 +232,25 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
231 | 232 | ||
232 | //US mAccess->save(); | 233 | //US mAccess->save(); |
233 | 234 | ||
234 | mDirWatch.startScan(); | 235 | mDirWatch.startScan(); |
235 | delete ticket; | 236 | delete ticket; |
236 | unlock( fileName() ); | 237 | unlock( fileName() ); |
237 | 238 | ||
238 | return true; | 239 | return true; |
239 | } | 240 | } |
240 | 241 | ||
241 | bool ResourceSharpDTM::lock( const QString &lockfileName ) | 242 | bool ResourceSharpDTM::lock( const QString &lockfileName ) |
242 | { | 243 | { |
244 | #ifdef ALLOW_LOCKING | ||
243 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); | 245 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); |
244 | 246 | ||
245 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; | 247 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; |
246 | 248 | ||
247 | QString fn = lockfileName; | 249 | QString fn = lockfileName; |
248 | 250 | ||
249 | KURL url(fn); | 251 | KURL url(fn); |
250 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 252 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
251 | 253 | ||
252 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 254 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
253 | 255 | ||
254 | if (QFile::exists( lockName )) | 256 | if (QFile::exists( lockName )) |
@@ -276,37 +278,42 @@ bool ResourceSharpDTM::lock( const QString &lockfileName ) | |||
276 | #ifndef _WIN32_ | 278 | #ifndef _WIN32_ |
277 | result = ::link( QFile::encodeName( mLockUniqueName ), | 279 | result = ::link( QFile::encodeName( mLockUniqueName ), |
278 | QFile::encodeName( lockName ) ); | 280 | QFile::encodeName( lockName ) ); |
279 | #endif | 281 | #endif |
280 | if ( result == 0 ) { | 282 | if ( result == 0 ) { |
281 | addressBook()->emitAddressBookLocked(); | 283 | addressBook()->emitAddressBookLocked(); |
282 | return true; | 284 | return true; |
283 | } | 285 | } |
284 | 286 | ||
285 | // TODO: check stat | 287 | // TODO: check stat |
286 | 288 | ||
287 | return false; | 289 | return false; |
290 | #else | ||
291 | return true; | ||
292 | #endif | ||
288 | } | 293 | } |
289 | 294 | ||
290 | void ResourceSharpDTM::unlock( const QString &fileName ) | 295 | void ResourceSharpDTM::unlock( const QString &fileName ) |
291 | { | 296 | { |
297 | #ifdef ALLOW_LOCKING | ||
292 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); | 298 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); |
293 | 299 | ||
294 | QString fn = fileName; | 300 | QString fn = fileName; |
295 | KURL url(fn); | 301 | KURL url(fn); |
296 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 302 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
297 | 303 | ||
298 | QFile::remove( lockName ); | 304 | QFile::remove( lockName ); |
299 | QFile::remove( mLockUniqueName ); | 305 | QFile::remove( mLockUniqueName ); |
300 | addressBook()->emitAddressBookUnlocked(); | 306 | addressBook()->emitAddressBookUnlocked(); |
307 | #endif | ||
301 | } | 308 | } |
302 | 309 | ||
303 | void ResourceSharpDTM::setFileName( const QString &newFileName ) | 310 | void ResourceSharpDTM::setFileName( const QString &newFileName ) |
304 | { | 311 | { |
305 | mDirWatch.stopScan(); | 312 | mDirWatch.stopScan(); |
306 | mDirWatch.removeFile( fileName() ); | 313 | mDirWatch.removeFile( fileName() ); |
307 | 314 | ||
308 | Resource::setFileName( newFileName ); | 315 | Resource::setFileName( newFileName ); |
309 | 316 | ||
310 | mDirWatch.addFile( fileName() ); | 317 | mDirWatch.addFile( fileName() ); |
311 | mDirWatch.startScan(); | 318 | mDirWatch.startScan(); |
312 | 319 | ||
diff --git a/kmicromail/accountitem.h b/kmicromail/accountitem.h index faf919d..4c92bfc 100644 --- a/kmicromail/accountitem.h +++ b/kmicromail/accountitem.h | |||
@@ -1,18 +1,20 @@ | |||
1 | #ifndef __ACCOUNT_ITEM | 1 | #ifndef __ACCOUNT_ITEM |
2 | #define __ACCOUNT_ITEM | 2 | #define __ACCOUNT_ITEM |
3 | 3 | ||
4 | |||
4 | #include <qlistview.h> | 5 | #include <qlistview.h> |
5 | #include <qlist.h> | 6 | #include <qlist.h> |
6 | #include <opie2/osmartpointer.h> | 7 | #include <opie2/osmartpointer.h> |
8 | #include <libmailwrapper/mailwrapper.h> | ||
7 | 9 | ||
8 | class POP3wrapper; | 10 | class POP3wrapper; |
9 | class RecMail; | 11 | class RecMail; |
10 | class RecBody; | 12 | class RecBody; |
11 | class QPopupMenu; | 13 | class QPopupMenu; |
12 | class Selectstore; | 14 | class Selectstore; |
13 | class AccountView; | 15 | class AccountView; |
14 | class POP3account; | 16 | class POP3account; |
15 | class NNTPaccount; | 17 | class NNTPaccount; |
16 | class IMAPaccount; | 18 | class IMAPaccount; |
17 | class AbstractMail; | 19 | class AbstractMail; |
18 | class Folder; | 20 | class Folder; |