kabc
vcardformat.cpp
00001 /* 00002 This file is part of libkabc. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@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 "vcardformat.h" 00022 #include "vcardconverter.h" 00023 #include "address.h" 00024 #include "addressee.h" 00025 00026 #include <QtCore/QFile> 00027 00028 using namespace KABC; 00029 00030 VCardFormat::VCardFormat() 00031 : d( 0 ) 00032 { 00033 } 00034 00035 VCardFormat::~VCardFormat() 00036 { 00037 //delete d; 00038 } 00039 00040 bool VCardFormat::load( Addressee &addressee, QFile *file ) 00041 { 00042 QByteArray data; 00043 00044 data = file->readAll(); 00045 00046 VCardConverter converter; 00047 Addressee::List l = converter.parseVCards( data ); 00048 00049 if ( ! l.first().isEmpty() ) { 00050 addressee = l.first(); 00051 return true; 00052 } 00053 00054 return false; 00055 } 00056 00057 bool VCardFormat::loadAll( AddressBook *, Resource *resource, QFile *file ) 00058 { 00059 QByteArray data; 00060 00061 data = file->readAll(); 00062 00063 VCardConverter converter; 00064 00065 Addressee::List l = converter.parseVCards( data ); 00066 00067 Addressee::List::iterator itr; 00068 for ( itr = l.begin(); itr != l.end(); ++itr ) { 00069 Addressee addressee = *itr; 00070 addressee.setResource( resource ); 00071 addressee.setChanged( false ); 00072 resource->insertAddressee( addressee ); 00073 } 00074 00075 return true; 00076 } 00077 00078 void VCardFormat::save( const Addressee &addressee, QFile *file ) 00079 { 00080 VCardConverter converter; 00081 Addressee::List vcardlist; 00082 00083 vcardlist.append( addressee ); 00084 00085 QByteArray data = converter.createVCards( vcardlist ); 00086 00087 file->write( data ); 00088 } 00089 00090 void VCardFormat::saveAll( AddressBook *, Resource *resource, QFile *file ) 00091 { 00092 VCardConverter converter; 00093 Addressee::List vcardlist; 00094 00095 Resource::Iterator it; 00096 for ( it = resource->begin(); it != resource->end(); ++it ) { 00097 (*it).setChanged( false ); 00098 vcardlist.append( *it ); 00099 } 00100 00101 QByteArray data = converter.createVCards( vcardlist ); 00102 00103 file->write( data ); 00104 } 00105 00106 bool VCardFormat::checkFormat( QFile *file ) const 00107 { 00108 QByteArray line = file->readLine(); 00109 line = line.trimmed(); 00110 if ( line == "BEGIN:VCARD" ) { 00111 return true; 00112 } else { 00113 return false; 00114 } 00115 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:56 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:56 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.