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

« back to all changes in this revision

Viewing changes to tests/unittest/GTransport.cpp

  • 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-gcontact-plugin package
 
3
 *
 
4
 * Copyright (C) 2015 Canonical Ltd.
 
5
 *
 
6
 * Contributors: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public License
 
10
 * version 2.1 as published by the Free Software Foundation.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
20
 * 02110-1301 USA
 
21
 *
 
22
 */
 
23
 
 
24
#include "GTransport.h"
 
25
 
 
26
#include <QBuffer>
 
27
#include <QDebug>
 
28
#include <QNetworkProxy>
 
29
#include <QDateTime>
 
30
#include <QUrlQuery>
 
31
 
 
32
#include <LogMacros.h>
 
33
 
 
34
const int MAX_RESULTS = 10;
 
35
const QString SCOPE_URL("https://www.google.com/m8/feeds/");
 
36
const QString GCONTACT_URL(SCOPE_URL + "/contacts/default/");
 
37
 
 
38
const QString GDATA_VERSION_TAG = "GData-Version";
 
39
const QString GDATA_VERSION = "3.1";
 
40
const QString G_DELETE_OVERRIDE_HEADER("X-HTTP-Method-Override: DELETE");
 
41
const QString G_ETAG_HEADER("If-Match ");
 
42
const QString G_AUTH_HEADER ("Authorization");
 
43
const QString G_CONTENT_TYPE_HEADER = "application/atom+xml";
 
44
 
 
45
/* Query parameters */
 
46
const QString QUERY_TAG("q");
 
47
const QString MAX_RESULTS_TAG("max-results");
 
48
const QString START_INDEX_TAG("start-index");
 
49
const QString UPDATED_MIN_TAG("updated-min");
 
50
const QString ORDERBY_TAG("orderby");
 
51
const QString SHOW_DELETED_TAG("showdeleted");
 
52
const QString REQUIRE_ALL_DELETED("requirealldeleted");
 
53
const QString SORTORDER_TAG("sortorder");
 
54
 
 
55
const QString PHOTO_TAG("photos");
 
56
const QString MEDIA_TAG("media");
 
57
const QString BATCH_TAG("batch");
 
58
 
 
59
class GTransportPrivate
 
60
{
 
61
public:
 
62
    GTransportPrivate(QObject *parent)
 
63
    {
 
64
    }
 
65
    QList<QPair<QByteArray, QByteArray> > mHeaders;
 
66
};
 
67
 
 
68
GTransport::GTransport(QObject *parent)
 
69
    : QObject(parent),
 
70
      d_ptr(new GTransportPrivate(this))
 
71
{
 
72
    FUNCTION_CALL_TRACE;
 
73
    Q_D(GTransport);
 
74
}
 
75
 
 
76
GTransport::GTransport(QUrl url, QList<QPair<QByteArray, QByteArray> > headers)
 
77
    : d_ptr(new GTransportPrivate(this))
 
78
{
 
79
    FUNCTION_CALL_TRACE;
 
80
    Q_D(GTransport);
 
81
}
 
82
 
 
83
GTransport::GTransport(QUrl url, QList<QPair<QByteArray, QByteArray> > headers, QByteArray data)
 
84
    : d_ptr(new GTransportPrivate(this))
 
85
{
 
86
    FUNCTION_CALL_TRACE;
 
87
    Q_D(GTransport);
 
88
}
 
89
 
 
90
GTransport::~GTransport()
 
91
{
 
92
    FUNCTION_CALL_TRACE;
 
93
    Q_D(GTransport);
 
94
}
 
95
 
 
96
void
 
97
GTransport::setUrl(const QString &url)
 
98
{
 
99
    FUNCTION_CALL_TRACE;
 
100
    Q_D(GTransport);
 
101
    setProperty("URL", url);
 
102
}
 
103
 
 
104
void
 
105
GTransport::setData(QByteArray data)
 
106
{
 
107
    FUNCTION_CALL_TRACE;
 
108
    Q_D(GTransport);
 
109
    setProperty("DATA", data);
 
110
}
 
111
 
 
112
void GTransport::setHeaders()
 
113
{
 
114
    FUNCTION_CALL_TRACE;
 
115
    Q_D(GTransport);
 
116
}
 
117
 
 
118
void
 
119
GTransport::addHeader(const QByteArray first, const QByteArray second)
 
