26 #include <tdeabc/addressbook.h>
27 #include <tdeabc/resource.h>
29 #include <tdelocale.h>
30 #include <tdemessagebox.h>
32 #include <tdeapplication.h>
37 #include "xxportselectdialog.h"
39 #include "xxportmanager.h"
41 KURL XXPortManager::importURL = KURL();
42 TQString XXPortManager::importData = TQString();
44 XXPortManager::XXPortManager( KAB::Core *core, TQObject *parent,
const char *name )
45 : TQObject( parent, name ), mCore( core )
50 XXPortManager::~XXPortManager()
54 void XXPortManager::restoreSettings()
58 void XXPortManager::saveSettings()
62 void XXPortManager::importVCard(
const KURL &url )
65 slotImport(
"vcard",
"<empty>" );
69 void XXPortManager::importVCardFromData(
const TQString &vCard )
72 slotImport(
"vcard",
"<empty>" );
76 void XXPortManager::slotImport(
const TQString &identifier,
const TQString &data )
78 KAB::XXPort *obj = mXXPortObjects[ identifier ];
80 KMessageBox::error( mCore->widget(), i18n(
"<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
84 TDEABC::Resource *resource = mCore->requestResource( mCore->widget() );
88 TDEABC::AddresseeList list = obj->importContacts( data );
89 TDEABC::AddresseeList::Iterator it;
90 for ( it = list.begin(); it != list.end(); ++it )
91 (*it).setResource( resource );
93 if ( !list.isEmpty() ) {
94 NewCommand *command =
new NewCommand( mCore->addressBook(), list );
95 mCore->commandHistory()->addCommand( command );
100 void XXPortManager::slotExport(
const TQString &identifier,
const TQString &data )
102 KAB::XXPort *obj = mXXPortObjects[ identifier ];
104 KMessageBox::error( mCore->widget(), i18n(
"<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
108 TDEABC::AddresseeList addrList;
109 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore->widget() );
111 addrList = dlg.contacts();
115 if ( !obj->exportContacts( addrList, data ) )
116 KMessageBox::error( mCore->widget(), i18n(
"Unable to export contacts." ) );
119 void XXPortManager::loadPlugins()
121 mXXPortObjects.clear();
123 const TDETrader::OfferList plugins = TDETrader::self()->query(
"KAddressBook/XXPort",
124 TQString(
"[X-TDE-KAddressBook-XXPortPluginVersion] == %1" ).arg( KAB_XXPORT_PLUGIN_VERSION ) );
125 TDETrader::OfferList::ConstIterator it;
126 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
127 if ( !(*it)->hasServiceType(
"KAddressBook/XXPort" ) )
130 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
132 kdDebug(5720) <<
"XXPortManager::loadExtensions(): Factory creation failed" << endl;
136 KAB::XXPortFactory *xxportFactory =
static_cast<KAB::XXPortFactory*
>( factory );
138 if ( !xxportFactory ) {
139 kdDebug(5720) <<
"XXPortManager::loadExtensions(): Cast failed" << endl;
143 KAB::XXPort *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore->widget() );
145 if ( mCore->guiClient() )
146 mCore->guiClient()->insertChildClient( obj );
148 mXXPortObjects.insert( obj->identifier(), obj );
149 connect( obj, TQ_SIGNAL( exportActivated(
const TQString&,
const TQString& ) ),
150 this, TQ_SLOT( slotExport(
const TQString&,
const TQString& ) ) );
151 connect( obj, TQ_SIGNAL( importActivated(
const TQString&,
const TQString& ) ),
152 this, TQ_SLOT( slotImport(
const TQString&,
const TQString& ) ) );
154 obj->setTDEApplication( kapp );
159 #include "xxportmanager.moc"