kabc
testread.cpp
00001 /* 00002 This file is part of libkabc. 00003 Copyright (c) 2007 KDE-PIM team <kde-pim@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 <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 // QCoreApp not needed 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 ); // uses version 2.1 00073 } else { 00074 text = converter.createVCards( list ); // uses version 3.0 00075 } 00076 00077 std::cout << text.data(); 00078 00079 return 0; 00080 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:05:44 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:05:44 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.