120
{
 
121
    FUNCTION_CALL_TRACE;
 
122
    Q_D(GTransport);
 
123
    QVariantMap headers = property("Headers").value<QVariantMap>();
 
124
    headers.insert(first, second);
 
125
    setProperty("Headers", headers);
 
126
}
 
127
 
 
128
void
 
129
GTransport::setAuthToken(const QString token)
 
130
{
 
131
    FUNCTION_CALL_TRACE;
 
132
    Q_D(GTransport);
 
133
}
 
134
 
 
135
void
 
136
GTransport::setGDataVersionHeader()
 
137
{
 
138
    Q_D(GTransport);
 
139
    QVariantMap headers = property("Headers").value<QVariantMap>();
 
140
    headers.insert(QStringLiteral("GData-Version"), QStringLiteral("3.0"));
 
141
    setProperty("Headers", headers);
 
142
}
 
143
 
 
144
void
 
145
GTransport::setProxy (QString proxyHost, QString proxyPort)
 
146
{
 
147
    FUNCTION_CALL_TRACE;
 
148
    Q_D(GTransport);
 
149
    setProperty("ProxyHost", proxyHost);
 
150
    setProperty("ProxyPort", proxyPort);
 
151
}
 
152
 
 
153
void
 
154
GTransport::request(const HTTP_REQUEST_TYPE type)
 
155
{
 
156
    FUNCTION_CALL_TRACE;
 
157
    Q_D(GTransport);
 
158
    QUrl url(property("URL").toString());
 
159
    QByteArray data;
 
160
    emit requested(url, &data);
 
161
    setProperty("RequestType", (int) type);
 
162
    setProperty("ReplyBody", data);
 
163
    emit finishedRequest();
 
164
}
 
165
 
 
166
bool
 
167
GTransport::hasReply() const
 
168
{
 
169
    FUNCTION_CALL_TRACE;
 
170
    return true;
 
171
}
 
172
 
 
173
const
 
174
QByteArray GTransport::replyBody() const
 
175
{
 
176
    FUNCTION_CALL_TRACE;
 
177
    return property("ReplyBody").toByteArray();
 
178
}
 
179
 
 
180
void
 
181
GTransport::readyRead()
 
182
{
 
183
    FUNCTION_CALL_TRACE;
 
184
    Q_D(GTransport);
 
185
}
 
186
 
 
187
void
 
188
GTransport::finishedSlot(QNetworkReply *reply)
 
189
{
 
190
    FUNCTION_CALL_TRACE;
 
191
    Q_D(GTransport);
 
192
 
 
193
    emit finishedRequest();
 
194
}
 
195
 
 
196
void
 
197
GTransport::setUpdatedMin(const QDateTime datetime)
 
198
{
 
199
    FUNCTION_CALL_TRACE;
 
200
    Q_D(GTransport);
 
201
    setProperty("UpdatedMin", datetime);
 
202
}
 
203
 
 
204
void
 
205
GTransport::setMaxResults(unsigned int limit)
 
206
{
 
207
    FUNCTION_CALL_TRACE;
 
208
    Q_D(GTransport);
 
209
    setProperty("MaxResults", limit);
 
210
}
 
211
 
 
212
void
 
213
GTransport::setShowDeleted()
 
214
{
 
215
    FUNCTION_CALL_TRACE;
 
216
    Q_D(GTransport);
 
217
    setProperty("ShowDeleted", true);
 
218
}
 
219
 
 
220
bool GTransport::showDeleted() const
 
221
{
 
222
    const Q_D(GTransport);
 
223
    return property("ShowDeleted").toBool();
 
224
}
 
225
 
 
226
void
 
227
GTransport::setStartIndex(const int index)
 
228
{
 
229
    FUNCTION_CALL_TRACE;
 
230
    Q_D(GTransport);
 
231
    setProperty("StartIndex", index);
 
232
}
 
233
 
 
234
GTransport::HTTP_REQUEST_TYPE
 
235
GTransport::requestType()
 
236
{
 
237
    return GTransport::HTTP_REQUEST_TYPE(property("RequestType").toInt());
 
238
}
 
239
 
 
240
void
 
241
GTransport::reset()
 
242
{
 
243
    Q_D(GTransport);
 
244
}
 
245
 
 
246
void GTransport::setGroupFilter(const QString &account, const QString &groupId)
 
247
{
 
248
    setProperty("GroupFilter", QString("%1@%2").arg(account).arg(groupId));
 
249
}