libkcal
resourcecalendar.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <kconfig.h>
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028
00029 #include "calendar.h"
00030
00031 #include "resourcecalendar.h"
00032
00033 using namespace KCal;
00034
00035 ResourceCalendar::ResourceCalendar( const KConfig *config )
00036 : KRES::Resource( config ), mResolveConflict( false )
00037 {
00038 mException = 0;
00039 }
00040
00041 ResourceCalendar::~ResourceCalendar()
00042 {
00043 delete mException;
00044 }
00045
00046 void ResourceCalendar::clearException()
00047 {
00048 delete mException;
00049 mException = 0;
00050 }
00051
00052 void ResourceCalendar::setException( ErrorFormat *exception )
00053 {
00054 delete mException;
00055 mException = exception;
00056 }
00057
00058 ErrorFormat *ResourceCalendar::exception()
00059 {
00060 return mException;
00061 }
00062
00063 void ResourceCalendar::setResolveConflict( bool b)
00064 {
00065 mResolveConflict = b;
00066 }
00067
00068 TQString ResourceCalendar::infoText() const
00069 {
00070 TQString txt;
00071
00072 txt += "<b>" + resourceName() + "</b>";
00073 txt += "<br>";
00074
00075 KRES::Factory *factory = KRES::Factory::self( "calendar" );
00076 TQString t = factory->typeName( type() );
00077 txt += i18n("Type: %1").arg( t );
00078
00079 addInfoText( txt );
00080
00081 return txt;
00082 }
00083
00084 void ResourceCalendar::writeConfig( KConfig* config )
00085 {
00086
00087
00088 KRES::Resource::writeConfig( config );
00089 }
00090
00091 Incidence *ResourceCalendar::incidence( const TQString &uid )
00092 {
00093 Incidence *i = event( uid );
00094 if ( i ) return i;
00095 i = todo( uid );
00096 if ( i ) return i;
00097 i = journal( uid );
00098 return i;
00099 }
00100
00101 bool ResourceCalendar::addIncidence( Incidence *incidence )
00102 {
00103 Incidence::AddVisitor<ResourceCalendar> v( this );
00104 return incidence->accept( v );
00105 }
00106
00107 bool ResourceCalendar::addIncidence( Incidence *incidence, const TQString &subresource )
00108 {
00109 Incidence::AddSubResourceVisitor<ResourceCalendar> v( this, subresource );
00110 return incidence->accept( v );
00111 }
00112
00113 bool ResourceCalendar::deleteIncidence( Incidence *incidence )
00114 {
00115 Incidence::DeleteVisitor<ResourceCalendar> v( this );
00116 return incidence->accept( v );
00117 }
00118
00119 Incidence::List ResourceCalendar::rawIncidences()
00120 {
00121 return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() );
00122 }
00123
00124 void ResourceCalendar::setSubresourceActive( const TQString &, bool )
00125 {
00126 }
00127
00128 bool ResourceCalendar::addSubresource( const TQString &, const TQString & )
00129 {
00130 return true;
00131 }
00132
00133 bool ResourceCalendar::removeSubresource( const TQString & )
00134 {
00135 return true;
00136 }
00137
00138 bool ResourceCalendar::load()
00139 {
00140 kdDebug(5800) << "Loading resource " + resourceName() << endl;
00141
00142 mReceivedLoadError = false;
00143
00144 bool success = true;
00145 if ( !isOpen() )
00146 success = open();
00147 if ( success )
00148 success = doLoad();
00149
00150 if ( !success && !mReceivedLoadError )
00151 loadError();
00152
00153
00154
00155
00156 if ( readOnly() ) {
00157 Incidence::List incidences( rawIncidences() );
00158 Incidence::List::Iterator it;
00159 for ( it = incidences.begin(); it != incidences.end(); ++it ) {
00160 (*it)->setReadOnly( true );
00161 }
00162 }
00163
00164 kdDebug(5800) << "Done loading resource " + resourceName() << endl;
00165
00166 return success;
00167 }
00168
00169 void ResourceCalendar::loadError( const TQString &err )
00170 {
00171 kdDebug(5800) << "Error loading resource: " << err << endl;
00172
00173 mReceivedLoadError = true;
00174
00175 TQString msg = i18n("Error while loading %1.\n") .arg( resourceName() );
00176 if ( !err.isEmpty() ) {
00177 msg += err;
00178 }
00179 emit resourceLoadError( this, msg );
00180 }
00181
00182 bool ResourceCalendar::save( Incidence *incidence )
00183 {
00184 if ( !readOnly() ) {
00185 kdDebug(5800) << "Save resource " + resourceName() << endl;
00186
00187 mReceivedSaveError = false;
00188
00189 if ( !isOpen() ) return true;
00190 bool success = incidence ? doSave(incidence) : doSave();
00191 if ( !success && !mReceivedSaveError ) saveError();
00192
00193 return success;
00194 } else {
00195
00196 kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl;
00197 return true;
00198 }
00199 }
00200
00201 bool ResourceCalendar::doSave( Incidence * )
00202 {
00203 return doSave();
00204 }
00205
00206 void ResourceCalendar::saveError( const TQString &err )
00207 {
00208 kdDebug(5800) << "Error saving resource: " << err << endl;
00209
00210 mReceivedSaveError = true;
00211
00212 TQString msg = i18n("Error while saving %1.\n") .arg( resourceName() );
00213 if ( !err.isEmpty() ) {
00214 msg += err;
00215 }
00216 emit resourceSaveError( this, msg );
00217 }
00218
00219 bool ResourceCalendar::setValue( const TQString &key, const TQString &value )
00220 {
00221 Q_UNUSED( key );
00222 Q_UNUSED( value );
00223 return false;
00224 }
00225
00226 TQString ResourceCalendar::subresourceType( const TQString &resource )
00227 {
00228 Q_UNUSED( resource );
00229 return TQString();
00230 }
00231
00232 bool ResourceCalendar::subresourceWritable( const TQString &resource ) const
00233 {
00234 if ( resource.isEmpty() ) {
00235 return !readOnly();
00236 } else {
00237 return false;
00238 }
00239 }
00240
00241 void ResourceCalendar::beginAddingIncidences()
00242 {
00243 }
00244
00245 void ResourceCalendar::endAddingIncidences()
00246 {
00247 }
00248
00249 #include "resourcecalendar.moc"
|