Warning, file /frameworks/kcontacts/tests/testread.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KContacts framework. 0003 SPDX-FileCopyrightText: 2007 KDE-PIM team <kde-pim@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include <iostream> 0009 0010 #include <QFile> 0011 0012 #include <QCommandLineOption> 0013 #include <QCommandLineParser> 0014 #include <QCoreApplication> 0015 #include <QDebug> 0016 0017 #include "converter/kcontacts/vcardconverter.h" 0018 #include "vcard_p.h" 0019 0020 int main(int argc, char **argv) 0021 { 0022 QCoreApplication app(argc, argv); 0023 QCommandLineParser parser; 0024 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("vcard21"), QStringLiteral("vCard 2.1"))); 0025 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("+inputfile"), QStringLiteral("Input file"))); 0026 0027 parser.addVersionOption(); 0028 parser.addHelpOption(); 0029 parser.process(app); 0030 0031 if (parser.positionalArguments().count() != 1) { 0032 std::cerr << "Missing argument" << std::endl; 0033 return 1; 0034 } 0035 0036 QString inputFile(parser.positionalArguments().at(0)); 0037 0038 QFile file(inputFile); 0039 if (!file.open(QIODevice::ReadOnly)) { 0040 qDebug("Unable to open file '%s' for reading!", qPrintable(file.fileName())); 0041 return 1; 0042 } 0043 0044 QByteArray text = file.readAll(); 0045 file.close(); 0046 0047 KContacts::VCardConverter converter; 0048 KContacts::Addressee::List list = converter.parseVCards(text); 0049 0050 if (parser.isSet(QStringLiteral("vcard21"))) { 0051 text = converter.createVCards(list, KContacts::VCardConverter::v2_1); // uses version 2.1 0052 } else { 0053 text = converter.createVCards(list); // uses version 3.0 0054 } 0055 0056 std::cout << text.data(); 0057 0058 return 0; 0059 }