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_RESOURCEPRIVATEBASE_H
22
#define KRES_AKONADI_RESOURCEPRIVATEBASE_H
24
#include <akonadi/collection.h>
26
#include "storeconfigiface.h"
28
#include <KConfigGroup>
30
#include <QtCore/QObject>
36
class AbstractSubResourceModel;
38
class ItemSaveContext;
39
class StoreCollectionDialog;
40
class SubResourceBase;
42
class ResourcePrivateBase : public QObject, public StoreConfigIface
62
typedef QHash<QString, ChangeType> ChangeByKResId;
64
ResourcePrivateBase( IdArbiterBase *idArbiter, QObject *parent );
66
ResourcePrivateBase( const KConfigGroup &config, IdArbiterBase *idArbiter, QObject *parent );
68
virtual ~ResourcePrivateBase();
82
void writeConfig( KConfigGroup &config ) const;
86
void setStoreCollectionsByMimeType( const CollectionsByMimeType &collections );
88
CollectionsByMimeType storeCollectionsByMimeType() const;
90
bool addLocalItem( const QString &uid, const QString &mimeType );
92
void changeLocalItem( const QString &uid );
94
void removeLocalItem( const QString &uid );
99
IdArbiterBase *mIdArbiter;
101
ChangeByKResId mChanges;
103
Akonadi::Collection mDefaultStoreCollection;
105
CollectionsByMimeType mStoreCollectionsByMimeType;
107
QMap<QString, QString> mUidToResourceMap;
109
StoreCollectionDialog *mStoreCollectionDialog;
114
bool isLoading() const;
118
Akonadi::Collection storeCollectionForMimeType( const QString &mimeType ) const;
120
bool prepareItemSaveContext( ItemSaveContext &saveContext );
122
bool prepareItemSaveContext( const ChangeByKResId::const_iterator &it, ItemSaveContext &saveContext );
124
virtual bool openResource() = 0;
126
virtual bool closeResource() = 0;
128
virtual bool loadResource() = 0;
130
virtual bool asyncLoadResource() = 0;
132
virtual void writeResourceConfig( KConfigGroup &config ) const = 0;
134
virtual void clearResource() = 0;
136
virtual const SubResourceBase *subResourceBase( const QString &subResourceIdentifier ) const = 0;
138
virtual const SubResourceBase *findSubResourceForMappedItem( const QString &kresId ) const = 0;
140
virtual const SubResourceBase *storeSubResourceForMimeType( const QString &mimeType ) const = 0;
142
virtual QList<const SubResourceBase*> writableSubResourcesForMimeType( const QString &mimeType ) const = 0;
144
virtual const SubResourceBase *storeSubResourceFromUser( const QString &kresId, const QString &mimeType ) = 0;
146
virtual Akonadi::Item createItem( const QString &kresId ) = 0;
148
virtual Akonadi::Item updateItem( const Akonadi::Item &item, const QString &kresId, const QString &originalId ) = 0;
150
virtual const AbstractSubResourceModel *subResourceModel() const = 0;
152
virtual CollectionsByMimeType storeCollectionsFromOldDefault() const = 0;
155
virtual void subResourceAdded( SubResourceBase *subResource );
157
virtual void subResourceRemoved( SubResourceBase *subResource );
159
virtual void loadingResult( bool ok, const QString &errorString );
161
virtual void savingResult( bool ok, const QString &errorString );
165
bool mLoadingInProgress;
167
QString mDefaultResourceIdentifier;
173
BoolGuard( bool &variable, bool overrideValue )
174
: mVariable( variable ), mBaseValue( variable )
176
mVariable = overrideValue;
181
mVariable = mBaseValue;
186
const bool mBaseValue;
191
// kate: space-indent on; indent-width 2; replace-tabs on;