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