kaddressbook
xxportmanager.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <tqlayout.h>
00025
00026 #include <tdeabc/addressbook.h>
00027 #include <tdeabc/resource.h>
00028 #include <kdebug.h>
00029 #include <tdelocale.h>
00030 #include <tdemessagebox.h>
00031 #include <ktrader.h>
00032 #include <tdeapplication.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 TQString XXPortManager::importData = TQString();
00043
00044 XXPortManager::XXPortManager( KAB::Core *core, TQObject *parent, const char *name )
00045 : TQObject( 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::importVCardFromData( const TQString &vCard )
00070 {
00071 importData = vCard;
00072 slotImport( "vcard", "<empty>" );
00073 importData = "";
00074 }
00075
00076 void XXPortManager::slotImport( const TQString &identifier, const TQString &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 TDEABC::Resource *resource = mCore->requestResource( mCore->widget() );
00085 if ( !resource )
00086 return;
00087
00088 TDEABC::AddresseeList list = obj->importContacts( data );
00089 TDEABC::AddresseeList::Iterator it;
00090 for ( it = list.begin(); it != list.end(); ++it )
00091 (*it).setResource( resource );
00092
00093 if ( !list.isEmpty() ) {
00094 NewCommand *command = new NewCommand( mCore->addressBook(), list );
00095 mCore->commandHistory()->addCommand( command );
00096 emit modified();
00097 }
00098 }
00099
00100 void XXPortManager::slotExport( const TQString &identifier, const TQString &data )
00101 {
00102 KAB::XXPort *obj = mXXPortObjects[ identifier ];
00103 if ( !obj ) {
00104 KMessageBox::error( mCore->widget(), i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
00105 return;
00106 }
00107
00108 TDEABC::AddresseeList addrList;
00109 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore->widget() );
00110 if ( dlg.exec() )
00111 addrList = dlg.contacts();
00112 else
00113 return;
00114
00115 if ( !obj->exportContacts( addrList, data ) )
00116 KMessageBox::error( mCore->widget(), i18n( "Unable to export contacts." ) );
00117 }
00118
00119 void XXPortManager::loadPlugins()
00120 {
00121 mXXPortObjects.clear();
00122
00123 const TDETrader::OfferList plugins = TDETrader::self()->query( "KAddressBook/XXPort",
00124 TQString( "[X-TDE-KAddressBook-XXPortPluginVersion] == %1" ).arg( KAB_XXPORT_PLUGIN_VERSION ) );
00125 TDETrader::OfferList::ConstIterator it;
00126 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
00127 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) )
00128 continue;
00129
00130 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
00131 if ( !factory ) {
00132 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl;
00133 continue;
00134 }
00135
00136 KAB::XXPortFactory *xxportFactory = static_cast<KAB::XXPortFactory*>( factory );
00137
00138 if ( !xxportFactory ) {
00139 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl;
00140 continue;
00141 }
00142
00143 KAB::XXPort *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore->widget() );
00144 if ( obj ) {
00145 if ( mCore->guiClient() )
00146 mCore->guiClient()->insertChildClient( obj );
00147
00148 mXXPortObjects.insert( obj->identifier(), obj );
00149 connect( obj, TQT_SIGNAL( exportActivated( const TQString&, const TQString& ) ),
00150 this, TQT_SLOT( slotExport( const TQString&, const TQString& ) ) );
00151 connect( obj, TQT_SIGNAL( importActivated( const TQString&, const TQString& ) ),
00152 this, TQT_SLOT( slotImport( const TQString&, const TQString& ) ) );
00153
00154 obj->setTDEApplication( kapp );
00155 }
00156 }
00157 }
00158
00159 #include "xxportmanager.moc"
|