summaryrefslogtreecommitdiffabout
path: root/kabc
authorulf69 <ulf69>2004-07-16 01:16:48 (UTC)
committer ulf69 <ulf69>2004-07-16 01:16:48 (UTC)
commitdd3243de5d504c43987b0ef20243d9b499a6de3f (patch) (unidiff)
tree77606126c0e74fc74103e0dcd32b67e3f7047616 /kabc
parentd6589bebc11011fa7c4a96383e278202424b42eb (diff)
downloadkdepimpi-dd3243de5d504c43987b0ef20243d9b499a6de3f.zip
kdepimpi-dd3243de5d504c43987b0ef20243d9b499a6de3f.tar.gz
kdepimpi-dd3243de5d504c43987b0ef20243d9b499a6de3f.tar.bz2
first implementation of the sharp converter
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/converter/sharpdtm/sharpdtmE.pro30
-rw-r--r--kabc/converter/sharpdtm/sharpdtmconverter.cpp362
-rw-r--r--kabc/converter/sharpdtm/sharpdtmconverter.h81
3 files changed, 473 insertions, 0 deletions
diff --git a/kabc/converter/sharpdtm/sharpdtmE.pro b/kabc/converter/sharpdtm/sharpdtmE.pro
new file mode 100644
index 0000000..cd7032a
--- a/dev/null
+++ b/kabc/converter/sharpdtm/sharpdtmE.pro
@@ -0,0 +1,30 @@
1TEMPLATE = lib
2INCLUDEPATH += . ../.. ../../../external/sharpdtm/include ../../../microkde ../../../microkde/kdecore $(QPEDIR)/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 += -lqpepim
17LIBS += -lqpe
18LIBS += -lzdtm
19
20TARGET = microkabc_sharpdtmconverter
21
22# Input
23
24HEADERS += \
25 sharpdtmconverter.h \
26
27
28SOURCES += \
29 sharpdtmconverter.cpp \
30
diff --git a/kabc/converter/sharpdtm/sharpdtmconverter.cpp b/kabc/converter/sharpdtm/sharpdtmconverter.cpp
new file mode 100644
index 0000000..b3e2ee1
--- a/dev/null
+++ b/kabc/converter/sharpdtm/sharpdtmconverter.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/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include "kglobal.h"
29
30
31#include "sharpdtmconverter.h"
32
33#include <sl/slcategories.h>
34//US #include <qpe/categoryselect.h>
35
36
37using namespace KABC;
38using namespace SlCategory;
39
40SharpDTMConverter::SharpDTMConverter() : catDB(0)
41{
42}
43
44SharpDTMConverter::~SharpDTMConverter()
45{
46 deinit();
47}
48
49bool SharpDTMConverter::init()
50{
51 catDB = new SlCategory::SlCategories();
52
53 if (!catDB)
54 return false;
55
56// catDB->load( categoryFileName() );
57 return true;
58}
59
60void SharpDTMConverter::deinit()
61{
62 if (catDB)
63 {
64 delete catDB;
65 catDB = 0;
66 }
67}
68
69bool SharpDTMConverter::sharpToAddressee( const PimContact &contact, Addressee &addr )
70{
71/*US
72 // name
73 addr.setFormattedName(contact.fileAs());
74 addr.setFamilyName( contact.lastName() );
75 addr.setGivenName( contact.firstName() );
76 addr.setAdditionalName( contact.middleName() );
77 addr.setPrefix( contact.nameTitle() );
78 addr.setSuffix( contact.suffix() );
79
80
81 // email
82 QStringList emails = contact.emailList();
83 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
84 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
85 }
86
87 if (!contact.defaultEmail().isEmpty())
88 addr.insertEmail(contact.defaultEmail(), true);
89
90 // home
91 if ((!contact.homeStreet().isEmpty()) ||
92 (!contact.homeCity().isEmpty()) ||
93 (!contact.homeState().isEmpty()) ||
94 (!contact.homeZip().isEmpty()) ||
95 (!contact.homeCountry().isEmpty()))
96 {
97 Address homeaddress;
98 homeaddress.setType(Address::Home);
99//US homeaddress.setPostOfficeBox( "" );
100//US homeaddress.setExtended( "" );
101 homeaddress.setStreet( contact.homeStreet() );
102 homeaddress.setLocality( contact.homeCity() );
103 homeaddress.setRegion( contact.homeState() );
104 homeaddress.setPostalCode( contact.homeZip() );
105 homeaddress.setCountry( contact.homeCountry() );
106
107 addr.insertAddress( homeaddress );
108 }
109
110 if (!contact.homePhone().isEmpty())
111 {
112 PhoneNumber homephone;
113 homephone.setType( PhoneNumber::Home );
114 homephone.setNumber( contact.homePhone() );
115 addr.insertPhoneNumber( homephone );
116 }
117
118 if (!contact.homeFax().isEmpty())
119 {
120 PhoneNumber homefax;
121 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
122 homefax.setNumber( contact.homeFax() );
123 addr.insertPhoneNumber( homefax );
124 }
125
126 if (!contact.homeMobile().isEmpty())
127 {
128 PhoneNumber homemobile;
129 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
130 homemobile.setNumber( contact.homeMobile() );
131 addr.insertPhoneNumber( homemobile );
132 }
133
134 addr.setUrl( contact.homeWebpage() );
135
136
137 // business
138 if ((!contact.businessStreet().isEmpty()) ||
139 (!contact.businessCity().isEmpty()) ||
140 (!contact.businessState().isEmpty()) ||
141 (!contact.businessZip().isEmpty()) ||
142 (!contact.businessCountry().isEmpty()))
143 {
144 Address businessaddress;
145 businessaddress.setType(Address::Work);
146//US businessaddress.setPostOfficeBox( "" );
147//US businessaddress.setExtended( "" );
148 businessaddress.setStreet( contact.businessStreet() );
149 businessaddress.setLocality( contact.businessCity() );
150 businessaddress.setRegion( contact.businessState() );
151 businessaddress.setPostalCode( contact.businessZip() );
152 businessaddress.setCountry( contact.businessCountry() );
153
154 addr.insertAddress( businessaddress );
155 }
156
157
158 if (!contact.businessPhone().isEmpty())
159 {
160 PhoneNumber businessphone;
161 businessphone.setType( PhoneNumber::Work );
162 businessphone.setNumber( contact.businessPhone() );
163 addr.insertPhoneNumber( businessphone );
164 }
165
166 if (!contact.businessFax().isEmpty())
167 {
168 PhoneNumber businessfax;
169 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
170 businessfax.setNumber( contact.businessFax() );
171 addr.insertPhoneNumber( businessfax );
172 }
173
174 if (!contact.businessMobile().isEmpty())
175 {
176 PhoneNumber businessmobile;
177 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
178 businessmobile.setNumber( contact.businessMobile() );
179 addr.insertPhoneNumber( businessmobile );
180 }
181
182 if (!contact.businessPager().isEmpty())
183 {
184 PhoneNumber businesspager;
185 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
186 businesspager.setNumber( contact.businessPager() );
187 addr.insertPhoneNumber( businesspager );
188 }
189
190 addr.setRole( contact.jobTitle() ); //?
191 addr.setOrganization( contact.company() );
192 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() );
193 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() );
194 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() );
195 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() );
196 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() );
197
198 //personal
199 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
200 // qtopia uses this categorization:
201 // enum GenderType { UnspecifiedGender=0, Male, Female };
202 if (contact.gender() == PimContact::Male)
203 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male");
204 else if (contact.gender() == PimContact::Female)
205 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female");
206
207 if (contact.anniversary().isValid()) {
208 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate);
209//US
210// qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1());
211 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
212 }
213
214 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
215 if (contact.birthday().isValid())
216 addr.setBirthday( contact.birthday() );
217
218 addr.setNickName( contact.nickname() );
219
220 // others
221 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
222 QString notes = contact.notes();
223 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n";
224
225 addr.setNote( contact.notes() );
226
227
228
229//US QString groups() const { return find( Qtopia::Groups ); }
230//US QStringList groupList() const;
231
232 QArray<int> catArray = contact.categories();
233 QString cat;
234
235 for ( unsigned int i=0; i < catArray.size(); i++ ) {
236 cat = catDB->label("contact", catArray[i]);
237 if ( !cat.isEmpty() )
238 addr.insertCategory( cat );
239 }
240*/
241 return true;
242}
243
244bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, PimContact &contact )
245{
246/*US
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 // email
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/converter/sharpdtm/sharpdtmconverter.h b/kabc/converter/sharpdtm/sharpdtmconverter.h
new file mode 100644
index 0000000..85edea6
--- a/dev/null
+++ b/kabc/converter/sharpdtm/sharpdtmconverter.h
@@ -0,0 +1,81 @@
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_SHARPDTMCONVERTER_H
28#define KABC_SHARPDTMCONVERTER_H
29
30#include <qstring.h>
31
32#include "addressee.h"
33#include <qpe/pim/contact.h>
34
35namespace SlCategory {
36 class SlCategories;
37}
38
39namespace KABC {
40
41class SharpDTMConverter
42{
43public:
44
45 /**
46 * Constructor.
47 */
48 SharpDTMConverter();
49
50 /**
51 * Destructor.
52 */
53 virtual ~SharpDTMConverter();
54
55 bool init();
56 void deinit();
57
58 /**
59 * Converts a vcard string to an addressee.
60 *
61 * @param contact The sharp contact.
62 * @param addr The addressee.
63 */
64 bool sharpToAddressee( const PimContact &contact, Addressee &addr );
65
66 /**
67 * Converts an addressee to a sharp dtm contact.
68 *
69 * @param addr The addressee.
70 * @param contact The sharp contact.
71 */
72 bool addresseeToSharp( const Addressee &addr, PimContact &contact );
73
74 private:
75 SlCategory::SlCategories* catDB;
76
77
78};
79
80}
81#endif