summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp2
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp39
2 files changed, 4 insertions, 37 deletions
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index 430c7b3..5eab1be 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -1,185 +1,185 @@
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//US 28//US
29#include "kglobal.h" 29#include "kglobal.h"
30 30
31 31
32#include "qtopiaconverter.h" 32#include "qtopiaconverter.h"
33 33
34#include <qpe/categories.h> 34#include <qpe/categories.h>
35#include <libkdepim/ksyncprofile.h> 35#include <libkdepim/ksyncprofile.h>
36//US #include <qpe/categoryselect.h> 36//US #include <qpe/categoryselect.h>
37 37
38 38
39using namespace KABC; 39using namespace KABC;
40 40
41QtopiaConverter::QtopiaConverter() : catDB(0) 41QtopiaConverter::QtopiaConverter() : catDB(0)
42{ 42{
43} 43}
44 44
45QtopiaConverter::~QtopiaConverter() 45QtopiaConverter::~QtopiaConverter()
46{ 46{
47 deinit(); 47 deinit();
48} 48}
49 49
50bool QtopiaConverter::init() 50bool QtopiaConverter::init()
51{ 51{
52 catDB = new Categories(); 52 catDB = new Categories();
53 53
54 if (!catDB) 54 if (!catDB)
55 return false; 55 return false;
56 56
57 catDB->load( categoryFileName() ); 57 catDB->load( categoryFileName() );
58 return true; 58 return true;
59} 59}
60 60
61void QtopiaConverter::deinit() 61void QtopiaConverter::deinit()
62{ 62{
63 if (catDB) 63 if (catDB)
64 { 64 {
65 delete catDB; 65 delete catDB;
66 catDB = 0; 66 catDB = 0;
67 } 67 }
68} 68}
69 69
70bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) 70bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr )
71{ 71{
72 // name 72 // name
73 addr.setFormattedName(contact.fileAs()); 73 addr.setFormattedName(contact.fileAs());
74 addr.setFamilyName( contact.lastName() ); 74 addr.setFamilyName( contact.lastName() );
75 addr.setGivenName( contact.firstName() ); 75 addr.setGivenName( contact.firstName() );
76 addr.setAdditionalName( contact.middleName() ); 76 addr.setAdditionalName( contact.middleName() );
77 addr.setPrefix( contact.nameTitle() ); 77 addr.setPrefix( contact.nameTitle() );
78 addr.setSuffix( contact.suffix() ); 78 addr.setSuffix( contact.suffix() );
79 79
80 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 80 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
81 QString exuid = contact.uid().toString(); 81 QString exuid = contact.uid().toString();
82 addr.setOriginalExternalUID( exuid ); 82 addr.setOriginalExternalUID( exuid );
83 int ente = exuid.find( "-0000"); 83 int ente = exuid.find( "-0000");
84 if ( exuid.left(1) == "{" ) 84 if ( exuid.left(1) == "{" )
85 exuid = exuid.mid(1); 85 exuid = exuid.mid(1);
86 if ( ente > -1 ) 86 if ( ente > -1 )
87 exuid = exuid.left( ente-1 ); 87 exuid = exuid.left( ente-1 );
88 addr.setExternalUID( exuid ); 88 addr.setExternalUID( exuid );
89 qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() ); 89 // qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() );
90 90
91 // email 91 // email
92 QStringList emails = contact.emailList(); 92 QStringList emails = contact.emailList();
93 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 93 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
94 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); 94 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
95 } 95 }
96 96
97 if (!contact.defaultEmail().isEmpty()) 97 if (!contact.defaultEmail().isEmpty())
98 addr.insertEmail(contact.defaultEmail(), true); 98 addr.insertEmail(contact.defaultEmail(), true);
99 99
100 // home 100 // home
101 if ((!contact.homeStreet().isEmpty()) || 101 if ((!contact.homeStreet().isEmpty()) ||
102 (!contact.homeCity().isEmpty()) || 102 (!contact.homeCity().isEmpty()) ||
103 (!contact.homeState().isEmpty()) || 103 (!contact.homeState().isEmpty()) ||
104 (!contact.homeZip().isEmpty()) || 104 (!contact.homeZip().isEmpty()) ||
105 (!contact.homeCountry().isEmpty())) 105 (!contact.homeCountry().isEmpty()))
106 { 106 {
107 Address homeaddress; 107 Address homeaddress;
108 homeaddress.setType(Address::Home); 108 homeaddress.setType(Address::Home);
109//US homeaddress.setPostOfficeBox( "" ); 109//US homeaddress.setPostOfficeBox( "" );
110//US homeaddress.setExtended( "" ); 110//US homeaddress.setExtended( "" );
111 homeaddress.setStreet( contact.homeStreet() ); 111 homeaddress.setStreet( contact.homeStreet() );
112 homeaddress.setLocality( contact.homeCity() ); 112 homeaddress.setLocality( contact.homeCity() );
113 homeaddress.setRegion( contact.homeState() ); 113 homeaddress.setRegion( contact.homeState() );
114 homeaddress.setPostalCode( contact.homeZip() ); 114 homeaddress.setPostalCode( contact.homeZip() );
115 homeaddress.setCountry( contact.homeCountry() ); 115 homeaddress.setCountry( contact.homeCountry() );
116 116
117 addr.insertAddress( homeaddress ); 117 addr.insertAddress( homeaddress );
118 } 118 }
119 119
120 if (!contact.homePhone().isEmpty()) 120 if (!contact.homePhone().isEmpty())
121 { 121 {
122 PhoneNumber homephone; 122 PhoneNumber homephone;
123 homephone.setType( PhoneNumber::Home ); 123 homephone.setType( PhoneNumber::Home );
124 homephone.setNumber( contact.homePhone() ); 124 homephone.setNumber( contact.homePhone() );
125 addr.insertPhoneNumber( homephone ); 125 addr.insertPhoneNumber( homephone );
126 } 126 }
127 127
128 if (!contact.homeFax().isEmpty()) 128 if (!contact.homeFax().isEmpty())
129 { 129 {
130 PhoneNumber homefax; 130 PhoneNumber homefax;
131 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); 131 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
132 homefax.setNumber( contact.homeFax() ); 132 homefax.setNumber( contact.homeFax() );
133 addr.insertPhoneNumber( homefax ); 133 addr.insertPhoneNumber( homefax );
134 } 134 }
135 135
136 if (!contact.homeMobile().isEmpty()) 136 if (!contact.homeMobile().isEmpty())
137 { 137 {
138 PhoneNumber homemobile; 138 PhoneNumber homemobile;
139 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); 139 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
140 homemobile.setNumber( contact.homeMobile() ); 140 homemobile.setNumber( contact.homeMobile() );
141 addr.insertPhoneNumber( homemobile ); 141 addr.insertPhoneNumber( homemobile );
142 } 142 }
143 143
144 addr.setUrl( contact.homeWebpage() ); 144 addr.setUrl( contact.homeWebpage() );
145 145
146 146
147 // business 147 // business
148 if ((!contact.businessStreet().isEmpty()) || 148 if ((!contact.businessStreet().isEmpty()) ||
149 (!contact.businessCity().isEmpty()) || 149 (!contact.businessCity().isEmpty()) ||
150 (!contact.businessState().isEmpty()) || 150 (!contact.businessState().isEmpty()) ||
151 (!contact.businessZip().isEmpty()) || 151 (!contact.businessZip().isEmpty()) ||
152 (!contact.businessCountry().isEmpty())) 152 (!contact.businessCountry().isEmpty()))
153 { 153 {
154 Address businessaddress; 154 Address businessaddress;
155 businessaddress.setType(Address::Work); 155 businessaddress.setType(Address::Work);
156//US businessaddress.setPostOfficeBox( "" ); 156//US businessaddress.setPostOfficeBox( "" );
157//US businessaddress.setExtended( "" ); 157//US businessaddress.setExtended( "" );
158 businessaddress.setStreet( contact.businessStreet() ); 158 businessaddress.setStreet( contact.businessStreet() );
159 businessaddress.setLocality( contact.businessCity() ); 159 businessaddress.setLocality( contact.businessCity() );
160 businessaddress.setRegion( contact.businessState() ); 160 businessaddress.setRegion( contact.businessState() );
161 businessaddress.setPostalCode( contact.businessZip() ); 161 businessaddress.setPostalCode( contact.businessZip() );
162 businessaddress.setCountry( contact.businessCountry() ); 162 businessaddress.setCountry( contact.businessCountry() );
163 163
164 addr.insertAddress( businessaddress ); 164 addr.insertAddress( businessaddress );
165 } 165 }
166 166
167 167
168 if (!contact.businessPhone().isEmpty()) 168 if (!contact.businessPhone().isEmpty())
169 { 169 {
170 PhoneNumber businessphone; 170 PhoneNumber businessphone;
171 businessphone.setType( PhoneNumber::Work ); 171 businessphone.setType( PhoneNumber::Work );
172 businessphone.setNumber( contact.businessPhone() ); 172 businessphone.setNumber( contact.businessPhone() );
173 addr.insertPhoneNumber( businessphone ); 173 addr.insertPhoneNumber( businessphone );
174 } 174 }
175 175
176 if (!contact.businessFax().isEmpty()) 176 if (!contact.businessFax().isEmpty())
177 { 177 {
178 PhoneNumber businessfax; 178 PhoneNumber businessfax;
179 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); 179 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
180 businessfax.setNumber( contact.businessFax() ); 180 businessfax.setNumber( contact.businessFax() );
181 addr.insertPhoneNumber( businessfax ); 181 addr.insertPhoneNumber( businessfax );
182 } 182 }
183 183
184 if (!contact.businessMobile().isEmpty()) 184 if (!contact.businessMobile().isEmpty())
185 { 185 {
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index adc7256..c013f52 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -136,288 +136,255 @@ bool ResourceSharpDTM::doOpen()
136 return false; 136 return false;
137 } 137 }
138 138
139 if (mConverter == 0) 139 if (mConverter == 0)
140 { 140 {
141 mConverter = new SharpDTMConverter(); 141 mConverter = new SharpDTMConverter();
142 bool res = mConverter->init(); 142 bool res = mConverter->init();
143 if ( !res ) 143 if ( !res )
144 { 144 {
145 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");
146 146
147 qDebug(msg); 147 qDebug(msg);
148 delete mAccess; 148 delete mAccess;
149 mAccess = 0; 149 mAccess = 0;
150 return false; 150 return false;
151 } 151 }
152 } 152 }
153 153
154 return true; 154 return true;
155} 155}
156 156
157void ResourceSharpDTM::doClose() 157void ResourceSharpDTM::doClose()
158{ 158{
159 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); 159 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
160 160
161 if(mAccess) 161 if(mAccess)
162 { 162 {
163 delete mAccess; 163 delete mAccess;
164 mAccess = 0; 164 mAccess = 0;
165 } 165 }
166 // it seems so, that deletion of access deletes backend as well 166 // it seems so, that deletion of access deletes backend as well
167 //delete backend; 167 //delete backend;
168 168
169 return; 169 return;
170} 170}
171 171
172bool ResourceSharpDTM::load() 172bool ResourceSharpDTM::load()
173{ 173{
174 qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); 174 qDebug("ResourceSharpDTM::load: %s", fileName().latin1());
175 175
176 bool res = false; 176 bool res = false;
177 177
178 CardId id; 178 CardId id;
179 179
180 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 180 for (bool res=mAccess->first(); res == true; res=mAccess->next())
181 { 181 {
182 id = mAccess->cardId(); 182 id = mAccess->cardId();
183 183
184 KABC::Addressee addressee; 184 KABC::Addressee addressee;
185 185
186 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 186 res = mConverter->sharpToAddressee( id, mAccess, addressee );
187 187
188 if ( !addressee.isEmpty() && res ) 188 if ( !addressee.isEmpty() && res )
189 { 189 {
190 addressee.setResource( this ); 190 addressee.setResource( this );
191 addressBook()->insertAddressee( addressee ); 191 addressBook()->insertAddressee( addressee );
192 } 192 }
193 } 193 }
194 194
195 return true; 195 return true;
196} 196}
197 197
198bool ResourceSharpDTM::save( Ticket *ticket ) 198bool ResourceSharpDTM::save( Ticket *ticket )
199{ 199{
200 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 200 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
201 201
202 mDirWatch.stopScan(); 202 mDirWatch.stopScan();
203 203
204 KABC::AddressBook::Iterator it; 204 KABC::AddressBook::Iterator it;
205 bool res; 205 bool res;
206 KABC::Addressee::List changedAddressees; 206 KABC::Addressee::List changedAddressees;
207 typedef QMap<int,QString> AddresseeMap; 207 typedef QMap<int,QString> AddresseeMap;
208 AddresseeMap map; 208 AddresseeMap map;
209 CardId id ; 209 CardId id ;
210 210
211 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 211 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
212 212
213 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 213 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
214 QString uid = (*it).originalExternalUID(); 214 QString uid = (*it).originalExternalUID();
215 bool res; 215 bool res;
216 if ( uid.isEmpty() ) 216 if ( uid.isEmpty() )
217 id = 0; 217 id = 0;
218 else 218 else
219 id = uid.toUInt(); 219 id = uid.toUInt();
220 KABC::Addressee addressee = (*it); 220 KABC::Addressee addressee = (*it);
221 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 221 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
222 res = mAccess->startEditCard(id); 222 res = mAccess->startEditCard(id);
223 if (res == true) 223 if (res == true)
224 { 224 {
225 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 225 res = mConverter->addresseeToSharp( (*it), mAccess, id );
226 if (res == true) 226 if (res == true)
227 { 227 {
228 res = mAccess->finishEditCard(&id); 228 res = mAccess->finishEditCard(&id);
229 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 229 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
230 //(*it).setExternalUID( QString::number( id ) ); 230 //(*it).setExternalUID( QString::number( id ) );
231 //(*it).setOriginalExternalUID( QString::number( id ) ); 231 //(*it).setOriginalExternalUID( QString::number( id ) );
232 map.insert(id,(*it).uid()); 232 map.insert(id,(*it).uid());
233
234#if 0
235 KABC::Addressee addressee;
236 res = mConverter->sharpToAddressee( id, mAccess, addressee );
237 addressee.setUid((*it).uid() );
238 (it*).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
239 res = mAccess->finishEditCard(&id);
240 //qDebug("2NEW id is %d", id);
241 addressee.setExternalUID( QString::number( id ) );
242 addressee.setOriginalExternalUID( QString::number( id ) );
243 changedAddressees.append( addressee );
244#endif
245
246 if (res == false) 233 if (res == false)
247 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 234 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
248 235
249 } 236 }
250 else 237 else
251 { 238 {
252 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 239 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
253 mAccess->cancelEditCard(); 240 mAccess->cancelEditCard();
254 } 241 }
255 } 242 }
256 243
257 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 244 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
258 res = mAccess->deleteCard(&id); 245 res = mAccess->deleteCard(&id);
259 if ( res ) 246 if ( !res )
260 qDebug("delete success ");
261 else
262 qDebug("delete error "); 247 qDebug("delete error ");
263 248
264 249
265 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 250 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
266 //changed 251 //changed
267 qDebug("changed ****");
268 res = mAccess->startEditCard(id); 252 res = mAccess->startEditCard(id);
269 if (res == true) 253 if (res == true)
270 { 254 {
271 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 255 res = mConverter->addresseeToSharp( (*it), mAccess, id );
272 if (res == true) 256 if (res == true)
273 { 257 {
274 res = mAccess->finishEditCard(&id); 258 res = mAccess->finishEditCard(&id);
275 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); 259 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
276 map.insert(id,(*it).uid()); 260 map.insert(id,(*it).uid());
277
278#if 0
279 KABC::Addressee addressee;
280 res = mConverter->sharpToAddressee( id, mAccess, addressee );
281 addressee.setUid((*it).uid() );
282 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
283 changedAddressees.append( addressee );
284 res = mAccess->finishEditCard(&id);
285#endif
286 if (res == false) 261 if (res == false)
287 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 262 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
288 263
289 } 264 }
290 else 265 else
291 { 266 {
292 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 267 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
293 mAccess->cancelEditCard(); 268 mAccess->cancelEditCard();
294 } 269 }
295 } 270 }
296 } 271 }
297 } 272 }
298 273
299 } 274 }
300 AddresseeMap::Iterator itam; 275 AddresseeMap::Iterator itam;
301 for ( res=mAccess->first(); res == true; res=mAccess->next()) 276 for ( res=mAccess->first(); res == true; res=mAccess->next())
302 { 277 {
303 id = mAccess->cardId(); 278 id = mAccess->cardId();
304 int idint = id; 279 int idint = id;
305 itam = map.find( idint ); 280 itam = map.find( idint );
306 if ( itam != map.end() ) { 281 if ( itam != map.end() ) {
307 KABC::Addressee addressee; 282 KABC::Addressee addressee;
308 qDebug("found change %d %s ", idint, itam.data().latin1());
309 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 283 res = mConverter->sharpToAddressee( id, mAccess, addressee );
310 284
311 if ( !addressee.isEmpty() && res ) 285 if ( !addressee.isEmpty() && res )
312 { 286 {
313 addressee.setResource( this ); 287 addressee.setResource( this );
314 addressee.setUid( itam.data() ); 288 addressee.setUid( itam.data() );
315 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 289 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
316 addressBook()->insertAddressee( addressee , false ); 290 addressBook()->insertAddressee( addressee , false );
317 } 291 }
318 } 292 }
319 } 293 }
320#if 0 294
321 KABC::Addressee::List::Iterator it2;
322 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) {
323 (*it2).computeCsum( "Sharp_DTM" );
324 qDebug("CSUM: %s ",(*it2).getCsum( "Sharp_DTM" ).latin1() );
325 addressBook()->insertAddressee((*it2));
326 }
327#endif
328 //US mAccess->save(); 295 //US mAccess->save();
329 296
330 mDirWatch.startScan(); 297 mDirWatch.startScan();
331 delete ticket; 298 delete ticket;
332 unlock( fileName() ); 299 unlock( fileName() );
333 300
334 return true; 301 return true;
335} 302}
336 303
337bool ResourceSharpDTM::lock( const QString &lockfileName ) 304bool ResourceSharpDTM::lock( const QString &lockfileName )
338{ 305{
339#ifdef ALLOW_LOCKING 306#ifdef ALLOW_LOCKING
340 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); 307 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1());
341 308
342 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; 309 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl;
343 310
344 QString fn = lockfileName; 311 QString fn = lockfileName;
345 312
346 KURL url(fn); 313 KURL url(fn);
347 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 314 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
348 315
349 kdDebug(5700) << "-- lock name: " << lockName << endl; 316 kdDebug(5700) << "-- lock name: " << lockName << endl;
350 317
351 if (QFile::exists( lockName )) 318 if (QFile::exists( lockName ))
352 { 319 {
353 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); 320 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
354 return false; 321 return false;
355 } 322 }
356 323
357 324
358 QString lockUniqueName; 325 QString lockUniqueName;
359 lockUniqueName = fn + KApplication::randomString( 8 ); 326 lockUniqueName = fn + KApplication::randomString( 8 );
360 327
361 url = lockUniqueName; 328 url = lockUniqueName;
362//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 329//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
363 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 330 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
364 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 331 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
365 332
366 // Create unique file 333 // Create unique file
367 QFile file( mLockUniqueName ); 334 QFile file( mLockUniqueName );
368 file.open( IO_WriteOnly ); 335 file.open( IO_WriteOnly );
369 file.close(); 336 file.close();
370 337
371 // Create lock file 338 // Create lock file
372 int result = 0; 339 int result = 0;
373#ifndef _WIN32_ 340#ifndef _WIN32_
374 result = ::link( QFile::encodeName( mLockUniqueName ), 341 result = ::link( QFile::encodeName( mLockUniqueName ),
375 QFile::encodeName( lockName ) ); 342 QFile::encodeName( lockName ) );
376#endif 343#endif
377 if ( result == 0 ) { 344 if ( result == 0 ) {
378 addressBook()->emitAddressBookLocked(); 345 addressBook()->emitAddressBookLocked();
379 return true; 346 return true;
380 } 347 }
381 348
382 // TODO: check stat 349 // TODO: check stat
383 350
384 return false; 351 return false;
385#else 352#else
386 return true; 353 return true;
387#endif 354#endif
388} 355}
389 356
390void ResourceSharpDTM::unlock( const QString &fileName ) 357void ResourceSharpDTM::unlock( const QString &fileName )
391{ 358{
392#ifdef ALLOW_LOCKING 359#ifdef ALLOW_LOCKING
393 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); 360 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1());
394 361
395 QString fn = fileName; 362 QString fn = fileName;
396 KURL url(fn); 363 KURL url(fn);
397 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 364 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
398 365
399 QFile::remove( lockName ); 366 QFile::remove( lockName );
400 QFile::remove( mLockUniqueName ); 367 QFile::remove( mLockUniqueName );
401 addressBook()->emitAddressBookUnlocked(); 368 addressBook()->emitAddressBookUnlocked();
402#endif 369#endif
403} 370}
404 371
405void ResourceSharpDTM::setFileName( const QString &newFileName ) 372void ResourceSharpDTM::setFileName( const QString &newFileName )
406{ 373{
407 mDirWatch.stopScan(); 374 mDirWatch.stopScan();
408 mDirWatch.removeFile( fileName() ); 375 mDirWatch.removeFile( fileName() );
409 376
410 Resource::setFileName( newFileName ); 377 Resource::setFileName( newFileName );
411 378
412 mDirWatch.addFile( fileName() ); 379 mDirWatch.addFile( fileName() );
413 mDirWatch.startScan(); 380 mDirWatch.startScan();
414 381
415} 382}
416 383
417void ResourceSharpDTM::fileChanged() 384void ResourceSharpDTM::fileChanged()
418{ 385{
419 // There is a small theoretical chance that KDirWatch calls us before 386 // There is a small theoretical chance that KDirWatch calls us before
420 // we are fully constructed 387 // we are fully constructed
421 if (!addressBook()) 388 if (!addressBook())
422 return; 389 return;
423 390