2
* This file is part of buteo-gcontact-plugin package
4
* Copyright (C) 2015 Canonical Ltd.
6
* Contributors: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
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.
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.
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
24
#include "GTransport.h"
28
#include <QNetworkProxy>
32
#include <LogMacros.h>
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/");
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";
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");
55
const QString PHOTO_TAG("photos");
56
const QString MEDIA_TAG("media");
57
const QString BATCH_TAG("batch");
59
class GTransportPrivate
62
GTransportPrivate(QObject *parent)
65
QList<QPair<QByteArray, QByteArray> > mHeaders;
68
GTransport::GTransport(QObject *parent)
70
d_ptr(new GTransportPrivate(this))
76
GTransport::GTransport(QUrl url, QList<QPair<QByteArray, QByteArray> > headers)
77
: d_ptr(new GTransportPrivate(this))
83
GTransport::GTransport(QUrl url, QList<QPair<QByteArray, QByteArray> > headers, QByteArray data)
84
: d_ptr(new GTransportPrivate(this))
90
GTransport::~GTransport()
97
GTransport::setUrl(const QString &url)
101
setProperty("URL", url);
105
GTransport::setData(QByteArray data)
109
setProperty("DATA", data);
112
void GTransport::setHeaders()
119
GTransport::addHeader(const QByteArray first, const QByteArray second)
123
QVariantMap headers = property("Headers").value<QVariantMap>();
124
headers.insert(first, second);
125
setProperty("Headers", headers);
129
GTransport::setAuthToken(const QString token)
136
GTransport::setGDataVersionHeader()
139
QVariantMap headers = property("Headers").value<QVariantMap>();
140
headers.insert(QStringLiteral("GData-Version"), QStringLiteral("3.0"));
141
setProperty("Headers", headers);
145
GTransport::setProxy (QString proxyHost, QString proxyPort)
149
setProperty("ProxyHost", proxyHost);
150
setProperty("ProxyPort", proxyPort);
154
GTransport::request(const HTTP_REQUEST_TYPE type)
158
QUrl url(property("URL").toString());
160
emit requested(url, &data);
161
setProperty("RequestType", (int) type);
162
setProperty("ReplyBody", data);
163
emit finishedRequest();
167
GTransport::hasReply() const
174
QByteArray GTransport::replyBody() const
177
return property("ReplyBody").toByteArray();
181
GTransport::readyRead()
188
GTransport::finishedSlot(QNetworkReply *reply)
193
emit finishedRequest();
197
GTransport::setUpdatedMin(const QDateTime datetime)
201
setProperty("UpdatedMin", datetime);
205
GTransport::setMaxResults(unsigned int limit)
209
setProperty("MaxResults", limit);
213
GTransport::setShowDeleted()
217
setProperty("ShowDeleted", true);
220
bool GTransport::showDeleted() const
222
const Q_D(GTransport);
223
return property("ShowDeleted").toBool();
227
GTransport::setStartIndex(const int index)
231
setProperty("StartIndex", index);
234
GTransport::HTTP_REQUEST_TYPE
235
GTransport::requestType()
237
return GTransport::HTTP_REQUEST_TYPE(property("RequestType").toInt());
246
void GTransport::setGroupFilter(const QString &account, const QString &groupId)
248
setProperty("GroupFilter", QString("%1@%2").arg(account).arg(groupId));