summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorulf69 <ulf69>2004-07-20 21:28:10 (UTC)
committer ulf69 <ulf69>2004-07-20 21:28:10 (UTC)
commit6f2ccd235ef49d5606ecf4e540e8884f7a9b7ec4 (patch) (unidiff)
tree8ce4d24be2dfd04c386665723530435b66701286 /kaddressbook
parentfba0c028ac0ce15d0f7473439e025c56f108145e (diff)
downloadkdepimpi-6f2ccd235ef49d5606ecf4e540e8884f7a9b7ec4.zip
kdepimpi-6f2ccd235ef49d5606ecf4e540e8884f7a9b7ec4.tar.gz
kdepimpi-6f2ccd235ef49d5606ecf4e540e8884f7a9b7ec4.tar.bz2
remove the export was successfull dialog if the user canceled the operation
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/csv_xxport.cpp6
-rw-r--r--kaddressbook/xxport/opie/opie_xxport.cpp54
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp30
3 files changed, 45 insertions, 45 deletions
diff --git a/kaddressbook/xxport/csv_xxport.cpp b/kaddressbook/xxport/csv_xxport.cpp
index caee66d..d4d5475 100644
--- a/kaddressbook/xxport/csv_xxport.cpp
+++ b/kaddressbook/xxport/csv_xxport.cpp
@@ -21,172 +21,172 @@
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 61#endif //KAB_EMBEDDED
62 62
63 63
64extern "C" 64extern "C"
65{ 65{
66#ifndef KAB_EMBEDDED 66#ifndef KAB_EMBEDDED
67 void *init_libkaddrbk_csv_xxport() 67 void *init_libkaddrbk_csv_xxport()
68#else //KAB_EMBEDDED 68#else //KAB_EMBEDDED
69 void *init_kaddrbk_csv_xxport() 69 void *init_kaddrbk_csv_xxport()
70#endif //KAB_EMBEDDED 70#endif //KAB_EMBEDDED
71 { 71 {
72 return ( new CSVXXPortFactory() ); 72 return ( new CSVXXPortFactory() );
73 } 73 }
74} 74}
75 75
76 76
77CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 77CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
78 : XXPortObject( ab, parent, name ) 78 : XXPortObject( ab, parent, name )
79{ 79{
80 createImportAction( i18n( "Import CSV List..." ) ); 80 createImportAction( i18n( "Import CSV List..." ) );
81 createExportAction( i18n( "Export CSV List..." ) ); 81 createExportAction( i18n( "Export CSV List..." ) );
82} 82}
83 83
84bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& ) 84bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
85{ 85{
86#ifndef KAB_EMBEDDED 86#ifndef KAB_EMBEDDED
87 KURL url = KFileDialog::getSaveURL( "addressbook.csv" ); 87 KURL url = KFileDialog::getSaveURL( "addressbook.csv" );
88 if ( url.isEmpty() ) 88 if ( url.isEmpty() )
89 return true; 89 return true;
90 90
91 if ( !url.isLocalFile() ) { 91 if ( !url.isLocalFile() ) {
92 KTempFile tmpFile; 92 KTempFile tmpFile;
93 if ( tmpFile.status() != 0 ) { 93 if ( tmpFile.status() != 0 ) {
94 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>" );
95 KMessageBox::error( parentWidget(), txt.arg( url.url() ) 95 KMessageBox::error( parentWidget(), txt.arg( url.url() )
96 .arg( strerror( tmpFile.status() ) ) ); 96 .arg( strerror( tmpFile.status() ) ) );
97 return false; 97 return false;
98 } 98 }
99 99
100 doExport( tmpFile.file(), list ); 100 doExport( tmpFile.file(), list );
101 tmpFile.close(); 101 tmpFile.close();
102 102
103 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() ); 103 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
104 } else { 104 } else {
105 QFile file( url.path() ); 105 QFile file( url.path() );
106 if ( !file.open( IO_WriteOnly ) ) { 106 if ( !file.open( IO_WriteOnly ) ) {
107 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>" );
108 KMessageBox::error( parentWidget(), txt.arg( url.path() ) ); 108 KMessageBox::error( parentWidget(), txt.arg( url.path() ) );
109 return false; 109 return false;
110 } 110 }
111 111
112 doExport( &file, list ); 112 doExport( &file, list );
113 file.close(); 113 file.close();
114 114
115 return true; 115 return true;
116 } 116 }
117 117
118#else //KAB_EMBEDDED 118#else //KAB_EMBEDDED
119 119
120 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() ); 120 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() );
121 121
122 if ( fileName.isEmpty() ) 122 if ( fileName.isEmpty() )
123 return true; 123 return false;
124 124
125 QFile file( fileName ); 125 QFile file( fileName );
126 if ( !file.open( IO_WriteOnly ) ) { 126 if ( !file.open( IO_WriteOnly ) ) {
127 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ); 127 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
128 KMessageBox::error( parentWidget(), txt.arg( fileName ) ); 128 KMessageBox::error( parentWidget(), txt.arg( fileName ) );
129 return false; 129 return false;
130 } 130 }
131 131
132 doExport( &file, list ); 132 doExport( &file, list );
133 file.close(); 133 file.close();
134 134
135 return true; 135 return true;
136 136
137 137
138#endif //KAB_EMBEDDED 138#endif //KAB_EMBEDDED
139 139
140} 140}
141 141
142KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const 142KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const
143{ 143{
144 CSVImportDialog dlg( addressBook(), parentWidget() ); 144 CSVImportDialog dlg( addressBook(), parentWidget() );
145 if ( dlg.exec() ) 145 if ( dlg.exec() )
146 return dlg.contacts(); 146 return dlg.contacts();
147 else 147 else
148 return KABC::AddresseeList(); 148 return KABC::AddresseeList();
149} 149}
150 150
151void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list ) 151void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
152{ 152{
153 QTextStream t( fp ); 153 QTextStream t( fp );
154 154
155 KABC::AddresseeList::ConstIterator iter; 155 KABC::AddresseeList::ConstIterator iter;
156 KABC::Field::List fields = addressBook()->fields(); 156 KABC::Field::List fields = addressBook()->fields();
157 KABC::Field::List::Iterator fieldIter; 157 KABC::Field::List::Iterator fieldIter;
158 bool first = true; 158 bool first = true;
159 159
160 // First output the column headings 160 // First output the column headings
161 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) { 161 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
162 if ( !first ) 162 if ( !first )
163 t << ","; 163 t << ",";
164 164
165 t << "\"" << (*fieldIter)->label() << "\""; 165 t << "\"" << (*fieldIter)->label() << "\"";
166 first = false; 166 first = false;
167 } 167 }
168 t << "\n"; 168 t << "\n";
169 169
170 // Then all the addressee objects 170 // Then all the addressee objects
171 KABC::Addressee addr; 171 KABC::Addressee addr;
172 for ( iter = list.begin(); iter != list.end(); ++iter ) { 172 for ( iter = list.begin(); iter != list.end(); ++iter ) {
173 addr = *iter; 173 addr = *iter;
174 first = true; 174 first = true;
175 175
176 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) { 176 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
177 if ( !first ) 177 if ( !first )
178 t << ","; 178 t << ",";
179 179
180 t << "\"" << (*fieldIter)->value( addr ).replace( QRegExp("\n"), "\\n" ) << "\""; 180 t << "\"" << (*fieldIter)->value( addr ).replace( QRegExp("\n"), "\\n" ) << "\"";
181 first = false; 181 first = false;
182 } 182 }
183 183
184 t << "\n"; 184 t << "\n";
185 } 185 }
186} 186}
187 187
188#ifndef KAB_EMBEDDED 188#ifndef KAB_EMBEDDED
189#include "csv_xxport.moc" 189#include "csv_xxport.moc"
190#endif //KAB_EMBEDDED 190#endif //KAB_EMBEDDED
191 191
192 192
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp
index db30d34..c9b0163 100644
--- a/kaddressbook/xxport/opie/opie_xxport.cpp
+++ b/kaddressbook/xxport/opie/opie_xxport.cpp
@@ -1,221 +1,221 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 <qdir.h> 31#include <qdir.h>
32 32
33#include <kfiledialog.h> 33#include <kfiledialog.h>
34#include <kmessagebox.h> 34#include <kmessagebox.h>
35 35
36#include <opie/ocontactaccess.h> 36#include <opie/ocontactaccess.h>
37#include <opie/ocontactaccessbackend_xml.h> 37#include <opie/ocontactaccessbackend_xml.h>
38 38
39#include "stdaddressbook.h" 39#include "stdaddressbook.h"
40 40
41/*US 41/*US
42#include <qfile.h> 42#include <qfile.h>
43#include <qtextstream.h> 43#include <qtextstream.h>
44 44
45#include <kabc/vcardconverter.h> 45#include <kabc/vcardconverter.h>
46#ifndef KAB_EMBEDDED 46#ifndef KAB_EMBEDDED
47#include <kio/netaccess.h> 47#include <kio/netaccess.h>
48#endif //KAB_EMBEDDED 48#endif //KAB_EMBEDDED
49 49
50#include <klocale.h> 50#include <klocale.h>
51#include <kmessagebox.h> 51#include <kmessagebox.h>
52#include <ktempfile.h> 52#include <ktempfile.h>
53#include <kurl.h> 53#include <kurl.h>
54*/ 54*/
55 55
56#include "xxportmanager.h" 56#include "xxportmanager.h"
57#include "opieconverter.h" 57#include "opieconverter.h"
58 58
59#include "opie_xxport.h" 59#include "opie_xxport.h"
60 60
61 61
62class OpieXXPortFactory : public XXPortFactory 62class OpieXXPortFactory : public XXPortFactory
63{ 63{
64 public: 64 public:
65 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 65 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
66 { 66 {
67 return new OpieXXPort( ab, parent, name ); 67 return new OpieXXPort( ab, parent, name );
68 } 68 }
69}; 69};
70 70
71 71
72extern "C" 72extern "C"
73{ 73{
74 void *init_microkaddrbk_opie_xxport() 74 void *init_microkaddrbk_opie_xxport()
75 { 75 {
76 return ( new OpieXXPortFactory() ); 76 return ( new OpieXXPortFactory() );
77 } 77 }
78} 78}
79 79
80 80
81OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 81OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
82 : XXPortObject( ab, parent, name ) 82 : XXPortObject( ab, parent, name )
83{ 83{
84 createImportAction( i18n( "Import Opie..." ) ); 84 createImportAction( i18n( "Import Opie..." ) );
85 createExportAction( i18n( "Export Opie..." ) ); 85 createExportAction( i18n( "Export Opie..." ) );
86} 86}
87 87
88bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 88bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
89{ 89{
90 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 90 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
91 91
92#ifndef KAB_EMBEDDED 92#ifndef KAB_EMBEDDED
93 QString fileName = KFileDialog::getSaveFileName( name ); 93 QString fileName = KFileDialog::getSaveFileName( name );
94#else //KAB_EMBEDDED 94#else //KAB_EMBEDDED
95 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); 95 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
96#endif //KAB_EMBEDDED 96#endif //KAB_EMBEDDED
97 97
98 if ( fileName.isEmpty() ) 98 if ( fileName.isEmpty() )
99 return true; 99 return false;
100 100
101 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); 101 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName );
102 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); 102 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false);
103 103
104 if ( !access ) { 104 if ( !access ) {
105 qDebug("Unable to access file() %s", fileName.latin1()); 105 qDebug("Unable to access file() %s", fileName.latin1());
106 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 106 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
107 return false; 107 return false;
108 } 108 }
109 109
110 KABC::OpieConverter mConverter; 110 KABC::OpieConverter mConverter;
111 111
112 bool res = mConverter.init(); 112 bool res = mConverter.init();
113 if (!res) 113 if (!res)
114 { 114 {
115 QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) ); 115 QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) );
116 qDebug(text); 116 qDebug(text);
117 KMessageBox::error( parentWidget(), text ); 117 KMessageBox::error( parentWidget(), text );
118 delete access; 118 delete access;
119 return false; 119 return false;
120 } 120 }
121 121
122 //Now check if the file has already entries, and ask the user if he wants to delete them first. 122 //Now check if the file has already entries, and ask the user if he wants to delete them first.
123 OContactAccess::List contactList = access->allRecords(); 123 OContactAccess::List contactList = access->allRecords();
124 if (contactList.count() > 0) 124 if (contactList.count() > 0)
125 { 125 {
126 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 126 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
127 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 127 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
128 // Clean the database.. 128 // Clean the database..
129 access->clear(); 129 access->clear();
130 } 130 }
131 } 131 }
132 132
133 133
134 KABC::Addressee::List::ConstIterator it; 134 KABC::Addressee::List::ConstIterator it;
135 for ( it = list.begin(); it != list.end(); ++it ) { 135 for ( it = list.begin(); it != list.end(); ++it ) {
136 OContact c; 136 OContact c;
137 KABC::Addressee addressee = (*it); 137 KABC::Addressee addressee = (*it);
138 138
139 res = mConverter.addresseeToOpie( *it, c ); 139 res = mConverter.addresseeToOpie( *it, c );
140 if (res == true) 140 if (res == true)
141 { 141 {
142 res = access->add(c); 142 res = access->add(c);
143 if (res == false) 143 if (res == false)
144 qDebug("Unable to append Contact %s", c.fullName().latin1()); 144 qDebug("Unable to append Contact %s", c.fullName().latin1());
145 } 145 }
146 else 146 else
147 { 147 {
148 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 148 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
149 } 149 }
150 } 150 }
151 151
152 access->save(); 152 access->save();
153 153
154 delete access; 154 delete access;
155//US the deletion of the access object deletes the backend object as well. 155//US the deletion of the access object deletes the backend object as well.
156 156
157 return true; 157 return true;
158} 158}
159 159
160KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const 160KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const
161{ 161{
162 KABC::AddresseeList adrlst; 162 KABC::AddresseeList adrlst;
163 163
164 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 164 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
165 165
166#ifndef KAB_EMBEDDED 166#ifndef KAB_EMBEDDED
167 QString fileName = KFileDialog::getOpenFileName( name ); 167 QString fileName = KFileDialog::getOpenFileName( name );
168#else //KAB_EMBEDDED 168#else //KAB_EMBEDDED
169 QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); 169 QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() );
170#endif //KAB_EMBEDDED 170#endif //KAB_EMBEDDED
171 171
172 if ( fileName.isEmpty() ) 172 if ( fileName.isEmpty() )
173 return KABC::AddresseeList(); 173 return KABC::AddresseeList();
174 174
175 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); 175 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName );
176 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); 176 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false);
177 177
178 if ( !access ) { 178 if ( !access ) {
179 qDebug("Unable to access file() %s", fileName.latin1()); 179 qDebug("Unable to access file() %s", fileName.latin1());
180 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 180 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
181 return KABC::AddresseeList(); 181 return KABC::AddresseeList();
182 } 182 }
183 183
184 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available 184 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available
185 185
186 KABC::OpieConverter mConverter; 186 KABC::OpieConverter mConverter;
187 187
188 bool res = mConverter.init(); 188 bool res = mConverter.init();
189 if (!res) 189 if (!res)
190 { 190 {
191 QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) ); 191 QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) );
192 qDebug(text); 192 qDebug(text);
193 KMessageBox::error( parentWidget(), text ); 193 KMessageBox::error( parentWidget(), text );
194 delete access; 194 delete access;
195 return KABC::AddresseeList(); 195 return KABC::AddresseeList();
196 } 196 }
197 197
198 198
199 OContactAccess::List::Iterator it; 199 OContactAccess::List::Iterator it;
200 OContactAccess::List allList = access->allRecords(); 200 OContactAccess::List allList = access->allRecords();
201 for ( it = allList.begin(); it != allList.end(); ++it ) 201 for ( it = allList.begin(); it != allList.end(); ++it )
202 { 202 {
203 OContact c = (*it); 203 OContact c = (*it);
204 204
205 KABC::Addressee addressee; 205 KABC::Addressee addressee;
206 206
207 res = mConverter.opieToAddressee( c, addressee ); 207 res = mConverter.opieToAddressee( c, addressee );
208 208
209 if ( !addressee.isEmpty() && res ) { 209 if ( !addressee.isEmpty() && res ) {
210 adrlst.append( addressee ); 210 adrlst.append( addressee );
211 } 211 }
212 212
213// qDebug("found %s", c.fullName().latin1()); 213// qDebug("found %s", c.fullName().latin1());
214 } 214 }
215 215
216 delete access; 216 delete access;
217//US the deletion of the access object deletes the backend object as well. 217//US the deletion of the access object deletes the backend object as well.
218 218
219 return adrlst; 219 return adrlst;
220 220
221} 221}
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
index adf47cd..4819341 100644
--- a/kaddressbook/xxport/vcard_xxport.cpp
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -1,255 +1,255 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 <qtextstream.h> 32#include <qtextstream.h>
33 33
34#include <kabc/vcardconverter.h> 34#include <kabc/vcardconverter.h>
35#include <kabc/vcardparser/vcardtool.h> 35#include <kabc/vcardparser/vcardtool.h>
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 "xxportmanager.h" 46#include "xxportmanager.h"
47 47
48#include "vcard_xxport.h" 48#include "vcard_xxport.h"
49 49
50#ifndef KAB_EMBEDDED 50#ifndef KAB_EMBEDDED
51 51
52class VCardXXPortFactory : public XXPortFactory 52class VCardXXPortFactory : 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 VCardXXPort( ab, parent, name ); 57 return new VCardXXPort( ab, parent, name );
58 } 58 }
59}; 59};
60#endif //KAB_EMBEDDED 60#endif //KAB_EMBEDDED
61 61
62 62
63extern "C" 63extern "C"
64{ 64{
65#ifndef KAB_EMBEDDED 65#ifndef KAB_EMBEDDED
66 void *init_libkaddrbk_vcard_xxport() 66 void *init_libkaddrbk_vcard_xxport()
67#else //KAB_EMBEDDED 67#else //KAB_EMBEDDED
68 void *init_kaddrbk_vcard_xxport() 68 void *init_kaddrbk_vcard_xxport()
69#endif //KAB_EMBEDDED 69#endif //KAB_EMBEDDED
70 { 70 {
71 return ( new VCardXXPortFactory() ); 71 return ( new VCardXXPortFactory() );
72 } 72 }
73} 73}
74 74
75 75
76VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 76VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
77 : XXPortObject( ab, parent, name ) 77 : XXPortObject( ab, parent, name )
78{ 78{
79 createImportAction( i18n( "Import vCard..." ) ); 79 createImportAction( i18n( "Import vCard..." ) );
80//US KABC::VCardConverter does not support the export of 2.1 addressbooks. 80//US KABC::VCardConverter does not support the export of 2.1 addressbooks.
81//US createExportAction( i18n( "Export vCard 2.1..." ), "v21" ); 81//US createExportAction( i18n( "Export vCard 2.1..." ), "v21" );
82 createExportAction( i18n( "Export vCard 3.0..." ), "v30" ); 82 createExportAction( i18n( "Export vCard 3.0..." ), "v30" );
83} 83}
84 84
85bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 85bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
86{ 86{
87 QString name; 87 QString name;
88 88
89 if ( list.count() == 1 ) 89 if ( list.count() == 1 )
90 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; 90 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf";
91 else 91 else
92 name = "addressbook.vcf"; 92 name = "addressbook.vcf";
93 93
94#ifndef KAB_EMBEDDED 94#ifndef KAB_EMBEDDED
95 QString fileName = KFileDialog::getSaveFileName( name ); 95 QString fileName = KFileDialog::getSaveFileName( name );
96#else //KAB_EMBEDDED 96#else //KAB_EMBEDDED
97 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); 97 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
98#endif //KAB_EMBEDDED 98#endif //KAB_EMBEDDED
99 99
100 if ( fileName.isEmpty() ) 100 if ( fileName.isEmpty() )
101 return true; 101 return false;
102 102
103 QFile outFile( fileName ); 103 QFile outFile( fileName );
104 if ( !outFile.open( IO_WriteOnly ) ) { 104 if ( !outFile.open( IO_WriteOnly ) ) {
105 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 105 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
106 KMessageBox::error( parentWidget(), text.arg( fileName ) ); 106 KMessageBox::error( parentWidget(), text.arg( fileName ) );
107 return false; 107 return false;
108 } 108 }
109 109
110 QTextStream t( &outFile ); 110 QTextStream t( &outFile );
111 t.setEncoding( QTextStream::UnicodeUTF8 ); 111 t.setEncoding( QTextStream::UnicodeUTF8 );
112 112
113 KABC::Addressee::List::ConstIterator it; 113 KABC::Addressee::List::ConstIterator it;
114 for ( it = list.begin(); it != list.end(); ++it ) { 114 for ( it = list.begin(); it != list.end(); ++it ) {
115 KABC::VCardConverter converter; 115 KABC::VCardConverter converter;
116 QString vcard; 116 QString vcard;
117 117
118 KABC::VCardConverter::Version version; 118 KABC::VCardConverter::Version version;
119 if ( data == "v21" ) 119 if ( data == "v21" )
120 version = KABC::VCardConverter::v2_1; 120 version = KABC::VCardConverter::v2_1;
121 else 121 else
122 version = KABC::VCardConverter::v3_0; 122 version = KABC::VCardConverter::v3_0;
123 123
124 converter.addresseeToVCard( *it, vcard, version ); 124 converter.addresseeToVCard( *it, vcard, version );
125 t << vcard << "\r\n\r\n"; 125 t << vcard << "\r\n\r\n";
126 } 126 }
127 127
128 outFile.close(); 128 outFile.close();
129 129
130 return true; 130 return true;
131} 131}
132 132
133KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const 133KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
134{ 134{
135 QString fileName; 135 QString fileName;
136 KABC::AddresseeList addrList; 136 KABC::AddresseeList addrList;
137 KURL url; 137 KURL url;
138 138
139#ifndef KAB_EMBEDDED 139#ifndef KAB_EMBEDDED
140 if ( !XXPortManager::importData.isEmpty() ) 140 if ( !XXPortManager::importData.isEmpty() )
141 addrList = parseVCard( XXPortManager::importData ); 141 addrList = parseVCard( XXPortManager::importData );
142 else { 142 else {
143 if ( XXPortManager::importURL.isEmpty() ) 143 if ( XXPortManager::importURL.isEmpty() )
144 { 144 {
145 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); 145 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
146 } 146 }
147 else 147 else
148 url = XXPortManager::importURL; 148 url = XXPortManager::importURL;
149 149
150 if ( url.isEmpty() ) 150 if ( url.isEmpty() )
151 return addrList; 151 return addrList;
152 152
153 QString caption( i18n( "vCard Import Failed" ) ); 153 QString caption( i18n( "vCard Import Failed" ) );
154 if ( KIO::NetAccess::download( url, fileName ) ) { 154 if ( KIO::NetAccess::download( url, fileName ) ) {
155 QFile file( fileName ); 155 QFile file( fileName );
156 156
157 file.open( IO_ReadOnly ); 157 file.open( IO_ReadOnly );
158 QByteArray rawData = file.readAll(); 158 QByteArray rawData = file.readAll();
159 file.close(); 159 file.close();
160 160
161 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 161 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
162 addrList = parseVCard( data ); 162 addrList = parseVCard( data );
163 163
164 if ( !url.isLocalFile() ) 164 if ( !url.isLocalFile() )
165 KIO::NetAccess::removeTempFile( fileName ); 165 KIO::NetAccess::removeTempFile( fileName );
166 166
167 } else { 167 } else {
168 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ); 168 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
169 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption ); 169 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption );
170 } 170 }
171 171
172 } 172 }
173 173
174 174
175#else //KAB_EMBEDDED 175#else //KAB_EMBEDDED
176 176
177 177
178 if ( !XXPortManager::importData.isEmpty() ) 178 if ( !XXPortManager::importData.isEmpty() )
179 addrList = parseVCard( XXPortManager::importData ); 179 addrList = parseVCard( XXPortManager::importData );
180 else { 180 else {
181 if ( XXPortManager::importURL.isEmpty() ) 181 if ( XXPortManager::importURL.isEmpty() )
182 { 182 {
183 fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); 183 fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
184 if ( fileName.isEmpty() ) 184 if ( fileName.isEmpty() )
185 return addrList; 185 return addrList;
186 186
187 } 187 }
188 else 188 else
189 { 189 {
190//US url = XXPortManager::importURL; 190//US url = XXPortManager::importURL;
191 qDebug("VCardXXPort::importContacts Urls at the moment not supported"); 191 qDebug("VCardXXPort::importContacts Urls at the moment not supported");
192 if ( url.isEmpty() ) 192 if ( url.isEmpty() )
193 return addrList; 193 return addrList;
194 194
195 } 195 }
196 196
197 197
198 QFile file( fileName ); 198 QFile file( fileName );
199 199
200 file.open( IO_ReadOnly ); 200 file.open( IO_ReadOnly );
201 QByteArray rawData = file.readAll(); 201 QByteArray rawData = file.readAll();
202 file.close(); 202 file.close();
203 203
204 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 204 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
205 addrList = parseVCard( data ); 205 addrList = parseVCard( data );
206 206
207 } 207 }
208#endif //KAB_EMBEDDED 208#endif //KAB_EMBEDDED
209 209
210 return addrList; 210 return addrList;
211} 211}
212 212
213KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const 213KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const
214{ 214{
215 215
216 KABC::VCardTool tool; 216 KABC::VCardTool tool;
217 KABC::AddresseeList addrList; 217 KABC::AddresseeList addrList;
218 addrList = tool.parseVCards( data ); 218 addrList = tool.parseVCards( data );
219 // LR : I switched to the code, which is in current cvs HEAD 219 // LR : I switched to the code, which is in current cvs HEAD
220 /* 220 /*
221 uint numVCards = data.contains( "BEGIN:VCARD", false ); 221 uint numVCards = data.contains( "BEGIN:VCARD", false );
222 QStringList dataList = QStringList::split( "\r\n\r\n", data ); 222 QStringList dataList = QStringList::split( "\r\n\r\n", data );
223 223
224 for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) { 224 for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) {
225 KABC::Addressee addr; 225 KABC::Addressee addr;
226 bool ok = false; 226 bool ok = false;
227 227
228 if ( dataList[ i ].contains( "VERSION:3.0" ) ) 228 if ( dataList[ i ].contains( "VERSION:3.0" ) )
229 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 ); 229 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 );
230 else if ( dataList[ i ].contains( "VERSION:2.1" ) ) 230 else if ( dataList[ i ].contains( "VERSION:2.1" ) )
231 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 ); 231 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 );
232 else { 232 else {
233 KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) ); 233 KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) );
234 continue; 234 continue;
235 } 235 }
236 236
237 if ( !addr.isEmpty() && ok ) 237 if ( !addr.isEmpty() && ok )
238 addrList.append( addr ); 238 addrList.append( addr );
239 else { 239 else {
240 QString text = i18n( "The selected file does not include a valid vCard. " 240 QString text = i18n( "The selected file does not include a valid vCard. "
241 "Please check the file and try again." ); 241 "Please check the file and try again." );
242 KMessageBox::sorry( parentWidget(), text ); 242 KMessageBox::sorry( parentWidget(), text );
243 } 243 }
244 } 244 }
245 */ 245 */
246 if ( addrList.isEmpty() ) { 246 if ( addrList.isEmpty() ) {
247 QString text = i18n( "The selected file does not\ninclude a valid vCard.\nPlease check the file and try again.\n" ); 247 QString text = i18n( "The selected file does not\ninclude a valid vCard.\nPlease check the file and try again.\n" );
248 KMessageBox::sorry( parentWidget(), text ); 248 KMessageBox::sorry( parentWidget(), text );
249 } 249 }
250 return addrList; 250 return addrList;
251} 251}
252 252
253#ifndef KAB_EMBEDDED 253#ifndef KAB_EMBEDDED
254#include "vcard_xxport.moc" 254#include "vcard_xxport.moc"
255#endif //KAB_EMBEDDED 255#endif //KAB_EMBEDDED