summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (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
@@ -48,9 +48,9 @@ $Id$
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;
@@ -68,5 +68,5 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
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}
@@ -139,5 +139,5 @@ bool ResourceSharpDTM::doOpen()
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
@@ -145,5 +145,5 @@ bool ResourceSharpDTM::doOpen()
145 } 145 }
146*/ 146*/
147 return true; 147 return true;
148} 148}
149 149
@@ -157,7 +157,9 @@ bool ResourceSharpDTM::load()
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());
@@ -165,31 +167,31 @@ bool ResourceSharpDTM::load()
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 {
@@ -199,5 +201,5 @@ bool ResourceSharpDTM::load()
199 } 201 }
200 } 202 }
201*/ 203
202 delete access; 204 delete access;
203 return true; 205 return true;
@@ -212,7 +214,7 @@ bool ResourceSharpDTM::save( Ticket *ticket )
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 );
@@ -228,5 +230,5 @@ bool ResourceSharpDTM::save( Ticket *ticket )
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 );
@@ -234,22 +236,22 @@ bool ResourceSharpDTM::save( Ticket *ticket )
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}
@@ -264,8 +266,8 @@ bool ResourceSharpDTM::lock( const QString &fileName )
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
@@ -274,6 +276,6 @@ bool ResourceSharpDTM::lock( const QString &fileName )
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() );
@@ -306,7 +308,7 @@ void ResourceSharpDTM::unlock( const QString &fileName )
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 );
@@ -318,5 +320,5 @@ void ResourceSharpDTM::setFileName( const QString &fileName )
318 mDirWatch.stopScan(); 320 mDirWatch.stopScan();
319 mDirWatch.removeFile( mFileName ); 321 mDirWatch.removeFile( mFileName );
320 322
321 mFileName = fileName; 323 mFileName = fileName;
322 324
@@ -337,5 +339,5 @@ void ResourceSharpDTM::fileChanged()
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 ) {