summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-07-09 08:05:25 (UTC)
committer ulf69 <ulf69>2004-07-09 08:05:25 (UTC)
commit259a7a50e4f8138cedfc2004fbde3b37cedcc49f (patch) (unidiff)
treedfd2e89f169ba65ffd250f9b52f8f4efcd62d8b3
parentd91c533ffc42d7bf48fa1326754894b2c30b6831 (diff)
downloadkdepimpi-259a7a50e4f8138cedfc2004fbde3b37cedcc49f.zip
kdepimpi-259a7a50e4f8138cedfc2004fbde3b37cedcc49f.tar.gz
kdepimpi-259a7a50e4f8138cedfc2004fbde3b37cedcc49f.tar.bz2
support for export of categories und supression of empty fields
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/converter/opie/opieconverter.cpp105
-rw-r--r--kabc/converter/opie/opieconverter.h11
-rw-r--r--kaddressbook/xxport/opie/opie_xxport.cpp16
-rw-r--r--kaddressbook/xxport/opie/opie_xxportE.pro3
4 files changed, 96 insertions, 39 deletions
diff --git a/kabc/converter/opie/opieconverter.cpp b/kabc/converter/opie/opieconverter.cpp
index d785fbc..b4e9f1c 100644
--- a/kabc/converter/opie/opieconverter.cpp
+++ b/kabc/converter/opie/opieconverter.cpp
@@ -1,338 +1,375 @@
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 "opieconverter.h" 32#include "opieconverter.h"
33 33
34#include <qpe/categories.h> 34#include <qpe/categories.h>
35#include <qpe/categoryselect.h>
35 36
36 37
37using namespace KABC; 38using namespace KABC;
38 39
39OpieConverter::OpieConverter() 40OpieConverter::OpieConverter() : catDB(0)
40{ 41{
41} 42}
42 43
43OpieConverter::~OpieConverter() 44OpieConverter::~OpieConverter()
44{ 45{
46 deinit();
47}
48
49bool OpieConverter::init()
50{
51 catDB = new Categories();
52 if (catDB)
53 {
54 catDB->load( categoryFileName() );
55 return true;
56 }
57 else
58 {
59 return false;
60 }
61
62}
63
64void OpieConverter::deinit()
65{
66 if (catDB)
67 {
68 delete catDB;
69 catDB = 0;
70 }
45} 71}
46 72
47bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr ) 73bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
48{ 74{
49 // name 75 // name
50 addr.setFormattedName(contact.fileAs()); 76 addr.setFormattedName(contact.fileAs());
51 addr.setFamilyName( contact.lastName() ); 77 addr.setFamilyName( contact.lastName() );
52 addr.setGivenName( contact.firstName() ); 78 addr.setGivenName( contact.firstName() );
53 addr.setAdditionalName( contact.middleName() ); 79 addr.setAdditionalName( contact.middleName() );
54 addr.setPrefix( contact.title() ); 80 addr.setPrefix( contact.title() );
55 addr.setSuffix( contact.suffix() ); 81 addr.setSuffix( contact.suffix() );
56 82
57 83
58 // email 84 // email
59 QStringList emails = contact.emailList(); 85 QStringList emails = contact.emailList();
60 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 86 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
61 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); 87 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
62 } 88 }
63 89
64 addr.insertEmail(contact.defaultEmail(), true); 90 if (!contact.defaultEmail().isEmpty())
91 addr.insertEmail(contact.defaultEmail(), true);
65 92
66 // home 93 // home
67 Address homeaddress; 94 if ((!contact.homeStreet().isEmpty()) ||
68 homeaddress.setType(Address::Home); 95 (!contact.homeCity().isEmpty()) ||
96 (!contact.homeState().isEmpty()) ||
97 (!contact.homeZip().isEmpty()) ||
98 (!contact.homeCountry().isEmpty()))
99 {
100 Address homeaddress;
101 homeaddress.setType(Address::Home);
69//US homeaddress.setPostOfficeBox( "" ); 102//US homeaddress.setPostOfficeBox( "" );
70//US homeaddress.setExtended( "" ); 103//US homeaddress.setExtended( "" );
71 homeaddress.setStreet( contact.homeStreet() ); 104 homeaddress.setStreet( contact.homeStreet() );
72 homeaddress.setLocality( contact.homeCity() ); 105 homeaddress.setLocality( contact.homeCity() );
73 homeaddress.setRegion( contact.homeState() ); 106 homeaddress.setRegion( contact.homeState() );
74 homeaddress.setPostalCode( contact.homeZip() ); 107 homeaddress.setPostalCode( contact.homeZip() );
75 homeaddress.setCountry( contact.homeCountry() ); 108 homeaddress.setCountry( contact.homeCountry() );
76 109
77 addr.insertAddress( homeaddress ); 110 addr.insertAddress( homeaddress );
111 }
78 112
79 if (!contact.homePhone().isEmpty()) 113 if (!contact.homePhone().isEmpty())
80 { 114 {
81 PhoneNumber homephone; 115 PhoneNumber homephone;
82 homephone.setType( PhoneNumber::Home ); 116 homephone.setType( PhoneNumber::Home );
83 homephone.setNumber( contact.homePhone() ); 117 homephone.setNumber( contact.homePhone() );
84 addr.insertPhoneNumber( homephone ); 118 addr.insertPhoneNumber( homephone );
85 } 119 }
86 120
87 if (!contact.homeFax().isEmpty()) 121 if (!contact.homeFax().isEmpty())
88 { 122 {
89 PhoneNumber homefax; 123 PhoneNumber homefax;
90 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); 124 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
91 homefax.setNumber( contact.homeFax() ); 125 homefax.setNumber( contact.homeFax() );
92 addr.insertPhoneNumber( homefax ); 126 addr.insertPhoneNumber( homefax );
93 } 127 }
94 128
95 if (!contact.homeMobile().isEmpty()) 129 if (!contact.homeMobile().isEmpty())
96 { 130 {
97 PhoneNumber homemobile; 131 PhoneNumber homemobile;
98 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); 132 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
99 homemobile.setNumber( contact.homeMobile() ); 133 homemobile.setNumber( contact.homeMobile() );
100 addr.insertPhoneNumber( homemobile ); 134 addr.insertPhoneNumber( homemobile );
101 } 135 }
102 136
103 addr.setUrl( contact.homeWebpage() ); 137 addr.setUrl( contact.homeWebpage() );
104 138
105 139
106 // business 140 // business
107 Address businessaddress; 141 if ((!contact.businessStreet().isEmpty()) ||
108 businessaddress.setType(Address::Work); 142 (!contact.businessCity().isEmpty()) ||
143 (!contact.businessState().isEmpty()) ||
144 (!contact.businessZip().isEmpty()) ||
145 (!contact.businessCountry().isEmpty()))
146 {
147 Address businessaddress;
148 businessaddress.setType(Address::Work);
109//US businessaddress.setPostOfficeBox( "" ); 149//US businessaddress.setPostOfficeBox( "" );
110//US businessaddress.setExtended( "" ); 150//US businessaddress.setExtended( "" );
111 businessaddress.setStreet( contact.businessStreet() ); 151 businessaddress.setStreet( contact.businessStreet() );
112 businessaddress.setLocality( contact.businessCity() ); 152 businessaddress.setLocality( contact.businessCity() );
113 businessaddress.setRegion( contact.businessState() ); 153 businessaddress.setRegion( contact.businessState() );
114 businessaddress.setPostalCode( contact.businessZip() ); 154 businessaddress.setPostalCode( contact.businessZip() );
115 businessaddress.setCountry( contact.businessCountry() ); 155 businessaddress.setCountry( contact.businessCountry() );
156
157 addr.insertAddress( businessaddress );
158 }
159
116 160
117 addr.insertAddress( businessaddress );
118
119 if (!contact.businessPhone().isEmpty()) 161 if (!contact.businessPhone().isEmpty())
120 { 162 {
121 PhoneNumber businessphone; 163 PhoneNumber businessphone;
122 businessphone.setType( PhoneNumber::Work ); 164 businessphone.setType( PhoneNumber::Work );
123 businessphone.setNumber( contact.businessPhone() ); 165 businessphone.setNumber( contact.businessPhone() );
124 addr.insertPhoneNumber( businessphone ); 166 addr.insertPhoneNumber( businessphone );
125 } 167 }
126 168
127 if (!contact.businessFax().isEmpty()) 169 if (!contact.businessFax().isEmpty())
128 { 170 {
129 PhoneNumber businessfax; 171 PhoneNumber businessfax;
130 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); 172 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
131 businessfax.setNumber( contact.businessFax() ); 173 businessfax.setNumber( contact.businessFax() );
132 addr.insertPhoneNumber( businessfax ); 174 addr.insertPhoneNumber( businessfax );
133 } 175 }
134 176
135 if (!contact.businessMobile().isEmpty()) 177 if (!contact.businessMobile().isEmpty())
136 { 178 {
137 PhoneNumber businessmobile; 179 PhoneNumber businessmobile;
138 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); 180 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
139 businessmobile.setNumber( contact.businessMobile() ); 181 businessmobile.setNumber( contact.businessMobile() );
140 addr.insertPhoneNumber( businessmobile ); 182 addr.insertPhoneNumber( businessmobile );
141 } 183 }
142 184
143 if (!contact.businessPager().isEmpty()) 185 if (!contact.businessPager().isEmpty())
144 { 186 {
145 PhoneNumber businesspager; 187 PhoneNumber businesspager;
146 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); 188 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
147 businesspager.setNumber( contact.businessPager() ); 189 businesspager.setNumber( contact.businessPager() );
148 addr.insertPhoneNumber( businesspager ); 190 addr.insertPhoneNumber( businesspager );
149 } 191 }
150 192
151 addr.setRole( contact.jobTitle() ); //? 193 addr.setRole( contact.jobTitle() ); //?
152 addr.setOrganization( contact.company() ); 194 addr.setOrganization( contact.company() );
153 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); 195 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() );
154 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); 196 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() );
155 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); 197 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() );
156 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); 198 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() );
157 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); 199 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() );
158 200
159 //personal 201 //personal
160 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); 202 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
161 addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() ); 203 addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() );
162 204
163 if (contact.anniversary().isValid()) { 205 if (contact.anniversary().isValid()) {
164 int orgformat = KGlobal::locale()->getIntDateFormat(); 206 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate);
165 KGlobal::locale()->setIntDateFormat( 2 ); // = Qt::ISODate
166 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true);
167//US 207//US
168 qDebug("OpieConverter::opieToAddressee found:%s", dt.latin1()); 208 qDebug("OpieConverter::opieToAddressee found:%s", dt.latin1());
169 KGlobal::locale()->setIntDateFormat(orgformat );
170 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); 209 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
171 } 210 }
172 211
173 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); 212 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
174 if (contact.birthday().isValid()) 213 if (contact.birthday().isValid())
175 addr.setBirthday( contact.birthday() ); 214 addr.setBirthday( contact.birthday() );
176 215
177 addr.setNickName( contact.nickname() ); 216 addr.setNickName( contact.nickname() );
178 217
179 // others 218 // others
180 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. 219 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
181 QString notes = contact.notes(); 220 QString notes = contact.notes();
182 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; 221 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n";
183 222
184 addr.setNote( contact.notes() ); 223 addr.setNote( contact.notes() );
185 224
186 225
187 226
188//US QString groups() const { return find( Qtopia::Groups ); } 227//US QString groups() const { return find( Qtopia::Groups ); }
189//US QStringList groupList() const; 228//US QStringList groupList() const;
190 229
191 230
192 QStringList cats = contact.categoryNames("Contacts"); 231 QStringList cats = contact.categoryNames("Contacts");
193 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { 232// for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
194 qDebug("Cat: %s", (*it).latin1()); 233// qDebug("Cat: %s", (*it).latin1());
195 } 234// }
196 235
197 236
198 addr.setCategories( contact.categoryNames("Contacts") ); 237 addr.setCategories( contact.categoryNames("Contacts") );
199// qDebug("Groups: %s", contact.groups().latin1()); 238// qDebug("Groups: %s", contact.groups().latin1());
200// addr.setCategories( contact.groupList() ); 239// addr.setCategories( contact.groupList() );
201 240
202 241
203 return true; 242 return true;
204} 243}
205 244
206bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &contact ) 245bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &contact )
207{ 246{
208 // name 247 // name
209 contact.setLastName(addr.familyName()); 248 contact.setLastName(addr.familyName());
210 contact.setFirstName(addr.givenName()); 249 contact.setFirstName(addr.givenName());
211 contact.setMiddleName(addr.additionalName()); 250 contact.setMiddleName(addr.additionalName());
212 contact.setTitle(addr.prefix()); 251 contact.setTitle(addr.prefix());
213 contact.setSuffix(addr.suffix()); 252 contact.setSuffix(addr.suffix());
214 contact.setFileAs(); 253 contact.setFileAs();
215 254
216 255
217 // email 256 // email
218 QStringList emails = addr.emails(); 257 QStringList emails = addr.emails();
219 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 258 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
220 contact.insertEmail(*it); 259 contact.insertEmail(*it);
221 } 260 }
222 contact.setDefaultEmail( addr.preferredEmail() ); 261 contact.setDefaultEmail( addr.preferredEmail() );
223 262
224 263
225 // home 264 // home
226 const Address homeaddress = addr.address(Address::Home); 265 const Address homeaddress = addr.address(Address::Home);
227 if (!homeaddress.isEmpty()) { 266 if (!homeaddress.isEmpty()) {
228 contact.setHomeStreet(homeaddress.street()); 267 contact.setHomeStreet(homeaddress.street());
229 contact.setHomeCity(homeaddress.locality()); 268 contact.setHomeCity(homeaddress.locality());
230 contact.setHomeState(homeaddress.region()); 269 contact.setHomeState(homeaddress.region());
231 contact.setHomeZip(homeaddress.postalCode()); 270 contact.setHomeZip(homeaddress.postalCode());
232 contact.setHomeCountry(homeaddress.country()); 271 contact.setHomeCountry(homeaddress.country());
233 } 272 }
234 273
235 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); 274 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
236 if (!homephone.number().isEmpty()) 275 if (!homephone.number().isEmpty())
237 contact.setHomePhone(homephone.number()); 276 contact.setHomePhone(homephone.number());
238 277
239 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); 278 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
240 if (!homefax.number().isEmpty()) 279 if (!homefax.number().isEmpty())
241 contact.setHomeFax(homefax.number()); 280 contact.setHomeFax(homefax.number());
242 281
243 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); 282 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
244 if (!homemobile.number().isEmpty()) 283 if (!homemobile.number().isEmpty())
245 contact.setHomeMobile(homemobile.number()); 284 contact.setHomeMobile(homemobile.number());
246 285
247 contact.setHomeWebpage(addr.url().url()); 286 contact.setHomeWebpage(addr.url().url());
248 287
249 288
250 // business 289 // business
251 const Address businessaddress = addr.address(Address::Work); 290 const Address businessaddress = addr.address(Address::Work);
252 if (!businessaddress.isEmpty()) { 291 if (!businessaddress.isEmpty()) {
253 contact.setBusinessStreet(businessaddress.street()); 292 contact.setBusinessStreet(businessaddress.street());
254 contact.setBusinessCity(businessaddress.locality()); 293 contact.setBusinessCity(businessaddress.locality());
255 contact.setBusinessState(businessaddress.region()); 294 contact.setBusinessState(businessaddress.region());
256 contact.setBusinessZip(businessaddress.postalCode()); 295 contact.setBusinessZip(businessaddress.postalCode());
257 contact.setBusinessCountry(businessaddress.country()); 296 contact.setBusinessCountry(businessaddress.country());
258 } 297 }
259 298
260 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); 299 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work );
261 if (!businessphone.number().isEmpty()) 300 if (!businessphone.number().isEmpty())
262 contact.setBusinessPhone(businessphone.number()); 301 contact.setBusinessPhone(businessphone.number());
263 302
264 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); 303 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax );
265 if (!businessfax.number().isEmpty()) 304 if (!businessfax.number().isEmpty())
266 contact.setBusinessFax(businessfax.number()); 305 contact.setBusinessFax(businessfax.number());
267 306
268 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); 307 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell );
269 if (!businessmobile.number().isEmpty()) 308 if (!businessmobile.number().isEmpty())
270 contact.setBusinessMobile(businessmobile.number()); 309 contact.setBusinessMobile(businessmobile.number());
271 310
272 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); 311 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager );
273 if (!businesspager.number().isEmpty()) 312 if (!businesspager.number().isEmpty())
274 contact.setBusinessPager(businesspager.number()); 313 contact.setBusinessPager(businesspager.number());
275 314
276 contact.setJobTitle(addr.role()); 315 contact.setJobTitle(addr.role());
277 contact.setCompany(addr.organization()); 316 contact.setCompany(addr.organization());
278 317
279 contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); 318 contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" ));
280 contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); 319 contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" ));
281 contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); 320 contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" ));
282 contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); 321 contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" ));
283 contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); 322 contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" ));
284 323
285 //personal 324 //personal
286 contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); 325 contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" ));
287 contact.setGender(addr.custom( "KADDRESSBOOK", "X-Gender" )); 326 contact.setGender(addr.custom( "KADDRESSBOOK", "X-Gender" ));
288 327
289 QDate dt = KGlobal::locale()->readDate( 328 QDate dt = KGlobal::locale()->readDate(
290 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate 329 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
291 contact.setAnniversary( dt ); 330 contact.setAnniversary( dt );
292 331
293 contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); 332 contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" ));
294 333
295 contact.setBirthday(addr.birthday().date()); 334 contact.setBirthday(addr.birthday().date());
296 contact.setNickname(addr.nickName()); 335 contact.setNickname(addr.nickName());
297 336
298 // other 337 // other
299 contact.setNotes(addr.note()); 338 contact.setNotes(addr.note());
300 339
301//US QString groups() const { return find( Qtopia::Groups ); } 340//US QString groups() const { return find( Qtopia::Groups ); }
302//US QStringList groupList() const; 341//US QStringList groupList() const;
303 342
304/*US 343/*US
305 QStringList cats = contact.categoryNames("Contacts"); 344 QStringList cats = contact.categoryNames("Contacts");
306 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { 345 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
307 qDebug("Cat: %s", (*it).latin1()); 346 qDebug("Cat: %s", (*it).latin1());
308 } 347 }
309*/ 348*/
310 349
311// addr.setCategories( contact.categoryNames("Contacts") ); 350// addr.setCategories( contact.categoryNames("Contacts") );
312// contact.categoryNames("Contacts"); 351// contact.categoryNames("Contacts");
313// contact.setCategoryNames(addr.categories()); 352// contact.setCategoryNames(addr.categories());
314 353
315/*US 354/*US
316 QStringList cats = addr.categories(); 355 QStringList cats = addr.categories();
317 QArray<int> cat(cats.count()); 356 QArray<int> cat(cats.count());
318 int counter = 0; 357 int counter = 0;
319 for ( QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it ) 358 for ( QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it )
320 cat[counter] = (*it).toInt(); 359 cat[counter] = (*it).toInt();
321 360
322 contact.setCategories( cat ); 361 contact.setCategories( cat );
323*/ 362*/
324 363
325 Categories catDB; 364 Categories catDB;
326 catDB.dump(); 365 catDB.load( categoryFileName() );
327//US catDB.load( contact.categoryFileName() );
328 catDB.load( "contact" );
329
330 QStringList cats = addr.categories(); 366 QStringList cats = addr.categories();
331 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
332 qDebug("categories: %s", (*it).latin1());
333// contact.setCategories(catDB.id(*it));
334 }
335 367
368 QArray<int> iar;
369 if ( !cats.isEmpty() ) {
370 QArray<int> iar = catDB.ids("contact", cats);
371 contact.setCategories(iar);
372 }
336 373
337 return true; 374 return true;
338} 375}
diff --git a/kabc/converter/opie/opieconverter.h b/kabc/converter/opie/opieconverter.h
index ef7300b..7d2ad85 100644
--- a/kabc/converter/opie/opieconverter.h
+++ b/kabc/converter/opie/opieconverter.h
@@ -1,71 +1,80 @@
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#ifndef KABC_OPIECONVERTER_H 28#ifndef KABC_OPIECONVERTER_H
29#define KABC_OPIECONVERTER_H 29#define KABC_OPIECONVERTER_H
30 30
31#include <qstring.h> 31#include <qstring.h>
32 32
33#include "addressee.h" 33#include "addressee.h"
34#include <opie/ocontact.h> 34#include <opie/ocontact.h>
35 35
36class Categories;
37
36namespace KABC { 38namespace KABC {
37 39
38class OpieConverter 40class OpieConverter
39{ 41{
40public: 42public:
41 43
42 /** 44 /**
43 * Constructor. 45 * Constructor.
44 */ 46 */
45 OpieConverter(); 47 OpieConverter();
46 48
47 /** 49 /**
48 * Destructor. 50 * Destructor.
49 */ 51 */
50 ~OpieConverter(); 52 virtual ~OpieConverter();
53
54 virtual bool init();
55 virtual void deinit();
51 56
52 /** 57 /**
53 * Converts a vcard string to an addressee. 58 * Converts a vcard string to an addressee.
54 * 59 *
55 * @param contact The opie contact. 60 * @param contact The opie contact.
56 * @param addr The addressee. 61 * @param addr The addressee.
57 */ 62 */
58 bool opieToAddressee( OContact &contact, Addressee &addr ); 63 bool opieToAddressee( OContact &contact, Addressee &addr );
59 64
60 /** 65 /**
61 * Converts an addressee to a vcard string. 66 * Converts an addressee to a vcard string.
62 * 67 *
63 * @param addr The addressee. 68 * @param addr The addressee.
64 * @param contact The opie contact. 69 * @param contact The opie contact.
65 */ 70 */
66 bool addresseeToOpie( const Addressee &addr, OContact &contact ); 71 bool addresseeToOpie( const Addressee &addr, OContact &contact );
72
73 private:
74 Categories* catDB;
67 75
76
68}; 77};
69 78
70} 79}
71#endif 80#endif
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp
index d1def18..8ee0725 100644
--- a/kaddressbook/xxport/opie/opie_xxport.cpp
+++ b/kaddressbook/xxport/opie/opie_xxport.cpp
@@ -1,202 +1,212 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qdir.h> 31#include <qdir.h>
32 32
33#include <kfiledialog.h> 33#include <kfiledialog.h>
34#include <kmessagebox.h> 34#include <kmessagebox.h>
35 35
36#include <opie/ocontactaccess.h> 36#include <opie/ocontactaccess.h>
37#include <opie/ocontactaccessbackend_xml.h> 37#include <opie/ocontactaccessbackend_xml.h>
38 38
39#include "stdaddressbook.h" 39#include "stdaddressbook.h"
40 40
41/*US 41/*US
42#include <qfile.h> 42#include <qfile.h>
43#include <qtextstream.h> 43#include <qtextstream.h>
44 44
45#include <kabc/vcardconverter.h> 45#include <kabc/vcardconverter.h>
46#ifndef KAB_EMBEDDED 46#ifndef KAB_EMBEDDED
47#include <kio/netaccess.h> 47#include <kio/netaccess.h>
48#endif //KAB_EMBEDDED 48#endif //KAB_EMBEDDED
49 49
50#include <klocale.h> 50#include <klocale.h>
51#include <kmessagebox.h> 51#include <kmessagebox.h>
52#include <ktempfile.h> 52#include <ktempfile.h>
53#include <kurl.h> 53#include <kurl.h>
54*/ 54*/
55 55
56#include "xxportmanager.h" 56#include "xxportmanager.h"
57#include "opieconverter.h" 57#include "opieconverter.h"
58 58
59#include "opie_xxport.h" 59#include "opie_xxport.h"
60 60
61 61
62class OpieXXPortFactory : public XXPortFactory 62class OpieXXPortFactory : public XXPortFactory
63{ 63{
64 public: 64 public:
65 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 65 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
66 { 66 {
67 return new OpieXXPort( ab, parent, name ); 67 return new OpieXXPort( ab, parent, name );
68 } 68 }
69}; 69};
70 70
71 71
72extern "C" 72extern "C"
73{ 73{
74 void *init_kaddrbk_opie_xxport() 74 void *init_kaddrbk_opie_xxport()
75 { 75 {
76 return ( new OpieXXPortFactory() ); 76 return ( new OpieXXPortFactory() );
77 } 77 }
78} 78}
79 79
80 80
81OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 81OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
82 : XXPortObject( ab, parent, name ) 82 : XXPortObject( ab, parent, name )
83{ 83{
84 createImportAction( i18n( "Import Opie..." ) ); 84 createImportAction( i18n( "Import Opie..." ) );
85 createExportAction( i18n( "Export Opie..." ) ); 85 createExportAction( i18n( "Export Opie..." ) );
86} 86}
87 87
88bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 88bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
89{ 89{
90 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 90 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
91 91
92#ifndef KAB_EMBEDDED 92#ifndef KAB_EMBEDDED
93 QString fileName = KFileDialog::getSaveFileName( name ); 93 QString fileName = KFileDialog::getSaveFileName( name );
94#else //KAB_EMBEDDED 94#else //KAB_EMBEDDED
95 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); 95 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
96#endif //KAB_EMBEDDED 96#endif //KAB_EMBEDDED
97 97
98 if ( fileName.isEmpty() ) 98 if ( fileName.isEmpty() )
99 return true; 99 return true;
100 100
101 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); 101 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName );
102 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); 102 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false);
103 103
104 if ( !access ) { 104 if ( !access ) {
105 qDebug("Unable to access file() %s", fileName.latin1()); 105 qDebug("Unable to access file() %s", fileName.latin1());
106 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 106 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
107 return false; 107 return false;
108 } 108 }
109 109
110 KABC::OpieConverter mConverter;
111
112 bool res = mConverter.init();
113 if (!res)
114 {
115 QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) );
116 qDebug(text);
117 KMessageBox::error( parentWidget(), text );
118 delete access;
119 return false;
120 }
121
110 //Now check if the file has already entries, and ask the user if he wants to delete them first. 122 //Now check if the file has already entries, and ask the user if he wants to delete them first.
111 OContactAccess::List contactList = access->allRecords(); 123 OContactAccess::List contactList = access->allRecords();
112 if (contactList.count() > 0) 124 if (contactList.count() > 0)
113 { 125 {
114 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 126 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
115 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 127 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
116 // Clean the database.. 128 // Clean the database..
117 access->clear(); 129 access->clear();
118 } 130 }
119 } 131 }
120 132
121 KABC::OpieConverter mConverter;
122 bool res;
123 133
124 KABC::Addressee::List::ConstIterator it; 134 KABC::Addressee::List::ConstIterator it;
125 for ( it = list.begin(); it != list.end(); ++it ) { 135 for ( it = list.begin(); it != list.end(); ++it ) {
126 OContact c; 136 OContact c;
127 KABC::Addressee addressee = (*it); 137 KABC::Addressee addressee = (*it);
128 138
129 res = mConverter.addresseeToOpie( *it, c ); 139 res = mConverter.addresseeToOpie( *it, c );
130 if (res == true) 140 if (res == true)
131 { 141 {
132 res = access->add(c); 142 res = access->add(c);
133 if (res == false) 143 if (res == false)
134 qDebug("Unable to append Contact %s", c.fullName().latin1()); 144 qDebug("Unable to append Contact %s", c.fullName().latin1());
135 } 145 }
136 else 146 else
137 { 147 {
138 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 148 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
139 } 149 }
140 } 150 }
141 151
142 access->save(); 152 access->save();
143 153
144 delete access; 154 delete access;
145//US the deletion of the access object deletes the backend object as well. 155//US the deletion of the access object deletes the backend object as well.
146 156
147 return true; 157 return true;
148} 158}
149 159
150KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const 160KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const
151{ 161{
152 KABC::AddresseeList adrlst; 162 KABC::AddresseeList adrlst;
153 163
154 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 164 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
155 165
156#ifndef KAB_EMBEDDED 166#ifndef KAB_EMBEDDED
157 QString fileName = KFileDialog::getOpenFileName( name ); 167 QString fileName = KFileDialog::getOpenFileName( name );
158#else //KAB_EMBEDDED 168#else //KAB_EMBEDDED
159 QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); 169 QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() );
160#endif //KAB_EMBEDDED 170#endif //KAB_EMBEDDED
161 171
162 if ( fileName.isEmpty() ) 172 if ( fileName.isEmpty() )
163 return KABC::AddresseeList(); 173 return KABC::AddresseeList();
164 174
165 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); 175 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName );
166 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); 176 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false);
167 177
168 if ( !access ) { 178 if ( !access ) {
169 qDebug("Unable to access file() %s", fileName.latin1()); 179 qDebug("Unable to access file() %s", fileName.latin1());
170 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 180 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
171 return KABC::AddresseeList(); 181 return KABC::AddresseeList();
172 } 182 }
173 183
174 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available 184 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available
175 185
176 KABC::OpieConverter mConverter; 186 KABC::OpieConverter mConverter;
177 bool res = false; 187 bool res = false;
178 188
179 189
180 OContactAccess::List::Iterator it; 190 OContactAccess::List::Iterator it;
181 OContactAccess::List allList = access->allRecords(); 191 OContactAccess::List allList = access->allRecords();
182 for ( it = allList.begin(); it != allList.end(); ++it ) 192 for ( it = allList.begin(); it != allList.end(); ++it )
183 { 193 {
184 OContact c = (*it); 194 OContact c = (*it);
185 195
186 KABC::Addressee addressee; 196 KABC::Addressee addressee;
187 197
188 res = mConverter.opieToAddressee( c, addressee ); 198 res = mConverter.opieToAddressee( c, addressee );
189 199
190 if ( !addressee.isEmpty() && res ) { 200 if ( !addressee.isEmpty() && res ) {
191 adrlst.append( addressee ); 201 adrlst.append( addressee );
192 } 202 }
193 203
194// qDebug("found %s", c.fullName().latin1()); 204// qDebug("found %s", c.fullName().latin1());
195 } 205 }
196 206
197 delete access; 207 delete access;
198//US the deletion of the access object deletes the backend object as well. 208//US the deletion of the access object deletes the backend object as well.
199 209
200 return adrlst; 210 return adrlst;
201 211
202} 212}
diff --git a/kaddressbook/xxport/opie/opie_xxportE.pro b/kaddressbook/xxport/opie/opie_xxportE.pro
index a660a48..c373e37 100644
--- a/kaddressbook/xxport/opie/opie_xxportE.pro
+++ b/kaddressbook/xxport/opie/opie_xxportE.pro
@@ -1,27 +1,28 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3TARGET = kaddrbk_opie_xxport 3TARGET = kaddrbk_opie_xxport
4 4
5OBJECTS_DIR = obj/$(PLATFORM) 5OBJECTS_DIR = obj/$(PLATFORM)
6MOC_DIR = moc/$(PLATFORM) 6MOC_DIR = moc/$(PLATFORM)
7DESTDIR = $(QPEDIR)/lib 7DESTDIR = $(QPEDIR)/lib
8 8
9DEFINES += KAB_EMBEDDED 9DEFINES += KAB_EMBEDDED
10 10
11INCLUDEPATH += ../.. ../../.. ../../../kabc ../../../kabc/converter/opie ../../../microkde ../../../microkde/kdeui ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(QPEDIR)/include 11INCLUDEPATH += ../.. ../../.. ../../../kabc ../../../kabc/converter/opie ../../../microkde ../../../microkde/kdeui ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(OPIEDIR)/include
12LIBS += -L$(QPEDIR)/lib 12LIBS += -L$(QPEDIR)/lib
13LIBS += -L$(OPIEDIR)/lib
13LIBS += -lmicrokde 14LIBS += -lmicrokde
14LIBS += -lmicrokabc 15LIBS += -lmicrokabc
15LIBS += -lopie 16LIBS += -lopie
16LIBS += -lqpe 17LIBS += -lqpe
17LIBS += -lqte 18LIBS += -lqte
18LIBS += -lmicrokabc_opieconverter 19LIBS += -lmicrokabc_opieconverter
19 20
20INTERFACES = \ 21INTERFACES = \
21 22
22HEADERS = \ 23HEADERS = \
23 opie_xxport.h \ 24 opie_xxport.h \
24 25
25SOURCES = \ 26SOURCES = \
26 opie_xxport.cpp \ 27 opie_xxport.cpp \
27 28