summaryrefslogtreecommitdiffabout
path: root/kabc
authorulf69 <ulf69>2004-07-01 01:40:51 (UTC)
committer ulf69 <ulf69>2004-07-01 01:40:51 (UTC)
commit574570db1963fd729bb40a778ae3fc6a71ffc221 (patch) (unidiff)
tree470b49c7c1de2c415edcfb7f4962a23d848b5280 /kabc
parent94a34390c1c3f6554e171760aa250186e6c8cfc9 (diff)
downloadkdepimpi-574570db1963fd729bb40a778ae3fc6a71ffc221.zip
kdepimpi-574570db1963fd729bb40a778ae3fc6a71ffc221.tar.gz
kdepimpi-574570db1963fd729bb40a778ae3fc6a71ffc221.tar.bz2
converter also supports now export
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/converter/opie/opieconverter.cpp149
-rw-r--r--kabc/converter/opie/opieconverter.h3
2 files changed, 139 insertions, 13 deletions
diff --git a/kabc/converter/opie/opieconverter.cpp b/kabc/converter/opie/opieconverter.cpp
index fbb5817..cfbe5c0 100644
--- a/kabc/converter/opie/opieconverter.cpp
+++ b/kabc/converter/opie/opieconverter.cpp
@@ -10,76 +10,80 @@
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/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (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 "opieconverter.h" 32#include "opieconverter.h"
33 33
34#include <qpe/categories.h>
35
36
34using namespace KABC; 37using namespace KABC;
35 38
36OpieConverter::OpieConverter() 39OpieConverter::OpieConverter()
37{ 40{
38} 41}
39 42
40OpieConverter::~OpieConverter() 43OpieConverter::~OpieConverter()
41{ 44{
42} 45}
43 46
44bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr ) 47bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
45{ 48{
46 // name 49 // name
47//US QString fileAs() const { return find( Qtopia::FileAs ); } 50 addr.setFormattedName(contact.fileAs());
48
49 addr.setFamilyName( contact.lastName() ); 51 addr.setFamilyName( contact.lastName() );
50 addr.setGivenName( contact.firstName() ); 52 addr.setGivenName( contact.firstName() );
51 addr.setAdditionalName( contact.middleName() ); 53 addr.setAdditionalName( contact.middleName() );
52 addr.setPrefix( contact.title() ); 54 addr.setPrefix( contact.title() );
53 addr.setSuffix( contact.suffix() ); 55 addr.setSuffix( contact.suffix() );
54 56
55 57
56 // email 58 // email
57 QStringList emails = contact.emailList(); 59 QStringList emails = contact.emailList();
58 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 60 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
59 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); 61 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
60 } 62 }
61 63
64 addr.insertEmail(contact.defaultEmail(), true);
65
62 // home 66 // home
63 Address homeaddress; 67 Address homeaddress;
64 homeaddress.setType(Address::Home); 68 homeaddress.setType(Address::Home);
65//US homeaddress.setPostOfficeBox( "" ); 69//US homeaddress.setPostOfficeBox( "" );
66//US homeaddress.setExtended( "" ); 70//US homeaddress.setExtended( "" );
67 homeaddress.setStreet( contact.homeStreet() ); 71 homeaddress.setStreet( contact.homeStreet() );
68 homeaddress.setLocality( contact.homeCity() ); 72 homeaddress.setLocality( contact.homeCity() );
69 homeaddress.setRegion( contact.homeState() ); 73 homeaddress.setRegion( contact.homeState() );
70 homeaddress.setPostalCode( contact.homeZip() ); 74 homeaddress.setPostalCode( contact.homeZip() );
71 homeaddress.setCountry( contact.homeCountry() ); 75 homeaddress.setCountry( contact.homeCountry() );
72 76
73 addr.insertAddress( homeaddress ); 77 addr.insertAddress( homeaddress );
74 78
75 if (!contact.homePhone().isEmpty()) 79 if (!contact.homePhone().isEmpty())
76 { 80 {
77 PhoneNumber homephone; 81 PhoneNumber homephone;
78 homephone.setType( PhoneNumber::Home ); 82 homephone.setType( PhoneNumber::Home );
79 homephone.setNumber( contact.homePhone() ); 83 homephone.setNumber( contact.homePhone() );
80 addr.insertPhoneNumber( homephone ); 84 addr.insertPhoneNumber( homephone );
81 } 85 }
82 86
83 if (!contact.homeFax().isEmpty()) 87 if (!contact.homeFax().isEmpty())
84 { 88 {
85 PhoneNumber homefax; 89 PhoneNumber homefax;
@@ -137,60 +141,185 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
137 } 141 }
138 142
139 if (!contact.businessPager().isEmpty()) 143 if (!contact.businessPager().isEmpty())
140 { 144 {
141 PhoneNumber businesspager; 145 PhoneNumber businesspager;
142 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); 146 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
143 businesspager.setNumber( contact.businessPager() ); 147 businesspager.setNumber( contact.businessPager() );
144 addr.insertPhoneNumber( businesspager ); 148 addr.insertPhoneNumber( businesspager );
145 } 149 }
146 150
147 addr.setRole( contact.jobTitle() ); //? 151 addr.setRole( contact.jobTitle() ); //?
148 addr.setOrganization( contact.company() ); 152 addr.setOrganization( contact.company() );
149 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); 153 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() );
150 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); 154 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() );
151 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); 155 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() );
152 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); 156 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() );
153 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); 157 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() );
154 158
155//??? 159//???
156//US QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } 160//US QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); }
157 161
158 //personal 162 //personal
159 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); 163 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
160 addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() ); 164 addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() );
161 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dateToAddresseeString(contact.anniversary()) ); 165
166 int orgformat = KGlobal::locale()->getIntDateFormat();
167 KGlobal::locale()->setIntDateFormat( 2 ); // = Qt::ISODate
168 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true);
169 KGlobal::locale()->setIntDateFormat(orgformat );
170 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
171
162 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); 172 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
163 addr.setBirthday( contact.birthday() ); 173 addr.setBirthday( contact.birthday() );
164 addr.setNickName( contact.nickname() ); 174 addr.setNickName( contact.nickname() );
165 175
166 // other 176 // other
167 addr.setNote( contact.notes() ); 177 addr.setNote( contact.notes() );
168 178
169//US QString groups() const { return find( Qtopia::Groups ); } 179//US QString groups() const { return find( Qtopia::Groups ); }
170//US QStringList groupList() const; 180//US QStringList groupList() const;
171 181
172/*US 182/*US
173 QStringList cats = contact.categoryNames("Contacts"); 183 QStringList cats = contact.categoryNames("Contacts");
174 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { 184 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
175 qDebug("Cat: %s", (*it).latin1()); 185 qDebug("Cat: %s", (*it).latin1());
176 } 186 }
177*/ 187*/
178 addr.setCategories( contact.categoryNames("Contacts") ); 188 addr.setCategories( contact.categoryNames("Contacts") );
179// qDebug("Groups: %s", contact.groups().latin1()); 189// qDebug("Groups: %s", contact.groups().latin1());
180// addr.setCategories( contact.groupList() ); 190// addr.setCategories( contact.groupList() );
181 191
182 192
183 return true; 193 return true;
184} 194}
185 195
186bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &contact ) 196bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &contact )
187{ 197{
188 return false; 198 // name
189} 199 contact.setLastName(addr.familyName());
200 contact.setFirstName(addr.givenName());
201 contact.setMiddleName(addr.additionalName());
202 contact.setTitle(addr.prefix());
203 contact.setSuffix(addr.suffix());
204 contact.setFileAs();
205
206
207 // email
208 QStringList emails = addr.emails();
209 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
210 contact.insertEmail(*it);
211 }
212 contact.setDefaultEmail( addr.preferredEmail() );
213
190 214
191QString OpieConverter::dateToAddresseeString( const QDate &date ) 215 // home
192{ 216 const Address homeaddress = addr.address(Address::Home);
193 return KGlobal::locale()->formatDate(date, true); 217 if (!homeaddress.isEmpty()) {
194//US return date.toString("yyyyMMdd"); 218 contact.setHomeStreet(homeaddress.street());
195} 219 contact.setHomeCity(homeaddress.locality());
220 contact.setHomeState(homeaddress.region());
221 contact.setHomeZip(homeaddress.postalCode());
222 contact.setHomeCountry(homeaddress.country());
223 }
224
225 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
226 if (!homephone.number().isEmpty())
227 contact.setHomePhone(homephone.number());
228
229 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
230 if (!homefax.number().isEmpty())
231 contact.setHomeFax(homefax.number());
232
233 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
234 if (!homemobile.number().isEmpty())
235 contact.setHomeMobile(homemobile.number());
236
237 contact.setHomeWebpage(addr.url().url());
238
239
240 // business
241 const Address businessaddress = addr.address(Address::Work);
242 if (!businessaddress.isEmpty()) {
243 contact.setBusinessStreet(businessaddress.street());
244 contact.setBusinessCity(businessaddress.locality());
245 contact.setBusinessState(businessaddress.region());
246 contact.setBusinessZip(businessaddress.postalCode());
247 contact.setBusinessCountry(businessaddress.country());
248 }
249
250 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work );
251 if (!businessphone.number().isEmpty())
252 contact.setBusinessPhone(businessphone.number());
253
254 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax );
255 if (!businessfax.number().isEmpty())
256 contact.setBusinessFax(businessfax.number());
257
258 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell );
259 if (!businessmobile.number().isEmpty())
260 contact.setBusinessMobile(businessmobile.number());
261
262 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager );
263 if (!businesspager.number().isEmpty())
264 contact.setBusinessPager(businesspager.number());
196 265
266 contact.setJobTitle(addr.role());
267 contact.setCompany(addr.organization());
268
269 contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" ));
270 contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" ));
271 contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" ));
272 contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" ));
273 contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" ));
274
275 //personal
276 contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" ));
277 contact.setGender(addr.custom( "KADDRESSBOOK", "X-Gender" ));
278
279 QDate dt = KGlobal::locale()->readDate(
280 addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
281 contact.setAnniversary( dt );
282
283 contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" ));
284
285 contact.setBirthday(addr.birthday().date());
286 contact.setNickname(addr.nickName());
287
288 // other
289 contact.setNotes(addr.note());
290
291//US QString groups() const { return find( Qtopia::Groups ); }
292//US QStringList groupList() const;
293
294/*US
295 QStringList cats = contact.categoryNames("Contacts");
296 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
297 qDebug("Cat: %s", (*it).latin1());
298 }
299*/
300
301// addr.setCategories( contact.categoryNames("Contacts") );
302// contact.categoryNames("Contacts");
303// contact.setCategoryNames(addr.categories());
304
305/*US
306 QStringList cats = addr.categories();
307 QArray<int> cat(cats.count());
308 int counter = 0;
309 for ( QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it )
310 cat[counter] = (*it).toInt();
311
312 contact.setCategories( cat );
313*/
314/*US
315 Categories catDB;
316 catDB.load( contact.categoryFileName() );
317
318 QStringList cats = addr.categories();
319 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
320 contact.setCategories(catDB.id(*it));
321 }
322*/
323
324 return true;
325}
diff --git a/kabc/converter/opie/opieconverter.h b/kabc/converter/opie/opieconverter.h
index 55a869a..ef7300b 100644
--- a/kabc/converter/opie/opieconverter.h
+++ b/kabc/converter/opie/opieconverter.h
@@ -44,31 +44,28 @@ public:
44 */ 44 */
45 OpieConverter(); 45 OpieConverter();
46 46
47 /** 47 /**
48 * Destructor. 48 * Destructor.
49 */ 49 */
50 ~OpieConverter(); 50 ~OpieConverter();
51 51
52 /** 52 /**
53 * Converts a vcard string to an addressee. 53 * Converts a vcard string to an addressee.
54 * 54 *
55 * @param contact The opie contact. 55 * @param contact The opie contact.
56 * @param addr The addressee. 56 * @param addr The addressee.
57 */ 57 */
58 bool opieToAddressee( OContact &contact, Addressee &addr ); 58 bool opieToAddressee( OContact &contact, Addressee &addr );
59 59
60 /** 60 /**
61 * Converts an addressee to a vcard string. 61 * Converts an addressee to a vcard string.
62 * 62 *
63 * @param addr The addressee. 63 * @param addr The addressee.
64 * @param contact The opie contact. 64 * @param contact The opie contact.
65 */ 65 */
66 bool addresseeToOpie( const Addressee &addr, OContact &contact ); 66 bool addresseeToOpie( const Addressee &addr, OContact &contact );
67 67
68 private:
69 QString dateToAddresseeString( const QDate &date );
70
71}; 68};
72 69
73} 70}
74#endif 71#endif