# kabc Library API Documentation

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

# arser/testread.cpp

    00001 /*
    00002     This file is part of libkabc.
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public License
    00015     along with this library; see the file COPYING.LIB.  If not, write to
    00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017     Boston, MA 02111-1307, USA.
    00018 */
    00019
    00020 #include <iostream>
    00021 #include <stdlib.h>
    00022
    00023 #include <qfile.h>
    00024 #include <qtextstream.h>
    00025
    00026 #include <kprocess.h>
    00027 #include <kdebug.h>
    00028 #include <kapplication.h>
    00029 #include <kcmdlineargs.h>
    00030 #include <klocale.h>
    00031 #include <kaboutdata.h>
    00032
    00033 #include "vcardconverter.h"
    00034 #include "vcard.h"
    00035
    00036 static const KCmdLineOptions options[] =
    00037 {
    00038   {"vcard21", I18N_NOOP("vCard 2.1"), 0},
    00039   {"+inputfile", I18N_NOOP("Input file"), 0},
    00040   KCmdLineLastOption
    00041 };
    00042
    00043 int main( int argc, char **argv )
    00044 {
    00045   KAboutData aboutData( "testread", "vCard test reader", "0.1" );
    00046   aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
    00047
    00048   KCmdLineArgs::init( argc, argv, &aboutData );
    00049   KCmdLineArgs::addCmdLineOptions( options );
    00050
    00051   KApplication app( false, false );
    00052
    00053   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    00054
    00055   if ( args->count() != 1 ) {
    00056     std::cerr << "Missing argument" << std::endl;
    00057     return 1;
    00058   }
    00059
    00060   QString inputFile( args->arg( 0 ) );
    00061
    00062   QFile file( inputFile );
    00063   if ( !file.open( IO_ReadOnly ) ) {
    00064     qDebug( "Unable to open file '%s' for reading!", file.name().latin1() );
    00065     return 1;
    00066   }
    00067
    00068   QString text;
    00069
    00070   QTextStream s( &file );
    00071   s.setEncoding( QTextStream::UnicodeUTF8 );
    00072   text = s.read();
    00073   file.close();
    00074
    00075   KABC::VCardConverter converter;
    00076   KABC::Addressee::List list = converter.parseVCards( text );
    00077
    00078   if ( args->isSet( "vcard21" ) ) {
    00079     text = converter.createVCards( list, KABC::VCardConverter::v2_1 ); // uses version 2.1
    00080   } else {
    00081     text = converter.createVCards( list ); // uses version 3.0
    00082   }
    00083
    00084   std::cout << text.utf8();
    00085
    00086   return 0;
    00087 }

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:31 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003