summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
authorzautrix <zautrix>2004-09-20 00:12:42 (UTC)
committer zautrix <zautrix>2004-09-20 00:12:42 (UTC)
commitb01b669d88fa195261d29ecf73b1c69e608a5ebc (patch) (unidiff)
treec0e79d45242a764b49470d07a9c95be156c121cc /kabc/plugins
parent3da2cfeab2edbe64a17251662e56668fe143f7a3 (diff)
downloadkdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.zip
kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.gz
kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.bz2
more AB sync
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp2
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp79
2 files changed, 70 insertions, 11 deletions
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index de45e63..430c7b3 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -1,376 +1,376 @@
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 uid %s ",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 {
186 PhoneNumber businessmobile; 186 PhoneNumber businessmobile;
187 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); 187 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
188 businessmobile.setNumber( contact.businessMobile() ); 188 businessmobile.setNumber( contact.businessMobile() );
189 addr.insertPhoneNumber( businessmobile ); 189 addr.insertPhoneNumber( businessmobile );
190 } 190 }
191 191
192 if (!contact.businessPager().isEmpty()) 192 if (!contact.businessPager().isEmpty())
193 { 193 {
194 PhoneNumber businesspager; 194 PhoneNumber businesspager;
195 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); 195 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
196 businesspager.setNumber( contact.businessPager() ); 196 businesspager.setNumber( contact.businessPager() );
197 addr.insertPhoneNumber( businesspager ); 197 addr.insertPhoneNumber( businesspager );
198 } 198 }
199 199
200 addr.setRole( contact.jobTitle() ); //? 200 addr.setRole( contact.jobTitle() ); //?
201 addr.setOrganization( contact.company() ); 201 addr.setOrganization( contact.company() );
202 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); 202 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() );
203 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); 203 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() );
204 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); 204 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() );
205 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); 205 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() );
206 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); 206 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() );
207 207
208 //personal 208 //personal
209 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); 209 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
210 // qtopia uses this categorization: 210 // qtopia uses this categorization:
211 // enum GenderType { UnspecifiedGender=0, Male, Female }; 211 // enum GenderType { UnspecifiedGender=0, Male, Female };
212 if (contact.gender() == PimContact::Male) 212 if (contact.gender() == PimContact::Male)
213 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); 213 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male");
214 else if (contact.gender() == PimContact::Female) 214 else if (contact.gender() == PimContact::Female)
215 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); 215 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female");
216 216
217 if (contact.anniversary().isValid()) { 217 if (contact.anniversary().isValid()) {
218 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); 218 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate);
219//US 219//US
220// qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); 220// qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1());
221 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); 221 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
222 } 222 }
223 223
224 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); 224 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
225 if (contact.birthday().isValid()) 225 if (contact.birthday().isValid())
226 addr.setBirthday( contact.birthday() ); 226 addr.setBirthday( contact.birthday() );
227 227
228 addr.setNickName( contact.nickname() ); 228 addr.setNickName( contact.nickname() );
229 229
230 // others 230 // others
231 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. 231 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
232 QString notes = contact.notes(); 232 QString notes = contact.notes();
233 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; 233 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n";
234 234
235 addr.setNote( contact.notes() ); 235 addr.setNote( contact.notes() );
236 236
237 237
238 238
239//US QString groups() const { return find( Qtopia::Groups ); } 239//US QString groups() const { return find( Qtopia::Groups ); }
240//US QStringList groupList() const; 240//US QStringList groupList() const;
241 241
242 QArray<int> catArray = contact.categories(); 242 QArray<int> catArray = contact.categories();
243 QString cat; 243 QString cat;
244 244
245 for ( unsigned int i=0; i < catArray.size(); i++ ) { 245 for ( unsigned int i=0; i < catArray.size(); i++ ) {
246 cat = catDB->label("contact", catArray[i]); 246 cat = catDB->label("contact", catArray[i]);
247 if ( cat.isEmpty() ) 247 if ( cat.isEmpty() )
248 addr.insertCategory(QString::number(catArray[i])); 248 addr.insertCategory(QString::number(catArray[i]));
249 else 249 else
250 addr.insertCategory( cat ); 250 addr.insertCategory( cat );
251 } 251 }
252 252
253 return true; 253 return true;
254} 254}
255 255
256bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) 256bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact )
257{ 257{
258 258
259 259
260 260
261 // name 261 // name
262 contact.setLastName(addr.familyName()); 262 contact.setLastName(addr.familyName());
263 contact.setFirstName(addr.givenName()); 263 contact.setFirstName(addr.givenName());
264 contact.setMiddleName(addr.additionalName()); 264 contact.setMiddleName(addr.additionalName());
265 contact.setNameTitle(addr.prefix()); 265 contact.setNameTitle(addr.prefix());
266 contact.setSuffix(addr.suffix()); 266 contact.setSuffix(addr.suffix());
267 contact.setFileAs(); 267 contact.setFileAs();
268 268
269 269
270 // email 270 // email
271 QStringList emails = addr.emails(); 271 QStringList emails = addr.emails();
272 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 272 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
273 contact.insertEmail(*it); 273 contact.insertEmail(*it);
274 } 274 }
275 contact.setDefaultEmail( addr.preferredEmail() ); 275 contact.setDefaultEmail( addr.preferredEmail() );
276 276
277 277
278 // home 278 // home
279 const Address homeaddress = addr.address(Address::Home); 279 const Address homeaddress = addr.address(Address::Home);
280 if (!homeaddress.isEmpty()) { 280 if (!homeaddress.isEmpty()) {
281 contact.setHomeStreet(homeaddress.street()); 281 contact.setHomeStreet(homeaddress.street());
282 contact.setHomeCity(homeaddress.locality()); 282 contact.setHomeCity(homeaddress.locality());
283 contact.setHomeState(homeaddress.region()); 283 contact.setHomeState(homeaddress.region());
284 contact.setHomeZip(homeaddress.postalCode()); 284 contact.setHomeZip(homeaddress.postalCode());
285 contact.setHomeCountry(homeaddress.country()); 285 contact.setHomeCountry(homeaddress.country());
286 } 286 }
287 287
288 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); 288 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
289 if (!homephone.number().isEmpty()) 289 if (!homephone.number().isEmpty())
290 contact.setHomePhone(homephone.number()); 290 contact.setHomePhone(homephone.number());
291 291
292 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); 292 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
293 if (!homefax.number().isEmpty()) 293 if (!homefax.number().isEmpty())
294 contact.setHomeFax(homefax.number()); 294 contact.setHomeFax(homefax.number());
295 295
296 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); 296 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
297 if (!homemobile.number().isEmpty()) 297 if (!homemobile.number().isEmpty())
298 contact.setHomeMobile(homemobile.number()); 298 contact.setHomeMobile(homemobile.number());
299 299
300 contact.setHomeWebpage(addr.url().url()); 300 contact.setHomeWebpage(addr.url().url());
301 301
302 302
303 // business 303 // business
304 const Address businessaddress = addr.address(Address::Work); 304 const Address businessaddress = addr.address(Address::Work);
305 if (!businessaddress.isEmpty()) { 305 if (!businessaddress.isEmpty()) {
306 contact.setBusinessStreet(businessaddress.street()); 306 contact.setBusinessStreet(businessaddress.street());
307 contact.setBusinessCity(businessaddress.locality()); 307 contact.setBusinessCity(businessaddress.locality());
308 contact.setBusinessState(businessaddress.region()); 308 contact.setBusinessState(businessaddress.region());
309 contact.setBusinessZip(businessaddress.postalCode()); 309 contact.setBusinessZip(businessaddress.postalCode());
310 contact.setBusinessCountry(businessaddress.country()); 310 contact.setBusinessCountry(businessaddress.country());
311 } 311 }
312 312
313 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); 313 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work );
314 if (!businessphone.number().isEmpty()) 314 if (!businessphone.number().isEmpty())
315 contact.setBusinessPhone(businessphone.number()); 315 contact.setBusinessPhone(businessphone.number());
316 316
317 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); 317 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax );
318 if (!businessfax.number().isEmpty()) 318 if (!businessfax.number().isEmpty())
319 contact.setBusinessFax(businessfax.number()); 319 contact.setBusinessFax(businessfax.number());
320 320
321 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); 321 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell );
322 if (!businessmobile.number().isEmpty()) 322 if (!businessmobile.number().isEmpty())
323 contact.setBusinessMobile(businessmobile.number()); 323 contact.setBusinessMobile(businessmobile.number());
324 324
325 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); 325 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager );
326 if (!businesspager.number().isEmpty()) 326 if (!businesspager.number().isEmpty())
327 contact.setBusinessPager(businesspager.number()); 327 contact.setBusinessPager(businesspager.number());
328 328
329 contact.setJobTitle(addr.role()); 329 contact.setJobTitle(addr.role());
330 contact.setCompany(addr.organization()); 330 contact.setCompany(addr.organization());
331 331
332 contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); 332 contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" ));
333 contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); 333 contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" ));
334 contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); 334 contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" ));
335 contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); 335 contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" ));
336 contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); 336 contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" ));
337 337
338 //personal 338 //personal
339 contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); 339 contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" ));
340 // qtopia uses this categorization: 340 // qtopia uses this categorization:
341 // enum GenderType { UnspecifiedGender=0, Male, Female }; 341 // enum GenderType { UnspecifiedGender=0, Male, Female };
342 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); 342 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" );
343 if (gt = "male") 343 if (gt = "male")
344 contact.setGender(PimContact::Male); 344 contact.setGender(PimContact::Male);
345 else if (gt = "female") 345 else if (gt = "female")
346 contact.setGender(PimContact::Female); 346 contact.setGender(PimContact::Female);
347 else 347 else
348 contact.setGender(PimContact::UnspecifiedGender); 348 contact.setGender(PimContact::UnspecifiedGender);
349 349
350 350
351 QDate dt = KGlobal::locale()->readDate( 351 QDate dt = KGlobal::locale()->readDate(
352 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate 352 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
353 contact.setAnniversary( dt ); 353 contact.setAnniversary( dt );
354 354
355 contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); 355 contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" ));
356 356
357 contact.setBirthday(addr.birthday().date()); 357 contact.setBirthday(addr.birthday().date());
358 contact.setNickname(addr.nickName()); 358 contact.setNickname(addr.nickName());
359 359
360 // other 360 // other
361 contact.setNotes(addr.note()); 361 contact.setNotes(addr.note());
362 362
363//US QString groups() const { return find( Qtopia::Groups ); } 363//US QString groups() const { return find( Qtopia::Groups ); }
364//US QStringList groupList() const; 364//US QStringList groupList() const;
365 365
366 366
367 QStringList cats = addr.categories(); 367 QStringList cats = addr.categories();
368 368
369 QArray<int> iar; 369 QArray<int> iar;
370 if ( !cats.isEmpty() ) { 370 if ( !cats.isEmpty() ) {
371 QArray<int> iar = catDB->ids("contact", cats); 371 QArray<int> iar = catDB->ids("contact", cats);
372 contact.setCategories(iar); 372 contact.setCategories(iar);
373 } 373 }
374 374
375 return true; 375 return true;
376} 376}
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 935a1cf..1f90fcb 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -1,346 +1,405 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@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#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <qdir.h> 31#include <qdir.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qregexp.h> 34#include <qregexp.h>
35//US #include <qtimer.h> 35//US #include <qtimer.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45#include <qpe/pim/addressbookaccess.h> 45#include <qpe/pim/addressbookaccess.h>
46 46
47 47
48#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
49#include "stdaddressbook.h" 49#include "stdaddressbook.h"
50 50
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52#include "syncprefwidget.h" 52#include "syncprefwidget.h"
53 53
54#include "resourceqtopia.h" 54#include "resourceqtopia.h"
55#include <libkdepim/ksyncprofile.h> 55#include <libkdepim/ksyncprofile.h>
56#include <qpe/quuid.h> 56#include <qpe/quuid.h>
57 57
58using namespace KABC; 58using namespace KABC;
59extern "C" 59extern "C"
60{ 60{
61 void *init_microkabc_qtopia() 61 void *init_microkabc_qtopia()
62 { 62 {
63 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); 63 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>();
64 } 64 }
65} 65}
66 66
67ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) 67ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable )
68 : Resource( config, syncable ), mConverter (0) 68 : Resource( config, syncable ), mConverter (0)
69{ 69{
70 // we can not choose the filename. Therefore use the default to display 70 // we can not choose the filename. Therefore use the default to display
71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
72 init( fileName ); 72 init( fileName );
73} 73}
74 74
75ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) 75ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable )
76 : Resource( 0, syncable ) 76 : Resource( 0, syncable )
77{ 77{
78 init( fileName ); 78 init( fileName );
79} 79}
80 80
81void ResourceQtopia::init( const QString &fileName ) 81void ResourceQtopia::init( const QString &fileName )
82{ 82{
83 83
84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
87 87
88 setFileName( fileName ); 88 setFileName( fileName );
89} 89}
90 90
91ResourceQtopia::~ResourceQtopia() 91ResourceQtopia::~ResourceQtopia()
92{ 92{
93 if (mConverter != 0) 93 if (mConverter != 0)
94 delete mConverter; 94 delete mConverter;
95 95
96 if(mAccess != 0) 96 if(mAccess != 0)
97 delete mAccess; 97 delete mAccess;
98} 98}
99 99
100void ResourceQtopia::writeConfig( KConfig *config ) 100void ResourceQtopia::writeConfig( KConfig *config )
101{ 101{
102 Resource::writeConfig( config ); 102 Resource::writeConfig( config );
103} 103}
104 104
105Ticket *ResourceQtopia::requestSaveTicket() 105Ticket *ResourceQtopia::requestSaveTicket()
106{ 106{
107 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; 107 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl;
108 108
109 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); 109 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1());
110 110
111 if ( !addressBook() ) return 0; 111 if ( !addressBook() ) return 0;
112 112
113 if ( !lock( fileName() ) ) { 113 if ( !lock( fileName() ) ) {
114 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" 114 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
115 << fileName() << "'" << endl; 115 << fileName() << "'" << endl;
116 return 0; 116 return 0;
117 } 117 }
118 return createTicket( this ); 118 return createTicket( this );
119} 119}
120 120
121 121
122bool ResourceQtopia::doOpen() 122bool ResourceQtopia::doOpen()
123{ 123{
124 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); 124 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
125 125
126 mAccess = new AddressBookAccess(); 126 mAccess = new AddressBookAccess();
127 127
128 if ( !mAccess ) { 128 if ( !mAccess ) {
129 qDebug("Unable to load file() %s", fileName().latin1()); 129 qDebug("Unable to load file() %s", fileName().latin1());
130 return false; 130 return false;
131 } 131 }
132 132
133 133
134 if (mConverter == 0) 134 if (mConverter == 0)
135 { 135 {
136 mConverter = new QtopiaConverter(); 136 mConverter = new QtopiaConverter();
137 bool res = mConverter->init(); 137 bool res = mConverter->init();
138 if ( !res ) 138 if ( !res )
139 { 139 {
140 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); 140 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
141 qDebug(msg); 141 qDebug(msg);
142 delete mAccess; 142 delete mAccess;
143 mAccess = 0; 143 mAccess = 0;
144 return false; 144 return false;
145 } 145 }
146 } 146 }
147 147
148 return true; 148 return true;
149} 149}
150 150
151void ResourceQtopia::doClose() 151void ResourceQtopia::doClose()
152{ 152{
153 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 153 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
154 154
155 if(mAccess) 155 if(mAccess)
156 { 156 {
157 delete mAccess; 157 delete mAccess;
158 mAccess = 0; 158 mAccess = 0;
159 } 159 }
160 // it seems so, that deletion of access deletes backend as well 160 // it seems so, that deletion of access deletes backend as well
161 //delete backend; 161 //delete backend;
162 162
163 return; 163 return;
164} 164}
165 165
166bool ResourceQtopia::load() 166bool ResourceQtopia::load()
167{ 167{
168 qDebug("ResourceQtopia::load: %s", fileName().latin1()); 168 qDebug("ResourceQtopia::load: %s", fileName().latin1());
169 169
170 AddressBookIterator it(*mAccess); 170 AddressBookIterator it(*mAccess);
171 const PimContact* contact; 171 const PimContact* contact;
172 bool res; 172 bool res;
173 173
174 for (contact=it.toFirst(); it.current(); ++it) 174 for (contact=it.toFirst(); it.current(); ++it)
175 { 175 {
176 contact = it.current(); 176 contact = it.current();
177 177
178 KABC::Addressee addressee; 178 KABC::Addressee addressee;
179 179
180 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 180 res = mConverter->qtopiaToAddressee( (*contact), addressee );
181 181
182 if ( !addressee.isEmpty() && res ) 182 if ( !addressee.isEmpty() && res )
183 { 183 {
184 addressee.setResource( this ); 184 addressee.setResource( this );
185 addressBook()->insertAddressee( addressee ); 185 addressBook()->insertAddressee( addressee );
186 } 186 }
187 } 187 }
188 188
189 return true; 189 return true;
190} 190}
191 191
192bool ResourceQtopia::save( Ticket *ticket ) 192bool ResourceQtopia::save( Ticket *ticket )
193{ 193{
194 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 194 qDebug("ResourceQtopia::save: %s", fileName().latin1());
195 195
196 mDirWatch.stopScan(); 196 mDirWatch.stopScan();
197 197
198 KABC::AddressBook::Iterator it; 198 KABC::AddressBook::Iterator it;
199 bool res; 199 bool res;
200 200 KABC::Addressee::List changedAddressees;
201 QStringList addedUID;
201 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 202 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
202 //KABC::Addressee addressee = (*it); 203 //KABC::Addressee addressee = (*it);
204 // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() );
203 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 205 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
204 QUuid uid( (*it).originalExternalUID() ); 206 QUuid uid( (*it).originalExternalUID() );
205 bool ok; 207 bool ok;
206 PimContact c = mAccess->contactForId( uid, &ok ); 208 PimContact c = mAccess->contactForId( uid, &ok );
209 qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() );
207 res = mConverter->addresseeToQtopia( *it, c ); 210 res = mConverter->addresseeToQtopia( *it, c );
208 if (res == true) { 211 if (res == true) {
209 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 212 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
210 mAccess->addContact(c); 213 qDebug("skipping adding of contact ");
211 KABC::Addressee addressee; 214 continue;
212 mConverter->qtopiaToAddressee( c, addressee ); 215 PimContact e;
213 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 216 AddressBookAccess Access2;
214 addressBook()->insertAddressee( addressee ); 217 Access2.addContact(e);
218 const PimContact* contact;
219 bool res;
220 QString uid2, Ouid;
221 AddressBookIterator itt(Access2);
222 for (contact=itt.toFirst(); itt.current(); ++itt)
223 {
224 contact = itt.current();
225 QString exuid = contact->uid().toString();
226 Ouid =exuid;
227 int ente = exuid.find( "-0000");
228 if ( exuid.left(1) == "{" )
229 exuid = exuid.mid(1);
230 if ( ente > -1 )
231 exuid = exuid.left( ente-1 );
232 uid2 = exuid;
233 qDebug("trying find uid ");
234 if ( !addressBook()->containsExternalUid( uid2 ) ) {
235 qDebug("ab not contains ");
236 if ( !addedUID.contains( uid2 )) {
237 qDebug("list not contains ");
238 break;
239 }
240 }
241
242 }
243 if ( !itt.current()) {
244 qDebug("ERROR uid ");
245 continue;
246 }
247 else
248 qDebug("ADD uid detected ");
249
250
251 QUuid uid3( Ouid);
252 PimContact d = Access2.contactForId( uid3, &ok );
253 if ( ! ok ) {
254 qDebug("ADD: Error getting new uid ");
255 } else {
256 qDebug("NEW UID found ");
257 PimContact g = mAccess->contactForId( c.uid(), &ok );
258 KABC::Addressee addressee;
259 mConverter->qtopiaToAddressee( g, addressee );
260 addressee.setUid((*it).uid() );
261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
262 changedAddressees.append( addressee );
263 addedUID.append( uid2 );
264 }
265
215 266
216 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 267 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
268 qDebug("Remove contact ");
217 if ( ok ) 269 if ( ok )
218 mAccess->removeContact(c); 270 mAccess->removeContact(c);
219 else 271 else
220 qDebug("Error revoe contact from qtopia "); 272 qDebug("Error remove contact from qtopia ");
221 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 273 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
222 if ( ok ) { 274 if ( ok ) {
275 qDebug("Update contact ");
223 mAccess->updateContact(c); 276 mAccess->updateContact(c);
277 PimContact g = mAccess->contactForId( c.uid(), &ok );
224 KABC::Addressee addressee; 278 KABC::Addressee addressee;
225 mConverter->qtopiaToAddressee( c, addressee ); 279 mConverter->qtopiaToAddressee( g, addressee );
280 addressee.setUid((*it).uid() );
226 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); 281 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
227 addressBook()->insertAddressee( addressee ); 282 changedAddressees.append( addressee );
228 } 283 }
229 else 284 else
230 qDebug("Error update contact from qtopia "); 285 qDebug("Error update contact from qtopia ");
231 286
232 } 287 }
233 288
234 } else { 289 } else {
235 qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); 290 qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1());
236 } 291 }
237 } 292 }
238 } 293 }
239 294
240 // mAccess->addressBookUpdated(); 295 KABC::Addressee::List::Iterator it2;
296 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
297 addressBook()->insertAddressee((*it2));
298
299
241 300
242 mDirWatch.startScan(); 301 mDirWatch.startScan();
243 302
244 delete ticket; 303 delete ticket;
245 unlock( fileName() ); 304 unlock( fileName() );
246 305
247 return true; 306 return true;
248} 307}
249 308
250bool ResourceQtopia::lock( const QString &lockfileName ) 309bool ResourceQtopia::lock( const QString &lockfileName )
251{ 310{
252 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 311 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
253 312
254 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 313 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
255 314
256 QString fn = lockfileName; 315 QString fn = lockfileName;
257 316
258 KURL url(fn); 317 KURL url(fn);
259 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 318 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
260 319
261 kdDebug(5700) << "-- lock name: " << lockName << endl; 320 kdDebug(5700) << "-- lock name: " << lockName << endl;
262 321
263 if (QFile::exists( lockName )) 322 if (QFile::exists( lockName ))
264 { 323 {
265 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 324 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
266 return false; 325 return false;
267 } 326 }
268 327
269 QString lockUniqueName; 328 QString lockUniqueName;
270 lockUniqueName = fn + KApplication::randomString( 8 ); 329 lockUniqueName = fn + KApplication::randomString( 8 );
271 330
272 url = lockUniqueName; 331 url = lockUniqueName;
273//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 332//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
274 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 333 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
275 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 334 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
276 335
277 // Create unique file 336 // Create unique file
278 QFile file( mLockUniqueName ); 337 QFile file( mLockUniqueName );
279 file.open( IO_WriteOnly ); 338 file.open( IO_WriteOnly );
280 file.close(); 339 file.close();
281 340
282 // Create lock file 341 // Create lock file
283 int result = 0; 342 int result = 0;
284#ifndef _WIN32_ 343#ifndef _WIN32_
285 result = ::link( QFile::encodeName( mLockUniqueName ), 344 result = ::link( QFile::encodeName( mLockUniqueName ),
286 QFile::encodeName( lockName ) ); 345 QFile::encodeName( lockName ) );
287#endif 346#endif
288 if ( result == 0 ) { 347 if ( result == 0 ) {
289 addressBook()->emitAddressBookLocked(); 348 addressBook()->emitAddressBookLocked();
290 return true; 349 return true;
291 } 350 }
292 351
293 // TODO: check stat 352 // TODO: check stat
294 353
295 return false; 354 return false;
296} 355}
297 356
298void ResourceQtopia::unlock( const QString &fileName ) 357void ResourceQtopia::unlock( const QString &fileName )
299{ 358{
300 qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); 359 qDebug("ResourceQtopia::unlock() %s", fileName.latin1());
301 360
302 QString fn = fileName; 361 QString fn = fileName;
303 KURL url(fn); 362 KURL url(fn);
304 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 363 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
305 364
306 QFile::remove( lockName ); 365 QFile::remove( lockName );
307 QFile::remove( mLockUniqueName ); 366 QFile::remove( mLockUniqueName );
308 addressBook()->emitAddressBookUnlocked(); 367 addressBook()->emitAddressBookUnlocked();
309} 368}
310 369
311void ResourceQtopia::setFileName( const QString &newFileName ) 370void ResourceQtopia::setFileName( const QString &newFileName )
312{ 371{
313 mDirWatch.stopScan(); 372 mDirWatch.stopScan();
314 mDirWatch.removeFile( fileName() ); 373 mDirWatch.removeFile( fileName() );
315 374
316 Resource::setFileName( newFileName ); 375 Resource::setFileName( newFileName );
317 376
318 mDirWatch.addFile( fileName() ); 377 mDirWatch.addFile( fileName() );
319 mDirWatch.startScan(); 378 mDirWatch.startScan();
320} 379}
321 380
322 381
323void ResourceQtopia::fileChanged() 382void ResourceQtopia::fileChanged()
324{ 383{
325 // There is a small theoretical chance that KDirWatch calls us before 384 // There is a small theoretical chance that KDirWatch calls us before
326 // we are fully constructed 385 // we are fully constructed
327 if (!addressBook()) 386 if (!addressBook())
328 return; 387 return;
329 388
330 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 389 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
331 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 390 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
332 load(); 391 load();
333 addressBook()->emitAddressBookChanged(); 392 addressBook()->emitAddressBookChanged();
334 } 393 }
335} 394}
336 395
337void ResourceQtopia::removeAddressee( const Addressee &addr ) 396void ResourceQtopia::removeAddressee( const Addressee &addr )
338{ 397{
339} 398}
340 399
341void ResourceQtopia::cleanUp() 400void ResourceQtopia::cleanUp()
342{ 401{
343 unlock( fileName() ); 402 unlock( fileName() );
344} 403}
345 404
346//US #include "resourceqtopia.moc" 405//US #include "resourceqtopia.moc"