summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp95
-rw-r--r--kabc/plugins/sharpdtm/sharpdtmE.pro2
-rw-r--r--kabc/plugins/sharpdtm/sharpdtmconverter.cpp6
3 files changed, 100 insertions, 3 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 867bc07..bba5f9a 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,346 +1,437 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36//US #include <qtimer.h> 36//US #include <qtimer.h>
37 37
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <klocale.h> 41#include <klocale.h>
42//US #include <ksavefile.h> 42//US #include <ksavefile.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kmessagebox.h> 44#include <kmessagebox.h>
45 45
46#include <sl/slzdb.h> 46#include <sl/slzdb.h>
47 47
48#include <libkdepim/ksyncprofile.h>
48 49
49#include "resourcesharpdtmconfig.h" 50#include "resourcesharpdtmconfig.h"
50#include "resourcesharpdtm.h" 51#include "resourcesharpdtm.h"
51 52
52#include "syncprefwidget.h" 53#include "syncprefwidget.h"
53 54
54#include "stdaddressbook.h" 55#include "stdaddressbook.h"
55 56
56#include "sharpdtmconverter.h" 57#include "sharpdtmconverter.h"
57//#define ALLOW_LOCKING 58//#define ALLOW_LOCKING
58using namespace KABC; 59using namespace KABC;
59extern "C" 60extern "C"
60{ 61{
61 void *init_microkabc_sharpdtm() 62 void *init_microkabc_sharpdtm()
62 { 63 {
63 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); 64 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>();
64 } 65 }
65} 66}
66 67
67ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) 68ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable )
68 : Resource( config, syncable ), mConverter (0) 69 : Resource( config, syncable ), mConverter (0)
69{ 70{
70 // we can not choose the filename. Therefore use the default to display 71 // we can not choose the filename. Therefore use the default to display
71 72
72 QString fileName = SlZDataBase::addressbookFileName(); 73 QString fileName = SlZDataBase::addressbookFileName();
73 init( fileName ); 74 init( fileName );
74} 75}
75 76
76ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) 77ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable )
77 : Resource( 0, syncable ) 78 : Resource( 0, syncable )
78{ 79{
79 init( fileName ); 80 init( fileName );
80} 81}
81 82
82void ResourceSharpDTM::init( const QString &fileName ) 83void ResourceSharpDTM::init( const QString &fileName )
83{ 84{
84 85
85 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 86 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
86 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 87 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
87 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 88 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
88 89
89 setFileName( fileName ); 90 setFileName( fileName );
90} 91}
91 92
92ResourceSharpDTM::~ResourceSharpDTM() 93ResourceSharpDTM::~ResourceSharpDTM()
93{ 94{
94 if (mConverter != 0) 95 if (mConverter != 0)
95 delete mConverter; 96 delete mConverter;
96 97
97 if(mAccess != 0) 98 if(mAccess != 0)
98 delete mAccess; 99 delete mAccess;
99} 100}
100 101
101void ResourceSharpDTM::writeConfig( KConfig *config ) 102void ResourceSharpDTM::writeConfig( KConfig *config )
102{ 103{
103 Resource::writeConfig( config ); 104 Resource::writeConfig( config );
104} 105}
105 106
106Ticket *ResourceSharpDTM::requestSaveTicket() 107Ticket *ResourceSharpDTM::requestSaveTicket()
107{ 108{
108 109
109 110
110 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 111 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
111 112
112 if ( !addressBook() ) return 0; 113 if ( !addressBook() ) return 0;
113 114
114#ifdef ALLOW_LOCKING 115#ifdef ALLOW_LOCKING
115 if ( !lock( fileName() ) ) { 116 if ( !lock( fileName() ) ) {
116 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); 117 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file ");
117 return 0; 118 return 0;
118 } 119 }
119#endif 120#endif
120 return createTicket( this ); 121 return createTicket( this );
121} 122}
122 123
123 124
124bool ResourceSharpDTM::doOpen() 125bool ResourceSharpDTM::doOpen()
125{ 126{
126 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); 127 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1());
127 128
128 // the last parameter in the SlZDataBase constructor means "readonly" 129 // the last parameter in the SlZDataBase constructor means "readonly"
129 mAccess = new SlZDataBase(fileName(), 130 mAccess = new SlZDataBase(fileName(),
130 SlZDataBase::addressbookItems(), 131 SlZDataBase::addressbookItems(),
131 NULL, true); 132 NULL, true);
132 133
133 if ( !mAccess ) { 134 if ( !mAccess ) {
134 qDebug("Unable to load file() %s", fileName().latin1()); 135 qDebug("Unable to load file() %s", fileName().latin1());
135 return false; 136 return false;
136 } 137 }
137 138
138 if (mConverter == 0) 139 if (mConverter == 0)
139 { 140 {
140 mConverter = new SharpDTMConverter(); 141 mConverter = new SharpDTMConverter();
141 bool res = mConverter->init(); 142 bool res = mConverter->init();
142 if ( !res ) 143 if ( !res )
143 { 144 {
144 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); 145 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
145 146
146 qDebug(msg); 147 qDebug(msg);
147 delete mAccess; 148 delete mAccess;
148 mAccess = 0; 149 mAccess = 0;
149 return false; 150 return false;
150 } 151 }
151 } 152 }
152 153
153 return true; 154 return true;
154} 155}
155 156
156void ResourceSharpDTM::doClose() 157void ResourceSharpDTM::doClose()
157{ 158{
158 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); 159 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
159 160
160 if(mAccess) 161 if(mAccess)
161 { 162 {
162 delete mAccess; 163 delete mAccess;
163 mAccess = 0; 164 mAccess = 0;
164 } 165 }
165 // it seems so, that deletion of access deletes backend as well 166 // it seems so, that deletion of access deletes backend as well
166 //delete backend; 167 //delete backend;
167 168
168 return; 169 return;
169} 170}
170 171
171bool ResourceSharpDTM::load() 172bool ResourceSharpDTM::load()
172{ 173{
173 qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); 174 qDebug("ResourceSharpDTM::load: %s", fileName().latin1());
174 175
175 bool res = false; 176 bool res = false;
176 177
177 CardId id; 178 CardId id;
178 179
179 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 180 for (bool res=mAccess->first(); res == true; res=mAccess->next())
180 { 181 {
181 id = mAccess->cardId(); 182 id = mAccess->cardId();
182 183
183 KABC::Addressee addressee; 184 KABC::Addressee addressee;
184 185
185 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 186 res = mConverter->sharpToAddressee( id, mAccess, addressee );
186 187
187 if ( !addressee.isEmpty() && res ) 188 if ( !addressee.isEmpty() && res )
188 { 189 {
189 addressee.setResource( this ); 190 addressee.setResource( this );
190 addressBook()->insertAddressee( addressee ); 191 addressBook()->insertAddressee( addressee );
191 } 192 }
192 } 193 }
193 194
194 return true; 195 return true;
195} 196}
196 197
197bool ResourceSharpDTM::save( Ticket *ticket ) 198bool ResourceSharpDTM::save( Ticket *ticket )
198{ 199{
199 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 200 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
200 201
201 mDirWatch.stopScan(); 202 mDirWatch.stopScan();
202 203
203 KABC::AddressBook::Iterator it; 204 KABC::AddressBook::Iterator it;
204 bool res; 205 bool res;
206 KABC::Addressee::List changedAddressees;
205 207
206 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 208 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
209
210 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
211 QString uid = (*it).originalExternalUID();
212 CardId id ;
213 bool res;
214 if ( uid.isEmpty() )
215 id = 0;
216 else
217 id = uid.toUInt();
218 KABC::Addressee addressee = (*it);
219 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
220 res = mAccess->startEditCard(id);
221 if (res == true)
222 {
223 res = mConverter->addresseeToSharp( (*it), mAccess, id );
224 if (res == true)
225 {
226 KABC::Addressee addressee;
227 qDebug("1NEW id is %d", id);
228 res = mConverter->sharpToAddressee( id, mAccess, addressee );
229 addressee.setUid((*it).uid() );
230 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
231 changedAddressees.append( addressee );
232 res = mAccess->finishEditCard(&id);
233 qDebug("2NEW id is %d", id);
234
235 if (res == false)
236 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
237 else {
238 qDebug("added card success ");
239 }
240 }
241 else
242 {
243 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
244 mAccess->cancelEditCard();
245 }
246 }
247
248 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
249 res = mAccess->deleteCard(&id);
250 if ( res )
251 qDebug("delete success ");
252 else
253 qDebug("delete error ");
254
255
256 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
257 //changed
258 res = mAccess->startEditCard(id);
259 if (res == true)
260 {
261 res = mConverter->addresseeToSharp( (*it), mAccess, id );
262 if (res == true)
263 {
264 KABC::Addressee addressee;
265 res = mConverter->sharpToAddressee( id, mAccess, addressee );
266 addressee.setUid((*it).uid() );
267 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
268 changedAddressees.append( addressee );
269 res = mAccess->finishEditCard(&id);
270 if (res == false)
271 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
272 else {
273 qDebug("change card succes ");
274 }
275 }
276 else
277 {
278 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
279 mAccess->cancelEditCard();
280 }
281 }
282 }
283
284
285
286
287
288
289
290
291 }
292
293#if 0
294 // old code
207 CardId id = 0;// 0 means new card 295 CardId id = 0;// 0 means new card
208 KABC::Addressee addressee = (*it); 296 KABC::Addressee addressee = (*it);
209 297
210 res = mAccess->startEditCard(id); 298 res = mAccess->startEditCard(id);
211 if (res == true) 299 if (res == true)
212 { 300 {
213 res = mConverter->addresseeToSharp( *it, mAccess, id ); 301 res = mConverter->addresseeToSharp( *it, mAccess, id );
214 if (res == true) 302 if (res == true)
215 { 303 {
216 res = mAccess->finishEditCard(&id); 304 res = mAccess->finishEditCard(&id);
217 if (res == false) 305 if (res == false)
218 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 306 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
219 } 307 }
220 else 308 else
221 { 309 {
222 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 310 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
223 mAccess->cancelEditCard(); 311 mAccess->cancelEditCard();
224 } 312 }
225 } 313 }
226 else 314 else
227 { 315 {
228 qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); 316 qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1());
229 } 317 }
318#endif
230 319
231 } 320 }
232 321 KABC::Addressee::List::Iterator it2;
233//US mAccess->save(); 322 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
323 addressBook()->insertAddressee((*it2));
324 //US mAccess->save();
234 325
235 mDirWatch.startScan(); 326 mDirWatch.startScan();
236 delete ticket; 327 delete ticket;
237 unlock( fileName() ); 328 unlock( fileName() );
238 329
239 return true; 330 return true;
240} 331}
241 332
242bool ResourceSharpDTM::lock( const QString &lockfileName ) 333bool ResourceSharpDTM::lock( const QString &lockfileName )
243{ 334{
244#ifdef ALLOW_LOCKING 335#ifdef ALLOW_LOCKING
245 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); 336 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1());
246 337
247 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; 338 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl;
248 339
249 QString fn = lockfileName; 340 QString fn = lockfileName;
250 341
251 KURL url(fn); 342 KURL url(fn);
252 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 343 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
253 344
254 kdDebug(5700) << "-- lock name: " << lockName << endl; 345 kdDebug(5700) << "-- lock name: " << lockName << endl;
255 346
256 if (QFile::exists( lockName )) 347 if (QFile::exists( lockName ))
257 { 348 {
258 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); 349 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
259 return false; 350 return false;
260 } 351 }
261 352
262 353
263 QString lockUniqueName; 354 QString lockUniqueName;
264 lockUniqueName = fn + KApplication::randomString( 8 ); 355 lockUniqueName = fn + KApplication::randomString( 8 );
265 356
266 url = lockUniqueName; 357 url = lockUniqueName;
267//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 358//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
268 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 359 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
269 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 360 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
270 361
271 // Create unique file 362 // Create unique file
272 QFile file( mLockUniqueName ); 363 QFile file( mLockUniqueName );
273 file.open( IO_WriteOnly ); 364 file.open( IO_WriteOnly );
274 file.close(); 365 file.close();
275 366
276 // Create lock file 367 // Create lock file
277 int result = 0; 368 int result = 0;
278#ifndef _WIN32_ 369#ifndef _WIN32_
279 result = ::link( QFile::encodeName( mLockUniqueName ), 370 result = ::link( QFile::encodeName( mLockUniqueName ),
280 QFile::encodeName( lockName ) ); 371 QFile::encodeName( lockName ) );
281#endif 372#endif
282 if ( result == 0 ) { 373 if ( result == 0 ) {
283 addressBook()->emitAddressBookLocked(); 374 addressBook()->emitAddressBookLocked();
284 return true; 375 return true;
285 } 376 }
286 377
287 // TODO: check stat 378 // TODO: check stat
288 379
289 return false; 380 return false;
290#else 381#else
291 return true; 382 return true;
292#endif 383#endif
293} 384}
294 385
295void ResourceSharpDTM::unlock( const QString &fileName ) 386void ResourceSharpDTM::unlock( const QString &fileName )
296{ 387{
297#ifdef ALLOW_LOCKING 388#ifdef ALLOW_LOCKING
298 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); 389 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1());
299 390
300 QString fn = fileName; 391 QString fn = fileName;
301 KURL url(fn); 392 KURL url(fn);
302 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 393 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
303 394
304 QFile::remove( lockName ); 395 QFile::remove( lockName );
305 QFile::remove( mLockUniqueName ); 396 QFile::remove( mLockUniqueName );
306 addressBook()->emitAddressBookUnlocked(); 397 addressBook()->emitAddressBookUnlocked();
307#endif 398#endif
308} 399}
309 400
310void ResourceSharpDTM::setFileName( const QString &newFileName ) 401void ResourceSharpDTM::setFileName( const QString &newFileName )
311{ 402{
312 mDirWatch.stopScan(); 403 mDirWatch.stopScan();
313 mDirWatch.removeFile( fileName() ); 404 mDirWatch.removeFile( fileName() );
314 405
315 Resource::setFileName( newFileName ); 406 Resource::setFileName( newFileName );
316 407
317 mDirWatch.addFile( fileName() ); 408 mDirWatch.addFile( fileName() );
318 mDirWatch.startScan(); 409 mDirWatch.startScan();
319 410
320} 411}
321 412
322void ResourceSharpDTM::fileChanged() 413void ResourceSharpDTM::fileChanged()
323{ 414{
324 // There is a small theoretical chance that KDirWatch calls us before 415 // There is a small theoretical chance that KDirWatch calls us before
325 // we are fully constructed 416 // we are fully constructed
326 if (!addressBook()) 417 if (!addressBook())
327 return; 418 return;
328 419
329 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 420 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
330 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 421 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
331 load(); 422 load();
332 addressBook()->emitAddressBookChanged(); 423 addressBook()->emitAddressBookChanged();
333 } 424 }
334} 425}
335 426
336void ResourceSharpDTM::removeAddressee( const Addressee &addr ) 427void ResourceSharpDTM::removeAddressee( const Addressee &addr )
337{ 428{
338} 429}
339 430
340void ResourceSharpDTM::cleanUp() 431void ResourceSharpDTM::cleanUp()
341{ 432{
342 unlock( fileName() ); 433 unlock( fileName() );
343} 434}
344 435
345 436
346 437
diff --git a/kabc/plugins/sharpdtm/sharpdtmE.pro b/kabc/plugins/sharpdtm/sharpdtmE.pro
index f335729..b80a1da 100644
--- a/kabc/plugins/sharpdtm/sharpdtmE.pro
+++ b/kabc/plugins/sharpdtm/sharpdtmE.pro
@@ -1,36 +1,36 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3TARGET = microkabc_sharpdtm 3TARGET = microkabc_sharpdtm
4 4
5INCLUDEPATH += $(KDEPIMDIR)/kabc $(SHARPDTMSDK)/include $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include 5INCLUDEPATH += $(KDEPIMDIR) $(KDEPIMDIR)/kabc $(SHARPDTMSDK)/include $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include
6 6
7 7
8OBJECTS_DIR = obj/$(PLATFORM) 8OBJECTS_DIR = obj/$(PLATFORM)
9MOC_DIR = moc/$(PLATFORM) 9MOC_DIR = moc/$(PLATFORM)
10DESTDIR = $(QPEDIR)/lib 10DESTDIR = $(QPEDIR)/lib
11LIBS += -lmicrokde 11LIBS += -lmicrokde
12LIBS += -lmicrokabc 12LIBS += -lmicrokabc
13LIBS += -lmicrokdepim 13LIBS += -lmicrokdepim
14LIBS += -lmicroqtcompat 14LIBS += -lmicroqtcompat
15LIBS += -lmicrokcal 15LIBS += -lmicrokcal
16LIBS += -L$(QPEDIR)/lib 16LIBS += -L$(QPEDIR)/lib
17LIBS += -ljpeg 17LIBS += -ljpeg
18LIBS += -lqpe 18LIBS += -lqpe
19LIBS += -lqte 19LIBS += -lqte
20LIBS += -lzdtm 20LIBS += -lzdtm
21LIBS += -lsl 21LIBS += -lsl
22 22
23 23
24 24
25INTERFACES = \ 25INTERFACES = \
26 26
27HEADERS = \ 27HEADERS = \
28 resourcesharpdtm.h \ 28 resourcesharpdtm.h \
29 resourcesharpdtmconfig.h \ 29 resourcesharpdtmconfig.h \
30 sharpdtmconverter.h 30 sharpdtmconverter.h
31 31
32SOURCES = \ 32SOURCES = \
33 resourcesharpdtm.cpp \ 33 resourcesharpdtm.cpp \
34 resourcesharpdtmconfig.cpp \ 34 resourcesharpdtmconfig.cpp \
35 sharpdtmconverter.cpp 35 sharpdtmconverter.cpp
36 36
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
index 8f8334e..b065bf3 100644
--- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
+++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
@@ -1,199 +1,205 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include "kglobal.h" 28#include "kglobal.h"
29 29
30 30
31#include "sharpdtmconverter.h" 31#include "sharpdtmconverter.h"
32 32
33#include <sl/slcategories.h> 33#include <sl/slcategories.h>
34//US #include <qpe/categoryselect.h> 34//US #include <qpe/categoryselect.h>
35 35
36 36
37using namespace KABC; 37using namespace KABC;
38using namespace SlCategory; 38using namespace SlCategory;
39 39
40SharpDTMConverter::SharpDTMConverter() : catDB(0) 40SharpDTMConverter::SharpDTMConverter() : catDB(0)
41{ 41{
42} 42}
43 43
44SharpDTMConverter::~SharpDTMConverter() 44SharpDTMConverter::~SharpDTMConverter()
45{ 45{
46 deinit(); 46 deinit();
47} 47}
48 48
49bool SharpDTMConverter::init() 49bool SharpDTMConverter::init()
50{ 50{
51 catDB = new SlCategory::SlCategories(); 51 catDB = new SlCategory::SlCategories();
52 52
53 if (!catDB) 53 if (!catDB)
54 return false; 54 return false;
55 55
56// catDB->load( categoryFileName() ); 56// catDB->load( categoryFileName() );
57 return true; 57 return true;
58} 58}
59 59
60void SharpDTMConverter::deinit() 60void SharpDTMConverter::deinit()
61{ 61{
62 if (catDB) 62 if (catDB)
63 { 63 {
64 delete catDB; 64 delete catDB;
65 catDB = 0; 65 catDB = 0;
66 } 66 }
67} 67}
68 68
69bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr ) 69bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr )
70{ 70{
71 SlZDataBase* db = (SlZDataBase*)database; 71 SlZDataBase* db = (SlZDataBase*)database;
72
73 // for syncing: we need setting of the two fields
74 addr.setExternalUID( QString::number( contact ) );
75 addr.setOriginalExternalUID( QString::number( contact ) );
76
77
72 // name 78 // name
73 qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!"); 79 qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!");
74 addr.setFormattedName(db->readField(ZdbAdrs::FileAs)); 80 addr.setFormattedName(db->readField(ZdbAdrs::FileAs));
75 81
76 addr.setFamilyName( db->readField(ZdbAdrs::LastName) ); 82 addr.setFamilyName( db->readField(ZdbAdrs::LastName) );
77 addr.setGivenName( db->readField(ZdbAdrs::FirstName) ); 83 addr.setGivenName( db->readField(ZdbAdrs::FirstName) );
78 addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) ); 84 addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) );
79 addr.setPrefix( db->readField(ZdbAdrs::Title) ); 85 addr.setPrefix( db->readField(ZdbAdrs::Title) );
80 addr.setSuffix( db->readField(ZdbAdrs::Suffix) ); 86 addr.setSuffix( db->readField(ZdbAdrs::Suffix) );
81 87
82 88
83 // email 89 // email
84 QString emailstr = db->readField(ZdbAdrs::Emails); 90 QString emailstr = db->readField(ZdbAdrs::Emails);
85 qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1()); 91 qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1());
86 QStringList emails = QStringList::split(",", emailstr); 92 QStringList emails = QStringList::split(",", emailstr);
87 93
88 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 94 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
89 addr.insertEmail( *it, ((*it) == db->readField(ZdbAdrs::DefaultEmail)) ); 95 addr.insertEmail( *it, ((*it) == db->readField(ZdbAdrs::DefaultEmail)) );
90 } 96 }
91 97
92 if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty()) 98 if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty())
93 addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true); 99 addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true);
94 100
95 // home 101 // home
96 if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) || 102 if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) ||
97 (!db->readField(ZdbAdrs::HomeCity).isEmpty()) || 103 (!db->readField(ZdbAdrs::HomeCity).isEmpty()) ||
98 (!db->readField(ZdbAdrs::HomeState).isEmpty()) || 104 (!db->readField(ZdbAdrs::HomeState).isEmpty()) ||
99 (!db->readField(ZdbAdrs::HomeZip).isEmpty()) || 105 (!db->readField(ZdbAdrs::HomeZip).isEmpty()) ||
100 (!db->readField(ZdbAdrs::HomeCountry).isEmpty())) 106 (!db->readField(ZdbAdrs::HomeCountry).isEmpty()))
101 { 107 {
102 Address homeaddress; 108 Address homeaddress;
103 homeaddress.setType(Address::Home); 109 homeaddress.setType(Address::Home);
104//US homeaddress.setPostOfficeBox( "" ); 110//US homeaddress.setPostOfficeBox( "" );
105//US homeaddress.setExtended( "" ); 111//US homeaddress.setExtended( "" );
106 homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet) ); 112 homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet) );
107 homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) ); 113 homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) );
108 homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) ); 114 homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) );
109 homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) ); 115 homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) );
110 homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) ); 116 homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) );
111 117
112 addr.insertAddress( homeaddress ); 118 addr.insertAddress( homeaddress );
113 } 119 }
114 120
115 if (!db->readField(ZdbAdrs::HomePhone).isEmpty()) 121 if (!db->readField(ZdbAdrs::HomePhone).isEmpty())
116 { 122 {
117 PhoneNumber homephone; 123 PhoneNumber homephone;
118 homephone.setType( PhoneNumber::Home ); 124 homephone.setType( PhoneNumber::Home );
119 homephone.setNumber( db->readField(ZdbAdrs::HomePhone) ); 125 homephone.setNumber( db->readField(ZdbAdrs::HomePhone) );
120 addr.insertPhoneNumber( homephone ); 126 addr.insertPhoneNumber( homephone );
121 } 127 }
122 128
123 if (!db->readField(ZdbAdrs::HomeFax).isEmpty()) 129 if (!db->readField(ZdbAdrs::HomeFax).isEmpty())
124 { 130 {
125 PhoneNumber homefax; 131 PhoneNumber homefax;
126 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); 132 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
127 homefax.setNumber( db->readField(ZdbAdrs::HomeFax) ); 133 homefax.setNumber( db->readField(ZdbAdrs::HomeFax) );
128 addr.insertPhoneNumber( homefax ); 134 addr.insertPhoneNumber( homefax );
129 } 135 }
130 136
131 if (!db->readField(ZdbAdrs::HomeMobile).isEmpty()) 137 if (!db->readField(ZdbAdrs::HomeMobile).isEmpty())
132 { 138 {
133 PhoneNumber homemobile; 139 PhoneNumber homemobile;
134 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); 140 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
135 homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) ); 141 homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) );
136 addr.insertPhoneNumber( homemobile ); 142 addr.insertPhoneNumber( homemobile );
137 } 143 }
138 144
139 addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) ); 145 addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) );
140 146
141 147
142 // business 148 // business
143 if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) || 149 if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) ||
144 (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) || 150 (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) ||
145 (!db->readField(ZdbAdrs::BusinessState).isEmpty()) || 151 (!db->readField(ZdbAdrs::BusinessState).isEmpty()) ||
146 (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) || 152 (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) ||
147 (!db->readField(ZdbAdrs::BusinessCountry).isEmpty())) 153 (!db->readField(ZdbAdrs::BusinessCountry).isEmpty()))
148 { 154 {
149 Address businessaddress; 155 Address businessaddress;
150 businessaddress.setType(Address::Work); 156 businessaddress.setType(Address::Work);
151//US businessaddress.setPostOfficeBox( "" ); 157//US businessaddress.setPostOfficeBox( "" );
152//US businessaddress.setExtended( "" ); 158//US businessaddress.setExtended( "" );
153 businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet) ); 159 businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet) );
154 businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) ); 160 businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) );
155 businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) ); 161 businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) );
156 businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) ); 162 businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) );
157 businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) ); 163 businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) );
158 164
159 addr.insertAddress( businessaddress ); 165 addr.insertAddress( businessaddress );
160 } 166 }
161 167
162 168
163 if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty()) 169 if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty())
164 { 170 {
165 PhoneNumber businessphone; 171 PhoneNumber businessphone;
166 businessphone.setType( PhoneNumber::Work ); 172 businessphone.setType( PhoneNumber::Work );
167 businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) ); 173 businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) );
168 addr.insertPhoneNumber( businessphone ); 174 addr.insertPhoneNumber( businessphone );
169 } 175 }
170 176
171 if (!db->readField(ZdbAdrs::BusinessFax).isEmpty()) 177 if (!db->readField(ZdbAdrs::BusinessFax).isEmpty())
172 { 178 {
173 PhoneNumber businessfax; 179 PhoneNumber businessfax;
174 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); 180 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
175 businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) ); 181 businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) );
176 addr.insertPhoneNumber( businessfax ); 182 addr.insertPhoneNumber( businessfax );
177 } 183 }
178 184
179 if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty()) 185 if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty())
180 { 186 {
181 PhoneNumber businessmobile; 187 PhoneNumber businessmobile;
182 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); 188 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
183 businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) ); 189 businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) );
184 addr.insertPhoneNumber( businessmobile ); 190 addr.insertPhoneNumber( businessmobile );
185 } 191 }
186 192
187 if (!db->readField(ZdbAdrs::BusinessPager).isEmpty()) 193 if (!db->readField(ZdbAdrs::BusinessPager).isEmpty())
188 { 194 {
189 PhoneNumber businesspager; 195 PhoneNumber businesspager;
190 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); 196 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
191 businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) ); 197 businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) );
192 addr.insertPhoneNumber( businesspager ); 198 addr.insertPhoneNumber( businesspager );
193 } 199 }
194 200
195 addr.setRole( db->readField(ZdbAdrs::JobTitle) ); //? 201 addr.setRole( db->readField(ZdbAdrs::JobTitle) ); //?
196 addr.setOrganization( db->readField(ZdbAdrs::Company) ); 202 addr.setOrganization( db->readField(ZdbAdrs::Company) );
197 addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) ); 203 addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) );
198 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) ); 204 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) );
199 addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) ); 205 addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) );