28 #include <tdefiledialog.h>
29 #include <tdeio/netaccess.h>
30 #include <tdelocale.h>
31 #include <tdemessagebox.h>
32 #include <tdetempfile.h>
37 #include "opera_xxport.h"
39 K_EXPORT_KADDRESSBOOK_XXFILTER( libkaddrbk_opera_xxport, OperaXXPort )
41 OperaXXPort::OperaXXPort( TDEABC::AddressBook *ab, TQWidget *parent,
const char *name )
42 : KAB::XXPort( ab, parent, name )
44 createImportAction( i18n(
"Import Opera Addressbook..." ) );
47 TDEABC::AddresseeList OperaXXPort::importContacts(
const TQString& )
const
49 TDEABC::AddresseeList addrList;
51 TQString fileName = KFileDialog::getOpenFileName( TQDir::homeDirPath() + TQString::fromLatin1(
"/.opera/contacts.adr" ) );
52 if ( fileName.isEmpty() )
55 TQFile file( fileName );
56 if ( !file.open( IO_ReadOnly ) ) {
57 TQString msg = i18n(
"<qt>Unable to open <b>%1</b> for reading.</qt>" );
58 KMessageBox::error( parentWidget(), msg.arg( fileName ) );
62 TQTextStream stream( &file );
63 stream.setEncoding( TQTextStream::UnicodeUTF8 );
64 TQString line, key, value;
65 bool parseContact =
false;
66 TDEABC::Addressee addr;
68 TQRegExp separator(
"\x02\x02" );
70 while ( !stream.atEnd() ) {
71 line = stream.readLine();
72 line = line.stripWhiteSpace();
73 if ( line == TQString::fromLatin1(
"#CONTACT" ) ) {
75 addr = TDEABC::Addressee();
77 }
else if ( line.isEmpty() ) {
79 if ( !addr.isEmpty() ) {
80 addrList.append( addr );
81 addr = TDEABC::Addressee();
86 if ( parseContact ==
true ) {
87 int sep = line.find(
'=' );
88 key = line.left( sep ).lower();
89 value = line.mid( sep + 1 );
90 if ( key == TQString::fromLatin1(
"name" ) )
91 addr.setNameFromString( value );
92 else if ( key == TQString::fromLatin1(
"mail" ) ) {
93 TQStringList emails = TQStringList::split( separator, value );
95 TQStringList::Iterator it = emails.begin();
96 bool preferred =
true;
97 for ( ; it != emails.end(); ++it ) {
98 addr.insertEmail( *it, preferred );
101 }
else if ( key == TQString::fromLatin1(
"phone" ) )
102 addr.insertPhoneNumber( TDEABC::PhoneNumber( value ) );
103 else if ( key == TQString::fromLatin1(
"fax" ) )
104 addr.insertPhoneNumber( TDEABC::PhoneNumber( value,
105 TDEABC::PhoneNumber::Fax | TDEABC::PhoneNumber::Home ) );
106 else if ( key == TQString::fromLatin1(
"postaladdress" ) ) {
107 TDEABC::Address address( TDEABC::Address::Home );
108 address.setLabel( value.replace( separator,
"\n" ) );
109 addr.insertAddress( address );
110 }
else if ( key == TQString::fromLatin1(
"description" ) )
111 addr.setNote( value.replace( separator,
"\n" ) );
112 else if ( key == TQString::fromLatin1(
"url" ) )
113 addr.setUrl( KURL( value ) );
114 else if ( key == TQString::fromLatin1(
"pictureurl" ) ) {
115 TDEABC::Picture pic( value );
116 addr.setPhoto( pic );
126 #include "opera_xxport.moc"