kcalkonnector.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 );
00088 caps.setSupportsPushSync( false );
00089 caps.setNeedsConnection( false );
00090 caps.setSupportsListDir( false );
00091 caps.setNeedsIPs( false );
00092 caps.setNeedsSrcIP( false );
00093 caps.setNeedsDestIP( false );
00094 caps.setAutoHandle( false );
00095 caps.setNeedAuthentication( false );
00096 caps.setNeedsModelName( false );
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"
This file is part of the documentation for kitchensync Library Version 3.3.2.