summaryrefslogtreecommitdiffabout
path: root/kabc/vcardparser
authorulf69 <ulf69>2004-09-09 18:57:57 (UTC)
committer ulf69 <ulf69>2004-09-09 18:57:57 (UTC)
commit880518b6f1d4b06e3df45224c244d9c62f6fb7a9 (patch) (unidiff)
tree2b0b5a0c7e40481c31f29ff2bd98aa6abb4c6c90 /kabc/vcardparser
parent72860f2b84ba97de9223238d9fb97edc0804cc68 (diff)
downloadkdepimpi-880518b6f1d4b06e3df45224c244d9c62f6fb7a9.zip
kdepimpi-880518b6f1d4b06e3df45224c244d9c62f6fb7a9.tar.gz
kdepimpi-880518b6f1d4b06e3df45224c244d9c62f6fb7a9.tar.bz2
added sip type to phonnumbers
Diffstat (limited to 'kabc/vcardparser') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardparser/vcardtool.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp
index 71f29d7..3fb212e 100644
--- a/kabc/vcardparser/vcardtool.cpp
+++ b/kabc/vcardparser/vcardtool.cpp
@@ -1,897 +1,898 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
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#include <qdatastream.h> 21#include <qdatastream.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qregexp.h> 23#include <qregexp.h>
24#include <kmdcodec.h> 24#include <kmdcodec.h>
25 25
26#include "agent.h" 26#include "agent.h"
27#include "key.h" 27#include "key.h"
28#include "picture.h" 28#include "picture.h"
29#include "secrecy.h" 29#include "secrecy.h"
30#include "sound.h" 30#include "sound.h"
31 31
32#include "vcardtool.h" 32#include "vcardtool.h"
33 33
34using namespace KABC; 34using namespace KABC;
35 35
36VCardTool::VCardTool() 36VCardTool::VCardTool()
37{ 37{
38 mAddressTypeMap.insert( "dom", Address::Dom ); 38 mAddressTypeMap.insert( "dom", Address::Dom );
39 mAddressTypeMap.insert( "intl", Address::Intl ); 39 mAddressTypeMap.insert( "intl", Address::Intl );
40 mAddressTypeMap.insert( "postal", Address::Postal ); 40 mAddressTypeMap.insert( "postal", Address::Postal );
41 mAddressTypeMap.insert( "parcel", Address::Parcel ); 41 mAddressTypeMap.insert( "parcel", Address::Parcel );
42 mAddressTypeMap.insert( "home", Address::Home ); 42 mAddressTypeMap.insert( "home", Address::Home );
43 mAddressTypeMap.insert( "work", Address::Work ); 43 mAddressTypeMap.insert( "work", Address::Work );
44 mAddressTypeMap.insert( "pref", Address::Pref ); 44 mAddressTypeMap.insert( "pref", Address::Pref );
45 45
46 mPhoneTypeMap.insert( "HOME", PhoneNumber::Home ); 46 mPhoneTypeMap.insert( "HOME", PhoneNumber::Home );
47 mPhoneTypeMap.insert( "WORK", PhoneNumber::Work ); 47 mPhoneTypeMap.insert( "WORK", PhoneNumber::Work );
48 mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg ); 48 mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg );
49 mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref ); 49 mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref );
50 mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice ); 50 mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice );
51 mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax ); 51 mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax );
52 mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell ); 52 mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell );
53 mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video ); 53 mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video );
54 mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs ); 54 mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs );
55 mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem ); 55 mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem );
56 mPhoneTypeMap.insert( "CAR", PhoneNumber::Car ); 56 mPhoneTypeMap.insert( "CAR", PhoneNumber::Car );
57 mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn ); 57 mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn );
58 mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs ); 58 mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs );
59 mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager ); 59 mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager );
60 mPhoneTypeMap.insert( "SIP", PhoneNumber::Sip );
60} 61}
61 62
62VCardTool::~VCardTool() 63VCardTool::~VCardTool()
63{ 64{
64} 65}
65 66
66QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) 67QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
67{ 68{
68 VCard::List vCardList; 69 VCard::List vCardList;
69 70
70 Addressee::List::Iterator addrIt; 71 Addressee::List::Iterator addrIt;
71 for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) { 72 for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) {
72 VCard card; 73 VCard card;
73 QStringList::ConstIterator strIt; 74 QStringList::ConstIterator strIt;
74 75
75 // ADR + LABEL 76 // ADR + LABEL
76 Address::List addresses = (*addrIt).addresses(); 77 Address::List addresses = (*addrIt).addresses();
77 for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { 78 for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) {
78 QStringList address; 79 QStringList address;
79 80
80/*US 81/*US
81 address.append( (*it).postOfficeBox().replace( ';', "\\;" ) ); 82 address.append( (*it).postOfficeBox().replace( ';', "\\;" ) );
82 address.append( (*it).extended().replace( ';', "\\;" ) ); 83 address.append( (*it).extended().replace( ';', "\\;" ) );
83 address.append( (*it).street().replace( ';', "\\;" ) ); 84 address.append( (*it).street().replace( ';', "\\;" ) );
84 address.append( (*it).locality().replace( ';', "\\;" ) ); 85 address.append( (*it).locality().replace( ';', "\\;" ) );
85 address.append( (*it).region().replace( ';', "\\;" ) ); 86 address.append( (*it).region().replace( ';', "\\;" ) );
86 address.append( (*it).postalCode().replace( ';', "\\;" ) ); 87 address.append( (*it).postalCode().replace( ';', "\\;" ) );
87 address.append( (*it).country().replace( ';', "\\;" ) ); 88 address.append( (*it).country().replace( ';', "\\;" ) );
88*/ 89*/
89//US using the old implementation instead 90//US using the old implementation instead
90 //qDebug("VCardTool::createVCards has to be verified"); 91 //qDebug("VCardTool::createVCards has to be verified");
91 address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) ); 92 address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) );
92 address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) ); 93 address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) );
93 address.append( (*it).street().replace( QRegExp(";"), "\\;" ) ); 94 address.append( (*it).street().replace( QRegExp(";"), "\\;" ) );
94 address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) ); 95 address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) );
95 address.append( (*it).region().replace( QRegExp(";"), "\\;" ) ); 96 address.append( (*it).region().replace( QRegExp(";"), "\\;" ) );
96 address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) ); 97 address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) );
97 address.append( (*it).country().replace( QRegExp(";"), "\\;" ) ); 98 address.append( (*it).country().replace( QRegExp(";"), "\\;" ) );
98 99
99 VCardLine adrLine( "ADR", address.join( ";" ) ); 100 VCardLine adrLine( "ADR", address.join( ";" ) );
100 VCardLine labelLine( "LABEL", (*it).label() ); 101 VCardLine labelLine( "LABEL", (*it).label() );
101 102
102 bool hasLabel = !(*it).label().isEmpty(); 103 bool hasLabel = !(*it).label().isEmpty();
103 QMap<QString, int>::Iterator typeIt; 104 QMap<QString, int>::Iterator typeIt;
104 for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) { 105 for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) {
105 if ( typeIt.data() & (*it).type() ) { 106 if ( typeIt.data() & (*it).type() ) {
106 if ( version == VCard::v3_0 ) { 107 if ( version == VCard::v3_0 ) {
107 adrLine.addParameter( "TYPE", typeIt.key().lower() ); 108 adrLine.addParameter( "TYPE", typeIt.key().lower() );
108 } 109 }
109 else { 110 else {
110 adrLine.addParameter( "TYPE", typeIt.key() ); 111 adrLine.addParameter( "TYPE", typeIt.key() );
111 } 112 }
112 if ( hasLabel ) { 113 if ( hasLabel ) {
113 if ( version == VCard::v3_0 ) { 114 if ( version == VCard::v3_0 ) {
114 labelLine.addParameter( "TYPE", typeIt.key().lower() ); 115 labelLine.addParameter( "TYPE", typeIt.key().lower() );
115 } 116 }
116 else { 117 else {
117 labelLine.addParameter( "TYPE", typeIt.key() ); 118 labelLine.addParameter( "TYPE", typeIt.key() );
118 } 119 }
119 } 120 }
120 } 121 }
121 } 122 }
122 123
123 card.addLine( adrLine ); 124 card.addLine( adrLine );
124 if ( hasLabel ) 125 if ( hasLabel )
125 card.addLine( labelLine ); 126 card.addLine( labelLine );
126 } 127 }
127 128
128 // AGENT 129 // AGENT
129 card.addLine( createAgent( version, (*addrIt).agent() ) ); 130 card.addLine( createAgent( version, (*addrIt).agent() ) );
130 131
131 // BDAY 132 // BDAY
132 card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) ); 133 card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) );
133 134
134 // CATEGORIES 135 // CATEGORIES
135 if ( version == VCard::v3_0 ) { 136 if ( version == VCard::v3_0 ) {
136 QStringList categories = (*addrIt).categories(); 137 QStringList categories = (*addrIt).categories();
137 QStringList::Iterator catIt; 138 QStringList::Iterator catIt;
138 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) 139 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt )
139 { 140 {
140//US using the old implementation instead 141//US using the old implementation instead
141 // qDebug("VCardTool::createVCards has to be verified"); 142 // qDebug("VCardTool::createVCards has to be verified");
142//US (*catIt).replace( ',', "\\," ); 143//US (*catIt).replace( ',', "\\," );
143 (*catIt).replace( QRegExp(","), "\\," ); 144 (*catIt).replace( QRegExp(","), "\\," );
144 } 145 }
145 card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) ); 146 card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) );
146 } 147 }
147 148
148 // CLASS 149 // CLASS
149 if ( version == VCard::v3_0 ) { 150 if ( version == VCard::v3_0 ) {
150 card.addLine( createSecrecy( (*addrIt).secrecy() ) ); 151 card.addLine( createSecrecy( (*addrIt).secrecy() ) );
151 } 152 }
152 153
153 // EMAIL 154 // EMAIL
154 QStringList emails = (*addrIt).emails(); 155 QStringList emails = (*addrIt).emails();
155 bool pref = true; 156 bool pref = true;
156 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) { 157 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) {
157 VCardLine line( "EMAIL", *strIt ); 158 VCardLine line( "EMAIL", *strIt );
158 if ( pref == true ) { 159 if ( pref == true ) {
159 line.addParameter( "TYPE", "PREF" ); 160 line.addParameter( "TYPE", "PREF" );
160 pref = false; 161 pref = false;
161 } 162 }
162 card.addLine( line ); 163 card.addLine( line );
163 } 164 }
164 165
165 // FN 166 // FN
166 card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) ); 167 card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) );
167 168
168 // GEO 169 // GEO
169 Geo geo = (*addrIt).geo(); 170 Geo geo = (*addrIt).geo();
170 if ( geo.isValid() ) { 171 if ( geo.isValid() ) {
171 QString str; 172 QString str;
172 str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() ); 173 str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() );
173 card.addLine( VCardLine( "GEO", str ) ); 174 card.addLine( VCardLine( "GEO", str ) );
174 } 175 }
175 176
176 // KEY 177 // KEY
177 Key::List keys = (*addrIt).keys(); 178 Key::List keys = (*addrIt).keys();
178 Key::List::ConstIterator keyIt; 179 Key::List::ConstIterator keyIt;
179 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt ) 180 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt )
180 card.addLine( createKey( *keyIt ) ); 181 card.addLine( createKey( *keyIt ) );
181 182
182 // LOGO 183 // LOGO
183 card.addLine( createPicture( "LOGO", (*addrIt).logo() ) ); 184 card.addLine( createPicture( "LOGO", (*addrIt).logo() ) );
184 185
185 // MAILER 186 // MAILER
186 card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) ); 187 card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) );
187 188
188 // N 189 // N
189 QStringList name; 190 QStringList name;
190//US using the old implementation instead 191//US using the old implementation instead
191 //qDebug("VCardTool::createVCards has to be verified"); 192 //qDebug("VCardTool::createVCards has to be verified");
192/*US 193/*US
193 name.append( (*addrIt).familyName().replace( ';', "\\;" ) ); 194 name.append( (*addrIt).familyName().replace( ';', "\\;" ) );
194 name.append( (*addrIt).givenName().replace( ';', "\\;" ) ); 195 name.append( (*addrIt).givenName().replace( ';', "\\;" ) );
195 name.append( (*addrIt).additionalName().replace( ';', "\\;" ) ); 196 name.append( (*addrIt).additionalName().replace( ';', "\\;" ) );
196 name.append( (*addrIt).prefix().replace( ';', "\\;" ) ); 197 name.append( (*addrIt).prefix().replace( ';', "\\;" ) );
197 name.append( (*addrIt).suffix().replace( ';', "\\;" ) ); 198 name.append( (*addrIt).suffix().replace( ';', "\\;" ) );
198*/ 199*/
199 name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) ); 200 name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) );
200 name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) ); 201 name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) );
201 name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) ); 202 name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) );
202 name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) ); 203 name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) );
203 name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) ); 204 name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) );
204 205
205 if ( !name.join( "" ).isEmpty() ) 206 if ( !name.join( "" ).isEmpty() )
206 card.addLine( VCardLine( "N", name.join( ";" ) ) ); 207 card.addLine( VCardLine( "N", name.join( ";" ) ) );
207 208
208 // NICKNAME 209 // NICKNAME
209 if ( version == VCard::v3_0 ) 210 if ( version == VCard::v3_0 )
210 card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) ); 211 card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) );
211 212
212 // NOTE 213 // NOTE
213 card.addLine( VCardLine( "NOTE", (*addrIt).note() ) ); 214 card.addLine( VCardLine( "NOTE", (*addrIt).note() ) );
214 215
215 // ORG 216 // ORG
216 card.addLine( VCardLine( "ORG", (*addrIt).organization() ) ); 217 card.addLine( VCardLine( "ORG", (*addrIt).organization() ) );
217 218
218 // PHOTO 219 // PHOTO
219 card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) ); 220 card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) );
220 221
221 // PROID 222 // PROID
222 if ( version == VCard::v3_0 ) 223 if ( version == VCard::v3_0 )
223 card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) ); 224 card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) );
224 225
225 // REV 226 // REV
226 card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) ); 227 card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) );
227 228
228 // ROLE 229 // ROLE
229 card.addLine( VCardLine( "ROLE", (*addrIt).role() ) ); 230 card.addLine( VCardLine( "ROLE", (*addrIt).role() ) );
230 231
231 // SORT-STRING 232 // SORT-STRING
232 if ( version == VCard::v3_0 ) 233 if ( version == VCard::v3_0 )
233 card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) ); 234 card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) );
234 235
235 // SOUND 236 // SOUND
236 card.addLine( createSound( (*addrIt).sound() ) ); 237 card.addLine( createSound( (*addrIt).sound() ) );
237 238
238 // TEL 239 // TEL
239 PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); 240 PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
240 PhoneNumber::List::ConstIterator phoneIt; 241 PhoneNumber::List::ConstIterator phoneIt;
241 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { 242 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
242 VCardLine line( "TEL", (*phoneIt).number() ); 243 VCardLine line( "TEL", (*phoneIt).number() );
243 244
244 QMap<QString, int>::Iterator typeIt; 245 QMap<QString, int>::Iterator typeIt;
245 for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) { 246 for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) {
246 if ( typeIt.data() & (*phoneIt).type() ) 247 if ( typeIt.data() & (*phoneIt).type() )
247 if ( version == VCard::v3_0 ) 248 if ( version == VCard::v3_0 )
248 line.addParameter( "TYPE", typeIt.key().lower() ); 249 line.addParameter( "TYPE", typeIt.key().lower() );
249 else 250 else
250 line.addParameter( "TYPE", typeIt.key() ); 251 line.addParameter( "TYPE", typeIt.key() );
251 } 252 }
252 253
253 card.addLine( line ); 254 card.addLine( line );
254 } 255 }
255 256
256 // TITLE 257 // TITLE
257 card.addLine( VCardLine( "TITLE", (*addrIt).title() ) ); 258 card.addLine( VCardLine( "TITLE", (*addrIt).title() ) );
258 259
259 // TZ 260 // TZ
260 TimeZone timeZone = (*addrIt).timeZone(); 261 TimeZone timeZone = (*addrIt).timeZone();
261 if ( timeZone.isValid() ) { 262 if ( timeZone.isValid() ) {
262 QString str; 263 QString str;
263 264
264 int neg = 1; 265 int neg = 1;
265 if ( timeZone.offset() < 0 ) 266 if ( timeZone.offset() < 0 )
266 neg = -1; 267 neg = -1;
267 268
268 str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ), 269 str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ),
269 ( timeZone.offset() / 60 ) * neg, 270 ( timeZone.offset() / 60 ) * neg,
270 ( timeZone.offset() % 60 ) * neg ); 271 ( timeZone.offset() % 60 ) * neg );
271 272
272 card.addLine( VCardLine( "TZ", str ) ); 273 card.addLine( VCardLine( "TZ", str ) );
273 } 274 }
274 275
275 // UID 276 // UID
276 card.addLine( VCardLine( "UID", (*addrIt).uid() ) ); 277 card.addLine( VCardLine( "UID", (*addrIt).uid() ) );
277 278
278 // URL 279 // URL
279 card.addLine( VCardLine( "URL", (*addrIt).url().url() ) ); 280 card.addLine( VCardLine( "URL", (*addrIt).url().url() ) );
280 281
281 // VERSION 282 // VERSION
282 if ( version == VCard::v2_1 ) 283 if ( version == VCard::v2_1 )
283 card.addLine( VCardLine( "VERSION", "2.1" ) ); 284 card.addLine( VCardLine( "VERSION", "2.1" ) );
284 if ( version == VCard::v3_0 ) 285 if ( version == VCard::v3_0 )
285 card.addLine( VCardLine( "VERSION", "3.0" ) ); 286 card.addLine( VCardLine( "VERSION", "3.0" ) );
286 287
287 // X- 288 // X-
288 QStringList customs = (*addrIt).customs(); 289 QStringList customs = (*addrIt).customs();
289 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) { 290 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
290 QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) ); 291 QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) );
291 QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 ); 292 QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 );
292 if ( value.isEmpty() ) 293 if ( value.isEmpty() )
293 continue; 294 continue;
294 295
295 card.addLine( VCardLine( identifier, value ) ); 296 card.addLine( VCardLine( identifier, value ) );
296 } 297 }
297 298
298 vCardList.append( card ); 299 vCardList.append( card );
299 } 300 }
300 301
301 return VCardParser::createVCards( vCardList ); 302 return VCardParser::createVCards( vCardList );
302} 303}
303 304
304Addressee::List VCardTool::parseVCards( const QString& vcard ) 305Addressee::List VCardTool::parseVCards( const QString& vcard )
305{ 306{
306 QChar semicolonSep( ';' ); 307 QChar semicolonSep( ';' );
307 QChar commaSep( ',' ); 308 QChar commaSep( ',' );
308 QString identifier; 309 QString identifier;
309 310
310 Addressee::List addrList; 311 Addressee::List addrList;
311 VCard::List vCardList = VCardParser::parseVCards( vcard ); 312 VCard::List vCardList = VCardParser::parseVCards( vcard );
312 VCard::List::Iterator cardIt; 313 VCard::List::Iterator cardIt;
313 for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) { 314 for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) {
314 Addressee addr; 315 Addressee addr;
315 QStringList idents = (*cardIt).identifiers(); 316 QStringList idents = (*cardIt).identifiers();
316 QStringList::ConstIterator identIt; 317 QStringList::ConstIterator identIt;
317 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { 318 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
318 VCard card = (*cardIt); 319 VCard card = (*cardIt);
319 VCardLine::List lines = card.lines( (*identIt) ); 320 VCardLine::List lines = card.lines( (*identIt) );
320 VCardLine::List::Iterator lineIt; 321 VCardLine::List::Iterator lineIt;
321 322
322 // iterate over the lines 323 // iterate over the lines
323 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { 324 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
324 QStringList params = (*lineIt).parameterList(); 325 QStringList params = (*lineIt).parameterList();
325 326
326 identifier = (*lineIt).identifier().lower(); 327 identifier = (*lineIt).identifier().lower();
327 // ADR 328 // ADR
328 if ( identifier == "adr" ) { 329 if ( identifier == "adr" ) {
329 Address address; 330 Address address;
330 QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); 331 QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
331 if ( addrParts.count() > 0 ) 332 if ( addrParts.count() > 0 )
332 address.setPostOfficeBox( addrParts[ 0 ] ); 333 address.setPostOfficeBox( addrParts[ 0 ] );
333 if ( addrParts.count() > 1 ) 334 if ( addrParts.count() > 1 )
334 address.setExtended( addrParts[ 1 ] ); 335 address.setExtended( addrParts[ 1 ] );
335 if ( addrParts.count() > 2 ) 336 if ( addrParts.count() > 2 )
336 address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") ); 337 address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") );
337 if ( addrParts.count() > 3 ) 338 if ( addrParts.count() > 3 )
338 address.setLocality( addrParts[ 3 ] ); 339 address.setLocality( addrParts[ 3 ] );
339 if ( addrParts.count() > 4 ) 340 if ( addrParts.count() > 4 )
340 address.setRegion( addrParts[ 4 ] ); 341 address.setRegion( addrParts[ 4 ] );
341 if ( addrParts.count() > 5 ) 342 if ( addrParts.count() > 5 )
342 address.setPostalCode( addrParts[ 5 ] ); 343 address.setPostalCode( addrParts[ 5 ] );
343 if ( addrParts.count() > 6 ) 344 if ( addrParts.count() > 6 )
344 address.setCountry( addrParts[ 6 ] ); 345 address.setCountry( addrParts[ 6 ] );
345 346
346 int type = 0; 347 int type = 0;
347 348
348 QStringList types = (*lineIt).parameters( "type" ); 349 QStringList types = (*lineIt).parameters( "type" );
349 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 350 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
350 type += mAddressTypeMap[ (*it).lower() ]; 351 type += mAddressTypeMap[ (*it).lower() ];
351 352
352 if ( !type ) 353 if ( !type )
353 type = Address::Home; // default 354 type = Address::Home; // default
354 355
355 address.setType( type ); 356 address.setType( type );
356 addr.insertAddress( address ); 357 addr.insertAddress( address );
357 } 358 }
358 359
359 // AGENT 360 // AGENT
360 if ( identifier == "agent" ) 361 if ( identifier == "agent" )
361 addr.setAgent( parseAgent( *lineIt ) ); 362 addr.setAgent( parseAgent( *lineIt ) );
362 363
363 // BDAY 364 // BDAY
364 if ( identifier == "bday" ) 365 if ( identifier == "bday" )
365 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) ); 366 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) );
366 367
367 // CATEGORIES 368 // CATEGORIES
368 if ( identifier == "categories" ) { 369 if ( identifier == "categories" ) {
369 QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); 370 QStringList categories = splitString( commaSep, (*lineIt).value().asString() );
370 addr.setCategories( categories ); 371 addr.setCategories( categories );
371 } 372 }
372 373
373 // CLASS 374 // CLASS
374 if ( identifier == "class" ) 375 if ( identifier == "class" )
375 addr.setSecrecy( parseSecrecy( *lineIt ) ); 376 addr.setSecrecy( parseSecrecy( *lineIt ) );
376 377
377 // EMAIL 378 // EMAIL
378 if ( identifier == "email" ) { 379 if ( identifier == "email" ) {
379 QStringList types = (*lineIt).parameters( "type" ); 380 QStringList types = (*lineIt).parameters( "type" );
380 addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) ); 381 addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) );
381 } 382 }
382 383
383 // FN 384 // FN
384 if ( identifier == "fn" ) 385 if ( identifier == "fn" )
385 addr.setFormattedName( (*lineIt).value().asString() ); 386 addr.setFormattedName( (*lineIt).value().asString() );
386 387
387 // GEO 388 // GEO
388 if ( identifier == "geo" ) { 389 if ( identifier == "geo" ) {
389 Geo geo; 390 Geo geo;
390 391
391 QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); 392 QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true );
392 geo.setLatitude( geoParts[ 0 ].toFloat() ); 393 geo.setLatitude( geoParts[ 0 ].toFloat() );
393 geo.setLongitude( geoParts[ 1 ].toFloat() ); 394 geo.setLongitude( geoParts[ 1 ].toFloat() );
394 395
395 addr.setGeo( geo ); 396 addr.setGeo( geo );
396 } 397 }
397 398
398 // KEY 399 // KEY
399 if ( identifier == "key" ) 400 if ( identifier == "key" )
400 addr.insertKey( parseKey( *lineIt ) ); 401 addr.insertKey( parseKey( *lineIt ) );
401 402
402 // LABEL 403 // LABEL
403 if ( identifier == "label" ) { 404 if ( identifier == "label" ) {
404 int type = 0; 405 int type = 0;
405 406
406 QStringList types = (*lineIt).parameters( "type" ); 407 QStringList types = (*lineIt).parameters( "type" );
407 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 408 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
408 type += mAddressTypeMap[ (*it).lower() ]; 409 type += mAddressTypeMap[ (*it).lower() ];
409 410
410 if ( !type ) 411 if ( !type )
411 type = Address::Home; 412 type = Address::Home;
412 413
413 KABC::Address::List addressList = addr.addresses(); 414 KABC::Address::List addressList = addr.addresses();
414 KABC::Address::List::Iterator it; 415 KABC::Address::List::Iterator it;
415 for ( it = addressList.begin(); it != addressList.end(); ++it ) { 416 for ( it = addressList.begin(); it != addressList.end(); ++it ) {
416 if ( (*it).type() == type ) { 417 if ( (*it).type() == type ) {
417 (*it).setLabel( (*lineIt).value().asString() ); 418 (*it).setLabel( (*lineIt).value().asString() );
418 addr.insertAddress( *it ); 419 addr.insertAddress( *it );
419 } 420 }
420 } 421 }
421 } 422 }
422 423
423 // LOGO 424 // LOGO
424 if ( identifier == "logo" ) 425 if ( identifier == "logo" )
425 addr.setLogo( parsePicture( *lineIt ) ); 426 addr.setLogo( parsePicture( *lineIt ) );
426 427
427 // MAILER 428 // MAILER
428 if ( identifier == "mailer" ) 429 if ( identifier == "mailer" )
429 addr.setMailer( (*lineIt).value().asString() ); 430 addr.setMailer( (*lineIt).value().asString() );
430 431
431 // N 432 // N
432 if ( identifier == "n" ) { 433 if ( identifier == "n" ) {
433 QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); 434 QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() );
434 if ( nameParts.count() > 0 ) 435 if ( nameParts.count() > 0 )
435 addr.setFamilyName( nameParts[ 0 ] ); 436 addr.setFamilyName( nameParts[ 0 ] );
436 if ( nameParts.count() > 1 ) 437 if ( nameParts.count() > 1 )
437 addr.setGivenName( nameParts[ 1 ] ); 438 addr.setGivenName( nameParts[ 1 ] );
438 if ( nameParts.count() > 2 ) 439 if ( nameParts.count() > 2 )
439 addr.setAdditionalName( nameParts[ 2 ] ); 440 addr.setAdditionalName( nameParts[ 2 ] );
440 if ( nameParts.count() > 3 ) 441 if ( nameParts.count() > 3 )
441 addr.setPrefix( nameParts[ 3 ] ); 442 addr.setPrefix( nameParts[ 3 ] );
442 if ( nameParts.count() > 4 ) 443 if ( nameParts.count() > 4 )
443 addr.setSuffix( nameParts[ 4 ] ); 444 addr.setSuffix( nameParts[ 4 ] );
444 } 445 }
445 446
446 // NICKNAME 447 // NICKNAME
447 if ( identifier == "nickname" ) 448 if ( identifier == "nickname" )
448 addr.setNickName( (*lineIt).value().asString() ); 449 addr.setNickName( (*lineIt).value().asString() );
449 450
450 // NOTE 451 // NOTE
451 if ( identifier == "note" ) { 452 if ( identifier == "note" ) {
452// #ifdef DESKTOP_VERSION 453// #ifdef DESKTOP_VERSION
453// addr.setNote( (*lineIt).value().asString() ); 454// addr.setNote( (*lineIt).value().asString() );
454// #else 455// #else
455 QString note = (*lineIt).value().asString(); 456 QString note = (*lineIt).value().asString();
456 if ( ! note.isEmpty() ) 457 if ( ! note.isEmpty() )
457 addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") ); 458 addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") );
458 else 459 else
459 addr.setNote( note ); 460 addr.setNote( note );
460 //#endif 461 //#endif
461 } 462 }
462 463
463 // ORGANIZATION 464 // ORGANIZATION
464 if ( identifier == "org" ) 465 if ( identifier == "org" )
465 addr.setOrganization( (*lineIt).value().asString() ); 466 addr.setOrganization( (*lineIt).value().asString() );
466 467
467 // PHOTO 468 // PHOTO
468 if ( identifier == "photo" ) 469 if ( identifier == "photo" )
469 addr.setPhoto( parsePicture( *lineIt ) ); 470 addr.setPhoto( parsePicture( *lineIt ) );
470 471
471 // PROID 472 // PROID
472 if ( identifier == "prodid" ) 473 if ( identifier == "prodid" )
473 addr.setProductId( (*lineIt).value().asString() ); 474 addr.setProductId( (*lineIt).value().asString() );
474 475
475 // REV 476 // REV
476 if ( identifier == "rev" ) 477 if ( identifier == "rev" )
477 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) ); 478 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
478 479
479 // ROLE 480 // ROLE
480 if ( identifier == "role" ) 481 if ( identifier == "role" )
481 addr.setRole( (*lineIt).value().asString() ); 482 addr.setRole( (*lineIt).value().asString() );
482 483
483 // SORT-STRING 484 // SORT-STRING
484 if ( identifier == "sort-string" ) 485 if ( identifier == "sort-string" )
485 addr.setSortString( (*lineIt).value().asString() ); 486 addr.setSortString( (*lineIt).value().asString() );
486 487
487 // SOUND 488 // SOUND
488 if ( identifier == "sound" ) 489 if ( identifier == "sound" )
489 addr.setSound( parseSound( *lineIt ) ); 490 addr.setSound( parseSound( *lineIt ) );
490 491
491 // TEL 492 // TEL
492 if ( identifier == "tel" ) { 493 if ( identifier == "tel" ) {
493 PhoneNumber phone; 494 PhoneNumber phone;
494 phone.setNumber( (*lineIt).value().asString() ); 495 phone.setNumber( (*lineIt).value().asString() );
495 496
496 int type = 0; 497 int type = 0;
497 498
498 QStringList types = (*lineIt).parameters( "type" ); 499 QStringList types = (*lineIt).parameters( "type" );
499 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 500 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
500 type += mPhoneTypeMap[(*it).upper()]; 501 type += mPhoneTypeMap[(*it).upper()];
501 502
502 if ( !type ) 503 if ( !type )
503 type = PhoneNumber::Home; // default 504 type = PhoneNumber::Home; // default
504 505
505 phone.setType( type ); 506 phone.setType( type );
506 507
507 addr.insertPhoneNumber( phone ); 508 addr.insertPhoneNumber( phone );
508 } 509 }
509 510
510 // TITLE 511 // TITLE
511 if ( identifier == "title" ) 512 if ( identifier == "title" )
512 addr.setTitle( (*lineIt).value().asString() ); 513 addr.setTitle( (*lineIt).value().asString() );
513 514
514 // TZ 515 // TZ
515 if ( identifier == "tz" ) { 516 if ( identifier == "tz" ) {
516 TimeZone tz; 517 TimeZone tz;
517 QString date = (*lineIt).value().asString(); 518 QString date = (*lineIt).value().asString();
518 519
519 int hours = date.mid( 1, 2).toInt(); 520 int hours = date.mid( 1, 2).toInt();
520 int minutes = date.mid( 4, 2 ).toInt(); 521 int minutes = date.mid( 4, 2 ).toInt();
521 int offset = ( hours * 60 ) + minutes; 522 int offset = ( hours * 60 ) + minutes;
522 offset = offset * ( date[ 0 ] == '+' ? 1 : -1 ); 523 offset = offset * ( date[ 0 ] == '+' ? 1 : -1 );
523 524
524 tz.setOffset( offset ); 525 tz.setOffset( offset );
525 addr.setTimeZone( tz ); 526 addr.setTimeZone( tz );
526 } 527 }
527 528
528 // UID 529 // UID
529 if ( identifier == "uid" ) 530 if ( identifier == "uid" )
530 addr.setUid( (*lineIt).value().asString() ); 531 addr.setUid( (*lineIt).value().asString() );
531 532
532 // URL 533 // URL
533 if ( identifier == "url" ) 534 if ( identifier == "url" )
534 addr.setUrl( (*lineIt).value().asString() ); 535 addr.setUrl( (*lineIt).value().asString() );
535 536
536 // X- 537 // X-
537 if ( identifier.startsWith( "x-" ) ) { 538 if ( identifier.startsWith( "x-" ) ) {
538 QString key = (*lineIt).identifier().mid( 2 ); 539 QString key = (*lineIt).identifier().mid( 2 );
539 int dash = key.find( "-" ); 540 int dash = key.find( "-" );
540 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() ); 541 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
541 } 542 }
542 } 543 }
543 } 544 }
544 545
545 addrList.append( addr ); 546 addrList.append( addr );
546 } 547 }
547 548
548 return addrList; 549 return addrList;
549} 550}
550 551
551QDateTime VCardTool::parseDateTime( const QString &str ) 552QDateTime VCardTool::parseDateTime( const QString &str )
552{ 553{
553 QDateTime dateTime; 554 QDateTime dateTime;
554 555
555 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd) 556 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd)
556 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(), 557 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
557 str.mid( 6, 2 ).toInt() ) ); 558 str.mid( 6, 2 ).toInt() ) );
558 559
559 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss 560 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss
560 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), 561 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
561 str.mid( 17, 2 ).toInt() ) ); 562 str.mid( 17, 2 ).toInt() ) );
562 563
563 } else { // is extended format yyyy-mm-dd 564 } else { // is extended format yyyy-mm-dd
564 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(), 565 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
565 str.mid( 8, 2 ).toInt() ) ); 566 str.mid( 8, 2 ).toInt() ) );
566 567
567 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss 568 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss
568 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), 569 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
569 str.mid( 17, 2 ).toInt() ) ); 570 str.mid( 17, 2 ).toInt() ) );
570 } 571 }
571 572
572 return dateTime; 573 return dateTime;
573} 574}
574 575
575QString VCardTool::createDateTime( const QDateTime &dateTime ) 576QString VCardTool::createDateTime( const QDateTime &dateTime )
576{ 577{
577 QString str; 578 QString str;
578 579
579 if ( dateTime.date().isValid() ) { 580 if ( dateTime.date().isValid() ) {
580 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(), 581 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
581 dateTime.date().day() ); 582 dateTime.date().day() );
582 if ( dateTime.time().isValid() ) { 583 if ( dateTime.time().isValid() ) {
583 QString tmp; 584 QString tmp;
584 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(), 585 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
585 dateTime.time().second() ); 586 dateTime.time().second() );
586 str += tmp; 587 str += tmp;
587 } 588 }
588 } 589 }
589 590
590 return str; 591 return str;
591} 592}
592 593
593Picture VCardTool::parsePicture( const VCardLine &line ) 594Picture VCardTool::parsePicture( const VCardLine &line )
594{ 595{
595 Picture pic; 596 Picture pic;
596 597
597 QStringList params = line.parameterList(); 598 QStringList params = line.parameterList();
598 if ( params.contains( "encoding" ) ) { 599 if ( params.contains( "encoding" ) ) {
599 QCString cs(line.value().asCString()); 600 QCString cs(line.value().asCString());
600 QByteArray input, output; 601 QByteArray input, output;
601 input = line.value().asCString(); 602 input = line.value().asCString();
602 if ( line.parameter( "encoding" ).lower() == "b" ) 603 if ( line.parameter( "encoding" ).lower() == "b" )
603 KCodecs::base64Decode( input, output ); 604 KCodecs::base64Decode( input, output );
604 else if ( line.parameter( "encoding" ).lower() == "quoted-printable" ) 605 else if ( line.parameter( "encoding" ).lower() == "quoted-printable" )
605 KCodecs::quotedPrintableDecode( input, output ); 606 KCodecs::quotedPrintableDecode( input, output );
606 607
607 qDebug("********** DECODING OKAY ************** (picture)"); 608 qDebug("********** DECODING OKAY ************** (picture)");
608 pic.setData( QImage(output) ); 609 pic.setData( QImage(output) );
609 610
610 } 611 }
611 else if ( params.contains( "value" ) ) { 612 else if ( params.contains( "value" ) ) {
612 if ( line.parameter( "value" ).lower() == "uri" ) 613 if ( line.parameter( "value" ).lower() == "uri" )
613 pic.setUrl( line.value().asString() ); 614 pic.setUrl( line.value().asString() );
614 } 615 }
615 616
616 if ( params.contains( "type" ) ) 617 if ( params.contains( "type" ) )
617 pic.setType( line.parameter( "type" ) ); 618 pic.setType( line.parameter( "type" ) );
618 619
619 return pic; 620 return pic;
620} 621}
621 622
622VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) 623VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
623{ 624{
624 // LR fixed 625 // LR fixed
625 VCardLine line( identifier ); 626 VCardLine line( identifier );
626 627
627 if ( pic.isIntern() ) { 628 if ( pic.isIntern() ) {
628 if ( !pic.data().isNull() ) { 629 if ( !pic.data().isNull() ) {
629#if 0 630#if 0
630 QByteArray input; 631 QByteArray input;
631 QDataStream s( input, IO_WriteOnly ); 632 QDataStream s( input, IO_WriteOnly );
632 s.setVersion( 4 ); 633 s.setVersion( 4 );
633 s << pic.data(); 634 s << pic.data();
634 line.setValue( input ); 635 line.setValue( input );
635#else 636#else
636 QCString input; 637 QCString input;
637 QDataStream s( input, IO_WriteOnly ); 638 QDataStream s( input, IO_WriteOnly );
638 s.setVersion( 4 ); 639 s.setVersion( 4 );
639 s << pic.data(); 640 s << pic.data();
640 //QCString cs(line.value().asCString()); 641 //QCString cs(line.value().asCString());
641 //QImage qi(cs); 642 //QImage qi(cs);
642 line.setValue( input ); 643 line.setValue( input );
643#endif 644#endif
644 645
645 line.addParameter( "encoding", "b" ); 646 line.addParameter( "encoding", "b" );
646 line.addParameter( "type", "image/png" ); 647 line.addParameter( "type", "image/png" );
647 } 648 }
648 } else if ( !pic.url().isEmpty() ) { 649 } else if ( !pic.url().isEmpty() ) {
649 line.setValue( pic.url() ); 650 line.setValue( pic.url() );
650 line.addParameter( "value", "URI" ); 651 line.addParameter( "value", "URI" );
651 } 652 }
652 653
653 return line; 654 return line;
654} 655}
655 656
656Sound VCardTool::parseSound( const VCardLine &line ) 657Sound VCardTool::parseSound( const VCardLine &line )
657{ 658{
658 Sound snd; 659 Sound snd;
659 660
660 QStringList params = line.parameterList(); 661 QStringList params = line.parameterList();
661 if ( params.contains( "encoding" ) ) { 662 if ( params.contains( "encoding" ) ) {
662 qDebug("VCardTool::parseSound has to be verified"); 663 qDebug("VCardTool::parseSound has to be verified");
663//US snd.setData( line.value().asByteArray() ); 664//US snd.setData( line.value().asByteArray() );
664//US I am not sure if this is correct 665//US I am not sure if this is correct
665 QCString cs(line.value().asCString()); 666 QCString cs(line.value().asCString());
666 snd.setData( cs ); 667 snd.setData( cs );
667 } 668 }
668 else if ( params.contains( "value" ) ) { 669 else if ( params.contains( "value" ) ) {
669 if ( line.parameter( "value" ).lower() == "uri" ) 670 if ( line.parameter( "value" ).lower() == "uri" )
670 snd.setUrl( line.value().asString() ); 671 snd.setUrl( line.value().asString() );
671 } 672 }
672 673
673/* TODO: support sound types 674/* TODO: support sound types
674 if ( params.contains( "type" ) ) 675 if ( params.contains( "type" ) )
675 snd.setType( line.parameter( "type" ) ); 676 snd.setType( line.parameter( "type" ) );
676*/ 677*/
677 678
678 return snd; 679 return snd;
679} 680}
680 681
681VCardLine VCardTool::createSound( const Sound &snd ) 682VCardLine VCardTool::createSound( const Sound &snd )
682{ 683{
683 VCardLine line( "SOUND" ); 684 VCardLine line( "SOUND" );
684 685
685 if ( snd.isIntern() ) { 686 if ( snd.isIntern() ) {
686 if ( !snd.data().isEmpty() ) { 687 if ( !snd.data().isEmpty() ) {
687 qDebug("VCardTool::createSound has to be verified"); 688 qDebug("VCardTool::createSound has to be verified");
688//US line.setValue( snd.data() ); 689//US line.setValue( snd.data() );
689 690
690//US I am not sure if this is correct 691//US I am not sure if this is correct
691 QCString cs(snd.data()); 692 QCString cs(snd.data());
692 line.setValue( cs ); 693 line.setValue( cs );
693 694
694 695
695 line.addParameter( "encoding", "b" ); 696 line.addParameter( "encoding", "b" );
696 // TODO: need to store sound type!!! 697 // TODO: need to store sound type!!!
697 } 698 }
698 } else if ( !snd.url().isEmpty() ) { 699 } else if ( !snd.url().isEmpty() ) {
699 line.setValue( snd.url() ); 700 line.setValue( snd.url() );
700 line.addParameter( "value", "URI" ); 701 line.addParameter( "value", "URI" );
701 } 702 }
702 703
703 return line; 704 return line;
704} 705}
705 706
706Key VCardTool::parseKey( const VCardLine &line ) 707Key VCardTool::parseKey( const VCardLine &line )
707{ 708{
708 Key key; 709 Key key;
709 710
710 QStringList params = line.parameterList(); 711 QStringList params = line.parameterList();
711 if ( params.contains( "encoding" ) ) { 712 if ( params.contains( "encoding" ) ) {
712 qDebug("VCardTool::parseKey has to be verified"); 713 qDebug("VCardTool::parseKey has to be verified");
713//US key.setBinaryData( line.value().asByteArray() ); 714//US key.setBinaryData( line.value().asByteArray() );
714 715
715//US I am not sure if this is correct 716//US I am not sure if this is correct
716 QCString cs( line.value().asCString() ); 717 QCString cs( line.value().asCString() );
717 key.setBinaryData( cs ); 718 key.setBinaryData( cs );
718 } 719 }
719 else 720 else
720 key.setTextData( line.value().asString() ); 721 key.setTextData( line.value().asString() );
721 722
722 if ( params.contains( "type" ) ) { 723 if ( params.contains( "type" ) ) {
723 if ( line.parameter( "type" ).lower() == "x509" ) 724 if ( line.parameter( "type" ).lower() == "x509" )
724 key.setType( Key::X509 ); 725 key.setType( Key::X509 );
725 else if ( line.parameter( "type" ).lower() == "pgp" ) 726 else if ( line.parameter( "type" ).lower() == "pgp" )
726 key.setType( Key::PGP ); 727 key.setType( Key::PGP );
727 else { 728 else {
728 key.setType( Key::Custom ); 729 key.setType( Key::Custom );
729 key.setCustomTypeString( line.parameter( "type" ) ); 730 key.setCustomTypeString( line.parameter( "type" ) );
730 } 731 }
731 } 732 }
732 733
733 return key; 734 return key;
734} 735}
735 736
736VCardLine VCardTool::createKey( const Key &key ) 737VCardLine VCardTool::createKey( const Key &key )
737{ 738{
738 VCardLine line( "KEY" ); 739 VCardLine line( "KEY" );
739 740
740 if ( key.isBinary() ) { 741 if ( key.isBinary() ) {
741 if ( !key.binaryData().isEmpty() ) { 742 if ( !key.binaryData().isEmpty() ) {
742 qDebug("VCardTool::createKey has to be verified"); 743 qDebug("VCardTool::createKey has to be verified");
743//US line.setValue( key.binaryData() ); 744//US line.setValue( key.binaryData() );
744//US I am not sure if this is correct 745//US I am not sure if this is correct
745 QCString cs(key.binaryData()); 746 QCString cs(key.binaryData());
746 line.setValue( cs ); 747 line.setValue( cs );
747 748
748 749
749 line.addParameter( "encoding", "b" ); 750 line.addParameter( "encoding", "b" );
750 } 751 }
751 } else if ( !key.textData().isEmpty() ) 752 } else if ( !key.textData().isEmpty() )
752 line.setValue( key.textData() ); 753 line.setValue( key.textData() );
753 754
754 if ( key.type() == Key::X509 ) 755 if ( key.type() == Key::X509 )
755 line.addParameter( "type", "X509" ); 756 line.addParameter( "type", "X509" );
756 else if ( key.type() == Key::PGP ) 757 else if ( key.type() == Key::PGP )
757 line.addParameter( "type", "PGP" ); 758 line.addParameter( "type", "PGP" );
758 else if ( key.type() == Key::Custom ) 759 else if ( key.type() == Key::Custom )
759 line.addParameter( "type", key.customTypeString() ); 760 line.addParameter( "type", key.customTypeString() );
760 761
761 return line; 762 return line;
762} 763}
763 764
764Secrecy VCardTool::parseSecrecy( const VCardLine &line ) 765Secrecy VCardTool::parseSecrecy( const VCardLine &line )
765{ 766{
766 Secrecy secrecy; 767 Secrecy secrecy;
767 768
768 if ( line.value().asString().lower() == "public" ) 769 if ( line.value().asString().lower() == "public" )
769 secrecy.setType( Secrecy::Public ); 770 secrecy.setType( Secrecy::Public );
770 if ( line.value().asString().lower() == "private" ) 771 if ( line.value().asString().lower() == "private" )
771 secrecy.setType( Secrecy::Private ); 772 secrecy.setType( Secrecy::Private );
772 if ( line.value().asString().lower() == "confidential" ) 773 if ( line.value().asString().lower() == "confidential" )
773 secrecy.setType( Secrecy::Confidential ); 774 secrecy.setType( Secrecy::Confidential );
774 775
775 return secrecy; 776 return secrecy;
776} 777}
777 778
778VCardLine VCardTool::createSecrecy( const Secrecy &secrecy ) 779VCardLine VCardTool::createSecrecy( const Secrecy &secrecy )
779{ 780{
780 VCardLine line( "CLASS" ); 781 VCardLine line( "CLASS" );
781 782
782 int type = secrecy.type(); 783 int type = secrecy.type();
783 784
784 if ( type == Secrecy::Public ) 785 if ( type == Secrecy::Public )
785 line.setValue( "PUBLIC" ); 786 line.setValue( "PUBLIC" );
786 else if ( type == Secrecy::Private ) 787 else if ( type == Secrecy::Private )
787 line.setValue( "PRIVATE" ); 788 line.setValue( "PRIVATE" );
788 else if ( type == Secrecy::Confidential ) 789 else if ( type == Secrecy::Confidential )
789 line.setValue( "CONFIDENTIAL" ); 790 line.setValue( "CONFIDENTIAL" );
790 791
791 return line; 792 return line;
792} 793}
793 794
794Agent VCardTool::parseAgent( const VCardLine &line ) 795Agent VCardTool::parseAgent( const VCardLine &line )
795{ 796{
796 Agent agent; 797 Agent agent;
797 798
798 QStringList params = line.parameterList(); 799 QStringList params = line.parameterList();
799 if ( params.contains( "value" ) ) { 800 if ( params.contains( "value" ) ) {
800 if ( line.parameter( "value" ).lower() == "uri" ) 801 if ( line.parameter( "value" ).lower() == "uri" )
801 agent.setUrl( line.value().asString() ); 802 agent.setUrl( line.value().asString() );
802 } else { 803 } else {
803 QString str = line.value().asString(); 804 QString str = line.value().asString();
804 805
805//US using the old implementation instead 806//US using the old implementation instead
806 qDebug("VCardTool::parseAgent has to be verified"); 807 qDebug("VCardTool::parseAgent has to be verified");
807/*US 808/*US
808 str.replace( "\\n", "\r\n" ); 809 str.replace( "\\n", "\r\n" );
809 str.replace( "\\N", "\r\n" ); 810 str.replace( "\\N", "\r\n" );
810 str.replace( "\\;", ";" ); 811 str.replace( "\\;", ";" );
811 str.replace( "\\:", ":" ); 812 str.replace( "\\:", ":" );
812 str.replace( "\\,", "," ); 813 str.replace( "\\,", "," );
813*/ 814*/
814 str.replace( QRegExp("\\n") , "\r\n" ); 815 str.replace( QRegExp("\\n") , "\r\n" );
815 str.replace( QRegExp("\\N") , "\r\n" ); 816 str.replace( QRegExp("\\N") , "\r\n" );
816 str.replace( QRegExp("\\;") , ";" ); 817 str.replace( QRegExp("\\;") , ";" );
817 str.replace( QRegExp("\\:") , ":" ); 818 str.replace( QRegExp("\\:") , ":" );
818 str.replace( QRegExp("\\,") , "," ); 819 str.replace( QRegExp("\\,") , "," );
819 820
820 Addressee::List list = parseVCards( str ); 821 Addressee::List list = parseVCards( str );
821 if ( list.count() > 0 ) { 822 if ( list.count() > 0 ) {
822 Addressee *addr = new Addressee; 823 Addressee *addr = new Addressee;
823 *addr = list[ 0 ]; 824 *addr = list[ 0 ];
824 agent.setAddressee( addr ); 825 agent.setAddressee( addr );
825 } 826 }
826 } 827 }
827 828
828 return agent; 829 return agent;
829} 830}
830 831
831VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent ) 832VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent )
832{ 833{
833 VCardLine line( "AGENT" ); 834 VCardLine line( "AGENT" );
834 835
835 if ( agent.isIntern() ) { 836 if ( agent.isIntern() ) {
836 if ( agent.addressee() != 0 ) { 837 if ( agent.addressee() != 0 ) {
837 Addressee::List list; 838 Addressee::List list;
838 list.append( *agent.addressee() ); 839 list.append( *agent.addressee() );
839 840
840 QString str = createVCards( list, version ); 841 QString str = createVCards( list, version );
841 842
842//US using the old implementation instead 843//US using the old implementation instead
843 qDebug("VCardTool::createAgent has to be verified"); 844 qDebug("VCardTool::createAgent has to be verified");
844/*US 845/*US
845 str.replace( "\r\n", "\\n" ); 846 str.replace( "\r\n", "\\n" );
846 str.replace( ";", "\\;" ); 847 str.replace( ";", "\\;" );
847 str.replace( ":", "\\:" ); 848 str.replace( ":", "\\:" );
848 str.replace( ",", "\\," ); 849 str.replace( ",", "\\," );
849*/ 850*/
850 str.replace( QRegExp("\r\n"), "\\n" ); 851 str.replace( QRegExp("\r\n"), "\\n" );
851 str.replace( QRegExp(";"), "\\;" ); 852 str.replace( QRegExp(";"), "\\;" );
852 str.replace( QRegExp(":"), "\\:" ); 853 str.replace( QRegExp(":"), "\\:" );
853 str.replace( QRegExp(","), "\\," ); 854 str.replace( QRegExp(","), "\\," );
854 line.setValue( str ); 855 line.setValue( str );
855 } 856 }
856 } else if ( !agent.url().isEmpty() ) { 857 } else if ( !agent.url().isEmpty() ) {
857 line.setValue( agent.url() ); 858 line.setValue( agent.url() );
858 line.addParameter( "value", "URI" ); 859 line.addParameter( "value", "URI" );
859 } 860 }
860 861
861 return line; 862 return line;
862} 863}
863 864
864QStringList VCardTool::splitString( const QChar &sep, const QString &str ) 865QStringList VCardTool::splitString( const QChar &sep, const QString &str )
865{ 866{
866 QStringList list; 867 QStringList list;
867 QString value( str ); 868 QString value( str );
868 869
869 int start = 0; 870 int start = 0;
870 int pos = value.find( sep, start ); 871 int pos = value.find( sep, start );
871 872
872 while ( pos != -1 ) { 873 while ( pos != -1 ) {
873 if ( value[ pos - 1 ] != '\\' ) { 874 if ( value[ pos - 1 ] != '\\' ) {
874 if ( pos > start && pos <= (int)value.length() ) 875 if ( pos > start && pos <= (int)value.length() )
875 list << value.mid( start, pos - start ); 876 list << value.mid( start, pos - start );
876 else 877 else
877 list << QString::null; 878 list << QString::null;
878 879
879 start = pos + 1; 880 start = pos + 1;
880 pos = value.find( sep, start ); 881 pos = value.find( sep, start );
881 } else { 882 } else {
882 if ( pos != 0 ) { 883 if ( pos != 0 ) {
883 value.replace( pos - 1, 2, sep ); 884 value.replace( pos - 1, 2, sep );
884 pos = value.find( sep, pos ); 885 pos = value.find( sep, pos );
885 } else 886 } else
886 pos = value.find( sep, pos + 1 ); 887 pos = value.find( sep, pos + 1 );
887 } 888 }
888 } 889 }
889 890
890 int l = value.length() - 1; 891 int l = value.length() - 1;
891 if ( value.mid( start, l - start + 1 ).length() > 0 ) 892 if ( value.mid( start, l - start + 1 ).length() > 0 )
892 list << value.mid( start, l - start + 1 ); 893 list << value.mid( start, l - start + 1 );
893 else 894 else
894 list << QString::null; 895 list << QString::null;
895 896
896 return list; 897 return list;
897} 898}