summaryrefslogtreecommitdiffabout
path: root/kaddressbook/xxport/csv_xxport.cpp
Unidiff
Diffstat (limited to 'kaddressbook/xxport/csv_xxport.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/csv_xxport.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/kaddressbook/xxport/csv_xxport.cpp b/kaddressbook/xxport/csv_xxport.cpp
index 7281003..ed5807f 100644
--- a/kaddressbook/xxport/csv_xxport.cpp
+++ b/kaddressbook/xxport/csv_xxport.cpp
@@ -17,33 +17,33 @@
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qfile.h> 31#include <qfile.h>
32#include <qregexp.h> 32#include <qregexp.h>
33#include <qtextstream.h> 33#include <q3textstream.h>
34#include <qtextcodec.h> 34#include <qtextcodec.h>
35 35
36#include <kfiledialog.h> 36#include <kfiledialog.h>
37#ifndef KAB_EMBEDDED 37#ifndef KAB_EMBEDDED
38#include <kio/netaccess.h> 38#include <kio/netaccess.h>
39#endif //KAB_EMBEDDED 39#endif //KAB_EMBEDDED
40 40
41#include <klocale.h> 41#include <klocale.h>
42#include <kmessagebox.h> 42#include <kmessagebox.h>
43#include <ktempfile.h> 43#include <ktempfile.h>
44#include <kurl.h> 44#include <kurl.h>
45 45
46#include "csvimportdialog.h" 46#include "csvimportdialog.h"
47 47
48#include "csv_xxport.h" 48#include "csv_xxport.h"
49 49
@@ -91,80 +91,80 @@ bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString&
91 91
92 if ( !url.isLocalFile() ) { 92 if ( !url.isLocalFile() ) {
93 KTempFile tmpFile; 93 KTempFile tmpFile;
94 if ( tmpFile.status() != 0 ) { 94 if ( tmpFile.status() != 0 ) {
95 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" ); 95 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
96 KMessageBox::error( parentWidget(), txt.arg( url.url() ) 96 KMessageBox::error( parentWidget(), txt.arg( url.url() )
97 .arg( strerror( tmpFile.status() ) ) ); 97 .arg( strerror( tmpFile.status() ) ) );
98 return false; 98 return false;
99 } 99 }
100 100
101 doExport( tmpFile.file(), list ); 101 doExport( tmpFile.file(), list );
102 tmpFile.close(); 102 tmpFile.close();
103 103
104 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() ); 104 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
105 } else { 105 } else {
106 QFile file( url.path() ); 106 QFile file( url.path() );
107 if ( !file.open( IO_WriteOnly ) ) { 107 if ( !file.open( QIODevice::WriteOnly ) ) {
108 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ); 108 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
109 KMessageBox::error( parentWidget(), txt.arg( url.path() ) ); 109 KMessageBox::error( parentWidget(), txt.arg( url.path() ) );
110 return false; 110 return false;
111 } 111 }
112 112
113 doExport( &file, list ); 113 doExport( &file, list );
114 file.close(); 114 file.close();
115 115
116 return true; 116 return true;
117 } 117 }
118 118
119#else //KAB_EMBEDDED 119#else //KAB_EMBEDDED
120 120
121 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() ); 121 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() );
122 122
123 if ( fileName.isEmpty() ) 123 if ( fileName.isEmpty() )
124 return false; 124 return false;
125 125
126 QFile file( fileName ); 126 QFile file( fileName );
127 if ( !file.open( IO_WriteOnly ) ) { 127 if ( !file.open( QIODevice::WriteOnly ) ) {
128 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ); 128 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
129 KMessageBox::error( parentWidget(), txt.arg( fileName ) ); 129 KMessageBox::error( parentWidget(), txt.arg( fileName ) );
130 return false; 130 return false;
131 } 131 }
132 132
133 doExport( &file, list ); 133 doExport( &file, list );
134 file.close(); 134 file.close();
135 135
136 return true; 136 return true;
137 137
138 138
139#endif //KAB_EMBEDDED 139#endif //KAB_EMBEDDED
140 140
141} 141}
142 142
143KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const 143KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const
144{ 144{
145 CSVImportDialog dlg( addressBook(), parentWidget() ); 145 CSVImportDialog dlg( addressBook(), parentWidget() );
146 if ( dlg.exec() ) 146 if ( dlg.exec() )
147 return dlg.contacts(); 147 return dlg.contacts();
148 else 148 else
149 return KABC::AddresseeList(); 149 return KABC::AddresseeList();
150} 150}
151 151
152void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list ) 152void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
153{ 153{
154 QTextStream t( fp ); 154 Q3TextStream t( fp );
155 t.setCodec( QTextCodec::codecForName("utf8") ); 155 t.setCodec( QTextCodec::codecForName("utf8") );
156 156
157 KABC::AddresseeList::ConstIterator iter; 157 KABC::AddresseeList::ConstIterator iter;
158 KABC::Field::List fields = addressBook()->fields(); 158 KABC::Field::List fields = addressBook()->fields();
159 KABC::Field::List::Iterator fieldIter; 159 KABC::Field::List::Iterator fieldIter;
160 bool first = true; 160 bool first = true;
161 161
162 // First output the column headings 162 // First output the column headings
163 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) { 163 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
164 if ( !first ) 164 if ( !first )
165 t << ","; 165 t << ",";
166 166
167 t << "\"" << (*fieldIter)->label() << "\""; 167 t << "\"" << (*fieldIter)->label() << "\"";
168 first = false; 168 first = false;
169 } 169 }
170 t << "\n"; 170 t << "\n";
@@ -174,21 +174,19 @@ void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
174 for ( iter = list.begin(); iter != list.end(); ++iter ) { 174 for ( iter = list.begin(); iter != list.end(); ++iter ) {
175 addr = *iter; 175 addr = *iter;
176 first = true; 176 first = true;
177 177
178 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) { 178 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
179 if ( !first ) 179 if ( !first )
180 t << ","; 180 t << ",";
181 181
182 t << "\"" << (*fieldIter)->value( addr ) << "\""; 182 t << "\"" << (*fieldIter)->value( addr ) << "\"";
183 first = false; 183 first = false;
184 } 184 }
185 185
186 t << "\n"; 186 t << "\n";
187 } 187 }
188} 188}
189 189
190#ifndef KAB_EMBEDDED 190#ifndef KAB_EMBEDDED_
191#include "csv_xxport.moc" 191#include "moc_csv_xxport.cpp"
192#endif //KAB_EMBEDDED 192#endif //KAB_EMBEDDED
193
194