-rw-r--r-- | kabc/plugins/qtopia/qtopiaE.pro | 11 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 362 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.h | 79 |
3 files changed, 447 insertions, 5 deletions
diff --git a/kabc/plugins/qtopia/qtopiaE.pro b/kabc/plugins/qtopia/qtopiaE.pro index d9fa87f..56eae87 100644 --- a/kabc/plugins/qtopia/qtopiaE.pro +++ b/kabc/plugins/qtopia/qtopiaE.pro | |||
@@ -4,5 +4,5 @@ CONFIG += qt warn_on | |||
4 | TARGET = microkabc_qtopia | 4 | TARGET = microkabc_qtopia |
5 | 5 | ||
6 | INCLUDEPATH += ../.. ../../converter/qtopia ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include | 6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include |
7 | 7 | ||
8 | OBJECTS_DIR = obj/$(PLATFORM) | 8 | OBJECTS_DIR = obj/$(PLATFORM) |
@@ -14,5 +14,4 @@ LIBS += -L$(QPEDIR)/lib | |||
14 | LIBS += -lqpepim | 14 | LIBS += -lqpepim |
15 | LIBS += -lqpe | 15 | LIBS += -lqpe |
16 | LIBS += -lmicrokabc_qtopiaconverter | ||
17 | 16 | ||
18 | INTERFACES = \ | 17 | INTERFACES = \ |
@@ -20,7 +19,9 @@ INTERFACES = \ | |||
20 | HEADERS = \ | 19 | HEADERS = \ |
21 | resourceqtopia.h \ | 20 | resourceqtopia.h \ |
22 | resourceqtopiaconfig.h | 21 | resourceqtopiaconfig.h \ |
23 | 22 | qtopiaconverter.h | |
23 | |||
24 | SOURCES = \ | 24 | SOURCES = \ |
25 | resourceqtopia.cpp \ | 25 | resourceqtopia.cpp \ |
26 | resourceqtopiaconfig.cpp | 26 | resourceqtopiaconfig.cpp \ |
27 | qtopiaconverter.cpp | ||
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp new file mode 100644 index 0000000..ac513b6 --- a/dev/null +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp | |||
@@ -0,0 +1,362 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | //US | ||
29 | #include "kglobal.h" | ||
30 | |||
31 | |||
32 | #include "qtopiaconverter.h" | ||
33 | |||
34 | #include <qpe/categories.h> | ||
35 | //US #include <qpe/categoryselect.h> | ||
36 | |||
37 | |||
38 | using namespace KABC; | ||
39 | |||
40 | QtopiaConverter::QtopiaConverter() : catDB(0) | ||
41 | { | ||
42 | } | ||
43 | |||
44 | QtopiaConverter::~QtopiaConverter() | ||
45 | { | ||
46 | deinit(); | ||
47 | } | ||
48 | |||
49 | bool QtopiaConverter::init() | ||
50 | { | ||
51 | catDB = new Categories(); | ||
52 | |||
53 | if (!catDB) | ||
54 | return false; | ||
55 | |||
56 | catDB->load( categoryFileName() ); | ||
57 | return true; | ||
58 | } | ||
59 | |||
60 | void QtopiaConverter::deinit() | ||
61 | { | ||
62 | if (catDB) | ||
63 | { | ||
64 | delete catDB; | ||
65 | catDB = 0; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) | ||
70 | { | ||
71 | // name | ||
72 | addr.setFormattedName(contact.fileAs()); | ||
73 | addr.setFamilyName( contact.lastName() ); | ||
74 | addr.setGivenName( contact.firstName() ); | ||
75 | addr.setAdditionalName( contact.middleName() ); | ||
76 | addr.setPrefix( contact.nameTitle() ); | ||
77 | addr.setSuffix( contact.suffix() ); | ||
78 | |||
79 | |||
80 | |||
81 | QStringList emails = contact.emailList(); | ||
82 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | ||
83 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); | ||
84 | } | ||
85 | |||
86 | if (!contact.defaultEmail().isEmpty()) | ||
87 | addr.insertEmail(contact.defaultEmail(), true); | ||
88 | |||
89 | // home | ||
90 | if ((!contact.homeStreet().isEmpty()) || | ||
91 | (!contact.homeCity().isEmpty()) || | ||
92 | (!contact.homeState().isEmpty()) || | ||
93 | (!contact.homeZip().isEmpty()) || | ||
94 | (!contact.homeCountry().isEmpty())) | ||
95 | { | ||
96 | Address homeaddress; | ||
97 | homeaddress.setType(Address::Home); | ||
98 | //US homeaddress.setPostOfficeBox( "" ); | ||
99 | //US homeaddress.setExtended( "" ); | ||
100 | homeaddress.setStreet( contact.homeStreet() ); | ||
101 | homeaddress.setLocality( contact.homeCity() ); | ||
102 | homeaddress.setRegion( contact.homeState() ); | ||
103 | homeaddress.setPostalCode( contact.homeZip() ); | ||
104 | homeaddress.setCountry( contact.homeCountry() ); | ||
105 | |||
106 | addr.insertAddress( homeaddress ); | ||
107 | } | ||
108 | |||
109 | if (!contact.homePhone().isEmpty()) | ||
110 | { | ||
111 | PhoneNumber homephone; | ||
112 | homephone.setType( PhoneNumber::Home ); | ||
113 | homephone.setNumber( contact.homePhone() ); | ||
114 | addr.insertPhoneNumber( homephone ); | ||
115 | } | ||
116 | |||
117 | if (!contact.homeFax().isEmpty()) | ||
118 | { | ||
119 | PhoneNumber homefax; | ||
120 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); | ||
121 | homefax.setNumber( contact.homeFax() ); | ||
122 | addr.insertPhoneNumber( homefax ); | ||
123 | } | ||
124 | |||
125 | if (!contact.homeMobile().isEmpty()) | ||
126 | { | ||
127 | PhoneNumber homemobile; | ||
128 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); | ||
129 | homemobile.setNumber( contact.homeMobile() ); | ||
130 | addr.insertPhoneNumber( homemobile ); | ||
131 | } | ||
132 | |||
133 | addr.setUrl( contact.homeWebpage() ); | ||
134 | |||
135 | |||
136 | // business | ||
137 | if ((!contact.businessStreet().isEmpty()) || | ||
138 | (!contact.businessCity().isEmpty()) || | ||
139 | (!contact.businessState().isEmpty()) || | ||
140 | (!contact.businessZip().isEmpty()) || | ||
141 | (!contact.businessCountry().isEmpty())) | ||
142 | { | ||
143 | Address businessaddress; | ||
144 | businessaddress.setType(Address::Work); | ||
145 | //US businessaddress.setPostOfficeBox( "" ); | ||
146 | //US businessaddress.setExtended( "" ); | ||
147 | businessaddress.setStreet( contact.businessStreet() ); | ||
148 | businessaddress.setLocality( contact.businessCity() ); | ||
149 | businessaddress.setRegion( contact.businessState() ); | ||
150 | businessaddress.setPostalCode( contact.businessZip() ); | ||
151 | businessaddress.setCountry( contact.businessCountry() ); | ||
152 | |||
153 | addr.insertAddress( businessaddress ); | ||
154 | } | ||
155 | |||
156 | |||
157 | if (!contact.businessPhone().isEmpty()) | ||
158 | { | ||
159 | PhoneNumber businessphone; | ||
160 | businessphone.setType( PhoneNumber::Work ); | ||
161 | businessphone.setNumber( contact.businessPhone() ); | ||
162 | addr.insertPhoneNumber( businessphone ); | ||
163 | } | ||
164 | |||
165 | if (!contact.businessFax().isEmpty()) | ||
166 | { | ||
167 | PhoneNumber businessfax; | ||
168 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); | ||
169 | businessfax.setNumber( contact.businessFax() ); | ||
170 | addr.insertPhoneNumber( businessfax ); | ||
171 | } | ||
172 | |||
173 | if (!contact.businessMobile().isEmpty()) | ||
174 | { | ||
175 | PhoneNumber businessmobile; | ||
176 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); | ||
177 | businessmobile.setNumber( contact.businessMobile() ); | ||
178 | addr.insertPhoneNumber( businessmobile ); | ||
179 | } | ||
180 | |||
181 | if (!contact.businessPager().isEmpty()) | ||
182 | { | ||
183 | PhoneNumber businesspager; | ||
184 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); | ||
185 | businesspager.setNumber( contact.businessPager() ); | ||
186 | addr.insertPhoneNumber( businesspager ); | ||
187 | } | ||
188 | |||
189 | addr.setRole( contact.jobTitle() ); //? | ||
190 | addr.setOrganization( contact.company() ); | ||
191 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); | ||
192 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); | ||
193 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); | ||
194 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); | ||
195 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); | ||
196 | |||
197 | //personal | ||
198 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); | ||
199 | // qtopia uses this categorization: | ||
200 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | ||
201 | if (contact.gender() == PimContact::Male) | ||
202 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); | ||
203 | else if (contact.gender() == PimContact::Female) | ||
204 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); | ||
205 | |||
206 | if (contact.anniversary().isValid()) { | ||
207 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); | ||
208 | //US | ||
209 | // qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); | ||
210 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | ||
211 | } | ||
212 | |||
213 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); | ||
214 | if (contact.birthday().isValid()) | ||
215 | addr.setBirthday( contact.birthday() ); | ||
216 | |||
217 | addr.setNickName( contact.nickname() ); | ||
218 | |||
219 | // others | ||
220 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. | ||
221 | QString notes = contact.notes(); | ||
222 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; | ||
223 | |||
224 | addr.setNote( contact.notes() ); | ||
225 | |||
226 | |||
227 | |||
228 | //US QString groups() const { return find( Qtopia::Groups ); } | ||
229 | //US QStringList groupList() const; | ||
230 | |||
231 | QArray<int> catArray = contact.categories(); | ||
232 | QString cat; | ||
233 | |||
234 | for ( unsigned int i=0; i < catArray.size(); i++ ) { | ||
235 | cat = catDB->label("contact", catArray[i]); | ||
236 | if ( cat.isEmpty() ) | ||
237 | addr.insertCategory(QString::number(catArray[i])); | ||
238 | else | ||
239 | addr.insertCategory( cat ); | ||
240 | } | ||
241 | |||
242 | return true; | ||
243 | } | ||
244 | |||
245 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) | ||
246 | { | ||
247 | // name | ||
248 | contact.setLastName(addr.familyName()); | ||
249 | contact.setFirstName(addr.givenName()); | ||
250 | contact.setMiddleName(addr.additionalName()); | ||
251 | contact.setNameTitle(addr.prefix()); | ||
252 | contact.setSuffix(addr.suffix()); | ||
253 | contact.setFileAs(); | ||
254 | |||
255 | |||
256 | |||
257 | QStringList emails = addr.emails(); | ||
258 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | ||
259 | contact.insertEmail(*it); | ||
260 | } | ||
261 | contact.setDefaultEmail( addr.preferredEmail() ); | ||
262 | |||
263 | |||
264 | // home | ||
265 | const Address homeaddress = addr.address(Address::Home); | ||
266 | if (!homeaddress.isEmpty()) { | ||
267 | contact.setHomeStreet(homeaddress.street()); | ||
268 | contact.setHomeCity(homeaddress.locality()); | ||
269 | contact.setHomeState(homeaddress.region()); | ||
270 | contact.setHomeZip(homeaddress.postalCode()); | ||
271 | contact.setHomeCountry(homeaddress.country()); | ||
272 | } | ||
273 | |||
274 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); | ||
275 | if (!homephone.number().isEmpty()) | ||
276 | contact.setHomePhone(homephone.number()); | ||
277 | |||
278 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); | ||
279 | if (!homefax.number().isEmpty()) | ||
280 | contact.setHomeFax(homefax.number()); | ||
281 | |||
282 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); | ||
283 | if (!homemobile.number().isEmpty()) | ||
284 | contact.setHomeMobile(homemobile.number()); | ||
285 | |||
286 | contact.setHomeWebpage(addr.url().url()); | ||
287 | |||
288 | |||
289 | // business | ||
290 | const Address businessaddress = addr.address(Address::Work); | ||
291 | if (!businessaddress.isEmpty()) { | ||
292 | contact.setBusinessStreet(businessaddress.street()); | ||
293 | contact.setBusinessCity(businessaddress.locality()); | ||
294 | contact.setBusinessState(businessaddress.region()); | ||
295 | contact.setBusinessZip(businessaddress.postalCode()); | ||
296 | contact.setBusinessCountry(businessaddress.country()); | ||
297 | } | ||
298 | |||
299 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); | ||
300 | if (!businessphone.number().isEmpty()) | ||
301 | contact.setBusinessPhone(businessphone.number()); | ||
302 | |||
303 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); | ||
304 | if (!businessfax.number().isEmpty()) | ||
305 | contact.setBusinessFax(businessfax.number()); | ||
306 | |||
307 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); | ||
308 | if (!businessmobile.number().isEmpty()) | ||
309 | contact.setBusinessMobile(businessmobile.number()); | ||
310 | |||
311 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); | ||
312 | if (!businesspager.number().isEmpty()) | ||
313 | contact.setBusinessPager(businesspager.number()); | ||
314 | |||
315 | contact.setJobTitle(addr.role()); | ||
316 | contact.setCompany(addr.organization()); | ||
317 | |||
318 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); | ||
319 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); | ||
320 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); | ||
321 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); | ||
322 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); | ||
323 | |||
324 | //personal | ||
325 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); | ||
326 | // qtopia uses this categorization: | ||
327 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | ||
328 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); | ||
329 | if (gt = "male") | ||
330 | contact.setGender(PimContact::Male); | ||
331 | else if (gt = "female") | ||
332 | contact.setGender(PimContact::Female); | ||
333 | else | ||
334 | contact.setGender(PimContact::UnspecifiedGender); | ||
335 | |||
336 | |||
337 | QDate dt = KGlobal::locale()->readDate( | ||
338 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate | ||
339 | contact.setAnniversary( dt ); | ||
340 | |||
341 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); | ||
342 | |||
343 | contact.setBirthday(addr.birthday().date()); | ||
344 | contact.setNickname(addr.nickName()); | ||
345 | |||
346 | // other | ||
347 | contact.setNotes(addr.note()); | ||
348 | |||
349 | //US QString groups() const { return find( Qtopia::Groups ); } | ||
350 | //US QStringList groupList() const; | ||
351 | |||
352 | |||
353 | QStringList cats = addr.categories(); | ||
354 | |||
355 | QArray<int> iar; | ||
356 | if ( !cats.isEmpty() ) { | ||
357 | QArray<int> iar = catDB->ids("contact", cats); | ||
358 | contact.setCategories(iar); | ||
359 | } | ||
360 | |||
361 | return true; | ||
362 | } | ||
diff --git a/kabc/plugins/qtopia/qtopiaconverter.h b/kabc/plugins/qtopia/qtopiaconverter.h new file mode 100644 index 0000000..8f4c698 --- a/dev/null +++ b/kabc/plugins/qtopia/qtopiaconverter.h | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | $Id$ | ||
25 | */ | ||
26 | |||
27 | #ifndef KABC_QTOPIACONVERTER_H | ||
28 | #define KABC_QTOPIACONVERTER_H | ||
29 | |||
30 | #include <qstring.h> | ||
31 | |||
32 | #include "addressee.h" | ||
33 | #include <qpe/pim/contact.h> | ||
34 | |||
35 | class Categories; | ||
36 | |||
37 | namespace KABC { | ||
38 | |||
39 | class QtopiaConverter | ||
40 | { | ||
41 | public: | ||
42 | |||
43 | /** | ||
44 | * Constructor. | ||
45 | */ | ||
46 | QtopiaConverter(); | ||
47 | |||
48 | /** | ||
49 | * Destructor. | ||
50 | */ | ||
51 | virtual ~QtopiaConverter(); | ||
52 | |||
53 | bool init(); | ||
54 | void deinit(); | ||
55 | |||
56 | /** | ||
57 | * Converts a vcard string to an addressee. | ||
58 | * | ||
59 | * @param contact The qtopia contact. | ||
60 | * @param addr The addressee. | ||
61 | */ | ||
62 | bool qtopiaToAddressee( const PimContact &contact, Addressee &addr ); | ||
63 | |||
64 | /** | ||
65 | * Converts an addressee to a vcard string. | ||
66 | * | ||
67 | * @param addr The addressee. | ||
68 | * @param contact The qtopia contact. | ||
69 | */ | ||
70 | bool addresseeToQtopia( const Addressee &addr, PimContact &contact ); | ||
71 | |||
72 | private: | ||
73 | Categories* catDB; | ||
74 | |||
75 | |||
76 | }; | ||
77 | |||
78 | } | ||
79 | #endif | ||