26 #include <tdefiledialog.h>
27 #include <tdeio/netaccess.h>
28 #include <tdelocale.h>
29 #include <tdemessagebox.h>
30 #include <tdetempfile.h>
35 #include "eudora_xxport.h"
39 K_EXPORT_KADDRESSBOOK_XXFILTER( libkaddrbk_eudora_xxport, EudoraXXPort )
41 EudoraXXPort::EudoraXXPort( TDEABC::AddressBook *ab, TQWidget *parent,
const char *name )
42 : KAB::XXPort( ab, parent, name )
44 createImportAction( i18n(
"Import Eudora Addressbook..." ) );
47 TDEABC::AddresseeList EudoraXXPort::importContacts(
const TQString& )
const
49 TQString fileName = KFileDialog::getOpenFileName( TQDir::homeDirPath(),
50 "*.[tT][xX][tT]|" + i18n(
"Eudora Light Addressbook (*.txt)"), 0 );
51 if ( fileName.isEmpty() )
52 return TDEABC::AddresseeList();
54 TQFile file( fileName );
55 if ( !file.open( IO_ReadOnly ) )
56 return TDEABC::AddresseeList();
59 TQTextStream stream( &file );
60 TDEABC::Addressee *a = 0;
63 TDEABC::AddresseeList list;
65 while( !stream.eof() ) {
66 line = stream.readLine();
67 bytesRead += line.length();
70 if ( line.startsWith(
"alias" ) ) {
75 a =
new TDEABC::Addressee();
77 a =
new TDEABC::Addressee();
79 tmp = key( line ).stripWhiteSpace();
81 a->setFormattedName( tmp );
83 tmp = email( line ).stripWhiteSpace();
85 a->insertEmail( tmp );
86 }
else if ( line.startsWith(
"note" ) ) {
90 tmp = comment( line ).stripWhiteSpace();
94 tmp = get( line,
"name" ).stripWhiteSpace();
96 a->setNameFromString( tmp );
98 tmp = get( line,
"address" ).stripWhiteSpace();
99 if ( !tmp.isEmpty() ) {
100 TDEABC::Address addr;
101 kdDebug(5720) << tmp << endl;
102 addr.setLabel( tmp );
103 a->insertAddress( addr );
106 tmp = get( line,
"phone" ).stripWhiteSpace();
107 if ( !tmp.isEmpty() )
108 a->insertPhoneNumber( TDEABC::PhoneNumber( tmp, TDEABC::PhoneNumber::Home ) );
123 TQString EudoraXXPort::key(
const TQString& line)
const
127 int b = line.find(
'\"', 0 );
130 b = line.find(
' ' );
135 e = line.find(
' ', b );
136 result = line.mid( b, e - b );
142 e = line.find(
'\"', b );
146 result = line.mid( b, e - b );
151 TQString EudoraXXPort::email(
const TQString& line )
const
155 b = line.findRev(
'\"' );
157 b = line.findRev(
' ' );
161 result = line.mid( b + 1 );
166 TQString EudoraXXPort::comment(
const TQString& line )
const
171 b = line.findRev(
'>' );
173 b = line.findRev(
'\"' );
178 result = line.mid( b + 1 );
179 for ( i = 0; i < result.length(); i++ ) {
180 if ( result[ i ] == CTRL_C )
187 TQString EudoraXXPort::get(
const TQString& line,
const TQString& key )
const
189 TQString fd =
"<" + key +
":";
199 e = line.find(
'>', b );
204 TQString result = line.mid( b, e - b + 1 );
205 for ( i = 0; i < result.length(); i++ ) {
206 if ( result[ i ] == CTRL_C )
213 #include "eudora_xxport.moc"