author | ulf69 <ulf69> | 2004-08-02 18:32:08 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-02 18:32:08 (UTC) |
commit | 863c4c3678e59ef125c08c00e9532ded5b540f67 (patch) (unidiff) | |
tree | 449428c45689ffe10ff1ce4caa18f959c4dfe402 /kabc/plugins/opie | |
parent | 983127ce46c9ff6663d08dedd450da3fe7dd549b (diff) | |
download | kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.zip kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.tar.gz kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.tar.bz2 |
added support for syncprofiles for resources and export/import capabilities
-rw-r--r-- | kabc/plugins/opie/opieE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 302 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.h | 40 |
3 files changed, 172 insertions, 172 deletions
diff --git a/kabc/plugins/opie/opieE.pro b/kabc/plugins/opie/opieE.pro index 8d45c3d..912e596 100644 --- a/kabc/plugins/opie/opieE.pro +++ b/kabc/plugins/opie/opieE.pro | |||
@@ -3,7 +3,7 @@ CONFIG += qt warn_on | |||
3 | #release debug | 3 | #release debug |
4 | TARGET = microkabc_opie | 4 | TARGET = microkabc_opie |
5 | 5 | ||
6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include $(OPIEDIR)/include | 6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat $(QPEDIR)/include $(OPIEDIR)/include |
7 | 7 | ||
8 | 8 | ||
9 | OBJECTS_DIR = obj/$(PLATFORM) | 9 | OBJECTS_DIR = obj/$(PLATFORM) |
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index aaee801..1222242 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -50,6 +50,7 @@ $Id$ | |||
50 | 50 | ||
51 | #include "resourceopieconfig.h" | 51 | #include "resourceopieconfig.h" |
52 | #include "stdaddressbook.h" | 52 | #include "stdaddressbook.h" |
53 | #include "syncwidget.h" | ||
53 | 54 | ||
54 | #include "opieconverter.h" | 55 | #include "opieconverter.h" |
55 | 56 | ||
@@ -60,28 +61,28 @@ extern "C" | |||
60 | { | 61 | { |
61 | void *init_microkabc_opie() | 62 | void *init_microkabc_opie() |
62 | { | 63 | { |
63 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); | 64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, KRES::SyncWidget>(); |
64 | } | 65 | } |
65 | } | 66 | } |
66 | 67 | ||
67 | ResourceOpie::ResourceOpie( const KConfig *config ) | 68 | ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) |
68 | : Resource( config ), mConverter (0) | 69 | : Resource( config, syncable ), mAccess(0), mConverter (0) |
69 | { | 70 | { |
70 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
71 | 72 | ||
72 | KConfig *cfg = (KConfig *)config; | 73 | KConfig *cfg = (KConfig *)config; |
73 | if ( cfg ) { | 74 | if ( cfg ) { |
74 | fileName = cfg->readEntry( "FileName", fileName ); | 75 | fileName = cfg->readEntry( "FileName", fileName ); |
75 | 76 | ||
76 | } | 77 | } |
77 | 78 | ||
78 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); | 79 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); |
79 | 80 | ||
80 | init( fileName ); | 81 | init( fileName ); |
81 | } | 82 | } |
82 | 83 | ||
83 | ResourceOpie::ResourceOpie( const QString &fileName ) | 84 | ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) |
84 | : Resource( 0 ) | 85 | : Resource( 0, syncable ) |
85 | { | 86 | { |
86 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); | 87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); |
87 | init( fileName ); | 88 | init( fileName ); |
@@ -93,37 +94,40 @@ void ResourceOpie::init( const QString &fileName ) | |||
93 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 94 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
94 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 95 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
95 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 96 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
96 | 97 | ||
97 | 98 | ||
98 | setFileName( fileName ); | 99 | setFileName( fileName ); |
99 | 100 | ||
100 | } | 101 | } |
101 | 102 | ||
102 | ResourceOpie::~ResourceOpie() | 103 | ResourceOpie::~ResourceOpie() |
103 | { | 104 | { |
104 | if (mConverter != 0) | 105 | if (mConverter != 0) |
105 | delete mConverter; | 106 | delete mConverter; |
107 | |||
108 | if(mAccess != 0) | ||
109 | delete mAccess; | ||
110 | |||
106 | } | 111 | } |
107 | 112 | ||
108 | void ResourceOpie::writeConfig( KConfig *config ) | 113 | void ResourceOpie::writeConfig( KConfig *config ) |
109 | { | 114 | { |
110 | Resource::writeConfig( config ); | 115 | Resource::writeConfig( config ); |
111 | 116 | ||
112 | config->writeEntry( "FileName", mFileName ); | 117 | config->writeEntry( "FileName", fileName() ); |
113 | |||
114 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
115 | |||
116 | } | 118 | } |
117 | 119 | ||
118 | Ticket *ResourceOpie::requestSaveTicket() | 120 | Ticket *ResourceOpie::requestSaveTicket() |
119 | { | 121 | { |
120 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | 122 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; |
121 | 123 | ||
124 | qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); | ||
125 | |||
122 | if ( !addressBook() ) return 0; | 126 | if ( !addressBook() ) return 0; |
123 | 127 | ||
124 | if ( !lock( mFileName ) ) { | 128 | if ( !lock( fileName() ) ) { |
125 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | 129 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" |
126 | << mFileName << "'" << endl; | 130 | << fileName() << "'" << endl; |
127 | return 0; | 131 | return 0; |
128 | } | 132 | } |
129 | return createTicket( this ); | 133 | return createTicket( this ); |
@@ -132,177 +136,142 @@ Ticket *ResourceOpie::requestSaveTicket() | |||
132 | 136 | ||
133 | bool ResourceOpie::doOpen() | 137 | bool ResourceOpie::doOpen() |
134 | { | 138 | { |
135 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); | 139 | qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); |
136 | /*US | ||
137 | QFile file( mFileName ); | ||
138 | |||
139 | if ( !file.exists() ) { | ||
140 | // try to create the file | ||
141 | bool ok = file.open( IO_WriteOnly ); | ||
142 | if ( ok ) | ||
143 | file.close(); | ||
144 | |||
145 | return ok; | ||
146 | } else { | ||
147 | if ( !file.open( IO_ReadWrite ) ) | ||
148 | return false; | ||
149 | |||
150 | if ( file.size() == 0 ) { | ||
151 | file.close(); | ||
152 | return true; | ||
153 | } | ||
154 | 140 | ||
155 | //US bool ok = mFormat->checkFormat( &file ); | 141 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); |
156 | bool ok = true; | 142 | mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); |
157 | |||
158 | file.close(); | ||
159 | 143 | ||
160 | return ok; | 144 | if ( !mAccess ) { |
145 | qDebug("Unable to load file() %s", fileName().latin1()); | ||
146 | return false; | ||
161 | } | 147 | } |
162 | */ | ||
163 | qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); | ||
164 | return true; | ||
165 | } | ||
166 | 148 | ||
167 | void ResourceOpie::doClose() | 149 | mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available |
168 | { | ||
169 | // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); | ||
170 | } | ||
171 | 150 | ||
172 | bool ResourceOpie::load() | ||
173 | { | ||
174 | // qDebug("ResourceOpie::load() %s", mFileName.latin1()); | ||
175 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; | ||
176 | |||
177 | qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); | ||
178 | |||
179 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); | ||
180 | OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); | ||
181 | |||
182 | if ( !access ) { | ||
183 | qDebug("Unable to load file() %s", mFileName.latin1()); | ||
184 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | ||
185 | return false; | ||
186 | } | ||
187 | |||
188 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | ||
189 | 151 | ||
190 | bool res = false; | ||
191 | if (mConverter == 0) | 152 | if (mConverter == 0) |
192 | { | 153 | { |
193 | mConverter = new OpieConverter(); | 154 | mConverter = new OpieConverter(); |
194 | res = mConverter->init(); | 155 | bool res = mConverter->init(); |
195 | if ( !res ) | 156 | if ( !res ) |
196 | { | 157 | { |
197 | qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); | 158 | qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); |
198 | addressBook()->error( i18n( "Unable to initialize opie converter. Most likely a problem with the category file" ) ); | 159 | delete mAccess; |
199 | delete access; | 160 | mAccess = 0; |
200 | return false; | 161 | return false; |
201 | } | 162 | } |
202 | } | 163 | } |
203 | 164 | ||
204 | 165 | ||
205 | OContactAccess::List::Iterator it; | 166 | |
206 | OContactAccess::List allList = access->allRecords(); | 167 | return true; |
168 | } | ||
169 | |||
170 | void ResourceOpie::doClose() | ||
171 | { | ||
172 | qDebug("ResourceOpie::doClose: %s", fileName().latin1()); | ||
173 | |||
174 | if(mAccess) | ||
175 | { | ||
176 | delete mAccess; | ||
177 | mAccess = 0; | ||
178 | } | ||
179 | // it seems so, that deletion of access deletes backend as well | ||
180 | //delete backend; | ||
181 | |||
182 | return; | ||
183 | |||
184 | } | ||
185 | |||
186 | |||
187 | bool ResourceOpie::load() | ||
188 | { | ||
189 | qDebug("ResourceOpie::load: %s", fileName().latin1()); | ||
190 | |||
191 | bool res = false; | ||
192 | |||
193 | OContactAccess::List::Iterator it; | ||
194 | OContactAccess::List allList = mAccess->allRecords(); | ||
207 | for ( it = allList.begin(); it != allList.end(); ++it ) | 195 | for ( it = allList.begin(); it != allList.end(); ++it ) |
208 | { | 196 | { |
209 | const OContact c = (*it); | 197 | const OContact c = (*it); |
210 | 198 | ||
211 | KABC::Addressee addressee; | 199 | KABC::Addressee addressee; |
212 | 200 | ||
213 | res = mConverter->opieToAddressee( c, addressee ); | 201 | res = mConverter->opieToAddressee( c, addressee ); |
214 | 202 | ||
215 | if ( !addressee.isEmpty() && res ) | 203 | if ( !addressee.isEmpty() && res ) |
216 | { | 204 | { |
217 | addressee.setResource( this ); | 205 | addressee.setResource( this ); |
218 | addressBook()->insertAddressee( addressee ); | 206 | addressBook()->insertAddressee( addressee ); |
219 | } | 207 | } |
220 | 208 | ||
221 | // qDebug("found %s", c.fullName().latin1()); | ||
222 | } | 209 | } |
223 | 210 | ||
224 | delete access; | 211 | |
225 | // it seems so, that deletion of access deletes backend as well | ||
226 | //delete backend; | ||
227 | |||
228 | return true; | 212 | return true; |
229 | } | 213 | } |
230 | 214 | ||
231 | bool ResourceOpie::save( Ticket *ticket ) | 215 | bool ResourceOpie::save( Ticket *ticket ) |
232 | { | 216 | { |
233 | qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); | 217 | qDebug("ResourceOpie::save: %s", fileName().latin1()); |
234 | /*US | 218 | |
235 | 219 | ||
236 | qDebug("ResourceOpie::save %s", mFileName.latin1()); | 220 | |
237 | kdDebug(5700) << "ResourceOpie::save()" << endl; | 221 | KABC::AddressBook::Iterator it; |
238 | 222 | bool res; | |
239 | // create backup file | 223 | |
240 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 224 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
241 | */ | 225 | OContact c; |
242 | /*US we use a simpler method to create a backupfile | 226 | KABC::Addressee addressee = (*it); |
243 | 227 | ||
244 | (void) KSaveFile::backupFile( mFileName, QString::null | 228 | res = mConverter->addresseeToOpie( *it, c ); |
245 | ,extension ); | 229 | if (res == true) |
246 | 230 | { | |
247 | KSaveFile saveFile( mFileName ); | 231 | res = mAccess->add(c); |
248 | bool ok = false; | 232 | if (res == false) |
249 | if ( saveFile.status() == 0 && saveFile.file() ) | 233 | qDebug("Unable to append Contact %s", c.fullName().latin1()); |
250 | { | 234 | } |
251 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 235 | else |
252 | ok = saveFile.close(); | 236 | { |
253 | } | 237 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
254 | */ | 238 | } |
255 | /*US | ||
256 | //US ToDo: write backupfile | ||
257 | QFile info; | ||
258 | info.setName( mFileName ); | ||
259 | bool ok = info.open( IO_WriteOnly ); | ||
260 | if ( ok ) { | ||
261 | //US mFormat->saveAll( addressBook(), this, &info ); | ||
262 | |||
263 | info.close(); | ||
264 | ok = true; | ||
265 | } | ||
266 | else { | ||
267 | |||
268 | } | 239 | } |
269 | 240 | ||
270 | if ( !ok ) | 241 | mAccess->save(); |
271 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 242 | |
272 | |||
273 | delete ticket; | 243 | delete ticket; |
274 | unlock( mFileName ); | 244 | unlock( fileName() ); |
275 | |||
276 | return ok; | ||
277 | 245 | ||
278 | qDebug("ResourceOpie::save has to be changed"); | ||
279 | */ | ||
280 | return true; | 246 | return true; |
281 | 247 | ||
282 | } | 248 | } |
283 | 249 | ||
284 | bool ResourceOpie::lock( const QString &fileName ) | 250 | bool ResourceOpie::lock( const QString &lockfileName ) |
285 | { | 251 | { |
252 | qDebug("ResourceOpie::lock: %s", fileName().latin1()); | ||
253 | |||
254 | |||
286 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); | 255 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); |
287 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | 256 | kdDebug(5700) << "ResourceOpie::lock()" << endl; |
288 | 257 | ||
289 | QString fn = fileName; | 258 | QString fn = lockfileName; |
290 | 259 | ||
291 | //US change the implementation how the lockfilename is getting created | 260 | //US change the implementation how the lockfilename is getting created |
292 | //US fn.replace( QRegExp("/"), "_" ); | 261 | //US fn.replace( QRegExp("/"), "_" ); |
293 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 262 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
294 | 263 | ||
295 | KURL url(fn); | 264 | KURL url(fn); |
296 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 265 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
297 | 266 | ||
298 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 267 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
299 | 268 | ||
300 | if (QFile::exists( lockName )) return false; | 269 | if (QFile::exists( lockName )) return false; |
301 | 270 | ||
302 | QString lockUniqueName; | 271 | QString lockUniqueName; |
303 | lockUniqueName = fn + KApplication::randomString( 8 ); | 272 | lockUniqueName = fn + KApplication::randomString( 8 ); |
304 | 273 | ||
305 | url = lockUniqueName; | 274 | url = lockUniqueName; |
306 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 275 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
307 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 276 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
308 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 277 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
@@ -330,39 +299,33 @@ bool ResourceOpie::lock( const QString &fileName ) | |||
330 | 299 | ||
331 | void ResourceOpie::unlock( const QString &fileName ) | 300 | void ResourceOpie::unlock( const QString &fileName ) |
332 | { | 301 | { |
333 | // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); | 302 | qDebug("ResourceOpie::unlock() %s", fileName.latin1()); |
334 | 303 | ||
335 | QString fn = fileName; | 304 | QString fn = fileName; |
336 | //US change the implementation how the lockfilename is getting created | 305 | //US change the implementation how the lockfilename is getting created |
337 | //US fn.replace( QRegExp( "/" ), "_" ); | 306 | //US fn.replace( QRegExp( "/" ), "_" ); |
338 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 307 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
339 | //US QString lockName = fn + ".lock"; | 308 | //US QString lockName = fn + ".lock"; |
340 | KURL url(fn); | 309 | KURL url(fn); |
341 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 310 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
342 | 311 | ||
343 | QFile::remove( lockName ); | 312 | QFile::remove( lockName ); |
344 | QFile::remove( mLockUniqueName ); | 313 | QFile::remove( mLockUniqueName ); |
345 | addressBook()->emitAddressBookUnlocked(); | 314 | addressBook()->emitAddressBookUnlocked(); |
346 | } | 315 | } |
347 | 316 | ||
348 | void ResourceOpie::setFileName( const QString &fileName ) | 317 | void ResourceOpie::setFileName( const QString &newFileName ) |
349 | { | 318 | { |
350 | mDirWatch.stopScan(); | 319 | mDirWatch.stopScan(); |
351 | mDirWatch.removeFile( mFileName ); | 320 | mDirWatch.removeFile( fileName() ); |
352 | 321 | ||
353 | mFileName = fileName; | 322 | Resource::setFileName( newFileName ); |
354 | 323 | ||
355 | mDirWatch.addFile( mFileName ); | 324 | mDirWatch.addFile( fileName() ); |
356 | mDirWatch.startScan(); | 325 | mDirWatch.startScan(); |
357 | 326 | ||
358 | //US simulate KDirWatch event | ||
359 | //US fileChanged(); | ||
360 | } | 327 | } |
361 | 328 | ||
362 | QString ResourceOpie::fileName() const | ||
363 | { | ||
364 | return mFileName; | ||
365 | } | ||
366 | 329 | ||
367 | void ResourceOpie::fileChanged() | 330 | void ResourceOpie::fileChanged() |
368 | { | 331 | { |
@@ -370,13 +333,13 @@ void ResourceOpie::fileChanged() | |||
370 | // we are fully constructed | 333 | // we are fully constructed |
371 | if (!addressBook()) | 334 | if (!addressBook()) |
372 | return; | 335 | return; |
373 | 336 | ||
374 | QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 337 | QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
375 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 338 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
376 | load(); | 339 | load(); |
377 | addressBook()->emitAddressBookChanged(); | 340 | addressBook()->emitAddressBookChanged(); |
378 | } | 341 | } |
379 | 342 | ||
380 | load(); | 343 | load(); |
381 | addressBook()->emitAddressBookChanged(); | 344 | addressBook()->emitAddressBookChanged(); |
382 | } | 345 | } |
@@ -389,7 +352,40 @@ void ResourceOpie::cleanUp() | |||
389 | { | 352 | { |
390 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); | 353 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); |
391 | 354 | ||
392 | unlock( mFileName ); | 355 | unlock( fileName() ); |
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * This method returns the number of elements that are currently in the resource. | ||
361 | */ | ||
362 | int ResourceOpie::count() const | ||
363 | { | ||
364 | qDebug("ResourceOpie::count: %x", mAccess); | ||
365 | |||
366 | if (mAccess != 0) | ||
367 | { | ||
368 | OContactAccess::List contactList = mAccess->allRecords(); | ||
369 | return contactList.count(); | ||
370 | } | ||
371 | else | ||
372 | return 0; | ||
373 | } | ||
374 | |||
375 | |||
376 | /** | ||
377 | * This method removes all elements from the resource!! (Not from the addressbook) | ||
378 | */ | ||
379 | bool ResourceOpie::clear() | ||
380 | { | ||
381 | if (mAccess != 0) { | ||
382 | mAccess->clear(); | ||
383 | return true; | ||
384 | } | ||
385 | else | ||
386 | return false; | ||
393 | } | 387 | } |
394 | 388 | ||
389 | |||
390 | |||
395 | //US #include "resourceopie.moc" | 391 | //US #include "resourceopie.moc" |
diff --git a/kabc/plugins/opie/resourceopie.h b/kabc/plugins/opie/resourceopie.h index 9db9485..ca30fee 100644 --- a/kabc/plugins/opie/resourceopie.h +++ b/kabc/plugins/opie/resourceopie.h | |||
@@ -37,12 +37,10 @@ $Id$ | |||
37 | #include "resource.h" | 37 | #include "resource.h" |
38 | 38 | ||
39 | 39 | ||
40 | //class QTimer; | 40 | class OContactAccess; |
41 | //class FormatPlugin; | ||
42 | 41 | ||
43 | namespace KABC { | 42 | namespace KABC { |
44 | 43 | ||
45 | //US class FormatPlugin; | ||
46 | class ResourceConfigWidget; | 44 | class ResourceConfigWidget; |
47 | class OpieConverter; | 45 | class OpieConverter; |
48 | /** | 46 | /** |
@@ -59,12 +57,12 @@ public: | |||
59 | 57 | ||
60 | @param cfg The config object where custom resource settings are stored. | 58 | @param cfg The config object where custom resource settings are stored. |
61 | */ | 59 | */ |
62 | ResourceOpie( const KConfig *cfg ); | 60 | ResourceOpie( const KConfig *cfg, bool syncable ); |
63 | 61 | ||
64 | /** | 62 | /** |
65 | Construct file resource on file @arg fileName using format @arg formatName. | 63 | Construct file resource on file @arg fileName using format @arg formatName. |
66 | */ | 64 | */ |
67 | ResourceOpie( const QString &fileName ); | 65 | ResourceOpie( const QString &fileName, bool syncable ); |
68 | 66 | ||
69 | /** | 67 | /** |
70 | * Destructor. | 68 | * Destructor. |
@@ -86,7 +84,7 @@ public: | |||
86 | * Closes the file again. | 84 | * Closes the file again. |
87 | */ | 85 | */ |
88 | virtual void doClose(); | 86 | virtual void doClose(); |
89 | 87 | ||
90 | /** | 88 | /** |
91 | * Requests a save ticket, that is used by @ref save() | 89 | * Requests a save ticket, that is used by @ref save() |
92 | */ | 90 | */ |
@@ -106,15 +104,6 @@ public: | |||
106 | */ | 104 | */ |
107 | virtual bool save( Ticket *ticket ); | 105 | virtual bool save( Ticket *ticket ); |
108 | 106 | ||
109 | /** | ||
110 | * Set name of file to be used for saving. | ||
111 | */ | ||
112 | void setFileName( const QString & ); | ||
113 | |||
114 | /** | ||
115 | * Return name of file used for loading and saving the address book. | ||
116 | */ | ||
117 | QString fileName() const; | ||
118 | 107 | ||
119 | /** | 108 | /** |
120 | * Remove a addressee from its source. | 109 | * Remove a addressee from its source. |
@@ -123,11 +112,27 @@ public: | |||
123 | virtual void removeAddressee( const Addressee& addr ); | 112 | virtual void removeAddressee( const Addressee& addr ); |
124 | 113 | ||
125 | /** | 114 | /** |
115 | * Set name of file to be used for saving. | ||
116 | */ | ||
117 | virtual void setFileName( const QString & ); | ||
118 | |||
119 | /** | ||
126 | * This method is called by an error handler if the application | 120 | * This method is called by an error handler if the application |
127 | * crashed | 121 | * crashed |
128 | */ | 122 | */ |
129 | virtual void cleanUp(); | 123 | virtual void cleanUp(); |
130 | 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 | |||
135 | |||
131 | protected slots: | 136 | protected slots: |
132 | void fileChanged(); | 137 | void fileChanged(); |
133 | 138 | ||
@@ -138,12 +143,11 @@ protected: | |||
138 | void unlock( const QString &fileName ); | 143 | void unlock( const QString &fileName ); |
139 | 144 | ||
140 | private: | 145 | private: |
146 | OContactAccess* mAccess; | ||
141 | OpieConverter* mConverter; | 147 | OpieConverter* mConverter; |
142 | |||
143 | QString mFileName; | ||
144 | 148 | ||
145 | QString mLockUniqueName; | 149 | QString mLockUniqueName; |
146 | 150 | ||
147 | KDirWatch mDirWatch; | 151 | KDirWatch mDirWatch; |
148 | }; | 152 | }; |
149 | 153 | ||