-
Notifications
You must be signed in to change notification settings - Fork 10
/
ewsresource.h
173 lines (150 loc) · 6.96 KB
/
ewsresource.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* This file is part of Akonadi EWS Resource
Copyright (C) 2015-2017 Krzysztof Nowicki <krissn@op.pl>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef EWSRESOURCE_H
#define EWSRESOURCE_H
#include <QScopedPointer>
#include <AkonadiAgentBase/ResourceBase>
#include <AkonadiAgentBase/TransportResourceBase>
#include <akonadi_version.h>
#include "ewsclient.h"
#include "ewsfetchitemsjob.h"
#include "ewsid.h"
#include <config.h>
// Some older variants of akonadi_version.h use a different name
#ifndef AKONADI_VERSION
#define AKONADI_VERSION AKONADILIBRARIES_VERSION
#endif
class FetchItemState;
class EwsGetItemRequest;
class EwsFindFolderRequest;
class EwsFolder;
class EwsSubscriptionManager;
class EwsTagStore;
class Settings;
class EwsResource : public Akonadi::ResourceBase, public Akonadi::AgentBase::ObserverV4,
public Akonadi::TransportResourceBase
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.Akonadi.Ews.Resource")
public:
static const QString akonadiEwsPropsetUuid;
static const EwsPropertyField globalTagsProperty;
static const EwsPropertyField globalTagsVersionProperty;
static const EwsPropertyField tagsProperty;
static const EwsPropertyField flagsProperty;
explicit EwsResource(const QString &id);
~EwsResource();
virtual void itemsTagsChanged(const Akonadi::Item::List &items, const QSet<Akonadi::Tag> &addedTags,
const QSet<Akonadi::Tag> &removedTags) Q_DECL_OVERRIDE;
virtual void tagAdded(const Akonadi::Tag &tag) Q_DECL_OVERRIDE;
virtual void tagChanged(const Akonadi::Tag &tag) Q_DECL_OVERRIDE;
virtual void tagRemoved(const Akonadi::Tag &tag) Q_DECL_OVERRIDE;
virtual void collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent) Q_DECL_OVERRIDE;
virtual void collectionMoved(const Akonadi::Collection &collection, const Akonadi::Collection &collectionSource,
const Akonadi::Collection &collectionDestination) Q_DECL_OVERRIDE;
virtual void collectionChanged(const Akonadi::Collection &collection,
const QSet<QByteArray> &changedAttributes) Q_DECL_OVERRIDE;
virtual void collectionChanged(const Akonadi::Collection &collection) Q_DECL_OVERRIDE;
virtual void collectionRemoved(const Akonadi::Collection &collection) Q_DECL_OVERRIDE;
virtual void itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection) Q_DECL_OVERRIDE;
virtual void itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &partIdentifiers) Q_DECL_OVERRIDE;
virtual void itemsFlagsChanged(const Akonadi::Item::List &items, const QSet<QByteArray> &addedFlags,
const QSet<QByteArray> &removedFlags) Q_DECL_OVERRIDE;
virtual void itemsMoved(const Akonadi::Item::List &items, const Akonadi::Collection &sourceCollection,
const Akonadi::Collection &destinationCollection) Q_DECL_OVERRIDE;
virtual void itemsRemoved(const Akonadi::Item::List &items) Q_DECL_OVERRIDE;
virtual void sendItem(const Akonadi::Item &item) Q_DECL_OVERRIDE;
const Akonadi::Collection &rootCollection() const { return mRootCollection; };
Settings *settings() { return mSettings.data(); };
protected:
void doSetOnline(bool online) Q_DECL_OVERRIDE;
public Q_SLOTS:
void configure(WId windowId) Q_DECL_OVERRIDE;
Q_SCRIPTABLE void clearFolderSyncState(QString folderId);
Q_SCRIPTABLE void clearFolderSyncState();
Q_SCRIPTABLE void clearFolderTreeSyncState();
protected Q_SLOTS:
void retrieveCollections() Q_DECL_OVERRIDE;
void retrieveItems(const Akonadi::Collection &collection) Q_DECL_OVERRIDE;
#if (AKONADI_VERSION > 0x50328)
bool retrieveItems(const Akonadi::Item::List &items, const QSet<QByteArray> &parts) Q_DECL_OVERRIDE;
#else
bool retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> &parts) Q_DECL_OVERRIDE;
#endif
void retrieveTags() Q_DECL_OVERRIDE;
private Q_SLOTS:
void fetchFoldersJobFinished(KJob *job);
void fetchFoldersIncrJobFinished(KJob *job);
void itemFetchJobFinished(KJob *job);
#if (AKONADI_VERSION > 0x50328)
void getItemsRequestFinished(KJob *job);
#else
void getItemRequestFinished(KJob *job);
#endif
void itemChangeRequestFinished(KJob *job);
void itemModifyFlagsRequestFinished(KJob *job);
void itemMoveRequestFinished(KJob *job);
void itemDeleteRequestFinished(KJob *job);
void itemCreateRequestFinished(KJob *job);
void itemSendRequestFinished(KJob *job);
void folderCreateRequestFinished(KJob *job);
void folderMoveRequestFinished(KJob *job);
void folderUpdateRequestFinished(KJob *job);
void folderDeleteRequestFinished(KJob *job);
void delayedInit();
void foldersModifiedEvent(EwsId::List folders);
void foldersModifiedCollectionSyncFinished(KJob *job);
void folderTreeModifiedEvent();
void fullSyncRequestedEvent();
void rootFolderFetchFinished(KJob *job);
void specialFoldersFetchFinished(KJob *job);
void itemsTagChangeFinished(KJob *job);
void globalTagChangeFinished(KJob *job);
void globalTagsRetrievalFinished(KJob *job);
void adjustInboxRemoteIdFetchFinished(KJob *job);
void rootCollectionFetched(KJob *job);
void connectionError();
void reloadConfig();
public Q_SLOTS:
Q_SCRIPTABLE void sendMessage(QString id, QByteArray content);
Q_SIGNALS:
Q_SCRIPTABLE void messageSent(QString id, QString error);
#ifdef HAVE_SEPARATE_MTA_RESOURCE
private Q_SLOTS:
void messageSendRequestFinished(KJob *job);
#endif
private:
void finishItemsFetch(FetchItemState *state);
void fetchSpecialFolders();
void specialFoldersCollectionsRetrieved(const Akonadi::Collection::List &folders);
void saveState();
void resetUrl();
void doRetrieveCollections();
int reconnectTimeout();
EwsClient mEwsClient;
Akonadi::Collection mRootCollection;
QScopedPointer<EwsSubscriptionManager> mSubManager;
QHash<QString, QString> mSyncState;
QString mFolderSyncState;
QHash<QString, EwsId::List> mItemsToCheck;
QHash<QString, EwsFetchItemsJob::QueuedUpdateList> mQueuedUpdates;
QString mPassword;
bool mTagsRetrieved;
int mReconnectTimeout;
EwsTagStore *mTagStore;
QScopedPointer<Settings> mSettings;
};
#endif