~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/kresources/shared/concurrentjobs.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of kdepim.
 
3
    Copyright (c) 2009 Kevin Krammer <kevin.krammer@gmx.at>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
19
*/
 
20
 
 
21
#ifndef KRES_AKONADI_CONCURRENTJOBS_H
 
22
#define KRES_AKONADI_CONCURRENTJOBS_H
 
23
 
 
24
#include "itemsavejob.h"
 
25
 
 
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>
 
32
 
 
33
#include <QtCore/QMutex>
 
34
#include <QtCore/QMutexLocker>
 
35
#include <QtCore/QThread>
 
36
#include <QtCore/QWaitCondition>
 
37
 
 
38
class ItemSaveContext;
 
39
 
 
40
class ConcurrentJobBase
 
41
{
 
42
  public:
 
43
    virtual ~ConcurrentJobBase();
 
44
 
 
45
    QString errorString() const
 
46
    {
 
47
      return mErrorString;
 
48
    }
 
49
 
 
50
  protected:
 
51
    bool mRunnerResult;
 
52
 
 
53
    QString mErrorString;
 
54
 
 
55
    QMutex mMutex;
 
56
    QWaitCondition mCondition;
 
57
 
 
58
  protected:
 
59
    virtual void createJob() = 0;
 
60
 
 
61
    virtual void handleSuccess() = 0;
 
62
 
 
63
    virtual Akonadi::Job *job() = 0;
 
64
 
 
65
    class JobRunner : public QThread
 
66
    {
 
67
      public:
 
68
        JobRunner( ConcurrentJobBase *parent );
 
69
 
 
70
      protected:
 
71
        void run();
 
72
 
 
73
      private:
 
74
        ConcurrentJobBase *mParent;
 
75
    };
 
76
};
 
77
 
 
78
template <class JobClass>
 
79
class ConcurrentJob : public ConcurrentJobBase
 
80
{
 
81
  public:
 
82
    ConcurrentJob() : mJob( 0 ) {}
 
83
 
 
84
    virtual ~ConcurrentJob() {}
 
85
 
 
86
    bool exec()
 
87
    {
 
88
      JobRunner *runner = new JobRunner( this );
 
89
      QObject::connect( runner, SIGNAL( finished() ), runner, SLOT( deleteLater() ) );
 
90
 
 
91
      QMutexLocker mutexLocker( &mMutex );
 
92
 
 
93
      runner->start();
 
94
 
 
95
      mCondition.wait( &mMutex );
 
96
 
 
97
      return mRunnerResult;
 
98
    }
 
99
 
 
100
  protected:
 
101
    JobClass *mJob;
 
102
 
 
103
  protected:
 
104
    Akonadi::Job *job()
 
105
    {
 
106
      return mJob;
 
107
    }
 
108
};
 
109
 
 
110
class ConcurrentCollectionFetchJob : public ConcurrentJob<Akonadi::CollectionFetchJob>
 
111
{
 
112
  public:
 
113
    const ConcurrentCollectionFetchJob *operator->() const;
 
114
 
 
115
    Akonadi::Collection::List collections() const;
 
116
 
 
117
  protected:
 
118
    Akonadi::Collection::List mCollections;
 
119
 
 
120
  protected:
 
121
    void createJob();
 
122
 
 
123
    void handleSuccess();
 
124
};
 
125
 
 
126
class ConcurrentItemFetchJob : public ConcurrentJob<Akonadi::ItemFetchJob>
 
127
{
 
128
  public:
 
129
    ConcurrentItemFetchJob( const Akonadi::Collection &collection );
 
130
 
 
131
    const ConcurrentItemFetchJob *operator->() const;
 
132
 
 
133
    Akonadi::Item::List items() const;
 
134
 
 
135
  protected:
 
136
    const Akonadi::Collection mCollection;
 
137
    Akonadi::Item::List mItems;
 
138
 
 
139
  protected:
 
140
    void createJob();
 
141
 
 
142
    void handleSuccess();
 
143
};
 
144
 
 
145
class ConcurrentItemSaveJob : public ConcurrentJob<ItemSaveJob>
 
146
{
 
147
  public:
 
148
    ConcurrentItemSaveJob( const ItemSaveContext &saveContext );
 
149
 
 
150
    const ConcurrentItemSaveJob *operator->() const;
 
151
 
 
152
  protected:
 
153
    const ItemSaveContext &mSaveContext;
 
154
 
 
155
  protected:
 
156
    void createJob();
 
157
 
 
158
    void handleSuccess();
 
159
};
 
160
 
 
161
class ConcurrentCollectionCreateJob : public ConcurrentJob<Akonadi::CollectionCreateJob>
 
162
{
 
163
  public:
 
164
    ConcurrentCollectionCreateJob( const Akonadi::Collection &collection );
 
165
 
 
166
    const ConcurrentCollectionCreateJob *operator->() const;
 
167
 
 
168
  protected:
 
169
    Akonadi::Collection mCollection;
 
170
 
 
171
  protected:
 
172
    void createJob();
 
173
 
 
174
    void handleSuccess();
 
175
};
 
176
 
 
177
class ConcurrentCollectionDeleteJob : public ConcurrentJob<Akonadi::CollectionDeleteJob>
 
178
{
 
179
  public:
 
180
    ConcurrentCollectionDeleteJob( const Akonadi::Collection &collection );
 
181
 
 
182
    const ConcurrentCollectionDeleteJob *operator->() const;
 
183
 
 
184
  protected:
 
185
    Akonadi::Collection mCollection;
 
186
 
 
187
  protected:
 
188
    void createJob();
 
189
 
 
190
    void handleSuccess();
 
191
};
 
192
 
 
193
#endif
 
194
 
 
195
// kate: space-indent on; indent-width 2; replace-tabs on;