summaryrefslogtreecommitdiffabout
path: root/kaddressbook/xxport/vcard_xxport.cpp
Unidiff
Diffstat (limited to 'kaddressbook/xxport/vcard_xxport.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
index 9a8fa68..64b9071 100644
--- a/kaddressbook/xxport/vcard_xxport.cpp
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -16,34 +16,36 @@
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/*
25 Enhanced Version of the file for platform independent KDE tools. 25 Enhanced Version of the file for platform independent KDE tools.
26 Copyright (c) 2004 Ulf Schenk 26 Copyright (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 <q3textstream.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34//Added by qt3to4:
35#include <Q3CString>
34 36
35#include <kabc/vcardconverter.h> 37#include <kabc/vcardconverter.h>
36#include <kabc/vcardparser/vcardtool.h> 38#include <kabc/vcardparser/vcardtool.h>
37#include <kfiledialog.h> 39#include <kfiledialog.h>
38#ifndef KAB_EMBEDDED 40#ifndef KAB_EMBEDDED
39#include <kio/netaccess.h> 41#include <kio/netaccess.h>
40#endif //KAB_EMBEDDED 42#endif //KAB_EMBEDDED
41 43
42#include <klocale.h> 44#include <klocale.h>
43#include <kmessagebox.h> 45#include <kmessagebox.h>
44#include <ktempfile.h> 46#include <ktempfile.h>
45#include <kurl.h> 47#include <kurl.h>
46 48
47#include "xxportmanager.h" 49#include "xxportmanager.h"
48 50
49#include "vcard_xxport.h" 51#include "vcard_xxport.h"
@@ -89,40 +91,40 @@ bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString
89 91
90 if ( list.count() == 1 ) 92 if ( list.count() == 1 )
91 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; 93 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf";
92 else 94 else
93 name = "addressbook.vcf"; 95 name = "addressbook.vcf";
94 96
95#ifndef KAB_EMBEDDED 97#ifndef KAB_EMBEDDED
96 QString fileName = KFileDialog::getSaveFileName( name ); 98 QString fileName = KFileDialog::getSaveFileName( name );
97#else //KAB_EMBEDDED 99#else //KAB_EMBEDDED
98 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); 100 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
99#endif //KAB_EMBEDDED 101#endif //KAB_EMBEDDED
100 102
101 if ( fileName.isEmpty() ) 103 if ( fileName.isEmpty() )
102 return false; 104 return false;
103 105
104 QFile outFile( fileName ); 106 QFile outFile( fileName );
105 if ( !outFile.open( IO_WriteOnly ) ) { 107 if ( !outFile.open( QIODevice::WriteOnly ) ) {
106 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 108 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
107 KMessageBox::error( parentWidget(), text.arg( fileName ) ); 109 KMessageBox::error( parentWidget(), text.arg( fileName ) );
108 return false; 110 return false;
109 } 111 }
110 112
111 QTextStream t( &outFile ); 113 Q3TextStream t( &outFile );
112 t.setEncoding( QTextStream::UnicodeUTF8 ); 114 t.setEncoding( Q3TextStream::UnicodeUTF8 );
113 115
114 KABC::Addressee::List::ConstIterator it; 116 KABC::Addressee::List::ConstIterator it;
115 for ( it = list.begin(); it != list.end(); ++it ) { 117 for ( it = list.begin(); it != list.end(); ++it ) {
116 KABC::VCardConverter converter; 118 KABC::VCardConverter converter;
117 QString vcard; 119 QString vcard;
118 120
119 KABC::VCardConverter::Version version; 121 KABC::VCardConverter::Version version;
120 if ( data == "v21" ) 122 if ( data == "v21" )
121 version = KABC::VCardConverter::v2_1; 123 version = KABC::VCardConverter::v2_1;
122 else 124 else
123 version = KABC::VCardConverter::v3_0; 125 version = KABC::VCardConverter::v3_0;
124 126
125 converter.addresseeToVCard( *it, vcard, version ); 127 converter.addresseeToVCard( *it, vcard, version );
126 t << vcard << "\r\n\r\n"; 128 t << vcard << "\r\n\r\n";
127 } 129 }
128 130
@@ -140,33 +142,33 @@ KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
140#ifndef KAB_EMBEDDED 142#ifndef KAB_EMBEDDED
141 if ( !XXPortManager::importData.isEmpty() ) 143 if ( !XXPortManager::importData.isEmpty() )
142 addrList = parseVCard( XXPortManager::importData ); 144 addrList = parseVCard( XXPortManager::importData );
143 else { 145 else {
144 if ( XXPortManager::importURL.isEmpty() ) 146 if ( XXPortManager::importURL.isEmpty() )
145 { 147 {
146 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); 148 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
147 } 149 }
148 else 150 else
149 url = XXPortManager::importURL; 151 url = XXPortManager::importURL;
150 if ( url.isEmpty() ) 152 if ( url.isEmpty() )
151 return addrList; 153 return addrList;
152 QString caption( i18n( "vCard Import Failed" ) ); 154 QString caption( i18n( "vCard Import Failed" ) );
153 if ( KIO::NetAccess::download( url, fileName ) ) { 155 if ( KIO::NetAccess::download( url, fileName ) ) {
154 QFile file( fileName ); 156 QFile file( fileName );
155 157
156 file.open( IO_ReadOnly ); 158 file.open( QIODevice::ReadOnly );
157 QByteArray rawData = file.readAll(); 159 QByteArray rawData = file.readAll();
158 file.close(); 160 file.close();
159 161
160 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 162 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
161 addrList = parseVCard( data ); 163 addrList = parseVCard( data );
162 164
163 if ( !url.isLocalFile() ) 165 if ( !url.isLocalFile() )
164 KIO::NetAccess::removeTempFile( fileName ); 166 KIO::NetAccess::removeTempFile( fileName );
165 167
166 } else { 168 } else {
167 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ); 169 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
168 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption ); 170 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption );
169 } 171 }
170 172
171 } 173 }
172 174
@@ -183,34 +185,34 @@ KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
183 185
184 if ( fileName.isEmpty() ) 186 if ( fileName.isEmpty() )
185 return addrList; 187 return addrList;
186 QFileInfo fi ( fileName ); 188 QFileInfo fi ( fileName );
187 if ( !fi.isFile() ) 189 if ( !fi.isFile() )
188 return addrList; 190 return addrList;
189 } 191 }
190 else 192 else
191 { 193 {
192 //US url = XXPortManager::importURL; 194 //US url = XXPortManager::importURL;
193 qDebug("VCardXXPort::importContacts Urls at the moment not supported"); 195 qDebug("VCardXXPort::importContacts Urls at the moment not supported");
194 if ( url.isEmpty() ) 196 if ( url.isEmpty() )
195 return addrList; 197 return addrList;
196 198
197 } 199 }
198 QFile file( fileName ); 200 QFile file( fileName );
199 if ( file.open( IO_ReadOnly ) ) { 201 if ( file.open( QIODevice::ReadOnly ) ) {
200 QCString rawData ( file.readAll().data(),file.size()+1); 202 Q3CString rawData ( file.readAll().data(),file.size()+1);
201 file.close(); 203 file.close();
202 int start = 0; 204 int start = 0;
203#ifndef DESKTOP_VERSION 205#ifndef DESKTOP_VERSION
204 while ( start < rawData.size()-2 ) { 206 while ( start < rawData.size()-2 ) {
205 if ( rawData.at( start ) == '\r' ) 207 if ( rawData.at( start ) == '\r' )
206 if ( rawData.at( start+1 ) == '\n' ) 208 if ( rawData.at( start+1 ) == '\n' )
207 if ( rawData.at( start+2 ) == ' ' ) { 209 if ( rawData.at( start+2 ) == ' ' ) {
208 rawData.remove(start,3); 210 rawData.remove(start,3);
209 --start; 211 --start;
210 } 212 }
211 ++start; 213 ++start;
212 } 214 }
213#endif 215#endif
214 int ret = KMessageBox::warningYesNoCancel( 0, i18n("Select import format!\nDefault and standard is Utf8.\nLatin1 may be the right\nfor some West Europian languages."), i18n("Import Format"), i18n("Utf8"), i18n("Latin1") ); 216 int ret = KMessageBox::warningYesNoCancel( 0, i18n("Select import format!\nDefault and standard is Utf8.\nLatin1 may be the right\nfor some West Europian languages."), i18n("Import Format"), i18n("Utf8"), i18n("Latin1") );
215 if ( ret == KMessageBox::Cancel ) 217 if ( ret == KMessageBox::Cancel )
216 return addrList; 218 return addrList;
@@ -254,19 +256,19 @@ KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const
254 addrList.append( addr ); 256 addrList.append( addr );
255 else { 257 else {
256 QString text = i18n( "The selected file does not include a valid vCard. " 258 QString text = i18n( "The selected file does not include a valid vCard. "
257 "Please check the file and try again." ); 259 "Please check the file and try again." );
258 KMessageBox::sorry( parentWidget(), text ); 260 KMessageBox::sorry( parentWidget(), text );
259 } 261 }
260 } 262 }
261 */ 263 */
262 if ( addrList.isEmpty() ) { 264 if ( addrList.isEmpty() ) {
263 QString text = i18n( "The selected file does not\ninclude a valid vCard.\nPlease check the file and try again.\n" ); 265 QString text = i18n( "The selected file does not\ninclude a valid vCard.\nPlease check the file and try again.\n" );
264 KMessageBox::sorry( parentWidget(), text ); 266 KMessageBox::sorry( parentWidget(), text );
265 } 267 }
266 return addrList; 268 return addrList;
267} 269}
268 270
269 271
270#ifndef KAB_EMBEDDED 272#ifndef KAB_EMBEDDED_
271#include "vcard_xxport.moc" 273#include "moc_vcard_xxport.cpp"
272#endif //KAB_EMBEDDED 274#endif //KAB_EMBEDDED