testvcardformatimpl.cpp
00001 00002 /* 00003 This file is part of libtdeabc. 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 <kdebug.h> 00022 #include <kapplication.h> 00023 #include <kcmdlineargs.h> 00024 // #include <klocale.h> 00025 #include <kaboutdata.h> 00026 00027 #include "vcardformatimpl.h" 00028 00029 using namespace KABC; 00030 00031 int 00032 main( int argc, char **argv ) 00033 { 00034 KAboutData aboutData( "testvcardformatimpl", "vCard format plugin", "0.1" ); 00035 00036 KCmdLineArgs::init( argc, argv, &aboutData ); 00037 00038 KApplication app( false, false ); 00039 00040 00041 KABC::Addressee addressee; 00042 00043 addressee.setNameFromString( TQString::fromUtf8("Иван Иванов") ); 00044 addressee.setNickName( TQString::fromUtf8("иванчо") ); 00045 addressee.setBirthday( TQDate( 1981, 7, 19 ) ); 00046 addressee.setMailer( "mutt1.2" ); 00047 addressee.setTimeZone( KABC::TimeZone( +2 ) ); 00048 00049 KABC::Geo geo; 00050 geo.setLatitude( 30 ); 00051 geo.setLongitude( 51 ); 00052 addressee.setGeo( geo ); 00053 00054 addressee.setTitle( TQString::fromUtf8("Др") ); 00055 addressee.setRole( TQString::fromUtf8("Самарянин") ); 00056 addressee.setOrganization( TQString::fromUtf8("България ООД") ); 00057 addressee.setNote( TQString::fromUtf8("не\nпипай работеща система") ); 00058 addressee.setProductId( "testId" ); 00059 addressee.setRevision( TQDateTime::currentDateTime() ); 00060 addressee.setSortString( TQString::fromUtf8("сортиране") ); 00061 addressee.setUrl( KURL( "http://wgess17.dyndns.org") ); 00062 addressee.setSecrecy( KABC::Secrecy( KABC::Secrecy::Confidential ) ); 00063 /* 00064 TQImage img; 00065 img.load( "testimg.png", "PNG" ); 00066 KABC::Picture photo; 00067 photo.setData( img ); 00068 addressee.setPhoto( photo ); 00069 00070 TQImage img2; 00071 img2.load( "testimg.png", "PNG" ); 00072 KABC::Picture logo; 00073 logo.setData( img2 ); 00074 addressee.setLogo( logo ); 00075 00076 TQFile soundFile( "testsound.wav" ); 00077 soundFile.open( IO_ReadOnly ); 00078 TQByteArray data = soundFile.readAll(); 00079 soundFile.close(); 00080 KABC::Sound sound; 00081 sound.setData( data ); 00082 addressee.setSound( sound ); 00083 */ 00084 addressee.insertEmail( TQString::fromUtf8("иван.иванов@българия.оод"), true ); 00085 addressee.insertEmail( TQString::fromUtf8("иванчо@yahoo.de"), true ); 00086 00087 KABC::PhoneNumber phone1( "029876543", KABC::PhoneNumber::Pref | KABC::PhoneNumber::Home ); 00088 KABC::PhoneNumber phone2( "+359888111222", KABC::PhoneNumber::Work ); 00089 addressee.insertPhoneNumber( phone1 ); 00090 addressee.insertPhoneNumber( phone2 ); 00091 00092 KABC::Key key( "secret key", KABC::Key::X509 ); 00093 addressee.insertKey( key ); 00094 00095 TQStringList categories; 00096 categories << "Friends" << "School" << "KDE"; 00097 addressee.setCategories( categories ); 00098 00099 KABC::Address a( KABC::Address::Work | KABC::Address::Postal | KABC::Address::Parcel ); 00100 a.setStreet( TQString::fromUtf8("Цар Борис III") ); 00101 a.setLocality( TQString::fromUtf8("София" )); 00102 a.setRegion( TQString::fromUtf8("София град" )); 00103 a.setPostalCode( TQString::fromUtf8("1000" )); 00104 a.setCountry( TQString::fromUtf8("България" )); 00105 addressee.insertAddress( a ); 00106 00107 addressee.insertCustom( "1hsdf", "test1",TQString::fromUtf8( "ежзик" )); 00108 addressee.insertCustom( "2hsdf", "test2",TQString::fromUtf8( "ежзик" )); 00109 addressee.insertCustom( "3hsdf", "test3",TQString::fromUtf8( "ежзик" )); 00110 00111 addressee.dump(); 00112 00113 kdDebug() << ">>>>>>>>>>>>>>>>END FIRST ADDRESSEE<<<<<<<<<<<<<<" << endl; 00114 00115 // KABC::Addressee::List list; 00116 // for ( int i = 0; i < 20; ++i ) { 00117 // KABC::Addressee addr = addressee; 00118 // addr.setUid( TQString::number( i ) ); 00119 // list.append( addr ); 00120 // } 00121 00122 // KABC::VCardConverter converter; 00123 // TQString txt = converter.createVCards( list ); 00124 // 00125 // TQFile file( "out2.vcf" ); 00126 // file.open( IO_WriteOnly ); 00127 // 00128 // TQTextStream s( &file ); 00129 // s.setEncoding( TQTextStream::UnicodeUTF8 ); 00130 // s << txt; 00131 // file.close(); 00132 00133 VCardFormatImpl *vcfImpl = new VCardFormatImpl(); 00134 TQFile file( "vfimpout.vcf" ); 00135 if ( file.open(IO_WriteOnly) ){ 00136 vcfImpl->save(addressee, &file); 00137 file.close(); 00138 } 00139 00140 00141 KABC::Addressee addressee2; 00142 00143 if ( file.open(IO_ReadOnly ) ){ 00144 vcfImpl->load(addressee2, &file); 00145 file.close(); 00146 } 00147 00148 addressee2.dump(); 00149 00150 return 0; 00151 00152 00153 /* Addressee::List::iterator itr1; 00154 Addressee::List::iterator itr2; 00155 for ( itr1 = l.begin(), itr2 = parsed.begin(); 00156 itr1 != l.end(); ++itr1, ++itr2 ) { 00157 if ( (*itr1).fullEmail() == (*itr2).fullEmail() && 00158 (*itr1).organization() == (*itr2).organization() && 00159 (*itr1).phoneNumbers() == (*itr2).phoneNumbers() && 00160 (*itr1).emails() == (*itr2).emails() && 00161 (*itr1).role() == (*itr2).role() ) { 00162 kdDebug()<<"\tAddressee - PASSED"<<endl; 00163 kdDebug()<<"\t\t"<< (*itr1).fullEmail() << " VS. " << (*itr2).fullEmail()<<endl; 00164 } else { 00165 kdDebug()<<"\tAddressee - FAILED"<<endl; 00166 kdDebug()<<">>>>>>>Addressee from code<<<<<<<<"<<endl; 00167 (*itr1).dump(); 00168 kdDebug()<<">>>>>>>Addressee from file<<<<<<<<"<<endl; 00169 (*itr2).dump(); 00170 //kdDebug()<<"\t\t"<< (*itr1).fullEmail() << " VS. " << (*itr2).fullEmail()<<endl; 00171 } 00172 } 00173 */ 00174 }