kabc
vcard.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "vcard.h"
00022
00023 using namespace KABC;
00024
00025 VCard::VCard()
00026 {
00027 }
00028
00029 VCard::VCard( const VCard &vcard )
00030 {
00031 mLineMap = vcard.mLineMap;
00032 }
00033
00034 VCard::~VCard()
00035 {
00036 }
00037
00038 VCard &VCard::operator=( const VCard &vcard )
00039 {
00040 if ( &vcard == this ) {
00041 return *this;
00042 }
00043
00044 mLineMap = vcard.mLineMap;
00045
00046 return *this;
00047 }
00048
00049 void VCard::clear()
00050 {
00051 mLineMap.clear();
00052 }
00053
00054 QStringList VCard::identifiers() const
00055 {
00056 return mLineMap.keys();
00057 }
00058
00059 void VCard::addLine( const VCardLine &line )
00060 {
00061 mLineMap[ line.identifier() ].append( line );
00062 }
00063
00064 VCardLine::List VCard::lines( const QString &identifier ) const
00065 {
00066 LineMap::ConstIterator it = mLineMap.find( identifier );
00067 if ( it == mLineMap.end() ) {
00068 return VCardLine::List();
00069 }
00070
00071 return *it;
00072 }
00073
00074 VCardLine VCard::line( const QString &identifier ) const
00075 {
00076 LineMap::ConstIterator it = mLineMap.find( identifier );
00077 if ( it == mLineMap.end() ) {
00078 return VCardLine();
00079 }
00080
00081 if ( (*it).isEmpty() ) {
00082 return VCardLine();
00083 } else {
00084 return (*it).first();
00085 }
00086 }
00087
00088 void VCard::setVersion( Version version )
00089 {
00090 mLineMap.remove( QLatin1String( "VERSION" ) );
00091
00092 VCardLine line;
00093 line.setIdentifier( QLatin1String( "VERSION" ) );
00094 if ( version == v2_1 ) {
00095 line.setIdentifier( QLatin1String( "2.1" ) );
00096 } else if ( version == v3_0 ) {
00097 line.setIdentifier( QLatin1String( "3.0" ) );
00098 }
00099
00100 mLineMap[ QLatin1String( "VERSION" ) ].append( line );
00101 }
00102
00103 VCard::Version VCard::version() const
00104 {
00105 LineMap::ConstIterator versionEntry = mLineMap.find( QLatin1String( "VERSION" ) );
00106 if ( versionEntry == mLineMap.end() ) {
00107 return v3_0;
00108 }
00109
00110 VCardLine line = ( *versionEntry )[ 0 ];
00111 if ( line.value() == QLatin1String( "2.1" ) ) {
00112 return v2_1;
00113 } else {
00114 return v3_0;
00115 }
00116 }