• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

kabc

  • kabc
  • vcardparser
testread.cpp
1/*
2 This file is part of libkabc.
3 Copyright (c) 2007 KDE-PIM team <kde-pim@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include <iostream>
22#include <stdlib.h>
23
24#include <QtCore/QFile>
25
26#include <kdebug.h>
27#include <kcomponentdata.h>
28#include <kcmdlineargs.h>
29#include <klocalizedstring.h>
30#include <kaboutdata.h>
31
32#include "kabc/vcardconverter.h"
33#include "vcard.h"
34
35int main( int argc, char **argv )
36{
37 KAboutData aboutData( "testread", 0, ki18n( "vCard test reader" ), "0.1" );
38 aboutData.addAuthor( ki18n( "Cornelius Schumacher" ), KLocalizedString(), "schumacher@kde.org" );
39
40 KCmdLineArgs::init( argc, argv, &aboutData );
41
42 KCmdLineOptions options;
43 options.add( "vcard21", ki18n( "vCard 2.1" ) );
44 options.add( "+inputfile", ki18n( "Input file" ) );
45 KCmdLineArgs::addCmdLineOptions( options );
46
47 KComponentData componentData( &aboutData );
48 // QCoreApp not needed
49
50 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
51
52 if ( args->count() != 1 ) {
53 std::cerr << "Missing argument" << std::endl;
54 return 1;
55 }
56
57 QString inputFile( args->arg( 0 ) );
58
59 QFile file( inputFile );
60 if ( !file.open( QIODevice::ReadOnly ) ) {
61 qDebug( "Unable to open file '%s' for reading!", qPrintable( file.fileName() ) );
62 return 1;
63 }
64
65 QByteArray text = file.readAll();
66 file.close();
67
68 KABC::VCardConverter converter;
69 KABC::Addressee::List list = converter.parseVCards( text );
70
71 if ( args->isSet( "vcard21" ) ) {
72 text = converter.createVCards( list, KABC::VCardConverter::v2_1 ); // uses version 2.1
73 } else {
74 text = converter.createVCards( list ); // uses version 3.0
75 }
76
77 std::cout << text.data();
78
79 return 0;
80}
KABC::AddresseeList
a QValueList of Addressee, with sorting functionality
Definition: addresseelist.h:289
KABC::VCardConverter
Class to converting contact objects into vCard format and vice versa.
Definition: vcardconverter.h:54
KABC::VCardConverter::createVCards
QByteArray createVCards(Addressee::List list, Version version=v3_0) const
Creates a string in vCard format which contains the given list of contact.
Definition: vcardconverter.cpp:70
KABC::VCardConverter::parseVCards
Addressee::List parseVCards(const QByteArray &vcard) const
Parses a string in vCard format and returns a list of contact objects.
Definition: vcardconverter.cpp:96
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal