[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/akonadi-ports
From: Bertjan Broeksema <b.broeksema () home ! nl>
Date: 2009-10-17 19:34:45
Message-ID: 1255808085.824690.9595.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1036785 by bbroeksema:
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.
M +1 -1 kdepim/akonadi/resources/ical/icalresourcebase.cpp
M +1 -1 kdepim/akonadi/resources/ical/icalresourcebase.h
M +1 -1 kdepim/akonadi/resources/mbox/mboxresource.cpp
M +1 -1 kdepim/akonadi/resources/mbox/mboxresource.h
M +0 -1 kdepim/akonadi/resources/shared/singlefileresource.h
M +4 -13 kdepim/akonadi/resources/shared/singlefileresourcebase.cpp
M +1 -17 kdepim/akonadi/resources/shared/singlefileresourcebase.h
M +1 -1 kdepim/akonadi/resources/vcard/vcardresource.cpp
M +1 -1 kdepim/akonadi/resources/vcard/vcardresource.h
M +2 -2 kdepimlibs/akonadi/resourcebase.cpp
M +13 -2 kdepimlibs/akonadi/resourcebase.h
M +25 -2 kdepimlibs/akonadi/resourcescheduler.cpp
M +2 -1 kdepimlibs/akonadi/resourcescheduler_p.h
--- branches/work/akonadi-ports/kdepim/akonadi/resources/ical/icalresourcebase.cpp \
#1036784:1036785 @@ -107,7 +107,7 @@
changeProcessed();
}
-void ICalResourceBase::retrieveItemsFromFile( const Akonadi::Collection & col )
+void ICalResourceBase::retrieveItems( const Akonadi::Collection & col )
{
if ( !mCalendar )
return;
--- branches/work/akonadi-ports/kdepim/akonadi/resources/ical/icalresourcebase.h \
#1036784:1036785 @@ -45,6 +45,7 @@
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 @@
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.
--- branches/work/akonadi-ports/kdepim/akonadi/resources/mbox/mboxresource.cpp \
#1036784:1036785 @@ -97,7 +97,7 @@
delete dlg;
}
-void MboxResource::retrieveItemsFromFile( const Akonadi::Collection &col )
+void MboxResource::retrieveItems( const Akonadi::Collection &col )
{
Q_UNUSED( col );
if ( !mMBox )
--- branches/work/akonadi-ports/kdepim/akonadi/resources/mbox/mboxresource.h \
#1036784:1036785 @@ -38,10 +38,10 @@
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 );
--- branches/work/akonadi-ports/kdepim/akonadi/resources/shared/singlefileresource.h \
#1036784:1036785 @@ -169,7 +169,6 @@
if ( !writeResult )
return;
- mHasUnwrittenChanges = false;
emit status( Idle, i18nc( "@info:status", "Ready" ) );
} else {
// Check if there is a download or an upload in progress.
--- branches/work/akonadi-ports/kdepim/akonadi/resources/shared/singlefileresourcebase.cpp \
#1036784:1036785 @@ -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 @@
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 @@
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::markAsDirty()
+void SingleFileResourceBase::scheduleWrite()
{
- mHasUnwrittenChanges = true;
+ scheduleCustomTask(this, "writeFile", QVariant(), \
ResourceBase::AfterChangeReplay); }
void SingleFileResourceBase::slotDownloadJobResult( KJob *job )
@@ -268,7 +260,6 @@
mUploadJob = 0;
KGlobal::deref();
- mHasUnwrittenChanges = false;
emit status( Idle, i18nc( "@info:status", "Ready" ) );
}
--- branches/work/akonadi-ports/kdepim/akonadi/resources/shared/singlefileresourcebase.h \
#1036784:1036785 @@ -56,23 +56,8 @@
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 @@
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 * );
};
--- branches/work/akonadi-ports/kdepim/akonadi/resources/vcard/vcardresource.cpp \
#1036784:1036785 @@ -127,7 +127,7 @@
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 );
--- branches/work/akonadi-ports/kdepim/akonadi/resources/vcard/vcardresource.h \
#1036784:1036785 @@ -39,12 +39,12 @@
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 );
--- branches/work/akonadi-ports/kdepimlibs/akonadi/resourcebase.cpp #1036784:1036785
@@ -661,10 +661,10 @@
d->mHierarchicalRid = enable;
}
-void ResourceBase::scheduleCustomTask( QObject *receiver, const char *method, const \
QVariant &argument ) +void ResourceBase::scheduleCustomTask( QObject *receiver, const \
char *method, const QVariant &argument, SchedulePriority priority ) {
Q_D( ResourceBase );
- d->scheduler->scheduleCustomTask( receiver, method, argument );
+ d->scheduler->scheduleCustomTask( receiver, method, argument, priority );
}
void ResourceBase::taskDone()
--- branches/work/akonadi-ports/kdepimlibs/akonadi/resourcebase.h #1036784:1036785
@@ -434,19 +434,30 @@
*/
void setHierarchicalRemoteIdentifiersEnabled( bool enable );
+ friend class ResourceScheduler;
+
+ enum SchedulePriority {
+ Prepend, ///> The task will be executed as soon as the current task \
has finished. + AfterChangeReplay, ///> The task is scheduled after the last \
ChangeReplay task in the queue + Append ///> The task will be \
executed after all tasks currently in the queue are finished + };
+
/**
* Schedules a custom task in the internal scheduler. It will be queued with
* all other tasks such as change replays and retrieval requests and eventually
- * executed by calling the specified method.
+ * executed by calling the specified method. With the priority parameter the
+ * time of execution of the Task can be influenced. @see SchedulePriority
* @param receiver The object the slot should be called on.
* @param methodName The name of the method (and only the name, not signature, \
not SLOT(...) macro),
* that should be called to execute this task. The method has to be a slot and \
take a QVariant as
* argument.
* @param argument A QVariant argument passed to the method specified above. Use \
this to pass task
* parameters.
+ * @param priority Priority if the task. Use this to influence the position in
+ * the execution queue.
* @since 4.4
*/
- void scheduleCustomTask( QObject* receiver, const char* method, const QVariant \
&argument ); + void scheduleCustomTask( QObject* receiver, const char* method, \
const QVariant &argument, SchedulePriority priority = Append );
/**
* Indicate that the current task is finished. Use this method from the slot \
called via scheduleCustomTaks().
--- branches/work/akonadi-ports/kdepimlibs/akonadi/resourcescheduler.cpp \
#1036784:1036785 @@ -121,7 +121,7 @@
scheduleNext();
}
-void Akonadi::ResourceScheduler::scheduleCustomTask( QObject *receiver, const char* \
methodName, const QVariant &argument ) +void \
Akonadi::ResourceScheduler::scheduleCustomTask( QObject *receiver, const char* \
methodName, const QVariant &argument, ResourceBase::SchedulePriority priority ) {
Task t;
t.type = Custom;
@@ -130,7 +130,30 @@
t.argument = argument;
if ( mTaskList.contains( t ) )
return;
- mTaskList.append( t );
+
+ switch (priority) {
+ case ResourceBase::Prepend:
+ mTaskList.prepend(t);
+ break;
+ case ResourceBase::AfterChangeReplay:
+ {
+ QMutableListIterator<Task> it(mTaskList);
+ bool inserted = false;
+ while (it.hasNext() && !inserted) {
+ if (it.next().type != ChangeReplay) {
+ it.previous(); // next returns the item *and* advances the iterator.
+ it.insert(t);
+ inserted = true;
+ }
+ }
+ if (!inserted)
+ mTaskList.append(t);
+ }
+ break;
+ default:
+ mTaskList.append(t);
+ }
+
signalTaskToTracker( t, "Custom-" + t.methodName );
scheduleNext();
}
--- branches/work/akonadi-ports/kdepimlibs/akonadi/resourcescheduler_p.h \
#1036784:1036785 @@ -23,6 +23,7 @@
#include <akonadi/agentbase.h>
#include <akonadi/collection.h>
#include <akonadi/item.h>
+#include <akonadi/resourcebase.h>
#include <QtCore/QObject>
#include <QtCore/QStringList>
@@ -124,7 +125,7 @@
Insert a custom taks.
@param methodName The method name, without signature, do not use the SLOT() \
macro
*/
- void scheduleCustomTask( QObject *receiver, const char *methodName, const \
QVariant &argument ); + void scheduleCustomTask( QObject *receiver, const char \
*methodName, const QVariant &argument, ResourceBase::SchedulePriority priority = \
ResourceBase::Append );
/**
Returns true if no tasks are running or in the queue.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic