summaryrefslogtreecommitdiffabout
path: root/kabc/vcardparser/vcard.cpp
Unidiff
Diffstat (limited to 'kabc/vcardparser/vcard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardparser/vcard.cpp144
1 files changed, 144 insertions, 0 deletions
diff --git a/kabc/vcardparser/vcard.cpp b/kabc/vcardparser/vcard.cpp
new file mode 100644
index 0000000..da97ec2
--- a/dev/null
+++ b/kabc/vcardparser/vcard.cpp
@@ -0,0 +1,144 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include "vcard.h"
22
23using namespace KABC;
24
25VCard::VCard()
26 : mLineMap( 0 )
27{
28}
29
30VCard::VCard( const VCard& vcard )
31 : mLineMap( 0 )
32{
33 if ( vcard.mLineMap ) {
34 if ( !mLineMap )
35 mLineMap = new QMap<QString, QValueList<VCardLine> >;
36
37 *mLineMap = *(vcard.mLineMap);
38 } else {
39 delete mLineMap;
40 mLineMap = 0;
41 }
42}
43
44VCard::~VCard()
45{
46 delete mLineMap;
47 mLineMap = 0;
48}
49
50VCard& VCard::operator=( const VCard& vcard )
51{
52 if ( &vcard == this )
53 return *this;
54
55 if ( vcard.mLineMap ) {
56 if ( !mLineMap )
57 mLineMap = new QMap<QString, QValueList<VCardLine> >;
58
59 *mLineMap = *(vcard.mLineMap);
60 } else {
61 delete mLineMap;
62 mLineMap = 0;
63 }
64
65 return *this;
66}
67
68void VCard::clear()
69{
70 if ( mLineMap )
71 mLineMap->clear();
72}
73
74QStringList VCard::identifiers() const
75{
76 if ( !mLineMap )
77 return QStringList();
78 else {
79//US method QMap::keys() not available yet. SO collect the data manually
80//US return mLineMap->keys();
81
82 QStringList result;
83
84 QMap< QString, VCardLine::List >::ConstIterator it;
85 for( it = mLineMap->begin(); it != mLineMap->end(); ++it ) {
86 result << it.key().latin1();
87 }
88 return result;
89 }
90}
91
92void VCard::addLine( const VCardLine& line )
93{
94 if ( !mLineMap )
95 mLineMap = new QMap<QString, QValueList<VCardLine> >;
96
97 (*mLineMap)[ line.identifier() ].append( line );
98}
99
100VCardLine::List VCard::lines( const QString& identifier )
101{
102 if ( !mLineMap )
103 return VCardLine::List();
104 else
105 return (*mLineMap)[ identifier ];
106}
107
108VCardLine VCard::line( const QString& identifier )
109{
110 if ( !mLineMap )
111 return VCardLine();
112 else
113 return (*mLineMap)[ identifier ][ 0 ];
114}
115
116void VCard::setVersion( Version version )
117{
118 if ( !mLineMap )
119 mLineMap = new QMap<QString, QValueList<VCardLine> >;
120 else {
121//US mLineMap->erase( "VERSION" );
122 mLineMap->remove( "VERSION" );
123 }
124 VCardLine line;
125 line.setIdentifier( "VERSION" );
126 if ( version == v2_1 )
127 line.setIdentifier( "2.1" );
128 if ( version == v3_0 )
129 line.setIdentifier( "3.0" );
130
131 (*mLineMap)[ "VERSION" ].append( line );
132}
133
134VCard::Version VCard::version() const
135{
136 if ( !mLineMap )
137 return v3_0;
138
139 VCardLine line = (*mLineMap)[ "VERSION" ][ 0 ];
140 if ( line.value() == "2.1" )
141 return v2_1;
142 else
143 return v3_0;
144}