-rw-r--r-- | kabc/converter/qtopia/qtopiaconverter.cpp | 2 | ||||
-rw-r--r-- | kaddressbook/xxport/opie/opie_xxport.cpp | 11 | ||||
-rw-r--r-- | kaddressbook/xxport/qtopia/qtopia_xxport.cpp | 12 |
3 files changed, 22 insertions, 3 deletions
diff --git a/kabc/converter/qtopia/qtopiaconverter.cpp b/kabc/converter/qtopia/qtopiaconverter.cpp index f451b8b..498e89e 100644 --- a/kabc/converter/qtopia/qtopiaconverter.cpp +++ b/kabc/converter/qtopia/qtopiaconverter.cpp | |||
@@ -1,360 +1,360 @@ | |||
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 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (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 | //US #include <qpe/categoryselect.h> | 35 | //US #include <qpe/categoryselect.h> |
36 | 36 | ||
37 | 37 | ||
38 | using namespace KABC; | 38 | using namespace KABC; |
39 | 39 | ||
40 | QtopiaConverter::QtopiaConverter() : catDB(0) | 40 | QtopiaConverter::QtopiaConverter() : catDB(0) |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | QtopiaConverter::~QtopiaConverter() | 44 | QtopiaConverter::~QtopiaConverter() |
45 | { | 45 | { |
46 | deinit(); | 46 | deinit(); |
47 | } | 47 | } |
48 | 48 | ||
49 | bool QtopiaConverter::init() | 49 | bool QtopiaConverter::init() |
50 | { | 50 | { |
51 | catDB = new Categories(); | 51 | catDB = new Categories(); |
52 | 52 | ||
53 | if (!catDB) | 53 | if (!catDB) |
54 | return false; | 54 | return false; |
55 | 55 | ||
56 | catDB->load( categoryFileName() ); | 56 | catDB->load( categoryFileName() ); |
57 | return true; | 57 | return true; |
58 | } | 58 | } |
59 | 59 | ||
60 | void QtopiaConverter::deinit() | 60 | void QtopiaConverter::deinit() |
61 | { | 61 | { |
62 | if (catDB) | 62 | if (catDB) |
63 | { | 63 | { |
64 | delete catDB; | 64 | delete catDB; |
65 | catDB = 0; | 65 | catDB = 0; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) | 69 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) |
70 | { | 70 | { |
71 | // name | 71 | // name |
72 | addr.setFormattedName(contact.fileAs()); | 72 | addr.setFormattedName(contact.fileAs()); |
73 | addr.setFamilyName( contact.lastName() ); | 73 | addr.setFamilyName( contact.lastName() ); |
74 | addr.setGivenName( contact.firstName() ); | 74 | addr.setGivenName( contact.firstName() ); |
75 | addr.setAdditionalName( contact.middleName() ); | 75 | addr.setAdditionalName( contact.middleName() ); |
76 | addr.setPrefix( contact.nameTitle() ); | 76 | addr.setPrefix( contact.nameTitle() ); |
77 | addr.setSuffix( contact.suffix() ); | 77 | addr.setSuffix( contact.suffix() ); |
78 | 78 | ||
79 | 79 | ||
80 | 80 | ||
81 | QStringList emails = contact.emailList(); | 81 | QStringList emails = contact.emailList(); |
82 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 82 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
83 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); | 83 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); |
84 | } | 84 | } |
85 | 85 | ||
86 | if (!contact.defaultEmail().isEmpty()) | 86 | if (!contact.defaultEmail().isEmpty()) |
87 | addr.insertEmail(contact.defaultEmail(), true); | 87 | addr.insertEmail(contact.defaultEmail(), true); |
88 | 88 | ||
89 | // home | 89 | // home |
90 | if ((!contact.homeStreet().isEmpty()) || | 90 | if ((!contact.homeStreet().isEmpty()) || |
91 | (!contact.homeCity().isEmpty()) || | 91 | (!contact.homeCity().isEmpty()) || |
92 | (!contact.homeState().isEmpty()) || | 92 | (!contact.homeState().isEmpty()) || |
93 | (!contact.homeZip().isEmpty()) || | 93 | (!contact.homeZip().isEmpty()) || |
94 | (!contact.homeCountry().isEmpty())) | 94 | (!contact.homeCountry().isEmpty())) |
95 | { | 95 | { |
96 | Address homeaddress; | 96 | Address homeaddress; |
97 | homeaddress.setType(Address::Home); | 97 | homeaddress.setType(Address::Home); |
98 | //US homeaddress.setPostOfficeBox( "" ); | 98 | //US homeaddress.setPostOfficeBox( "" ); |
99 | //US homeaddress.setExtended( "" ); | 99 | //US homeaddress.setExtended( "" ); |
100 | homeaddress.setStreet( contact.homeStreet() ); | 100 | homeaddress.setStreet( contact.homeStreet() ); |
101 | homeaddress.setLocality( contact.homeCity() ); | 101 | homeaddress.setLocality( contact.homeCity() ); |
102 | homeaddress.setRegion( contact.homeState() ); | 102 | homeaddress.setRegion( contact.homeState() ); |
103 | homeaddress.setPostalCode( contact.homeZip() ); | 103 | homeaddress.setPostalCode( contact.homeZip() ); |
104 | homeaddress.setCountry( contact.homeCountry() ); | 104 | homeaddress.setCountry( contact.homeCountry() ); |
105 | 105 | ||
106 | addr.insertAddress( homeaddress ); | 106 | addr.insertAddress( homeaddress ); |
107 | } | 107 | } |
108 | 108 | ||
109 | if (!contact.homePhone().isEmpty()) | 109 | if (!contact.homePhone().isEmpty()) |
110 | { | 110 | { |
111 | PhoneNumber homephone; | 111 | PhoneNumber homephone; |
112 | homephone.setType( PhoneNumber::Home ); | 112 | homephone.setType( PhoneNumber::Home ); |
113 | homephone.setNumber( contact.homePhone() ); | 113 | homephone.setNumber( contact.homePhone() ); |
114 | addr.insertPhoneNumber( homephone ); | 114 | addr.insertPhoneNumber( homephone ); |
115 | } | 115 | } |
116 | 116 | ||
117 | if (!contact.homeFax().isEmpty()) | 117 | if (!contact.homeFax().isEmpty()) |
118 | { | 118 | { |
119 | PhoneNumber homefax; | 119 | PhoneNumber homefax; |
120 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); | 120 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); |
121 | homefax.setNumber( contact.homeFax() ); | 121 | homefax.setNumber( contact.homeFax() ); |
122 | addr.insertPhoneNumber( homefax ); | 122 | addr.insertPhoneNumber( homefax ); |
123 | } | 123 | } |
124 | 124 | ||
125 | if (!contact.homeMobile().isEmpty()) | 125 | if (!contact.homeMobile().isEmpty()) |
126 | { | 126 | { |
127 | PhoneNumber homemobile; | 127 | PhoneNumber homemobile; |
128 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); | 128 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); |
129 | homemobile.setNumber( contact.homeMobile() ); | 129 | homemobile.setNumber( contact.homeMobile() ); |
130 | addr.insertPhoneNumber( homemobile ); | 130 | addr.insertPhoneNumber( homemobile ); |
131 | } | 131 | } |
132 | 132 | ||
133 | addr.setUrl( contact.homeWebpage() ); | 133 | addr.setUrl( contact.homeWebpage() ); |
134 | 134 | ||
135 | 135 | ||
136 | // business | 136 | // business |
137 | if ((!contact.businessStreet().isEmpty()) || | 137 | if ((!contact.businessStreet().isEmpty()) || |
138 | (!contact.businessCity().isEmpty()) || | 138 | (!contact.businessCity().isEmpty()) || |
139 | (!contact.businessState().isEmpty()) || | 139 | (!contact.businessState().isEmpty()) || |
140 | (!contact.businessZip().isEmpty()) || | 140 | (!contact.businessZip().isEmpty()) || |
141 | (!contact.businessCountry().isEmpty())) | 141 | (!contact.businessCountry().isEmpty())) |
142 | { | 142 | { |
143 | Address businessaddress; | 143 | Address businessaddress; |
144 | businessaddress.setType(Address::Work); | 144 | businessaddress.setType(Address::Work); |
145 | //US businessaddress.setPostOfficeBox( "" ); | 145 | //US businessaddress.setPostOfficeBox( "" ); |
146 | //US businessaddress.setExtended( "" ); | 146 | //US businessaddress.setExtended( "" ); |
147 | businessaddress.setStreet( contact.businessStreet() ); | 147 | businessaddress.setStreet( contact.businessStreet() ); |
148 | businessaddress.setLocality( contact.businessCity() ); | 148 | businessaddress.setLocality( contact.businessCity() ); |
149 | businessaddress.setRegion( contact.businessState() ); | 149 | businessaddress.setRegion( contact.businessState() ); |
150 | businessaddress.setPostalCode( contact.businessZip() ); | 150 | businessaddress.setPostalCode( contact.businessZip() ); |
151 | businessaddress.setCountry( contact.businessCountry() ); | 151 | businessaddress.setCountry( contact.businessCountry() ); |
152 | 152 | ||
153 | addr.insertAddress( businessaddress ); | 153 | addr.insertAddress( businessaddress ); |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | if (!contact.businessPhone().isEmpty()) | 157 | if (!contact.businessPhone().isEmpty()) |
158 | { | 158 | { |
159 | PhoneNumber businessphone; | 159 | PhoneNumber businessphone; |
160 | businessphone.setType( PhoneNumber::Work ); | 160 | businessphone.setType( PhoneNumber::Work ); |
161 | businessphone.setNumber( contact.businessPhone() ); | 161 | businessphone.setNumber( contact.businessPhone() ); |
162 | addr.insertPhoneNumber( businessphone ); | 162 | addr.insertPhoneNumber( businessphone ); |
163 | } | 163 | } |
164 | 164 | ||
165 | if (!contact.businessFax().isEmpty()) | 165 | if (!contact.businessFax().isEmpty()) |
166 | { | 166 | { |
167 | PhoneNumber businessfax; | 167 | PhoneNumber businessfax; |
168 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); | 168 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); |
169 | businessfax.setNumber( contact.businessFax() ); | 169 | businessfax.setNumber( contact.businessFax() ); |
170 | addr.insertPhoneNumber( businessfax ); | 170 | addr.insertPhoneNumber( businessfax ); |
171 | } | 171 | } |
172 | 172 | ||
173 | if (!contact.businessMobile().isEmpty()) | 173 | if (!contact.businessMobile().isEmpty()) |
174 | { | 174 | { |
175 | PhoneNumber businessmobile; | 175 | PhoneNumber businessmobile; |
176 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); | 176 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); |
177 | businessmobile.setNumber( contact.businessMobile() ); | 177 | businessmobile.setNumber( contact.businessMobile() ); |
178 | addr.insertPhoneNumber( businessmobile ); | 178 | addr.insertPhoneNumber( businessmobile ); |
179 | } | 179 | } |
180 | 180 | ||
181 | if (!contact.businessPager().isEmpty()) | 181 | if (!contact.businessPager().isEmpty()) |
182 | { | 182 | { |
183 | PhoneNumber businesspager; | 183 | PhoneNumber businesspager; |
184 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); | 184 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); |
185 | businesspager.setNumber( contact.businessPager() ); | 185 | businesspager.setNumber( contact.businessPager() ); |
186 | addr.insertPhoneNumber( businesspager ); | 186 | addr.insertPhoneNumber( businesspager ); |
187 | } | 187 | } |
188 | 188 | ||
189 | addr.setRole( contact.jobTitle() ); //? | 189 | addr.setRole( contact.jobTitle() ); //? |
190 | addr.setOrganization( contact.company() ); | 190 | addr.setOrganization( contact.company() ); |
191 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); | 191 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); |
192 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); | 192 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); |
193 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); | 193 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); |
194 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); | 194 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); |
195 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); | 195 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); |
196 | 196 | ||
197 | //personal | 197 | //personal |
198 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); | 198 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); |
199 | // qtopia uses this categorization: | 199 | // qtopia uses this categorization: |
200 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | 200 | // enum GenderType { UnspecifiedGender=0, Male, Female }; |
201 | if (contact.gender() == PimContact::Male) | 201 | if (contact.gender() == PimContact::Male) |
202 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); | 202 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); |
203 | else if (contact.gender() == PimContact::Female) | 203 | else if (contact.gender() == PimContact::Female) |
204 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); | 204 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); |
205 | 205 | ||
206 | if (contact.anniversary().isValid()) { | 206 | if (contact.anniversary().isValid()) { |
207 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); | 207 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); |
208 | //US | 208 | //US |
209 | qDebug("OpieConverter::qtopiaToAddressee found:%s", dt.latin1()); | 209 | // qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); |
210 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | 210 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); |
211 | } | 211 | } |
212 | 212 | ||
213 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); | 213 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); |
214 | if (contact.birthday().isValid()) | 214 | if (contact.birthday().isValid()) |
215 | addr.setBirthday( contact.birthday() ); | 215 | addr.setBirthday( contact.birthday() ); |
216 | 216 | ||
217 | addr.setNickName( contact.nickname() ); | 217 | addr.setNickName( contact.nickname() ); |
218 | 218 | ||
219 | // others | 219 | // others |
220 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. | 220 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. |
221 | QString notes = contact.notes(); | 221 | QString notes = contact.notes(); |
222 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; | 222 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; |
223 | 223 | ||
224 | addr.setNote( contact.notes() ); | 224 | addr.setNote( contact.notes() ); |
225 | 225 | ||
226 | 226 | ||
227 | 227 | ||
228 | //US QString groups() const { return find( Qtopia::Groups ); } | 228 | //US QString groups() const { return find( Qtopia::Groups ); } |
229 | //US QStringList groupList() const; | 229 | //US QStringList groupList() const; |
230 | 230 | ||
231 | QArray<int> catArray = contact.categories(); | 231 | QArray<int> catArray = contact.categories(); |
232 | QString cat; | 232 | QString cat; |
233 | 233 | ||
234 | for ( unsigned int i=0; i < catArray.size(); i++ ) { | 234 | for ( unsigned int i=0; i < catArray.size(); i++ ) { |
235 | cat = catDB->label("contact", catArray[i]); | 235 | cat = catDB->label("contact", catArray[i]); |
236 | if ( !cat.isEmpty() ) | 236 | if ( !cat.isEmpty() ) |
237 | addr.insertCategory( cat ); | 237 | addr.insertCategory( cat ); |
238 | } | 238 | } |
239 | 239 | ||
240 | return true; | 240 | return true; |
241 | } | 241 | } |
242 | 242 | ||
243 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) | 243 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) |
244 | { | 244 | { |
245 | // name | 245 | // name |
246 | contact.setLastName(addr.familyName()); | 246 | contact.setLastName(addr.familyName()); |
247 | contact.setFirstName(addr.givenName()); | 247 | contact.setFirstName(addr.givenName()); |
248 | contact.setMiddleName(addr.additionalName()); | 248 | contact.setMiddleName(addr.additionalName()); |
249 | contact.setNameTitle(addr.prefix()); | 249 | contact.setNameTitle(addr.prefix()); |
250 | contact.setSuffix(addr.suffix()); | 250 | contact.setSuffix(addr.suffix()); |
251 | contact.setFileAs(); | 251 | contact.setFileAs(); |
252 | 252 | ||
253 | 253 | ||
254 | 254 | ||
255 | QStringList emails = addr.emails(); | 255 | QStringList emails = addr.emails(); |
256 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 256 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
257 | contact.insertEmail(*it); | 257 | contact.insertEmail(*it); |
258 | } | 258 | } |
259 | contact.setDefaultEmail( addr.preferredEmail() ); | 259 | contact.setDefaultEmail( addr.preferredEmail() ); |
260 | 260 | ||
261 | 261 | ||
262 | // home | 262 | // home |
263 | const Address homeaddress = addr.address(Address::Home); | 263 | const Address homeaddress = addr.address(Address::Home); |
264 | if (!homeaddress.isEmpty()) { | 264 | if (!homeaddress.isEmpty()) { |
265 | contact.setHomeStreet(homeaddress.street()); | 265 | contact.setHomeStreet(homeaddress.street()); |
266 | contact.setHomeCity(homeaddress.locality()); | 266 | contact.setHomeCity(homeaddress.locality()); |
267 | contact.setHomeState(homeaddress.region()); | 267 | contact.setHomeState(homeaddress.region()); |
268 | contact.setHomeZip(homeaddress.postalCode()); | 268 | contact.setHomeZip(homeaddress.postalCode()); |
269 | contact.setHomeCountry(homeaddress.country()); | 269 | contact.setHomeCountry(homeaddress.country()); |
270 | } | 270 | } |
271 | 271 | ||
272 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); | 272 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); |
273 | if (!homephone.number().isEmpty()) | 273 | if (!homephone.number().isEmpty()) |
274 | contact.setHomePhone(homephone.number()); | 274 | contact.setHomePhone(homephone.number()); |
275 | 275 | ||
276 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); | 276 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); |
277 | if (!homefax.number().isEmpty()) | 277 | if (!homefax.number().isEmpty()) |
278 | contact.setHomeFax(homefax.number()); | 278 | contact.setHomeFax(homefax.number()); |
279 | 279 | ||
280 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); | 280 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); |
281 | if (!homemobile.number().isEmpty()) | 281 | if (!homemobile.number().isEmpty()) |
282 | contact.setHomeMobile(homemobile.number()); | 282 | contact.setHomeMobile(homemobile.number()); |
283 | 283 | ||
284 | contact.setHomeWebpage(addr.url().url()); | 284 | contact.setHomeWebpage(addr.url().url()); |
285 | 285 | ||
286 | 286 | ||
287 | // business | 287 | // business |
288 | const Address businessaddress = addr.address(Address::Work); | 288 | const Address businessaddress = addr.address(Address::Work); |
289 | if (!businessaddress.isEmpty()) { | 289 | if (!businessaddress.isEmpty()) { |
290 | contact.setBusinessStreet(businessaddress.street()); | 290 | contact.setBusinessStreet(businessaddress.street()); |
291 | contact.setBusinessCity(businessaddress.locality()); | 291 | contact.setBusinessCity(businessaddress.locality()); |
292 | contact.setBusinessState(businessaddress.region()); | 292 | contact.setBusinessState(businessaddress.region()); |
293 | contact.setBusinessZip(businessaddress.postalCode()); | 293 | contact.setBusinessZip(businessaddress.postalCode()); |
294 | contact.setBusinessCountry(businessaddress.country()); | 294 | contact.setBusinessCountry(businessaddress.country()); |
295 | } | 295 | } |
296 | 296 | ||
297 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); | 297 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); |
298 | if (!businessphone.number().isEmpty()) | 298 | if (!businessphone.number().isEmpty()) |
299 | contact.setBusinessPhone(businessphone.number()); | 299 | contact.setBusinessPhone(businessphone.number()); |
300 | 300 | ||
301 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); | 301 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); |
302 | if (!businessfax.number().isEmpty()) | 302 | if (!businessfax.number().isEmpty()) |
303 | contact.setBusinessFax(businessfax.number()); | 303 | contact.setBusinessFax(businessfax.number()); |
304 | 304 | ||
305 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); | 305 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); |
306 | if (!businessmobile.number().isEmpty()) | 306 | if (!businessmobile.number().isEmpty()) |
307 | contact.setBusinessMobile(businessmobile.number()); | 307 | contact.setBusinessMobile(businessmobile.number()); |
308 | 308 | ||
309 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); | 309 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); |
310 | if (!businesspager.number().isEmpty()) | 310 | if (!businesspager.number().isEmpty()) |
311 | contact.setBusinessPager(businesspager.number()); | 311 | contact.setBusinessPager(businesspager.number()); |
312 | 312 | ||
313 | contact.setJobTitle(addr.role()); | 313 | contact.setJobTitle(addr.role()); |
314 | contact.setCompany(addr.organization()); | 314 | contact.setCompany(addr.organization()); |
315 | 315 | ||
316 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); | 316 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); |
317 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); | 317 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); |
318 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); | 318 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); |
319 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); | 319 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); |
320 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); | 320 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); |
321 | 321 | ||
322 | //personal | 322 | //personal |
323 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); | 323 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); |
324 | // qtopia uses this categorization: | 324 | // qtopia uses this categorization: |
325 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | 325 | // enum GenderType { UnspecifiedGender=0, Male, Female }; |
326 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); | 326 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); |
327 | if (gt = "male") | 327 | if (gt = "male") |
328 | contact.setGender(PimContact::Male); | 328 | contact.setGender(PimContact::Male); |
329 | else if (gt = "female") | 329 | else if (gt = "female") |
330 | contact.setGender(PimContact::Female); | 330 | contact.setGender(PimContact::Female); |
331 | else | 331 | else |
332 | contact.setGender(PimContact::UnspecifiedGender); | 332 | contact.setGender(PimContact::UnspecifiedGender); |
333 | 333 | ||
334 | 334 | ||
335 | QDate dt = KGlobal::locale()->readDate( | 335 | QDate dt = KGlobal::locale()->readDate( |
336 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate | 336 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate |
337 | contact.setAnniversary( dt ); | 337 | contact.setAnniversary( dt ); |
338 | 338 | ||
339 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); | 339 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); |
340 | 340 | ||
341 | contact.setBirthday(addr.birthday().date()); | 341 | contact.setBirthday(addr.birthday().date()); |
342 | contact.setNickname(addr.nickName()); | 342 | contact.setNickname(addr.nickName()); |
343 | 343 | ||
344 | // other | 344 | // other |
345 | contact.setNotes(addr.note()); | 345 | contact.setNotes(addr.note()); |
346 | 346 | ||
347 | //US QString groups() const { return find( Qtopia::Groups ); } | 347 | //US QString groups() const { return find( Qtopia::Groups ); } |
348 | //US QStringList groupList() const; | 348 | //US QStringList groupList() const; |
349 | 349 | ||
350 | 350 | ||
351 | QStringList cats = addr.categories(); | 351 | QStringList cats = addr.categories(); |
352 | 352 | ||
353 | QArray<int> iar; | 353 | QArray<int> iar; |
354 | if ( !cats.isEmpty() ) { | 354 | if ( !cats.isEmpty() ) { |
355 | QArray<int> iar = catDB->ids("contact", cats); | 355 | QArray<int> iar = catDB->ids("contact", cats); |
356 | contact.setCategories(iar); | 356 | contact.setCategories(iar); |
357 | } | 357 | } |
358 | 358 | ||
359 | return true; | 359 | return true; |
360 | } | 360 | } |
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp index 12c83af..db30d34 100644 --- a/kaddressbook/xxport/opie/opie_xxport.cpp +++ b/kaddressbook/xxport/opie/opie_xxport.cpp | |||
@@ -1,212 +1,221 @@ | |||
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 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (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 | ||
62 | class OpieXXPortFactory : public XXPortFactory | 62 | class 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 | ||
72 | extern "C" | 72 | extern "C" |
73 | { | 73 | { |
74 | void *init_microkaddrbk_opie_xxport() | 74 | void *init_microkaddrbk_opie_xxport() |
75 | { | 75 | { |
76 | return ( new OpieXXPortFactory() ); | 76 | return ( new OpieXXPortFactory() ); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 81 | OpieXXPort::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 | ||
88 | bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | 88 | bool 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; | 110 | KABC::OpieConverter mConverter; |
111 | 111 | ||
112 | bool res = mConverter.init(); | 112 | bool res = mConverter.init(); |
113 | if (!res) | 113 | if (!res) |
114 | { | 114 | { |
115 | QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) ); | 115 | QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) ); |
116 | qDebug(text); | 116 | qDebug(text); |
117 | KMessageBox::error( parentWidget(), text ); | 117 | KMessageBox::error( parentWidget(), text ); |
118 | delete access; | 118 | delete access; |
119 | return false; | 119 | return false; |
120 | } | 120 | } |
121 | 121 | ||
122 | //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. |
123 | OContactAccess::List contactList = access->allRecords(); | 123 | OContactAccess::List contactList = access->allRecords(); |
124 | if (contactList.count() > 0) | 124 | if (contactList.count() > 0) |
125 | { | 125 | { |
126 | 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.?" ) ); |
127 | if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { | 127 | if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { |
128 | // Clean the database.. | 128 | // Clean the database.. |
129 | access->clear(); | 129 | access->clear(); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | KABC::Addressee::List::ConstIterator it; | 134 | KABC::Addressee::List::ConstIterator it; |
135 | for ( it = list.begin(); it != list.end(); ++it ) { | 135 | for ( it = list.begin(); it != list.end(); ++it ) { |
136 | OContact c; | 136 | OContact c; |
137 | KABC::Addressee addressee = (*it); | 137 | KABC::Addressee addressee = (*it); |
138 | 138 | ||
139 | res = mConverter.addresseeToOpie( *it, c ); | 139 | res = mConverter.addresseeToOpie( *it, c ); |
140 | if (res == true) | 140 | if (res == true) |
141 | { | 141 | { |
142 | res = access->add(c); | 142 | res = access->add(c); |
143 | if (res == false) | 143 | if (res == false) |
144 | qDebug("Unable to append Contact %s", c.fullName().latin1()); | 144 | qDebug("Unable to append Contact %s", c.fullName().latin1()); |
145 | } | 145 | } |
146 | else | 146 | else |
147 | { | 147 | { |
148 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | 148 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
149 | } | 149 | } |
150 | } | 150 | } |
151 | 151 | ||
152 | access->save(); | 152 | access->save(); |
153 | 153 | ||
154 | delete access; | 154 | delete access; |
155 | //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. |
156 | 156 | ||
157 | return true; | 157 | return true; |
158 | } | 158 | } |
159 | 159 | ||
160 | KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const | 160 | KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const |
161 | { | 161 | { |
162 | KABC::AddresseeList adrlst; | 162 | KABC::AddresseeList adrlst; |
163 | 163 | ||
164 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 164 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
165 | 165 | ||
166 | #ifndef KAB_EMBEDDED | 166 | #ifndef KAB_EMBEDDED |
167 | QString fileName = KFileDialog::getOpenFileName( name ); | 167 | QString fileName = KFileDialog::getOpenFileName( name ); |
168 | #else //KAB_EMBEDDED | 168 | #else //KAB_EMBEDDED |
169 | QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); | 169 | QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); |
170 | #endif //KAB_EMBEDDED | 170 | #endif //KAB_EMBEDDED |
171 | 171 | ||
172 | if ( fileName.isEmpty() ) | 172 | if ( fileName.isEmpty() ) |
173 | return KABC::AddresseeList(); | 173 | return KABC::AddresseeList(); |
174 | 174 | ||
175 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); | 175 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); |
176 | OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); | 176 | OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); |
177 | 177 | ||
178 | if ( !access ) { | 178 | if ( !access ) { |
179 | qDebug("Unable to access file() %s", fileName.latin1()); | 179 | qDebug("Unable to access file() %s", fileName.latin1()); |
180 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | 180 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); |
181 | return KABC::AddresseeList(); | 181 | return KABC::AddresseeList(); |
182 | } | 182 | } |
183 | 183 | ||
184 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | 184 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available |
185 | 185 | ||
186 | KABC::OpieConverter mConverter; | 186 | KABC::OpieConverter mConverter; |
187 | bool res = false; | ||
188 | 187 | ||
188 | bool res = mConverter.init(); | ||
189 | if (!res) | ||
190 | { | ||
191 | QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) ); | ||
192 | qDebug(text); | ||
193 | KMessageBox::error( parentWidget(), text ); | ||
194 | delete access; | ||
195 | return KABC::AddresseeList(); | ||
196 | } | ||
197 | |||
189 | 198 | ||
190 | OContactAccess::List::Iterator it; | 199 | OContactAccess::List::Iterator it; |
191 | OContactAccess::List allList = access->allRecords(); | 200 | OContactAccess::List allList = access->allRecords(); |
192 | for ( it = allList.begin(); it != allList.end(); ++it ) | 201 | for ( it = allList.begin(); it != allList.end(); ++it ) |
193 | { | 202 | { |
194 | OContact c = (*it); | 203 | OContact c = (*it); |
195 | 204 | ||
196 | KABC::Addressee addressee; | 205 | KABC::Addressee addressee; |
197 | 206 | ||
198 | res = mConverter.opieToAddressee( c, addressee ); | 207 | res = mConverter.opieToAddressee( c, addressee ); |
199 | 208 | ||
200 | if ( !addressee.isEmpty() && res ) { | 209 | if ( !addressee.isEmpty() && res ) { |
201 | adrlst.append( addressee ); | 210 | adrlst.append( addressee ); |
202 | } | 211 | } |
203 | 212 | ||
204 | // qDebug("found %s", c.fullName().latin1()); | 213 | // qDebug("found %s", c.fullName().latin1()); |
205 | } | 214 | } |
206 | 215 | ||
207 | delete access; | 216 | delete access; |
208 | //US the deletion of the access object deletes the backend object as well. | 217 | //US the deletion of the access object deletes the backend object as well. |
209 | 218 | ||
210 | return adrlst; | 219 | return adrlst; |
211 | 220 | ||
212 | } | 221 | } |
diff --git a/kaddressbook/xxport/qtopia/qtopia_xxport.cpp b/kaddressbook/xxport/qtopia/qtopia_xxport.cpp index 3d830df..bf39fdb 100644 --- a/kaddressbook/xxport/qtopia/qtopia_xxport.cpp +++ b/kaddressbook/xxport/qtopia/qtopia_xxport.cpp | |||
@@ -1,191 +1,201 @@ | |||
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 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (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 <qpe/pim/addressbookaccess.h> | 36 | #include <qpe/pim/addressbookaccess.h> |
37 | 37 | ||
38 | #include "stdaddressbook.h" | 38 | #include "stdaddressbook.h" |
39 | 39 | ||
40 | /*US | 40 | /*US |
41 | #include <qfile.h> | 41 | #include <qfile.h> |
42 | #include <qtextstream.h> | 42 | #include <qtextstream.h> |
43 | 43 | ||
44 | #include <kabc/vcardconverter.h> | 44 | #include <kabc/vcardconverter.h> |
45 | #ifndef KAB_EMBEDDED | 45 | #ifndef KAB_EMBEDDED |
46 | #include <kio/netaccess.h> | 46 | #include <kio/netaccess.h> |
47 | #endif //KAB_EMBEDDED | 47 | #endif //KAB_EMBEDDED |
48 | 48 | ||
49 | #include <klocale.h> | 49 | #include <klocale.h> |
50 | #include <kmessagebox.h> | 50 | #include <kmessagebox.h> |
51 | #include <ktempfile.h> | 51 | #include <ktempfile.h> |
52 | #include <kurl.h> | 52 | #include <kurl.h> |
53 | */ | 53 | */ |
54 | 54 | ||
55 | #include "xxportmanager.h" | 55 | #include "xxportmanager.h" |
56 | #include "qtopiaconverter.h" | 56 | #include "qtopiaconverter.h" |
57 | 57 | ||
58 | #include "qtopia_xxport.h" | 58 | #include "qtopia_xxport.h" |
59 | 59 | ||
60 | 60 | ||
61 | class QtopiaXXPortFactory : public XXPortFactory | 61 | class QtopiaXXPortFactory : public XXPortFactory |
62 | { | 62 | { |
63 | public: | 63 | public: |
64 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 64 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
65 | { | 65 | { |
66 | return new QtopiaXXPort( ab, parent, name ); | 66 | return new QtopiaXXPort( ab, parent, name ); |
67 | } | 67 | } |
68 | }; | 68 | }; |
69 | 69 | ||
70 | 70 | ||
71 | extern "C" | 71 | extern "C" |
72 | { | 72 | { |
73 | void *init_microkaddrbk_qtopia_xxport() | 73 | void *init_microkaddrbk_qtopia_xxport() |
74 | { | 74 | { |
75 | return ( new QtopiaXXPortFactory() ); | 75 | return ( new QtopiaXXPortFactory() ); |
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 80 | QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
81 | : XXPortObject( ab, parent, name ) | 81 | : XXPortObject( ab, parent, name ) |
82 | { | 82 | { |
83 | createImportAction( i18n( "Import Qtopia..." ) ); | 83 | createImportAction( i18n( "Import Qtopia..." ) ); |
84 | createExportAction( i18n( "Export Qtopia..." ) ); | 84 | createExportAction( i18n( "Export Qtopia..." ) ); |
85 | } | 85 | } |
86 | 86 | ||
87 | bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | 87 | bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) |
88 | { | 88 | { |
89 | // we can not choose the filename. Therefore use the default to display | 89 | // we can not choose the filename. Therefore use the default to display |
90 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 90 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
91 | 91 | ||
92 | AddressBookAccess* access = new AddressBookAccess(); | 92 | AddressBookAccess* access = new AddressBookAccess(); |
93 | 93 | ||
94 | if ( !access ) { | 94 | if ( !access ) { |
95 | QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | 95 | QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); |
96 | qDebug(text.latin1()); | 96 | qDebug(text.latin1()); |
97 | KMessageBox::error( parentWidget(), text ); | 97 | KMessageBox::error( parentWidget(), text ); |
98 | addressBook()->error( text ); | 98 | addressBook()->error( text ); |
99 | return false; | 99 | return false; |
100 | } | 100 | } |
101 | 101 | ||
102 | KABC::QtopiaConverter mConverter; | 102 | KABC::QtopiaConverter mConverter; |
103 | 103 | ||
104 | bool res = mConverter.init(); | 104 | bool res = mConverter.init(); |
105 | if (!res) | 105 | if (!res) |
106 | { | 106 | { |
107 | QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); | 107 | QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); |
108 | qDebug(text); | 108 | qDebug(text); |
109 | KMessageBox::error( parentWidget(), text ); | 109 | KMessageBox::error( parentWidget(), text ); |
110 | delete access; | 110 | delete access; |
111 | return false; | 111 | return false; |
112 | } | 112 | } |
113 | 113 | ||
114 | //Now check if the file has already entries, and ask the user if he wants to delete them first. | 114 | //Now check if the file has already entries, and ask the user if he wants to delete them first. |
115 | { //create a new scope | 115 | { //create a new scope |
116 | AddressBookIterator it(*access); | 116 | AddressBookIterator it(*access); |
117 | const PimContact* firstcontact = it.toFirst(); | 117 | const PimContact* firstcontact = it.toFirst(); |
118 | if (firstcontact) | 118 | if (firstcontact) |
119 | { | 119 | { |
120 | QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); | 120 | QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); |
121 | if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { | 121 | if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { |
122 | // Clean the database.. | 122 | // Clean the database.. |
123 | 123 | ||
124 | AddressBookIterator it2(*access); | 124 | AddressBookIterator it2(*access); |
125 | for (it2.toFirst(); it2.current(); ++it2) { | 125 | for (it2.toFirst(); it2.current(); ++it2) { |
126 | access->removeContact(*it2.current()); | 126 | access->removeContact(*it2.current()); |
127 | } | 127 | } |
128 | } | 128 | } |
129 | } | 129 | } |
130 | } | 130 | } |
131 | 131 | ||
132 | KABC::Addressee::List::ConstIterator it; | 132 | KABC::Addressee::List::ConstIterator it; |
133 | for ( it = list.begin(); it != list.end(); ++it ) { | 133 | for ( it = list.begin(); it != list.end(); ++it ) { |
134 | PimContact c; | 134 | PimContact c; |
135 | KABC::Addressee addressee = (*it); | 135 | KABC::Addressee addressee = (*it); |
136 | 136 | ||
137 | res = mConverter.addresseeToQtopia( *it, c ); | 137 | res = mConverter.addresseeToQtopia( *it, c ); |
138 | if (res == true) | 138 | if (res == true) |
139 | { | 139 | { |
140 | access->addContact(c); | 140 | access->addContact(c); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | delete access; | 144 | delete access; |
145 | 145 | ||
146 | return true; | 146 | return true; |
147 | } | 147 | } |
148 | 148 | ||
149 | KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const | 149 | KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const |
150 | { | 150 | { |
151 | KABC::AddresseeList adrlst; | 151 | KABC::AddresseeList adrlst; |
152 | 152 | ||
153 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 153 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
154 | 154 | ||
155 | AddressBookAccess* access = new AddressBookAccess(); | 155 | AddressBookAccess* access = new AddressBookAccess(); |
156 | 156 | ||
157 | if ( !access ) { | 157 | if ( !access ) { |
158 | QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | 158 | QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); |
159 | qDebug(text.latin1()); | 159 | qDebug(text.latin1()); |
160 | addressBook()->error( text ); | 160 | addressBook()->error( text ); |
161 | KMessageBox::error( parentWidget(), text ); | 161 | KMessageBox::error( parentWidget(), text ); |
162 | return KABC::AddresseeList(); | 162 | return KABC::AddresseeList(); |
163 | } | 163 | } |
164 | 164 | ||
165 | KABC::QtopiaConverter mConverter; | 165 | KABC::QtopiaConverter mConverter; |
166 | bool res = false; | ||
167 | 166 | ||
167 | bool res = mConverter.init(); | ||
168 | if (!res) | ||
169 | { | ||
170 | QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); | ||
171 | qDebug(text); | ||
172 | KMessageBox::error( parentWidget(), text ); | ||
173 | delete access; | ||
174 | return KABC::AddresseeList(); | ||
175 | } | ||
176 | |||
177 | |||
168 | 178 | ||
169 | { //create a new scope | 179 | { //create a new scope |
170 | AddressBookIterator it(*access); | 180 | AddressBookIterator it(*access); |
171 | 181 | ||
172 | for (it.toFirst(); it.current(); ++it) { | 182 | for (it.toFirst(); it.current(); ++it) { |
173 | const PimContact*contact = it.current(); | 183 | const PimContact*contact = it.current(); |
174 | 184 | ||
175 | KABC::Addressee addressee; | 185 | KABC::Addressee addressee; |
176 | 186 | ||
177 | res = mConverter.qtopiaToAddressee( (*contact), addressee ); | 187 | res = mConverter.qtopiaToAddressee( (*contact), addressee ); |
178 | 188 | ||
179 | if ( !addressee.isEmpty() && res ) | 189 | if ( !addressee.isEmpty() && res ) |
180 | { | 190 | { |
181 | adrlst.append( addressee ); | 191 | adrlst.append( addressee ); |
182 | } | 192 | } |
183 | } | 193 | } |
184 | } | 194 | } |
185 | 195 | ||
186 | delete access; | 196 | delete access; |
187 | //US the deletion of the access object deletes the backend object as well. | 197 | //US the deletion of the access object deletes the backend object as well. |
188 | 198 | ||
189 | return adrlst; | 199 | return adrlst; |
190 | 200 | ||
191 | } | 201 | } |