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