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
@@ -1,91 +1,91 @@
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 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
59 */ 59 */
60 void addLine( const VCardLine& line ); 60 void addLine( const VCardLine& line );
61 61
62 /** 62 /**
63 * Returns all lines of the vcard with a special identifier. 63 * Returns all lines of the vcard with a special identifier.
64 */ 64 */
65 VCardLine::List lines( const QString& identifier ) const; 65 VCardLine::List lines( const QString& identifier ) const;
66 66
67 /** 67 /**
68 * Returns only the first line of the vcard with a special identifier. 68 * Returns only the first line of the vcard with a special identifier.
69 */ 69 */
70 VCardLine line( const QString& identifier ) const; 70 VCardLine line( const QString& identifier ) const;
71 71
72 /** 72 /**
73 * Set the version of the vCard. 73 * Set the version of the vCard.
74 */ 74 */
75 void setVersion( Version version ); 75 void setVersion( Version version );
76 76
77 /** 77 /**
78 * Returns the version of this vCard. 78 * Returns the version of this vCard.
79 */ 79 */
80 Version version() const; 80 Version version() const;
81 81
82 private: 82 private:
83 LineMap mLineMap; 83 LineMap mLineMap;
84 84
85 class VCardPrivate; 85 class VCardPrivate;
86 VCardPrivate *d; 86 VCardPrivate *d;
87}; 87};
88 88
89} 89}
90 90
91#endif 91#endif
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,175 +1,177 @@
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
114 d->mGroup = group; 116 d->mGroup = group;
115} 117}
116 118
117QString VCardLine::group() const 119QString VCardLine::group() const
118{ 120{
119 if ( d ) 121 if ( d )
120 return d->mGroup; 122 return d->mGroup;
121 else 123 else
122 return QString(); 124 return QString();
123} 125}
124 126
125bool VCardLine::hasGroup() const 127bool VCardLine::hasGroup() const
126{ 128{
127 if ( !d ) 129 if ( !d )
128 return false; 130 return false;
129 else 131 else
130 return d->mGroup.isEmpty(); 132 return d->mGroup.isEmpty();
131} 133}
132 134
133QStringList VCardLine::parameterList() const 135QStringList VCardLine::parameterList() const
134{ 136{
135 //return mParamMap.keys(); 137 //return mParamMap.keys();
136//US method QMap::keys() not available yet. SO collect the data manually 138//US method QMap::keys() not available yet. SO collect the data manually
137//US return mParamMap->keys(); 139//US return mParamMap->keys();
138 140
139 QStringList result; 141 QStringList result;
140 142
141 QMap<QString, QStringList>::ConstIterator it; 143 QMap<QString, QStringList>::ConstIterator it;
142 for( it = mParamMap.begin(); it != mParamMap.end(); ++it ) { 144 for( it = mParamMap.begin(); it != mParamMap.end(); ++it ) {
143 result << it.key().latin1(); 145 result << it.key().latin1();
144 } 146 }
145 return result; 147 return result;
146} 148}
147 149
148void VCardLine::addParameter( const QString& param, const QString& value ) 150void VCardLine::addParameter( const QString& param, const QString& value )
149{ 151{
150 QStringList &list = mParamMap[ param ]; 152 QStringList &list = mParamMap[ param ];
151 if ( list.findIndex( value ) == -1 ) // not included yet 153 if ( list.findIndex( value ) == -1 ) // not included yet
152 list.append( value ); 154 list.append( value );
153} 155}
154 156
155QStringList VCardLine::parameters( const QString& param ) const 157QStringList VCardLine::parameters( const QString& param ) const
156{ 158{
157 ParamMap::ConstIterator it = mParamMap.find( param ); 159 ParamMap::ConstIterator it = mParamMap.find( param );
158 if ( it == mParamMap.end() ) 160 if ( it == mParamMap.end() )
159 return QStringList(); 161 return QStringList();
160 else 162 else
161 return *it; 163 return *it;
162} 164}
163 165
164QString VCardLine::parameter( const QString& param ) const 166QString VCardLine::parameter( const QString& param ) const
165{ 167{
166 ParamMap::ConstIterator it = mParamMap.find( param ); 168 ParamMap::ConstIterator it = mParamMap.find( param );
167 if ( it == mParamMap.end() ) 169 if ( it == mParamMap.end() )
168 return QString::null; 170 return QString::null;
169 else { 171 else {
170 if ( (*it).isEmpty() ) 172 if ( (*it).isEmpty() )
171 return QString::null; 173 return QString::null;
172 else 174 else
173 return (*it).first(); 175 return (*it).first();
174 } 176 }
175} 177}
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,119 +1,119 @@
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 /**
87 * Returns all parameters. 87 * Returns all parameters.
88 */ 88 */
89 QStringList parameterList() const; 89 QStringList parameterList() const;
90 90
91 /** 91 /**
92 * Add a new parameter to the line. 92 * Add a new parameter to the line.
93 */ 93 */
94 void addParameter( const QString& param, const QString& value ); 94 void addParameter( const QString& param, const QString& value );
95 95
96 /** 96 /**
97 * Returns the values of a special parameter. 97 * Returns the values of a special parameter.
98 * You can get a list of all parameters with paramList(). 98 * You can get a list of all parameters with paramList().
99 */ 99 */
100 QStringList parameters( const QString& param ) const; 100 QStringList parameters( const QString& param ) const;
101 101
102 /** 102 /**
103 * Returns only the first value of a special parameter. 103 * Returns only the first value of a special parameter.
104 * You can get a list of all parameters with paramList(). 104 * You can get a list of all parameters with paramList().
105 */ 105 */
106 QString parameter( const QString& param ) const; 106 QString parameter( const QString& param ) const;
107 107
108 private: 108 private:
109 ParamMap mParamMap; 109 ParamMap mParamMap;
110 QString mIdentifier; 110 QString mIdentifier;
111 QByteArray mValue; 111 QByteArray mValue;
112 112
113 class VCardLinePrivate; 113 class VCardLinePrivate;
114 VCardLinePrivate *d; 114 VCardLinePrivate *d;
115}; 115};
116 116
117} 117}
118 118
119#endif 119#endif
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
@@ -125,116 +125,116 @@ VCard::List VCardParser::parseVCards( const QString& text )
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.setValueBytes( 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.setValueString( 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
159 return vCardList; 159 return vCardList;
160} 160}
161 161
162QString VCardParser::createVCards( const VCard::List& list ) 162QString VCardParser::createVCards( const VCard::List& list )
163{ 163{
164 QString text; 164 QString text;
165 QString textLine; 165 QString textLine;
166 QString encodingType; 166 QString encodingType;
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).valueString().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, 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
@@ -559,193 +559,193 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
559 tz.setOffset( offset ); 559 tz.setOffset( offset );
560 addr.setTimeZone( tz ); 560 addr.setTimeZone( tz );
561 } 561 }
562 562
563 // UID 563 // UID
564 else if ( identifier == "uid" ) 564 else if ( identifier == "uid" )
565 addr.setUid( (*lineIt).valueString() ); 565 addr.setUid( (*lineIt).valueString() );
566 566
567 // URL 567 // URL
568 else if ( identifier == "url" ) 568 else if ( identifier == "url" )
569 addr.setUrl( KURL( (*lineIt).valueString() ) ); 569 addr.setUrl( KURL( (*lineIt).valueString() ) );
570 570
571 // X- 571 // X-
572 else if ( identifier.startsWith( "x-" ) ) { 572 else if ( identifier.startsWith( "x-" ) ) {
573 const QString key = (*lineIt).identifier().mid( 2 ); 573 const QString key = (*lineIt).identifier().mid( 2 );
574 int dash = key.find( "-" ); 574 int dash = key.find( "-" );
575 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).valueString() ); 575 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).valueString() );
576 } 576 }
577 } 577 }
578 } 578 }
579 addr.makePhoneNumbersOLcompatible(); 579 addr.makePhoneNumbersOLcompatible();
580 addrList.append( addr ); 580 addrList.append( addr );
581 } 581 }
582 582
583 return addrList; 583 return addrList;
584} 584}
585 585
586QDateTime VCardTool::parseDateTime( const QString &str ) 586QDateTime VCardTool::parseDateTime( const QString &str )
587{ 587{
588 QDateTime dateTime; 588 QDateTime dateTime;
589 589
590 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd) 590 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd)
591 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(), 591 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
592 str.mid( 6, 2 ).toInt() ) ); 592 str.mid( 6, 2 ).toInt() ) );
593 593
594 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss 594 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss
595 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), 595 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
596 str.mid( 17, 2 ).toInt() ) ); 596 str.mid( 17, 2 ).toInt() ) );
597 597
598 } else { // is extended format yyyy-mm-dd 598 } else { // is extended format yyyy-mm-dd
599 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(), 599 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
600 str.mid( 8, 2 ).toInt() ) ); 600 str.mid( 8, 2 ).toInt() ) );
601 601
602 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss 602 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss
603 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), 603 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
604 str.mid( 17, 2 ).toInt() ) ); 604 str.mid( 17, 2 ).toInt() ) );
605 } 605 }
606 606
607 return dateTime; 607 return dateTime;
608} 608}
609 609
610QString VCardTool::createDateTime( const QDateTime &dateTime ) 610QString VCardTool::createDateTime( const QDateTime &dateTime )
611{ 611{
612 QString str; 612 QString str;
613 613
614 if ( dateTime.date().isValid() ) { 614 if ( dateTime.date().isValid() ) {
615 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(), 615 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
616 dateTime.date().day() ); 616 dateTime.date().day() );
617 if ( dateTime.time().isValid() ) { 617 if ( dateTime.time().isValid() ) {
618 QString tmp; 618 QString tmp;
619 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(), 619 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
620 dateTime.time().second() ); 620 dateTime.time().second() );
621 str += tmp; 621 str += tmp;
622 } 622 }
623 } 623 }
624 624
625 return str; 625 return str;
626} 626}
627 627
628Picture VCardTool::parsePicture( const VCardLine &line ) 628Picture VCardTool::parsePicture( const VCardLine &line )
629{ 629{
630 Picture pic; 630 Picture pic;
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" )
680 snd.setUrl( line.valueString() ); 680 snd.setUrl( line.valueString() );
681 } 681 }
682 682
683/* TODO: support sound types 683/* TODO: support sound types
684 if ( params.contains( "type" ) ) 684 if ( params.contains( "type" ) )
685 snd.setType( line.parameter( "type" ) ); 685 snd.setType( line.parameter( "type" ) );
686*/ 686*/
687 687
688 return snd; 688 return snd;
689} 689}
690 690
691VCardLine VCardTool::createSound( const Sound &snd ) 691VCardLine VCardTool::createSound( const Sound &snd )
692{ 692{
693 VCardLine line( "SOUND" ); 693 VCardLine line( "SOUND" );
694 694
695 if ( snd.isIntern() ) { 695 if ( snd.isIntern() ) {
696 if ( !snd.data().isEmpty() ) { 696 if ( !snd.data().isEmpty() ) {
697 line.setValueBytes( snd.data() ); 697 line.setValueBytes( snd.data() );
698 line.addParameter( "encoding", "b" ); 698 line.addParameter( "encoding", "b" );
699 // TODO: need to store sound type!!! 699 // TODO: need to store sound type!!!
700 } 700 }
701 } else if ( !snd.url().isEmpty() ) { 701 } else if ( !snd.url().isEmpty() ) {
702 line.setValueString( snd.url() ); 702 line.setValueString( snd.url() );
703 line.addParameter( "value", "URI" ); 703 line.addParameter( "value", "URI" );
704 } 704 }
705 705
706 return line; 706 return line;
707} 707}
708 708
709Key VCardTool::parseKey( const VCardLine &line ) 709Key VCardTool::parseKey( const VCardLine &line )
710{ 710{
711 Key key; 711 Key key;
712 712
713 const QStringList params = line.parameterList(); 713 const QStringList params = line.parameterList();
714 if ( params.findIndex( "encoding" ) != -1 ) 714 if ( params.findIndex( "encoding" ) != -1 )
715 key.setBinaryData( line.valueBytes() ); 715 key.setBinaryData( line.valueBytes() );
716 else 716 else
717 key.setTextData( line.valueString() ); 717 key.setTextData( line.valueString() );
718 718
719 if ( params.findIndex( "type" ) != -1 ) { 719 if ( params.findIndex( "type" ) != -1 ) {
720 if ( line.parameter( "type" ).lower() == "x509" ) 720 if ( line.parameter( "type" ).lower() == "x509" )
721 key.setType( Key::X509 ); 721 key.setType( Key::X509 );
722 else if ( line.parameter( "type" ).lower() == "pgp" ) 722 else if ( line.parameter( "type" ).lower() == "pgp" )
723 key.setType( Key::PGP ); 723 key.setType( Key::PGP );
724 else { 724 else {
725 key.setType( Key::Custom ); 725 key.setType( Key::Custom );
726 key.setCustomTypeString( line.parameter( "type" ) ); 726 key.setCustomTypeString( line.parameter( "type" ) );
727 } 727 }
728 } 728 }
729 729
730 return key; 730 return key;
731} 731}
732 732
733VCardLine VCardTool::createKey( const Key &key ) 733VCardLine VCardTool::createKey( const Key &key )
734{ 734{
735 VCardLine line( "KEY" ); 735 VCardLine line( "KEY" );
736 736
737 if ( key.isBinary() ) { 737 if ( key.isBinary() ) {
738 if ( !key.binaryData().isEmpty() ) { 738 if ( !key.binaryData().isEmpty() ) {
739 line.setValueBytes( key.binaryData() ); 739 line.setValueBytes( key.binaryData() );
740 line.addParameter( "encoding", "b" ); 740 line.addParameter( "encoding", "b" );
741 } 741 }
742 } else if ( !key.textData().isEmpty() ) 742 } else if ( !key.textData().isEmpty() )
743 line.setValueString( key.textData() ); 743 line.setValueString( key.textData() );
744 744
745 if ( key.type() == Key::X509 ) 745 if ( key.type() == Key::X509 )
746 line.addParameter( "type", "X509" ); 746 line.addParameter( "type", "X509" );
747 else if ( key.type() == Key::PGP ) 747 else if ( key.type() == Key::PGP )
748 line.addParameter( "type", "PGP" ); 748 line.addParameter( "type", "PGP" );
749 else if ( key.type() == Key::Custom ) 749 else if ( key.type() == Key::Custom )
750 line.addParameter( "type", key.customTypeString() ); 750 line.addParameter( "type", key.customTypeString() );
751 751