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

« back to all changes in this revision

Viewing changes to akonadi/kresources/shared/resourceprivatebase.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_RESOURCEPRIVATEBASE_H
 
22
#define KRES_AKONADI_RESOURCEPRIVATEBASE_H
 
23
 
 
24
#include <akonadi/collection.h>
 
25
 
 
26
#include "storeconfigiface.h"
 
27
 
 
28
#include <KConfigGroup>
 
29
 
 
30
#include <QtCore/QObject>
 
31
 
 
32
namespace Akonadi {
 
33
  class Item;
 
34
}
 
35
 
 
36
class AbstractSubResourceModel;
 
37
class IdArbiterBase;
 
38
class ItemSaveContext;
 
39
class StoreCollectionDialog;
 
40
class SubResourceBase;
 
41
 
 
42
class ResourcePrivateBase : public QObject, public StoreConfigIface
 
43
{
 
44
  Q_OBJECT
 
45
 
 
46
  public:
 
47
    enum State
 
48
    {
 
49
      Closed,
 
50
      Opened,
 
51
      Failed
 
52
    };
 
53
 
 
54
    enum ChangeType
 
55
    {
 
56
      NoChange,
 
57
      Added,
 
58
      Changed,
 
59
      Removed
 
60
    };
 
61
 
 
62
    typedef QHash<QString, ChangeType> ChangeByKResId;
 
63
 
 
64
    ResourcePrivateBase( IdArbiterBase *idArbiter, QObject *parent );
 
65
 
 
66
    ResourcePrivateBase( const KConfigGroup &config, IdArbiterBase *idArbiter, QObject *parent );
 
67
 
 
68
    virtual ~ResourcePrivateBase();
 
69
 
 
70
    bool doOpen();
 
71
 
 
72
    bool doClose();
 
73
 
 
74
    bool doLoad();
 
75
 
 
76
    bool doAsyncLoad();
 
77
 
 
78
    bool doSave();
 
79
 
 
80
    bool doAsyncSave();
 
81
 
 
82
    void writeConfig( KConfigGroup &config ) const;
 
83
 
 
84
    void clear();
 
85
 
 
86
    void setStoreCollectionsByMimeType( const CollectionsByMimeType &collections );
 
87
 
 
88
    CollectionsByMimeType storeCollectionsByMimeType() const;
 
89
 
 
90
    bool addLocalItem( const QString &uid, const QString &mimeType );
 
91
 
 
92
    void changeLocalItem( const QString &uid );
 
93
 
 
94
    void removeLocalItem( const QString &uid );
 
95
 
 
96
  protected:
 
97
    KConfigGroup mConfig;
 
98
 
 
99
    IdArbiterBase *mIdArbiter;
 
100
 
 
101
    ChangeByKResId mChanges;
 
102
 
 
103
    Akonadi::Collection mDefaultStoreCollection;
 
104
 
 
105
    CollectionsByMimeType mStoreCollectionsByMimeType;
 
106
 
 
107
    QMap<QString, QString> mUidToResourceMap;
 
108
 
 
109
    StoreCollectionDialog *mStoreCollectionDialog;
 
110
 
 
111
  protected:
 
112
    State state() const;
 
113
 
 
114
    bool isLoading() const;
 
115
 
 
116
    bool startAkonadi();
 
117
 
 
118
    Akonadi::Collection storeCollectionForMimeType( const QString &mimeType ) const;
 
119
 
 
120
    bool prepareItemSaveContext( ItemSaveContext &saveContext );
 
121
 
 
122
    bool prepareItemSaveContext( const ChangeByKResId::const_iterator &it, ItemSaveContext &saveContext );
 
123
 
 
124
    virtual bool openResource() = 0;
 
125
 
 
126
    virtual bool closeResource() = 0;
 
127
 
 
128
    virtual bool loadResource() = 0;
 
129
 
 
130
    virtual bool asyncLoadResource() = 0;
 
131
 
 
132
    virtual void writeResourceConfig( KConfigGroup &config ) const = 0;
 
133
 
 
134
    virtual void clearResource() = 0;
 
135
 
 
136
    virtual const SubResourceBase *subResourceBase( const QString &subResourceIdentifier ) const = 0;
 
137
 
 
138
    virtual const SubResourceBase *findSubResourceForMappedItem( const QString &kresId ) const = 0;
 
139
 
 
140
    virtual const SubResourceBase *storeSubResourceForMimeType( const QString &mimeType ) const = 0;
 
141
 
 
142
    virtual QList<const SubResourceBase*> writableSubResourcesForMimeType( const QString &mimeType ) const = 0;
 
143
 
 
144
    virtual const SubResourceBase *storeSubResourceFromUser( const QString &kresId, const QString &mimeType ) = 0;
 
145
 
 
146
    virtual Akonadi::Item createItem( const QString &kresId ) = 0;
 
147
 
 
148
    virtual Akonadi::Item updateItem( const Akonadi::Item &item, const QString &kresId, const QString &originalId ) = 0;
 
149
 
 
150
    virtual const AbstractSubResourceModel *subResourceModel() const = 0;
 
151
 
 
152
    virtual CollectionsByMimeType storeCollectionsFromOldDefault() const = 0;
 
153
 
 
154
  protected Q_SLOTS:
 
155
    virtual void subResourceAdded( SubResourceBase *subResource );
 
156
 
 
157
    virtual void subResourceRemoved( SubResourceBase *subResource );
 
158
 
 
159
    virtual void loadingResult( bool ok, const QString &errorString );
 
160
 
 
161
    virtual void savingResult( bool ok, const QString &errorString );
 
162
 
 
163
  private:
 
164
    State mState;
 
165
    bool  mLoadingInProgress;
 
166
 
 
167
    QString mDefaultResourceIdentifier;
 
168
};
 
169
 
 
170
class BoolGuard
 
171
{
 
172
  public:
 
173
    BoolGuard( bool &variable, bool overrideValue )
 
174
      : mVariable( variable ), mBaseValue( variable )
 
175
    {
 
176
      mVariable = overrideValue;
 
177
    }
 
178
 
 
179
    ~BoolGuard()
 
180
    {
 
181
      mVariable = mBaseValue;
 
182
    }
 
183
 
 
184
  protected:
 
185
    bool &mVariable;
 
186
    const bool mBaseValue;
 
187
};
 
188
 
 
189
#endif
 
190
 
 
191
// kate: space-indent on; indent-width 2; replace-tabs on;