vcardline.cpp
00001 /* 00002 This file is part of libkabc. 00003 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "vcardline.h" 00022 00023 using namespace KABC; 00024 00025 class VCardLine::VCardLinePrivate 00026 { 00027 public: 00028 QString mGroup; 00029 }; 00030 00031 VCardLine::VCardLine() 00032 : d( 0 ) 00033 { 00034 } 00035 00036 VCardLine::VCardLine( const QString &identifier ) 00037 : d( 0 ) 00038 { 00039 mIdentifier = identifier; 00040 } 00041 00042 VCardLine::VCardLine( const QString &identifier, const QVariant &value ) 00043 : d( 0 ) 00044 { 00045 mIdentifier = identifier; 00046 mValue = value; 00047 } 00048 00049 VCardLine::VCardLine( const VCardLine& line ) 00050 : d( 0 ) 00051 { 00052 mParamMap = line.mParamMap; 00053 mValue = line.mValue; 00054 mIdentifier = line.mIdentifier; 00055 } 00056 00057 VCardLine::~VCardLine() 00058 { 00059 delete d; 00060 d = 0; 00061 } 00062 00063 VCardLine& VCardLine::operator=( const VCardLine& line ) 00064 { 00065 if ( &line == this ) 00066 return *this; 00067 00068 mParamMap = line.mParamMap; 00069 mValue = line.mValue; 00070 mIdentifier = line.mIdentifier; 00071 00072 return *this; 00073 } 00074 00075 void VCardLine::setIdentifier( const QString& identifier ) 00076 { 00077 mIdentifier = identifier; 00078 } 00079 00080 QString VCardLine::identifier() const 00081 { 00082 return mIdentifier; 00083 } 00084 00085 void VCardLine::setValue( const QVariant& value ) 00086 { 00087 mValue = value; 00088 } 00089 00090 QVariant VCardLine::value() const 00091 { 00092 return mValue; 00093 } 00094 00095 void VCardLine::setGroup( const QString& group ) 00096 { 00097 if ( !d ) 00098 d = new VCardLinePrivate(); 00099 00100 d->mGroup = group; 00101 } 00102 00103 QString VCardLine::group() const 00104 { 00105 if ( d ) 00106 return d->mGroup; 00107 else 00108 return QString(); 00109 } 00110 00111 bool VCardLine::hasGroup() const 00112 { 00113 if ( !d ) 00114 return false; 00115 else 00116 return d->mGroup.isEmpty(); 00117 } 00118 00119 QStringList VCardLine::parameterList() const 00120 { 00121 return mParamMap.keys(); 00122 } 00123 00124 void VCardLine::addParameter( const QString& param, const QString& value ) 00125 { 00126 QStringList &list = mParamMap[ param ]; 00127 if ( list.findIndex( value ) == -1 ) // not included yet 00128 list.append( value ); 00129 } 00130 00131 QStringList VCardLine::parameters( const QString& param ) const 00132 { 00133 ParamMap::ConstIterator it = mParamMap.find( param ); 00134 if ( it == mParamMap.end() ) 00135 return QStringList(); 00136 else 00137 return *it; 00138 } 00139 00140 QString VCardLine::parameter( const QString& param ) const 00141 { 00142 ParamMap::ConstIterator it = mParamMap.find( param ); 00143 if ( it == mParamMap.end() ) 00144 return QString::null; 00145 else { 00146 if ( (*it).isEmpty() ) 00147 return QString::null; 00148 else 00149 return (*it).first(); 00150 } 00151 }