kitchensync Library API Documentation

kcalkonnector.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 <calendarsyncee.h> 00023 00024 #include <kapabilities.h> 00025 #include <kconfig.h> 00026 #include <kgenericfactory.h> 00027 #include <konnectorinfo.h> 00028 #include <libkcal/resourcecalendar.h> 00029 #include <libkdepim/kpimprefs.h> 00030 00031 #include "kcalkonnector.h" 00032 #include "kcalkonnectorconfig.h" 00033 00034 using namespace KSync; 00035 00036 extern "C" 00037 { 00038 void *init_libkcalkonnector() 00039 { 00040 return new KRES::PluginFactory<KCalKonnector,KCalKonnectorConfig>(); 00041 } 00042 } 00043 00044 00045 KCalKonnector::KCalKonnector( const KConfig *config ) 00046 : Konnector( config ), mConfigWidget( 0 ), mResource( 0 ) 00047 { 00048 if ( config ) { 00049 mResourceIdentifier = config->readEntry( "CurrentResource" ); 00050 } 00051 00052 mCalendar = new KCal::CalendarResources( KPimPrefs::timezone() ); 00053 00054 mResource = createResource( mResourceIdentifier ); 00055 00056 if ( mResource ) { 00057 mCalendar->resourceManager()->add( mResource ); 00058 connect( mResource, SIGNAL( resourceLoaded( ResourceCalendar* ) ), 00059 SLOT( loadingFinished() ) ); 00060 connect( mResource, SIGNAL( resourceSaved( ResourceCalendar* ) ), 00061 SLOT( savingFinished() ) ); 00062 00063 mCalendarSyncee = new CalendarSyncee( mCalendar ); 00064 mCalendarSyncee->setSource( i18n( "Calendar" ) ); 00065 mCalendarSyncee->setIdentifier( "calendar" ); 00066 00067 mSyncees.append( mCalendarSyncee ); 00068 } 00069 } 00070 00071 KCalKonnector::~KCalKonnector() 00072 { 00073 delete mCalendar; 00074 } 00075 00076 void KCalKonnector::writeConfig( KConfig *config ) 00077 { 00078 Konnector::writeConfig( config ); 00079 00080 config->writeEntry( "CurrentResource", mResourceIdentifier ); 00081 } 00082 00083 KSync::Kapabilities KCalKonnector::capabilities() 00084 { 00085 KSync::Kapabilities caps; 00086 00087 caps.setSupportMetaSyncing( false ); // we can meta sync 00088 caps.setSupportsPushSync( false ); // we can initialize the sync from here 00089 caps.setNeedsConnection( false ); // we need to have pppd running 00090 caps.setSupportsListDir( false ); // we will support that once there is API for it... 00091 caps.setNeedsIPs( false ); // we need the IP 00092 caps.setNeedsSrcIP( false ); // we do not bind to any address... 00093 caps.setNeedsDestIP( false ); // we need to know where to connect 00094 caps.setAutoHandle( false ); // we currently do not support auto handling 00095 caps.setNeedAuthentication( false ); // HennevL says we do not need that 00096 caps.setNeedsModelName( false ); // we need a name for our meta path! 00097 00098 return caps; 00099 } 00100 00101 void KCalKonnector::setCapabilities( const KSync::Kapabilities& ) 00102 { 00103 } 00104 00105 bool KCalKonnector::readSyncees() 00106 { 00107 if ( mCalendar->resourceManager()->isEmpty() ) 00108 return false; 00109 00110 mCalendarSyncee->reset(); 00111 00112 mCalendar->close(); 00113 mCalendar->load(); 00114 00115 return true; 00116 } 00117 00118 bool KCalKonnector::connectDevice() 00119 { 00120 return true; 00121 } 00122 00123 bool KCalKonnector::disconnectDevice() 00124 { 00125 return true; 00126 } 00127 00128 KSync::KonnectorInfo KCalKonnector::info() const 00129 { 00130 return KonnectorInfo( i18n( "Calendar Konnector" ), 00131 QIconSet(), 00132 QString::fromLatin1( "KCalKonnector" ), 00133 "Calendar Konnector", 00134 "korganizer", 00135 false ); 00136 } 00137 00138 void KCalKonnector::download( const QString& ) 00139 { 00140 error( StdError::downloadNotSupported() ); 00141 } 00142 00143 bool KCalKonnector::writeSyncees() 00144 { 00145 if ( mCalendar->resourceManager()->isEmpty() ) 00146 return false; 00147 00148 KCal::CalendarResources::Ticket *ticket = mCalendar->requestSaveTicket( mResource ); 00149 if ( !ticket ) { 00150 kdWarning() << "KCalKonnector::writeSyncees(). Couldn't get ticket for resource." << endl; 00151 return false; 00152 } 00153 00154 mCalendar->save( ticket ); 00155 00156 return true; 00157 } 00158 00159 void KCalKonnector::loadingFinished() 00160 { 00161 emit synceesRead( this ); 00162 } 00163 00164 void KCalKonnector::savingFinished() 00165 { 00166 emit synceesWritten( this ); 00167 } 00168 00169 KCal::ResourceCalendar* KCalKonnector::createResource( const QString &identifier ) 00170 { 00171 KConfig config( "kresources/calendar/stdrc" ); 00172 00173 config.setGroup( "General" ); 00174 QStringList activeKeys = config.readListEntry( "ResourceKeys" ); 00175 if ( !activeKeys.contains( identifier ) ) 00176 return 0; 00177 00178 KRES::Factory *factory = KRES::Factory::self( "calendar" ); 00179 config.setGroup( "Resource_" + identifier ); 00180 00181 QString type = config.readEntry( "ResourceType" ); 00182 QString name = config.readEntry( "ResourceName" ); 00183 KCal::ResourceCalendar *resource = dynamic_cast<KCal::ResourceCalendar*>( factory->resource( type, &config ) ); 00184 if ( !resource ) { 00185 kdError() << "Failed to create resource with id " << identifier << endl; 00186 return 0; 00187 } 00188 00189 return resource; 00190 } 00191 00192 #include "kcalkonnector.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 Fri Oct 1 15:18:59 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003