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.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/kaddressbook/xxport/csv_xxport.cpp b/kaddressbook/xxport/csv_xxport.cpp
index ce35053..caee66d 100644
--- a/kaddressbook/xxport/csv_xxport.cpp
+++ b/kaddressbook/xxport/csv_xxport.cpp
@@ -13,105 +13,110 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
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 <qtextstream.h>
34 34
35#include <kfiledialog.h> 35#include <kfiledialog.h>
36#ifndef KAB_EMBEDDED 36#ifndef KAB_EMBEDDED
37#include <kio/netaccess.h> 37#include <kio/netaccess.h>
38#endif //KAB_EMBEDDED 38#endif //KAB_EMBEDDED
39 39
40#include <klocale.h> 40#include <klocale.h>
41#include <kmessagebox.h> 41#include <kmessagebox.h>
42#include <ktempfile.h> 42#include <ktempfile.h>
43#include <kurl.h> 43#include <kurl.h>
44 44
45#include "csvimportdialog.h" 45#include "csvimportdialog.h"
46 46
47#include "csv_xxport.h" 47#include "csv_xxport.h"
48 48
49 49
50#ifndef KAB_EMBEDDED 50#ifndef KAB_EMBEDDED
51 51
52class CSVXXPortFactory : public XXPortFactory 52class CSVXXPortFactory : public XXPortFactory
53{ 53{
54 public: 54 public:
55 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 55 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
56 { 56 {
57 return new CSVXXPort( ab, parent, name ); 57 return new CSVXXPort( ab, parent, name );
58 } 58 }
59}; 59};
60 60
61#endif //KAB_EMBEDDED
62
61 63
62extern "C" 64extern "C"
63{ 65{
66#ifndef KAB_EMBEDDED
64 void *init_libkaddrbk_csv_xxport() 67 void *init_libkaddrbk_csv_xxport()
68#else //KAB_EMBEDDED
69 void *init_kaddrbk_csv_xxport()
70#endif //KAB_EMBEDDED
65 { 71 {
66 return ( new CSVXXPortFactory() ); 72 return ( new CSVXXPortFactory() );
67 } 73 }
68} 74}
69#endif //KAB_EMBEDDED
70 75
71 76
72CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 77CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
73 : XXPortObject( ab, parent, name ) 78 : XXPortObject( ab, parent, name )
74{ 79{
75 createImportAction( i18n( "Import CSV List..." ) ); 80 createImportAction( i18n( "Import CSV List..." ) );
76 createExportAction( i18n( "Export CSV List..." ) ); 81 createExportAction( i18n( "Export CSV List..." ) );
77} 82}
78 83
79bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& ) 84bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
80{ 85{
81#ifndef KAB_EMBEDDED 86#ifndef KAB_EMBEDDED
82 KURL url = KFileDialog::getSaveURL( "addressbook.csv" ); 87 KURL url = KFileDialog::getSaveURL( "addressbook.csv" );
83 if ( url.isEmpty() ) 88 if ( url.isEmpty() )
84 return true; 89 return true;
85 90
86 if ( !url.isLocalFile() ) { 91 if ( !url.isLocalFile() ) {
87 KTempFile tmpFile; 92 KTempFile tmpFile;
88 if ( tmpFile.status() != 0 ) { 93 if ( tmpFile.status() != 0 ) {
89 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" ); 94 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
90 KMessageBox::error( parentWidget(), txt.arg( url.url() ) 95 KMessageBox::error( parentWidget(), txt.arg( url.url() )
91 .arg( strerror( tmpFile.status() ) ) ); 96 .arg( strerror( tmpFile.status() ) ) );
92 return false; 97 return false;
93 } 98 }
94 99
95 doExport( tmpFile.file(), list ); 100 doExport( tmpFile.file(), list );
96 tmpFile.close(); 101 tmpFile.close();
97 102
98 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() ); 103 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
99 } else { 104 } else {
100 QFile file( url.path() ); 105 QFile file( url.path() );
101 if ( !file.open( IO_WriteOnly ) ) { 106 if ( !file.open( IO_WriteOnly ) ) {
102 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ); 107 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
103 KMessageBox::error( parentWidget(), txt.arg( url.path() ) ); 108 KMessageBox::error( parentWidget(), txt.arg( url.path() ) );
104 return false; 109 return false;
105 } 110 }
106 111
107 doExport( &file, list ); 112 doExport( &file, list );
108 file.close(); 113 file.close();
109 114
110 return true; 115 return true;
111 } 116 }
112 117
113#else //KAB_EMBEDDED 118#else //KAB_EMBEDDED
114 119
115 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() ); 120 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() );
116 121
117 if ( fileName.isEmpty() ) 122 if ( fileName.isEmpty() )