~renatofilho/buteo-sync-plugins-contacts/solve-eds-conflict

« back to all changes in this revision

Viewing changes to google/GRemoteSource.h

  • Committer: CI Train Bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2015-09-24 17:50:44 UTC
  • mfrom: (1.3.53 initial-vr)
  • Revision ID: ci-train-bot@canonical.com-20150924175044-rp0akjs0h1xwxmpj
Implemented buteo contacts sync plugin for google, heavily based on:
  - https://github.com/nemomobile-graveyard/buteo-sync-plugins-google
  - https://github.com/nemomobile/buteo-sync-plugins-social
Approved by: Michael Sheldon

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of buteo-sync-plugins-contacts package
 
3
 *
 
4
 * Copyright (C) 2013 Jolla Ltd. and/or its subsidiary(-ies).
 
5
 *               2015 Canonical Ltd
 
6
 *
 
7
 * Contributors: Sateesh Kavuri <sateesh.kavuri@gmail.com>
 
8
 *               Mani Chandrasekar <maninc@gmail.com>
 
9
 *               Renato Araujo Oliveira Filho <renato.filho@canonical.com>
 
10
 *
 
11
 * This library is free software; you can redistribute it and/or
 
12
 * modify it under the terms of the GNU Lesser General Public License
 
13
 * version 2.1 as published by the Free Software Foundation.
 
14
 *
 
15
 * This library is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
18
 * Lesser General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU Lesser General Public
 
21
 * License along with this library; if not, write to the Free Software
 
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
23
 * 02110-1301 USA
 
24
 *
 
25
 */
 
26
 
 
27
#include "GContactStream.h"
 
28
 
 
29
#include <UAbstractRemoteSource.h>
 
30
 
 
31
#include <QHash>
 
32
#include <QScopedPointer>
 
33
 
 
34
class GTransport;
 
35
 
 
36
class GRemoteSource : public UAbstractRemoteSource
 
37
{
 
38
    Q_OBJECT
 
39
public:
 
40
    GRemoteSource(QObject *parent = 0);
 
41
    ~GRemoteSource();
 
42
 
 
43
    // UAbstractRemoteSource
 
44
    bool init(const QVariantMap &properties);
 
45
    void abort();
 
46
    void fetchContacts(const QDateTime &since, bool includeDeleted, bool fetchAvatar = true);
 
47
 
 
48
    // help on tests
 
49
    const GTransport *transport() const;
 
50
    int state() const;
 
51
 
 
52
protected:
 
53
    void saveContactsNonBatch(const QList<QtContacts::QContact> contacts);
 
54
    void removeContactsNonBatch(const QList<QtContacts::QContact> contacts);
 
55
 
 
56
    void batch(const QList<QtContacts::QContact> &contactsToCreate,
 
57
               const QList<QtContacts::QContact> &contactsToUpdate,
 
58
               const QList<QtContacts::QContact> &contactsToRemove);
 
59
 
 
60
private slots:
 
61
    void networkRequestFinished();
 
62
    void networkError(int errorCode);
 
63
 
 
64
private:
 
65
    enum SyncState {
 
66
        STATE_IDLE = 0,
 
67
        STATE_FETCHING_CONTACTS,
 
68
        STATE_BATCH_RUNNING,
 
69
        STATE_ABORTED
 
70
    };
 
71
 
 
72
    QScopedPointer<GTransport> mTransport;
 
73
    QString mRemoteUri;
 
74
    QString mAuthToken;
 
75
    QString mSyncTarget;
 
76
    QString mAccountName;
 
77
    SyncState mState;
 
78
    int mStartIndex;
 
79
    bool mFetchAvatars;
 
80
    QMap<QString, QPair<QString, QUrl> > mLocalIdToAvatar;
 
81
    QMap<QString, QContact> mLocalIdToContact;
 
82
    QMultiMap<GoogleContactStream::UpdateType, QPair<QtContacts::QContact, QStringList> > mPendingBatchOps;
 
83
 
 
84
    void fetchAvatars(QList<QtContacts::QContact> *contacts);
 
85
    void uploadAvatars(QList<QContact> *contacts);
 
86
    void fetchRemoteContacts(const QDateTime &since, bool includeDeleted, int startIndex);
 
87
    void batchOperationContinue();
 
88
    int parseErrorReponse(const GoogleContactAtom::BatchOperationResponse &response);
 
89
    void emitTransactionCommited(const QList<QtContacts::QContact> &created,
 
90
                                 const QList<QtContacts::QContact> &changed,
 
91
                                 const QList<QContact> &removed,
 
92
                                 const QMap<QString, int> &errorMap,
 
93
                                 Sync::SyncStatus status);
 
94
 
 
95
};