-rw-r--r-- | kaddressbook/xxportmanager.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp index 4798ffe..2962951 100644 --- a/kaddressbook/xxportmanager.cpp +++ b/kaddressbook/xxportmanager.cpp | |||
@@ -1,251 +1,258 @@ | |||
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 | /* |
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 <qlayout.h> | 31 | #include <qlayout.h> |
32 | #include <qlist.h> | 32 | #include <qlist.h> |
33 | 33 | ||
34 | #include <kabc/addressbook.h> | 34 | #include <kabc/addressbook.h> |
35 | #include <kabc/resource.h> | 35 | #include <kabc/resource.h> |
36 | #include <kdebug.h> | 36 | #include <kdebug.h> |
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 |
44 | extern "C" | 44 | extern "C" |
45 | { | 45 | { |
46 | void* init_kaddrbk_csv_xxport(); | 46 | void* init_kaddrbk_csv_xxport(); |
47 | void* init_kaddrbk_kde2_xxport(); | 47 | void* init_kaddrbk_kde2_xxport(); |
48 | void* init_kaddrbk_vcard_xxport(); | 48 | void* init_kaddrbk_vcard_xxport(); |
49 | } | 49 | } |
50 | #endif //KAB_EMBEDDED | 50 | #endif //KAB_EMBEDDED |
51 | 51 | ||
52 | #include <libkdepim/addresseeview.h> | 52 | #include <libkdepim/addresseeview.h> |
53 | 53 | ||
54 | #include "kabcore.h" | 54 | #include "kabcore.h" |
55 | #include "undocmds.h" | 55 | #include "undocmds.h" |
56 | #include "xxportselectdialog.h" | 56 | #include "xxportselectdialog.h" |
57 | 57 | ||
58 | #include "xxportmanager.h" | 58 | #include "xxportmanager.h" |
59 | 59 | ||
60 | KURL XXPortManager::importURL = KURL(); | 60 | KURL XXPortManager::importURL = KURL(); |
61 | QString XXPortManager::importData = QString::null; | 61 | QString XXPortManager::importData = QString::null; |
62 | 62 | ||
63 | class PreviewDialog : public KDialogBase | 63 | class PreviewDialog : public KDialogBase |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | PreviewDialog( const KABC::Addressee &addr, | 66 | PreviewDialog( const KABC::Addressee &addr, |
67 | QWidget *parent, const char *name = 0 ); | 67 | QWidget *parent, const char *name = 0 ); |
68 | }; | 68 | }; |
69 | 69 | ||
70 | XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name ) | 70 | XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name ) |
71 | : QObject( parent, name ), mCore( core ), mShowPreview( false ) | 71 | : QObject( parent, name ), mCore( core ), mShowPreview( false ) |
72 | { | 72 | { |
73 | loadPlugins(); | 73 | loadPlugins(); |
74 | } | 74 | } |
75 | 75 | ||
76 | XXPortManager::~XXPortManager() | 76 | XXPortManager::~XXPortManager() |
77 | { | 77 | { |
78 | } | 78 | } |
79 | 79 | ||
80 | void XXPortManager::restoreSettings() | 80 | void XXPortManager::restoreSettings() |
81 | { | 81 | { |
82 | } | 82 | } |
83 | 83 | ||
84 | void XXPortManager::saveSettings() | 84 | void XXPortManager::saveSettings() |
85 | { | 85 | { |
86 | } | 86 | } |
87 | 87 | ||
88 | void XXPortManager::importVCard( const KURL &url ) | 88 | void XXPortManager::importVCard( const KURL &url ) |
89 | { | 89 | { |
90 | importVCard( url, false ); | 90 | importVCard( url, false ); |
91 | } | 91 | } |
92 | 92 | ||
93 | void XXPortManager::importVCard( const KURL &url, bool showPreview ) | 93 | void XXPortManager::importVCard( const KURL &url, bool showPreview ) |
94 | { | 94 | { |
95 | importURL = url; | 95 | importURL = url; |
96 | mShowPreview = showPreview; | 96 | mShowPreview = showPreview; |
97 | slotImport( "vcard", "<empty>" ); | 97 | slotImport( "vcard", "<empty>" ); |
98 | mShowPreview = false; | 98 | mShowPreview = false; |
99 | importURL = KURL(); | 99 | importURL = KURL(); |
100 | } | 100 | } |
101 | 101 | ||
102 | void XXPortManager::importVCard( const QString &vCard, bool showPreview ) | 102 | void XXPortManager::importVCard( const QString &vCard, bool showPreview ) |
103 | { | 103 | { |
104 | importData = vCard; | 104 | importData = vCard; |
105 | mShowPreview = showPreview; | 105 | mShowPreview = showPreview; |
106 | slotImport( "vcard", "<empty>" ); | 106 | slotImport( "vcard", "<empty>" ); |
107 | mShowPreview = false; | 107 | mShowPreview = false; |
108 | importData = ""; | 108 | importData = ""; |
109 | } | 109 | } |
110 | 110 | ||
111 | void XXPortManager::slotImport( const QString &identifier, const QString &data ) | 111 | void XXPortManager::slotImport( const QString &identifier, const QString &data ) |
112 | { | 112 | { |
113 | XXPortObject *obj = mXXPortObjects[ identifier ]; | 113 | XXPortObject *obj = mXXPortObjects[ identifier ]; |
114 | if ( !obj ) { | 114 | if ( !obj ) { |
115 | KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); | 115 | KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); |
116 | return; | 116 | return; |
117 | } | 117 | } |
118 | 118 | ||
119 | KABC::Resource *resource = mCore->requestResource( mCore ); | 119 | KABC::Resource *resource = mCore->requestResource( mCore ); |
120 | if ( !resource ) | 120 | if ( !resource ) |
121 | return; | 121 | return; |
122 | 122 | ||
123 | KABC::AddresseeList list = obj->importContacts( data ); | 123 | KABC::AddresseeList list = obj->importContacts( data ); |
124 | KABC::AddresseeList::Iterator it; | 124 | KABC::AddresseeList::Iterator it; |
125 | bool imported = false; | 125 | bool imported = false; |
126 | for ( it = list.begin(); it != list.end(); ++it ) { | 126 | for ( it = list.begin(); it != list.end(); ++it ) { |
127 | if ( mShowPreview ) { | 127 | if ( mShowPreview ) { |
128 | PreviewDialog dlg( *it, mCore ); | 128 | PreviewDialog dlg( *it, mCore ); |
129 | if ( !dlg.exec() ) | 129 | if ( !dlg.exec() ) |
130 | continue; | 130 | continue; |
131 | } | 131 | } |
132 | 132 | ||
133 | (*it).setResource( resource ); | 133 | (*it).setResource( resource ); |
134 | // We use a PwNewCommand so the user can undo it. | 134 | // We use a PwNewCommand so the user can undo it. |
135 | PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it ); | 135 | PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it ); |
136 | UndoStack::instance()->push( command ); | 136 | UndoStack::instance()->push( command ); |
137 | RedoStack::instance()->clear(); | 137 | RedoStack::instance()->clear(); |
138 | imported = true; | 138 | imported = true; |
139 | } | 139 | } |
140 | 140 | ||
141 | if ( imported ) { | 141 | if ( imported ) { |
142 | KMessageBox::information( mCore, i18n( "contacts successfully imported." ) ); | 142 | KMessageBox::information( mCore, i18n( "contacts successfully imported." ) ); |
143 | 143 | ||
144 | emit modified(); | 144 | emit modified(); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | void XXPortManager::slotExport( const QString &identifier, const QString &data ) | 148 | void XXPortManager::slotExport( const QString &identifier, const QString &data ) |
149 | { | 149 | { |
150 | XXPortObject *obj = mXXPortObjects[ identifier ]; | 150 | XXPortObject *obj = mXXPortObjects[ identifier ]; |
151 | if ( !obj ) { | 151 | if ( !obj ) { |
152 | KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); | 152 | KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); |
153 | return; | 153 | return; |
154 | } | 154 | } |
155 | 155 | ||
156 | KABC::AddresseeList addrList; | 156 | KABC::AddresseeList addrList; |
157 | XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore ); | 157 | XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore ); |
158 | if ( dlg.exec() ) | 158 | if ( dlg.exec() ) |
159 | addrList = dlg.contacts(); | 159 | addrList = dlg.contacts(); |
160 | else | 160 | else |
161 | return; | 161 | return; |
162 | 162 | ||
163 | if ( !obj->exportContacts( addrList, data ) ) | 163 | if ( !obj->exportContacts( addrList, data ) ) |
164 | KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); | 164 | KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); |
165 | else | 165 | else |
166 | KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); | 166 | KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); |
167 | } | 167 | } |
168 | 168 | ||
169 | void XXPortManager::loadPlugins() | 169 | void XXPortManager::loadPlugins() |
170 | { | 170 | { |
171 | mXXPortObjects.clear(); | 171 | mXXPortObjects.clear(); |
172 | 172 | ||
173 | #ifndef KAB_EMBEDDED | 173 | #ifndef KAB_EMBEDDED |
174 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); | 174 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); |
175 | KTrader::OfferList::ConstIterator it; | 175 | KTrader::OfferList::ConstIterator it; |
176 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 176 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
177 | if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) | 177 | if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) |
178 | continue; | 178 | continue; |
179 | 179 | ||
180 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); | 180 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); |
181 | if ( !factory ) { | 181 | if ( !factory ) { |
182 | kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; | 182 | kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; |
183 | continue; | 183 | continue; |
184 | } | 184 | } |
185 | 185 | ||
186 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); | 186 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); |
187 | 187 | ||
188 | if ( !xxportFactory ) { | 188 | if ( !xxportFactory ) { |
189 | kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; | 189 | kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; |
190 | continue; | 190 | continue; |
191 | } | 191 | } |
192 | 192 | ||
193 | #else //KAB_EMBEDDED | 193 | #else //KAB_EMBEDDED |
194 | QList<XXPortFactory> factorylist; | 194 | QList<XXPortFactory> factorylist; |
195 | factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_csv_xxport())); | 195 | factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_csv_xxport())); |
196 | factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_kde2_xxport())); | 196 | factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_kde2_xxport())); |
197 | factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_vcard_xxport())); | 197 | factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_vcard_xxport())); |
198 | 198 | ||
199 | //add the opie import library dynamically | 199 | //add the opie import library dynamically |
200 | KLibFactory *factory = KLibLoader::self()->factory( "microkaddrbk_opie_xxport" ); | 200 | KLibFactory *factory = KLibLoader::self()->factory( "microkaddrbk_opie_xxport" ); |
201 | if ( factory ) { | 201 | if ( factory ) { |
202 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); | 202 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); |
203 | factorylist.append(xxportFactory); | 203 | factorylist.append(xxportFactory); |
204 | } | 204 | } |
205 | 205 | ||
206 | //add the qtopia import library dynamically | 206 | //add the qtopia import library dynamically |
207 | factory = KLibLoader::self()->factory( "microkaddrbk_qtopia_xxport" ); | 207 | factory = KLibLoader::self()->factory( "microkaddrbk_qtopia_xxport" ); |
208 | if ( factory ) { | 208 | if ( factory ) { |
209 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); | 209 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); |
210 | factorylist.append(xxportFactory); | 210 | factorylist.append(xxportFactory); |
211 | } | 211 | } |
212 | 212 | ||
213 | QListIterator<XXPortFactory> it(factorylist); | 213 | //add the sharp import library dynamically |
214 | factory = KLibLoader::self()->factory( "microkaddrbk_sharpdtm_xxport" ); | ||
215 | if ( factory ) { | ||
216 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); | ||
217 | factorylist.append(xxportFactory); | ||
218 | } | ||
219 | |||
220 | QListIterator<XXPortFactory> it(factorylist); | ||
214 | for ( ; it.current(); ++it ) | 221 | for ( ; it.current(); ++it ) |
215 | { | 222 | { |
216 | XXPortFactory *xxportFactory = it.current(); | 223 | XXPortFactory *xxportFactory = it.current(); |
217 | #endif //KAB_EMBEDDED | 224 | #endif //KAB_EMBEDDED |
218 | 225 | ||
219 | XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); | 226 | XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); |
220 | if ( obj ) { | 227 | if ( obj ) { |
221 | mCore->addGUIClient( obj ); | 228 | mCore->addGUIClient( obj ); |
222 | mXXPortObjects.insert( obj->identifier(), obj ); | 229 | mXXPortObjects.insert( obj->identifier(), obj ); |
223 | connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), | 230 | connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), |
224 | this, SLOT( slotExport( const QString&, const QString& ) ) ); | 231 | this, SLOT( slotExport( const QString&, const QString& ) ) ); |
225 | connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), | 232 | connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), |
226 | this, SLOT( slotImport( const QString&, const QString& ) ) ); | 233 | this, SLOT( slotImport( const QString&, const QString& ) ) ); |
227 | } | 234 | } |
228 | } | 235 | } |
229 | } | 236 | } |
230 | 237 | ||
231 | 238 | ||
232 | PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, | 239 | PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, |
233 | const char *name ) | 240 | const char *name ) |
234 | : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent, | 241 | : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent, |
235 | name, true, true ) | 242 | name, true, true ) |
236 | { | 243 | { |
237 | QWidget *page = plainPage(); | 244 | QWidget *page = plainPage(); |
238 | QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() ); | 245 | QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() ); |
239 | 246 | ||
240 | KPIM::AddresseeView *view = new KPIM::AddresseeView( page ); | 247 | KPIM::AddresseeView *view = new KPIM::AddresseeView( page ); |
241 | view->setAddressee( addr ); | 248 | view->setAddressee( addr ); |
242 | 249 | ||
243 | layout->addWidget( view ); | 250 | layout->addWidget( view ); |
244 | 251 | ||
245 | resize( 400, 300 ); | 252 | resize( 400, 300 ); |
246 | } | 253 | } |
247 | 254 | ||
248 | #ifndef KAB_EMBEDDED | 255 | #ifndef KAB_EMBEDDED |
249 | #include "xxportmanager.moc" | 256 | #include "xxportmanager.moc" |
250 | #endif //KAB_EMBEDDED | 257 | #endif //KAB_EMBEDDED |
251 | 258 | ||