kitchensync Library API Documentation

localkonnector.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2003 Cornelius Schumacher <schumacher@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 "localkonnector.h"
00023 
00024 #include "localkonnectorconfig.h"
00025 
00026 #include <calendarsyncee.h>
00027 #include <addressbooksyncee.h>
00028 #include <bookmarksyncee.h>
00029 
00030 #include <kabc/resourcefile.h>
00031 
00032 #include <konnectorinfo.h>
00033 #include <kapabilities.h>
00034 
00035 #include <kconfig.h>
00036 #include <kgenericfactory.h>
00037 
00038 using namespace KSync;
00039 
00040 extern "C"
00041 {
00042   void *init_liblocalkonnector()
00043   {
00044     return new KRES::PluginFactory<LocalKonnector,LocalKonnectorConfig>();
00045   }
00046 }
00047 
00048 
00049 LocalKonnector::LocalKonnector( const KConfig *config )
00050     : Konnector( config ), mConfigWidget( 0 )
00051 {
00052   if ( config ) {
00053     mCalendarFile = config->readPathEntry( "CalendarFile" );
00054     mAddressBookFile = config->readPathEntry( "AddressBookFile" );
00055     mBookmarkFile = config->readPathEntry( "BookmarkFile" );
00056   }
00057 
00058     mAddressBookSyncee = new AddressBookSyncee( &mAddressBook );
00059   mAddressBookSyncee->setSource( i18n( "Local" ) );
00060   mCalendarSyncee = new CalendarSyncee( &mCalendar );
00061   mCalendarSyncee->setSource( i18n( "Local" ) );
00062   
00063   mSyncees.append( mCalendarSyncee );
00064   mSyncees.append( mAddressBookSyncee );
00065   mSyncees.append( new BookmarkSyncee( &mBookmarkManager ) );
00066 
00067   mAddressBookResourceFile = new KABC::ResourceFile( mAddressBookFile );
00068   mAddressBook.addResource( mAddressBookResourceFile );
00069 }
00070 
00071 LocalKonnector::~LocalKonnector()
00072 {
00073 }
00074 
00075 void LocalKonnector::writeConfig( KConfig *config )
00076 {
00077   Konnector::writeConfig( config );
00078 
00079   config->writePathEntry( "CalendarFile", mCalendarFile );
00080   config->writeEntry( "AddressBookFile", mAddressBookFile );
00081   config->writeEntry( "BookmarkFile", mAddressBookFile );
00082 }
00083 
00084 KSync::Kapabilities LocalKonnector::capabilities()
00085 {
00086   KSync::Kapabilities caps;
00087 
00088   caps.setSupportMetaSyncing( false ); // we can meta sync
00089   caps.setSupportsPushSync( false ); // we can initialize the sync from here
00090   caps.setNeedsConnection( false ); // we need to have pppd running
00091   caps.setSupportsListDir( false ); // we will support that once there is API for it...
00092   caps.setNeedsIPs( false ); // we need the IP
00093   caps.setNeedsSrcIP( false ); // we do not bind to any address...
00094   caps.setNeedsDestIP( false ); // we need to know where to connect
00095   caps.setAutoHandle( false ); // we currently do not support auto handling
00096   caps.setNeedAuthentication( false ); // HennevL says we do not need that
00097   caps.setNeedsModelName( false ); // we need a name for our meta path!
00098 
00099   return caps;
00100 }
00101 
00102 void LocalKonnector::setCapabilities( const KSync::Kapabilities& )
00103 {
00104 }
00105 
00106 bool LocalKonnector::readSyncees()
00107 {
00108   kdDebug() << "LocalKonnector::readSyncee()" << endl;
00109 
00110   if ( !mCalendarFile.isEmpty() ) {
00111     kdDebug() << "LocalKonnector::readSyncee(): calendar: " << mCalendarFile
00112               << endl;
00113     mCalendar.close();
00114     if ( mCalendar.load( mCalendarFile ) ) {
00115       kdDebug() << "Read succeeded." << endl;
00116       mCalendarSyncee->reset();
00117       mCalendarSyncee->setIdentifier( mCalendarFile );
00118       kdDebug() << "IDENTIFIER: " << mCalendarSyncee->identifier() << endl;
00119     } else {
00120       kdDebug() << "Read failed." << endl;
00121       return false;
00122     }
00123   }
00124 
00125     if ( !mAddressBookFile.isEmpty() ) {
00126       kdDebug() << "LocalKonnector::readSyncee(): addressbook: "
00127                 << mAddressBookFile << endl;
00128 
00129       mAddressBookResourceFile->setFileName( mAddressBookFile );
00130       if ( !mAddressBook.load() ) {
00131         kdDebug() << "Read failed." << endl;
00132         return false;
00133       }
00134 
00135       kdDebug() << "Read succeeded." << endl;
00136 
00137       mAddressBookSyncee->reset();
00138       mAddressBookSyncee->setIdentifier( mAddressBook.identifier() );
00139   
00140       KABC::AddressBook::Iterator it;
00141       for ( it = mAddressBook.begin(); it != mAddressBook.end(); ++it ) {
00142         KSync::AddressBookSyncEntry entry( *it, mAddressBookSyncee );
00143         mAddressBookSyncee->addEntry( &entry );
00144       }
00145     }
00146 
00147   // TODO: Read Bookmarks
00148 
00149   emit synceesRead( this );
00150 
00151   return true;
00152 }
00153 
00154 bool LocalKonnector::connectDevice()
00155 {
00156   return true;
00157 }
00158 
00159 bool LocalKonnector::disconnectDevice()
00160 {
00161   return true;
00162 }
00163 
00164 KSync::KonnectorInfo LocalKonnector::info() const
00165 {
00166   return KonnectorInfo( i18n("Dummy Konnector"),
00167                         QIconSet(),
00168                         QString::fromLatin1("LocalKonnector"),  // same as the .desktop file
00169                         "Dummy Konnector",
00170                         "agenda", // icon name
00171                         false );
00172 }
00173 
00174 void LocalKonnector::download( const QString& )
00175 {
00176   error( StdError::downloadNotSupported() );
00177 }
00178 
00179 bool LocalKonnector::writeSyncees()
00180 {
00181   if ( !mCalendarFile.isEmpty() ) {
00182     if ( !mCalendar.save( mCalendarFile ) ) return false;
00183   }
00184 
00185     if ( !mAddressBookFile.isEmpty() ) {
00186       KABC::Ticket *ticket;
00187       ticket = mAddressBook.requestSaveTicket( mAddressBookResourceFile );
00188       if ( !ticket ) {
00189         kdWarning() << "LocalKonnector::writeSyncees(). Couldn't get ticket for "
00190                     << "addressbook." << endl;
00191         return false; 
00192       }
00193       if ( !mAddressBook.save( ticket ) ) return false;
00194     }
00195 
00196   // TODO: Write Bookmarks
00197 
00198   emit synceesWritten( this );
00199 
00200   return true;
00201 }
00202 
00203 
00204 #include "localkonnector.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