00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <iostream>
00022 #include <stdlib.h>
00023
00024 #include <QtCore/QFile>
00025
00026 #include <kdebug.h>
00027 #include <kcomponentdata.h>
00028 #include <kcmdlineargs.h>
00029 #include <klocale.h>
00030 #include <kaboutdata.h>
00031
00032 #include "kabc/vcardconverter.h"
00033 #include "vcard.h"
00034
00035 int main( int argc, char **argv )
00036 {
00037 KAboutData aboutData( "testread", 0, ki18n( "vCard test reader" ), "0.1" );
00038 aboutData.addAuthor( ki18n( "Cornelius Schumacher" ), KLocalizedString(), "schumacher@kde.org" );
00039
00040 KCmdLineArgs::init( argc, argv, &aboutData );
00041
00042 KCmdLineOptions options;
00043 options.add( "vcard21", ki18n( "vCard 2.1" ) );
00044 options.add( "+inputfile", ki18n( "Input file" ) );
00045 KCmdLineArgs::addCmdLineOptions( options );
00046
00047 KComponentData componentData( &aboutData );
00048
00049
00050 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00051
00052 if ( args->count() != 1 ) {
00053 std::cerr << "Missing argument" << std::endl;
00054 return 1;
00055 }
00056
00057 QString inputFile( args->arg( 0 ) );
00058
00059 QFile file( inputFile );
00060 if ( !file.open( QIODevice::ReadOnly ) ) {
00061 qDebug( "Unable to open file '%s' for reading!", qPrintable( file.fileName() ) );
00062 return 1;
00063 }
00064
00065 QByteArray text = file.readAll();
00066 file.close();
00067
00068 KABC::VCardConverter converter;
00069 KABC::Addressee::List list = converter.parseVCards( text );
00070
00071 if ( args->isSet( "vcard21" ) ) {
00072 text = converter.createVCards( list, KABC::VCardConverter::v2_1 );
00073 } else {
00074 text = converter.createVCards( list );
00075 }
00076
00077 std::cout << text.data();
00078
00079 return 0;
00080 }