-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 7475685..7e10e46 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -66,7 +66,7 @@ ResourceQtopia::ResourceQtopia( const KConfig *config ) | |||
66 | { | 66 | { |
67 | // we can not choose the filename. Therefore use the default to display | 67 | // we can not choose the filename. Therefore use the default to display |
68 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 68 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
69 | 69 | ||
70 | init( fileName ); | 70 | init( fileName ); |
71 | } | 71 | } |
72 | 72 | ||
@@ -137,13 +137,13 @@ bool ResourceQtopia::doOpen() | |||
137 | 137 | ||
138 | //US bool ok = mFormat->checkFormat( &file ); | 138 | //US bool ok = mFormat->checkFormat( &file ); |
139 | bool ok = true; | 139 | bool ok = true; |
140 | 140 | ||
141 | file.close(); | 141 | file.close(); |
142 | 142 | ||
143 | return ok; | 143 | return ok; |
144 | } | 144 | } |
145 | */ | 145 | */ |
146 | return true; | 146 | return true; |
147 | } | 147 | } |
148 | 148 | ||
149 | void ResourceQtopia::doClose() | 149 | void ResourceQtopia::doClose() |
@@ -155,7 +155,7 @@ bool ResourceQtopia::load() | |||
155 | kdDebug(5700) << "ResourceQtopia::load(): '" << mFileName << "'" << endl; | 155 | kdDebug(5700) << "ResourceQtopia::load(): '" << mFileName << "'" << endl; |
156 | 156 | ||
157 | // qDebug("ResourceQtopia::load: Try to load file() %s", mFileName.latin1()); | 157 | // qDebug("ResourceQtopia::load: Try to load file() %s", mFileName.latin1()); |
158 | 158 | ||
159 | AddressBookAccess* access = new AddressBookAccess(); | 159 | AddressBookAccess* access = new AddressBookAccess(); |
160 | 160 | ||
161 | if ( !access ) { | 161 | if ( !access ) { |
@@ -163,7 +163,7 @@ bool ResourceQtopia::load() | |||
163 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | 163 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); |
164 | return false; | 164 | return false; |
165 | } | 165 | } |
166 | 166 | ||
167 | bool res = false; | 167 | bool res = false; |
168 | if (mConverter == 0) | 168 | if (mConverter == 0) |
169 | { | 169 | { |
@@ -171,24 +171,25 @@ bool ResourceQtopia::load() | |||
171 | res = mConverter->init(); | 171 | res = mConverter->init(); |
172 | if ( !res ) | 172 | if ( !res ) |
173 | { | 173 | { |
174 | qDebug("Unable to initialize qtopia converter. Most likely a problem with the category file"); | 174 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); |
175 | addressBook()->error( i18n( "Unable to initialize qtopia converter. Most likely a problem with the category file" ) ); | 175 | qDebug(msg); |
176 | addressBook()->error( i18n( msg ) ); | ||
176 | delete access; | 177 | delete access; |
177 | return false; | 178 | return false; |
178 | } | 179 | } |
179 | } | 180 | } |
180 | 181 | ||
181 | { //create a new scope | 182 | { //create a new scope |
182 | AddressBookIterator it(*access); | 183 | AddressBookIterator it(*access); |
183 | const PimContact* contact; | 184 | const PimContact* contact; |
184 | 185 | ||
185 | for (contact=it.toFirst(); it.current(); ++it) { | 186 | for (contact=it.toFirst(); it.current(); ++it) { |
186 | contact = it.current(); | 187 | contact = it.current(); |
187 | 188 | ||
188 | KABC::Addressee addressee; | 189 | KABC::Addressee addressee; |
189 | 190 | ||
190 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); | 191 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); |
191 | 192 | ||
192 | if ( !addressee.isEmpty() && res ) | 193 | if ( !addressee.isEmpty() && res ) |
193 | { | 194 | { |
194 | addressee.setResource( this ); | 195 | addressee.setResource( this ); |
@@ -196,7 +197,7 @@ bool ResourceQtopia::load() | |||
196 | } | 197 | } |
197 | } | 198 | } |
198 | } | 199 | } |
199 | 200 | ||
200 | delete access; | 201 | delete access; |
201 | return true; | 202 | return true; |
202 | } | 203 | } |
@@ -209,9 +210,9 @@ bool ResourceQtopia::save( Ticket *ticket ) | |||
209 | 210 | ||
210 | // create backup file | 211 | // create backup file |
211 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 212 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
212 | 213 | ||
213 | /*US we use a simpler method to create a backupfile | 214 | /*US we use a simpler method to create a backupfile |
214 | 215 | ||
215 | (void) KSaveFile::backupFile( mFileName, QString::null | 216 | (void) KSaveFile::backupFile( mFileName, QString::null |
216 | ,extension ); | 217 | ,extension ); |
217 | 218 | ||
@@ -225,30 +226,30 @@ bool ResourceQtopia::save( Ticket *ticket ) | |||
225 | */ | 226 | */ |
226 | 227 | ||
227 | /*US | 228 | /*US |
228 | //US ToDo: write backupfile | 229 | //US ToDo: write backupfile |
229 | QFile info; | 230 | QFile info; |
230 | info.setName( mFileName ); | 231 | info.setName( mFileName ); |
231 | bool ok = info.open( IO_WriteOnly ); | 232 | bool ok = info.open( IO_WriteOnly ); |
232 | if ( ok ) { | 233 | if ( ok ) { |
233 | //US mFormat->saveAll( addressBook(), this, &info ); | 234 | //US mFormat->saveAll( addressBook(), this, &info ); |
234 | 235 | ||
235 | info.close(); | 236 | info.close(); |
236 | ok = true; | 237 | ok = true; |
237 | } | 238 | } |
238 | else { | 239 | else { |
239 | 240 | ||
240 | } | 241 | } |
241 | 242 | ||
242 | if ( !ok ) | 243 | if ( !ok ) |
243 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 244 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
244 | 245 | ||
245 | delete ticket; | 246 | delete ticket; |
246 | unlock( mFileName ); | 247 | unlock( mFileName ); |
247 | 248 | ||
248 | return ok; | 249 | return ok; |
249 | 250 | ||
250 | qDebug("ResourceQtopia::save has to be changed"); | 251 | qDebug("ResourceQtopia::save has to be changed"); |
251 | */ | 252 | */ |
252 | return true; | 253 | return true; |
253 | } | 254 | } |
254 | 255 | ||
@@ -261,18 +262,18 @@ bool ResourceQtopia::lock( const QString &fileName ) | |||
261 | //US change the implementation how the lockfilename is getting created | 262 | //US change the implementation how the lockfilename is getting created |
262 | //US fn.replace( QRegExp("/"), "_" ); | 263 | //US fn.replace( QRegExp("/"), "_" ); |
263 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 264 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
264 | 265 | ||
265 | KURL url(fn); | 266 | KURL url(fn); |
266 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 267 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
267 | 268 | ||
268 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 269 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
269 | 270 | ||
270 | if (QFile::exists( lockName )) return false; | 271 | if (QFile::exists( lockName )) return false; |
271 | 272 | ||
272 | QString lockUniqueName; | 273 | QString lockUniqueName; |
273 | lockUniqueName = fn + KApplication::randomString( 8 ); | 274 | lockUniqueName = fn + KApplication::randomString( 8 ); |
274 | 275 | ||
275 | url = lockUniqueName; | 276 | url = lockUniqueName; |
276 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 277 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
277 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 278 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
278 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 279 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
@@ -303,9 +304,9 @@ void ResourceQtopia::unlock( const QString &fileName ) | |||
303 | //US fn.replace( QRegExp( "/" ), "_" ); | 304 | //US fn.replace( QRegExp( "/" ), "_" ); |
304 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 305 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
305 | //US QString lockName = fn + ".lock"; | 306 | //US QString lockName = fn + ".lock"; |
306 | KURL url(fn); | 307 | KURL url(fn); |
307 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 308 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
308 | 309 | ||
309 | QFile::remove( lockName ); | 310 | QFile::remove( lockName ); |
310 | QFile::remove( mLockUniqueName ); | 311 | QFile::remove( mLockUniqueName ); |
311 | addressBook()->emitAddressBookUnlocked(); | 312 | addressBook()->emitAddressBookUnlocked(); |
@@ -315,13 +316,13 @@ void ResourceQtopia::setFileName( const QString &fileName ) | |||
315 | { | 316 | { |
316 | mDirWatch.stopScan(); | 317 | mDirWatch.stopScan(); |
317 | mDirWatch.removeFile( mFileName ); | 318 | mDirWatch.removeFile( mFileName ); |
318 | 319 | ||
319 | mFileName = fileName; | 320 | mFileName = fileName; |
320 | 321 | ||
321 | mDirWatch.addFile( mFileName ); | 322 | mDirWatch.addFile( mFileName ); |
322 | mDirWatch.startScan(); | 323 | mDirWatch.startScan(); |
323 | 324 | ||
324 | //US simulate KDirWatch event | 325 | //US simulate KDirWatch event |
325 | //US fileChanged(); | 326 | //US fileChanged(); |
326 | } | 327 | } |
327 | 328 | ||
@@ -336,7 +337,7 @@ void ResourceQtopia::fileChanged() | |||
336 | // we are fully constructed | 337 | // we are fully constructed |
337 | if (!addressBook()) | 338 | if (!addressBook()) |
338 | return; | 339 | return; |
339 | 340 | ||
340 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 341 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); |
341 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 342 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
342 | load(); | 343 | load(); |