# kabc Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include "vcard21parser.h"
    00022 #include "vcardformatimpl.h"
    00023 #include "vcardtool.h"
    00024
    00025 #include "vcardconverter.h"
    00026
    00027 using namespace KABC;
    00028
    00029 struct VCardConverter::VCardConverterData
    00030 {
    00031   VCard21Parser vcard21parser;
    00032   VCardFormatImpl vcard30parser;
    00033 };
    00034
    00035 VCardConverter::VCardConverter()
    00036   : d( new VCardConverterData )
    00037 {
    00038 }
    00039
    00040 VCardConverter::~VCardConverter()
    00041 {
    00042   delete d;
    00043   d = 0;
    00044 }
    00045
    00046 QString VCardConverter::createVCard( const Addressee &addr, Version version )
    00047 {
    00048   Addressee::List list;
    00049   list.append( addr );
    00050
    00051   return createVCards( list, version );
    00052 }
    00053
    00054 QString VCardConverter::createVCards( Addressee::List list, Version version )
    00055 {
    00056   VCardTool tool;
    00057
    00058   return tool.createVCards( list, ( version == v3_0 ? VCard::v3_0 : VCard::v2_1 ) );
    00059 }
    00060
    00061 Addressee VCardConverter::parseVCard( const QString& vcard )
    00062 {
    00063   Addressee::List list = parseVCards( vcard );
    00064
    00065   return list[ 0 ];
    00066 }
    00067
    00068 Addressee::List VCardConverter::parseVCards( const QString& vcard )
    00069 {
    00070   VCardTool tool;
    00071
    00072   return tool.parseVCards( vcard );
    00073 }
    00074
    00075 // ---------------------------- deprecated stuff ---------------------------- //
    00076
    00077 bool VCardConverter::vCardToAddressee( const QString &str, Addressee &addr, Version version )
    00078 {
    00079   if ( version == v2_1 ) {
    00080     addr = d->vcard21parser.readFromString( str );
    00081     return true;
    00082   }
    00083
    00084   if ( version == v3_0 )
    00085     return d->vcard30parser.readFromString( str, addr );
    00086
    00087   return false;
    00088 }
    00089
    00090 bool VCardConverter::addresseeToVCard( const Addressee &addr, QString &str, Version version )
    00091 {
    00092   if ( version == v2_1 )
    00093     return false;
    00094
    00095   if ( version == v3_0 )
    00096     return d->vcard30parser.writeToString( addr, str );
    00097
    00098   return false;
    00099 }
    00100
    00101
    00102 /* Helper functions */
    00103
    00104 QString KABC::dateToVCardString( const QDateTime &dateTime )
    00105 {
    00106   return dateTime.toString("yyyyMMddThhmmssZ");
    00107 }
    00108
    00109 QString KABC::dateToVCardString( const QDate &date )
    00110 {
    00111   return date.toString("yyyyMMdd");
    00112 }
    00113
    00114 QDateTime KABC::VCardStringToDate( const QString &dateString )
    00115 {
    00116   QDate date;
    00117   QTime time;
    00118   QString d( dateString );
    00119
    00120   d = d.remove('-').remove(':');
    00121
    00122   if (d.length()>=8)
    00123     date = QDate( d.mid(0,4).toUInt(), d.mid(4,2).toUInt(), d.mid(6,2).toUInt() );
    00124   if (d.length()>9 && d[8].upper()=='T')
    00125     time = QTime( d.mid(9,2).toUInt(), d.mid(11,2).toUInt(), d.mid(13,2).toUInt() );
    00126
    00127   return QDateTime( date, time );
    00128 }
    00129

This file is part of the documentation for kabc Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:32 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003