testwrite.cpp

00001 /*
00002     This file is part of libkabc.
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <kabc/addressee.h>
00021 #include <kabc/phonenumber.h>
00022 #include <kabc/address.h>
00023 #include <kabc/key.h>
00024 #include <kabc/picture.h>
00025 #include <kabc/sound.h>
00026 #include <kabc/secrecy.h>
00027 #include <kaboutdata.h>
00028 #include <kapplication.h>
00029 #include <kcmdlineargs.h>
00030 
00031 #include <qfile.h>
00032 #include <qtextstream.h>
00033 
00034 #include "vcardconverter.h"
00035 
00036 int main( int argc, char **argv )
00037 {
00038   KAboutData aboutData( "testwrite", "vCard test writer", "0.1" );
00039 
00040   KCmdLineArgs::init( argc, argv, &aboutData );
00041 
00042   KApplication app( false, false );
00043   
00044 
00045   KABC::Addressee addressee;
00046 
00047   addressee.setNameFromString( "Mr. Tobias Koenig Jr." );
00048   addressee.setNickName( "tokoe" );
00049   addressee.setBirthday( QDate( 1982, 7, 19 ) );
00050   addressee.setMailer( "mutt1.2" );
00051   addressee.setTimeZone( KABC::TimeZone( +2 ) );
00052 
00053   KABC::Geo geo;
00054   geo.setLatitude( 30 );
00055   geo.setLongitude( 51 );
00056   addressee.setGeo( geo );
00057 
00058   addressee.setTitle( "nerd" );
00059   addressee.setRole( "Maintainer" );
00060   addressee.setOrganization( "KDE" );
00061   addressee.setNote( "nerver\ntouch a running system" );
00062   addressee.setProductId( "testId" );
00063   addressee.setRevision( QDateTime::currentDateTime() );
00064   addressee.setSortString( "koenig" );
00065   addressee.setUrl( KURL( "http://wgess16.dyndns.org") );
00066   addressee.setSecrecy(  KABC::Secrecy( KABC::Secrecy::Confidential ) );
00067 /*
00068   QImage img;
00069   img.load( "testimg.png", "PNG" );
00070   KABC::Picture photo;
00071   photo.setData( img );
00072   addressee.setPhoto( photo );
00073 
00074   QImage img2;
00075   img2.load( "testimg.png", "PNG" );
00076   KABC::Picture logo;
00077   logo.setData( img2 );
00078   addressee.setLogo( logo );
00079 
00080   QFile soundFile( "testsound.wav" );
00081   soundFile.open( IO_ReadOnly );
00082   QByteArray data = soundFile.readAll();
00083   soundFile.close();
00084   KABC::Sound sound;
00085   sound.setData( data );
00086   addressee.setSound( sound );
00087 */
00088   addressee.insertEmail( "tokoe@kde.org", true );
00089   addressee.insertEmail( "tokoe82@yahoo.de", true );
00090 
00091   KABC::PhoneNumber phone1( "3541523475", KABC::PhoneNumber::Pref | KABC::PhoneNumber::Home );
00092   KABC::PhoneNumber phone2( "+46745673475", KABC::PhoneNumber::Work );
00093   addressee.insertPhoneNumber( phone1 );
00094   addressee.insertPhoneNumber( phone2 );
00095 
00096   KABC::Key key( "secret key", KABC::Key::X509 );
00097   addressee.insertKey( key );
00098 
00099   QStringList categories;
00100   categories << "Friends" << "School" << "KDE";
00101   addressee.setCategories( categories );
00102 
00103   KABC::Address a( KABC::Address::Work | KABC::Address::Postal | KABC::Address::Parcel );
00104   a.setStreet( "6544 Battleford Drive" );
00105   a.setLocality( "Raleigh" );
00106   a.setRegion( "NC" );
00107   a.setPostalCode( "27613-3502" );
00108   a.setCountry( "U.S.A." );
00109   addressee.insertAddress( a );
00110 
00111   addressee.insertCustom( "1hsdf", "ertuer", "iurt" );
00112   addressee.insertCustom( "2hsdf", "ertuer", "iurt" );
00113   addressee.insertCustom( "3hsdf", "ertuer", "iurt" );
00114 
00115   KABC::Addressee::List list;
00116   for ( int i = 0; i < 1000; ++i ) {
00117     KABC::Addressee addr = addressee;
00118     addr.setUid( QString::number( i ) );
00119     list.append( addr );
00120   }
00121 
00122   KABC::VCardConverter converter;
00123   QString txt = converter.createVCards( list );
00124 
00125   QFile file( "out.vcf" );
00126   file.open( IO_WriteOnly );
00127 
00128   QTextStream s( &file );
00129   s.setEncoding( QTextStream::UnicodeUTF8 );
00130   s << txt;
00131   file.close();
00132 
00133   return 0;
00134 }
KDE Home | KDE Accessibility Home | Description of Access Keys