• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

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 
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(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   // 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(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     // Read-only, just don't save...
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   // the resource identifier is a sane fallback
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 }

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal