From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kaddressbook/xxportmanager.cpp | 159 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 kaddressbook/xxportmanager.cpp (limited to 'kaddressbook/xxportmanager.cpp') diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp new file mode 100644 index 000000000..3382ac439 --- /dev/null +++ b/kaddressbook/xxportmanager.cpp @@ -0,0 +1,159 @@ +/* + This file is part of KAddressbook. + Copyright (c) 2003 Tobias Koenig + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "core.h" +#include "kablock.h" +#include "undocmds.h" +#include "xxportselectdialog.h" + +#include "xxportmanager.h" + +KURL XXPortManager::importURL = KURL(); +QString XXPortManager::importData = QString::null; + +XXPortManager::XXPortManager( KAB::Core *core, QObject *parent, const char *name ) + : QObject( parent, name ), mCore( core ) +{ + loadPlugins(); +} + +XXPortManager::~XXPortManager() +{ +} + +void XXPortManager::restoreSettings() +{ +} + +void XXPortManager::saveSettings() +{ +} + +void XXPortManager::importVCard( const KURL &url ) +{ + importURL = url; + slotImport( "vcard", "" ); + importURL = KURL(); +} + +void XXPortManager::importVCardFromData( const QString &vCard ) +{ + importData = vCard; + slotImport( "vcard", "" ); + importData = ""; +} + +void XXPortManager::slotImport( const QString &identifier, const QString &data ) +{ + KAB::XXPort *obj = mXXPortObjects[ identifier ]; + if ( !obj ) { + KMessageBox::error( mCore->widget(), i18n( "No import plugin available for %1." ).arg( identifier ) ); + return; + } + + KABC::Resource *resource = mCore->requestResource( mCore->widget() ); + if ( !resource ) + return; + + KABC::AddresseeList list = obj->importContacts( data ); + KABC::AddresseeList::Iterator it; + for ( it = list.begin(); it != list.end(); ++it ) + (*it).setResource( resource ); + + if ( !list.isEmpty() ) { + NewCommand *command = new NewCommand( mCore->addressBook(), list ); + mCore->commandHistory()->addCommand( command ); + emit modified(); + } +} + +void XXPortManager::slotExport( const QString &identifier, const QString &data ) +{ + KAB::XXPort *obj = mXXPortObjects[ identifier ]; + if ( !obj ) { + KMessageBox::error( mCore->widget(), i18n( "No export plugin available for %1." ).arg( identifier ) ); + return; + } + + KABC::AddresseeList addrList; + XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore->widget() ); + if ( dlg.exec() ) + addrList = dlg.contacts(); + else + return; + + if ( !obj->exportContacts( addrList, data ) ) + KMessageBox::error( mCore->widget(), i18n( "Unable to export contacts." ) ); +} + +void XXPortManager::loadPlugins() +{ + mXXPortObjects.clear(); + + const KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort", + QString( "[X-KDE-KAddressBook-XXPortPluginVersion] == %1" ).arg( KAB_XXPORT_PLUGIN_VERSION ) ); + KTrader::OfferList::ConstIterator it; + for ( it = plugins.begin(); it != plugins.end(); ++it ) { + if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) + continue; + + KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); + if ( !factory ) { + kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; + continue; + } + + KAB::XXPortFactory *xxportFactory = static_cast( factory ); + + if ( !xxportFactory ) { + kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; + continue; + } + + KAB::XXPort *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore->widget() ); + if ( obj ) { + if ( mCore->guiClient() ) + mCore->guiClient()->insertChildClient( obj ); + + mXXPortObjects.insert( obj->identifier(), obj ); + connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), + this, SLOT( slotExport( const QString&, const QString& ) ) ); + connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), + this, SLOT( slotImport( const QString&, const QString& ) ) ); + + obj->setKApplication( kapp ); + } + } +} + +#include "xxportmanager.moc" -- cgit v1.2.1