2
This file is part of kdepim.
3
Copyright (c) 2009 Kevin Krammer <kevin.krammer@gmx.at>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
21
#ifndef KRES_AKONADI_CONCURRENTJOBS_H
22
#define KRES_AKONADI_CONCURRENTJOBS_H
24
#include "itemsavejob.h"
26
#include <akonadi/collection.h>
27
#include <akonadi/collectioncreatejob.h>
28
#include <akonadi/collectiondeletejob.h>
29
#include <akonadi/collectionfetchjob.h>
30
#include <akonadi/item.h>
31
#include <akonadi/itemfetchjob.h>
33
#include <QtCore/QMutex>
34
#include <QtCore/QMutexLocker>
35
#include <QtCore/QThread>
36
#include <QtCore/QWaitCondition>
38
class ItemSaveContext;
40
class ConcurrentJobBase
43
virtual ~ConcurrentJobBase();
45
QString errorString() const
56
QWaitCondition mCondition;
59
virtual void createJob() = 0;
61
virtual void handleSuccess() = 0;
63
virtual Akonadi::Job *job() = 0;
65
class JobRunner : public QThread
68
JobRunner( ConcurrentJobBase *parent );
74
ConcurrentJobBase *mParent;
78
template <class JobClass>
79
class ConcurrentJob : public ConcurrentJobBase
82
ConcurrentJob() : mJob( 0 ) {}
84
virtual ~ConcurrentJob() {}
88
JobRunner *runner = new JobRunner( this );
89
QObject::connect( runner, SIGNAL( finished() ), runner, SLOT( deleteLater() ) );
91
QMutexLocker mutexLocker( &mMutex );
95
mCondition.wait( &mMutex );
110
class ConcurrentCollectionFetchJob : public ConcurrentJob<Akonadi::CollectionFetchJob>
113
const ConcurrentCollectionFetchJob *operator->() const;
115
Akonadi::Collection::List collections() const;
118
Akonadi::Collection::List mCollections;
123
void handleSuccess();
126
class ConcurrentItemFetchJob : public ConcurrentJob<Akonadi::ItemFetchJob>
129
ConcurrentItemFetchJob( const Akonadi::Collection &collection );
131
const ConcurrentItemFetchJob *operator->() const;
133
Akonadi::Item::List items() const;
136
const Akonadi::Collection mCollection;
137
Akonadi::Item::List mItems;
142
void handleSuccess();
145
class ConcurrentItemSaveJob : public ConcurrentJob<ItemSaveJob>
148
ConcurrentItemSaveJob( const ItemSaveContext &saveContext );
150
const ConcurrentItemSaveJob *operator->() const;
153
const ItemSaveContext &mSaveContext;
158
void handleSuccess();
161
class ConcurrentCollectionCreateJob : public ConcurrentJob<Akonadi::CollectionCreateJob>
164
ConcurrentCollectionCreateJob( const Akonadi::Collection &collection );
166
const ConcurrentCollectionCreateJob *operator->() const;
169
Akonadi::Collection mCollection;
174
void handleSuccess();
177
class ConcurrentCollectionDeleteJob : public ConcurrentJob<Akonadi::CollectionDeleteJob>
180
ConcurrentCollectionDeleteJob( const Akonadi::Collection &collection );
182
const ConcurrentCollectionDeleteJob *operator->() const;
185
Akonadi::Collection mCollection;
190
void handleSuccess();
195
// kate: space-indent on; indent-width 2; replace-tabs on;