26 #include <tdefiledialog.h>
27 #include <tdeio/netaccess.h>
28 #include <tdelocale.h>
29 #include <tdemessagebox.h>
30 #include <tdetempfile.h>
33 #include "csvimportdialog.h"
35 #include "csv_xxport.h"
37 K_EXPORT_KADDRESSBOOK_XXFILTER( libkaddrbk_csv_xxport, CSVXXPort )
39 CSVXXPort::CSVXXPort( TDEABC::AddressBook *ab, TQWidget *parent,
const char *name )
40 : KAB::XXPort( ab, parent, name )
42 createImportAction( i18n(
"Import CSV List..." ) );
43 createExportAction( i18n(
"Export CSV List..." ) );
46 bool CSVXXPort::exportContacts(
const TDEABC::AddresseeList &list,
const TQString& )
48 KURL url = KFileDialog::getSaveURL(
"addressbook.csv" );
52 if( TQFileInfo(url.path()).exists() ) {
53 if(KMessageBox::questionYesNo( parentWidget(), i18n(
"Do you want to overwrite file \"%1\"").arg( url.path()) ) == KMessageBox::No)
57 if ( !url.isLocalFile() ) {
59 if ( tmpFile.status() != 0 ) {
60 TQString txt = i18n(
"<qt>Unable to open file <b>%1</b>.%2.</qt>" );
61 KMessageBox::error( parentWidget(), txt.arg( url.url() )
62 .arg( strerror( tmpFile.status() ) ) );
66 doExport( tmpFile.file(), list );
69 return TDEIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
71 TQFile file( url.path() );
72 if ( !file.open( IO_WriteOnly ) ) {
73 TQString txt = i18n(
"<qt>Unable to open file <b>%1</b>.</qt>" );
74 KMessageBox::error( parentWidget(), txt.arg( url.path() ) );
78 doExport( &file, list );
81 KMessageBox::information( parentWidget(), i18n(
"The contacts have been exported successfully." ) );
87 TDEABC::AddresseeList CSVXXPort::importContacts(
const TQString& )
const
89 CSVImportDialog dlg( addressBook(), parentWidget() );
91 return dlg.contacts();
93 return TDEABC::AddresseeList();
96 void CSVXXPort::doExport( TQFile *fp,
const TDEABC::AddresseeList &list )
99 t.setEncoding( TQTextStream::Locale );
101 TDEABC::AddresseeList::ConstIterator iter;
102 TDEABC::Field::List fields = addressBook()->fields();
103 TDEABC::Field::List::Iterator fieldIter;
107 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
111 t <<
"\"" << (*fieldIter)->label() <<
"\"";
117 TDEABC::Addressee addr;
118 for ( iter = list.begin(); iter != list.end(); ++iter ) {
122 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
126 t <<
"\"" << (*fieldIter)->value( addr ).replace(
"\n",
"\\n" ) <<
"\"";
134 #include "csv_xxport.moc"