testread.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 KApplication::disableAutoDcopRegistration();
00046
00047 KAboutData aboutData( "testread", "vCard test reader", "0.1" );
00048 aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00049
00050 KCmdLineArgs::init( argc, argv, &aboutData );
00051 KCmdLineArgs::addCmdLineOptions( options );
00052
00053 KApplication app( false, false );
00054
00055 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00056
00057 if ( args->count() != 1 ) {
00058 std::cerr << "Missing argument" << std::endl;
00059 return 1;
00060 }
00061
00062 QString inputFile( args->arg( 0 ) );
00063
00064 QFile file( inputFile );
00065 if ( !file.open( IO_ReadOnly ) ) {
00066 qDebug( "Unable to open file '%s' for reading!", file.name().latin1() );
00067 return 1;
00068 }
00069
00070 QString text;
00071
00072 QTextStream s( &file );
00073 s.setEncoding( QTextStream::Latin1 );
00074 text = s.read();
00075 file.close();
00076
00077 KABC::VCardConverter converter;
00078 KABC::Addressee::List list = converter.parseVCards( text );
00079
00080 if ( args->isSet( "vcard21" ) ) {
00081 text = converter.createVCards( list, KABC::VCardConverter::v2_1 );
00082 } else {
00083 text = converter.createVCards( list );
00084 }
00085
00086 std::cout << text.utf8();
00087
00088 return 0;
00089 }
|