summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/csv_xxport.cpp7
-rw-r--r--kaddressbook/xxport/kde2_xxport.cpp7
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp6
3 files changed, 17 insertions, 3 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
@@ -1,165 +1,170 @@
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 <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() )
118 return true; 123 return true;
119 124
120 QFile file( fileName ); 125 QFile file( fileName );
121 if ( !file.open( IO_WriteOnly ) ) { 126 if ( !file.open( IO_WriteOnly ) ) {
122 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>" );
123 KMessageBox::error( parentWidget(), txt.arg( fileName ) ); 128 KMessageBox::error( parentWidget(), txt.arg( fileName ) );
124 return false; 129 return false;
125 } 130 }
126 131
127 doExport( &file, list ); 132 doExport( &file, list );
128 file.close(); 133 file.close();
129 134
130 return true; 135 return true;
131 136
132 137
133#endif //KAB_EMBEDDED 138#endif //KAB_EMBEDDED
134 139
135} 140}
136 141
137KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const 142KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const
138{ 143{
139 CSVImportDialog dlg( addressBook(), parentWidget() ); 144 CSVImportDialog dlg( addressBook(), parentWidget() );
140 if ( dlg.exec() ) 145 if ( dlg.exec() )
141 return dlg.contacts(); 146 return dlg.contacts();
142 else 147 else
143 return KABC::AddresseeList(); 148 return KABC::AddresseeList();
144} 149}
145 150
146void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list ) 151void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
147{ 152{
148 QTextStream t( fp ); 153 QTextStream t( fp );
149 154
150 KABC::AddresseeList::ConstIterator iter; 155 KABC::AddresseeList::ConstIterator iter;
151 KABC::Field::List fields = addressBook()->fields(); 156 KABC::Field::List fields = addressBook()->fields();
152 KABC::Field::List::Iterator fieldIter; 157 KABC::Field::List::Iterator fieldIter;
153 bool first = true; 158 bool first = true;
154 159
155 // First output the column headings 160 // First output the column headings
156 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) { 161 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
157 if ( !first ) 162 if ( !first )
158 t << ","; 163 t << ",";
159 164
160 t << "\"" << (*fieldIter)->label() << "\""; 165 t << "\"" << (*fieldIter)->label() << "\"";
161 first = false; 166 first = false;
162 } 167 }
163 t << "\n"; 168 t << "\n";
164 169
165 // Then all the addressee objects 170 // Then all the addressee objects
diff --git a/kaddressbook/xxport/kde2_xxport.cpp b/kaddressbook/xxport/kde2_xxport.cpp
index d5fc075..3fdb36d 100644
--- a/kaddressbook/xxport/kde2_xxport.cpp
+++ b/kaddressbook/xxport/kde2_xxport.cpp
@@ -1,116 +1,121 @@
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 32
33#include <kdebug.h> 33#include <kdebug.h>
34#include <kfiledialog.h> 34#include <kfiledialog.h>
35#ifndef KAB_EMBEDDED 35#ifndef KAB_EMBEDDED
36#include <kio/netaccess.h> 36#include <kio/netaccess.h>
37#endif //KAB_EMBEDDED 37#endif //KAB_EMBEDDED
38#include <klocale.h> 38#include <klocale.h>
39#include <kmessagebox.h> 39#include <kmessagebox.h>
40#include <kprocess.h> 40#include <kprocess.h>
41#include <kstandarddirs.h> 41#include <kstandarddirs.h>
42#include <ktempfile.h> 42#include <ktempfile.h>
43#include <kurl.h> 43#include <kurl.h>
44 44
45#include "xxportmanager.h" 45#include "xxportmanager.h"
46 46
47#include "kde2_xxport.h" 47#include "kde2_xxport.h"
48 48
49#ifndef KAB_EMBEDDED 49#ifndef KAB_EMBEDDED
50 50
51class KDE2XXPortFactory : public XXPortFactory 51class KDE2XXPortFactory : public XXPortFactory
52{ 52{
53 public: 53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 { 55 {
56 return new KDE2XXPort( ab, parent, name ); 56 return new KDE2XXPort( ab, parent, name );
57 } 57 }
58}; 58};
59 59
60#endif //KAB_EMBEDDED
61
60 62
61extern "C" 63extern "C"
62{ 64{
65#ifndef KAB_EMBEDDED
63 void *init_libkaddrbk_kde2_xxport() 66 void *init_libkaddrbk_kde2_xxport()
67#else //KAB_EMBEDDED
68 void *init_kaddrbk_kde2_xxport()
69#endif //KAB_EMBEDDED
64 { 70 {
65 return ( new KDE2XXPortFactory() ); 71 return ( new KDE2XXPortFactory() );
66 } 72 }
67} 73}
68#endif //KAB_EMBEDDED
69 74
70 75
71KDE2XXPort::KDE2XXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 76KDE2XXPort::KDE2XXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
72 : XXPortObject( ab, parent, name ) 77 : XXPortObject( ab, parent, name )
73{ 78{
74 createImportAction( i18n( "Import KDE 2 Addressbook..." ) ); 79 createImportAction( i18n( "Import KDE 2 Addressbook..." ) );
75} 80}
76 81
77KABC::AddresseeList KDE2XXPort::importContacts( const QString& ) const 82KABC::AddresseeList KDE2XXPort::importContacts( const QString& ) const
78{ 83{
79 QString fileName = locateLocal( "data", "kabc/std.vcf" ); 84 QString fileName = locateLocal( "data", "kabc/std.vcf" );
80 if ( !QFile::exists( fileName ) ) { 85 if ( !QFile::exists( fileName ) ) {
81 KMessageBox::sorry( parentWidget(), i18n( "<qt>Couldn't find a KDE 2 address book <b>%1</b>.</qt>" ).arg( fileName ) ); 86 KMessageBox::sorry( parentWidget(), i18n( "<qt>Couldn't find a KDE 2 address book <b>%1</b>.</qt>" ).arg( fileName ) );
82 return KABC::AddresseeList(); 87 return KABC::AddresseeList();
83 } 88 }
84 89
85#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
86 int result = KMessageBox::questionYesNoCancel( parentWidget(), 91 int result = KMessageBox::questionYesNoCancel( parentWidget(),
87 i18n( "Override previously imported entries?" ), 92 i18n( "Override previously imported entries?" ),
88 i18n( "Import KDE 2 Addressbook" ) ); 93 i18n( "Import KDE 2 Addressbook" ) );
89#else //KAB_EMBEDDED 94#else //KAB_EMBEDDED
90 int result = KMessageBox::warningYesNoCancel( parentWidget(), 95 int result = KMessageBox::warningYesNoCancel( parentWidget(),
91 i18n( "Override previously imported entries?" ), 96 i18n( "Override previously imported entries?" ),
92 i18n( "Import KDE 2 Addressbook" ) ); 97 i18n( "Import KDE 2 Addressbook" ) );
93#endif //KAB_EMBEDDED 98#endif //KAB_EMBEDDED
94 99
95 if ( !result ) return KABC::AddresseeList(); 100 if ( !result ) return KABC::AddresseeList();
96 101
97 KProcess proc; 102 KProcess proc;
98 103
99 if ( result == KMessageBox::Yes ) { 104 if ( result == KMessageBox::Yes ) {
100 proc << "kab2kabc"; 105 proc << "kab2kabc";
101 proc << "--override"; 106 proc << "--override";
102 } else if ( result == KMessageBox::No ) 107 } else if ( result == KMessageBox::No )
103 proc << "kab2kabc"; 108 proc << "kab2kabc";
104 else 109 else
105 kdDebug(5720) << "KAddressBook::importKDE2(): Unknow return value." << endl; 110 kdDebug(5720) << "KAddressBook::importKDE2(): Unknow return value." << endl;
106 111
107 proc.start( KProcess::Block ); 112 proc.start( KProcess::Block );
108 113
109 addressBook()->load(); 114 addressBook()->load();
110 115
111 return KABC::AddresseeList(); 116 return KABC::AddresseeList();
112} 117}
113 118
114#ifndef KAB_EMBEDDED 119#ifndef KAB_EMBEDDED
115#include "kde2_xxport.moc" 120#include "kde2_xxport.moc"
116#endif //KAB_EMBEDDED 121#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
index dd49a9c..c017f5b 100644
--- a/kaddressbook/xxport/vcard_xxport.cpp
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -1,164 +1,168 @@
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 <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 "xxportmanager.h" 45#include "xxportmanager.h"
46 46
47#include "vcard_xxport.h" 47#include "vcard_xxport.h"
48 48
49#ifndef KAB_EMBEDDED 49#ifndef KAB_EMBEDDED
50 50
51class VCardXXPortFactory : public XXPortFactory 51class VCardXXPortFactory : public XXPortFactory
52{ 52{
53 public: 53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 { 55 {
56 return new VCardXXPort( ab, parent, name ); 56 return new VCardXXPort( ab, parent, name );
57 } 57 }
58}; 58};
59#endif //KAB_EMBEDDED
59 60
60 61
61extern "C" 62extern "C"
62{ 63{
64#ifndef KAB_EMBEDDED
63 void *init_libkaddrbk_vcard_xxport() 65 void *init_libkaddrbk_vcard_xxport()
66#else //KAB_EMBEDDED
67 void *init_kaddrbk_vcard_xxport()
68#endif //KAB_EMBEDDED
64 { 69 {
65 return ( new VCardXXPortFactory() ); 70 return ( new VCardXXPortFactory() );
66 } 71 }
67} 72}
68#endif //KAB_EMBEDDED
69 73
70 74
71VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 75VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
72 : XXPortObject( ab, parent, name ) 76 : XXPortObject( ab, parent, name )
73{ 77{
74 createImportAction( i18n( "Import vCard..." ) ); 78 createImportAction( i18n( "Import vCard..." ) );
75 createExportAction( i18n( "Export vCard 2.1..." ), "v21" ); 79 createExportAction( i18n( "Export vCard 2.1..." ), "v21" );
76 createExportAction( i18n( "Export vCard 3.0..." ), "v30" ); 80 createExportAction( i18n( "Export vCard 3.0..." ), "v30" );
77} 81}
78 82
79bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 83bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
80{ 84{
81 QString name; 85 QString name;
82 86
83 if ( list.count() == 1 ) 87 if ( list.count() == 1 )
84 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; 88 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf";
85 else 89 else
86 name = "addressbook.vcf"; 90 name = "addressbook.vcf";
87 91
88#ifndef KAB_EMBEDDED 92#ifndef KAB_EMBEDDED
89 QString fileName = KFileDialog::getSaveFileName( name ); 93 QString fileName = KFileDialog::getSaveFileName( name );
90#else //KAB_EMBEDDED 94#else //KAB_EMBEDDED
91 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); 95 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
92#endif //KAB_EMBEDDED 96#endif //KAB_EMBEDDED
93 97
94 if ( fileName.isEmpty() ) 98 if ( fileName.isEmpty() )
95 return true; 99 return true;
96 100
97 QFile outFile( fileName ); 101 QFile outFile( fileName );
98 if ( !outFile.open( IO_WriteOnly ) ) { 102 if ( !outFile.open( IO_WriteOnly ) ) {
99 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 103 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
100 KMessageBox::error( parentWidget(), text.arg( fileName ) ); 104 KMessageBox::error( parentWidget(), text.arg( fileName ) );
101 return false; 105 return false;
102 } 106 }
103 107
104 QTextStream t( &outFile ); 108 QTextStream t( &outFile );
105 t.setEncoding( QTextStream::UnicodeUTF8 ); 109 t.setEncoding( QTextStream::UnicodeUTF8 );
106 110
107 KABC::Addressee::List::ConstIterator it; 111 KABC::Addressee::List::ConstIterator it;
108 for ( it = list.begin(); it != list.end(); ++it ) { 112 for ( it = list.begin(); it != list.end(); ++it ) {
109 KABC::VCardConverter converter; 113 KABC::VCardConverter converter;
110 QString vcard; 114 QString vcard;
111 115
112 KABC::VCardConverter::Version version; 116 KABC::VCardConverter::Version version;
113 if ( data == "v21" ) 117 if ( data == "v21" )
114 version = KABC::VCardConverter::v2_1; 118 version = KABC::VCardConverter::v2_1;
115 else 119 else
116 version = KABC::VCardConverter::v3_0; 120 version = KABC::VCardConverter::v3_0;
117 121
118 converter.addresseeToVCard( *it, vcard, version ); 122 converter.addresseeToVCard( *it, vcard, version );
119 t << vcard << "\r\n\r\n"; 123 t << vcard << "\r\n\r\n";
120 } 124 }
121 125
122 outFile.close(); 126 outFile.close();
123 127
124 return true; 128 return true;
125} 129}
126 130
127KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const 131KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
128{ 132{
129 QString fileName; 133 QString fileName;
130 KABC::AddresseeList addrList; 134 KABC::AddresseeList addrList;
131 KURL url; 135 KURL url;
132 136
133#ifndef KAB_EMBEDDED 137#ifndef KAB_EMBEDDED
134 if ( !XXPortManager::importData.isEmpty() ) 138 if ( !XXPortManager::importData.isEmpty() )
135 addrList = parseVCard( XXPortManager::importData ); 139 addrList = parseVCard( XXPortManager::importData );
136 else { 140 else {
137 if ( XXPortManager::importURL.isEmpty() ) 141 if ( XXPortManager::importURL.isEmpty() )
138 { 142 {
139 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); 143 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
140 } 144 }
141 else 145 else
142 url = XXPortManager::importURL; 146 url = XXPortManager::importURL;
143 147
144 if ( url.isEmpty() ) 148 if ( url.isEmpty() )
145 return addrList; 149 return addrList;
146 150
147 QString caption( i18n( "vCard Import Failed" ) ); 151 QString caption( i18n( "vCard Import Failed" ) );
148 if ( KIO::NetAccess::download( url, fileName ) ) { 152 if ( KIO::NetAccess::download( url, fileName ) ) {
149 QFile file( fileName ); 153 QFile file( fileName );
150 154
151 file.open( IO_ReadOnly ); 155 file.open( IO_ReadOnly );
152 QByteArray rawData = file.readAll(); 156 QByteArray rawData = file.readAll();
153 file.close(); 157 file.close();
154 158
155 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 159 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
156 addrList = parseVCard( data ); 160 addrList = parseVCard( data );
157 161
158 if ( !url.isLocalFile() ) 162 if ( !url.isLocalFile() )
159 KIO::NetAccess::removeTempFile( fileName ); 163 KIO::NetAccess::removeTempFile( fileName );
160 164
161 } else { 165 } else {
162 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ); 166 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
163 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption ); 167 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption );
164 } 168 }