summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
authorulf69 <ulf69>2004-07-26 22:10:28 (UTC)
committer ulf69 <ulf69>2004-07-26 22:10:28 (UTC)
commitd7336fb5466f19b2757392fa96b7c4eb713b7bd9 (patch) (unidiff)
tree6878487c18874a09a83ef44dfc75f11be56b242a /kabc/plugins
parentcd4e3730fed61ca0a2c4195bff83669d7ae6610c (diff)
downloadkdepimpi-d7336fb5466f19b2757392fa96b7c4eb713b7bd9.zip
kdepimpi-d7336fb5466f19b2757392fa96b7c4eb713b7bd9.tar.gz
kdepimpi-d7336fb5466f19b2757392fa96b7c4eb713b7bd9.tar.bz2
added the converter to the resource plugin. That makes the sync impl easier
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/opie/opieE.pro9
-rw-r--r--kabc/plugins/opie/opieconverter.cpp355
-rw-r--r--kabc/plugins/opie/opieconverter.h80
3 files changed, 439 insertions, 5 deletions
diff --git a/kabc/plugins/opie/opieE.pro b/kabc/plugins/opie/opieE.pro
index 4048cc0..8d45c3d 100644
--- a/kabc/plugins/opie/opieE.pro
+++ b/kabc/plugins/opie/opieE.pro
@@ -1,32 +1,31 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3#release debug 3#release debug
4TARGET = microkabc_opie 4TARGET = microkabc_opie
5 5
6INCLUDEPATH += ../.. ../../converter/opie ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include $(OPIEDIR)/include 6INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include $(OPIEDIR)/include
7 7
8 8
9OBJECTS_DIR = obj/$(PLATFORM) 9OBJECTS_DIR = obj/$(PLATFORM)
10MOC_DIR = moc/$(PLATFORM) 10MOC_DIR = moc/$(PLATFORM)
11DESTDIR = $(QPEDIR)/lib 11DESTDIR = $(QPEDIR)/lib
12LIBS += -lmicrokde 12LIBS += -lmicrokde
13LIBS += -lmicrokabc 13LIBS += -lmicrokabc
14LIBS += -L$(QPEDIR)/lib 14LIBS += -L$(QPEDIR)/lib
15LIBS += -L$(OPIEDIR)/lib 15LIBS += -L$(OPIEDIR)/lib
16LIBS += -lopie 16LIBS += -lopie
17LIBS += -lqpe 17LIBS += -lqpe
18LIBS += -lqte 18LIBS += -lqte
19LIBS += -lmicrokabc_opieconverter
20#LIBS += -L../../lib/$(PLATFORM)
21
22 19
23INTERFACES = \ 20INTERFACES = \
24 21
25HEADERS = \ 22HEADERS = \
26 resourceopie.h \ 23 resourceopie.h \
27 resourceopieconfig.h \ 24 resourceopieconfig.h \
25 opieconverter.h \
28 26
29SOURCES = \ 27SOURCES = \
30 resourceopie.cpp \ 28 resourceopie.cpp \
31 resourceopieconfig.cpp \ 29 resourceopieconfig.cpp \
32 30 opieconverter.cpp \
31
diff --git a/kabc/plugins/opie/opieconverter.cpp b/kabc/plugins/opie/opieconverter.cpp
new file mode 100644
index 0000000..46e14dd
--- a/dev/null
+++ b/kabc/plugins/opie/opieconverter.cpp
@@ -0,0 +1,355 @@
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 "opieconverter.h"
33
34#include <qpe/categories.h>
35#include <qpe/categoryselect.h>
36
37
38using namespace KABC;
39
40OpieConverter::OpieConverter() : catDB(0)
41{
42}
43
44OpieConverter::~OpieConverter()
45{
46 deinit();
47}
48
49bool OpieConverter::init()
50{
51 catDB = new Categories();
52 if (catDB)
53 {
54 catDB->load( categoryFileName() );
55 return true;
56 }
57 else
58 {
59 return false;
60 }
61
62}
63
64void OpieConverter::deinit()
65{
66 if (catDB)
67 {
68 delete catDB;
69 catDB = 0;
70 }
71}
72
73bool OpieConverter::opieToAddressee( const OContact &contact, Addressee &addr )
74{
75 // name
76 addr.setFormattedName(contact.fileAs());
77 addr.setFamilyName( contact.lastName() );
78 addr.setGivenName( contact.firstName() );
79 addr.setAdditionalName( contact.middleName() );
80 addr.setPrefix( contact.title() );
81 addr.setSuffix( contact.suffix() );
82
83
84 // email
85 QStringList emails = contact.emailList();
86 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
87 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
88 }
89
90 if (!contact.defaultEmail().isEmpty())
91 addr.insertEmail(contact.defaultEmail(), true);
92
93 // home
94 if ((!contact.homeStreet().isEmpty()) ||
95 (!contact.homeCity().isEmpty()) ||
96 (!contact.homeState().isEmpty()) ||
97 (!contact.homeZip().isEmpty()) ||
98 (!contact.homeCountry().isEmpty()))
99 {
100 Address homeaddress;
101 homeaddress.setType(Address::Home);
102//US homeaddress.setPostOfficeBox( "" );
103//US homeaddress.setExtended( "" );
104 homeaddress.setStreet( contact.homeStreet() );
105 homeaddress.setLocality( contact.homeCity() );
106 homeaddress.setRegion( contact.homeState() );
107 homeaddress.setPostalCode( contact.homeZip() );
108 homeaddress.setCountry( contact.homeCountry() );
109
110 addr.insertAddress( homeaddress );
111 }
112
113 if (!contact.homePhone().isEmpty())
114 {
115 PhoneNumber homephone;
116 homephone.setType( PhoneNumber::Home );
117 homephone.setNumber( contact.homePhone() );
118 addr.insertPhoneNumber( homephone );
119 }
120
121 if (!contact.homeFax().isEmpty())
122 {
123 PhoneNumber homefax;
124 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
125 homefax.setNumber( contact.homeFax() );
126 addr.insertPhoneNumber( homefax );
127 }
128
129 if (!contact.homeMobile().isEmpty())
130 {
131 PhoneNumber homemobile;
132 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
133 homemobile.setNumber( contact.homeMobile() );
134 addr.insertPhoneNumber( homemobile );
135 }
136
137 addr.setUrl( contact.homeWebpage() );
138
139
140 // business
141 if ((!contact.businessStreet().isEmpty()) ||
142 (!contact.businessCity().isEmpty()) ||
143 (!contact.businessState().isEmpty()) ||
144 (!contact.businessZip().isEmpty()) ||
145 (!contact.businessCountry().isEmpty()))
146 {
147 Address businessaddress;
148 businessaddress.setType(Address::Work);
149//US businessaddress.setPostOfficeBox( "" );
150//US businessaddress.setExtended( "" );
151 businessaddress.setStreet( contact.businessStreet() );
152 businessaddress.setLocality( contact.businessCity() );
153 businessaddress.setRegion( contact.businessState() );
154 businessaddress.setPostalCode( contact.businessZip() );
155 businessaddress.setCountry( contact.businessCountry() );
156
157 addr.insertAddress( businessaddress );
158 }
159
160
161 if (!contact.businessPhone().isEmpty())
162 {
163 PhoneNumber businessphone;
164 businessphone.setType( PhoneNumber::Work );
165 businessphone.setNumber( contact.businessPhone() );
166 addr.insertPhoneNumber( businessphone );
167 }
168
169 if (!contact.businessFax().isEmpty())
170 {
171 PhoneNumber businessfax;
172 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
173 businessfax.setNumber( contact.businessFax() );
174 addr.insertPhoneNumber( businessfax );
175 }
176
177 if (!contact.businessMobile().isEmpty())
178 {
179 PhoneNumber businessmobile;
180 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
181 businessmobile.setNumber( contact.businessMobile() );
182 addr.insertPhoneNumber( businessmobile );
183 }
184
185 if (!contact.businessPager().isEmpty())
186 {
187 PhoneNumber businesspager;
188 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
189 businesspager.setNumber( contact.businessPager() );
190 addr.insertPhoneNumber( businesspager );
191 }
192
193 addr.setRole( contact.jobTitle() ); //?
194 addr.setOrganization( contact.company() );
195 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() );
196 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() );
197 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() );
198 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() );
199 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() );
200
201 //personal
202 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
203 if (contact.gender() == 1)
204 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female" );
205 else if (contact.gender() == 2)
206 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male" );
207
208 if (contact.anniversary().isValid()) {
209 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate);
210//US
211 qDebug("OpieConverter::opieToAddressee found:%s", dt.latin1());
212 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
213 }
214
215 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
216 if (contact.birthday().isValid())
217 addr.setBirthday( contact.birthday() );
218
219 addr.setNickName( contact.nickname() );
220
221 // others
222 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
223 QString notes = contact.notes();
224 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n";
225
226 addr.setNote( contact.notes() );
227
228
229
230//US QString groups() const { return find( Qtopia::Groups ); }
231//US QStringList groupList() const;
232
233
234 QStringList cats = contact.categoryNames("Contacts");
235 addr.setCategories( cats );
236// for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
237// qDebug("Cat: %s", (*it).latin1());
238// }
239
240
241 return true;
242}
243
244bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &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 QString gend = addr.custom( "KADDRESSBOOK", "X-Gender" );
326 if (gend == "female")
327 contact.setGender("1");
328 else if (gend == "male")
329 contact.setGender("2");
330
331 QDate dt = KGlobal::locale()->readDate(
332 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
333 contact.setAnniversary( dt );
334
335 contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" ));
336
337 contact.setBirthday(addr.birthday().date());
338 contact.setNickname(addr.nickName());
339
340 // other
341 contact.setNotes(addr.note());
342
343//US QString groups() const { return find( Qtopia::Groups ); }
344//US QStringList groupList() const;
345
346 QStringList cats = addr.categories();
347
348 QArray<int> iar;
349 if ( !cats.isEmpty() ) {
350 QArray<int> iar = catDB->ids("contact", cats);
351 contact.setCategories(iar);
352 }
353
354 return true;
355}
diff --git a/kabc/plugins/opie/opieconverter.h b/kabc/plugins/opie/opieconverter.h
new file mode 100644
index 0000000..d251a24
--- a/dev/null
+++ b/kabc/plugins/opie/opieconverter.h
@@ -0,0 +1,80 @@
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#ifndef KABC_OPIECONVERTER_H
29#define KABC_OPIECONVERTER_H
30
31#include <qstring.h>
32
33#include "addressee.h"
34#include <opie/ocontact.h>
35
36class Categories;
37
38namespace KABC {
39
40class OpieConverter
41{
42public:
43
44 /**
45 * Constructor.
46 */
47 OpieConverter();
48
49 /**
50 * Destructor.
51 */
52 virtual ~OpieConverter();
53
54 bool init();
55 void deinit();
56
57 /**
58 * Converts a vcard string to an addressee.
59 *
60 * @param contact The opie contact.
61 * @param addr The addressee.
62 */
63 bool opieToAddressee( const OContact &contact, Addressee &addr );
64
65 /**
66 * Converts an addressee to a vcard string.
67 *
68 * @param addr The addressee.
69 * @param contact The opie contact.
70 */
71 bool addresseeToOpie( const Addressee &addr, OContact &contact );
72
73 private:
74 Categories* catDB;
75
76
77};
78
79}
80#endif