KCal Library
resourcecalendar.cpp
00001
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 "resourcecalendar.h"
00026
00027 #include <kconfig.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030
00031 #include "resourcecalendar.moc"
00032
00033 using namespace KCal;
00034
00035
00036 class ResourceCalendar::Private
00037 {
00038 public:
00039 Private()
00040 : mResolveConflict( false ),
00041 mNoReadOnlyOnLoad( false ),
00042 mInhibitSave( false )
00043 {}
00044 bool mResolveConflict;
00045 bool mNoReadOnlyOnLoad;
00046 bool mInhibitSave;
00047 bool mReceivedLoadError;
00048 bool mReceivedSaveError;
00049
00050 };
00051
00052
00053 ResourceCalendar::ResourceCalendar()
00054 : KRES::Resource(), d( new Private )
00055 {
00056 }
00057
00058 ResourceCalendar::ResourceCalendar( const KConfigGroup &group )
00059 : KRES::Resource( group ),
00060 d( new Private )
00061 {
00062 }
00063
00064 ResourceCalendar::~ResourceCalendar()
00065 {
00066 delete d;
00067 }
00068
00069 bool ResourceCalendar::isResolveConflictSet() const
00070 {
00071 return d->mResolveConflict;
00072 }
00073
00074 void ResourceCalendar::setResolveConflict( bool b )
00075 {
00076 d->mResolveConflict = b;
00077 }
00078
00079 QString ResourceCalendar::infoText() const
00080 {
00081 QString txt;
00082
00083 txt += "<b>" + resourceName() + "</b>";
00084 txt += "<br>";
00085
00086 KRES::Factory *factory = KRES::Factory::self( "calendar" );
00087 QString t = factory->typeName( type() );
00088 txt += i18n( "Type: %1", t );
00089
00090 addInfoText( txt );
00091
00092 return txt;
00093 }
00094
00095 void ResourceCalendar::writeConfig( KConfigGroup &group )
00096 {
00097 KRES::Resource::writeConfig( group );
00098 }
00099
00100 Incidence *ResourceCalendar::incidence( const QString &uid )
00101 {
00102 Incidence *i = event( uid );
00103 if ( i ) {
00104 return i;
00105 }
00106
00107 i = todo( uid );
00108 if ( i ) {
00109 return i;
00110 }
00111
00112 i = journal( uid );
00113 return i;
00114 }
00115
00116 bool ResourceCalendar::addIncidence( Incidence *incidence )
00117 {
00118 Incidence::AddVisitor<ResourceCalendar> v( this );
00119 return incidence->accept( v );
00120 }
00121
00122 bool ResourceCalendar::deleteIncidence( Incidence *incidence )
00123 {
00124 Incidence::DeleteVisitor<ResourceCalendar> v( this );
00125 return incidence->accept( v );
00126 }
00127
00128 Incidence::List ResourceCalendar::rawIncidences()
00129 {
00130 return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() );
00131 }
00132
00133 void ResourceCalendar::setSubresourceActive( const QString &, bool )
00134 {
00135 }
00136
00137 bool ResourceCalendar::removeSubresource( const QString &resource )
00138 {
00139 Q_UNUSED( resource )
00140 return true;
00141 }
00142
00143 bool ResourceCalendar::addSubresource( const QString &resource, const QString &parent )
00144 {
00145 Q_UNUSED( resource )
00146 Q_UNUSED( parent )
00147 return true;
00148 }
00149
00150 QString ResourceCalendar::subresourceType( const QString &resource )
00151 {
00152 Q_UNUSED( resource )
00153 return QString();
00154 }
00155
00156 bool ResourceCalendar::load()
00157 {
00158 kDebug(5800) << "Loading resource" << resourceName();
00159
00160 d->mReceivedLoadError = false;
00161
00162 bool success = true;
00163 if ( !isOpen() ) {
00164 success = open();
00165 }
00166 if ( success ) {
00167 success = doLoad( false );
00168 }
00169 if ( !success && !d->mReceivedLoadError ) {
00170 loadError();
00171 }
00172
00173
00174
00175
00176 if ( !d->mNoReadOnlyOnLoad && readOnly() ) {
00177 Incidence::List incidences( rawIncidences() );
00178 Incidence::List::Iterator it;
00179 for ( it = incidences.begin(); it != incidences.end(); ++it ) {
00180 (*it)->setReadOnly( true );
00181 }
00182 }
00183
00184 kDebug(5800) << "Done loading resource" << resourceName();
00185
00186 return success;
00187 }
00188
00189 void ResourceCalendar::loadError( const QString &err )
00190 {
00191 kDebug(5800) << "Error loading resource:" << err;
00192
00193 d->mReceivedLoadError = true;
00194
00195 QString msg = i18n( "Error while loading %1.\n", resourceName() );
00196 if ( !err.isEmpty() ) {
00197 msg += err;
00198 }
00199 emit resourceLoadError( this, msg );
00200 }
00201
00202 bool ResourceCalendar::receivedLoadError() const
00203 {
00204 return d->mReceivedLoadError;
00205 }
00206
00207 void ResourceCalendar::setReceivedLoadError( bool b )
00208 {
00209 d->mReceivedLoadError = b;
00210 }
00211
00212 bool ResourceCalendar::save( Incidence *incidence )
00213 {
00214 if ( d->mInhibitSave ) {
00215 return true;
00216 }
00217
00218 if ( !readOnly() ) {
00219 kDebug(5800) << "Save resource" << resourceName();
00220
00221 d->mReceivedSaveError = false;
00222
00223 if ( !isOpen() ) {
00224 kDebug(5800) << "Trying to save into a closed resource" << resourceName();
00225 return true;
00226 }
00227 bool success = incidence ? doSave( false, incidence ) : doSave( false );
00228 if ( !success && !d->mReceivedSaveError ) {
00229 saveError();
00230 }
00231 return success;
00232 } else {
00233
00234 kDebug(5800) << "Don't save read-only resource" << resourceName();
00235 return true;
00236 }
00237 }
00238
00239 bool ResourceCalendar::isSaving()
00240 {
00241 return false;
00242 }
00243
00244 bool ResourceCalendar::doSave( bool syncCache, Incidence *incidence )
00245 {
00246 return doSave( syncCache, incidence );
00247 }
00248
00249 void ResourceCalendar::saveError( const QString &err )
00250 {
00251 kDebug(5800) << "Error saving resource:" << err;
00252
00253 d->mReceivedSaveError = true;
00254 QString msg = i18n( "Error while saving %1.\n", resourceName() );
00255 if ( !err.isEmpty() ) {
00256 msg += err;
00257 }
00258 emit resourceSaveError( this, msg );
00259 }
00260
00261 QStringList ResourceCalendar::subresources() const
00262 {
00263 return QStringList();
00264 }
00265
00266 bool ResourceCalendar::canHaveSubresources() const
00267 {
00268 return false;
00269 }
00270
00271 bool ResourceCalendar::subresourceActive( const QString &resource ) const
00272 {
00273 Q_UNUSED( resource );
00274 return true;
00275 }
00276
00277 QString ResourceCalendar::labelForSubresource( const QString &resource ) const
00278 {
00279
00280 return resource;
00281 }
00282
00283 QString ResourceCalendar::subresourceIdentifier( Incidence *incidence )
00284 {
00285 Q_UNUSED( incidence );
00286 return QString();
00287 }
00288
00289 bool ResourceCalendar::receivedSaveError() const
00290 {
00291 return d->mReceivedSaveError;
00292 }
00293
00294 void ResourceCalendar::setReceivedSaveError( bool b )
00295 {
00296 d->mReceivedSaveError = b;
00297 }
00298
00299 void ResourceCalendar::setInhibitSave( bool inhibit )
00300 {
00301 d->mInhibitSave = inhibit;
00302 }
00303
00304 bool ResourceCalendar::saveInhibited() const
00305 {
00306 return d->mInhibitSave;
00307 }
00308
00309 bool ResourceCalendar::setValue( const QString &key, const QString &value )
00310 {
00311 Q_UNUSED( key );
00312 Q_UNUSED( value );
00313 return false;
00314 }
00315
00316 void ResourceCalendar::setNoReadOnlyOnLoad( bool noReadOnly )
00317 {
00318 d->mNoReadOnlyOnLoad = noReadOnly;
00319 }
00320
00321 bool ResourceCalendar::noReadOnlyOnLoad() const
00322 {
00323 return d->mNoReadOnlyOnLoad;
00324 }