KCal Library
resourcecalendar.cpp
00001 /* 00002 This file is part of the kcal library. 00003 00004 Copyright (c) 1998 Preston Brown <pbrown@kde.org> 00005 Copyright (c) 2001-2004 Cornelius Schumacher <schumacher@kde.org> 00006 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 00007 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Library General Public 00011 License as published by the Free Software Foundation; either 00012 version 2 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Library General Public License for more details. 00018 00019 You should have received a copy of the GNU Library General Public License 00020 along with this library; see the file COPYING.LIB. If not, write to 00021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00022 Boston, MA 02110-1301, USA. 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 //@cond PRIVATE 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; // true to prevent saves 00047 bool mReceivedLoadError; 00048 bool mReceivedSaveError; 00049 QString mLastError; 00050 }; 00051 //@endcond 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() << resourceName(); 00159 00160 d->mReceivedLoadError = false; 00161 00162 bool success = true; 00163 if ( !isOpen() ) { 00164 success = open(); //krazy:exclude=syscalls open is a class method 00165 } 00166 if ( success ) { 00167 success = doLoad( false ); 00168 } 00169 if ( !success && !d->mReceivedLoadError ) { 00170 loadError(); 00171 } 00172 00173 // If the resource is read-only, we need to set its incidences to read-only, 00174 // too. This can't be done at a lower-level, since the read-only setting 00175 // happens at this level 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() << "Done loading resource" << resourceName(); 00185 00186 return success; 00187 } 00188 00189 void ResourceCalendar::loadError( const QString &err ) 00190 { 00191 kDebug() << "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() << resourceName(); 00220 00221 d->mReceivedSaveError = false; 00222 00223 if ( !isOpen() ) { 00224 kDebug() << "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 // Read-only, just don't save... 00234 kDebug() << "Don't save read-only resource" << resourceName(); 00235 return true; 00236 } 00237 } 00238 00239 bool ResourceCalendar::save( QString &err, Incidence *incidence ) 00240 { 00241 d->mLastError.clear(); 00242 bool ret = save( incidence ); // a new mLastError may be set in here 00243 err = d->mLastError; 00244 return ret; 00245 } 00246 00247 bool ResourceCalendar::isSaving() 00248 { 00249 return false; 00250 } 00251 00252 bool ResourceCalendar::doSave( bool syncCache, Incidence *incidence ) 00253 { 00254 Q_UNUSED( incidence ); 00255 return doSave( syncCache ); 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 // the resource identifier is a sane fallback 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 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:53 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:53 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.