summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorzautrix <zautrix>2004-10-22 10:07:21 (UTC)
committer zautrix <zautrix>2004-10-22 10:07:21 (UTC)
commita97485bb2ff1b4f274d9cf0fba9e2f122297deed (patch) (unidiff)
treee28b897185c7ee09d6fa22efbb44e6886905a619 /kaddressbook
parente61ce30fc3f2376d8e9caff421495496344a8359 (diff)
downloadkdepimpi-a97485bb2ff1b4f274d9cf0fba9e2f122297deed.zip
kdepimpi-a97485bb2ff1b4f274d9cf0fba9e2f122297deed.tar.gz
kdepimpi-a97485bb2ff1b4f274d9cf0fba9e2f122297deed.tar.bz2
fixed vcard export bug
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp1
-rw-r--r--kaddressbook/xxportmanager.cpp1
2 files changed, 0 insertions, 2 deletions
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
index 3079d42..acf6419 100644
--- a/kaddressbook/xxport/vcard_xxport.cpp
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -1,252 +1,251 @@
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_microkaddrbk_vcard_xxport() 68 void *init_microkaddrbk_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 false; 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 version = KABC::VCardConverter::v2_1;
125 converter.addresseeToVCard( *it, vcard, version ); 124 converter.addresseeToVCard( *it, vcard, version );
126 t << vcard << "\r\n\r\n"; 125 t << vcard << "\r\n\r\n";
127 } 126 }
128 127
129 outFile.close(); 128 outFile.close();
130 129
131 return true; 130 return true;
132} 131}
133 132
134KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const 133KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
135{ 134{
136 QString fileName; 135 QString fileName;
137 KABC::AddresseeList addrList; 136 KABC::AddresseeList addrList;
138 KURL url; 137 KURL url;
139 138
140#ifndef KAB_EMBEDDED 139#ifndef KAB_EMBEDDED
141 if ( !XXPortManager::importData.isEmpty() ) 140 if ( !XXPortManager::importData.isEmpty() )
142 addrList = parseVCard( XXPortManager::importData ); 141 addrList = parseVCard( XXPortManager::importData );
143 else { 142 else {
144 if ( XXPortManager::importURL.isEmpty() ) 143 if ( XXPortManager::importURL.isEmpty() )
145 { 144 {
146 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); 145 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
147 } 146 }
148 else 147 else
149 url = XXPortManager::importURL; 148 url = XXPortManager::importURL;
150 149
151 if ( url.isEmpty() ) 150 if ( url.isEmpty() )
152 return addrList; 151 return addrList;
153 152
154 QString caption( i18n( "vCard Import Failed" ) ); 153 QString caption( i18n( "vCard Import Failed" ) );
155 if ( KIO::NetAccess::download( url, fileName ) ) { 154 if ( KIO::NetAccess::download( url, fileName ) ) {
156 QFile file( fileName ); 155 QFile file( fileName );
157 156
158 file.open( IO_ReadOnly ); 157 file.open( IO_ReadOnly );
159 QByteArray rawData = file.readAll(); 158 QByteArray rawData = file.readAll();
160 file.close(); 159 file.close();
161 160
162 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 161 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
163 addrList = parseVCard( data ); 162 addrList = parseVCard( data );
164 163
165 if ( !url.isLocalFile() ) 164 if ( !url.isLocalFile() )
166 KIO::NetAccess::removeTempFile( fileName ); 165 KIO::NetAccess::removeTempFile( fileName );
167 166
168 } else { 167 } else {
169 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ); 168 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
170 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption ); 169 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption );
171 } 170 }
172 171
173 } 172 }
174 173
175 174
176#else //KAB_EMBEDDED 175#else //KAB_EMBEDDED
177 176
178 177
179 if ( !XXPortManager::importData.isEmpty() ) 178 if ( !XXPortManager::importData.isEmpty() )
180 addrList = parseVCard( XXPortManager::importData ); 179 addrList = parseVCard( XXPortManager::importData );
181 else { 180 else {
182 if ( XXPortManager::importURL.isEmpty() ) 181 if ( XXPortManager::importURL.isEmpty() )
183 { 182 {
184 fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); 183 fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
185 if ( fileName.isEmpty() ) 184 if ( fileName.isEmpty() )
186 return addrList; 185 return addrList;
187 186
188 } 187 }
189 else 188 else
190 { 189 {
191//US url = XXPortManager::importURL; 190//US url = XXPortManager::importURL;
192 qDebug("VCardXXPort::importContacts Urls at the moment not supported"); 191 qDebug("VCardXXPort::importContacts Urls at the moment not supported");
193 if ( url.isEmpty() ) 192 if ( url.isEmpty() )
194 return addrList; 193 return addrList;
195 194
196 } 195 }
197 196
198 197
199 QFile file( fileName ); 198 QFile file( fileName );
200 199
201 file.open( IO_ReadOnly ); 200 file.open( IO_ReadOnly );
202 QByteArray rawData = file.readAll(); 201 QByteArray rawData = file.readAll();
203 file.close(); 202 file.close();
204 203
205 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 204 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
206 addrList = parseVCard( data ); 205 addrList = parseVCard( data );
207 206
208 } 207 }
209#endif //KAB_EMBEDDED 208#endif //KAB_EMBEDDED
210 209
211 return addrList; 210 return addrList;
212} 211}
213 212
214KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const 213KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const
215{ 214{
216 215
217 KABC::VCardTool tool; 216 KABC::VCardTool tool;
218 KABC::AddresseeList addrList; 217 KABC::AddresseeList addrList;
219 addrList = tool.parseVCards( data ); 218 addrList = tool.parseVCards( data );
220 // 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
221 /* 220 /*
222 uint numVCards = data.contains( "BEGIN:VCARD", false ); 221 uint numVCards = data.contains( "BEGIN:VCARD", false );
223 QStringList dataList = QStringList::split( "\r\n\r\n", data ); 222 QStringList dataList = QStringList::split( "\r\n\r\n", data );
224 223
225 for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) { 224 for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) {
226 KABC::Addressee addr; 225 KABC::Addressee addr;
227 bool ok = false; 226 bool ok = false;
228 227
229 if ( dataList[ i ].contains( "VERSION:3.0" ) ) 228 if ( dataList[ i ].contains( "VERSION:3.0" ) )
230 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 ); 229 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 );
231 else if ( dataList[ i ].contains( "VERSION:2.1" ) ) 230 else if ( dataList[ i ].contains( "VERSION:2.1" ) )
232 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 ); 231 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 );
233 else { 232 else {
234 KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) ); 233 KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) );
235 continue; 234 continue;
236 } 235 }
237 236
238 if ( !addr.isEmpty() && ok ) 237 if ( !addr.isEmpty() && ok )
239 addrList.append( addr ); 238 addrList.append( addr );
240 else { 239 else {
241 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. "
242 "Please check the file and try again." ); 241 "Please check the file and try again." );
243 KMessageBox::sorry( parentWidget(), text ); 242 KMessageBox::sorry( parentWidget(), text );
244 } 243 }
245 } 244 }
246 */ 245 */
247 if ( addrList.isEmpty() ) { 246 if ( addrList.isEmpty() ) {
248 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" );
249 KMessageBox::sorry( parentWidget(), text ); 248 KMessageBox::sorry( parentWidget(), text );
250 } 249 }
251 return addrList; 250 return addrList;
252} 251}
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp
index 810c3e2..1f0c9ea 100644
--- a/kaddressbook/xxportmanager.cpp
+++ b/kaddressbook/xxportmanager.cpp
@@ -37,207 +37,206 @@ $Id$
37#include <kdialogbase.h> 37#include <kdialogbase.h>
38#include <klocale.h> 38#include <klocale.h>
39#include <kmessagebox.h> 39#include <kmessagebox.h>
40 40
41#ifndef KAB_EMBEDDED 41#ifndef KAB_EMBEDDED
42#include <ktrader.h> 42#include <ktrader.h>
43#else //KAB_EMBEDDED 43#else //KAB_EMBEDDED
44extern "C" 44extern "C"
45{ 45{
46 void* init_microkaddrbk_csv_xxport(); 46 void* init_microkaddrbk_csv_xxport();
47 void* init_microkaddrbk_kde2_xxport(); 47 void* init_microkaddrbk_kde2_xxport();
48 void* init_microkaddrbk_vcard_xxport(); 48 void* init_microkaddrbk_vcard_xxport();
49 void* init_microkaddrbk_opie_xxport(); 49 void* init_microkaddrbk_opie_xxport();
50 void* init_microkaddrbk_qtopia_xxport(); 50 void* init_microkaddrbk_qtopia_xxport();
51 void* init_microkaddrbk_sharpdtm_xxport(); 51 void* init_microkaddrbk_sharpdtm_xxport();
52} 52}
53#endif //KAB_EMBEDDED 53#endif //KAB_EMBEDDED
54 54
55#include <addresseeview.h> 55#include <addresseeview.h>
56 56
57#include "kabcore.h" 57#include "kabcore.h"
58#include "undocmds.h" 58#include "undocmds.h"
59#include "xxportselectdialog.h" 59#include "xxportselectdialog.h"
60 60
61#include "xxportmanager.h" 61#include "xxportmanager.h"
62 62
63KURL XXPortManager::importURL = KURL(); 63KURL XXPortManager::importURL = KURL();
64QString XXPortManager::importData = QString::null; 64QString XXPortManager::importData = QString::null;
65 65
66class PreviewDialog : public KDialogBase 66class PreviewDialog : public KDialogBase
67{ 67{
68 public: 68 public:
69 PreviewDialog( const KABC::Addressee &addr, 69 PreviewDialog( const KABC::Addressee &addr,
70 QWidget *parent, const char *name = 0 ); 70 QWidget *parent, const char *name = 0 );
71}; 71};
72 72
73XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name ) 73XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name )
74 : QObject( parent, name ), mCore( core ), mShowPreview( false ) 74 : QObject( parent, name ), mCore( core ), mShowPreview( false )
75{ 75{
76 loadPlugins(); 76 loadPlugins();
77} 77}
78 78
79XXPortManager::~XXPortManager() 79XXPortManager::~XXPortManager()
80{ 80{
81} 81}
82 82
83void XXPortManager::restoreSettings() 83void XXPortManager::restoreSettings()
84{ 84{
85} 85}
86 86
87void XXPortManager::saveSettings() 87void XXPortManager::saveSettings()
88{ 88{
89} 89}
90 90
91void XXPortManager::importVCard( const KURL &url ) 91void XXPortManager::importVCard( const KURL &url )
92{ 92{
93 importVCard( url, false ); 93 importVCard( url, false );
94} 94}
95 95
96void XXPortManager::importVCard( const KURL &url, bool showPreview ) 96void XXPortManager::importVCard( const KURL &url, bool showPreview )
97{ 97{
98 importURL = url; 98 importURL = url;
99 mShowPreview = showPreview; 99 mShowPreview = showPreview;
100 slotImport( "vcard", "<empty>" ); 100 slotImport( "vcard", "<empty>" );
101 mShowPreview = false; 101 mShowPreview = false;
102 importURL = KURL(); 102 importURL = KURL();
103} 103}
104 104
105void XXPortManager::importVCard( const QString &vCard, bool showPreview ) 105void XXPortManager::importVCard( const QString &vCard, bool showPreview )
106{ 106{
107 importData = vCard; 107 importData = vCard;
108 mShowPreview = showPreview; 108 mShowPreview = showPreview;
109 slotImport( "vcard", "<empty>" ); 109 slotImport( "vcard", "<empty>" );
110 mShowPreview = false; 110 mShowPreview = false;
111 importData = ""; 111 importData = "";
112} 112}
113 113
114void XXPortManager::slotImport( const QString &identifier, const QString &data ) 114void XXPortManager::slotImport( const QString &identifier, const QString &data )
115{ 115{
116 XXPortObject *obj = mXXPortObjects[ identifier ]; 116 XXPortObject *obj = mXXPortObjects[ identifier ];
117 if ( !obj ) { 117 if ( !obj ) {
118 KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); 118 KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
119 return; 119 return;
120 } 120 }
121 121
122 KABC::Resource *resource = mCore->requestResource( mCore ); 122 KABC::Resource *resource = mCore->requestResource( mCore );
123 if ( !resource ) 123 if ( !resource )
124 return; 124 return;
125 125
126 KABC::AddresseeList list = obj->importContacts( data ); 126 KABC::AddresseeList list = obj->importContacts( data );
127 KABC::AddresseeList::Iterator it; 127 KABC::AddresseeList::Iterator it;
128 bool imported = false; 128 bool imported = false;
129 for ( it = list.begin(); it != list.end(); ++it ) { 129 for ( it = list.begin(); it != list.end(); ++it ) {
130 if ( mShowPreview ) { 130 if ( mShowPreview ) {
131 PreviewDialog dlg( *it, mCore ); 131 PreviewDialog dlg( *it, mCore );
132 if ( !dlg.exec() ) 132 if ( !dlg.exec() )
133 continue; 133 continue;
134 } 134 }
135 135
136 (*it).setResource( resource ); 136 (*it).setResource( resource );
137 // We use a PwNewCommand so the user can undo it. 137 // We use a PwNewCommand so the user can undo it.
138 PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it ); 138 PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it );
139 UndoStack::instance()->push( command ); 139 UndoStack::instance()->push( command );
140 RedoStack::instance()->clear(); 140 RedoStack::instance()->clear();
141 imported = true; 141 imported = true;
142 } 142 }
143 143
144 if ( imported ) { 144 if ( imported ) {
145 KMessageBox::information( mCore, i18n( "contacts successfully imported." ) ); 145 KMessageBox::information( mCore, i18n( "contacts successfully imported." ) );
146 146
147 emit modified(); 147 emit modified();
148 } 148 }
149} 149}
150 150
151void XXPortManager::slotExport( const QString &identifier, const QString &data ) 151void XXPortManager::slotExport( const QString &identifier, const QString &data )
152{ 152{
153 XXPortObject *obj = mXXPortObjects[ identifier ]; 153 XXPortObject *obj = mXXPortObjects[ identifier ];
154 if ( !obj ) { 154 if ( !obj ) {
155 KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); 155 KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
156 return; 156 return;
157 } 157 }
158 158
159 KABC::AddresseeList addrList; 159 KABC::AddresseeList addrList;
160 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore ); 160 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore );
161 if ( dlg.exec() ) 161 if ( dlg.exec() )
162 addrList = dlg.contacts(); 162 addrList = dlg.contacts();
163 else 163 else
164 return; 164 return;
165
166 if ( !obj->exportContacts( addrList, data ) ) 165 if ( !obj->exportContacts( addrList, data ) )
167 KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); 166 KMessageBox::error( mCore, i18n( "Unable to export contacts." ) );
168 else 167 else
169 KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); 168 KMessageBox::information( mCore, i18n( "contacts successfully exported." ) );
170} 169}
171 170
172void XXPortManager::loadPlugins() 171void XXPortManager::loadPlugins()
173{ 172{
174 mXXPortObjects.clear(); 173 mXXPortObjects.clear();
175 174
176#ifndef KAB_EMBEDDED 175#ifndef KAB_EMBEDDED
177 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); 176 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" );
178 KTrader::OfferList::ConstIterator it; 177 KTrader::OfferList::ConstIterator it;
179 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 178 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
180 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) 179 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) )
181 continue; 180 continue;
182 181
183 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 182 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
184 if ( !factory ) { 183 if ( !factory ) {
185 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; 184 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl;
186 continue; 185 continue;
187 } 186 }
188 187
189 XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); 188 XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory );
190 189
191 if ( !xxportFactory ) { 190 if ( !xxportFactory ) {
192 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; 191 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl;
193 continue; 192 continue;
194 } 193 }
195 194
196#else //KAB_EMBEDDED 195#else //KAB_EMBEDDED
197 QList<XXPortFactory> factorylist; 196 QList<XXPortFactory> factorylist;
198 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_csv_xxport())); 197 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_csv_xxport()));
199 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_kde2_xxport())); 198 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_kde2_xxport()));
200 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_vcard_xxport())); 199 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_vcard_xxport()));
201 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_opie_xxport())); 200 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_opie_xxport()));
202 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_qtopia_xxport())); 201 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_qtopia_xxport()));
203 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_sharpdtm_xxport())); 202 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_sharpdtm_xxport()));
204 203
205 QListIterator<XXPortFactory> it(factorylist); 204 QListIterator<XXPortFactory> it(factorylist);
206 for ( ; it.current(); ++it ) 205 for ( ; it.current(); ++it )
207 { 206 {
208 XXPortFactory *xxportFactory = it.current(); 207 XXPortFactory *xxportFactory = it.current();
209#endif //KAB_EMBEDDED 208#endif //KAB_EMBEDDED
210 209
211 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); 210 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
212 if ( obj ) { 211 if ( obj ) {
213 mCore->addGUIClient( obj ); 212 mCore->addGUIClient( obj );
214 mXXPortObjects.insert( obj->identifier(), obj ); 213 mXXPortObjects.insert( obj->identifier(), obj );
215 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), 214 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
216 this, SLOT( slotExport( const QString&, const QString& ) ) ); 215 this, SLOT( slotExport( const QString&, const QString& ) ) );
217 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), 216 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
218 this, SLOT( slotImport( const QString&, const QString& ) ) ); 217 this, SLOT( slotImport( const QString&, const QString& ) ) );
219 } 218 }
220 } 219 }
221} 220}
222 221
223 222
224PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, 223PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent,
225 const char *name ) 224 const char *name )
226 : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent, 225 : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent,
227 name, true, true ) 226 name, true, true )
228{ 227{
229 QWidget *page = plainPage(); 228 QWidget *page = plainPage();
230 QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() ); 229 QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() );
231 230
232 KPIM::AddresseeView *view = new KPIM::AddresseeView( page ); 231 KPIM::AddresseeView *view = new KPIM::AddresseeView( page );
233 view->setAddressee( addr ); 232 view->setAddressee( addr );
234 233
235 layout->addWidget( view ); 234 layout->addWidget( view );
236 235
237 resize( 400, 300 ); 236 resize( 400, 300 );
238} 237}
239 238
240#ifndef KAB_EMBEDDED 239#ifndef KAB_EMBEDDED
241#include "xxportmanager.moc" 240#include "xxportmanager.moc"
242#endif //KAB_EMBEDDED 241#endif //KAB_EMBEDDED
243 242