kabc
testwrite.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 <QtCore/QFile> 00022 00023 #include <kaboutdata.h> 00024 #include <kapplication.h> 00025 #include <kcmdlineargs.h> 00026 00027 #include "kabc/addressee.h" 00028 #include "kabc/phonenumber.h" 00029 #include "kabc/address.h" 00030 #include "kabc/key.h" 00031 #include "kabc/picture.h" 00032 #include "kabc/sound.h" 00033 #include "kabc/secrecy.h" 00034 #include "kabc/vcardconverter.h" 00035 00036 int main( int argc, char **argv ) 00037 { 00038 KAboutData aboutData( "testwrite", 0, ki18n("vCard test writer"), "0.1" ); 00039 00040 KCmdLineArgs::init( argc, argv, &aboutData ); 00041 00042 KApplication app( false ); 00043 00044 KABC::Addressee addressee; 00045 00046 addressee.setNameFromString( QLatin1String( "Mr. Tobias Koenig Jr." ) ); 00047 addressee.setNickName( QLatin1String( "tokoe" ) ); 00048 addressee.setBirthday( QDateTime( QDate( 1982, 7, 19 ) ) ); 00049 addressee.setMailer( QLatin1String( "mutt1.2" ) ); 00050 addressee.setTimeZone( KABC::TimeZone( +2 ) ); 00051 00052 KABC::Geo geo; 00053 geo.setLatitude( 30 ); 00054 geo.setLongitude( 51 ); 00055 addressee.setGeo( geo ); 00056 00057 addressee.setTitle( QLatin1String( "nerd" ) ); 00058 addressee.setRole( QLatin1String( "Maintainer" ) ); 00059 addressee.setOrganization( QLatin1String( "KDE" ) ); 00060 addressee.setNote( QLatin1String( "nerver\ntouch a running system" ) ); 00061 addressee.setProductId( QLatin1String( "testId" ) ); 00062 addressee.setRevision( QDateTime::currentDateTime() ); 00063 addressee.setSortString( QLatin1String( "koenig" ) ); 00064 addressee.setUrl( KUrl( QLatin1String( "http://wgess16.dyndns.org" ) ) ); 00065 addressee.setSecrecy( KABC::Secrecy( KABC::Secrecy::Confidential ) ); 00066 00067 addressee.insertEmail( QLatin1String( "tokoe@kde.org" ), true ); 00068 addressee.insertEmail( QLatin1String( "tokoe82@yahoo.de" ), true ); 00069 00070 KABC::PhoneNumber phone1( QLatin1String( "3541523475" ), 00071 KABC::PhoneNumber::Pref | KABC::PhoneNumber::Home ); 00072 KABC::PhoneNumber phone2( QLatin1String( "+46745673475" ), 00073 KABC::PhoneNumber::Work ); 00074 addressee.insertPhoneNumber( phone1 ); 00075 addressee.insertPhoneNumber( phone2 ); 00076 00077 KABC::Key key( QLatin1String( "secret key" ), KABC::Key::X509 ); 00078 addressee.insertKey( key ); 00079 00080 QStringList categories; 00081 categories << QLatin1String( "Friends" ) << QLatin1String( "School" ) << QLatin1String( "KDE" ); 00082 addressee.setCategories( categories ); 00083 00084 KABC::Address a( KABC::Address::Work | KABC::Address::Postal | KABC::Address::Parcel ); 00085 a.setStreet( QLatin1String( "6544 Battleford Drive" ) ); 00086 a.setLocality( QLatin1String( "Raleigh" ) ); 00087 a.setRegion( QLatin1String( "NC" ) ); 00088 a.setPostalCode( QLatin1String( "27613-3502" ) ); 00089 a.setCountry( QLatin1String( "U.S.A." ) ); 00090 addressee.insertAddress( a ); 00091 00092 addressee.insertCustom( QLatin1String( "1hsdf" ), QLatin1String( "ertuer" ), 00093 QLatin1String( "iurt" ) ); 00094 addressee.insertCustom( QLatin1String( "2hsdf" ), QLatin1String( "ertuer" ), 00095 QLatin1String( "iurt" ) ); 00096 addressee.insertCustom( QLatin1String( "3hsdf" ), QLatin1String( "ertuer" ), 00097 QLatin1String( "iurt" ) ); 00098 00099 KABC::Addressee::List list; 00100 for ( int i = 0; i < 1000; ++i ) { 00101 KABC::Addressee addr = addressee; 00102 addr.setUid( QString::number( i ) ); 00103 list.append( addr ); 00104 } 00105 00106 KABC::VCardConverter converter; 00107 QByteArray txt = converter.createVCards( list ); 00108 00109 QFile file( QLatin1String( "out.vcf" ) ); 00110 if ( !file.open( QIODevice::WriteOnly ) ) { 00111 qDebug( "Can't open file '%s' fro writing", qPrintable( file.fileName() ) ); 00112 return 1; 00113 } 00114 00115 file.write( txt ); 00116 file.close(); 00117 00118 return 0; 00119 }
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.