Diffstat (limited to 'kaddressbook/xxportmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/xxportmanager.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp index 405f7ec..95b240d 100644 --- a/kaddressbook/xxportmanager.cpp +++ b/kaddressbook/xxportmanager.cpp | |||
@@ -1,270 +1,269 @@ | |||
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 | //Added by qt3to4: | ||
34 | #include <Q3VBoxLayout> | ||
33 | 35 | ||
34 | #include <kabc/addressbook.h> | 36 | #include <kabc/addressbook.h> |
35 | #include <kabc/resource.h> | 37 | #include <kabc/resource.h> |
36 | #include <kdebug.h> | 38 | #include <kdebug.h> |
37 | #include <kdialogbase.h> | 39 | #include <kdialogbase.h> |
38 | #include <klocale.h> | 40 | #include <klocale.h> |
39 | #include <kmessagebox.h> | 41 | #include <kmessagebox.h> |
40 | 42 | ||
41 | #ifndef KAB_EMBEDDED | 43 | #ifndef KAB_EMBEDDED |
42 | #include <ktrader.h> | 44 | #include <ktrader.h> |
43 | #else //KAB_EMBEDDED | 45 | #else //KAB_EMBEDDED |
44 | extern "C" | 46 | extern "C" |
45 | { | 47 | { |
46 | void* init_microkaddrbk_csv_xxport(); | 48 | void* init_microkaddrbk_csv_xxport(); |
47 | void* init_microkaddrbk_kde2_xxport(); | 49 | void* init_microkaddrbk_kde2_xxport(); |
48 | void* init_microkaddrbk_vcard_xxport(); | 50 | void* init_microkaddrbk_vcard_xxport(); |
49 | // void* init_microkaddrbk_opie_xxport(); | 51 | // void* init_microkaddrbk_opie_xxport(); |
50 | void* init_microkaddrbk_qtopia_xxport(); | 52 | void* init_microkaddrbk_qtopia_xxport(); |
51 | void* init_microkaddrbk_sharpdtm_xxport(); | 53 | void* init_microkaddrbk_sharpdtm_xxport(); |
52 | } | 54 | } |
53 | #endif //KAB_EMBEDDED | 55 | #endif //KAB_EMBEDDED |
54 | 56 | ||
55 | #include <addresseeview.h> | 57 | #include <addresseeview.h> |
56 | 58 | ||
57 | #include "kabcore.h" | 59 | #include "kabcore.h" |
58 | #include "undocmds.h" | 60 | #include "undocmds.h" |
59 | #include "xxportselectdialog.h" | 61 | #include "xxportselectdialog.h" |
60 | 62 | ||
61 | #include "xxportmanager.h" | 63 | #include "xxportmanager.h" |
62 | #include "nameeditdialog.h" | 64 | #include "nameeditdialog.h" |
63 | 65 | ||
64 | KURL XXPortManager::importURL = KURL(); | 66 | KURL XXPortManager::importURL = KURL(); |
65 | QString XXPortManager::importData = QString::null; | 67 | QString XXPortManager::importData = QString::null; |
66 | 68 | ||
67 | class PreviewDialog : public KDialogBase | 69 | class PreviewDialog : public KDialogBase |
68 | { | 70 | { |
69 | public: | 71 | public: |
70 | PreviewDialog( const KABC::Addressee &addr, | 72 | PreviewDialog( const KABC::Addressee &addr, |
71 | QWidget *parent, const char *name = 0 ); | 73 | QWidget *parent, const char *name = 0 ); |
72 | }; | 74 | }; |
73 | 75 | ||
74 | XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name ) | 76 | XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name ) |
75 | : QObject( parent, name ), mCore( core ), mShowPreview( false ) | 77 | : QObject( parent, name ), mCore( core ), mShowPreview( false ) |
76 | { | 78 | { |
77 | loadPlugins(); | 79 | loadPlugins(); |
78 | } | 80 | } |
79 | 81 | ||
80 | XXPortManager::~XXPortManager() | 82 | XXPortManager::~XXPortManager() |
81 | { | 83 | { |
82 | } | 84 | } |
83 | 85 | ||
84 | void XXPortManager::restoreSettings() | 86 | void XXPortManager::restoreSettings() |
85 | { | 87 | { |
86 | } | 88 | } |
87 | 89 | ||
88 | void XXPortManager::saveSettings() | 90 | void XXPortManager::saveSettings() |
89 | { | 91 | { |
90 | } | 92 | } |
91 | 93 | ||
92 | void XXPortManager::importVCard( const KURL &url ) | 94 | void XXPortManager::importVCard( const KURL &url ) |
93 | { | 95 | { |
94 | importVCard( url, false ); | 96 | importVCard( url, false ); |
95 | } | 97 | } |
96 | 98 | ||
97 | void XXPortManager::importVCard( const KURL &url, bool showPreview ) | 99 | void XXPortManager::importVCard( const KURL &url, bool showPreview ) |
98 | { | 100 | { |
99 | importURL = url; | 101 | importURL = url; |
100 | mShowPreview = showPreview; | 102 | mShowPreview = showPreview; |
101 | slotImport( "vcard", "<empty>" ); | 103 | slotImport( "vcard", "<empty>" ); |
102 | mShowPreview = false; | 104 | mShowPreview = false; |
103 | importURL = KURL(); | 105 | importURL = KURL(); |
104 | } | 106 | } |
105 | 107 | ||
106 | void XXPortManager::importVCard( const QString &vCard, bool showPreview ) | 108 | void XXPortManager::importVCard( const QString &vCard, bool showPreview ) |
107 | { | 109 | { |
108 | importData = vCard; | 110 | importData = vCard; |
109 | mShowPreview = showPreview; | 111 | mShowPreview = showPreview; |
110 | slotImport( "vcard", "<empty>" ); | 112 | slotImport( "vcard", "<empty>" ); |
111 | mShowPreview = false; | 113 | mShowPreview = false; |
112 | importData = ""; | 114 | importData = ""; |
113 | } | 115 | } |
114 | 116 | ||
115 | void XXPortManager::slotImport( const QString &identifier, const QString &data ) | 117 | void XXPortManager::slotImport( const QString &identifier, const QString &data ) |
116 | { | 118 | { |
117 | XXPortObject *obj = mXXPortObjects[ identifier ]; | 119 | XXPortObject *obj = mXXPortObjects[ identifier ]; |
118 | if ( !obj ) { | 120 | if ( !obj ) { |
119 | KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); | 121 | KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); |
120 | return; | 122 | return; |
121 | } | 123 | } |
122 | 124 | ||
123 | KABC::Resource *resource = mCore->requestResource( mCore ); | 125 | KABC::Resource *resource = mCore->requestResource( mCore ); |
124 | if ( !resource ) | 126 | if ( !resource ) |
125 | return; | 127 | return; |
126 | 128 | ||
127 | KABC::AddresseeList list = obj->importContacts( data ); | 129 | KABC::AddresseeList list = obj->importContacts( data ); |
128 | bool useUndo = ( list.count() < 25 ); | 130 | bool useUndo = ( list.count() < 25 ); |
129 | #ifdef DESKTOP_VERSION | 131 | #ifdef DESKTOP_VERSION |
130 | useUndo = true; | 132 | useUndo = true; |
131 | #endif | 133 | #endif |
132 | mShowPreview = true; | 134 | mShowPreview = true; |
133 | KABC::AddresseeList::Iterator it; | 135 | KABC::AddresseeList::Iterator it; |
134 | bool imported = false; | 136 | bool imported = false; |
135 | int count = 0; | 137 | int count = 0; |
136 | 138 | ||
137 | KConfig config( locateLocal("config", "kabcrc") ); | 139 | KConfig config( locateLocal("config", "kabcrc") ); |
138 | config.setGroup( "General" ); | 140 | config.setGroup( "General" ); |
139 | int FormattedNameType = config.readNumEntry( "FormattedNameType", 1 ); | 141 | int FormattedNameType = config.readNumEntry( "FormattedNameType", 1 ); |
140 | 142 | ||
141 | 143 | ||
142 | for ( it = list.begin(); it != list.end(); ++it ) { | 144 | for ( it = list.begin(); it != list.end(); ++it ) { |
143 | if ( mShowPreview ) { | 145 | if ( mShowPreview ) { |
144 | PreviewDialog dlg( *it, mCore ); | 146 | PreviewDialog dlg( *it, mCore ); |
145 | connect( &dlg, SIGNAL( closeClicked() ), this, SLOT ( noPreview()) ); | 147 | connect( &dlg, SIGNAL( closeClicked() ), this, SLOT ( noPreview()) ); |
146 | if ( !dlg.exec() ) { | 148 | if ( !dlg.exec() ) { |
147 | if ( mShowPreview ) | 149 | if ( mShowPreview ) |
148 | continue; | 150 | continue; |
149 | } | 151 | } |
150 | } | 152 | } |
151 | (*it).setResource( resource ); | 153 | (*it).setResource( resource ); |
152 | if ( (*it).formattedName().isEmpty() ) | 154 | if ( (*it).formattedName().isEmpty() ) |
153 | (*it).setFormattedName( NameEditDialog::formattedName( (*it), FormattedNameType ) ); | 155 | (*it).setFormattedName( NameEditDialog::formattedName( (*it), FormattedNameType ) ); |
154 | if ( useUndo ) { | 156 | if ( useUndo ) { |
155 | ++count; | 157 | ++count; |
156 | // We use a PwNewCommand so the user can undo it. | 158 | // We use a PwNewCommand so the user can undo it. |
157 | PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it ); | 159 | PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it ); |
158 | UndoStack::instance()->push( command ); | 160 | UndoStack::instance()->push( command ); |
159 | RedoStack::instance()->clear(); | 161 | RedoStack::instance()->clear(); |
160 | } else { | 162 | } else { |
161 | ++count; | 163 | ++count; |
162 | mCore->addressBook()->insertAddressee( (*it), true, true ); | 164 | mCore->addressBook()->insertAddressee( (*it), true, true ); |
163 | } | 165 | } |
164 | imported = true; | 166 | imported = true; |
165 | } | 167 | } |
166 | if ( imported ) { | 168 | if ( imported ) { |
167 | KMessageBox::information( mCore, i18n( "%1 contacts\nsuccessfully\nimported.").arg( count) ); | 169 | KMessageBox::information( mCore, i18n( "%1 contacts\nsuccessfully\nimported.").arg( count) ); |
168 | emit modified(); | 170 | emit modified(); |
169 | } | 171 | } |
170 | } | 172 | } |
171 | void XXPortManager::noPreview() | 173 | void XXPortManager::noPreview() |
172 | { | 174 | { |
173 | mShowPreview = false; | 175 | mShowPreview = false; |
174 | } | 176 | } |
175 | void XXPortManager::slotExport( const QString &identifier, const QString &data ) | 177 | void XXPortManager::slotExport( const QString &identifier, const QString &data ) |
176 | { | 178 | { |
177 | XXPortObject *obj = mXXPortObjects[ identifier ]; | 179 | XXPortObject *obj = mXXPortObjects[ identifier ]; |
178 | if ( !obj ) { | 180 | if ( !obj ) { |
179 | KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); | 181 | KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); |
180 | return; | 182 | return; |
181 | } | 183 | } |
182 | 184 | ||
183 | KABC::AddresseeList addrList; | 185 | KABC::AddresseeList addrList; |
184 | XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore ); | 186 | XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore ); |
185 | if ( dlg.exec() ) | 187 | if ( dlg.exec() ) |
186 | addrList = dlg.contacts(); | 188 | addrList = dlg.contacts(); |
187 | else | 189 | else |
188 | return; | 190 | return; |
189 | if ( !obj->exportContacts( addrList, data ) ) | 191 | if ( !obj->exportContacts( addrList, data ) ) |
190 | KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); | 192 | KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); |
191 | else | 193 | else |
192 | KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); | 194 | KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); |
193 | } | 195 | } |
194 | 196 | ||
195 | void XXPortManager::loadPlugins() | 197 | void XXPortManager::loadPlugins() |
196 | { | 198 | { |
197 | mXXPortObjects.clear(); | 199 | mXXPortObjects.clear(); |
198 | 200 | ||
199 | #ifndef KAB_EMBEDDED | 201 | #ifndef KAB_EMBEDDED |
200 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); | 202 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); |
201 | KTrader::OfferList::ConstIterator it; | 203 | KTrader::OfferList::ConstIterator it; |
202 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 204 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
203 | if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) | 205 | if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) |
204 | continue; | 206 | continue; |
205 | 207 | ||
206 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); | 208 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); |
207 | if ( !factory ) { | 209 | if ( !factory ) { |
208 | kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; | 210 | kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; |
209 | continue; | 211 | continue; |
210 | } | 212 | } |
211 | 213 | ||
212 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); | 214 | XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); |
213 | 215 | ||
214 | if ( !xxportFactory ) { | 216 | if ( !xxportFactory ) { |
215 | kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; | 217 | kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; |
216 | continue; | 218 | continue; |
217 | } | 219 | } |
218 | 220 | ||
219 | #else //KAB_EMBEDDED | 221 | #else //KAB_EMBEDDED |
220 | QList<XXPortFactory> factorylist; | 222 | QList<XXPortFactory*> factorylist; |
221 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_csv_xxport())); | 223 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_csv_xxport())); |
222 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_kde2_xxport())); | 224 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_kde2_xxport())); |
223 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_vcard_xxport())); | 225 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_vcard_xxport())); |
224 | //US factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_opie_xxport())); | 226 | //US factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_opie_xxport())); |
225 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_qtopia_xxport())); | 227 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_qtopia_xxport())); |
226 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_sharpdtm_xxport())); | 228 | factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_sharpdtm_xxport())); |
227 | 229 | ||
228 | QListIterator<XXPortFactory> it(factorylist); | 230 | for(QList<XXPortFactory*>::iterator it=factorylist.begin();it!=factorylist.end();++it) { |
229 | for ( ; it.current(); ++it ) | 231 | XXPortFactory *xxportFactory = *it; |
230 | { | ||
231 | XXPortFactory *xxportFactory = it.current(); | ||
232 | #endif //KAB_EMBEDDED | 232 | #endif //KAB_EMBEDDED |
233 | 233 | ||
234 | XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); | 234 | XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); |
235 | if ( obj ) { | 235 | if ( obj ) { |
236 | mCore->addGUIClient( obj ); | 236 | mCore->addGUIClient( obj ); |
237 | mXXPortObjects.insert( obj->identifier(), obj ); | 237 | mXXPortObjects.insert( obj->identifier(), obj ); |
238 | connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), | 238 | connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), |
239 | this, SLOT( slotExport( const QString&, const QString& ) ) ); | 239 | this, SLOT( slotExport( const QString&, const QString& ) ) ); |
240 | connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), | 240 | connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), |
241 | this, SLOT( slotImport( const QString&, const QString& ) ) ); | 241 | this, SLOT( slotImport( const QString&, const QString& ) ) ); |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, | 247 | PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, |
248 | const char *name ) | 248 | const char *name ) |
249 | : KDialogBase( Plain, i18n( "Import this contact?" ), Ok | User1| User2, Ok, parent, | 249 | : KDialogBase( Plain, i18n( "Import this contact?" ), Ok | User1| User2, Ok, parent, |
250 | name, true, true ,i18n( "Import all!" ),i18n( "No" ) ) | 250 | name, true, true ,i18n( "Import all!" ),i18n( "No" ) ) |
251 | { | 251 | { |
252 | QWidget *page = plainPage(); | 252 | QWidget *page = plainPage(); |
253 | QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() ); | 253 | Q3VBoxLayout *layout = new Q3VBoxLayout( page, marginHint(), spacingHint() ); |
254 | connect( this, SIGNAL( user1Clicked() ), this, SLOT ( slotClose() ) ); | 254 | connect( this, SIGNAL( user1Clicked() ), this, SLOT ( slotClose() ) ); |
255 | connect( this, SIGNAL( user2Clicked() ), this, SLOT ( slotCancel() ) ); | 255 | connect( this, SIGNAL( user2Clicked() ), this, SLOT ( slotCancel() ) ); |
256 | 256 | ||
257 | KABC::AddresseeView *view = new KABC::AddresseeView( page ); | 257 | KABC::AddresseeView *view = new KABC::AddresseeView( page ); |
258 | view->setAddressee( addr ); | 258 | view->setAddressee( addr ); |
259 | layout->addWidget( view ); | 259 | layout->addWidget( view ); |
260 | #ifdef DESKTOP_VERSION | 260 | #ifdef DESKTOP_VERSION |
261 | resize( 640, 480 ); | 261 | resize( 640, 480 ); |
262 | #else | 262 | #else |
263 | showMaximized(); | 263 | showMaximized(); |
264 | #endif | 264 | #endif |
265 | } | 265 | } |
266 | 266 | ||
267 | #ifndef KAB_EMBEDDED | 267 | #ifndef KAB_EMBEDDED_ |
268 | #include "xxportmanager.moc" | 268 | #include "moc_xxportmanager.cpp" |
269 | #endif //KAB_EMBEDDED | 269 | #endif //KAB_EMBEDDED |
270 | |||