kitchensync Library API Documentation

remotekonnector.cpp

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2004 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 "remotekonnector.h" 00023 00024 #include "remotekonnectorconfig.h" 00025 00026 #include <calendarsyncee.h> 00027 #include <addressbooksyncee.h> 00028 #include <bookmarksyncee.h> 00029 00030 #include <kabc/vcardconverter.h> 00031 #include <libkcal/icalformat.h> 00032 #include <libkdepim/kabcresourcenull.h> 00033 00034 #include <konnectorinfo.h> 00035 #include <kapabilities.h> 00036 00037 #include <kconfig.h> 00038 #include <kgenericfactory.h> 00039 00040 using namespace KSync; 00041 using namespace KABC; 00042 using namespace KCal; 00043 00044 extern "C" 00045 { 00046 void *init_libremotekonnector() 00047 { 00048 return new KRES::PluginFactory<RemoteKonnector,RemoteKonnectorConfig>(); 00049 } 00050 } 00051 00052 00053 RemoteKonnector::RemoteKonnector( const KConfig *config ) 00054 : Konnector( config ), mConfigWidget( 0 ) 00055 { 00056 if ( config ) { 00057 mCalendarUrl = config->readPathEntry( "CalendarUrl" ); 00058 mAddressBookUrl = config->readPathEntry( "AddressBookUrl" ); 00059 mBookmarkUrl = config->readPathEntry( "BookmarkUrl" ); 00060 } 00061 00062 mAddressBook.addResource( new KABC::ResourceNull() ); 00063 00064 mAddressBookSyncee = new AddressBookSyncee( &mAddressBook ); 00065 mAddressBookSyncee->setSource( i18n( "Remote" ) ); 00066 mCalendarSyncee = new CalendarSyncee( &mCalendar ); 00067 mCalendarSyncee->setSource( i18n( "Remote" ) ); 00068 00069 mSyncees.append( mCalendarSyncee ); 00070 mSyncees.append( mAddressBookSyncee ); 00071 mSyncees.append( new BookmarkSyncee( &mBookmarkManager ) ); 00072 } 00073 00074 RemoteKonnector::~RemoteKonnector() 00075 { 00076 } 00077 00078 void RemoteKonnector::writeConfig( KConfig *config ) 00079 { 00080 Konnector::writeConfig( config ); 00081 00082 config->writePathEntry( "CalendarUrl", mCalendarUrl ); 00083 config->writeEntry( "AddressBookUrl", mAddressBookUrl ); 00084 config->writeEntry( "BookmarkFile", mAddressBookUrl ); 00085 } 00086 00087 KSync::Kapabilities RemoteKonnector::capabilities() 00088 { 00089 KSync::Kapabilities caps; 00090 00091 caps.setSupportMetaSyncing( false ); // we can meta sync 00092 caps.setSupportsPushSync( false ); // we can initialize the sync from here 00093 caps.setNeedsConnection( false ); // we need to have pppd running 00094 caps.setSupportsListDir( false ); // we will support that once there is API for it... 00095 caps.setNeedsIPs( false ); // we need the IP 00096 caps.setNeedsSrcIP( false ); // we do not bind to any address... 00097 caps.setNeedsDestIP( false ); // we need to know where to connect 00098 caps.setAutoHandle( false ); // we currently do not support auto handling 00099 caps.setNeedAuthentication( false ); // HennevL says we do not need that 00100 caps.setNeedsModelName( false ); // we need a name for our meta path! 00101 00102 return caps; 00103 } 00104 00105 void RemoteKonnector::setCapabilities( const KSync::Kapabilities& ) 00106 { 00107 } 00108 00109 bool RemoteKonnector::readSyncees() 00110 { 00111 kdDebug() << "RemoteKonnector::readSyncees()" << endl; 00112 00113 mSynceeReadCount = 0; 00114 00115 if ( !mCalendarUrl.isEmpty() ) { 00116 kdDebug() << "RemoteKonnector::readSyncees(): calendar: " << mCalendarUrl 00117 << endl; 00118 00119 mCalendarData = ""; 00120 00121 KIO::TransferJob *job = KIO::get( KURL( mCalendarUrl ) ); 00122 connect( job, SIGNAL( result( KIO::Job * ) ), 00123 SLOT( slotCalendarReadResult( KIO::Job * ) ) ); 00124 connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ), 00125 SLOT( slotCalendarData( KIO::Job *, const QByteArray & ) ) ); 00126 00127 ++mSynceeReadCount; 00128 } 00129 00130 if ( !mAddressBookUrl.isEmpty() ) { 00131 kdDebug() << "RemoteKonnector::readSyncees(): AddressBook: " 00132 << mAddressBookUrl << endl; 00133 00134 mAddressBookData = ""; 00135 00136 KIO::TransferJob *job = KIO::get( KURL( mAddressBookUrl ) ); 00137 connect( job, SIGNAL( result( KIO::Job * ) ), 00138 SLOT( slotAddressBookReadResult( KIO::Job * ) ) ); 00139 connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ), 00140 SLOT( slotAddressBookData( KIO::Job *, const QByteArray & ) ) ); 00141 00142 ++mSynceeReadCount; 00143 } 00144 00145 // TODO: Read Bookmarks 00146 00147 return true; 00148 } 00149 00150 void RemoteKonnector::slotCalendarData( KIO::Job *, const QByteArray &d ) 00151 { 00152 mCalendarData += QString::fromUtf8( d ); 00153 } 00154 00155 void RemoteKonnector::slotCalendarReadResult( KIO::Job *job ) 00156 { 00157 --mSynceeReadCount; 00158 00159 if ( job->error() ) { 00160 job->showErrorDialog( 0 ); 00161 emit synceeReadError( this ); 00162 } else { 00163 mCalendar.close(); 00164 ICalFormat ical; 00165 if ( ical.fromString( &mCalendar, mCalendarData ) ) { 00166 kdDebug() << "Read succeeded." << endl; 00167 mCalendarSyncee->reset(); 00168 mCalendarSyncee->setIdentifier( mCalendarUrl ); 00169 kdDebug() << "IDENTIFIER: " << mCalendarSyncee->identifier() << endl; 00170 } else { 00171 kdDebug() << "Read failed." << endl; 00172 emit synceeReadError( this ); 00173 } 00174 } 00175 00176 finishRead(); 00177 } 00178 00179 void RemoteKonnector::slotAddressBookData( KIO::Job *, const QByteArray &d ) 00180 { 00181 mAddressBookData += QString::fromUtf8( d ); 00182 } 00183 00184 void RemoteKonnector::slotAddressBookReadResult( KIO::Job *job ) 00185 { 00186 --mSynceeReadCount; 00187 00188 if ( job->error() ) { 00189 job->showErrorDialog( 0 ); 00190 emit synceeReadError( this ); 00191 } else { 00192 mAddressBook.clear(); 00193 VCardConverter v; 00194 Addressee::List a = v.parseVCards( mAddressBookData ); 00195 Addressee::List::ConstIterator it; 00196 for( it = a.begin(); it != a.end(); ++it ) { 00197 mAddressBook.insertAddressee( *it ); 00198 KSync::AddressBookSyncEntry entry( *it, mAddressBookSyncee ); 00199 mAddressBookSyncee->addEntry( &entry ); 00200 } 00201 } 00202 00203 finishRead(); 00204 } 00205 00206 void RemoteKonnector::finishRead() 00207 { 00208 if ( mSynceeReadCount > 0 ) return; 00209 00210 emit synceesRead( this ); 00211 } 00212 00213 bool RemoteKonnector::connectDevice() 00214 { 00215 return true; 00216 } 00217 00218 bool RemoteKonnector::disconnectDevice() 00219 { 00220 return true; 00221 } 00222 00223 KSync::KonnectorInfo RemoteKonnector::info() const 00224 { 00225 return KonnectorInfo( i18n("Remote Konnector"), 00226 QIconSet(), 00227 QString::fromLatin1("RemoteKonnector"), // same as the .desktop file 00228 "Remote Konnector", 00229 "agenda", // icon name 00230 false ); 00231 } 00232 00233 bool RemoteKonnector::writeSyncees() 00234 { 00235 kdDebug() << "RemoteKonnector::writeSyncees()" << endl; 00236 00237 mSynceeWriteCount = 0; 00238 00239 if ( !mCalendarUrl.isEmpty() ) { 00240 kdDebug() << "RemoteKonnector::writeSyncees(): calendar: " << mCalendarUrl 00241 << endl; 00242 00243 ICalFormat ical; 00244 mCalendarData = ical.toString( &mCalendar ); 00245 if ( !mCalendarData.isEmpty() ) { 00246 KIO::TransferJob *job = KIO::put( KURL( mCalendarUrl ), -1, true, false ); 00247 connect( job, SIGNAL( result( KIO::Job * ) ), 00248 SLOT( slotCalendarWriteResult( KIO::Job * ) ) ); 00249 connect( job, SIGNAL( dataReq( KIO::Job *, QByteArray & ) ), 00250 SLOT( slotCalendarDataReq( KIO::Job *, QByteArray & ) ) ); 00251 00252 ++mSynceeWriteCount; 00253 } 00254 } 00255 00256 if ( !mAddressBookUrl.isEmpty() ) { 00257 kdDebug() << "RemoteKonnector::writeSyncees(): AddressBook: " 00258 << mAddressBookUrl << endl; 00259 00260 mAddressBookData = ""; 00261 00262 VCardConverter v; 00263 AddressBook::ConstIterator it; 00264 for ( it = mAddressBook.begin(); it != mAddressBook.end(); ++it ) { 00265 mAddressBookData.append( v.createVCard( *it ) ); 00266 } 00267 00268 if ( !mAddressBookData.isEmpty() ) { 00269 KIO::TransferJob *job = KIO::put( KURL( mAddressBookUrl ), -1, true, 00270 false ); 00271 connect( job, SIGNAL( result( KIO::Job * ) ), 00272 SLOT( slotAddressBookWriteResult( KIO::Job * ) ) ); 00273 connect( job, SIGNAL( dataReq( KIO::Job *, QByteArray & ) ), 00274 SLOT( slotAddressBookDataReq( KIO::Job *, QByteArray & ) ) ); 00275 00276 ++mSynceeWriteCount; 00277 } 00278 } 00279 00280 // TODO: Write Bookmarks 00281 00282 return true; 00283 } 00284 00285 void RemoteKonnector::slotCalendarDataReq( KIO::Job *, QByteArray &d ) 00286 { 00287 if ( !mCalendarData.isEmpty() ) { 00288 d = mCalendarData.utf8(); 00289 mCalendarData = QString::null; 00290 } 00291 } 00292 00293 void RemoteKonnector::slotCalendarWriteResult( KIO::Job *job ) 00294 { 00295 --mSynceeWriteCount; 00296 00297 if ( job->error() ) { 00298 job->showErrorDialog( 0 ); 00299 emit synceeWriteError( this ); 00300 } 00301 00302 finishWrite(); 00303 } 00304 00305 void RemoteKonnector::slotAddressBookDataReq( KIO::Job *, QByteArray &d ) 00306 { 00307 if ( !mAddressBookData.isEmpty() ) { 00308 d = mAddressBookData.utf8(); 00309 mAddressBookData = QString::null; 00310 } 00311 } 00312 00313 void RemoteKonnector::slotAddressBookWriteResult( KIO::Job *job ) 00314 { 00315 --mSynceeWriteCount; 00316 00317 if ( job->error() ) { 00318 job->showErrorDialog( 0 ); 00319 emit synceeWriteError( this ); 00320 } 00321 00322 finishWrite(); 00323 } 00324 00325 void RemoteKonnector::finishWrite() 00326 { 00327 if ( mSynceeWriteCount > 0 ) return; 00328 00329 emit synceesWritten( this ); 00330 } 00331 00332 00333 #include "remotekonnector.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:32 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003