author | zautrix <zautrix> | 2004-10-22 10:07:21 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-22 10:07:21 (UTC) |
commit | a97485bb2ff1b4f274d9cf0fba9e2f122297deed (patch) (unidiff) | |
tree | e28b897185c7ee09d6fa22efbb44e6886905a619 /kaddressbook | |
parent | e61ce30fc3f2376d8e9caff421495496344a8359 (diff) | |
download | kdepimpi-a97485bb2ff1b4f274d9cf0fba9e2f122297deed.zip kdepimpi-a97485bb2ff1b4f274d9cf0fba9e2f122297deed.tar.gz kdepimpi-a97485bb2ff1b4f274d9cf0fba9e2f122297deed.tar.bz2 |
fixed vcard export bug
-rw-r--r-- | kaddressbook/xxport/vcard_xxport.cpp | 1 | ||||
-rw-r--r-- | kaddressbook/xxportmanager.cpp | 1 |
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 | |||
@@ -60,129 +60,128 @@ class VCardXXPortFactory : public XXPortFactory | |||
60 | #endif //KAB_EMBEDDED | 60 | #endif //KAB_EMBEDDED |
61 | 61 | ||
62 | 62 | ||
63 | extern "C" | 63 | extern "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 | ||
76 | VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 76 | VCardXXPort::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 | ||
85 | bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | 85 | bool 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 | ||
134 | KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const | 133 | KABC::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 | } |
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp index 810c3e2..1f0c9ea 100644 --- a/kaddressbook/xxportmanager.cpp +++ b/kaddressbook/xxportmanager.cpp | |||
@@ -101,129 +101,128 @@ void XXPortManager::importVCard( const KURL &url, bool showPreview ) | |||
101 | mShowPreview = false; | 101 | mShowPreview = false; |
102 | importURL = KURL(); | 102 | importURL = KURL(); |
103 | } | 103 | } |
104 | 104 | ||
105 | void XXPortManager::importVCard( const QString &vCard, bool showPreview ) | 105 | void 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 | ||
114 | void XXPortManager::slotImport( const QString &identifier, const QString &data ) | 114 | void 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 | ||
151 | void XXPortManager::slotExport( const QString &identifier, const QString &data ) | 151 | void 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 | ||
172 | void XXPortManager::loadPlugins() | 171 | void 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 | ||
224 | PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, | 223 | PreviewDialog::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(); |