• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kabc
 

kabc

  • kabc
  • vcardparser
vcardparser/testread.cpp
1 /*
2  This file is part of libkabc.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <iostream>
21 #include <stdlib.h>
22 
23 #include <tqfile.h>
24 #include <tqtextstream.h>
25 
26 #include <kprocess.h>
27 #include <kdebug.h>
28 #include <kapplication.h>
29 #include <kcmdlineargs.h>
30 #include <klocale.h>
31 #include <kaboutdata.h>
32 
33 #include "kabc/vcardconverter.h"
34 #include "vcard.h"
35 
36 static const KCmdLineOptions options[] =
37 {
38  {"vcard21", I18N_NOOP("vCard 2.1"), 0},
39  {"+inputfile", I18N_NOOP("Input file"), 0},
40  KCmdLineLastOption
41 };
42 
43 int main( int argc, char **argv )
44 {
45  KApplication::disableAutoDcopRegistration();
46 
47  KAboutData aboutData( "testread", "vCard test reader", "0.1" );
48  aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
49 
50  KCmdLineArgs::init( argc, argv, &aboutData );
51  KCmdLineArgs::addCmdLineOptions( options );
52 
53  KApplication app( false, false );
54 
55  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
56 
57  if ( args->count() != 1 ) {
58  std::cerr << "Missing argument" << std::endl;
59  return 1;
60  }
61 
62  TQString inputFile( args->arg( 0 ) );
63 
64  TQFile file( inputFile );
65  if ( !file.open( IO_ReadOnly ) ) {
66  qDebug( "Unable to open file '%s' for reading!", file.name().latin1() );
67  return 1;
68  }
69 
70  TQString text;
71 
72  TQTextStream s( &file );
73  s.setEncoding( TQTextStream::UnicodeUTF8 );
74  text = s.read();
75  file.close();
76 
77  KABC::VCardConverter converter;
78  KABC::Addressee::List list = converter.parseVCards( text );
79 
80  if ( args->isSet( "vcard21" ) ) {
81  text = converter.createVCards( list, KABC::VCardConverter::v2_1 ); // uses version 2.1
82  } else {
83  text = converter.createVCards( list ); // uses version 3.0
84  }
85 
86  std::cout << text.utf8();
87 
88  return 0;
89 }
KABC::VCardConverter
Class to converting contact objects into vCard format and vice versa.
Definition: vcardconverter.h:54
KABC::VCardConverter::createVCards
TQString createVCards(Addressee::List list, Version version=v3_0)
Creates a string in vCard format which contains the given list of contact.
Definition: vcardconverter.cpp:54
KABC::VCardConverter::parseVCards
Addressee::List parseVCards(const TQString &vcard)
Parses a string in vCard format and returns a list of contact objects.
Definition: vcardconverter.cpp:68
KAboutData
KApplication
KApplication::disableAutoDcopRegistration
static void disableAutoDcopRegistration()
KCmdLineArgs
KCmdLineArgs::init
static void init(int _argc, char **_argv, const char *_appname, const char *programName, const char *_description, const char *_version, bool noKApp=false)
KCmdLineArgs::isSet
bool isSet(const char *option) const
KCmdLineArgs::addCmdLineOptions
static void addCmdLineOptions(const KCmdLineOptions *options, const char *name=0, const char *id=0, const char *afterId=0)
KCmdLineArgs::arg
const char * arg(int n) const
KCmdLineArgs::count
int count() const
KCmdLineArgs::parsedArgs
static KCmdLineArgs * parsedArgs(const char *id=0)
I18N_NOOP
#define I18N_NOOP(x)
endl
kndbgstream & endl(kndbgstream &s)
klocale.h
KCmdLineOptions

kabc

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

kabc

Skip menu "kabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kabc by doxygen 1.9.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |