• Skip to content
  • Skip to link menu
KDE 4.3 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     QString mLastError;
00050 
00051 };
00052 //@endcond
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(); //krazy:exclude=syscalls open is a class method
00166   }
00167   if ( success ) {
00168     success = doLoad( false );
00169   }
00170   if ( !success && !d->mReceivedLoadError ) {
00171     loadError();
00172   }
00173 
00174   // If the resource is read-only, we need to set its incidences to read-only,
00175   // too. This can't be done at a lower-level, since the read-only setting
00176   // happens at this level
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     // Read-only, just don't save...
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.clear();
00243   bool ret = save( incidence ); // a new mLastError may be set in here
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   Q_UNUSED( incidence );
00256   return doSave( syncCache );
00257 }
00258 
00259 void ResourceCalendar::saveError( const QString &err )
00260 {
00261   kDebug() << "Error saving resource:" << err;
00262 
00263   d->mReceivedSaveError = true;
00264   QString msg = i18n( "Error while saving %1.\n", resourceName() );
00265   if ( !err.isEmpty() ) {
00266     msg += err;
00267   }
00268   d->mLastError = err;
00269   emit resourceSaveError( this, msg );
00270 }
00271 
00272 QStringList ResourceCalendar::subresources() const
00273 {
00274   return QStringList();
00275 }
00276 
00277 bool ResourceCalendar::canHaveSubresources() const
00278 {
00279   return false;
00280 }
00281 
00282 bool ResourceCalendar::subresourceActive( const QString &resource ) const
00283 {
00284   Q_UNUSED( resource );
00285   return true;
00286 }
00287 
00288 QString ResourceCalendar::labelForSubresource( const QString &resource ) const
00289 {
00290   // the resource identifier is a sane fallback
00291   return resource;
00292 }
00293 
00294 QString ResourceCalendar::subresourceIdentifier( Incidence *incidence )
00295 {
00296   Q_UNUSED( incidence );
00297   return QString();
00298 }
00299 
00300 bool ResourceCalendar::receivedSaveError() const
00301 {
00302   return d->mReceivedSaveError;
00303 }
00304 
00305 void ResourceCalendar::setReceivedSaveError( bool b )
00306 {
00307   d->mReceivedSaveError = b;
00308 }
00309 
00310 void ResourceCalendar::setInhibitSave( bool inhibit )
00311 {
00312   d->mInhibitSave = inhibit;
00313 }
00314 
00315 bool ResourceCalendar::saveInhibited() const
00316 {
00317   return d->mInhibitSave;
00318 }
00319 
00320 bool ResourceCalendar::setValue( const QString &key, const QString &value )
00321 {
00322   Q_UNUSED( key );
00323   Q_UNUSED( value );
00324   return false;
00325 }
00326 
00327 void ResourceCalendar::setNoReadOnlyOnLoad( bool noReadOnly )
00328 {
00329   d->mNoReadOnlyOnLoad = noReadOnly;
00330 }
00331 
00332 bool ResourceCalendar::noReadOnlyOnLoad() const
00333 {
00334   return d->mNoReadOnlyOnLoad;
00335 }

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"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.8
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