Changeset View
Changeset View
Standalone View
Standalone View
src/provider.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | |||||
84 | 84 | | |||
85 | #include <QStringList> | 85 | #include <QStringList> | ||
86 | #include <QNetworkAccessManager> | 86 | #include <QNetworkAccessManager> | ||
87 | #include <QDebug> | 87 | #include <QDebug> | ||
88 | #include <QUrl> | 88 | #include <QUrl> | ||
89 | #include <QUrlQuery> | 89 | #include <QUrlQuery> | ||
90 | #include <QNetworkReply> | 90 | #include <QNetworkReply> | ||
91 | #include <QFile> | 91 | #include <QFile> | ||
92 | #include <QCoreApplication> | ||||
92 | 93 | | |||
93 | using namespace Attica; | 94 | using namespace Attica; | ||
94 | 95 | | |||
95 | QDebug operator<<(QDebug s, const Attica::Provider& prov) | 96 | QDebug operator<<(QDebug s, const Attica::Provider& prov) | ||
96 | { | 97 | { | ||
97 | if (prov.isValid()) | 98 | if (prov.isValid()) | ||
98 | s.nospace() << "Provider(" << prov.name() << ':' << prov.baseUrl() << ')'; | 99 | s.nospace() << "Provider(" << prov.name() << ':' << prov.baseUrl() << ')'; | ||
99 | else | 100 | else | ||
Show All 17 Lines | 107 | public: | |||
117 | QString m_contentVersion; | 118 | QString m_contentVersion; | ||
118 | QString m_fanVersion; | 119 | QString m_fanVersion; | ||
119 | QString m_forumVersion; | 120 | QString m_forumVersion; | ||
120 | QString m_knowledgebaseVersion; | 121 | QString m_knowledgebaseVersion; | ||
121 | QString m_eventVersion; | 122 | QString m_eventVersion; | ||
122 | QString m_commentVersion; | 123 | QString m_commentVersion; | ||
123 | QString m_registerUrl; | 124 | QString m_registerUrl; | ||
124 | PlatformDependent *m_internals; | 125 | PlatformDependent *m_internals; | ||
126 | QString m_additionalAgentInformation; | ||||
125 | 127 | | |||
126 | Private() | 128 | Private() | ||
127 | : m_internals(nullptr) | 129 | : m_internals(nullptr) | ||
128 | {} | 130 | {} | ||
129 | 131 | | |||
130 | Private(const Private &other) | 132 | Private(const Private &other) | ||
131 | : QSharedData(other), m_baseUrl(other.m_baseUrl), m_name(other.m_name) | 133 | : QSharedData(other), m_baseUrl(other.m_baseUrl), m_name(other.m_name) | ||
132 | , m_credentialsUserName(other.m_credentialsUserName) | 134 | , m_credentialsUserName(other.m_credentialsUserName) | ||
133 | , m_credentialsPassword(other.m_credentialsPassword) | 135 | , m_credentialsPassword(other.m_credentialsPassword) | ||
134 | , m_personVersion(other.m_personVersion) | 136 | , m_personVersion(other.m_personVersion) | ||
135 | , m_friendVersion(other.m_friendVersion) | 137 | , m_friendVersion(other.m_friendVersion) | ||
136 | , m_messageVersion(other.m_messageVersion) | 138 | , m_messageVersion(other.m_messageVersion) | ||
137 | , m_achievementVersion(other.m_achievementVersion) | 139 | , m_achievementVersion(other.m_achievementVersion) | ||
138 | , m_activityVersion(other.m_activityVersion) | 140 | , m_activityVersion(other.m_activityVersion) | ||
139 | , m_contentVersion(other.m_contentVersion) | 141 | , m_contentVersion(other.m_contentVersion) | ||
140 | , m_fanVersion(other.m_fanVersion) | 142 | , m_fanVersion(other.m_fanVersion) | ||
141 | , m_forumVersion(other.m_forumVersion) | 143 | , m_forumVersion(other.m_forumVersion) | ||
142 | , m_knowledgebaseVersion(other.m_knowledgebaseVersion) | 144 | , m_knowledgebaseVersion(other.m_knowledgebaseVersion) | ||
143 | , m_eventVersion(other.m_eventVersion) | 145 | , m_eventVersion(other.m_eventVersion) | ||
144 | , m_commentVersion(other.m_commentVersion) | 146 | , m_commentVersion(other.m_commentVersion) | ||
145 | , m_registerUrl(other.m_registerUrl) | 147 | , m_registerUrl(other.m_registerUrl) | ||
146 | , m_internals(other.m_internals) | 148 | , m_internals(other.m_internals) | ||
149 | , m_additionalAgentInformation(other.m_additionalAgentInformation) | ||||
147 | { | 150 | { | ||
148 | } | 151 | } | ||
149 | 152 | | |||
150 | Private(PlatformDependent *internals, const QUrl &baseUrl, const QString &name, const QUrl &icon, | 153 | Private(PlatformDependent *internals, const QUrl &baseUrl, const QString &name, const QUrl &icon, | ||
151 | const QString &person, const QString &friendV, const QString &message, const QString &achievement, | 154 | const QString &person, const QString &friendV, const QString &message, const QString &achievement, | ||
152 | const QString &activity, const QString &content, const QString &fan, const QString &forum, | 155 | const QString &activity, const QString &content, const QString &fan, const QString &forum, | ||
153 | const QString &knowledgebase, const QString &event, const QString &comment, const QString ®isterUrl) | 156 | const QString &knowledgebase, const QString &event, const QString &comment, const QString ®isterUrl, | ||
157 | const QString &additionalAgentInformation) | ||||
154 | : m_baseUrl(baseUrl), m_icon(icon), m_name(name) | 158 | : m_baseUrl(baseUrl), m_icon(icon), m_name(name) | ||
155 | , m_personVersion(person) | 159 | , m_personVersion(person) | ||
156 | , m_friendVersion(friendV) | 160 | , m_friendVersion(friendV) | ||
157 | , m_messageVersion(message) | 161 | , m_messageVersion(message) | ||
158 | , m_achievementVersion(achievement) | 162 | , m_achievementVersion(achievement) | ||
159 | , m_activityVersion(activity) | 163 | , m_activityVersion(activity) | ||
160 | , m_contentVersion(content) | 164 | , m_contentVersion(content) | ||
161 | , m_fanVersion(fan) | 165 | , m_fanVersion(fan) | ||
162 | , m_forumVersion(forum) | 166 | , m_forumVersion(forum) | ||
163 | , m_knowledgebaseVersion(knowledgebase) | 167 | , m_knowledgebaseVersion(knowledgebase) | ||
164 | , m_eventVersion(event) | 168 | , m_eventVersion(event) | ||
165 | , m_commentVersion(comment) | 169 | , m_commentVersion(comment) | ||
166 | , m_registerUrl(registerUrl) | 170 | , m_registerUrl(registerUrl) | ||
167 | , m_internals(internals) | 171 | , m_internals(internals) | ||
172 | , m_additionalAgentInformation(additionalAgentInformation) | ||||
168 | { | 173 | { | ||
169 | if (m_baseUrl.isEmpty()) { | 174 | if (m_baseUrl.isEmpty()) { | ||
170 | return; | 175 | return; | ||
171 | } | 176 | } | ||
172 | QString user; | 177 | QString user; | ||
173 | QString pass; | 178 | QString pass; | ||
174 | if (m_internals->hasCredentials(m_baseUrl) && m_internals->loadCredentials(m_baseUrl, user, pass)) { | 179 | if (m_internals->hasCredentials(m_baseUrl) && m_internals->loadCredentials(m_baseUrl, user, pass)) { | ||
175 | m_credentialsUserName = user; | 180 | m_credentialsUserName = user; | ||
Show All 16 Lines | |||||
192 | { | 197 | { | ||
193 | } | 198 | } | ||
194 | 199 | | |||
195 | Provider::Provider(PlatformDependent *internals, const QUrl &baseUrl, const QString &name, const QUrl &icon, | 200 | Provider::Provider(PlatformDependent *internals, const QUrl &baseUrl, const QString &name, const QUrl &icon, | ||
196 | const QString &person, const QString &friendV, const QString &message, const QString &achievement, | 201 | const QString &person, const QString &friendV, const QString &message, const QString &achievement, | ||
197 | const QString &activity, const QString &content, const QString &fan, const QString &forum, | 202 | const QString &activity, const QString &content, const QString &fan, const QString &forum, | ||
198 | const QString &knowledgebase, const QString &event, const QString &comment) | 203 | const QString &knowledgebase, const QString &event, const QString &comment) | ||
199 | : d(new Private(internals, baseUrl, name, icon, person, friendV, message, achievement, activity, content, | 204 | : d(new Private(internals, baseUrl, name, icon, person, friendV, message, achievement, activity, content, | ||
200 | fan, forum, knowledgebase, event, comment, QString())) | 205 | fan, forum, knowledgebase, event, comment, QString(), QString())) | ||
201 | { | 206 | { | ||
202 | } | 207 | } | ||
203 | 208 | | |||
204 | Provider::Provider(PlatformDependent *internals, const QUrl &baseUrl, const QString &name, const QUrl &icon, | 209 | Provider::Provider(PlatformDependent *internals, const QUrl &baseUrl, const QString &name, const QUrl &icon, | ||
205 | const QString &person, const QString &friendV, const QString &message, const QString &achievement, | 210 | const QString &person, const QString &friendV, const QString &message, const QString &achievement, | ||
206 | const QString &activity, const QString &content, const QString &fan, const QString &forum, | 211 | const QString &activity, const QString &content, const QString &fan, const QString &forum, | ||
207 | const QString &knowledgebase, const QString &event, const QString &comment, const QString ®isterUrl) | 212 | const QString &knowledgebase, const QString &event, const QString &comment, const QString ®isterUrl) | ||
208 | : d(new Private(internals, baseUrl, name, icon, person, friendV, message, achievement, activity, content, | 213 | : d(new Private(internals, baseUrl, name, icon, person, friendV, message, achievement, activity, content, | ||
209 | fan, forum, knowledgebase, event, comment, registerUrl)) | 214 | fan, forum, knowledgebase, event, comment, registerUrl, QString())) | ||
215 | { | ||||
216 | } | ||||
217 | | ||||
218 | Provider::Provider(PlatformDependent *internals, const QUrl &baseUrl, const QString &name, const QUrl &icon, | ||||
219 | const QString &person, const QString &friendV, const QString &message, const QString &achievement, | ||||
220 | const QString &activity, const QString &content, const QString &fan, const QString &forum, | ||||
221 | const QString &knowledgebase, const QString &event, const QString &comment, const QString ®isterUrl, | ||||
222 | const QString &additionalAgentInformation) | ||||
223 | : d(new Private(internals, baseUrl, name, icon, person, friendV, message, achievement, activity, content, | ||||
224 | fan, forum, knowledgebase, event, comment, registerUrl, additionalAgentInformation)) | ||||
210 | { | 225 | { | ||
211 | } | 226 | } | ||
212 | 227 | | |||
213 | Provider &Provider::operator=(const Attica::Provider &other) | 228 | Provider &Provider::operator=(const Attica::Provider &other) | ||
214 | { | 229 | { | ||
215 | d = other.d; | 230 | d = other.d; | ||
216 | return *this; | 231 | return *this; | ||
217 | } | 232 | } | ||
Show All 25 Lines | |||||
243 | { | 258 | { | ||
244 | if (!isValid()) { | 259 | if (!isValid()) { | ||
245 | return; | 260 | return; | ||
246 | } | 261 | } | ||
247 | 262 | | |||
248 | d->m_internals->enableProvider(d->m_baseUrl, enabled); | 263 | d->m_internals->enableProvider(d->m_baseUrl, enabled); | ||
249 | } | 264 | } | ||
250 | 265 | | |||
266 | void Provider::setAdditionalAgentInformation(const QString& additionalInformation) { | ||||
267 | d->m_additionalAgentInformation = additionalInformation; | ||||
268 | } | ||||
269 | | ||||
270 | QString Provider::additionalAgentInformation() const { | ||||
271 | return d->m_additionalAgentInformation; | ||||
272 | } | ||||
273 | | ||||
251 | QString Provider::name() const | 274 | QString Provider::name() const | ||
252 | { | 275 | { | ||
253 | return d->m_name; | 276 | return d->m_name; | ||
254 | } | 277 | } | ||
255 | 278 | | |||
256 | bool Provider::hasCredentials() | 279 | bool Provider::hasCredentials() | ||
257 | { | 280 | { | ||
258 | if (!isValid()) { | 281 | if (!isValid()) { | ||
▲ Show 20 Lines • Show All 1339 Lines • ▼ Show 20 Line(s) | 1620 | { | |||
1598 | QUrl url(d->m_baseUrl.toString() + path); | 1621 | QUrl url(d->m_baseUrl.toString() + path); | ||
1599 | return url; | 1622 | return url; | ||
1600 | } | 1623 | } | ||
1601 | 1624 | | |||
1602 | QNetworkRequest Provider::createRequest(const QUrl &url) | 1625 | QNetworkRequest Provider::createRequest(const QUrl &url) | ||
1603 | { | 1626 | { | ||
1604 | QNetworkRequest request(url); | 1627 | QNetworkRequest request(url); | ||
1605 | request.setHeader(QNetworkRequest::ContentTypeHeader,QStringLiteral("application/x-www-form-urlencoded")); | 1628 | request.setHeader(QNetworkRequest::ContentTypeHeader,QStringLiteral("application/x-www-form-urlencoded")); | ||
1629 | | ||||
1630 | QString agentHeader; | ||||
1631 | if (QCoreApplication::instance()) { | ||||
1632 | agentHeader = QString::fromLocal8Bit("%1/%2").arg(QCoreApplication::instance()->applicationName(), QCoreApplication::instance()->applicationVersion()); | ||||
davidedmundson: string.arg(foo, bar)
not
string.arg(foo).arg(bar)
otherwise we explode if foo contains the… | |||||
Oh dear, yes, quite - thanks :) Old habits die hard, got a few places that'll want doing in... various places, i'll have to take a look. leinir: Oh dear, yes, quite - thanks :) Old habits die hard, got a few places that'll want doing in... | |||||
1633 | } else { | ||||
1634 | agentHeader = QString::fromLocal8Bit("Attica/%1").arg(QCoreApplication::instance()->applicationVersion()); | ||||
davidedmundson: where does %1 get set?
(same for the %2 below) | |||||
1635 | } | ||||
1636 | if (!d->m_additionalAgentInformation.isEmpty()) { | ||||
1637 | agentHeader = QString::fromLocal8Bit("%1 (+%2)").arg(agentHeader, d->m_additionalAgentInformation); | ||||
1638 | } | ||||
1639 | request.setHeader(QNetworkRequest::UserAgentHeader, agentHeader); | ||||
1640 | | ||||
1606 | if (!d->m_credentialsUserName.isEmpty()) { | 1641 | if (!d->m_credentialsUserName.isEmpty()) { | ||
1607 | request.setAttribute((QNetworkRequest::Attribute) BaseJob::UserAttribute, QVariant(d->m_credentialsUserName)); | 1642 | request.setAttribute((QNetworkRequest::Attribute) BaseJob::UserAttribute, QVariant(d->m_credentialsUserName)); | ||
1608 | request.setAttribute((QNetworkRequest::Attribute) BaseJob::PasswordAttribute, QVariant(d->m_credentialsPassword)); | 1643 | request.setAttribute((QNetworkRequest::Attribute) BaseJob::PasswordAttribute, QVariant(d->m_credentialsPassword)); | ||
1609 | } | 1644 | } | ||
1610 | return request; | 1645 | return request; | ||
1611 | } | 1646 | } | ||
1612 | 1647 | | |||
1613 | QNetworkRequest Provider::createRequest(const QString &path) | 1648 | QNetworkRequest Provider::createRequest(const QString &path) | ||
▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines |
string.arg(foo, bar)
not
string.arg(foo).arg(bar)
otherwise we explode if foo contains the string "%1"