kitchensync Library API Documentation

kabckonnector.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include <qtimer.h>
00023 
00024 #include <addressbooksyncee.h>
00025 
00026 #include <kabc/resource.h>
00027 #include <kabc/resourcefile.h>
00028 #include <kapabilities.h>
00029 #include <kconfig.h>
00030 #include <kgenericfactory.h>
00031 #include <konnectorinfo.h>
00032 #include <libkdepim/kabcresourcenull.h>
00033 
00034 #include "kabckonnector.h"
00035 #include "kabckonnectorconfig.h"
00036 
00037 using namespace KSync;
00038 
00039 extern "C"
00040 {
00041   void *init_libkabckonnector()
00042   {
00043     return new KRES::PluginFactory<KABCKonnector,KABCKonnectorConfig>();
00044   }
00045 }
00046 
00047 
00048 KABCKonnector::KABCKonnector( const KConfig *config )
00049     : Konnector( config ), mConfigWidget( 0 ), mResource( 0 )
00050 {
00051   if ( config ) {
00052     mResourceIdentifier = config->readEntry( "CurrentResource" );
00053   }
00054 
00055   mManager = new KRES::Manager<KABC::Resource>( "contact" );
00056   mManager->readConfig();
00057 
00058   mAddressBook.addResource( new KABC::ResourceNull() );
00059 
00060   mAddressBookSyncee = new AddressBookSyncee( &mAddressBook );
00061   mAddressBookSyncee->setSource( i18n( "Address Book" ) );
00062   
00063   mSyncees.append( mAddressBookSyncee );
00064 
00065   KRES::Manager<KABC::Resource>::ActiveIterator it;
00066   for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
00067     if ( (*it)->identifier() == mResourceIdentifier ) {
00068       mResource = *it;
00069       break;
00070     }
00071   }
00072 
00073   if ( mResource ) {
00074     connect( mResource, SIGNAL( loadingFinished( Resource* ) ),
00075              SLOT( loadingFinished() ) );
00076 
00077     mResource->setAddressBook( &mAddressBook );
00078   }
00079 }
00080 
00081 KABCKonnector::~KABCKonnector()
00082 {
00083   delete mManager;
00084 }
00085 
00086 void KABCKonnector::writeConfig( KConfig *config )
00087 {
00088   Konnector::writeConfig( config );
00089 
00090   config->writeEntry( "CurrentResource", mResourceIdentifier );
00091 }
00092 
00093 KSync::Kapabilities KABCKonnector::capabilities()
00094 {
00095   KSync::Kapabilities caps;
00096 
00097   caps.setSupportMetaSyncing( false ); // we can meta sync
00098   caps.setSupportsPushSync( false ); // we can initialize the sync from here
00099   caps.setNeedsConnection( false ); // we need to have pppd running
00100   caps.setSupportsListDir( false ); // we will support that once there is API for it...
00101   caps.setNeedsIPs( false ); // we need the IP
00102   caps.setNeedsSrcIP( false ); // we do not bind to any address...
00103   caps.setNeedsDestIP( false ); // we need to know where to connect
00104   caps.setAutoHandle( false ); // we currently do not support auto handling
00105   caps.setNeedAuthentication( false ); // HennevL says we do not need that
00106   caps.setNeedsModelName( false ); // we need a name for our meta path!
00107 
00108   return caps;
00109 }
00110 
00111 void KABCKonnector::setCapabilities( const KSync::Kapabilities& )
00112 {
00113 }
00114 
00115 bool KABCKonnector::readSyncees()
00116 {
00117   if ( !mResource )
00118     return false;
00119 
00120   if ( !mResource->open() )
00121     return false;
00122 
00123   mResource->asyncLoad();
00124 
00125   return true;
00126 }
00127 
00128 bool KABCKonnector::connectDevice()
00129 {
00130   return true;
00131 }
00132 
00133 bool KABCKonnector::disconnectDevice()
00134 {
00135   return true;
00136 }
00137 
00138 KSync::KonnectorInfo KABCKonnector::info() const
00139 {
00140   return KonnectorInfo( i18n( "Address Book Konnector" ),
00141                         QIconSet(),
00142                         QString::fromLatin1( "KABCKonnector" ),
00143                         "Address Book Konnector",
00144                         "kaddressbook",
00145                         false );
00146 }
00147 
00148 void KABCKonnector::download( const QString& )
00149 {
00150   error( StdError::downloadNotSupported() );
00151 }
00152 
00153 bool KABCKonnector::writeSyncees()
00154 {
00155   if ( !mResource )
00156     return false;
00157 
00158   KABC::AddressBook::Iterator it;
00159   for ( it = mAddressBook.begin(); it != mAddressBook.end(); ++it )
00160     mResource->insertAddressee( *it );
00161 
00162   if ( !mResource->readOnly() ) {
00163     KABC::Ticket *ticket;
00164     ticket = mResource->requestSaveTicket();
00165     if ( !ticket ) {
00166       kdWarning() << "KABCKonnector::writeSyncees(). Couldn't get ticket for "
00167                   << "resource." << endl;
00168       return false;
00169     }
00170 
00171     if ( !mResource->save( ticket ) ) {
00172       kdWarning() << "KABCKonnector::writeSyncees(). Couldn't save resource." << endl;
00173       return false;
00174     }
00175   }
00176 
00177   emit synceesWritten( this );
00178 
00179   return true;
00180 }
00181 
00182 void KABCKonnector::loadingFinished()
00183 {
00184   mAddressBookSyncee->reset();
00185   
00186   KABC::Resource::Iterator it;
00187   for ( it = mResource->begin(); it != mResource->end(); ++it ) {
00188     KSync::AddressBookSyncEntry entry( *it, mAddressBookSyncee );
00189     mAddressBookSyncee->addEntry( &entry );
00190   }
00191 
00192   emit synceesRead( this );
00193 }
00194 
00195 #include "kabckonnector.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:23:40 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003