summaryrefslogtreecommitdiffabout
path: root/kabc/vcardparser
authorzautrix <zautrix>2004-10-13 05:15:03 (UTC)
committer zautrix <zautrix>2004-10-13 05:15:03 (UTC)
commitf08cf9044213a60c87e2bf299665d13a335feff5 (patch) (unidiff)
treec9c0e8b0f7f7a48dcee8fbdd5b9a467985c78fdd /kabc/vcardparser
parent308bc78a3ab0d27718070a5ebdf3f019ac570c6b (diff)
downloadkdepimpi-f08cf9044213a60c87e2bf299665d13a335feff5.zip
kdepimpi-f08cf9044213a60c87e2bf299665d13a335feff5.tar.gz
kdepimpi-f08cf9044213a60c87e2bf299665d13a335feff5.tar.bz2
fixed some newline probs
Diffstat (limited to 'kabc/vcardparser') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardparser/vcardparser.cpp2
-rw-r--r--kabc/vcardparser/vcardtool.cpp10
2 files changed, 6 insertions, 6 deletions
diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp
index 9ea084d..bec2a0c 100644
--- a/kabc/vcardparser/vcardparser.cpp
+++ b/kabc/vcardparser/vcardparser.cpp
@@ -1,233 +1,233 @@
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 <qregexp.h> 21#include <qregexp.h>
22 22
23#include <kmdcodec.h> 23#include <kmdcodec.h>
24 24
25#include "vcardparser.h" 25#include "vcardparser.h"
26 26
27#define FOLD_WIDTH 75 27#define FOLD_WIDTH 75
28 28
29using namespace KABC; 29using namespace KABC;
30 30
31VCardParser::VCardParser() 31VCardParser::VCardParser()
32{ 32{
33} 33}
34 34
35VCardParser::~VCardParser() 35VCardParser::~VCardParser()
36{ 36{
37} 37}
38 38
39VCard::List VCardParser::parseVCards( const QString& text ) 39VCard::List VCardParser::parseVCards( const QString& text )
40{ 40{
41 VCard currentVCard; 41 VCard currentVCard;
42 VCard::List vCardList; 42 VCard::List vCardList;
43 QString currentLine; 43 QString currentLine;
44 44
45 QStringList lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), text ); 45 QStringList lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), text );
46 QStringList::Iterator it; 46 QStringList::Iterator it;
47 47
48 bool inVCard = false; 48 bool inVCard = false;
49 for ( it = lines.begin(); it != lines.end(); ++it ) { 49 for ( it = lines.begin(); it != lines.end(); ++it ) {
50 50
51 if ( (*it).isEmpty() ) // empty line 51 if ( (*it).isEmpty() ) // empty line
52 continue; 52 continue;
53 53
54 if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous 54 if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous
55 currentLine += (*it).remove( 0, 1 ); 55 currentLine += (*it).remove( 0, 1 );
56 continue; 56 continue;
57 } else { 57 } else {
58 if ( inVCard && !currentLine.isEmpty() ) { // now parse the line 58 if ( inVCard && !currentLine.isEmpty() ) { // now parse the line
59 int colon = currentLine.find( ':' ); 59 int colon = currentLine.find( ':' );
60 if ( colon == -1 ) { // invalid line 60 if ( colon == -1 ) { // invalid line
61 currentLine = (*it); 61 currentLine = (*it);
62 continue; 62 continue;
63 } 63 }
64 64
65 VCardLine vCardLine; 65 VCardLine vCardLine;
66 QString key = currentLine.left( colon ).stripWhiteSpace(); 66 QString key = currentLine.left( colon ).stripWhiteSpace();
67 QString value = currentLine.mid( colon + 1 ); 67 QString value = currentLine.mid( colon + 1 );
68 68
69 QStringList params = QStringList::split( ';', key ); 69 QStringList params = QStringList::split( ';', key );
70 vCardLine.setIdentifier( params[0] ); 70 vCardLine.setIdentifier( params[0] );
71 if ( params.count() > 1 ) { // find all parameters 71 if ( params.count() > 1 ) { // find all parameters
72 for ( uint i = 1; i < params.count(); ++i ) { 72 for ( uint i = 1; i < params.count(); ++i ) {
73 QStringList pair = QStringList::split( '=', params[i] ); 73 QStringList pair = QStringList::split( '=', params[i] );
74//US if ( pair.size() == 1 ) { 74//US if ( pair.size() == 1 ) {
75 if ( pair.count() == 1 ) { 75 if ( pair.count() == 1 ) {
76 pair.prepend( "type" ); 76 pair.prepend( "type" );
77 } 77 }
78 if ( pair[1].contains( ',' ) ) { // parameter in type=x,y,z format 78 if ( pair[1].contains( ',' ) ) { // parameter in type=x,y,z format
79 QStringList args = QStringList::split( ',', pair[ 1 ] ); 79 QStringList args = QStringList::split( ',', pair[ 1 ] );
80 for ( uint j = 0; j < args.count(); ++j ) 80 for ( uint j = 0; j < args.count(); ++j )
81 vCardLine.addParameter( pair[0].lower(), args[j] ); 81 vCardLine.addParameter( pair[0].lower(), args[j] );
82 } else 82 } else
83 vCardLine.addParameter( pair[0].lower(), pair[1] ); 83 vCardLine.addParameter( pair[0].lower(), pair[1] );
84 } 84 }
85 } 85 }
86 86
87 params = vCardLine.parameterList(); 87 params = vCardLine.parameterList();
88 if ( params.contains( "encoding" ) ) { // have to decode the data 88 if ( params.contains( "encoding" ) ) { // have to decode the data
89#if 0 89#if 0
90 QByteArray input, output; 90 QByteArray input, output;
91 input = value.local8Bit(); 91 input = value.local8Bit();
92 if ( vCardLine.parameter( "encoding" ).lower() == "b" ) 92 if ( vCardLine.parameter( "encoding" ).lower() == "b" )
93 KCodecs::base64Decode( input, output ); 93 KCodecs::base64Decode( input, output );
94 else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" ) 94 else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" )
95 KCodecs::quotedPrintableDecode( input, output ); 95 KCodecs::quotedPrintableDecode( input, output );
96 96
97 //qDebug("VCardParser::parseVCards has to be verified"); 97 //qDebug("VCardParser::parseVCards has to be verified");
98 //US I am not sure if this is correct 98 //US I am not sure if this is correct
99 //US vCardLine.setValue( output ); 99 //US vCardLine.setValue( output );
100 QCString cs(output); 100 QCString cs(output);
101 qDebug("len1 %d len2 %d ",input.size(), output.size( )); 101 qDebug("len1 %d len2 %d ",input.size(), output.size( ));
102#endif 102#endif
103 QCString cs = value.local8Bit(); 103 QCString cs = value.local8Bit();
104 qDebug("****************************************** "); 104 qDebug("****************************************** ");
105 qDebug("************* WARNING ******************** "); 105 qDebug("************* WARNING ******************** ");
106 qDebug("****************************************** "); 106 qDebug("****************************************** ");
107 qDebug("Make sure, the decoding is done after"); 107 qDebug("Make sure, the decoding is done after");
108 qDebug("QVariant conversion!"); 108 qDebug("QVariant conversion!");
109 qDebug("Insert Line DECODING OKAY, where this is implemented"); 109 qDebug("Insert Line DECODING OKAY, where this is implemented");
110 // use for decoding the above code! 110 // use for decoding the above code!
111 vCardLine.setValue( cs ); 111 vCardLine.setValue( cs );
112 } else { 112 } else {
113 113
114 //qDebug("VCardParser::parseVCards has to be verified"); 114 //qDebug("VCardParser::parseVCards has to be verified");
115//US vCardLine.setValue( value.replace( "\\n", "\n" ) ); 115//US vCardLine.setValue( value.replace( "\\n", "\n" ) );
116 vCardLine.setValue( value.replace( QRegExp("\\n"), "\n" ) ); 116 vCardLine.setValue( value.replace( QRegExp("\\\\n"), "\n" ) );
117 } 117 }
118 118
119 currentVCard.addLine( vCardLine ); 119 currentVCard.addLine( vCardLine );
120 } 120 }
121 // we do not save the start and end tag as vcardline 121 // we do not save the start and end tag as vcardline
122 if ( (*it).lower().startsWith( "begin:vcard" ) ) { 122 if ( (*it).lower().startsWith( "begin:vcard" ) ) {
123 inVCard = true; 123 inVCard = true;
124 //qDebug("VCardParser::parseVCards has to be verified"); 124 //qDebug("VCardParser::parseVCards has to be verified");
125//US currentLine.setLength( 0 ); 125//US currentLine.setLength( 0 );
126 currentLine = ""; 126 currentLine = "";
127 currentVCard.clear(); // flush vcard 127 currentVCard.clear(); // flush vcard
128 continue; 128 continue;
129 } 129 }
130 130
131 if ( (*it).lower().startsWith( "end:vcard" ) ) { 131 if ( (*it).lower().startsWith( "end:vcard" ) ) {
132 inVCard = false; 132 inVCard = false;
133 vCardList.append( currentVCard ); 133 vCardList.append( currentVCard );
134 //qDebug("VCardParser::parseVCards has to be verified"); 134 //qDebug("VCardParser::parseVCards has to be verified");
135//US currentLine.setLength( 0 ); 135//US currentLine.setLength( 0 );
136 currentLine = ""; 136 currentLine = "";
137 currentVCard.clear(); // flush vcard 137 currentVCard.clear(); // flush vcard
138 continue; 138 continue;
139 } 139 }
140 140
141 currentLine = (*it); 141 currentLine = (*it);
142 } 142 }
143 } 143 }
144 144
145 return vCardList; 145 return vCardList;
146} 146}
147 147
148QString VCardParser::createVCards( const VCard::List& list ) 148QString VCardParser::createVCards( const VCard::List& list )
149{ 149{
150 QString text; 150 QString text;
151 QString textLine; 151 QString textLine;
152 QString encodingType; 152 QString encodingType;
153 QStringList idents; 153 QStringList idents;
154 QStringList params; 154 QStringList params;
155 QStringList values; 155 QStringList values;
156 QStringList::ConstIterator identIt; 156 QStringList::ConstIterator identIt;
157 QStringList::Iterator paramIt; 157 QStringList::Iterator paramIt;
158 QStringList::Iterator valueIt; 158 QStringList::Iterator valueIt;
159 159
160 VCardLine::List lines; 160 VCardLine::List lines;
161 VCardLine::List::Iterator lineIt; 161 VCardLine::List::Iterator lineIt;
162 VCard::List::ConstIterator cardIt; 162 VCard::List::ConstIterator cardIt;
163 163
164 bool hasEncoding; 164 bool hasEncoding;
165 165
166 166
167 // iterate over the cards 167 // iterate over the cards
168 for ( cardIt = list.begin(); cardIt != list.end(); ++cardIt ) { 168 for ( cardIt = list.begin(); cardIt != list.end(); ++cardIt ) {
169 text.append( "BEGIN:VCARD\r\n" ); 169 text.append( "BEGIN:VCARD\r\n" );
170 170
171 idents = (*cardIt).identifiers(); 171 idents = (*cardIt).identifiers();
172 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { 172 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
173 VCard card = (*cardIt); 173 VCard card = (*cardIt);
174 lines = card.lines( (*identIt) ); 174 lines = card.lines( (*identIt) );
175 175
176 // iterate over the lines 176 // iterate over the lines
177 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { 177 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
178 if ( !(*lineIt).value().asString().isEmpty() ) { 178 if ( !(*lineIt).value().asString().isEmpty() ) {
179 textLine = (*lineIt).identifier(); 179 textLine = (*lineIt).identifier();
180 180
181 params = (*lineIt).parameterList(); 181 params = (*lineIt).parameterList();
182 hasEncoding = false; 182 hasEncoding = false;
183 if ( params.count() > 0 ) { // we have parameters 183 if ( params.count() > 0 ) { // we have parameters
184 for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { 184 for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) {
185 if ( (*paramIt) == "encoding" ) { 185 if ( (*paramIt) == "encoding" ) {
186 hasEncoding = true; 186 hasEncoding = true;
187 encodingType = (*lineIt).parameter( "encoding" ).lower(); 187 encodingType = (*lineIt).parameter( "encoding" ).lower();
188 } 188 }
189 189
190 values = (*lineIt).parameters( *paramIt ); 190 values = (*lineIt).parameters( *paramIt );
191 for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) { 191 for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) {
192 textLine.append( ";" + (*paramIt).upper() ); 192 textLine.append( ";" + (*paramIt).upper() );
193 if ( !(*valueIt).isEmpty() ) 193 if ( !(*valueIt).isEmpty() )
194 textLine.append( "=" + (*valueIt) ); 194 textLine.append( "=" + (*valueIt) );
195 } 195 }
196 } 196 }
197 } 197 }
198 198
199 if ( hasEncoding ) { // have to encode the data 199 if ( hasEncoding ) { // have to encode the data
200 QByteArray input, output; 200 QByteArray input, output;
201 201
202 qDebug("VCardParser::createVCards has to be verified"); 202 qDebug("VCardParser::createVCards has to be verified");
203//US input = (*lineIt).value().toByteArray(); 203//US input = (*lineIt).value().toByteArray();
204 204
205//US I am not sure if this is correct 205//US I am not sure if this is correct
206 QCString cs ((*lineIt).value().toCString()); 206 QCString cs ((*lineIt).value().toCString());
207 input = cs; 207 input = cs;
208 208
209 if ( encodingType == "b" ) 209 if ( encodingType == "b" )
210 KCodecs::base64Encode( input, output ); 210 KCodecs::base64Encode( input, output );
211 else if ( encodingType == "quoted-printable" ) 211 else if ( encodingType == "quoted-printable" )
212 KCodecs::quotedPrintableEncode( input, output ); 212 KCodecs::quotedPrintableEncode( input, output );
213 textLine.append( ":" + QString( output ) ); 213 textLine.append( ":" + QString( output ) );
214 } else { 214 } else {
215 qDebug("VCardParser::createVCards has to be verified"); 215 qDebug("VCardParser::createVCards has to be verified");
216//US textLine.append( ":" + (*lineIt).value().asString().replace( "\n", "\\n" ) ); 216//US textLine.append( ":" + (*lineIt).value().asString().replace( "\n", "\\n" ) );
217 textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) ); 217 textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) );
218 } 218 }
219 if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line 219 if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line
220 for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) 220 for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i )
221 text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); 221 text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" );
222 } else 222 } else
223 text.append( textLine + "\r\n" ); 223 text.append( textLine + "\r\n" );
224 } 224 }
225 } 225 }
226 } 226 }
227 227
228 text.append( "END:VCARD\r\n" ); 228 text.append( "END:VCARD\r\n" );
229 text.append( "\r\n" ); 229 text.append( "\r\n" );
230 } 230 }
231 231
232 return text; 232 return text;
233} 233}
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp
index 3fb212e..d1f823b 100644
--- a/kabc/vcardparser/vcardtool.cpp
+++ b/kabc/vcardparser/vcardtool.cpp
@@ -623,276 +623,276 @@ Picture VCardTool::parsePicture( const VCardLine &line )
623VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) 623VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
624{ 624{
625 // LR fixed 625 // LR fixed
626 VCardLine line( identifier ); 626 VCardLine line( identifier );
627 627
628 if ( pic.isIntern() ) { 628 if ( pic.isIntern() ) {
629 if ( !pic.data().isNull() ) { 629 if ( !pic.data().isNull() ) {
630#if 0 630#if 0
631 QByteArray input; 631 QByteArray input;
632 QDataStream s( input, IO_WriteOnly ); 632 QDataStream s( input, IO_WriteOnly );
633 s.setVersion( 4 ); 633 s.setVersion( 4 );
634 s << pic.data(); 634 s << pic.data();
635 line.setValue( input ); 635 line.setValue( input );
636#else 636#else
637 QCString input; 637 QCString input;
638 QDataStream s( input, IO_WriteOnly ); 638 QDataStream s( input, IO_WriteOnly );
639 s.setVersion( 4 ); 639 s.setVersion( 4 );
640 s << pic.data(); 640 s << pic.data();
641 //QCString cs(line.value().asCString()); 641 //QCString cs(line.value().asCString());
642 //QImage qi(cs); 642 //QImage qi(cs);
643 line.setValue( input ); 643 line.setValue( input );
644#endif 644#endif
645 645
646 line.addParameter( "encoding", "b" ); 646 line.addParameter( "encoding", "b" );
647 line.addParameter( "type", "image/png" ); 647 line.addParameter( "type", "image/png" );
648 } 648 }
649 } else if ( !pic.url().isEmpty() ) { 649 } else if ( !pic.url().isEmpty() ) {
650 line.setValue( pic.url() ); 650 line.setValue( pic.url() );
651 line.addParameter( "value", "URI" ); 651 line.addParameter( "value", "URI" );
652 } 652 }
653 653
654 return line; 654 return line;
655} 655}
656 656
657Sound VCardTool::parseSound( const VCardLine &line ) 657Sound VCardTool::parseSound( const VCardLine &line )
658{ 658{
659 Sound snd; 659 Sound snd;
660 660
661 QStringList params = line.parameterList(); 661 QStringList params = line.parameterList();
662 if ( params.contains( "encoding" ) ) { 662 if ( params.contains( "encoding" ) ) {
663 qDebug("VCardTool::parseSound has to be verified"); 663 qDebug("VCardTool::parseSound has to be verified");
664//US snd.setData( line.value().asByteArray() ); 664//US snd.setData( line.value().asByteArray() );
665//US I am not sure if this is correct 665//US I am not sure if this is correct
666 QCString cs(line.value().asCString()); 666 QCString cs(line.value().asCString());
667 snd.setData( cs ); 667 snd.setData( cs );
668 } 668 }
669 else if ( params.contains( "value" ) ) { 669 else if ( params.contains( "value" ) ) {
670 if ( line.parameter( "value" ).lower() == "uri" ) 670 if ( line.parameter( "value" ).lower() == "uri" )
671 snd.setUrl( line.value().asString() ); 671 snd.setUrl( line.value().asString() );
672 } 672 }
673 673
674/* TODO: support sound types 674/* TODO: support sound types
675 if ( params.contains( "type" ) ) 675 if ( params.contains( "type" ) )
676 snd.setType( line.parameter( "type" ) ); 676 snd.setType( line.parameter( "type" ) );
677*/ 677*/
678 678
679 return snd; 679 return snd;
680} 680}
681 681
682VCardLine VCardTool::createSound( const Sound &snd ) 682VCardLine VCardTool::createSound( const Sound &snd )
683{ 683{
684 VCardLine line( "SOUND" ); 684 VCardLine line( "SOUND" );
685 685
686 if ( snd.isIntern() ) { 686 if ( snd.isIntern() ) {
687 if ( !snd.data().isEmpty() ) { 687 if ( !snd.data().isEmpty() ) {
688 qDebug("VCardTool::createSound has to be verified"); 688 qDebug("VCardTool::createSound has to be verified");
689//US line.setValue( snd.data() ); 689//US line.setValue( snd.data() );
690 690
691//US I am not sure if this is correct 691//US I am not sure if this is correct
692 QCString cs(snd.data()); 692 QCString cs(snd.data());
693 line.setValue( cs ); 693 line.setValue( cs );
694 694
695 695
696 line.addParameter( "encoding", "b" ); 696 line.addParameter( "encoding", "b" );
697 // TODO: need to store sound type!!! 697 // TODO: need to store sound type!!!
698 } 698 }
699 } else if ( !snd.url().isEmpty() ) { 699 } else if ( !snd.url().isEmpty() ) {
700 line.setValue( snd.url() ); 700 line.setValue( snd.url() );
701 line.addParameter( "value", "URI" ); 701 line.addParameter( "value", "URI" );
702 } 702 }
703 703
704 return line; 704 return line;
705} 705}
706 706
707Key VCardTool::parseKey( const VCardLine &line ) 707Key VCardTool::parseKey( const VCardLine &line )
708{ 708{
709 Key key; 709 Key key;
710 710
711 QStringList params = line.parameterList(); 711 QStringList params = line.parameterList();
712 if ( params.contains( "encoding" ) ) { 712 if ( params.contains( "encoding" ) ) {
713 qDebug("VCardTool::parseKey has to be verified"); 713 qDebug("VCardTool::parseKey has to be verified");
714//US key.setBinaryData( line.value().asByteArray() ); 714//US key.setBinaryData( line.value().asByteArray() );
715 715
716//US I am not sure if this is correct 716//US I am not sure if this is correct
717 QCString cs( line.value().asCString() ); 717 QCString cs( line.value().asCString() );
718 key.setBinaryData( cs ); 718 key.setBinaryData( cs );
719 } 719 }
720 else 720 else
721 key.setTextData( line.value().asString() ); 721 key.setTextData( line.value().asString() );
722 722
723 if ( params.contains( "type" ) ) { 723 if ( params.contains( "type" ) ) {
724 if ( line.parameter( "type" ).lower() == "x509" ) 724 if ( line.parameter( "type" ).lower() == "x509" )
725 key.setType( Key::X509 ); 725 key.setType( Key::X509 );
726 else if ( line.parameter( "type" ).lower() == "pgp" ) 726 else if ( line.parameter( "type" ).lower() == "pgp" )
727 key.setType( Key::PGP ); 727 key.setType( Key::PGP );
728 else { 728 else {
729 key.setType( Key::Custom ); 729 key.setType( Key::Custom );
730 key.setCustomTypeString( line.parameter( "type" ) ); 730 key.setCustomTypeString( line.parameter( "type" ) );
731 } 731 }
732 } 732 }
733 733
734 return key; 734 return key;
735} 735}
736 736
737VCardLine VCardTool::createKey( const Key &key ) 737VCardLine VCardTool::createKey( const Key &key )
738{ 738{
739 VCardLine line( "KEY" ); 739 VCardLine line( "KEY" );
740 740
741 if ( key.isBinary() ) { 741 if ( key.isBinary() ) {
742 if ( !key.binaryData().isEmpty() ) { 742 if ( !key.binaryData().isEmpty() ) {
743 qDebug("VCardTool::createKey has to be verified"); 743 qDebug("VCardTool::createKey has to be verified");
744//US line.setValue( key.binaryData() ); 744//US line.setValue( key.binaryData() );
745//US I am not sure if this is correct 745//US I am not sure if this is correct
746 QCString cs(key.binaryData()); 746 QCString cs(key.binaryData());
747 line.setValue( cs ); 747 line.setValue( cs );
748 748
749 749
750 line.addParameter( "encoding", "b" ); 750 line.addParameter( "encoding", "b" );
751 } 751 }
752 } else if ( !key.textData().isEmpty() ) 752 } else if ( !key.textData().isEmpty() )
753 line.setValue( key.textData() ); 753 line.setValue( key.textData() );
754 754
755 if ( key.type() == Key::X509 ) 755 if ( key.type() == Key::X509 )
756 line.addParameter( "type", "X509" ); 756 line.addParameter( "type", "X509" );
757 else if ( key.type() == Key::PGP ) 757 else if ( key.type() == Key::PGP )
758 line.addParameter( "type", "PGP" ); 758 line.addParameter( "type", "PGP" );
759 else if ( key.type() == Key::Custom ) 759 else if ( key.type() == Key::Custom )
760 line.addParameter( "type", key.customTypeString() ); 760 line.addParameter( "type", key.customTypeString() );
761 761
762 return line; 762 return line;
763} 763}
764 764
765Secrecy VCardTool::parseSecrecy( const VCardLine &line ) 765Secrecy VCardTool::parseSecrecy( const VCardLine &line )
766{ 766{
767 Secrecy secrecy; 767 Secrecy secrecy;
768 768
769 if ( line.value().asString().lower() == "public" ) 769 if ( line.value().asString().lower() == "public" )
770 secrecy.setType( Secrecy::Public ); 770 secrecy.setType( Secrecy::Public );
771 if ( line.value().asString().lower() == "private" ) 771 if ( line.value().asString().lower() == "private" )
772 secrecy.setType( Secrecy::Private ); 772 secrecy.setType( Secrecy::Private );
773 if ( line.value().asString().lower() == "confidential" ) 773 if ( line.value().asString().lower() == "confidential" )
774 secrecy.setType( Secrecy::Confidential ); 774 secrecy.setType( Secrecy::Confidential );
775 775
776 return secrecy; 776 return secrecy;
777} 777}
778 778
779VCardLine VCardTool::createSecrecy( const Secrecy &secrecy ) 779VCardLine VCardTool::createSecrecy( const Secrecy &secrecy )
780{ 780{
781 VCardLine line( "CLASS" ); 781 VCardLine line( "CLASS" );
782 782
783 int type = secrecy.type(); 783 int type = secrecy.type();
784 784
785 if ( type == Secrecy::Public ) 785 if ( type == Secrecy::Public )
786 line.setValue( "PUBLIC" ); 786 line.setValue( "PUBLIC" );
787 else if ( type == Secrecy::Private ) 787 else if ( type == Secrecy::Private )
788 line.setValue( "PRIVATE" ); 788 line.setValue( "PRIVATE" );
789 else if ( type == Secrecy::Confidential ) 789 else if ( type == Secrecy::Confidential )
790 line.setValue( "CONFIDENTIAL" ); 790 line.setValue( "CONFIDENTIAL" );
791 791
792 return line; 792 return line;
793} 793}
794 794
795Agent VCardTool::parseAgent( const VCardLine &line ) 795Agent VCardTool::parseAgent( const VCardLine &line )
796{ 796{
797 Agent agent; 797 Agent agent;
798 798
799 QStringList params = line.parameterList(); 799 QStringList params = line.parameterList();
800 if ( params.contains( "value" ) ) { 800 if ( params.contains( "value" ) ) {
801 if ( line.parameter( "value" ).lower() == "uri" ) 801 if ( line.parameter( "value" ).lower() == "uri" )
802 agent.setUrl( line.value().asString() ); 802 agent.setUrl( line.value().asString() );
803 } else { 803 } else {
804 QString str = line.value().asString(); 804 QString str = line.value().asString();
805 805
806//US using the old implementation instead 806//US using the old implementation instead
807 qDebug("VCardTool::parseAgent has to be verified"); 807 qDebug("VCardTool::parseAgent has to be verified");
808/*US 808/*US
809 str.replace( "\\n", "\r\n" ); 809 str.replace( "\\n", "\r\n" );
810 str.replace( "\\N", "\r\n" ); 810 str.replace( "\\N", "\r\n" );
811 str.replace( "\\;", ";" ); 811 str.replace( "\\;", ";" );
812 str.replace( "\\:", ":" ); 812 str.replace( "\\:", ":" );
813 str.replace( "\\,", "," ); 813 str.replace( "\\,", "," );
814*/ 814*/
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("\\\\N") , "\r\n" );
817 str.replace( QRegExp("\\;") , ";" ); 817 str.replace( QRegExp("\\\\;") , ";" );
818 str.replace( QRegExp("\\:") , ":" ); 818 str.replace( QRegExp("\\\\:") , ":" );
819 str.replace( QRegExp("\\,") , "," ); 819 str.replace( QRegExp("\\\\,") , "," );
820 820
821 Addressee::List list = parseVCards( str ); 821 Addressee::List list = parseVCards( str );
822 if ( list.count() > 0 ) { 822 if ( list.count() > 0 ) {
823 Addressee *addr = new Addressee; 823 Addressee *addr = new Addressee;
824 *addr = list[ 0 ]; 824 *addr = list[ 0 ];
825 agent.setAddressee( addr ); 825 agent.setAddressee( addr );
826 } 826 }
827 } 827 }
828 828
829 return agent; 829 return agent;
830} 830}
831 831
832VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent ) 832VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent )
833{ 833{
834 VCardLine line( "AGENT" ); 834 VCardLine line( "AGENT" );
835 835
836 if ( agent.isIntern() ) { 836 if ( agent.isIntern() ) {
837 if ( agent.addressee() != 0 ) { 837 if ( agent.addressee() != 0 ) {
838 Addressee::List list; 838 Addressee::List list;
839 list.append( *agent.addressee() ); 839 list.append( *agent.addressee() );
840 840
841 QString str = createVCards( list, version ); 841 QString str = createVCards( list, version );
842 842
843//US using the old implementation instead 843//US using the old implementation instead
844 qDebug("VCardTool::createAgent has to be verified"); 844 qDebug("VCardTool::createAgent has to be verified");
845/*US 845/*US
846 str.replace( "\r\n", "\\n" ); 846 str.replace( "\r\n", "\\n" );
847 str.replace( ";", "\\;" ); 847 str.replace( ";", "\\;" );
848 str.replace( ":", "\\:" ); 848 str.replace( ":", "\\:" );
849 str.replace( ",", "\\," ); 849 str.replace( ",", "\\," );
850*/ 850*/
851 str.replace( QRegExp("\r\n"), "\\n" ); 851 str.replace( QRegExp("\r\n"), "\\n" );
852 str.replace( QRegExp(";"), "\\;" ); 852 str.replace( QRegExp(";"), "\\;" );
853 str.replace( QRegExp(":"), "\\:" ); 853 str.replace( QRegExp(":"), "\\:" );
854 str.replace( QRegExp(","), "\\," ); 854 str.replace( QRegExp(","), "\\," );
855 line.setValue( str ); 855 line.setValue( str );
856 } 856 }
857 } else if ( !agent.url().isEmpty() ) { 857 } else if ( !agent.url().isEmpty() ) {
858 line.setValue( agent.url() ); 858 line.setValue( agent.url() );
859 line.addParameter( "value", "URI" ); 859 line.addParameter( "value", "URI" );
860 } 860 }
861 861
862 return line; 862 return line;
863} 863}
864 864
865QStringList VCardTool::splitString( const QChar &sep, const QString &str ) 865QStringList VCardTool::splitString( const QChar &sep, const QString &str )
866{ 866{
867 QStringList list; 867 QStringList list;
868 QString value( str ); 868 QString value( str );
869 869
870 int start = 0; 870 int start = 0;
871 int pos = value.find( sep, start ); 871 int pos = value.find( sep, start );
872 872
873 while ( pos != -1 ) { 873 while ( pos != -1 ) {
874 if ( value[ pos - 1 ] != '\\' ) { 874 if ( value[ pos - 1 ] != '\\' ) {
875 if ( pos > start && pos <= (int)value.length() ) 875 if ( pos > start && pos <= (int)value.length() )
876 list << value.mid( start, pos - start ); 876 list << value.mid( start, pos - start );
877 else 877 else
878 list << QString::null; 878 list << QString::null;
879 879
880 start = pos + 1; 880 start = pos + 1;
881 pos = value.find( sep, start ); 881 pos = value.find( sep, start );
882 } else { 882 } else {
883 if ( pos != 0 ) { 883 if ( pos != 0 ) {
884 value.replace( pos - 1, 2, sep ); 884 value.replace( pos - 1, 2, sep );
885 pos = value.find( sep, pos ); 885 pos = value.find( sep, pos );
886 } else 886 } else
887 pos = value.find( sep, pos + 1 ); 887 pos = value.find( sep, pos + 1 );
888 } 888 }
889 } 889 }
890 890
891 int l = value.length() - 1; 891 int l = value.length() - 1;
892 if ( value.mid( start, l - start + 1 ).length() > 0 ) 892 if ( value.mid( start, l - start + 1 ).length() > 0 )
893 list << value.mid( start, l - start + 1 ); 893 list << value.mid( start, l - start + 1 );
894 else 894 else
895 list << QString::null; 895 list << QString::null;
896 896
897 return list; 897 return list;
898} 898}