summaryrefslogtreecommitdiffabout
path: root/kabc/vcardparser
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/vcardparser
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip
kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz
kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2
initial public commit of qt4 portp1
Diffstat (limited to 'kabc/vcardparser') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardparser/vcard.h4
-rw-r--r--kabc/vcardparser/vcardline.cpp6
-rw-r--r--kabc/vcardparser/vcardline.h8
-rw-r--r--kabc/vcardparser/vcardparser.cpp2
-rw-r--r--kabc/vcardparser/vcardtool.cpp2
5 files changed, 12 insertions, 10 deletions
diff --git a/kabc/vcardparser/vcard.h b/kabc/vcardparser/vcard.h
index 0bee441..85b50e4 100644
--- a/kabc/vcardparser/vcard.h
+++ b/kabc/vcardparser/vcard.h
@@ -3,56 +3,56 @@
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#ifndef VCARDPARSER_VCARD_H 21#ifndef VCARDPARSER_VCARD_H
22#define VCARDPARSER_VCARD_H 22#define VCARDPARSER_VCARD_H
23 23
24#include "vcardline.h" 24#include "vcardline.h"
25#include <qmap.h> 25#include <qmap.h>
26#include <qstringlist.h> 26#include <qstringlist.h>
27#include <qvaluelist.h> 27#include <q3valuelist.h>
28 28
29namespace KABC { 29namespace KABC {
30 30
31class VCard 31class VCard
32{ 32{
33 public: 33 public:
34 typedef QValueList<VCard> List; 34 typedef Q3ValueList<VCard> List;
35 typedef QMap< QString, VCardLine::List > LineMap; 35 typedef QMap< QString, VCardLine::List > LineMap;
36 36
37 enum Version { v2_1, v3_0 }; 37 enum Version { v2_1, v3_0 };
38 38
39 VCard(); 39 VCard();
40 VCard( const VCard& ); 40 VCard( const VCard& );
41 41
42 ~VCard(); 42 ~VCard();
43 43
44 VCard& operator=( const VCard& ); 44 VCard& operator=( const VCard& );
45 45
46 /** 46 /**
47 * Removes all lines from the vCard. 47 * Removes all lines from the vCard.
48 */ 48 */
49 void clear(); 49 void clear();
50 50
51 /** 51 /**
52 * Returns a list of all identifiers that exists in the 52 * Returns a list of all identifiers that exists in the
53 * vCard. 53 * vCard.
54 */ 54 */
55 QStringList identifiers() const; 55 QStringList identifiers() const;
56 56
57 /** 57 /**
58 * Adds a VCardLine to the VCard 58 * Adds a VCardLine to the VCard
diff --git a/kabc/vcardparser/vcardline.cpp b/kabc/vcardparser/vcardline.cpp
index 8df2d32..c7254a0 100644
--- a/kabc/vcardparser/vcardline.cpp
+++ b/kabc/vcardparser/vcardline.cpp
@@ -1,113 +1,115 @@
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 "vcardline.h" 21#include "vcardline.h"
22//Added by qt3to4:
23#include <Q3CString>
22 24
23using namespace KABC; 25using namespace KABC;
24 26
25class VCardLine::VCardLinePrivate 27class VCardLine::VCardLinePrivate
26{ 28{
27 public: 29 public:
28 QString mGroup; 30 QString mGroup;
29}; 31};
30 32
31VCardLine::VCardLine() 33VCardLine::VCardLine()
32 : d( 0 ) 34 : d( 0 )
33{ 35{
34} 36}
35 37
36VCardLine::VCardLine( const QString &identifier ) 38VCardLine::VCardLine( const QString &identifier )
37 : d( 0 ) 39 : d( 0 )
38{ 40{
39 mIdentifier = identifier; 41 mIdentifier = identifier;
40} 42}
41 43
42VCardLine::VCardLine( const QString &identifier, const QString &value ) 44VCardLine::VCardLine( const QString &identifier, const QString &value )
43 : d( 0 ) 45 : d( 0 )
44{ 46{
45 mIdentifier = identifier; 47 mIdentifier = identifier;
46 mValue.assign( value.data(), value.length() ); 48 mValue = value;
47} 49}
48 50
49VCardLine::VCardLine( const VCardLine& line ) 51VCardLine::VCardLine( const VCardLine& line )
50 : d( 0 ) 52 : d( 0 )
51{ 53{
52 mParamMap = line.mParamMap; 54 mParamMap = line.mParamMap;
53 mValue = line.mValue; 55 mValue = line.mValue;
54 mIdentifier = line.mIdentifier; 56 mIdentifier = line.mIdentifier;
55} 57}
56 58
57VCardLine::~VCardLine() 59VCardLine::~VCardLine()
58{ 60{
59 delete d; 61 delete d;
60 d = 0; 62 d = 0;
61} 63}
62 64
63VCardLine& VCardLine::operator=( const VCardLine& line ) 65VCardLine& VCardLine::operator=( const VCardLine& line )
64{ 66{
65 if ( &line == this ) 67 if ( &line == this )
66 return *this; 68 return *this;
67 69
68 mParamMap = line.mParamMap; 70 mParamMap = line.mParamMap;
69 mValue = line.mValue; 71 mValue = line.mValue;
70 mIdentifier = line.mIdentifier; 72 mIdentifier = line.mIdentifier;
71 73
72 return *this; 74 return *this;
73} 75}
74 76
75void VCardLine::setIdentifier( const QString& identifier ) 77void VCardLine::setIdentifier( const QString& identifier )
76{ 78{
77 mIdentifier = identifier; 79 mIdentifier = identifier;
78} 80}
79 81
80QString VCardLine::identifier() const 82QString VCardLine::identifier() const
81{ 83{
82 return mIdentifier; 84 return mIdentifier;
83} 85}
84 86
85void VCardLine::setValueString( const QString& value ) 87void VCardLine::setValueString( const QString& value )
86{ 88{
87 setValueCString( value.utf8() ); 89 setValueCString( value.utf8() );
88} 90}
89void VCardLine::setValueCString( const QCString& value ) 91void VCardLine::setValueCString( const Q3CString& value )
90{ 92{
91 mValue.duplicate( value.data(), value.length() ); 93 mValue.duplicate( value.data(), value.length() );
92} 94}
93 95
94void VCardLine::setValueBytes( const QByteArray& value ) 96void VCardLine::setValueBytes( const QByteArray& value )
95{ 97{
96 mValue = value; 98 mValue = value;
97} 99}
98 100
99QString VCardLine::valueString() const 101QString VCardLine::valueString() const
100{ 102{
101 return QString::fromUtf8( mValue.data(), mValue.size() ); 103 return QString::fromUtf8( mValue.data(), mValue.size() );
102} 104}
103 105
104QByteArray VCardLine::valueBytes() const 106QByteArray VCardLine::valueBytes() const
105{ 107{
106 return mValue; 108 return mValue;
107} 109}
108 110
109void VCardLine::setGroup( const QString& group ) 111void VCardLine::setGroup( const QString& group )
110{ 112{
111 if ( !d ) 113 if ( !d )
112 d = new VCardLinePrivate(); 114 d = new VCardLinePrivate();
113 115
diff --git a/kabc/vcardparser/vcardline.h b/kabc/vcardparser/vcardline.h
index 8dc9322..dc4bdec 100644
--- a/kabc/vcardparser/vcardline.h
+++ b/kabc/vcardparser/vcardline.h
@@ -1,86 +1,86 @@
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#ifndef VCARDLINE_H 21#ifndef VCARDLINE_H
22#define VCARDLINE_H 22#define VCARDLINE_H
23 23
24#include <qstringlist.h> 24#include <qstringlist.h>
25#include <qvaluelist.h> 25#include <q3valuelist.h>
26#include <qcstring.h> 26#include <q3cstring.h>
27#include <qvariant.h> 27#include <qvariant.h>
28#include <qmap.h> 28#include <qmap.h>
29#include <qstring.h> 29#include <qstring.h>
30 30
31namespace KABC { 31namespace KABC {
32 32
33class VCardLine 33class VCardLine
34{ 34{
35 public: 35 public:
36 typedef QValueList<VCardLine> List; 36 typedef Q3ValueList<VCardLine> List;
37 typedef QMap<QString, QStringList> ParamMap; 37 typedef QMap<QString, QStringList> ParamMap;
38 38
39 VCardLine(); 39 VCardLine();
40 VCardLine( const QString &identifier ); 40 VCardLine( const QString &identifier );
41 VCardLine( const QString &identifier, const QString &value ); 41 VCardLine( const QString &identifier, const QString &value );
42 VCardLine( const VCardLine& ); 42 VCardLine( const VCardLine& );
43 43
44 ~VCardLine(); 44 ~VCardLine();
45 45
46 VCardLine& operator=( const VCardLine& ); 46 VCardLine& operator=( const VCardLine& );
47 47
48 /** 48 /**
49 * Sets the identifier of this line e.g. UID, FN, CLASS 49 * Sets the identifier of this line e.g. UID, FN, CLASS
50 */ 50 */
51 void setIdentifier( const QString& identifier ); 51 void setIdentifier( const QString& identifier );
52 52
53 /** 53 /**
54 * Returns the identifier of this line. 54 * Returns the identifier of this line.
55 */ 55 */
56 QString identifier() const; 56 QString identifier() const;
57 57
58 /** 58 /**
59 * Sets the value of of this line. 59 * Sets the value of of this line.
60 */ 60 */
61 void setValueString( const QString& value ); 61 void setValueString( const QString& value );
62 void setValueCString( const QCString& value ); 62 void setValueCString( const Q3CString& value );
63 void setValueBytes( const QByteArray& value ); 63 void setValueBytes( const QByteArray& value );
64 64
65 /** 65 /**
66 * Returns the value of this line. 66 * Returns the value of this line.
67 */ 67 */
68 QString valueString() const; 68 QString valueString() const;
69 QByteArray valueBytes() const; 69 QByteArray valueBytes() const;
70 70
71 /** 71 /**
72 * Sets the group the line belongs to. 72 * Sets the group the line belongs to.
73 */ 73 */
74 void setGroup( const QString& group ); 74 void setGroup( const QString& group );
75 75
76 /** 76 /**
77 * Returns the group the line belongs to. 77 * Returns the group the line belongs to.
78 */ 78 */
79 QString group() const; 79 QString group() const;
80 80
81 /** 81 /**
82 * Returns whether the line belongs to a group. 82 * Returns whether the line belongs to a group.
83 */ 83 */
84 bool hasGroup() const; 84 bool hasGroup() const;
85 85
86 /** 86 /**
diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp
index 11622a0..a319531 100644
--- a/kabc/vcardparser/vcardparser.cpp
+++ b/kabc/vcardparser/vcardparser.cpp
@@ -197,44 +197,44 @@ QString VCardParser::createVCards( const VCard::List& list )
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, true );
222 textLine.append( ":" + QString( output ) ); 222 textLine.append( ":" + QString( output ) );
223 } else 223 } else
224 textLine.append( ":" + (*lineIt).valueString().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}
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp
index 204326e..435c3b0 100644
--- a/kabc/vcardparser/vcardtool.cpp
+++ b/kabc/vcardparser/vcardtool.cpp
@@ -631,49 +631,49 @@ Picture VCardTool::parsePicture( const VCardLine &line )
631 631
632 const QStringList params = line.parameterList(); 632 const QStringList params = line.parameterList();
633 if ( params.findIndex( "encoding" ) != -1 ) { 633 if ( params.findIndex( "encoding" ) != -1 ) {
634 QImage img; 634 QImage img;
635 img.loadFromData( line.valueBytes() ); 635 img.loadFromData( line.valueBytes() );
636 pic.setData( img ); 636 pic.setData( img );
637 } else if ( params.findIndex( "value" ) != -1 ) { 637 } else if ( params.findIndex( "value" ) != -1 ) {
638 if ( line.parameter( "value" ).lower() == "uri" ) 638 if ( line.parameter( "value" ).lower() == "uri" )
639 pic.setUrl( line.valueString() ); 639 pic.setUrl( line.valueString() );
640 } 640 }
641 641
642 if ( params.findIndex( "type" ) != -1 ) 642 if ( params.findIndex( "type" ) != -1 )
643 pic.setType( line.parameter( "type" ) ); 643 pic.setType( line.parameter( "type" ) );
644 644
645 return pic; 645 return pic;
646} 646}
647 647
648VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) 648VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
649{ 649{
650 VCardLine line( identifier ); 650 VCardLine line( identifier );
651 651
652 if ( pic.isIntern() ) { 652 if ( pic.isIntern() ) {
653 if ( !pic.data().isNull() ) { 653 if ( !pic.data().isNull() ) {
654 QByteArray input; 654 QByteArray input;
655 QDataStream s( input, IO_WriteOnly ); 655 QDataStream s( &input, QIODevice::WriteOnly );
656 s.setVersion( 4 ); 656 s.setVersion( 4 );
657 s << pic.data(); 657 s << pic.data();
658 line.setValueBytes( input ); 658 line.setValueBytes( input );
659 line.addParameter( "encoding", "b" ); 659 line.addParameter( "encoding", "b" );
660 line.addParameter( "type", "image/png" ); 660 line.addParameter( "type", "image/png" );
661 } 661 }
662 } else if ( !pic.url().isEmpty() ) { 662 } else if ( !pic.url().isEmpty() ) {
663 QByteArray ba; 663 QByteArray ba;
664 line.setValueString( pic.url() ); 664 line.setValueString( pic.url() );
665 line.addParameter( "value", "URI" ); 665 line.addParameter( "value", "URI" );
666 } 666 }
667 667
668 return line; 668 return line;
669} 669}
670 670
671Sound VCardTool::parseSound( const VCardLine &line ) 671Sound VCardTool::parseSound( const VCardLine &line )
672{ 672{
673 Sound snd; 673 Sound snd;
674 674
675 const QStringList params = line.parameterList(); 675 const QStringList params = line.parameterList();
676 if ( params.findIndex( "encoding" ) != -1 ) 676 if ( params.findIndex( "encoding" ) != -1 )
677 snd.setData( line.valueBytes() ); 677 snd.setData( line.valueBytes() );
678 else if ( params.findIndex( "value" ) != -1 ) { 678 else if ( params.findIndex( "value" ) != -1 ) {
679 if ( line.parameter( "value" ).lower() == "uri" ) 679 if ( line.parameter( "value" ).lower() == "uri" )