summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
Unidiff
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp67
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
@@ -57,25 +57,25 @@ extern "C"
57{ 57{
58 void *init_microkabc_qtopia() 58 void *init_microkabc_qtopia()
59 { 59 {
60 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); 60 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>();
61 } 61 }
62} 62}
63 63
64ResourceQtopia::ResourceQtopia( const KConfig *config ) 64ResourceQtopia::ResourceQtopia( const KConfig *config )
65 : Resource( config ), mConverter (0) 65 : Resource( config ), mConverter (0)
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
73ResourceQtopia::ResourceQtopia( const QString &fileName ) 73ResourceQtopia::ResourceQtopia( const QString &fileName )
74 : Resource( 0 ) 74 : Resource( 0 )
75{ 75{
76// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 76// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
77 init( fileName ); 77 init( fileName );
78} 78}
79 79
80void ResourceQtopia::init( const QString &fileName ) 80void ResourceQtopia::init( const QString &fileName )
81{ 81{
@@ -128,160 +128,161 @@ bool ResourceQtopia::doOpen()
128 return ok; 128 return ok;
129 } else { 129 } else {
130 if ( !file.open( IO_ReadWrite ) ) 130 if ( !file.open( IO_ReadWrite ) )
131 return false; 131 return false;
132 132
133 if ( file.size() == 0 ) { 133 if ( file.size() == 0 ) {
134 file.close(); 134 file.close();
135 return true; 135 return true;
136 } 136 }
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
149void ResourceQtopia::doClose() 149void ResourceQtopia::doClose()
150{ 150{
151} 151}
152 152
153bool ResourceQtopia::load() 153bool ResourceQtopia::load()
154{ 154{
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 ) {
162 qDebug("Unable to load file() %s", mFileName.latin1()); 162 qDebug("Unable to load file() %s", mFileName.latin1());
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 {
170 mConverter = new QtopiaConverter(); 170 mConverter = new QtopiaConverter();
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 );
195 addressBook()->insertAddressee( addressee ); 196 addressBook()->insertAddressee( addressee );
196 } 197 }
197 } 198 }
198 } 199 }
199 200
200 delete access; 201 delete access;
201 return true; 202 return true;
202} 203}
203 204
204bool ResourceQtopia::save( Ticket *ticket ) 205bool ResourceQtopia::save( Ticket *ticket )
205{ 206{
206/*US 207/*US
207// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 208// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
208 kdDebug(5700) << "ResourceQtopia::save()" << endl; 209 kdDebug(5700) << "ResourceQtopia::save()" << endl;
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
218 KSaveFile saveFile( mFileName ); 219 KSaveFile saveFile( mFileName );
219 bool ok = false; 220 bool ok = false;
220 if ( saveFile.status() == 0 && saveFile.file() ) 221 if ( saveFile.status() == 0 && saveFile.file() )
221 { 222 {
222 mFormat->saveAll( addressBook(), this, saveFile.file() ); 223 mFormat->saveAll( addressBook(), this, saveFile.file() );
223 ok = saveFile.close(); 224 ok = saveFile.close();
224 } 225 }
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
255bool ResourceQtopia::lock( const QString &fileName ) 256bool ResourceQtopia::lock( const QString &fileName )
256{ 257{
257 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 258 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
258 259
259 QString fn = fileName; 260 QString fn = fileName;
260 261
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;
279 280
280 // Create unique file 281 // Create unique file
281 QFile file( mLockUniqueName ); 282 QFile file( mLockUniqueName );
282 file.open( IO_WriteOnly ); 283 file.open( IO_WriteOnly );
283 file.close(); 284 file.close();
284 285
285 // Create lock file 286 // Create lock file
286 int result = ::link( QFile::encodeName( mLockUniqueName ), 287 int result = ::link( QFile::encodeName( mLockUniqueName ),
287 QFile::encodeName( lockName ) ); 288 QFile::encodeName( lockName ) );
@@ -294,58 +295,58 @@ bool ResourceQtopia::lock( const QString &fileName )
294 // TODO: check stat 295 // TODO: check stat
295 296
296 return false; 297 return false;
297} 298}
298 299
299void ResourceQtopia::unlock( const QString &fileName ) 300void ResourceQtopia::unlock( const QString &fileName )
300{ 301{
301 QString fn = fileName; 302 QString fn = fileName;
302//US change the implementation how the lockfilename is getting created 303//US change the implementation how the lockfilename is getting created
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();
312} 313}
313 314
314void ResourceQtopia::setFileName( const QString &fileName ) 315void 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
328QString ResourceQtopia::fileName() const 329QString ResourceQtopia::fileName() const
329{ 330{
330 return mFileName; 331 return mFileName;
331} 332}
332 333
333void ResourceQtopia::fileChanged() 334void ResourceQtopia::fileChanged()
334{ 335{
335 // There is a small theoretical chance that KDirWatch calls us before 336 // There is a small theoretical chance that KDirWatch calls us before
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();
343 addressBook()->emitAddressBookChanged(); 344 addressBook()->emitAddressBookChanged();
344 } 345 }
345} 346}
346 347
347void ResourceQtopia::removeAddressee( const Addressee &addr ) 348void ResourceQtopia::removeAddressee( const Addressee &addr )
348{ 349{
349} 350}
350 351
351void ResourceQtopia::cleanUp() 352void ResourceQtopia::cleanUp()