summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorulf69 <ulf69>2004-06-30 21:59:48 (UTC)
committer ulf69 <ulf69>2004-06-30 21:59:48 (UTC)
commit2de4aeb0272fa7d96a55332196a11e52b2f27539 (patch) (unidiff)
treed455673832ac53a085cd3f280f60c11d12d45f83 /kaddressbook
parente0e3d743a6b61eaac023c9f284362ab08337da05 (diff)
downloadkdepimpi-2de4aeb0272fa7d96a55332196a11e52b2f27539.zip
kdepimpi-2de4aeb0272fa7d96a55332196a11e52b2f27539.tar.gz
kdepimpi-2de4aeb0272fa7d96a55332196a11e52b2f27539.tar.bz2
preparations for dynamic import/export module loading
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxportmanager.cpp78
-rw-r--r--kaddressbook/xxportobject.h20
2 files changed, 27 insertions, 71 deletions
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp
index 6cfa9cb..20cde49 100644
--- a/kaddressbook/xxportmanager.cpp
+++ b/kaddressbook/xxportmanager.cpp
@@ -1,77 +1,81 @@
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 <qlayout.h> 31#include <qlayout.h>
32#include <qlist.h>
32 33
33#include <kabc/addressbook.h> 34#include <kabc/addressbook.h>
34#include <kabc/resource.h> 35#include <kabc/resource.h>
35#include <kdebug.h> 36#include <kdebug.h>
36#include <kdialogbase.h> 37#include <kdialogbase.h>
37#include <klocale.h> 38#include <klocale.h>
38#include <kmessagebox.h> 39#include <kmessagebox.h>
39 40
40#ifndef KAB_EMBEDDED 41#ifndef KAB_EMBEDDED
41#include <ktrader.h> 42#include <ktrader.h>
42#else //KAB_EMBEDDED 43#else //KAB_EMBEDDED
43#include "xxport/csv_xxport.h" 44extern "C"
44#include "xxport/kde2_xxport.h" 45{
45#include "xxport/vcard_xxport.h" 46 void* init_kaddrbk_csv_xxport();
47 void* init_kaddrbk_kde2_xxport();
48 void* init_kaddrbk_vcard_xxport();
49}
46#endif //KAB_EMBEDDED 50#endif //KAB_EMBEDDED
47 51
48#include <libkdepim/addresseeview.h> 52#include <libkdepim/addresseeview.h>
49 53
50#include "kabcore.h" 54#include "kabcore.h"
51#include "undocmds.h" 55#include "undocmds.h"
52#include "xxportselectdialog.h" 56#include "xxportselectdialog.h"
53 57
54#include "xxportmanager.h" 58#include "xxportmanager.h"
55 59
56KURL XXPortManager::importURL = KURL(); 60KURL XXPortManager::importURL = KURL();
57QString XXPortManager::importData = QString::null; 61QString XXPortManager::importData = QString::null;
58 62
59class PreviewDialog : public KDialogBase 63class PreviewDialog : public KDialogBase
60{ 64{
61 public: 65 public:
62 PreviewDialog( const KABC::Addressee &addr, 66 PreviewDialog( const KABC::Addressee &addr,
63 QWidget *parent, const char *name = 0 ); 67 QWidget *parent, const char *name = 0 );
64}; 68};
65 69
66XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name ) 70XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name )
67 : QObject( parent, name ), mCore( core ), mShowPreview( false ) 71 : QObject( parent, name ), mCore( core ), mShowPreview( false )
68{ 72{
69 loadPlugins(); 73 loadPlugins();
70} 74}
71 75
72XXPortManager::~XXPortManager() 76XXPortManager::~XXPortManager()
73{ 77{
74} 78}
75 79
76void XXPortManager::restoreSettings() 80void XXPortManager::restoreSettings()
77{ 81{
@@ -143,127 +147,99 @@ void XXPortManager::slotImport( const QString &identifier, const QString &data )
143 147
144void XXPortManager::slotExport( const QString &identifier, const QString &data ) 148void XXPortManager::slotExport( const QString &identifier, const QString &data )
145{ 149{
146 XXPortObject *obj = mXXPortObjects[ identifier ]; 150 XXPortObject *obj = mXXPortObjects[ identifier ];
147 if ( !obj ) { 151 if ( !obj ) {
148 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 ) );
149 return; 153 return;
150 } 154 }
151 155
152 KABC::AddresseeList addrList; 156 KABC::AddresseeList addrList;
153 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore ); 157 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore );
154 if ( dlg.exec() ) 158 if ( dlg.exec() )
155 addrList = dlg.contacts(); 159 addrList = dlg.contacts();
156 else 160 else
157 return; 161 return;
158 162
159 if ( !obj->exportContacts( addrList, data ) ) 163 if ( !obj->exportContacts( addrList, data ) )
160 KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); 164 KMessageBox::error( mCore, i18n( "Unable to export contacts." ) );
161 else 165 else
162 KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); 166 KMessageBox::information( mCore, i18n( "contacts successfully exported." ) );
163} 167}
164 168
165void XXPortManager::loadPlugins() 169void XXPortManager::loadPlugins()
166{ 170{
167 mXXPortObjects.clear(); 171 mXXPortObjects.clear();
168 172
169#ifndef KAB_EMBEDDED 173#ifndef KAB_EMBEDDED
170 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); 174 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" );
171 KTrader::OfferList::ConstIterator it; 175 KTrader::OfferList::ConstIterator it;
172 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 176 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
173 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) 177 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) )
174 continue; 178 continue;
175 179
176 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 180 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
177 if ( !factory ) { 181 if ( !factory ) {
178 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; 182 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl;
179 continue; 183 continue;
180 } 184 }
181 185
182 XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); 186 XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory );
183 187
184 if ( !xxportFactory ) { 188 if ( !xxportFactory ) {
185 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; 189 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl;
186 continue; 190 continue;
187 } 191 }
192
193#else //KAB_EMBEDDED
194 QList<XXPortFactory> factorylist;
195 factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_csv_xxport()));
196 factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_kde2_xxport()));
197 factorylist.append(static_cast<XXPortFactory*>(init_kaddrbk_vcard_xxport()));
198
199 //now add the opie import library dynamically
200 KLibFactory *factory = KLibLoader::self()->factory( "kaddrbk_opie_xxport" );
201 if ( factory ) {
202 XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory );
203 factorylist.append(xxportFactory);
204 }
205
206 QListIterator<XXPortFactory> it(factorylist);
207 for ( ; it.current(); ++it )
208 {
209 XXPortFactory *xxportFactory = it.current();
210#endif //KAB_EMBEDDED
188 211
189 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); 212 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
190 if ( obj ) { 213 if ( obj ) {
191 mCore->addGUIClient( obj ); 214 mCore->addGUIClient( obj );
192 mXXPortObjects.insert( obj->identifier(), obj ); 215 mXXPortObjects.insert( obj->identifier(), obj );
193 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), 216 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
194 this, SLOT( slotExport( const QString&, const QString& ) ) ); 217 this, SLOT( slotExport( const QString&, const QString& ) ) );
195 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), 218 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
196 this, SLOT( slotImport( const QString&, const QString& ) ) ); 219 this, SLOT( slotImport( const QString&, const QString& ) ) );
197 } 220 }
198 } 221 }
199 222
200#else //KAB_EMBEDDED
201//lets load the export/import stubs directly. Is dynamic loading necessary for KA/Pi?
202
203 // CVS import/export
204 XXPortFactory *xxportFactory = new CSVXXPortFactory();
205
206 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
207 if ( obj ) {
208 mCore->addGUIClient( obj );
209 mXXPortObjects.insert( obj->identifier(), obj );
210 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
211 this, SLOT( slotExport( const QString&, const QString& ) ) );
212 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
213 this, SLOT( slotImport( const QString&, const QString& ) ) );
214 }
215
216
217
218 // KDE2 import/export
219 xxportFactory = new KDE2XXPortFactory();
220
221 obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
222 if ( obj ) {
223 mCore->addGUIClient( obj );
224 mXXPortObjects.insert( obj->identifier(), obj );
225 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
226 this, SLOT( slotExport( const QString&, const QString& ) ) );
227 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
228 this, SLOT( slotImport( const QString&, const QString& ) ) );
229 }
230
231
232
233 // VCARD import/export
234 xxportFactory = new VCardXXPortFactory();
235
236 obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
237 if ( obj ) {
238 mCore->addGUIClient( obj );
239 mXXPortObjects.insert( obj->identifier(), obj );
240 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
241 this, SLOT( slotExport( const QString&, const QString& ) ) );
242 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
243 this, SLOT( slotImport( const QString&, const QString& ) ) );
244 }
245#endif //KAB_EMBEDDED
246
247} 223}
248 224
249 225
250PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, 226PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent,
251 const char *name ) 227 const char *name )
252 : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent, 228 : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent,
253 name, true, true ) 229 name, true, true )
254{ 230{
255 QWidget *page = plainPage(); 231 QWidget *page = plainPage();
256 QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() ); 232 QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() );
257 233
258 KPIM::AddresseeView *view = new KPIM::AddresseeView( page ); 234 KPIM::AddresseeView *view = new KPIM::AddresseeView( page );
259 view->setAddressee( addr ); 235 view->setAddressee( addr );
260 236
261 layout->addWidget( view ); 237 layout->addWidget( view );
262 238
263 resize( 400, 300 ); 239 resize( 400, 300 );
264} 240}
265 241
266#ifndef KAB_EMBEDDED 242#ifndef KAB_EMBEDDED
267#include "xxportmanager.moc" 243#include "xxportmanager.moc"
268#endif //KAB_EMBEDDED 244#endif //KAB_EMBEDDED
269 245
diff --git a/kaddressbook/xxportobject.h b/kaddressbook/xxportobject.h
index d697700..fddc219 100644
--- a/kaddressbook/xxportobject.h
+++ b/kaddressbook/xxportobject.h
@@ -7,67 +7,65 @@
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#ifndef XXPORTOBJECT_H 31#ifndef XXPORTOBJECT_H
32#define XXPORTOBJECT_H 32#define XXPORTOBJECT_H
33 33
34#include <qobject.h> 34#include <qobject.h>
35 35
36#include <kabc/addressbook.h> 36#include <kabc/addressbook.h>
37#include <kabc/addresseelist.h> 37#include <kabc/addresseelist.h>
38#include <kxmlguiclient.h> 38#include <kxmlguiclient.h>
39#ifndef KAB_EMBEDDED
40#include <klibloader.h> 39#include <klibloader.h>
41#endif //KAB_EMBEDDED
42 40
43 41
44class XXPortObject : public QObject, virtual public KXMLGUIClient 42class XXPortObject : public QObject, virtual public KXMLGUIClient
45{ 43{
46 Q_OBJECT 44 Q_OBJECT
47 45
48 public: 46 public:
49 XXPortObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 47 XXPortObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
50 ~XXPortObject(); 48 ~XXPortObject();
51 49
52 /** 50 /**
53 Returns the unique identifier of this xxport modul, it should 51 Returns the unique identifier of this xxport modul, it should
54 be the lowercase name of the import/export format e.g. 'vcard' 52 be the lowercase name of the import/export format e.g. 'vcard'
55 */ 53 */
56 virtual QString identifier() const = 0; 54 virtual QString identifier() const = 0;
57 55
58 /** 56 /**
59 Reimplement this method if the XXPortManager shall 57 Reimplement this method if the XXPortManager shall
60 pass a sorted list to @ref exportContacts(). 58 pass a sorted list to @ref exportContacts().
61 */ 59 */
62 virtual bool requiresSorting() const { return false; } 60 virtual bool requiresSorting() const { return false; }
63 61
64 public slots: 62 public slots:
65 /** 63 /**
66 Reimplement this method for exporting the contacts. 64 Reimplement this method for exporting the contacts.
67 */ 65 */
68 virtual bool exportContacts( const KABC::AddresseeList &list, const QString& identifier ); 66 virtual bool exportContacts( const KABC::AddresseeList &list, const QString& identifier );
69 67
70 /** 68 /**
71 Reimplement this method for importing the contacts. 69 Reimplement this method for importing the contacts.
72 */ 70 */
73 virtual KABC::AddresseeList importContacts( const QString& identifier ) const; 71 virtual KABC::AddresseeList importContacts( const QString& identifier ) const;
@@ -93,65 +91,47 @@ class XXPortObject : public QObject, virtual public KXMLGUIClient
93 */ 91 */
94 void createImportAction( const QString &label, const QString &identifier = QString::null ); 92 void createImportAction( const QString &label, const QString &identifier = QString::null );
95 93
96 /** 94 /**
97 Create the export action. The identifier is passed in the export slot. 95 Create the export action. The identifier is passed in the export slot.
98 */ 96 */
99 void createExportAction( const QString &label, const QString &identifier = QString::null ); 97 void createExportAction( const QString &label, const QString &identifier = QString::null );
100 98
101 /** 99 /**
102 Returns a pointer to the address book object. 100 Returns a pointer to the address book object.
103 */ 101 */
104 KABC::AddressBook *addressBook() const; 102 KABC::AddressBook *addressBook() const;
105 103
106 /** 104 /**
107 Returns a pointer to the parent widget. It can be used as parent for 105 Returns a pointer to the parent widget. It can be used as parent for
108 message boxes. 106 message boxes.
109 */ 107 */
110 QWidget *parentWidget() const; 108 QWidget *parentWidget() const;
111 109
112 110
113 private slots: 111 private slots:
114 void slotImportActivated( const QString& ); 112 void slotImportActivated( const QString& );
115 void slotExportActivated( const QString& ); 113 void slotExportActivated( const QString& );
116 114
117 private: 115 private:
118 KABC::AddressBook *mAddressBook; 116 KABC::AddressBook *mAddressBook;
119 QWidget *mParentWidget; 117 QWidget *mParentWidget;
120 118
121 class XXPortObjectPrivate; 119 class XXPortObjectPrivate;
122 XXPortObjectPrivate *d; 120 XXPortObjectPrivate *d;
123}; 121};
124 122
125#ifndef KAB_EMBEDDED
126class XXPortFactory : public KLibFactory 123class XXPortFactory : public KLibFactory
127{ 124{
128 public: 125 public:
129 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, 126 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent,
130 const char *name = 0 ) = 0; 127 const char *name = 0 ) = 0;
131 128
132 protected: 129 protected:
133 virtual QObject* createObject( QObject*, const char*, const char*, 130 virtual QObject* createObject( QObject*, const char*, const char*,
134 const QStringList & ) 131 const QStringList & )
135 { 132 {
136 return 0; 133 return 0;
137 } 134 }
138}; 135};
139 136
140#else //KAB_EMBEDDED
141class XXPortFactory
142{
143 public:
144 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent,
145 const char *name = 0 ) = 0;
146
147 protected:
148 virtual QObject* createObject( QObject*, const char*, const char*,
149 const QStringList & )
150 {
151 return 0;
152 }
153};
154#endif //KAB_EMBEDDED
155
156
157#endif 137#endif