-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogleaccess.h
163 lines (123 loc) · 5.67 KB
/
googleaccess.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
#ifndef GOOGLEACCESS_H
#define GOOGLEACCESS_H
#include <QJsonObject>
#include <QDomElement>
#include <QString>
#include <QList>
#include "contact.h"
#include "appointment.h"
#include "calendar.h"
#include "contactdatabase.h"
// Contact Details
// Requested parameters for person, from: addresses,ageRanges,biographies,birthdays,
// braggingRights,coverPhotos,emailAddresses,events,genders,imClients,interests,locales,
// memberships,metadata,names,nicknames,occupations,organizations,phoneNumbers,photos,
// relations,relationshipInterests,relationshipStatuses,residences,sipAddresses,skills,
// taglines,urls,userDefined
//#define ALLPERSONFIELDS "addresses,ageRanges,biographies,birthdays,,braggingRights,coverPhotos,emailAddresses,events,genders,imClients,interests,locales,memberships,metadata,names,nicknames,occupations,organizations,phoneNumbers,photos,relations,relationshipInterests,relationshipStatuses,residences,sipAddresses,skills,taglines,urls,userDefined"
#define READPERSONFIELDS "addresses,biographies,birthdays,emailAddresses,events,memberships,metadata,names,organizations,phoneNumbers,sipAddresses,urls,userDefined"
#define WRITEPERSONFIELDS "addresses,biographies,birthdays,emailAddresses,names,organizations,phoneNumbers,sipAddresses,urls,userDefined"
#define GROUPPERSONFIELDS "memberships,userDefined"
class GoogleAccess
{
public:
enum googleAction {
Post = 0, // Create New Contact / Calendar Entry
Put = 1, // Not Used / Update Calendar Entry
Delete = 2, // Delete Contact / Calendar Entry
Patch = 3 // Update Contact
};
private:
// Details received following google authorisation
// either from the authorisation, or retrieved from
// storage and passed to the constructor. Used by:
// GoogleAccess(QString rtoken);
// QString googleAuthorise() ;
// QString getUsername() ;
QString username, refreshtoken, refreshtokenandusername ;
QString errorstatus ;
bool connectionerror ;
int errorcode ;
int logsequencenumber ;
// Groups update record
QString addedstr, deletedstr ;
// Group IDs
QString gidbusiness, gidclient, gidfamily, gidfriend, gidother ;
// Gets an access token, using the refresh token
void googleGetAccessToken() ;
QString accesstoken ;
// Parse JSon
bool parseContact(QString &json, QString &tag, Contact &contact) ;
bool parseContact(QJsonObject &item, Contact &contact) ;
// Check metadata source of entry
QString getMetadataField(QJsonValue object, bool primary=false) ;
bool isMetadataFromContacts(QJsonValue object) ;
bool isMetadataFromProfile(QJsonValue object) ;
bool isMetadataPrimary(QJsonValue object) ;
// Parse JSon
bool parseAppointment(QString &json, Appointment &appt, QString account) ;
bool parseAppointment(QJsonObject &item, Appointment &appt, QString account) ;
// Extracts the specified parameter from the occurrenceth record in response
QString ExtractParameter(QString Response, QString Parameter, int Occurrence=1) ;
QString extracttokenresult ;
// Fetch information via a http get
QString googleGet(QString link, QString logfile = "") ;
QString googleGetResponse ;
// Fetch information via an http put or post
QString googlePutPostDelete(QString link, enum googleAction action, QString data = "", QString logfile = "") ;
QString googlePutPostResponse ;
// Load the groups
QStringList groupslist ;
QString groupfindresult ;
bool loadGroups() ;
QString& findMyContactsId() ;
QString& findGroupName(QString id) ;
QString& findGroupId(QString name) ;
public:
// Constructor, sets the refresh token which has been
// previously generated with googleAuthorise.
GoogleAccess();
private:
// Unused copy construct
GoogleAccess(GoogleAccess& other) ;
GoogleAccess& operator =(const GoogleAccess &rhs) ;
public:
void setupRToken(const QString& rt) ;
// Pop up authorisation dialog, and return a refresh_token
// which must be saved for future use.
QString Authorise() ;
// Return the username associated with the current
// google account
QString getUsername() ;
// Return the last network error string, or "" if OK
QString getNetworkError() ;
int getNetworkErrorCode() ;
// Returns true if last network error was network-connection related
bool isConnectionError() ;
// Get all calendar from Google server
bool getCalendar(Calendar &googlecalendar, int startdays, int enddays) ;
// Download the appointment based on Google Details
bool getAppointment(Appointment& appt) ;
// Update Appointment to Google Server
bool updateAppointment(Appointment &appt, googleAction action) ;
// Update group IDs from Google server
bool getGroupIds() ;
bool createGroupIds() ;
// Get Group ID Info
QString getGroupId(Contact::ContactRecord rec, bool asverbosename=false) ;
// Get all contacts from Google server
bool getContacts(ContactDatabase &googlecontacts) ;
// Update contact on Google Server
bool updateContact(Contact &contact, googleAction action, QString etag = QString("")) ;
// Update a group on Google with all contact changes
bool updateSingleGoogleContactGroup(Contact::ContactRecord rec, ContactDatabase &db, ContactDatabase &googledb) ;
QString& contactsDeletedFromGroup() ;
QString& contactsAddedToGroup() ;
// Get Contact, and validate against reference if provided
bool getContact(Contact& googlecontact, bool getgrouponly=false) ;
// Useful debug functions
void resetLogFiles() ;
QString debugGetDataResponse() ;
QString debugPutPostDataResponse() ;
};
#endif // GOOGLEACCESS_H