summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-07-13 04:30:05 (UTC)
committer ulf69 <ulf69>2004-07-13 04:30:05 (UTC)
commitaee6b3ee8e225940cd2cbde0f881589694ee6af8 (patch) (unidiff)
treec0d9cf9e16c3c3d1aa1ce3183470a09a15905119
parenteb42916878f60819a2f57ccc14a7e2bac7addaf4 (diff)
downloadkdepimpi-aee6b3ee8e225940cd2cbde0f881589694ee6af8.zip
kdepimpi-aee6b3ee8e225940cd2cbde0f881589694ee6af8.tar.gz
kdepimpi-aee6b3ee8e225940cd2cbde0f881589694ee6af8.tar.bz2
add initial version of the qtopia converter
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/converter/qtopia/qtopiaE.pro32
-rw-r--r--kabc/converter/qtopia/qtopiaconverter.cpp353
-rw-r--r--kabc/converter/qtopia/qtopiaconverter.h79
3 files changed, 464 insertions, 0 deletions
diff --git a/kabc/converter/qtopia/qtopiaE.pro b/kabc/converter/qtopia/qtopiaE.pro
new file mode 100644
index 0000000..e026f2a
--- a/dev/null
+++ b/kabc/converter/qtopia/qtopiaE.pro
@@ -0,0 +1,32 @@
1TEMPLATE = lib
2INCLUDEPATH += . ../.. ../../../microkde ../../../microkde/kdecore $(OPIEDIR)/include $(OPEDIR)/include
3#CONFIG += staticlib
4OBJECTS_DIR = obj/$(PLATFORM)
5MOC_DIR = moc/$(PLATFORM)
6
7#for static linkage, put it here
8#DESTDIR=../../lib/$(PLATFORM)
9
10#for dynamic linkage, put it here
11DESTDIR=$(QPEDIR)/lib
12
13LIBS += -lmicrokde
14LIBS += -lmicrokabc
15LIBS += -L$(QPEDIR)/lib
16LIBS += -L$(OPIEDIR)/lib
17LIBS += -lopie
18LIBS += -lqpe
19LIBS += -lqte
20
21
22TARGET = microkabc_opieconverter
23
24# Input
25
26HEADERS += \
27 opieconverter.h \
28
29
30SOURCES += \
31 opieconverter.cpp \
32
diff --git a/kabc/converter/qtopia/qtopiaconverter.cpp b/kabc/converter/qtopia/qtopiaconverter.cpp
new file mode 100644
index 0000000..7aa76fe
--- a/dev/null
+++ b/kabc/converter/qtopia/qtopiaconverter.cpp
@@ -0,0 +1,353 @@
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/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28//US
29#include "kglobal.h"
30
31
32#include "qtopiaconverter.h"
33
34//US #include <qpe/categories.h>
35//US #include <qpe/categoryselect.h>
36
37
38using namespace KABC;
39
40QtopiaConverter::QtopiaConverter() : catDB(0)
41{
42}
43
44QtopiaConverter::~QtopiaConverter()
45{
46 deinit();
47}
48
49bool QtopiaConverter::init()
50{
51/*US
52 catDB = new Categories();
53 if (catDB)
54 {
55 catDB->load( categoryFileName() );
56 return true;
57 }
58 else
59 {
60 return false;
61 }
62*/
63return true;
64}
65
66void QtopiaConverter::deinit()
67{
68/*US
69 if (catDB)
70 {
71 delete catDB;
72 catDB = 0;
73 }
74*/
75}
76
77bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr )
78{
79 // name
80 addr.setFormattedName(contact.fileAs());
81 addr.setFamilyName( contact.lastName() );
82 addr.setGivenName( contact.firstName() );
83 addr.setAdditionalName( contact.middleName() );
84 addr.setPrefix( contact.title() );
85 addr.setSuffix( contact.suffix() );
86
87
88 // email
89 QStringList emails = contact.emailList();
90 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
91 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
92 }
93
94 if (!contact.defaultEmail().isEmpty())
95 addr.insertEmail(contact.defaultEmail(), true);
96
97 // home
98 if ((!contact.homeStreet().isEmpty()) ||
99 (!contact.homeCity().isEmpty()) ||
100 (!contact.homeState().isEmpty()) ||
101 (!contact.homeZip().isEmpty()) ||
102 (!contact.homeCountry().isEmpty()))
103 {
104 Address homeaddress;
105 homeaddress.setType(Address::Home);
106//US homeaddress.setPostOfficeBox( "" );
107//US homeaddress.setExtended( "" );
108 homeaddress.setStreet( contact.homeStreet() );
109 homeaddress.setLocality( contact.homeCity() );
110 homeaddress.setRegion( contact.homeState() );
111 homeaddress.setPostalCode( contact.homeZip() );
112 homeaddress.setCountry( contact.homeCountry() );
113
114 addr.insertAddress( homeaddress );
115 }
116
117 if (!contact.homePhone().isEmpty())
118 {
119 PhoneNumber homephone;
120 homephone.setType( PhoneNumber::Home );
121 homephone.setNumber( contact.homePhone() );
122 addr.insertPhoneNumber( homephone );
123 }
124
125 if (!contact.homeFax().isEmpty())
126 {
127 PhoneNumber homefax;
128 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
129 homefax.setNumber( contact.homeFax() );
130 addr.insertPhoneNumber( homefax );
131 }
132
133 if (!contact.homeMobile().isEmpty())
134 {
135 PhoneNumber homemobile;
136 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
137 homemobile.setNumber( contact.homeMobile() );
138 addr.insertPhoneNumber( homemobile );
139 }
140
141 addr.setUrl( contact.homeWebpage() );
142
143
144 // business
145 if ((!contact.businessStreet().isEmpty()) ||
146 (!contact.businessCity().isEmpty()) ||
147 (!contact.businessState().isEmpty()) ||
148 (!contact.businessZip().isEmpty()) ||
149 (!contact.businessCountry().isEmpty()))
150 {
151 Address businessaddress;
152 businessaddress.setType(Address::Work);
153//US businessaddress.setPostOfficeBox( "" );
154//US businessaddress.setExtended( "" );
155 businessaddress.setStreet( contact.businessStreet() );
156 businessaddress.setLocality( contact.businessCity() );
157 businessaddress.setRegion( contact.businessState() );
158 businessaddress.setPostalCode( contact.businessZip() );
159 businessaddress.setCountry( contact.businessCountry() );
160
161 addr.insertAddress( businessaddress );
162 }
163
164
165 if (!contact.businessPhone().isEmpty())
166 {
167 PhoneNumber businessphone;
168 businessphone.setType( PhoneNumber::Work );
169 businessphone.setNumber( contact.businessPhone() );
170 addr.insertPhoneNumber( businessphone );
171 }
172
173 if (!contact.businessFax().isEmpty())
174 {
175 PhoneNumber businessfax;
176 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
177 businessfax.setNumber( contact.businessFax() );
178 addr.insertPhoneNumber( businessfax );
179 }
180
181 if (!contact.businessMobile().isEmpty())
182 {
183 PhoneNumber businessmobile;
184 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
185 businessmobile.setNumber( contact.businessMobile() );
186 addr.insertPhoneNumber( businessmobile );
187 }
188
189 if (!contact.businessPager().isEmpty())
190 {
191 PhoneNumber businesspager;
192 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
193 businesspager.setNumber( contact.businessPager() );
194 addr.insertPhoneNumber( businesspager );
195 }
196
197 addr.setRole( contact.jobTitle() ); //?
198 addr.setOrganization( contact.company() );
199 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() );
200 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() );
201 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() );
202 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() );
203 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() );
204
205 //personal
206 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
207 addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() );
208
209 if (contact.anniversary().isValid()) {
210 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate);
211//US
212 qDebug("OpieConverter::opieToAddressee found:%s", dt.latin1());
213 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
214 }
215
216 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
217 if (contact.birthday().isValid())
218 addr.setBirthday( contact.birthday() );
219
220 addr.setNickName( contact.nickname() );
221
222 // others
223 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
224 QString notes = contact.notes();
225 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n";
226
227 addr.setNote( contact.notes() );
228
229
230
231//US QString groups() const { return find( Qtopia::Groups ); }
232//US QStringList groupList() const;
233
234
235 QStringList cats = contact.categoryNames("Contacts");
236 addr.setCategories( cats );
237// for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
238// qDebug("Cat: %s", (*it).latin1());
239// }
240
241 return true;
242}
243
244bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact )
245{
246 // name
247 contact.setLastName(addr.familyName());
248 contact.setFirstName(addr.givenName());
249 contact.setMiddleName(addr.additionalName());
250 contact.setTitle(addr.prefix());
251 contact.setSuffix(addr.suffix());
252 contact.setFileAs();
253
254
255 // email
256 QStringList emails = addr.emails();
257 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
258 contact.insertEmail(*it);
259 }
260 contact.setDefaultEmail( addr.preferredEmail() );
261
262
263 // home
264 const Address homeaddress = addr.address(Address::Home);
265 if (!homeaddress.isEmpty()) {
266 contact.setHomeStreet(homeaddress.street());
267 contact.setHomeCity(homeaddress.locality());
268 contact.setHomeState(homeaddress.region());
269 contact.setHomeZip(homeaddress.postalCode());
270 contact.setHomeCountry(homeaddress.country());
271 }
272
273 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
274 if (!homephone.number().isEmpty())
275 contact.setHomePhone(homephone.number());
276
277 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
278 if (!homefax.number().isEmpty())
279 contact.setHomeFax(homefax.number());
280
281 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
282 if (!homemobile.number().isEmpty())
283 contact.setHomeMobile(homemobile.number());
284
285 contact.setHomeWebpage(addr.url().url());
286
287
288 // business
289 const Address businessaddress = addr.address(Address::Work);
290 if (!businessaddress.isEmpty()) {
291 contact.setBusinessStreet(businessaddress.street());
292 contact.setBusinessCity(businessaddress.locality());
293 contact.setBusinessState(businessaddress.region());
294 contact.setBusinessZip(businessaddress.postalCode());
295 contact.setBusinessCountry(businessaddress.country());
296 }
297
298 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work );
299 if (!businessphone.number().isEmpty())
300 contact.setBusinessPhone(businessphone.number());
301
302 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax );
303 if (!businessfax.number().isEmpty())
304 contact.setBusinessFax(businessfax.number());
305
306 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell );
307 if (!businessmobile.number().isEmpty())
308 contact.setBusinessMobile(businessmobile.number());
309
310 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager );
311 if (!businesspager.number().isEmpty())
312 contact.setBusinessPager(businesspager.number());
313
314 contact.setJobTitle(addr.role());
315 contact.setCompany(addr.organization());
316
317 contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" ));
318 contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" ));
319 contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" ));
320 contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" ));
321 contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" ));
322
323 //personal
324 contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" ));
325 contact.setGender(addr.custom( "KADDRESSBOOK", "X-Gender" ));
326
327 QDate dt = KGlobal::locale()->readDate(
328 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
329 contact.setAnniversary( dt );
330
331 contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" ));
332
333 contact.setBirthday(addr.birthday().date());
334 contact.setNickname(addr.nickName());
335
336 // other
337 contact.setNotes(addr.note());
338
339//US QString groups() const { return find( Qtopia::Groups ); }
340//US QStringList groupList() const;
341
342
343/*US
344 QStringList cats = addr.categories();
345
346 QArray<int> iar;
347 if ( !cats.isEmpty() ) {
348 QArray<int> iar = catDB.ids("contact", cats);
349 contact.setCategories(iar);
350 }
351*/
352 return true;
353}
diff --git a/kabc/converter/qtopia/qtopiaconverter.h b/kabc/converter/qtopia/qtopiaconverter.h
new file mode 100644
index 0000000..aaa267a
--- a/dev/null
+++ b/kabc/converter/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/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (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//US class Categories;
36
37namespace KABC {
38
39class QtopiaConverter
40{
41public:
42
43 /**
44 * Constructor.
45 */
46 QtopiaConverter();
47
48 /**
49 * Destructor.
50 */
51 virtual ~QtopiaConverter();
52
53 virtual bool init();
54 virtual 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//US Categories* catDB;
74
75
76};
77
78}
79#endif