-rw-r--r-- | kaddressbook/xxportmanager.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp index 1f0c9ea..8d40ffe 100644 --- a/kaddressbook/xxportmanager.cpp +++ b/kaddressbook/xxportmanager.cpp | |||
@@ -1,242 +1,242 @@ | |||
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_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 | ||
63 | KURL XXPortManager::importURL = KURL(); | 63 | KURL XXPortManager::importURL = KURL(); |
64 | QString XXPortManager::importData = QString::null; | 64 | QString XXPortManager::importData = QString::null; |
65 | 65 | ||
66 | class PreviewDialog : public KDialogBase | 66 | class 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 | ||
73 | XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name ) | 73 | XXPortManager::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 | ||
79 | XXPortManager::~XXPortManager() | 79 | XXPortManager::~XXPortManager() |
80 | { | 80 | { |
81 | } | 81 | } |
82 | 82 | ||
83 | void XXPortManager::restoreSettings() | 83 | void XXPortManager::restoreSettings() |
84 | { | 84 | { |
85 | } | 85 | } |
86 | 86 | ||
87 | void XXPortManager::saveSettings() | 87 | void XXPortManager::saveSettings() |
88 | { | 88 | { |
89 | } | 89 | } |
90 | 90 | ||
91 | void XXPortManager::importVCard( const KURL &url ) | 91 | void XXPortManager::importVCard( const KURL &url ) |
92 | { | 92 | { |
93 | importVCard( url, false ); | 93 | importVCard( url, false ); |
94 | } | 94 | } |
95 | 95 | ||
96 | void XXPortManager::importVCard( const KURL &url, bool showPreview ) | 96 | void 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 | ||
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 | if ( !obj->exportContacts( addrList, data ) ) | 165 | if ( !obj->exportContacts( addrList, data ) ) |
166 | KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); | 166 | KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); |
167 | else | 167 | else |
168 | KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); | 168 | KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); |
169 | } | 169 | } |
170 | 170 | ||
171 | void XXPortManager::loadPlugins() | 171 | void XXPortManager::loadPlugins() |
172 | { | 172 | { |
173 | mXXPortObjects.clear(); | 173 | mXXPortObjects.clear(); |
174 | 174 | ||
175 | #ifndef KAB_EMBEDDED | 175 | #ifndef KAB_EMBEDDED |
176 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); | 176 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); |
177 | KTrader::OfferList::ConstIterator it; | 177 | KTrader::OfferList::ConstIterator it; |
178 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 178 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
179 | if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) | 179 | if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) |
180 | continue; | 180 | continue; |
181 | 181 | ||
182 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); | 182 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); |
183 | if ( !factory ) { | 183 | if ( !factory ) { |
184 | kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; | 184 | kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; |
185 | continue; | 185 | continue; |
186 | } | 186 | } |
187 | 187 | ||
188 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); | 188 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); |
189 | 189 | ||
190 | if ( !xxportFactory ) { | 190 | if ( !xxportFactory ) { |
191 | kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; | 191 | kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; |
192 | continue; | 192 | continue; |
193 | } | 193 | } |
194 | 194 | ||
195 | #else //KAB_EMBEDDED | 195 | #else //KAB_EMBEDDED |
196 | QList<XXPortFactory> factorylist; | 196 | QList<XXPortFactory> factorylist; |
197 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_csv_xxport())); | 197 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_csv_xxport())); |
198 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_kde2_xxport())); | 198 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_kde2_xxport())); |
199 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_vcard_xxport())); | 199 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_vcard_xxport())); |
200 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_opie_xxport())); | 200 | //US factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_opie_xxport())); |
201 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_qtopia_xxport())); | 201 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_qtopia_xxport())); |
202 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_sharpdtm_xxport())); | 202 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_sharpdtm_xxport())); |
203 | 203 | ||
204 | QListIterator<XXPortFactory> it(factorylist); | 204 | QListIterator<XXPortFactory> it(factorylist); |
205 | for ( ; it.current(); ++it ) | 205 | for ( ; it.current(); ++it ) |
206 | { | 206 | { |
207 | XXPortFactory *xxportFactory = it.current(); | 207 | XXPortFactory *xxportFactory = it.current(); |
208 | #endif //KAB_EMBEDDED | 208 | #endif //KAB_EMBEDDED |
209 | 209 | ||
210 | XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); | 210 | XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); |
211 | if ( obj ) { | 211 | if ( obj ) { |
212 | mCore->addGUIClient( obj ); | 212 | mCore->addGUIClient( obj ); |
213 | mXXPortObjects.insert( obj->identifier(), obj ); | 213 | mXXPortObjects.insert( obj->identifier(), obj ); |
214 | connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), | 214 | connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), |
215 | this, SLOT( slotExport( const QString&, const QString& ) ) ); | 215 | this, SLOT( slotExport( const QString&, const QString& ) ) ); |
216 | connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), | 216 | connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), |
217 | this, SLOT( slotImport( const QString&, const QString& ) ) ); | 217 | this, SLOT( slotImport( const QString&, const QString& ) ) ); |
218 | } | 218 | } |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, | 223 | PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, |
224 | const char *name ) | 224 | const char *name ) |
225 | : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent, | 225 | : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent, |
226 | name, true, true ) | 226 | name, true, true ) |
227 | { | 227 | { |
228 | QWidget *page = plainPage(); | 228 | QWidget *page = plainPage(); |
229 | QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() ); | 229 | QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() ); |
230 | 230 | ||
231 | KPIM::AddresseeView *view = new KPIM::AddresseeView( page ); | 231 | KPIM::AddresseeView *view = new KPIM::AddresseeView( page ); |
232 | view->setAddressee( addr ); | 232 | view->setAddressee( addr ); |
233 | 233 | ||
234 | layout->addWidget( view ); | 234 | layout->addWidget( view ); |
235 | 235 | ||
236 | resize( 400, 300 ); | 236 | resize( 400, 300 ); |
237 | } | 237 | } |
238 | 238 | ||
239 | #ifndef KAB_EMBEDDED | 239 | #ifndef KAB_EMBEDDED |
240 | #include "xxportmanager.moc" | 240 | #include "xxportmanager.moc" |
241 | #endif //KAB_EMBEDDED | 241 | #endif //KAB_EMBEDDED |
242 | 242 | ||