summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-06-30 21:59:48 (UTC)
committer ulf69 <ulf69>2004-06-30 21:59:48 (UTC)
commit2de4aeb0272fa7d96a55332196a11e52b2f27539 (patch) (unidiff)
treed455673832ac53a085cd3f280f60c11d12d45f83
parente0e3d743a6b61eaac023c9f284362ab08337da05 (diff)
downloadkdepimpi-2de4aeb0272fa7d96a55332196a11e52b2f27539.zip
kdepimpi-2de4aeb0272fa7d96a55332196a11e52b2f27539.tar.gz
kdepimpi-2de4aeb0272fa7d96a55332196a11e52b2f27539.tar.bz2
preparations for dynamic import/export module loading
Diffstat (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
@@ -20,38 +20,42 @@
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;
@@ -163,96 +167,68 @@ void XXPortManager::slotExport( const QString &identifier, const QString &data )
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 );
diff --git a/kaddressbook/xxportobject.h b/kaddressbook/xxportobject.h
index d697700..fddc219 100644
--- a/kaddressbook/xxportobject.h
+++ b/kaddressbook/xxportobject.h
@@ -27,27 +27,25 @@ Copyright (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
@@ -113,45 +111,27 @@ class XXPortObject : public QObject, virtual public KXMLGUIClient
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