author | zautrix <zautrix> | 2005-04-08 22:05:03 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-08 22:05:03 (UTC) |
commit | 9667e6f2589d5b2080cca928814f382761f8dda6 (patch) (unidiff) | |
tree | 438bcb5c041de0804284cf457cbc97a367dadf37 /kabc/vcardparser/vcardparser.cpp | |
parent | c0f1d38e29ee0d0a1d1dcb5bda08089923926b41 (diff) | |
download | kdepimpi-9667e6f2589d5b2080cca928814f382761f8dda6.zip kdepimpi-9667e6f2589d5b2080cca928814f382761f8dda6.tar.gz kdepimpi-9667e6f2589d5b2080cca928814f382761f8dda6.tar.bz2 |
utf8 kapi import fix
Diffstat (limited to 'kabc/vcardparser/vcardparser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/vcardparser/vcardparser.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp index 7fae011..11622a0 100644 --- a/kabc/vcardparser/vcardparser.cpp +++ b/kabc/vcardparser/vcardparser.cpp | |||
@@ -105,54 +105,54 @@ VCard::List VCardParser::parseVCards( const QString& text ) | |||
105 | vCardLine.addParameter( pair[0].lower(), pair[1] ); | 105 | vCardLine.addParameter( pair[0].lower(), pair[1] ); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | params = vCardLine.parameterList(); | 109 | params = vCardLine.parameterList(); |
110 | if ( params.findIndex( "encoding" ) != -1 ) { // have to decode the data | 110 | if ( params.findIndex( "encoding" ) != -1 ) { // have to decode the data |
111 | QByteArray input, output; | 111 | QByteArray input, output; |
112 | if ( vCardLine.parameter( "encoding" ).lower() == "b" || | 112 | if ( vCardLine.parameter( "encoding" ).lower() == "b" || |
113 | vCardLine.parameter( "encoding" ).lower() == "base64" ) { | 113 | vCardLine.parameter( "encoding" ).lower() == "base64" ) { |
114 | input = value.local8Bit(); | 114 | input = value.local8Bit(); |
115 | KCodecs::base64Decode( input, output ); | 115 | KCodecs::base64Decode( input, output ); |
116 | } else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" ) { | 116 | } else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" ) { |
117 | // join any qp-folded lines | 117 | // join any qp-folded lines |
118 | while ( value.mid(value.length()-1,1) == "=" && it != linesEnd ) { | 118 | while ( value.mid(value.length()-1,1) == "=" && it != linesEnd ) { |
119 | value = value.remove( value.length()-1, 1 ) + (*it); | 119 | value = value.remove( value.length()-1, 1 ) + (*it); |
120 | ++it; | 120 | ++it; |
121 | } | 121 | } |
122 | input = value.local8Bit(); | 122 | input = value.local8Bit(); |
123 | KCodecs::quotedPrintableDecode( input, output ); | 123 | KCodecs::quotedPrintableDecode( input, output ); |
124 | } | 124 | } |
125 | //PP our vcards are *supposed* to be in UTF-8 | 125 | //PP our vcards are *supposed* to be in UTF-8 |
126 | // if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) { | 126 | // if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) { |
127 | // vCardLine.setValue( QString::fromUtf8( output.data(), output.size() ) ); | 127 | // vCardLine.setValue( QString::fromUtf8( output.data(), output.size() ) ); |
128 | // } else | 128 | // } else |
129 | vCardLine.setValue( output ); | 129 | vCardLine.setValueBytes( output ); |
130 | //PP our vcards are *supposed* to be in UTF-8 | 130 | //PP our vcards are *supposed* to be in UTF-8 |
131 | // } else if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) { | 131 | // } else if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) { |
132 | // vCardLine.setValue( QString::fromUtf8( value.ascii() ) ); | 132 | // vCardLine.setValue( QString::fromUtf8( value.ascii() ) ); |
133 | } else | 133 | } else |
134 | vCardLine.setValue( value.replace( QRegExp("\\\\n"), "\n" ) ); | 134 | vCardLine.setValueString( value.replace( QRegExp("\\\\n"), "\n" ) ); |
135 | 135 | ||
136 | currentVCard.addLine( vCardLine ); | 136 | currentVCard.addLine( vCardLine ); |
137 | } | 137 | } |
138 | 138 | ||
139 | // we do not save the start and end tag as vcardline | 139 | // we do not save the start and end tag as vcardline |
140 | if ( (*it).lower().startsWith( "begin:vcard" ) ) { | 140 | if ( (*it).lower().startsWith( "begin:vcard" ) ) { |
141 | inVCard = true; | 141 | inVCard = true; |
142 | currentLine = ""; | 142 | currentLine = ""; |
143 | currentVCard.clear(); // flush vcard | 143 | currentVCard.clear(); // flush vcard |
144 | continue; | 144 | continue; |
145 | } | 145 | } |
146 | 146 | ||
147 | if ( (*it).lower().startsWith( "end:vcard" ) ) { | 147 | if ( (*it).lower().startsWith( "end:vcard" ) ) { |
148 | inVCard = false; | 148 | inVCard = false; |
149 | vCardList.append( currentVCard ); | 149 | vCardList.append( currentVCard ); |
150 | currentLine = ""; | 150 | currentLine = ""; |
151 | currentVCard.clear(); // flush vcard | 151 | currentVCard.clear(); // flush vcard |
152 | continue; | 152 | continue; |
153 | } | 153 | } |
154 | 154 | ||
155 | currentLine = (*it); | 155 | currentLine = (*it); |
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
@@ -167,74 +167,74 @@ QString VCardParser::createVCards( const VCard::List& list ) | |||
167 | QStringList idents; | 167 | QStringList idents; |
168 | QStringList params; | 168 | QStringList params; |
169 | QStringList values; | 169 | QStringList values; |
170 | QStringList::ConstIterator identIt; | 170 | QStringList::ConstIterator identIt; |
171 | QStringList::Iterator paramIt; | 171 | QStringList::Iterator paramIt; |
172 | QStringList::ConstIterator valueIt; | 172 | QStringList::ConstIterator valueIt; |
173 | 173 | ||
174 | VCardLine::List lines; | 174 | VCardLine::List lines; |
175 | VCardLine::List::ConstIterator lineIt; | 175 | VCardLine::List::ConstIterator lineIt; |
176 | VCard::List::ConstIterator cardIt; | 176 | VCard::List::ConstIterator cardIt; |
177 | 177 | ||
178 | bool hasEncoding; | 178 | bool hasEncoding; |
179 | 179 | ||
180 | // iterate over the cards | 180 | // iterate over the cards |
181 | VCard::List::ConstIterator listEnd( list.end() ); | 181 | VCard::List::ConstIterator listEnd( list.end() ); |
182 | for ( cardIt = list.begin(); cardIt != listEnd; ++cardIt ) { | 182 | for ( cardIt = list.begin(); cardIt != listEnd; ++cardIt ) { |
183 | text.append( "BEGIN:VCARD\r\n" ); | 183 | text.append( "BEGIN:VCARD\r\n" ); |
184 | 184 | ||
185 | idents = (*cardIt).identifiers(); | 185 | idents = (*cardIt).identifiers(); |
186 | for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { | 186 | for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { |
187 | lines = (*cardIt).lines( (*identIt) ); | 187 | lines = (*cardIt).lines( (*identIt) ); |
188 | 188 | ||
189 | // iterate over the lines | 189 | // iterate over the lines |
190 | for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { | 190 | for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { |
191 | if ( !(*lineIt).value().asString().isEmpty() ) { | 191 | if ( !(*lineIt).valueString().isEmpty() ) { |
192 | if ( (*lineIt).hasGroup() ) | 192 | if ( (*lineIt).hasGroup() ) |
193 | textLine = (*lineIt).group() + "." + (*lineIt).identifier(); | 193 | textLine = (*lineIt).group() + "." + (*lineIt).identifier(); |
194 | else | 194 | else |
195 | textLine = (*lineIt).identifier(); | 195 | textLine = (*lineIt).identifier(); |
196 | 196 | ||
197 | params = (*lineIt).parameterList(); | 197 | params = (*lineIt).parameterList(); |
198 | hasEncoding = false; | 198 | hasEncoding = false; |
199 | if ( params.count() > 0 ) { // we have parameters | 199 | if ( params.count() > 0 ) { // we have parameters |
200 | for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { | 200 | for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { |
201 | if ( (*paramIt) == "encoding" ) { | 201 | if ( (*paramIt) == "encoding" ) { |
202 | hasEncoding = true; | 202 | hasEncoding = true; |
203 | encodingType = (*lineIt).parameter( "encoding" ).lower(); | 203 | encodingType = (*lineIt).parameter( "encoding" ).lower(); |
204 | } | 204 | } |
205 | 205 | ||
206 | values = (*lineIt).parameters( *paramIt ); | 206 | values = (*lineIt).parameters( *paramIt ); |
207 | for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) { | 207 | for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) { |
208 | textLine.append( ";" + (*paramIt).upper() ); | 208 | textLine.append( ";" + (*paramIt).upper() ); |
209 | if ( !(*valueIt).isEmpty() ) | 209 | if ( !(*valueIt).isEmpty() ) |
210 | textLine.append( "=" + (*valueIt) ); | 210 | textLine.append( "=" + (*valueIt) ); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | if ( hasEncoding ) { // have to encode the data | 215 | if ( hasEncoding ) { // have to encode the data |
216 | QByteArray input, output; | 216 | QByteArray input, output; |
217 | input = (*lineIt).valueBytes(); | 217 | input = (*lineIt).valueBytes(); |
218 | if ( encodingType == "b" ) | 218 | if ( encodingType == "b" ) |
219 | KCodecs::base64Encode( input, output ); | 219 | KCodecs::base64Encode( input, output ); |
220 | else if ( encodingType == "quoted-printable" ) | 220 | else if ( encodingType == "quoted-printable" ) |
221 | KCodecs::quotedPrintableEncode( input, output ); | 221 | KCodecs::quotedPrintableEncode( input, output ); |
222 | textLine.append( ":" + QString( output ) ); | 222 | textLine.append( ":" + QString( output ) ); |
223 | } else | 223 | } else |
224 | textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) ); | 224 | textLine.append( ":" + (*lineIt).valueString().replace( QRegExp("\n"), "\\n" ) ); |
225 | 225 | ||
226 | if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line | 226 | if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line |
227 | for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) | 227 | for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) |
228 | text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); | 228 | text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); |
229 | } else | 229 | } else |
230 | text.append( textLine + "\r\n" ); | 230 | text.append( textLine + "\r\n" ); |
231 | } | 231 | } |
232 | } | 232 | } |
233 | } | 233 | } |
234 | 234 | ||
235 | text.append( "END:VCARD\r\n" ); | 235 | text.append( "END:VCARD\r\n" ); |
236 | text.append( "\r\n" ); | 236 | text.append( "\r\n" ); |
237 | } | 237 | } |
238 | 238 | ||
239 | return text; | 239 | return text; |
240 | } | 240 | } |