xxportmanager.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qlayout.h>
00025
00026 #include <kabc/addressbook.h>
00027 #include <kabc/resource.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 #include <kmessagebox.h>
00031 #include <ktrader.h>
00032 #include <kapplication.h>
00033
00034 #include "core.h"
00035 #include "kablock.h"
00036 #include "undocmds.h"
00037 #include "xxportselectdialog.h"
00038
00039 #include "xxportmanager.h"
00040
00041 KURL XXPortManager::importURL = KURL();
00042 QString XXPortManager::importData = QString::null;
00043
00044 XXPortManager::XXPortManager( KAB::Core *core, QObject *parent, const char *name )
00045 : QObject( parent, name ), mCore( core )
00046 {
00047 loadPlugins();
00048 }
00049
00050 XXPortManager::~XXPortManager()
00051 {
00052 }
00053
00054 void XXPortManager::restoreSettings()
00055 {
00056 }
00057
00058 void XXPortManager::saveSettings()
00059 {
00060 }
00061
00062 void XXPortManager::importVCard( const KURL &url )
00063 {
00064 importURL = url;
00065 slotImport( "vcard", "<empty>" );
00066 importURL = KURL();
00067 }
00068
00069 void XXPortManager::importVCard( const QString &vCard )
00070 {
00071 importData = vCard;
00072 slotImport( "vcard", "<empty>" );
00073 importData = "";
00074 }
00075
00076 void XXPortManager::slotImport( const QString &identifier, const QString &data )
00077 {
00078 KAB::XXPort *obj = mXXPortObjects[ identifier ];
00079 if ( !obj ) {
00080 KMessageBox::error( mCore->widget(), i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
00081 return;
00082 }
00083
00084 KABC::Resource *resource = mCore->requestResource( mCore->widget() );
00085 if ( !resource )
00086 return;
00087
00088 KABLock::self( mCore->addressBook() )->lock( resource );
00089
00090 KABC::AddresseeList list = obj->importContacts( data );
00091 KABC::AddresseeList::Iterator it;
00092 bool imported = false;
00093 for ( it = list.begin(); it != list.end(); ++it ) {
00094 (*it).setResource( resource );
00095
00096 PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it );
00097 UndoStack::instance()->push( command );
00098 RedoStack::instance()->clear();
00099 imported = true;
00100 }
00101
00102 KABLock::self( mCore->addressBook() )->unlock( resource );
00103
00104 if ( imported )
00105 emit modified();
00106 }
00107
00108 void XXPortManager::slotExport( const QString &identifier, const QString &data )
00109 {
00110 KAB::XXPort *obj = mXXPortObjects[ identifier ];
00111 if ( !obj ) {
00112 KMessageBox::error( mCore->widget(), i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
00113 return;
00114 }
00115
00116 KABC::AddresseeList addrList;
00117 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore->widget() );
00118 if ( dlg.exec() )
00119 addrList = dlg.contacts();
00120 else
00121 return;
00122
00123 if ( !obj->exportContacts( addrList, data ) )
00124 KMessageBox::error( mCore->widget(), i18n( "Unable to export contacts." ) );
00125 }
00126
00127 void XXPortManager::loadPlugins()
00128 {
00129 mXXPortObjects.clear();
00130
00131 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" );
00132 KTrader::OfferList::ConstIterator it;
00133 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
00134 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) )
00135 continue;
00136
00137 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
00138 if ( !factory ) {
00139 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl;
00140 continue;
00141 }
00142
00143 KAB::XXPortFactory *xxportFactory = static_cast<KAB::XXPortFactory*>( factory );
00144
00145 if ( !xxportFactory ) {
00146 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl;
00147 continue;
00148 }
00149
00150 KAB::XXPort *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore->widget() );
00151 if ( obj ) {
00152 if ( mCore->guiClient() )
00153 mCore->guiClient()->insertChildClient( obj );
00154
00155 mXXPortObjects.insert( obj->identifier(), obj );
00156 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
00157 this, SLOT( slotExport( const QString&, const QString& ) ) );
00158 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
00159 this, SLOT( slotImport( const QString&, const QString& ) ) );
00160
00161 obj->setKApplication( kapp );
00162 }
00163 }
00164 }
00165
00166 #include "xxportmanager.moc"
This file is part of the documentation for kaddressbook Library Version 3.3.2.