Commit c31fb685 authored by Bertjan Broeksema's avatar Bertjan Broeksema
Browse files

Undo most of the changes of r1036645. In stead of calling writeFile()

directly in retrieveItems we now use the new scheduleCustomTask() in
ResourceBase.

There are however a couple of assumptions made:
* The new Task is placed after ChangeRecorderTasks (This is also
  implemented in this commit).
* Duplicate tasks are filtered out. Important because otherwise on
  each change the file (local or remotely) would get written.

svn path=/branches/work/akonadi-ports/kdepim/akonadi/; revision=1036785
parent f22e10ea
......@@ -107,7 +107,7 @@ void ICalResourceBase::itemRemoved(const Akonadi::Item & item)
changeProcessed();
}
void ICalResourceBase::retrieveItemsFromFile( const Akonadi::Collection & col )
void ICalResourceBase::retrieveItems( const Akonadi::Collection & col )
{
if ( !mCalendar )
return;
......
......@@ -45,6 +45,7 @@ class ICalResourceBase : public Akonadi::SingleFileResource<Settings>
protected Q_SLOTS:
bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
void retrieveItems( const Akonadi::Collection &col );
protected:
enum CheckType { CheckForAdded, CheckForChanged };
......@@ -53,7 +54,6 @@ class ICalResourceBase : public Akonadi::SingleFileResource<Settings>
bool readFromFile( const QString &fileName );
bool writeToFile( const QString &fileName );
virtual void aboutToQuit();
virtual void retrieveItemsFromFile( const Akonadi::Collection &col );
/**
* Retrieve an incidence from the calendar, and set it into a new item's payload.
......
......@@ -97,7 +97,7 @@ void MboxResource::configure( WId windowId )
delete dlg;
}
void MboxResource::retrieveItemsFromFile( const Akonadi::Collection &col )
void MboxResource::retrieveItems( const Akonadi::Collection &col )
{
Q_UNUSED( col );
if ( !mMBox )
......
......@@ -38,10 +38,10 @@ class MboxResource : public Akonadi::SingleFileResource<Settings>
protected Q_SLOTS:
virtual bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
virtual void retrieveItems( const Akonadi::Collection &col );
protected:
virtual void aboutToQuit();
virtual void retrieveItemsFromFile( const Akonadi::Collection &col );
virtual void itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection );
virtual void itemChanged( const Akonadi::Item &item, const QSet<QByteArray> &parts );
......
......@@ -169,7 +169,6 @@ class SingleFileResource : public SingleFileResourceBase
if ( !writeResult )
return;
mHasUnwrittenChanges = false;
emit status( Idle, i18nc( "@info:status", "Ready" ) );
} else {
// Check if there is a download or an upload in progress.
......
......@@ -37,7 +37,7 @@
using namespace Akonadi;
SingleFileResourceBase::SingleFileResourceBase( const QString & id )
: ResourceBase( id ), mDownloadJob( 0 ), mUploadJob( 0 ), mHasUnwrittenChanges(false)
: ResourceBase( id ), mDownloadJob( 0 ), mUploadJob( 0 )
{
connect( &mDirtyTimer, SIGNAL( timeout() ), SLOT( writeFile() ) );
mDirtyTimer.setSingleShot( true );
......@@ -48,7 +48,7 @@ SingleFileResourceBase::SingleFileResourceBase( const QString & id )
changeRecorder()->itemFetchScope().fetchFullPayload();
changeRecorder()->fetchCollection( true );
connect( changeRecorder(), SIGNAL( changesAdded() ), SLOT( markAsDirty() ) );
connect( changeRecorder(), SIGNAL( changesAdded() ), SLOT( scheduleWrite() ) );
connect( KDirWatch::self(), SIGNAL( dirty( QString ) ), SLOT( fileChanged( QString ) ) );
connect( KDirWatch::self(), SIGNAL( created( QString ) ), SLOT( fileChanged( QString ) ) );
......@@ -56,14 +56,6 @@ SingleFileResourceBase::SingleFileResourceBase( const QString & id )
KGlobal::locale()->insertCatalog( "akonadi_singlefile_resource" );
}
void SingleFileResourceBase::retrieveItems( const Akonadi::Collection &col )
{
if ( mHasUnwrittenChanges )
writeFile();
retrieveItemsFromFile( col );
}
KSharedConfig::Ptr SingleFileResourceBase::runtimeConfig() const
{
return KSharedConfig::openConfig( name() + "rc", KConfig::SimpleConfig, "cache" );
......@@ -240,9 +232,9 @@ void SingleFileResourceBase::fileChanged( const QString & fileName )
}
}
void SingleFileResourceBase::markAsDirty()
void SingleFileResourceBase::scheduleWrite()
{
mHasUnwrittenChanges = true;
scheduleCustomTask(this, "writeFile", QVariant(), ResourceBase::AfterChangeReplay);
}
void SingleFileResourceBase::slotDownloadJobResult( KJob *job )
......@@ -268,7 +260,6 @@ void SingleFileResourceBase::slotUploadJobResult( KJob *job )
mUploadJob = 0;
KGlobal::deref();
mHasUnwrittenChanges = false;
emit status( Idle, i18nc( "@info:status", "Ready" ) );
}
......
......@@ -56,22 +56,7 @@ class SingleFileResourceBase : public ResourceBase, public Akonadi::AgentBase::O
virtual void readFile() = 0;
virtual void writeFile() = 0;
protected Q_SLOTS:
/**
* This does not actually retrieve the items but checks if the resources is
* has unwritten changes and write them before calling retrieveItemsFromFile().
*/
virtual void retrieveItems( const Akonadi::Collection &col );
protected:
/**
* This is the real implementation of retrieveItems( const Akonadi::Collection &col )
* and should be implemented by the specific resourses. When this method is
* called it can be assumed that changes there are no pending changes that
* need to be written to file.
*/
virtual void retrieveItemsFromFile( const Akonadi::Collection &col ) = 0;
/**
* Returns a pointer to the KConfig object which is used to store runtime
* information of the resource.
......@@ -159,12 +144,11 @@ class SingleFileResourceBase : public ResourceBase, public Akonadi::AgentBase::O
KIO::FileCopyJob *mUploadJob;
QByteArray mPreviousHash;
QByteArray mCurrentHash;
bool mHasUnwrittenChanges;
private Q_SLOTS:
void handleProgress( KJob *, unsigned long );
void fileChanged( const QString &fileName );
void markAsDirty(); /// Called when changes are added to the ChangeRecorder.
void scheduleWrite(); /// Called when changes are added to the ChangeRecorder.
void slotDownloadJobResult( KJob * );
void slotUploadJobResult( KJob * );
};
......
......@@ -127,7 +127,7 @@ void VCardResource::itemRemoved(const Akonadi::Item & item)
changeProcessed();
}
void VCardResource::retrieveItemsFromFile( const Akonadi::Collection & col )
void VCardResource::retrieveItems( const Akonadi::Collection & col )
{
// VCard does not support folders so we can safely ignore the collection
Q_UNUSED( col );
......
......@@ -39,12 +39,12 @@ class VCardResource : public Akonadi::SingleFileResource<Settings>
protected Q_SLOTS:
bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
void retrieveItems( const Akonadi::Collection &col );
protected:
bool readFromFile( const QString &fileName );
bool writeToFile( const QString &fileName );
virtual void aboutToQuit();
virtual void retrieveItemsFromFile( const Akonadi::Collection &col );
virtual void itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection );
virtual void itemChanged( const Akonadi::Item &item, const QSet<QByteArray> &parts );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment