summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/qtopia
Unidiff
Diffstat (limited to 'kabc/plugins/qtopia') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp49
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.h10
2 files changed, 5 insertions, 54 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 4a35f19..242e0c6 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -224,25 +224,29 @@ bool ResourceQtopia::lock( const QString &lockfileName )
224{ 224{
225 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 225 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
226 226
227 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 227 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
228 228
229 QString fn = lockfileName; 229 QString fn = lockfileName;
230 230
231 KURL url(fn); 231 KURL url(fn);
232 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 232 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
233 233
234 kdDebug(5700) << "-- lock name: " << lockName << endl; 234 kdDebug(5700) << "-- lock name: " << lockName << endl;
235 235
236 if (QFile::exists( lockName )) return false; 236 if (QFile::exists( lockName ))
237 {
238 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
239 return false;
240 }
237 241
238 QString lockUniqueName; 242 QString lockUniqueName;
239 lockUniqueName = fn + KApplication::randomString( 8 ); 243 lockUniqueName = fn + KApplication::randomString( 8 );
240 244
241 url = lockUniqueName; 245 url = lockUniqueName;
242//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 246//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
243 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 247 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
244 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 248 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
245 249
246 // Create unique file 250 // Create unique file
247 QFile file( mLockUniqueName ); 251 QFile file( mLockUniqueName );
248 file.open( IO_WriteOnly ); 252 file.open( IO_WriteOnly );
@@ -303,56 +307,13 @@ void ResourceQtopia::fileChanged()
303 } 307 }
304} 308}
305 309
306void ResourceQtopia::removeAddressee( const Addressee &addr ) 310void ResourceQtopia::removeAddressee( const Addressee &addr )
307{ 311{
308} 312}
309 313
310void ResourceQtopia::cleanUp() 314void ResourceQtopia::cleanUp()
311{ 315{
312 unlock( fileName() ); 316 unlock( fileName() );
313} 317}
314 318
315
316
317/**
318 * This method returns the number of elements that are currently in the resource.
319 */
320int ResourceQtopia::count() const
321{
322 if (mAccess != 0)
323 {
324 int counter = 0;
325 AddressBookIterator it2(*mAccess);
326 for (it2.toFirst(); it2.current(); ++it2) {
327 counter++;
328 }
329
330 return counter;
331 }
332 else
333 return 0;
334}
335
336
337/**
338 * This method removes all elements from the resource!! (Not from the addressbook)
339 */
340bool ResourceQtopia::clear()
341{
342 if (mAccess != 0)
343 {
344 AddressBookIterator it2(*mAccess);
345 for (it2.toFirst(); it2.current(); ++it2) {
346 mAccess->removeContact(*it2.current());
347 }
348 return true;
349 }
350 else
351 return false;
352}
353
354
355
356
357
358//US #include "resourceqtopia.moc" 319//US #include "resourceqtopia.moc"
diff --git a/kabc/plugins/qtopia/resourceqtopia.h b/kabc/plugins/qtopia/resourceqtopia.h
index 90ab1f4..eace280 100644
--- a/kabc/plugins/qtopia/resourceqtopia.h
+++ b/kabc/plugins/qtopia/resourceqtopia.h
@@ -113,34 +113,24 @@ public:
113 113
114 /** 114 /**
115 * Set name of file to be used for saving. 115 * Set name of file to be used for saving.
116 */ 116 */
117 virtual void setFileName( const QString & ); 117 virtual void setFileName( const QString & );
118 118
119 /** 119 /**
120 * This method is called by an error handler if the application 120 * This method is called by an error handler if the application
121 * crashed 121 * crashed
122 */ 122 */
123 virtual void cleanUp(); 123 virtual void cleanUp();
124 124
125 /**
126 * This method returns the number of elements that are currently in the resource.
127 */
128 virtual int count() const;
129
130 /**
131 * This method removes all elements from the resource!! (Not from the addressbook)
132 */
133 virtual bool clear();
134
135protected slots: 125protected slots:
136 void fileChanged(); 126 void fileChanged();
137 127
138protected: 128protected:
139 void init( const QString &fileName ); 129 void init( const QString &fileName );
140 130
141 bool lock( const QString &fileName ); 131 bool lock( const QString &fileName );
142 void unlock( const QString &fileName ); 132 void unlock( const QString &fileName );
143 133
144private: 134private:
145 AddressBookAccess* mAccess; 135 AddressBookAccess* mAccess;
146 QtopiaConverter* mConverter; 136 QtopiaConverter* mConverter;