kabc
vcardconverter.cpp
00001 /* 00002 This file is part of libkabc. 00003 Copyright (c) 2002 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 "vcardconverter.h" 00022 #include "vcardtool.h" 00023 00024 using namespace KABC; 00025 00026 VCardConverter::VCardConverter() 00027 : d( 0 ) 00028 { 00029 } 00030 00031 VCardConverter::~VCardConverter() 00032 { 00033 } 00034 00035 QByteArray VCardConverter::createVCard( const Addressee &addr, Version version ) const 00036 { 00037 Addressee::List list; 00038 list.append( addr ); 00039 00040 return createVCards( list, version ); 00041 } 00042 00043 QByteArray VCardConverter::createVCards( Addressee::List list, Version version ) const 00044 { 00045 VCardTool tool; 00046 00047 return tool.createVCards( list, ( version == v3_0 ? VCard::v3_0 : VCard::v2_1 ) ); 00048 } 00049 00050 Addressee VCardConverter::parseVCard( const QByteArray &vcard ) const 00051 { 00052 Addressee::List list = parseVCards( vcard ); 00053 00054 return list.isEmpty() ? Addressee() : list[ 0 ]; 00055 } 00056 00057 Addressee::List VCardConverter::parseVCards( const QByteArray &vcard ) const 00058 { 00059 VCardTool tool; 00060 00061 return tool.parseVCards( vcard ); 00062 } 00063 00064 /* Helper functions */ 00065 00066 QString KABC::dateToVCardString( const QDateTime &dateTime ) 00067 { 00068 return dateTime.toString( QLatin1String( "yyyyMMddThhmmssZ" ) ); 00069 } 00070 00071 QString KABC::dateToVCardString( const QDate &date ) 00072 { 00073 return date.toString( QLatin1String( "yyyyMMdd" ) ); 00074 } 00075 00076 QDateTime KABC::VCardStringToDate( const QString &dateString ) 00077 { 00078 QDate date; 00079 QTime time; 00080 QString d( dateString ); 00081 00082 d = d.remove( QLatin1Char( '-' ) ).remove( QLatin1Char( ':' ) ); 00083 00084 if ( d.length() >= 8 ) { 00085 date = QDate( d.mid( 0, 4 ).toUInt(), d.mid( 4, 2 ).toUInt(), d.mid( 6, 2 ).toUInt() ); 00086 } 00087 00088 if ( d.length() > 9 && d[ 8 ].toUpper() == QLatin1Char( 'T' ) ) { 00089 time = QTime( d.mid( 9, 2 ).toUInt(), d.mid( 11, 2 ).toUInt(), d.mid( 13, 2 ).toUInt() ); 00090 } 00091 00092 return QDateTime( date, time ); 00093 }