summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
Unidiff
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp90
1 files changed, 46 insertions, 44 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 347d51c..31b99ca 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -47,11 +47,11 @@ $Id$
47 47
48 48
49#include "resourcesharpdtmconfig.h" 49#include "resourcesharpdtmconfig.h"
50#include "stdaddressbook.h" 50#include "resourcesharpdtm.h"
51 51
52//#include "qtopiaconverter.h" 52#include "stdaddressbook.h"
53 53
54#include "resourcesharpdtm.h" 54#include "sharpdtmconverter.h"
55 55
56using namespace KABC; 56using namespace KABC;
57extern "C" 57extern "C"
@@ -67,7 +67,7 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
67{ 67{
68 // we can not choose the filename. Therefore use the default to display 68 // we can not choose the filename. Therefore use the default to display
69 69
70 QString fileName = SlZDataBase::addressbookFileName(); 70 QString fileName = SlZDataBase::addressbookFileName();
71 init( fileName ); 71 init( fileName );
72} 72}
73 73
@@ -138,13 +138,13 @@ bool ResourceSharpDTM::doOpen()
138 138
139//US bool ok = mFormat->checkFormat( &file ); 139//US bool ok = mFormat->checkFormat( &file );
140 bool ok = true; 140 bool ok = true;
141 141
142 file.close(); 142 file.close();
143 143
144 return ok; 144 return ok;
145 } 145 }
146*/ 146*/
147 return true; 147 return true;
148} 148}
149 149
150void ResourceSharpDTM::doClose() 150void ResourceSharpDTM::doClose()
@@ -156,41 +156,43 @@ bool ResourceSharpDTM::load()
156 kdDebug(5700) << "ResourcSharpDTM::load(): '" << mFileName << "'" << endl; 156 kdDebug(5700) << "ResourcSharpDTM::load(): '" << mFileName << "'" << endl;
157 157
158// qDebug("ResourceSharpDTM::load: Try to load file() %s", mFileName.latin1()); 158// qDebug("ResourceSharpDTM::load: Try to load file() %s", mFileName.latin1());
159 159
160 // the last parameter in the SlZDataBase constructor means "readonly"
160 SlZDataBase* access = new SlZDataBase(mFileName, 161 SlZDataBase* access = new SlZDataBase(mFileName,
161 SlZDataBase::addressbookItems()); 162 SlZDataBase::addressbookItems(),
163 NULL, true);
162 if ( !access ) { 164 if ( !access ) {
163 qDebug("Unable to load file() %s", mFileName.latin1()); 165 qDebug("Unable to load file() %s", mFileName.latin1());
164 addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); 166 addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) );
165 return false; 167 return false;
166 } 168 }
167 169
168 bool res = false; 170 bool res = false;
169 if (mConverter == 0) 171 if (mConverter == 0)
170 { 172 {
171// mConverter = new QtopiaConverter(); 173 mConverter = new SharpDTMConverter();
172// res = mConverter->init(); 174 res = mConverter->init();
173 res = true;
174 if ( !res ) 175 if ( !res )
175 { 176 {
176 qDebug("Unable to initialize qtopia converter. Most likely a problem with the category file"); 177 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
177 addressBook()->error( i18n( "Unable to initialize qtopia converter. Most likely a problem with the category file" ) ); 178
179 qDebug(msg);
180 addressBook()->error( i18n( msg ) );
178 delete access; 181 delete access;
179 return false; 182 return false;
180 } 183 }
181 } 184 }
182 /* 185
183 { //create a new scope 186 { //create a new scope
184 AddressBookIterator it(*access); 187 CardId id;
185 const PimContact* contact; 188
186 189 for (bool res=access->first(); res == true; res=access->next()) {
187 for (contact=it.toFirst(); it.current(); ++it) { 190 id = access->cardId();
188 contact = it.current(); 191
189
190 KABC::Addressee addressee; 192 KABC::Addressee addressee;
191 193
192 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 194 res = mConverter->sharpToAddressee( id, access, addressee );
193 195
194 if ( !addressee.isEmpty() && res ) 196 if ( !addressee.isEmpty() && res )
195 { 197 {
196 addressee.setResource( this ); 198 addressee.setResource( this );
@@ -198,7 +200,7 @@ bool ResourceSharpDTM::load()
198 } 200 }
199 } 201 }
200 } 202 }
201*/ 203
202 delete access; 204 delete access;
203 return true; 205 return true;
204} 206}
@@ -211,9 +213,9 @@ bool ResourceSharpDTM::save( Ticket *ticket )
211 213
212 // create backup file 214 // create backup file
213 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 215 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
214 216
215/*US we use a simpler method to create a backupfile 217/*US we use a simpler method to create a backupfile
216 218
217 (void) KSaveFile::backupFile( mFileName, QString::null 219 (void) KSaveFile::backupFile( mFileName, QString::null
218 ,extension ); 220 ,extension );
219 221
@@ -227,30 +229,30 @@ bool ResourceSharpDTM::save( Ticket *ticket )
227*/ 229*/
228 230
229/*US 231/*US
230//US ToDo: write backupfile 232//US ToDo: write backupfile
231 QFile info; 233 QFile info;
232 info.setName( mFileName ); 234 info.setName( mFileName );
233 bool ok = info.open( IO_WriteOnly ); 235 bool ok = info.open( IO_WriteOnly );
234 if ( ok ) { 236 if ( ok ) {
235//US mFormat->saveAll( addressBook(), this, &info ); 237//US mFormat->saveAll( addressBook(), this, &info );
236 238
237 info.close(); 239 info.close();
238 ok = true; 240 ok = true;
239 } 241 }
240 else { 242 else {
241 243
242 } 244 }
243 245
244 if ( !ok ) 246 if ( !ok )
245 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 247 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
246 248
247 delete ticket; 249 delete ticket;
248 unlock( mFileName ); 250 unlock( mFileName );
249 251
250 return ok; 252 return ok;
251 253
252 qDebug("ResourceQtopia::save has to be changed"); 254 qDebug("ResourceQtopia::save has to be changed");
253*/ 255*/
254 return true; 256 return true;
255} 257}
256 258
@@ -263,18 +265,18 @@ bool ResourceSharpDTM::lock( const QString &fileName )
263//US change the implementation how the lockfilename is getting created 265//US change the implementation how the lockfilename is getting created
264//US fn.replace( QRegExp("/"), "_" ); 266//US fn.replace( QRegExp("/"), "_" );
265//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 267//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
266 268
267 KURL url(fn); 269 KURL url(fn);
268 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 270 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
269 271
270 kdDebug(5700) << "-- lock name: " << lockName << endl; 272 kdDebug(5700) << "-- lock name: " << lockName << endl;
271 273
272 if (QFile::exists( lockName )) return false; 274 if (QFile::exists( lockName )) return false;
273 275
274 QString lockUniqueName; 276 QString lockUniqueName;
275 lockUniqueName = fn + KApplication::randomString( 8 ); 277 lockUniqueName = fn + KApplication::randomString( 8 );
276 278
277 url = lockUniqueName; 279 url = lockUniqueName;
278//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 280//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
279 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 281 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
280 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 282 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
@@ -305,9 +307,9 @@ void ResourceSharpDTM::unlock( const QString &fileName )
305//US fn.replace( QRegExp( "/" ), "_" ); 307//US fn.replace( QRegExp( "/" ), "_" );
306//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 308//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
307//US QString lockName = fn + ".lock"; 309//US QString lockName = fn + ".lock";
308 KURL url(fn); 310 KURL url(fn);
309 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 311 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
310 312
311 QFile::remove( lockName ); 313 QFile::remove( lockName );
312 QFile::remove( mLockUniqueName ); 314 QFile::remove( mLockUniqueName );
313 addressBook()->emitAddressBookUnlocked(); 315 addressBook()->emitAddressBookUnlocked();
@@ -317,7 +319,7 @@ void ResourceSharpDTM::setFileName( const QString &fileName )
317{ 319{
318 mDirWatch.stopScan(); 320 mDirWatch.stopScan();
319 mDirWatch.removeFile( mFileName ); 321 mDirWatch.removeFile( mFileName );
320 322
321 mFileName = fileName; 323 mFileName = fileName;
322 324
323 mDirWatch.addFile( mFileName ); 325 mDirWatch.addFile( mFileName );
@@ -336,7 +338,7 @@ void ResourceSharpDTM::fileChanged()
336 // we are fully constructed 338 // we are fully constructed
337 if (!addressBook()) 339 if (!addressBook())
338 return; 340 return;
339 341
340 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); 342 QString text( i18n( "Sharp DTM 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 ) { 343 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
342 load(); 344 load();