38 #include <tdefiledialog.h>
39 #include <tdeio/netaccess.h>
40 #include <tdelocale.h>
42 #include <tdemessagebox.h>
43 #include <tdetempfile.h>
45 #include <tdeabc/ldifconverter.h>
49 #include "ldif_xxport.h"
51 K_EXPORT_KADDRESSBOOK_XXFILTER( libkaddrbk_ldif_xxport, LDIFXXPort )
53 LDIFXXPort::LDIFXXPort( TDEABC::AddressBook *ab, TQWidget *parent,
const char *name )
54 : KAB::XXPort( ab, parent, name )
56 createImportAction( i18n(
"Import LDIF Addressbook..." ) );
57 createExportAction( i18n(
"Export LDIF Addressbook..." ) );
62 TDEABC::AddresseeList LDIFXXPort::importContacts(
const TQString& )
const
64 TDEABC::AddresseeList addrList;
66 TQString fileName = KFileDialog::getOpenFileName( TQDir::homeDirPath(),
68 if ( fileName.isEmpty() )
71 TQFile file( fileName );
72 if ( !file.open( IO_ReadOnly ) ) {
73 TQString msg = i18n(
"<qt>Unable to open <b>%1</b> for reading.</qt>" );
74 KMessageBox::error( parentWidget(), msg.arg( fileName ) );
78 TQTextStream t( &file );
79 t.setEncoding( TQTextStream::Latin1 );
80 TQString wholeFile = t.read();
81 TQDateTime dtDefault = TQFileInfo(file).lastModified();
84 TDEABC::LDIFConverter::LDIFToAddressee( wholeFile, addrList, dtDefault );
92 bool LDIFXXPort::exportContacts(
const TDEABC::AddresseeList &list,
const TQString& )
94 KURL url = KFileDialog::getSaveURL( TQDir::homeDirPath() +
"/addressbook.ldif",
99 if( TQFileInfo(url.path()).exists() ) {
100 if(KMessageBox::questionYesNo( parentWidget(), i18n(
"Do you want to overwrite file \"%1\"").arg( url.path()) ) == KMessageBox::No)
105 if ( !url.isLocalFile() ) {
107 if ( tmpFile.status() != 0 ) {
108 TQString txt = i18n(
"<qt>Unable to open file <b>%1</b>.%2.</qt>" );
109 KMessageBox::error( parentWidget(), txt.arg( url.url() )
110 .arg( strerror( tmpFile.status() ) ) );
114 doExport( tmpFile.file(), list );
117 return TDEIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
119 TQString filename = url.path();
120 TQFile file( filename );
122 if ( !file.open( IO_WriteOnly ) ) {
123 TQString txt = i18n(
"<qt>Unable to open file <b>%1</b>.</qt>" );
124 KMessageBox::error( parentWidget(), txt.arg( filename ) );
128 doExport( &file, list );
135 void LDIFXXPort::doExport( TQFile *fp,
const TDEABC::AddresseeList &list )
138 TDEABC::LDIFConverter::addresseeToLDIF( list, str );
140 TQTextStream t( fp );
141 t.setEncoding( TQTextStream::UnicodeUTF8 );
145 #include "ldif_xxport.moc"