summaryrefslogtreecommitdiffabout
path: root/kabc/vcardparser/vcardline.cpp
Unidiff
Diffstat (limited to 'kabc/vcardparser/vcardline.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardparser/vcardline.cpp148
1 files changed, 148 insertions, 0 deletions
diff --git a/kabc/vcardparser/vcardline.cpp b/kabc/vcardparser/vcardline.cpp
new file mode 100644
index 0000000..84638f8
--- a/dev/null
+++ b/kabc/vcardparser/vcardline.cpp
@@ -0,0 +1,148 @@
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 "vcardline.h"
22
23using namespace KABC;
24
25VCardLine::VCardLine()
26 : mParamMap( 0 )
27{
28}
29
30VCardLine::VCardLine( const QString &identifier )
31 : mParamMap( 0 )
32{
33 mIdentifier = identifier;
34}
35
36VCardLine::VCardLine( const QString &identifier, const QVariant &value )
37 : mParamMap( 0 )
38{
39 mIdentifier = identifier;
40 mValue = value;
41}
42
43VCardLine::VCardLine( const VCardLine& line )
44 : mParamMap( 0 )
45{
46 if ( line.mParamMap ) {
47 if ( !mParamMap )
48 mParamMap = new QMap<QString, QStringList>;
49
50 *mParamMap = *(line.mParamMap);
51 } else {
52 delete mParamMap;
53 mParamMap = 0;
54 }
55
56 mValue = line.mValue;
57 mIdentifier = line.mIdentifier;
58}
59
60VCardLine::~VCardLine()
61{
62 delete mParamMap;
63 mParamMap = 0;
64}
65
66VCardLine& VCardLine::operator=( const VCardLine& line )
67{
68 if ( &line == this )
69 return *this;
70
71 if ( line.mParamMap ) {
72 if ( !mParamMap )
73 mParamMap = new QMap<QString, QStringList>;
74
75 *mParamMap = *(line.mParamMap);
76 } else {
77 delete mParamMap;
78 mParamMap = 0;
79 }
80
81 mValue = line.mValue;
82 mIdentifier = line.mIdentifier;
83
84 return *this;
85}
86
87void VCardLine::setIdentifier( const QString& identifier )
88{
89 mIdentifier = identifier;
90}
91
92QString VCardLine::identifier() const
93{
94 return mIdentifier;
95}
96void VCardLine::setValue( const QVariant& value )
97{
98 mValue = value;
99}
100
101QVariant VCardLine::value() const
102{
103 return mValue;
104}
105
106QStringList VCardLine::parameterList() const
107{
108 if ( !mParamMap )
109 return QStringList();
110 else {
111//US method QMap::keys() not available yet. SO collect the data manually
112//US return mParamMap->keys();
113
114 QStringList result;
115
116 QMap<QString, QStringList>::ConstIterator it;
117 for( it = mParamMap->begin(); it != mParamMap->end(); ++it ) {
118 result << it.key().latin1();
119 }
120 return result;
121 }
122}
123
124void VCardLine::addParameter( const QString& param, const QString& value )
125{
126 if ( !mParamMap )
127 mParamMap = new QMap<QString, QStringList>;
128
129 QStringList &list = (*mParamMap)[ param ];
130 if ( list.find( value ) == list.end() ) // not included yet
131 list.append( value );
132}
133
134QStringList VCardLine::parameters( const QString& param ) const
135{
136 if ( !mParamMap )
137 return QStringList();
138 else
139 return (*mParamMap)[ param ];
140}
141
142QString VCardLine::parameter( const QString& param ) const
143{
144 if ( !mParamMap )
145 return QString::null;
146 else
147 return (*mParamMap)[ param ][ 0 ];
148}