diff --git a/kcal/assignmentvisitor_p.h b/kcal/assignmentvisitor_p.h new file mode 100755 index 000000000..6bba6c843 --- /dev/null +++ b/kcal/assignmentvisitor_p.h @@ -0,0 +1,128 @@ +/* + Copyright (c) 2009 Kevin Krammer + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef KCAL_ASSIGNMENTVISITOR_H +#define KCAL_ASSIGNMENTVISITOR_H + +#include "kcal_export.h" + +#include "incidencebase.h" + +namespace KCal { + +/** + Helper for type correct assignment of incidences via pointers. + + This class provides a way of correctly assigning one incidence to another, + given two IncidenceBase derived pointers. It effectively provides a virtual + assignment method which first type checks the two pointers to ensure they + reference the same incidence type, before performing the assignment. + + Usage example: + @code + KCal::Incidence *currentIncidence; // assume this is set somewhere else + KCal::Incidence *updatedIncidence; // assume this is set somewhere else + + KCal::AssignmentVisitor visitor; + + // assign + if ( !visitor.assign(currentIncidence, updatedIncidence) ) { + // not of same type + } + @endcode + + @author Kevin Krammer \ + + @since 4.3 + */ +class KCAL_EXPORT AssignmentVisitor : public IncidenceBase::Visitor +{ + public: + /** + Creates a visitor instance. + */ + AssignmentVisitor(); + + /** + Destroys the instance. + */ + virtual ~AssignmentVisitor(); + + /** + Assigns the incidence referenced by @p source to the incidence referenced + by @p target, first ensuring that the @p source incidence can be cast to + the same class as the @p target incidence. + + Basically it is a virtual equivalent of + @code + *target = *source + @endcode + + @param target pointer to the instance to assign to + @param source pointer to the instance to assign from + + @return @c false if the two objects are of different type + */ + bool assign( IncidenceBase *target, const IncidenceBase *source ); + + /** + Tries to assign to the given @p event, using the source passed to + assign(). + + @return @c false if the source passed to assign() is not an Event + */ + virtual bool visit( Event *event ); + + /** + Tries to assign to the given @p todo, using the source passed to + assign(). + + @return @c false if the source passed to assign() is not a Todo + */ + virtual bool visit( Todo *todo ); + + /** + Tries to assign to the given @p journal, using the source passed to + assign(). + + @return @c false if the source passed to assign() is not a Journal + */ + virtual bool visit( Journal *journal ); + + /** + Tries to assign to the given @p freebusy, using the source passed to + assign(). + + @return @c false if the source passed to assign() is not a FreeBusy + */ + virtual bool visit( FreeBusy *freebusy ); + + private: + //@cond PRIVATE + class Private; + Private *const d; + //@endcond + + Q_DISABLE_COPY( AssignmentVisitor ) +}; + +} + +#endif +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kcal/comparisonvisitor_p.h b/kcal/comparisonvisitor_p.h new file mode 100644 index 000000000..4fff997e1 --- /dev/null +++ b/kcal/comparisonvisitor_p.h @@ -0,0 +1,127 @@ +/* + Copyright 2009 Ingo Klöcker + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef KCAL_COMPARISONVISITOR_H +#define KCAL_COMPARISONVISITOR_H + +#include "kcal_export.h" +#include "incidencebase.h" + +namespace KCal { + +/** + Helper for type correct comparison of incidences via pointers. + + This class provides a way of correctly comparing one incidence to another, + given two IncidenceBase derived pointers. It effectively provides a virtual + comparison method which first type checks the two pointers to ensure they + reference the same incidence type, before performing the comparison. + + Usage example: + @code + KCal::Incidence *incidence; // assume this is set somewhere else + KCal::Incidence *referenceIncidence; // assume this is set somewhere else + + KCal::ComparisonVisitor visitor; + + // compare + if ( visitor.compare( incidence, referenceIncidence ) ) { + // incidence and referenceIncidence point to identical incidences + } + @endcode + + @author Ingo Klöcker + + @since 4.3 + */ +class KCAL_EXPORT ComparisonVisitor : public IncidenceBase::Visitor +{ + public: + /** + Creates a visitor instance. + */ + ComparisonVisitor(); + + /** + Destroys the instance. + */ + virtual ~ComparisonVisitor(); + + /** + Compares the incidence referenced by @p incidence to the incidence + referenced by @p reference. Returns true, if the incidence referenced + by @p incidence is identical to the incidence referenced by @p reference. + Also returns true, if @p incidence and @p reference are both @c 0. + + Basically it is a virtual equivalent of + @code + *incidence == *reference + @endcode + + @param incidence pointer to the incidence to compare with the reference incidence + @param reference pointer to the reference incidence + + @return @c true if the two incidences are identical or both @c 0 + */ + bool compare( IncidenceBase *incidence, const IncidenceBase *reference ); + + /** + Compares the event referenced by @p event to the incidence passed to + compare(). + + @return @c true if the event is identical to the reference incidence + */ + virtual bool visit( Event *event ); + + /** + Compares the todo referenced by @p todo to the incidence passed to + compare(). + + @return @c true if the todo is identical to the reference incidence + */ + virtual bool visit( Todo *todo ); + + /** + Compares the journal referenced by @p journal to the incidence passed to + compare(). + + @return @c true if the journal is identical to the reference incidence + */ + virtual bool visit( Journal *journal ); + + /** + Compares the freebusy object referenced by @p freebusy to the incidence passed to + compare(). + + @return @c true if the freebusy object is identical to the reference incidence + */ + virtual bool visit( FreeBusy *freebusy ); + + private: + //@cond PRIVATE + class Private; + Private *const d; + //@endcond + + Q_DISABLE_COPY( ComparisonVisitor ) +}; + +} + +#endif // KCAL_COMPARISONVISITOR_H diff --git a/kcal/resourcelocaldir.cpp b/kcal/resourcelocaldir.cpp index 5dcbbebee..0eb22ad97 100644 --- a/kcal/resourcelocaldir.cpp +++ b/kcal/resourcelocaldir.cpp @@ -1,314 +1,573 @@ /* This file is part of the kcal library. Copyright (c) 2003 Cornelius Schumacher + Copyright (c) 2009 Sergio Martins This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "resourcelocaldir.h" #include "resourcelocaldir_p.h" #include "calendarlocal.h" #include "incidence.h" #include "event.h" #include "todo.h" #include "journal.h" +#include "freebusy.h" #include "kresources/configwidget.h" +#include "assignmentvisitor_p.h" +#include "comparisonvisitor_p.h" #include #include #include #include #include #include #include #include #include #include #include "resourcelocaldir.moc" +#include "resourcelocaldir_p.moc" using namespace KCal; ResourceLocalDir::ResourceLocalDir() - : ResourceCached(), d( new KCal::ResourceLocalDir::Private ) + : ResourceCached(), d( new KCal::ResourceLocalDir::Private( this ) ) { - d->init( this ); + d->init(); } ResourceLocalDir::ResourceLocalDir( const KConfigGroup &group ) - : ResourceCached( group ), d( new KCal::ResourceLocalDir::Private ) + : ResourceCached( group ), d( new KCal::ResourceLocalDir::Private( this ) ) { readConfig( group ); - d->init( this ); + d->init(); } ResourceLocalDir::ResourceLocalDir( const QString &dirName ) - : ResourceCached(), d( new KCal::ResourceLocalDir::Private( dirName ) ) + : ResourceCached(), d( new KCal::ResourceLocalDir::Private( dirName, this ) ) { - d->init( this ); + d->init(); } void ResourceLocalDir::readConfig( const KConfigGroup &group ) { QString url = group.readPathEntry( "CalendarURL", QString() ); d->mURL = KUrl( url ); } void ResourceLocalDir::writeConfig( KConfigGroup &group ) { kDebug(); ResourceCalendar::writeConfig( group ); group.writePathEntry( "CalendarURL", d->mURL.prettyUrl() ); } -void ResourceLocalDir::Private::init( ResourceLocalDir *rdir ) +void ResourceLocalDir::Private::init( ) { - rdir->setType( "dir" ); + mResource->setType( "dir" ); - rdir->setSavePolicy( SaveDelayed ); + mResource->setSavePolicy( SaveDelayed ); - rdir->connect( &mDirWatch, SIGNAL( dirty( const QString & ) ), - SLOT( reload( const QString & ) ) ); - rdir->connect( &mDirWatch, SIGNAL( created( const QString & ) ), - SLOT( reload( const QString & ) ) ); - rdir->connect( &mDirWatch, SIGNAL( deleted( const QString & ) ), - SLOT( reload( const QString & ) ) ); + connect( &mDirWatch, SIGNAL( dirty( const QString & ) ), + this, SLOT( updateIncidenceInCalendar( const QString & ) ) ); + connect( &mDirWatch, SIGNAL( created( const QString & ) ), + this, SLOT( addIncidenceToCalendar( const QString & ) ) ); + connect( &mDirWatch, SIGNAL( deleted( const QString & ) ), + this, SLOT( deleteIncidenceFromCalendar( const QString & ) ) ); + + connect ( this, SIGNAL(resourceChanged( ResourceCalendar *)), + mResource, SIGNAL(resourceChanged( ResourceCalendar *)) ); mLock = new KABC::Lock( mURL.path() ); mDirWatch.addDir( mURL.path(), KDirWatch::WatchFiles ); mDirWatch.startScan(); } ResourceLocalDir::~ResourceLocalDir() { close(); delete d->mLock; delete d; } bool ResourceLocalDir::doOpen() { QFileInfo dirInfo( d->mURL.path() ); return dirInfo.isDir() && dirInfo.isReadable() && ( dirInfo.isWritable() || readOnly() ); } bool ResourceLocalDir::doLoad( bool ) { kDebug(); calendar()->close(); QString dirName = d->mURL.path(); if ( !( KStandardDirs::exists( dirName ) || KStandardDirs::exists( dirName + '/' ) ) ) { kDebug() << "Directory '" << dirName << "' doesn't exist yet. Creating it."; // Create the directory. Use 0775 to allow group-writable if the umask // allows it (permissions will be 0775 & ~umask). This is desired e.g. for // group-shared directories! return KStandardDirs::makeDir( dirName, 0775 ); } // The directory exists. Now try to open (the files in) it. kDebug() << dirName; QFileInfo dirInfo( dirName ); if ( !( dirInfo.isDir() && dirInfo.isReadable() && ( dirInfo.isWritable() || readOnly() ) ) ) return false; QDir dir( dirName ); const QStringList entries = dir.entryList( QDir::Files | QDir::Readable ); bool success = true; - for ( int i = 0, count = entries.count(); i < count; ++i ) { - if ( entries[i].contains( QRegExp( "(~|\\.new|\\.tmp)$" ) ) || - entries[i].startsWith( d->mURL.path() + "/qt_temp." ) ) { + + foreach ( const QString &entry, entries ) { + if ( d->isTempFile( entry ) ) { continue; // backup or temporary file, ignore it } - const QString fileName = dirName + '/' + entries[i]; + const QString fileName = dirName + '/' + entry; kDebug() << " read '" << fileName << "'"; CalendarLocal cal( calendar()->timeSpec() ); if ( !doFileLoad( cal, fileName ) ) { success = false; } } return success; } bool ResourceLocalDir::doFileLoad( CalendarLocal &cal, const QString &fileName ) { - if ( !cal.load( fileName ) ) { - return false; - } - Incidence::List incidences = cal.rawIncidences(); - Incidence::List::ConstIterator it; - for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) { - Incidence *i = *it; - if ( i ) { - calendar()->addIncidence( i->clone() ); - } - } - return true; + return d->doFileLoad( cal, fileName, false ); } bool ResourceLocalDir::doSave( bool syncCache ) { Q_UNUSED( syncCache ); Incidence::List list; bool success = true; list = addedIncidences(); list += changedIncidences(); for ( Incidence::List::iterator it = list.begin(); it != list.end(); ++it ) { if ( !doSave( *it ) ) { success = false; } } return success; } bool ResourceLocalDir::doSave( bool, Incidence *incidence ) { if ( d->mDeletedIncidences.contains( incidence ) ) { d->mDeletedIncidences.removeAll( incidence ); return true; } d->mDirWatch.stopScan(); // do prohibit the dirty() signal and a following reload() QString fileName = d->mURL.path() + '/' + incidence->uid(); kDebug() << "writing '" << fileName << "'"; CalendarLocal cal( calendar()->timeSpec() ); cal.addIncidence( incidence->clone() ); const bool ret = cal.save( fileName ); d->mDirWatch.startScan(); return ret; } KABC::Lock *ResourceLocalDir::lock() { return d->mLock; } void ResourceLocalDir::reload( const QString &file ) { - kDebug(); - - if ( !isOpen() || - file.contains( QRegExp( "(~|\\.new|\\.tmp)$" ) ) || - file.startsWith( d->mURL.path() + "/qt_temp." ) ) { - return; - } - - kDebug() << " File: '" << file << "'"; - - calendar()->close(); - load(); - - emit resourceChanged( this ); + Q_UNUSED( file ); } bool ResourceLocalDir::deleteEvent( Event *event ) { kDebug(); if ( d->deleteIncidenceFile( event ) ) { if ( calendar()->deleteEvent( event ) ) { d->mDeletedIncidences.append( event ); return true; } else { return false; } } else { return false; } } void ResourceLocalDir::deleteAllEvents() { calendar()->deleteAllEvents(); } bool ResourceLocalDir::deleteTodo( Todo *todo ) { if ( d->deleteIncidenceFile( todo ) ) { if ( calendar()->deleteTodo( todo ) ) { d->mDeletedIncidences.append( todo ); return true; } else { return false; } } else { return false; } } void ResourceLocalDir::deleteAllTodos() { calendar()->deleteAllTodos(); } bool ResourceLocalDir::deleteJournal( Journal *journal ) { if ( d->deleteIncidenceFile( journal ) ) { if ( calendar()->deleteJournal( journal ) ) { d->mDeletedIncidences.append( journal ); return true; } else { return false; } } else { return false; } } void ResourceLocalDir::deleteAllJournals() { calendar()->deleteAllJournals(); } void ResourceLocalDir::dump() const { ResourceCalendar::dump(); kDebug() << " Url:" << d->mURL.url(); } bool ResourceLocalDir::Private::deleteIncidenceFile( Incidence *incidence ) { QFile file( mURL.path() + '/' + incidence->uid() ); if ( !file.exists() ) { return true; } mDirWatch.stopScan(); bool removed = file.remove(); mDirWatch.startScan(); return removed; } + +bool ResourceLocalDir::Private::isTempFile( const QString &fileName ) const +{ + return + fileName.contains( QRegExp( "(~|\\.new|\\.tmp)$" ) ) || + QFileInfo( fileName ).fileName().startsWith( QLatin1String( "qt_temp." ) ) || + fileName == mURL.path(); +} + +void ResourceLocalDir::Private::addIncidenceToCalendar( const QString &file ) +{ + + if ( mResource->isOpen() && + !isTempFile( file ) && + !mResource->calendar()->incidence( getUidFromFileName( file ) ) ) { + + CalendarLocal cal( mResource->calendar()->timeSpec() ); + if ( doFileLoad( cal, file, true ) ) { + emit resourceChanged( mResource ); + } + } +} + +void ResourceLocalDir::Private::updateIncidenceInCalendar( const QString &file ) +{ + if ( mResource->isOpen() && !isTempFile( file ) ) { + CalendarLocal cal( mResource->calendar()->timeSpec() ); + if ( doFileLoad( cal, file, true ) ) { + emit resourceChanged( mResource ); + } + } +} + +QString ResourceLocalDir::Private::getUidFromFileName( const QString &fileName ) +{ + return QFileInfo( fileName ).fileName(); +} + +void ResourceLocalDir::Private::deleteIncidenceFromCalendar( const QString &file ) +{ + + if ( mResource->isOpen() && !isTempFile( file ) ) { + Incidence *inc = mResource->calendar()->incidence( getUidFromFileName( file ) ); + + if ( inc ) { + mResource->calendar()->deleteIncidence( inc ); + emit resourceChanged( mResource ); + } + } +} + +bool ResourceLocalDir::Private::doFileLoad( CalendarLocal &cal, + const QString &fileName, + const bool replace ) +{ + if ( !cal.load( fileName ) ) { + return false; + } + Incidence::List incidences = cal.rawIncidences(); + Incidence::List::ConstIterator it; + Incidence *inc; + ComparisonVisitor compVisitor; + AssignmentVisitor assVisitor; + for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) { + Incidence *i = *it; + if ( i ) { + // should we replace, and does the incidence exist in calendar? + if ( replace && ( inc = mResource->calendar()->incidence( i->uid() ) ) ) { + if ( compVisitor.compare( i, inc ) ) { + // no need to do anything + return false; + } else { + inc->startUpdates(); + + bool assignResult = assVisitor.assign( inc, i ); + + if ( assignResult ) { + if ( !inc->relatedToUid().isEmpty() ) { + QString uid = inc->relatedToUid(); + inc->setRelatedTo( mResource->calendar()->incidence( uid ) ); + } + inc->updated(); + inc->endUpdates(); + } else { + inc->endUpdates(); + kWarning() << "Incidence (uid=" << inc->uid() + << ", summary=" << inc->summary() + << ") changed type. Replacing it."; + + mResource->calendar()->deleteIncidence( inc ); + delete inc; + mResource->calendar()->addIncidence( i->clone() ); + } + } + } else { + mResource->calendar()->addIncidence( i->clone() ); + } + } + } + return true; +} + +class AssignmentVisitor::Private +{ + public: + Private() : mSource( 0 ) {} + + public: + const IncidenceBase *mSource; +}; + +AssignmentVisitor::AssignmentVisitor() : d( new Private() ) +{ +} + +AssignmentVisitor::~AssignmentVisitor() +{ + delete d; +} + +bool AssignmentVisitor::assign( IncidenceBase *target, const IncidenceBase *source ) +{ + Q_ASSERT( target != 0 ); + Q_ASSERT( source != 0 ); + + d->mSource = source; + + bool result = target->accept( *this ); + + d->mSource = 0; + + return result; +} + +bool AssignmentVisitor::visit( Event *event ) +{ + Q_ASSERT( event != 0 ); + + const Event *source = dynamic_cast( d->mSource ); + if ( source == 0 ) { + kError(5800) << "Type mismatch: source is" << d->mSource->type() + << "target is" << event->type(); + return false; + } + + *event = *source; + return true; +} + +bool AssignmentVisitor::visit( Todo *todo ) +{ + Q_ASSERT( todo != 0 ); + + const Todo *source = dynamic_cast( d->mSource ); + if ( source == 0 ) { + kError(5800) << "Type mismatch: source is" << d->mSource->type() + << "target is" << todo->type(); + return false; + } + + *todo = *source; + return true; +} + +bool AssignmentVisitor::visit( Journal *journal ) +{ + Q_ASSERT( journal != 0 ); + + const Journal *source = dynamic_cast( d->mSource ); + if ( source == 0 ) { + kError(5800) << "Type mismatch: source is" << d->mSource->type() + << "target is" << journal->type(); + return false; + } + + *journal = *source; + return true; +} + +bool AssignmentVisitor::visit( FreeBusy *freebusy ) +{ + Q_ASSERT( freebusy != 0 ); + + const FreeBusy *source = dynamic_cast( d->mSource ); + if ( source == 0 ) { + kError(5800) << "Type mismatch: source is" << d->mSource->type() + << "target is" << freebusy->type(); + return false; + } + + *freebusy = *source; + return true; +} + +class ComparisonVisitor::Private +{ + public: + Private() : mReference( 0 ) {} + + public: + const IncidenceBase *mReference; +}; + +ComparisonVisitor::ComparisonVisitor() : d( new Private() ) +{ +} + +ComparisonVisitor::~ComparisonVisitor() +{ + delete d; +} + +bool ComparisonVisitor::compare( IncidenceBase *incidence, const IncidenceBase *reference ) +{ + d->mReference = reference; + + const bool result = incidence ? incidence->accept( *this ) : reference == 0; + + d->mReference = 0; + + return result; +} + +bool ComparisonVisitor::visit( Event *event ) +{ + Q_ASSERT( event != 0 ); + + const Event *refEvent = dynamic_cast( d->mReference ); + if ( refEvent ) { + return *event == *refEvent; + } else { + // refEvent is no Event and thus cannot be equal to event + return false; + } +} + +bool ComparisonVisitor::visit( Todo *todo ) +{ + Q_ASSERT( todo != 0 ); + + const Todo *refTodo = dynamic_cast( d->mReference ); + if ( refTodo ) { + return *todo == *refTodo; + } else { + // refTodo is no Todo and thus cannot be equal to todo + return false; + } +} + +bool ComparisonVisitor::visit( Journal *journal ) +{ + Q_ASSERT( journal != 0 ); + + const Journal *refJournal = dynamic_cast( d->mReference ); + if ( refJournal ) { + return *journal == *refJournal; + } else { + // refJournal is no Journal and thus cannot be equal to journal + return false; + } +} + +bool ComparisonVisitor::visit( FreeBusy *freebusy ) +{ + Q_ASSERT( freebusy != 0 ); + + const FreeBusy *refFreeBusy = dynamic_cast( d->mReference ); + if ( refFreeBusy ) { + return *freebusy == *refFreeBusy; + } else { + // refFreeBusy is no FreeBusy and thus cannot be equal to freebusy + return false; + } +} + diff --git a/kcal/resourcelocaldir_p.h b/kcal/resourcelocaldir_p.h index b74119416..92b4eb869 100644 --- a/kcal/resourcelocaldir_p.h +++ b/kcal/resourcelocaldir_p.h @@ -1,65 +1,82 @@ /* This file is part of the kcal library. Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KCAL_RESOURCELOCALDIR_P_H #define KCAL_RESOURCELOCALDIR_P_H #include #include class QString; namespace KABC { class Lock; } namespace KCal { class ResourceLocalDir; class Incidence; /** Private class that helps to provide binary compatibility between releases. @internal */ //@cond PRIVATE -class ResourceLocalDir::Private +class ResourceLocalDir::Private : QObject { + Q_OBJECT public: - Private() - : mLock( 0 ) + Private( ResourceLocalDir *resource ) + : mLock( 0 ), mResource( resource ) { + init(); } - Private ( const QString &dirName ) + Private ( const QString &dirName, ResourceLocalDir *resource ) : mLock( 0 ), - mURL( KUrl::fromPath( dirName ) ) + mURL( KUrl::fromPath( dirName ) ), + mResource( resource ) { } - void init( ResourceLocalDir *rdir ); + void init(); bool deleteIncidenceFile( Incidence *incidence ); + static QString getUidFromFileName( const QString &fileName ); + bool isTempFile( const QString &fileName ) const; + bool doFileLoad( CalendarLocal &cal, const QString &fileName, bool replace ); + KABC::Lock *mLock; KUrl mURL; KDirWatch mDirWatch; QList mDeletedIncidences; + ResourceLocalDir *mResource; + + signals: + void resourceChanged( ResourceCalendar * ); + + protected Q_SLOTS: + void updateIncidenceInCalendar( const QString &file ); + void addIncidenceToCalendar( const QString &file ); + void deleteIncidenceFromCalendar( const QString &file ); + }; //@endcond } #endif