Commit a0f86265 authored by blam's avatar blam

Merge branch 'jb50799-google-people-api' into 'master'

[buteo-sync-plugins-social] Update Contacts plugin to use Google People API. JB#50799

See merge request !86
parents b6f3b38a a5309ea0
......@@ -4,14 +4,14 @@ QT += gui
SOURCES += \
$$PWD/googletwowaycontactsyncadaptor.cpp \
$$PWD/googlecontactstream.cpp \
$$PWD/googlecontactatom.cpp \
$$PWD/googlepeopleapi.cpp \
$$PWD/googlepeoplejson.cpp \
$$PWD/googlecontactimagedownloader.cpp
HEADERS += \
$$PWD/googletwowaycontactsyncadaptor.h \
$$PWD/googlecontactstream.h \
$$PWD/googlecontactatom.h \
$$PWD/googlepeopleapi.h \
$$PWD/googlepeoplejson.h \
$$PWD/googlecontactimagedownloader.h
INCLUDEPATH += $$PWD
......
/****************************************************************************
**
** Copyright (C) 2013-2014 Jolla Ltd. and/or its subsidiary(-ies).
** Contact: Chris Adams <chris.adams@jolla.com>
**
** Contributors: Sateesh Kavuri <sateesh.kavuri@gmail.com>
** Mani Chandrasekar <maninc@gmail.com>
** Chris Adams <chris.adams@jolla.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
**
****************************************************************************/
#include "googlecontactatom.h"
#include <LogMacros.h>
GoogleContactAtom::BatchOperationResponse::BatchOperationResponse()
: isError(false)
{
}
GoogleContactAtom::GoogleContactAtom()
{
}
void GoogleContactAtom::setAuthorEmail(const QString &authorEmail)
{
mAuthorEmail = authorEmail;
}
QString GoogleContactAtom::authorEmail() const
{
return mAuthorEmail;
}
void GoogleContactAtom::setAuthorName(const QString &authorName)
{
mAuthorName = authorName;
}
QString GoogleContactAtom::authorName() const
{
return mAuthorName;
}
void GoogleContactAtom::setId(const QString &id)
{
mId = id;
}
QString GoogleContactAtom::id() const
{
return mId;
}
void GoogleContactAtom::setUpdated(const QString &updated)
{
mUpdated = updated;
}
QString GoogleContactAtom::updated() const
{
return mUpdated;
}
void GoogleContactAtom::setCategory(const QString &schema, const QString &term)
{
mCategorySchema = schema;
mCategoryTerm = term;
}
QString GoogleContactAtom::categorySchema() const
{
return mCategorySchema;
}
QString GoogleContactAtom::categoryTerm() const
{
return mCategoryTerm;
}
void GoogleContactAtom::setTitle(const QString &title)
{
mTitle = title;
}
QString GoogleContactAtom::title() const
{
return mTitle;
}
void GoogleContactAtom::setGenerator(const QString &name, const QString &version, const QString &uri)
{
mGeneratorName = name;
mGeneratorVersion = version;
mGeneratorUri = uri;
}
void GoogleContactAtom::setContent(const QString &note, const QString &type)
{
Q_UNUSED(note)
Q_UNUSED(type)
}
QString GoogleContactAtom::generatorName() const
{
return mGeneratorName;
}
QString GoogleContactAtom::generatorVersion() const
{
return mGeneratorVersion;
}
QString GoogleContactAtom::generatorUri() const
{
return mGeneratorUri;
}
void GoogleContactAtom::setTotalResults(int totalResults)
{
mTotalResults = totalResults;
}
int GoogleContactAtom::totalResults() const
{
return mTotalResults;
}
void GoogleContactAtom::setStartIndex(int startIndex)
{
mStartIndex = startIndex;
}
int GoogleContactAtom::startIndex() const
{
return mStartIndex;
}
void GoogleContactAtom::setItemsPerPage(int itemsPerPage)
{
mItemsPerPage = itemsPerPage;
}
int GoogleContactAtom::itemsPerPage() const
{
return mItemsPerPage;
}
void GoogleContactAtom::addBatchOperationResponse(const QString &operationId, GoogleContactAtom::BatchOperationResponse response)
{
mBatchOperationResponses.insert(operationId, response);
}
QMap<QString, GoogleContactAtom::BatchOperationResponse> GoogleContactAtom::batchOperationResponses() const
{
return mBatchOperationResponses;
}
void GoogleContactAtom::addEntryContact(const QContact &entryContact, const QStringList &unsupportedElements)
{
mContactList.append(qMakePair(entryContact, unsupportedElements));
}
QList<QPair<QContact, QStringList> > GoogleContactAtom::entryContacts() const
{
return mContactList;
}
void GoogleContactAtom::addDeletedEntryContact(const QContact &deletedContact)
{
mDeletedContactList.append(deletedContact);
}
QList<QContact> GoogleContactAtom::deletedEntryContacts() const
{
return mDeletedContactList;
}
void GoogleContactAtom::addEntrySystemGroup(const QString &systemGroupId, const QString &systemGroupAtomId, const QString &systemGroupTitle)
{
mSystemGroupAtomIds.insert(systemGroupId, qMakePair(systemGroupAtomId, systemGroupTitle));
}
QMap<QString, QPair<QString, QString> > GoogleContactAtom::entrySystemGroups() const
{
return mSystemGroupAtomIds;
}
void GoogleContactAtom::setNextEntriesUrl(const QString &nextUrl)
{
mNextEntriesUrl = nextUrl;
}
QString GoogleContactAtom::nextEntriesUrl() const
{
return mNextEntriesUrl;
}
/****************************************************************************
**
** Copyright (C) 2013-2014 Jolla Ltd. and/or its subsidiary(-ies).
** Contact: Chris Adams <chris.adams@jolla.com>
**
** Contributors: Sateesh Kavuri <sateesh.kavuri@gmail.com>
** Chris Adams <chris.adams@jolla.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 GOOGLECONTACTATOM_H
#define GOOGLECONTACTATOM_H
#include <QMetaEnum>
#include <QMap>
#include <QList>
#include <QXmlStreamWriter>
#include <QContact>
USE_CONTACTS_NAMESPACE
class GoogleContactAtom {
public:
GoogleContactAtom();
void setAuthorName(const QString &authorName);
QString authorName() const;
void setAuthorEmail(const QString &authorEmail);
QString authorEmail() const;
void setId(const QString &id);
QString id() const;
void setUpdated(const QString &updated);
QString updated() const;
void setCategory(const QString &schema = QStringLiteral("http://schemas.google.com/g/2005#kind"),
const QString &term = QStringLiteral("http://schemas.google.com/contact/2008#contact"));
QString categorySchema() const;
QString categoryTerm() const;
void setTitle(const QString &title);
QString title() const;
void setContent(const QString &note, const QString &type = QStringLiteral("text"));
void setGenerator(const QString &name = QStringLiteral("Contacts"),
const QString &version = QStringLiteral("1.0"),
const QString &uri = QStringLiteral("https://sailfishos.org"));
QString generatorName() const;
QString generatorVersion() const;
QString generatorUri() const;
void setTotalResults(int totalResults);
int totalResults() const;
void setStartIndex(int startIndex);
int startIndex() const;
void setItemsPerPage(int itemsPerPage);
int itemsPerPage() const;
void addEntryContact(const QContact &contact, const QStringList &unsupportedElements);
QList<QPair<QContact, QStringList> > entryContacts() const;
void addDeletedEntryContact(const QContact &contact);
QList<QContact> deletedEntryContacts() const;
void addEntrySystemGroup(const QString &systemGroupId, const QString &systemGroupAtomId, const QString &systemGroupTitle);
QMap<QString, QPair<QString, QString> > entrySystemGroups() const;
void setNextEntriesUrl(const QString &nextUrl);
QString nextEntriesUrl() const;
class BatchOperationResponse {
public:
BatchOperationResponse();
QStringList unsupportedElements;
QString operationId;
QString type;
QString code;
QString reason;
QString reasonDescription;
QString contactGuid;
QString etag;
bool isError;
};
void addBatchOperationResponse(const QString &operationId, BatchOperationResponse response);
QMap<QString, BatchOperationResponse> batchOperationResponses() const;
private:
QString mAuthorEmail;
QString mAuthorName;
QString mCategory;
QString mCategorySchema;
QString mCategoryTerm;
QString mContributor;
QString mGeneratorName;
QString mGeneratorVersion;
QString mGeneratorUri;
QString mIcon;
QString mId;
QString mLink;
QString mLogo;
QString mRights;
QString mSubtitle;
QString mTitle;
QString mUpdated;
int mTotalResults;
int mStartIndex;
int mItemsPerPage;
QMap<QString, BatchOperationResponse> mBatchOperationResponses;
QList<QContact> mDeletedContactList;
QList<QPair<QContact, QStringList> > mContactList;
QMap<QString, QPair<QString, QString> > mSystemGroupAtomIds;
QString mNextEntriesUrl;
};
#endif // GOOGLECONTACTATOM_H
......@@ -45,7 +45,6 @@ QNetworkReply * GoogleContactImageDownloader::createReply(const QString &url,
QString accessToken = metadata.value(IMAGE_DOWNLOADER_TOKEN_KEY).toString();
QNetworkRequest request(url);
request.setRawHeader("GData-Version", "3.0");
request.setRawHeader(QString(QLatin1String("Authorization")).toUtf8(),
QString(QLatin1String("Bearer ") + accessToken).toUtf8());
return d->networkAccessManager->get(request);
......
This diff is collapsed.
/****************************************************************************
**
** 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 <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
};
Q_ENUM(UpdateType)
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> &notes);
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 encodeUnknownElements(const QStringList &unknownElements);
QXmlStreamWriter *mXmlWriter;
QList<QContactId> mEncodedContactsWithAvatars;
QString mAccountEmail;
};
#endif // GOOGLECONTACTSTREAM_H
This diff is collapsed.
/****************************************************************************
**
** Copyright (c) 2021 Jolla Ltd.
**
** 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 GOOGLEPEOPLEAPI_H
#define GOOGLEPEOPLEAPI_H
#include "googlepeoplejson.h"
#include <QContact>
#include <QContactCollection>
QTCONTACTS_USE_NAMESPACE
namespace GooglePeopleApi
{
enum OperationType {
UnsupportedOperation,
CreateContact,
UpdateContact,
DeleteContact,
AddContactPhoto,
UpdateContactPhoto,
DeleteContactPhoto
};
}
class GooglePeopleApiRequest
{
public:
GooglePeopleApiRequest(const QString &accessToken);
~GooglePeopleApiRequest();
static QByteArray writeMultiPartRequest(const QMap<GooglePeopleApi::OperationType, QList<QContact> > &batch);
private:
QString m_accessToken;
};
class GooglePeopleApiResponse
{
public:
class PeopleConnectionsListResponse
{
public:
QList<GooglePeople::Person> connections;
QString nextPageToken;
QString nextSyncToken;
int totalPeople = 0;
int totalItems = 0;
void getContacts(int accountId,
const QList<QContactCollection> &candidateCollections,
QList<QContact> *addedOrModified,
QList<QContact> *deleted) const;
};
class ContactGroupsResponse
{
public:
// Note: for this response, memberResourceNames of each group are not populated
QList<GooglePeople::ContactGroup> contactGroups;
int totalItems = 0;
QString nextPageToken;
QString nextSyncToken;
};
class BatchResponsePart
{
public:
struct Error {
int code;
QString message;
QString status;
};
QString contentType;
QString contentId;
QString bodyStatusLine;
QString bodyContentType;
QByteArray body;
void reset();
void parse(GooglePeopleApi::OperationType *operationType,
QString *contactId,
GooglePeople::Person *person,
Error *error) const;
};
static bool readResponse(const QByteArray &data, ContactGroupsResponse *response);
static bool readResponse(const QByteArray &data, PeopleConnectionsListResponse *response);
static bool readMultiPartResponse(const QByteArray &data, QList<BatchResponsePart> *responseParts);
};
#endif // GOOGLEPEOPLEAPI_H
This diff is collapsed.
This diff is collapsed.
......@@ -23,7 +23,7 @@
#define GOOGLETWOWAYCONTACTSYNCADAPTOR_H
#include "googledatatypesyncadaptor.h"
#include "googlecontactstream.h"
#include "googlepeopleapi.h"
#include <twowaycontactsyncadaptor.h>
......@@ -46,7 +46,7 @@ public:
GoogleContactSqliteSyncAdaptor(int accountId, GoogleTwoWayContactSyncAdaptor *parent);
~GoogleContactSqliteSyncAdaptor();
int accountId() const;
bool isLocallyDeletedGuid(const QString &guid) const;
virtual bool determineRemoteCollections() override;
virtual bool deleteRemoteCollection(const QContactCollection &collection) override;
......@@ -71,12 +71,8 @@ public:
virtual void syncFinishedSuccessfully() override;
virtual void syncFinishedWithError() override;
QContactCollection m_collection;
QDateTime m_syncDateTime;
private:
GoogleTwoWayContactSyncAdaptor *q;
int m_accountId = 0;
};
class GoogleTwoWayContactSyncAdaptor : public GoogleDataTypeSyncAdaptor
......@@ -101,91 +97,82 @@ public:
virtual QString syncServiceName() const override;
virtual void sync(const QString &dataTypeString, int accountId) override;
void requestData(int accountId,
int startIndex,
const QString &continuationRequest,
const QDateTime &syncTimestamp,
DataRequestType requestType,
ContactChangeNotifier contactChangeNotifier = NoContactChangeNotifier);
void upsyncLocalChanges(const QDateTime &localSince,
const QList<QContact> &locallyAdded,
void requestData(DataRequestType requestType,
ContactChangeNotifier contactChangeNotifier = NoContactChangeNotifier,