/
googlecontactstream.h
175 lines (152 loc) · 6.29 KB
/
googlecontactstream.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
174
175
/****************************************************************************
**
** Copyright (C) 2013-2014 Jolla Ltd. and/or its subsidiary(-ies).
** Contact: Chris Adams <chris.adams@jollamobile.com>
**
** Contributors: Sateesh Kavuri <sateesh.kavuri@gmail.com>
** Chris Adams <chris.adams@jollamobile.com>
**
** This program/library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public License
** version 2.1 as published by the Free Software Foundation.
**
** This program/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
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this program/library; if not, write to the Free
** Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
** 02110-1301 USA
**
****************************************************************************/
#ifndef GOOGLECONTACTSTREAM_H
#define GOOGLECONTACTSTREAM_H
#include "googlecontactatom.h"
#include <QObject>
#include <QMap>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QContact>
#include <QContactDetail>
#include <QContactSyncTarget>
#include <QContactName>
#include <QContactAddress>
#include <QContactAnniversary>
#include <QContactEmailAddress>
#include <QContactPhoneNumber>
#include <QContactNote>
#include <QContactOrganization>
#include <QContactGender>
#include <QContactFamily>
#include <QContactUrl>
#include <QContactOnlineAccount>
#include <QContactHobby>
#include <QContactAvatar>
#include <QContactBirthday>
#include <QContactGuid>
#include <QContactNickname>
#include <QContactDisplayLabel>
#include <QContactTimestamp>
#include <QContactGeoLocation>
#include <QContactOriginMetadata>
USE_CONTACTS_NAMESPACE
class GoogleContactStream : public QObject
{
Q_OBJECT
public:
enum UpdateType {
Add,
Modify,
Remove
};
public:
explicit GoogleContactStream(bool response, int accountId, const QString &accountEmail = QString(), QObject* parent = 0);
~GoogleContactStream();
QByteArray encode(const QMultiMap<GoogleContactStream::UpdateType, QPair<QContact, QStringList> > &updates);
GoogleContactAtom* parse(const QByteArray &xmlBuffer);
signals:
void parseDone(bool);
// Decoding XML stream to QContacts
private:
void initAtomFunctionMap();
void initResponseFunctionMap();
void initFunctionMap();
// Atom feed elements handler methods
void handleAtomUpdated();
void handleAtomCategory();
void handleAtomAuthor();
void handleAtomOpenSearch();
void handleAtomLink();
void handleAtomEntry();
// Following are for the response received from the server in case of failures
void handleEntryBatchStatus(GoogleContactAtom::BatchOperationResponse *response);
void handleEntryBatchOperation(GoogleContactAtom::BatchOperationResponse *response);
void handleEntryBatchId(GoogleContactAtom::BatchOperationResponse *response);
// gContact:xxx schema handler methods
QContactDetail handleEntryContent();
QContactDetail handleEntryBirthday();
QContactDetail handleEntryGender();
QContactDetail handleEntryHobby();
QContactDetail handleEntryNickname();
QContactDetail handleEntryOccupation();
QContactDetail handleEntryWebsite();
QContactDetail handleEntryJot();
QContactDetail handleEntryComments();
QContactDetail handleEntryEmail();
QContactDetail handleEntryIm();
QContactDetail handleEntryName();
QContactDetail handleEntryOrganization();
QContactDetail handleEntryPhoneNumber();
QContactDetail handleEntryStructuredPostalAddress();
QContactDetail handleEntryUpdated();
// handle the id specially
QContactDetail handleEntryId(QString *rawId);
// unknown / unsupported element handler methods
QString handleEntryExtendedProperty();
QString handleEntryLink(QContactAvatar *avatar, bool *isAvatar);
QString handleEntryUnknownElement();
typedef void (GoogleContactStream::*Handler)();
typedef QContactDetail (GoogleContactStream::*DetailHandler)();
QMap<QString, GoogleContactStream::Handler> mAtomFunctionMap;
QMap<QString, GoogleContactStream::DetailHandler> mContactFunctionMap;
QXmlStreamReader *mXmlReader;
GoogleContactAtom *mAtom;
int mAccountId;
// Encoding QContacts to XML stream
private:
void encodeContactUpdate(const QContact &qContact,
const QStringList &unsupportedElements,
const UpdateType updateType,
const bool batch);
void startBatchFeed();
void endBatchFeed();
void encodeBatchTag(const UpdateType updateType, const QString &batchElementId);
void encodeId(const QContact &qContact, bool isUpdate = false);
void encodeUpdatedTimestamp(const QContact &qContact);
void encodeEtag(const QContact &qContact, bool needed);
void encodeCategory();
void encodeName(const QContactName &name);
void encodePhoneNumber(const QContactPhoneNumber &phoneNumber);
void encodeEmailAddress(const QContactEmailAddress &emailAddress);
void encodeAddress(const QContactAddress &address);
void encodeUrl(const QContactUrl &url);
void encodeBirthday(const QContactBirthday &birthday);
void encodeNotes(const QList<QContactNote> ¬es);
void encodeHobby(const QContactHobby &hobby);
void encodeGeoLocation(const QContactGeoLocation &geolocation);
void encodeOrganization(const QContactOrganization &organization);
void encodeAvatar(const QContactAvatar &avatar, const QContact &qContact);
void encodeGender(const QContactGender &gender);
void encodeNickname(const QContactNickname &nickname);
void encodeAnniversary(const QContactAnniversary &anniversary);
void encodeOnlineAccount(const QContactOnlineAccount &onlineAccount);
void encodeFamily(const QContactFamily &family);
void encodeDisplayLabel(const QContactDisplayLabel &displayLabel);
void encodeUnknownElements(const QStringList &unknownElements);
QXmlStreamWriter *mXmlWriter;
QList<QContactId> mEncodedContactsWithAvatars;
QString mAccountEmail;
};
#endif // GOOGLECONTACTSTREAM_H