Attica

provider.cpp
1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2008 Cornelius Schumacher <schumacher@kde.org>
5 SPDX-FileCopyrightText: 2010 Sebastian Kügler <sebas@kde.org>
6 SPDX-FileCopyrightText: 2011 Laszlo Papp <djszapi@archlinux.us>
7
8 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
9*/
10
11#include "provider.h"
12
13#include "accountbalance.h"
14#include "accountbalanceparser.h"
15#include "achievementparser.h"
16#include "activity.h"
17#include "activityparser.h"
18#include "buildservice.h"
19#include "buildservicejob.h"
20#include "buildservicejoboutput.h"
21#include "buildservicejoboutputparser.h"
22#include "buildservicejobparser.h"
23#include "buildserviceparser.h"
24#include "categoryparser.h"
25#include "commentparser.h"
26#include "config.h"
27#include "content.h"
28#include "contentparser.h"
29#include "distributionparser.h"
30#include "downloaditem.h"
31#include "downloaditemparser.h"
32#include "event.h"
33#include "eventparser.h"
34#include "folder.h"
35#include "folderparser.h"
36#include "forumparser.h"
37#include "homepagetype.h"
38#include "homepagetypeparser.h"
39#include "knowledgebaseentry.h"
40#include "knowledgebaseentryparser.h"
41#include "licenseparser.h"
42#include "messageparser.h"
43#include "person.h"
44#include "personparser.h"
45#include "platformdependent_v2.h"
46#include "postfiledata.h"
47#include "postjob.h"
48#include "privatedata.h"
49#include "privatedataparser.h"
50#include "project.h"
51#include "projectparser.h"
52#include "publisher.h"
53#include "publisherfield.h"
54#include "publisherfieldparser.h"
55#include "publisherparser.h"
56#include "remoteaccount.h"
57#include "remoteaccountparser.h"
58#include "topic.h"
59#include "topicparser.h"
60#include "version.h"
61
62#include <QCoreApplication>
63#include <QDebug>
64#include <QFile>
65#include <QNetworkAccessManager>
66#include <QNetworkReply>
67#include <QThreadStorage>
68#include <QUrlQuery>
69
70using namespace Attica;
71
72class Q_DECL_HIDDEN Provider::Private : public QSharedData
73{
74public:
75 QUrl m_baseUrl;
76 QUrl m_icon;
77 QString m_name;
78 QString m_credentialsUserName;
79 QString m_credentialsPassword;
80 QString m_personVersion;
81 QString m_friendVersion;
82 QString m_messageVersion;
83 QString m_achievementVersion;
84 QString m_activityVersion;
85 QString m_contentVersion;
86 QString m_fanVersion;
87 QString m_forumVersion;
88 QString m_knowledgebaseVersion;
89 QString m_eventVersion;
90 QString m_commentVersion;
91 QString m_registerUrl;
92 PlatformDependent *m_internals;
93 QString m_additionalAgentInformation;
94
95 Private()
96 : m_internals(nullptr)
97 {
98 }
99
100 Private(const Private &other)
101 : QSharedData(other)
102 , m_baseUrl(other.m_baseUrl)
103 , m_name(other.m_name)
104 , m_credentialsUserName(other.m_credentialsUserName)
105 , m_credentialsPassword(other.m_credentialsPassword)
106 , m_personVersion(other.m_personVersion)
107 , m_friendVersion(other.m_friendVersion)
108 , m_messageVersion(other.m_messageVersion)
109 , m_achievementVersion(other.m_achievementVersion)
110 , m_activityVersion(other.m_activityVersion)
111 , m_contentVersion(other.m_contentVersion)
112 , m_fanVersion(other.m_fanVersion)
113 , m_forumVersion(other.m_forumVersion)
114 , m_knowledgebaseVersion(other.m_knowledgebaseVersion)
115 , m_eventVersion(other.m_eventVersion)
116 , m_commentVersion(other.m_commentVersion)
117 , m_registerUrl(other.m_registerUrl)
118 , m_internals(other.m_internals)
119 , m_additionalAgentInformation(other.m_additionalAgentInformation)
120 {
121 }
122
123 Private(PlatformDependent *internals,
124 const QUrl &baseUrl,
125 const QString &name,
126 const QUrl &icon,
127 const QString &person,
128 const QString &friendV,
129 const QString &message,
130 const QString &achievement,
131 const QString &activity,
132 const QString &content,
133 const QString &fan,
134 const QString &forum,
135 const QString &knowledgebase,
136 const QString &event,
137 const QString &comment,
138 const QString &registerUrl,
139 const QString &additionalAgentInformation)
140 : m_baseUrl(baseUrl)
141 , m_icon(icon)
142 , m_name(name)
143 , m_personVersion(person)
144 , m_friendVersion(friendV)
145 , m_messageVersion(message)
146 , m_achievementVersion(achievement)
147 , m_activityVersion(activity)
148 , m_contentVersion(content)
149 , m_fanVersion(fan)
150 , m_forumVersion(forum)
151 , m_knowledgebaseVersion(knowledgebase)
152 , m_eventVersion(event)
153 , m_commentVersion(comment)
154 , m_registerUrl(registerUrl)
155 , m_internals(internals)
156 , m_additionalAgentInformation(additionalAgentInformation)
157 {
158 if (m_baseUrl.isEmpty()) {
159 return;
160 }
161 QString user;
162 QString pass;
163 if (m_internals->hasCredentials(m_baseUrl) && m_internals->loadCredentials(m_baseUrl, user, pass)) {
164 m_credentialsUserName = user;
165 m_credentialsPassword = pass;
166 }
167 }
168
169 ~Private()
170 {
171 }
172};
173
175 : d(new Private)
176{
177}
178
179Provider::Provider(const Provider &other)
180 : d(other.d)
181{
182}
183
184Provider::Provider(PlatformDependent *internals,
185 const QUrl &baseUrl,
186 const QString &name,
187 const QUrl &icon,
188 const QString &person,
189 const QString &friendV,
190 const QString &message,
191 const QString &achievement,
192 const QString &activity,
193 const QString &content,
194 const QString &fan,
195 const QString &forum,
196 const QString &knowledgebase,
197 const QString &event,
198 const QString &comment)
199 : d(new Private(internals,
200 baseUrl,
201 name,
202 icon,
203 person,
204 friendV,
205 message,
206 achievement,
207 activity,
208 content,
209 fan,
210 forum,
211 knowledgebase,
212 event,
213 comment,
214 QString(),
215 QString()))
216{
217}
218
219Provider::Provider(PlatformDependent *internals,
220 const QUrl &baseUrl,
221 const QString &name,
222 const QUrl &icon,
223 const QString &person,
224 const QString &friendV,
225 const QString &message,
226 const QString &achievement,
227 const QString &activity,
228 const QString &content,
229 const QString &fan,
230 const QString &forum,
231 const QString &knowledgebase,
232 const QString &event,
233 const QString &comment,
234 const QString &registerUrl)
235 : d(new Private(internals,
236 baseUrl,
237 name,
238 icon,
239 person,
240 friendV,
241 message,
242 achievement,
243 activity,
244 content,
245 fan,
246 forum,
247 knowledgebase,
248 event,
249 comment,
250 registerUrl,
251 QString()))
252{
253}
254
255Provider::Provider(PlatformDependent *internals,
256 const QUrl &baseUrl,
257 const QString &name,
258 const QUrl &icon,
259 const QString &person,
260 const QString &friendV,
261 const QString &message,
262 const QString &achievement,
263 const QString &activity,
264 const QString &content,
265 const QString &fan,
266 const QString &forum,
267 const QString &knowledgebase,
268 const QString &event,
269 const QString &comment,
270 const QString &registerUrl,
271 const QString &additionalAgentInformation)
272 : d(new Private(internals,
273 baseUrl,
274 name,
275 icon,
276 person,
277 friendV,
278 message,
279 achievement,
280 activity,
281 content,
282 fan,
283 forum,
284 knowledgebase,
285 event,
286 comment,
287 registerUrl,
288 additionalAgentInformation))
289{
290}
291
292Provider &Provider::operator=(const Attica::Provider &other)
293{
294 d = other.d;
295 return *this;
296}
297
298Provider::~Provider()
299{
300}
301
303{
304 return d->m_baseUrl;
305}
306
308{
309 return d->m_baseUrl.isValid();
310}
311
313{
314 if (!isValid()) {
315 return false;
316 }
317
318 return d->m_internals->isEnabled(d->m_baseUrl);
319}
320
321void Provider::setEnabled(bool enabled)
322{
323 if (!isValid()) {
324 return;
325 }
326
327 d->m_internals->enableProvider(d->m_baseUrl, enabled);
328}
329
330void Provider::setAdditionalAgentInformation(const QString &additionalInformation)
331{
332 d->m_additionalAgentInformation = additionalInformation;
333}
334
336{
337 return d->m_additionalAgentInformation;
338}
339
341{
342 return d->m_name;
343}
344
346{
347 return d->m_icon;
348}
349
351{
352 if (!isValid()) {
353 return false;
354 }
355
356 return d->m_internals->hasCredentials(d->m_baseUrl);
357}
358
360{
361 if (!isValid()) {
362 return false;
363 }
364
365 return d->m_internals->hasCredentials(d->m_baseUrl);
366}
367
369{
370 if (!isValid()) {
371 return false;
372 }
373
374 if (d->m_internals->loadCredentials(d->m_baseUrl, user, password)) {
375 d->m_credentialsUserName = user;
376 d->m_credentialsPassword = password;
377 return true;
378 }
379 return false;
380}
381
382bool Provider::saveCredentials(const QString &user, const QString &password)
383{
384 if (!isValid()) {
385 return false;
386 }
387
388 d->m_credentialsUserName = user;
389 d->m_credentialsPassword = password;
390 return d->m_internals->saveCredentials(d->m_baseUrl, user, password);
391}
392
393PostJob *Provider::checkLogin(const QString &user, const QString &password)
394{
395 if (!isValid()) {
396 return nullptr;
397 }
398
399 QMap<QString, QString> postParameters;
400
401 postParameters.insert(QLatin1String("login"), user);
402 postParameters.insert(QLatin1String("password"), password);
403
404 return new PostJob(d->m_internals, createRequest(QLatin1String("person/check")), postParameters);
405}
406
408{
409 if (!isValid()) {
410 return nullptr;
411 }
412
413 QUrl url = createUrl(QLatin1String("config"));
414 return doRequestConfig(url);
415}
416
417PostJob *Provider::registerAccount(const QString &id, const QString &password, const QString &mail, const QString &firstName, const QString &lastName)
418{
419 if (!isValid()) {
420 return nullptr;
421 }
422
423 QMap<QString, QString> postParameters;
424
425 postParameters.insert(QLatin1String("login"), id);
426 postParameters.insert(QLatin1String("password"), password);
427 postParameters.insert(QLatin1String("firstname"), firstName);
428 postParameters.insert(QLatin1String("lastname"), lastName);
429 postParameters.insert(QLatin1String("email"), mail);
430
431 return new PostJob(d->m_internals, createRequest(QLatin1String("person/add")), postParameters);
432}
433
434const QString &Provider::getRegisterAccountUrl() const
435{
436 return d->m_registerUrl;
437}
438
439ItemJob<Person> *Provider::requestPerson(const QString &id)
440{
441 if (!isValid()) {
442 return nullptr;
443 }
444
445 QUrl url = createUrl(QLatin1String("person/data/") + id);
446 return doRequestPerson(url);
447}
448
449ItemJob<Person> *Provider::requestPersonSelf()
450{
451 if (!isValid()) {
452 return nullptr;
453 }
454
455 QUrl url = createUrl(QLatin1String("person/self"));
456 return doRequestPerson(url);
457}
458
459ItemJob<AccountBalance> *Provider::requestAccountBalance()
460{
461 if (!isValid()) {
462 return nullptr;
463 }
464
465 QUrl url = createUrl(QLatin1String("person/balance"));
466 return doRequestAccountBalance(url);
467}
468
469ListJob<Person> *Provider::requestPersonSearchByName(const QString &name)
470{
471 if (!isValid()) {
472 return nullptr;
473 }
474
475 QUrl url = createUrl(QStringLiteral("person/data"));
476 QUrlQuery q(url);
477 q.addQueryItem(QStringLiteral("name"), name);
478 url.setQuery(q);
479 return doRequestPersonList(url);
480}
481
482ListJob<Person> *Provider::requestPersonSearchByLocation(qreal latitude, qreal longitude, qreal distance, int page, int pageSize)
483{
484 if (!isValid()) {
485 return nullptr;
486 }
487
488 QUrl url = createUrl(QStringLiteral("person/data"));
489 QUrlQuery q(url);
490 q.addQueryItem(QStringLiteral("latitude"), QString::number(latitude));
491 q.addQueryItem(QStringLiteral("longitude"), QString::number(longitude));
492 if (distance > 0.0) {
493 q.addQueryItem(QStringLiteral("distance"), QString::number(distance));
494 }
495 q.addQueryItem(QStringLiteral("page"), QString::number(page));
496 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
497 url.setQuery(q);
498
499 return doRequestPersonList(url);
500}
501
502ListJob<Person> *Provider::requestFriends(const QString &id, int page, int pageSize)
503{
504 if (!isValid()) {
505 return nullptr;
506 }
507
508 QUrl url = createUrl(QLatin1String("friend/data/") + id);
509 QUrlQuery q(url);
510 q.addQueryItem(QLatin1String("page"), QString::number(page));
511 q.addQueryItem(QLatin1String("pagesize"), QString::number(pageSize));
512 url.setQuery(q);
513
514 return doRequestPersonList(url);
515}
516
517ListJob<Person> *Provider::requestSentInvitations(int page, int pageSize)
518{
519 if (!isValid()) {
520 return nullptr;
521 }
522
523 QUrl url = createUrl(QStringLiteral("friend/sentinvitations"));
524 QUrlQuery q(url);
525 q.addQueryItem(QStringLiteral("page"), QString::number(page));
526 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
527 url.setQuery(q);
528
529 return doRequestPersonList(url);
530}
531
532ListJob<Person> *Provider::requestReceivedInvitations(int page, int pageSize)
533{
534 if (!isValid()) {
535 return nullptr;
536 }
537
538 QUrl url = createUrl(QStringLiteral("friend/receivedinvitations"));
539 QUrlQuery q(url);
540 q.addQueryItem(QStringLiteral("page"), QString::number(page));
541 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
542 url.setQuery(q);
543
544 return doRequestPersonList(url);
545}
546
547ListJob<Achievement> *Provider::requestAchievements(const QString &contentId, const QString &achievementId, const QString &userId)
548{
549 if (!isValid()) {
550 return nullptr;
551 }
552
553 QUrl url = createUrl(QLatin1String("achievements/content/") + contentId + achievementId);
554 QUrlQuery q(url);
555 q.addQueryItem(QStringLiteral("user_id"), userId);
556 url.setQuery(q);
557 return doRequestAchievementList(url);
558}
559
561{
562 if (!isValid()) {
563 return nullptr;
564 }
565
566 StringMap postParameters;
567 int i = 0;
568 int j = 0;
569
570 postParameters.insert(QLatin1String("name"), newAchievement.name());
571 postParameters.insert(QLatin1String("description"), newAchievement.description());
572 postParameters.insert(QLatin1String("explanation"), newAchievement.explanation());
573 postParameters.insert(QLatin1String("points"), QString::number(newAchievement.points()));
574 postParameters.insert(QLatin1String("image"), newAchievement.image().toLocalFile());
575 const auto dependenciesList = newAchievement.dependencies();
576 for (const QString &dependency : dependenciesList) {
577 postParameters.insert(QString::fromLatin1("dependencies[%1]").arg(QString::number(i++)), dependency);
578 }
579
580 postParameters.insert(QLatin1String("type"), Achievement::achievementTypeToString(newAchievement.type()));
581 const auto optionsList = newAchievement.options();
582 for (const QString &option : optionsList) {
583 postParameters.insert(QString::fromLatin1("options[%1]").arg(QString::number(j++)), option);
584 }
585
586 postParameters.insert(QLatin1String("steps"), QString::number(newAchievement.steps()));
587 postParameters.insert(QLatin1String("visibility"), Achievement::achievementVisibilityToString(newAchievement.visibility()));
588
589 return new ItemPostJob<Achievement>(d->m_internals, createRequest(QLatin1String("achievements/content/") + contentId), postParameters);
590}
591
592PutJob *Provider::editAchievement(const QString &contentId, const QString &achievementId, const Achievement &achievement)
593{
594 if (!isValid()) {
595 return nullptr;
596 }
597
598 if (!dynamic_cast<Attica::PlatformDependentV2 *>(d->m_internals)) {
599 return nullptr;
600 }
601
602 StringMap postParameters;
603 int i = 0;
604 int j = 0;
605
606 postParameters.insert(QLatin1String("name"), achievement.name());
607 postParameters.insert(QLatin1String("description"), achievement.description());
608 postParameters.insert(QLatin1String("explanation"), achievement.explanation());
609 postParameters.insert(QLatin1String("points"), QString::number(achievement.points()));
610 postParameters.insert(QLatin1String("image"), achievement.image().toLocalFile());
611 const auto dependenciesList = achievement.dependencies();
612 for (const QString &dependency : dependenciesList) {
613 postParameters.insert(QString::fromLatin1("dependencies[%1]").arg(QString::number(i++)), dependency);
614 }
615
616 postParameters.insert(QLatin1String("type"), Achievement::achievementTypeToString(achievement.type()));
617 const auto optionsList = achievement.options();
618 for (const QString &option : optionsList) {
619 postParameters.insert(QString::fromLatin1("options[%1]").arg(QString::number(j++)), option);
620 }
621
622 postParameters.insert(QLatin1String("steps"), QString::number(achievement.steps()));
623 postParameters.insert(QLatin1String("visibility"), Achievement::achievementVisibilityToString(achievement.visibility()));
624
625 return new ItemPutJob<Achievement>(d->m_internals, createRequest(QLatin1String("achievement/content/") + contentId + achievementId), postParameters);
626}
627
628DeleteJob *Provider::deleteAchievement(const QString &contentId, const QString &achievementId)
629{
630 if (!isValid()) {
631 return nullptr;
632 }
633
634 if (!dynamic_cast<Attica::PlatformDependentV2 *>(d->m_internals)) {
635 return nullptr;
636 }
637
638 return new ItemDeleteJob<Achievement>(d->m_internals, createRequest(QLatin1String("achievements/progress/") + contentId + achievementId));
639}
640
641PostJob *Provider::setAchievementProgress(const QString &id, const QVariant &progress, const QDateTime &timestamp)
642{
643 if (!isValid()) {
644 return nullptr;
645 }
646
647 StringMap postParameters;
648
649 postParameters.insert(QLatin1String("progress"), progress.toString());
650 postParameters.insert(QLatin1String("timestamp"), timestamp.toString());
651
652 return new ItemPostJob<Achievement>(d->m_internals, createRequest(QLatin1String("achievements/progress/") + id), postParameters);
653}
654
655DeleteJob *Provider::resetAchievementProgress(const QString &id)
656{
657 if (!isValid()) {
658 return nullptr;
659 }
660
661 if (!dynamic_cast<Attica::PlatformDependentV2 *>(d->m_internals)) {
662 return nullptr;
663 }
664
665 return new ItemDeleteJob<Achievement>(d->m_internals, createRequest(QLatin1String("achievements/progress/") + id));
666}
667
668ListJob<Activity> *Provider::requestActivities()
669{
670 if (!isValid()) {
671 return nullptr;
672 }
673
674 // qCDebug(ATTICA) << "request activity";
675 QUrl url = createUrl(QLatin1String("activity"));
676 return doRequestActivityList(url);
677}
678
680{
681 if (!isValid()) {
682 return nullptr;
683 }
684
685 // qCDebug(ATTICA) << "request projects";
686 QUrl url = createUrl(QLatin1String("buildservice/project/list"));
687 return new ListJob<Project>(d->m_internals, createRequest(url));
688}
689
691{
692 if (!isValid()) {
693 return nullptr;
694 }
695
696 QUrl url = createUrl(QLatin1String("buildservice/project/get/") + id);
697 // qCDebug(ATTICA) << url;
698 return new ItemJob<Project>(d->m_internals, createRequest(url));
699}
700
701QMap<QString, QString> projectPostParameters(const Project &project)
702{
703 QMap<QString, QString> postParameters;
704
705 if (!project.name().isEmpty()) {
706 postParameters.insert(QLatin1String("name"), project.name());
707 }
708 if (!project.summary().isEmpty()) {
709 postParameters.insert(QLatin1String("summary"), project.summary());
710 }
711 if (!project.description().isEmpty()) {
712 postParameters.insert(QLatin1String("description"), project.description());
713 }
714 if (!project.url().isEmpty()) {
715 postParameters.insert(QLatin1String("url"), project.url());
716 }
717 if (!project.developers().isEmpty()) {
718 postParameters.insert(QLatin1String("developers"), project.developers().join(QLatin1Char('\n')));
719 }
720 if (!project.version().isEmpty()) {
721 postParameters.insert(QLatin1String("version"), project.version());
722 }
723 if (!project.license().isEmpty()) {
724 postParameters.insert(QLatin1String("license"), project.license());
725 }
726 if (!project.requirements().isEmpty()) {
727 postParameters.insert(QLatin1String("requirements"), project.requirements());
728 }
729 // The specfile generator expects an empty string parameter if it is supposed to regenerate the spec file
730 // So we need to check for nullity here as opposed to an empty string.
731 if (!project.specFile().isNull()) {
732 postParameters.insert(QLatin1String("specfile"), project.specFile());
733 }
734 return postParameters;
735}
736
738{
739 if (!isValid()) {
740 return nullptr;
741 }
742
743 return new PostJob(d->m_internals, createRequest(QLatin1String("buildservice/project/create")), projectPostParameters(project));
744}
745
747{
748 if (!isValid()) {
749 return nullptr;
750 }
751
752 return new PostJob(d->m_internals, createRequest(QLatin1String("buildservice/project/edit/") + project.id()), projectPostParameters(project));
753}
754
756{
757 if (!isValid()) {
758 return nullptr;
759 }
760
761 return new PostJob(d->m_internals, createRequest(QLatin1String("buildservice/project/delete/") + project.id()), projectPostParameters(project));
762}
763
765{
766 if (!isValid()) {
767 return nullptr;
768 }
769
770 QUrl url = createUrl(QLatin1String("buildservice/buildservices/get/") + id);
771 return new ItemJob<BuildService>(d->m_internals, createRequest(url));
772}
773
775{
776 if (!isValid()) {
777 return nullptr;
778 }
779
780 // qCDebug(ATTICA) << "request publisher" << id;
781 QUrl url = createUrl(QLatin1String("buildservice/publishing/getpublisher/") + id);
782 return new ItemJob<Publisher>(d->m_internals, createRequest(url));
783}
784
786{
787 if (!isValid()) {
788 return nullptr;
789 }
790
791 StringMap postParameters;
792 postParameters.insert(QLatin1String("fields[0][name]"), field.name());
793 postParameters.insert(QLatin1String("fields[0][fieldtype]"), field.type());
794 postParameters.insert(QLatin1String("fields[0][data]"), field.data());
795
796 QString url = QLatin1String("buildservice/publishing/savefields/") + project.id();
797 // qCDebug(ATTICA) << "saving field values...";
798 return new PostJob(d->m_internals, createRequest(url), postParameters);
799}
800
802{
803 if (!isValid()) {
804 return nullptr;
805 }
806
807 StringMap postParameters;
808 postParameters.insert(QLatin1String("dummyparameter"), QLatin1String("dummyvalue"));
809
810 QString url = QLatin1String("buildservice/publishing/publishtargetresult/") + buildjob.id() + QLatin1Char('/') + publisher.id();
811 // qCDebug(ATTICA) << "pub'ing";
812 return new PostJob(d->m_internals, createRequest(url), postParameters);
813}
814
815// Buildservices and their jobs
817{
818 if (!isValid()) {
819 return nullptr;
820 }
821
822 QUrl url = createUrl(QLatin1String("buildservice/jobs/getoutput/") + id);
823 // qCDebug(ATTICA) << url;
824 return new ItemJob<BuildServiceJobOutput>(d->m_internals, createRequest(url));
825}
826
828{
829 if (!isValid()) {
830 return nullptr;
831 }
832
833 QUrl url = createUrl(QLatin1String("buildservice/jobs/get/") + id);
834 // qCDebug(ATTICA) << url;
835 return new ItemJob<BuildServiceJob>(d->m_internals, createRequest(url));
836}
837
838QMap<QString, QString> buildServiceJobPostParameters(const BuildServiceJob &buildjob)
839{
840 QMap<QString, QString> postParameters;
841
842 if (!buildjob.name().isEmpty()) {
843 postParameters.insert(QLatin1String("name"), buildjob.name());
844 }
845 if (!buildjob.projectId().isEmpty()) {
846 postParameters.insert(QLatin1String("projectid"), buildjob.projectId());
847 }
848 if (!buildjob.target().isEmpty()) {
849 postParameters.insert(QLatin1String("target"), buildjob.target());
850 }
851 if (!buildjob.buildServiceId().isEmpty()) {
852 postParameters.insert(QLatin1String("buildservice"), buildjob.buildServiceId());
853 }
854
855 return postParameters;
856}
857
859{
860 if (!isValid()) {
861 return nullptr;
862 }
863
864 StringMap postParameters;
865 postParameters.insert(QLatin1String("dummyparameter"), QLatin1String("dummyvalue"));
866 // qCDebug(ATTICA) << "b....................b";
867 return new PostJob(d->m_internals, createRequest(QLatin1String("buildservice/jobs/cancel/") + job.id()), postParameters);
868}
869
871{
872 if (!isValid()) {
873 return nullptr;
874 }
875
876 StringMap postParameters;
877 // A postjob won't be run without parameters.
878 // so even while we don't need any in this case,
879 // we add dummy data to the request
880 postParameters.insert(QLatin1String("dummyparameter"), QLatin1String("dummyvalue"));
881 // qCDebug(ATTICA) << "Creating new BSJ on" << job.buildServiceId();
882 return new PostJob(
883 d->m_internals,
884 createRequest(QLatin1String("buildservice/jobs/create/") + job.projectId() + QLatin1Char('/') + job.buildServiceId() + QLatin1Char('/') + job.target()),
885 postParameters);
886}
887
889{
890 if (!isValid()) {
891 return nullptr;
892 }
893
894 // qCDebug(ATTICA) << "request projects";
895 QUrl url = createUrl(QLatin1String("buildservice/buildservices/list"));
896 return new ListJob<BuildService>(d->m_internals, createRequest(url));
897}
898
900{
901 if (!isValid()) {
902 return nullptr;
903 }
904
905 QUrl url = createUrl(QLatin1String("buildservice/publishing/getpublishingcapabilities"));
906 // qCDebug(ATTICA) << "request publishers" << url;
907 return new ListJob<Publisher>(d->m_internals, createRequest(url));
908}
909
911{
912 if (!isValid()) {
913 return nullptr;
914 }
915
916 // qCDebug(ATTICA) << "request projects";
917 QUrl url = createUrl(QLatin1String("buildservice/jobs/list/") + project.id());
918 return new ListJob<BuildServiceJob>(d->m_internals, createRequest(url));
919}
920
922{
923 if (!isValid()) {
924 return nullptr;
925 }
926
927 // qCDebug(ATTICA) << "request remoteaccounts";
928 QUrl url = createUrl(QLatin1String("buildservice/remoteaccounts/list/"));
929 return new ListJob<RemoteAccount>(d->m_internals, createRequest(url));
930}
931
933{
934 if (!isValid()) {
935 return nullptr;
936 }
937
938 StringMap postParameters;
939 // A postjob won't be run without parameters.
940 // so even while we don't need any in this case,
941 // we add dummy data to the request
942 postParameters.insert(QLatin1String("login"), account.login());
943 postParameters.insert(QLatin1String("password"), account.password());
944 postParameters.insert(QLatin1String("type"), account.type());
945 postParameters.insert(QLatin1String("typeid"), account.remoteServiceId()); // FIXME: remoteserviceid?
946 postParameters.insert(QLatin1String("data"), account.data());
947 // qCDebug(ATTICA) << "Creating new Remoteaccount" << account.id() << account.login() << account.password();
948 return new PostJob(d->m_internals, createRequest(QLatin1String("buildservice/remoteaccounts/add")), postParameters);
949}
950
952{
953 if (!isValid()) {
954 return nullptr;
955 }
956
957 StringMap postParameters;
958 // A postjob won't be run without parameters.
959 // so even while we don't need any in this case,
960 // we add dummy data to the request
961 postParameters.insert(QLatin1String("login"), account.login());
962 postParameters.insert(QLatin1String("password"), account.password());
963 postParameters.insert(QLatin1String("type"), account.type());
964 postParameters.insert(QLatin1String("typeid"), account.remoteServiceId()); // FIXME: remoteserviceid?
965 postParameters.insert(QLatin1String("data"), account.data());
966 // qCDebug(ATTICA) << "Creating new Remoteaccount" << account.id() << account.login() << account.password();
967 return new PostJob(d->m_internals, createRequest(QLatin1String("buildservice/remoteaccounts/edit/") + account.id()), postParameters);
968}
969
971{
972 if (!isValid()) {
973 return nullptr;
974 }
975
976 QUrl url = createUrl(QLatin1String("buildservice/remoteaccounts/get/") + id);
977 // qCDebug(ATTICA) << url;
978 return new ItemJob<RemoteAccount>(d->m_internals, createRequest(url));
979}
980
982{
983 if (!isValid()) {
984 return nullptr;
985 }
986
987 StringMap postParameters;
988 return new PostJob(d->m_internals, createRequest(QLatin1String("buildservice/remoteaccounts/remove/") + id), postParameters);
989}
990
991PostJob *Provider::uploadTarballToBuildService(const QString &projectId, const QString &fileName, const QByteArray &payload)
992{
993 if (!isValid()) {
994 return nullptr;
995 }
996
997 QUrl url = createUrl(QLatin1String("buildservice/project/uploadsource/") + projectId);
998 // qCDebug(ATTICA) << "Up'ing tarball" << url << projectId << fileName << payload;
999 PostFileData postRequest(url);
1000 postRequest.addFile(fileName, payload, QLatin1String("application/octet-stream"), QLatin1String("source"));
1001 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1002}
1003
1004// Activity
1005
1006PostJob *Provider::postActivity(const QString &message)
1007{
1008 if (!isValid()) {
1009 return nullptr;
1010 }
1011
1012 StringMap postParameters;
1013 postParameters.insert(QLatin1String("message"), message);
1014 return new PostJob(d->m_internals, createRequest(QLatin1String("activity")), postParameters);
1015}
1016
1017PostJob *Provider::inviteFriend(const QString &to, const QString &message)
1018{
1019 if (!isValid()) {
1020 return nullptr;
1021 }
1022
1023 StringMap postParameters;
1024 postParameters.insert(QLatin1String("message"), message);
1025 return new PostJob(d->m_internals, createRequest(QLatin1String("friend/invite/") + to), postParameters);
1026}
1027
1028PostJob *Provider::approveFriendship(const QString &to)
1029{
1030 if (!isValid()) {
1031 return nullptr;
1032 }
1033
1034 return new PostJob(d->m_internals, createRequest(QLatin1String("friend/approve/") + to));
1035}
1036
1037PostJob *Provider::declineFriendship(const QString &to)
1038{
1039 if (!isValid()) {
1040 return nullptr;
1041 }
1042
1043 return new PostJob(d->m_internals, createRequest(QLatin1String("friend/decline/") + to));
1044}
1045
1046PostJob *Provider::cancelFriendship(const QString &to)
1047{
1048 if (!isValid()) {
1049 return nullptr;
1050 }
1051
1052 return new PostJob(d->m_internals, createRequest(QLatin1String("friend/cancel/") + to));
1053}
1054
1055PostJob *Provider::postLocation(qreal latitude, qreal longitude, const QString &city, const QString &country)
1056{
1057 if (!isValid()) {
1058 return nullptr;
1059 }
1060
1061 StringMap postParameters;
1062 postParameters.insert(QLatin1String("latitude"), QString::number(latitude));
1063 postParameters.insert(QLatin1String("longitude"), QString::number(longitude));
1064 postParameters.insert(QLatin1String("city"), city);
1065 postParameters.insert(QLatin1String("country"), country);
1066 return new PostJob(d->m_internals, createRequest(QLatin1String("person/self")), postParameters);
1067}
1068
1069ListJob<Folder> *Provider::requestFolders()
1070{
1071 if (!isValid()) {
1072 return nullptr;
1073 }
1074
1075 return doRequestFolderList(createUrl(QLatin1String("message")));
1076}
1077
1078ListJob<Message> *Provider::requestMessages(const Folder &folder)
1079{
1080 if (!isValid()) {
1081 return nullptr;
1082 }
1083
1084 return doRequestMessageList(createUrl(QLatin1String("message/") + folder.id()));
1085}
1086
1087ListJob<Message> *Provider::requestMessages(const Folder &folder, Message::Status status)
1088{
1089 if (!isValid()) {
1090 return nullptr;
1091 }
1092
1093 QUrl url = createUrl(QLatin1String("message/") + folder.id());
1094 QUrlQuery q(url);
1095 q.addQueryItem(QStringLiteral("status"), QString::number(status));
1096 url.setQuery(q);
1097 return doRequestMessageList(url);
1098}
1099
1100ItemJob<Message> *Provider::requestMessage(const Folder &folder, const QString &id)
1101{
1102 if (!isValid()) {
1103 return nullptr;
1104 }
1105
1106 return new ItemJob<Message>(d->m_internals, createRequest(QLatin1String("message/") + folder.id() + QLatin1Char('/') + id));
1107}
1108
1109PostJob *Provider::postMessage(const Message &message)
1110{
1111 if (!isValid()) {
1112 return nullptr;
1113 }
1114
1115 StringMap postParameters;
1116 postParameters.insert(QLatin1String("message"), message.body());
1117 postParameters.insert(QLatin1String("subject"), message.subject());
1118 postParameters.insert(QLatin1String("to"), message.to());
1119 return new PostJob(d->m_internals, createRequest(QLatin1String("message/2")), postParameters);
1120}
1121
1123{
1124 if (!isValid()) {
1125 return nullptr;
1126 }
1127
1128 const QUrl url = createUrl(QLatin1String("content/categories"));
1129
1130 // Thread-local cache of categories requests. They are fairly slow and block startup
1132 ListJob<Category> *job = reqs.localData().value(url);
1133 if (!job) {
1134 job = new ListJob<Category>(d->m_internals, createRequest(url));
1135 QObject::connect(job, &BaseJob::finished, [url] {
1136 reqs.localData().remove(url);
1137 });
1138 reqs.localData().insert(url, job);
1139 }
1140 return job;
1141}
1142
1144{
1145 if (!isValid()) {
1146 return nullptr;
1147 }
1148
1149 QUrl url = createUrl(QLatin1String("content/licenses"));
1150 ListJob<License> *job = new ListJob<License>(d->m_internals, createRequest(url));
1151 return job;
1152}
1153
1155{
1156 if (!isValid()) {
1157 return nullptr;
1158 }
1159
1160 QUrl url = createUrl(QLatin1String("content/distributions"));
1161 ListJob<Distribution> *job = new ListJob<Distribution>(d->m_internals, createRequest(url));
1162 return job;
1163}
1164
1166{
1167 if (!isValid()) {
1168 return nullptr;
1169 }
1170
1171 QUrl url = createUrl(QLatin1String("content/homepages"));
1172 ListJob<HomePageType> *job = new ListJob<HomePageType>(d->m_internals, createRequest(url));
1173 return job;
1174}
1175
1176ListJob<Content> *Provider::searchContents(const Category::List &categories, const QString &search, SortMode sortMode, uint page, uint pageSize)
1177{
1178 return searchContents(categories, QString(), Distribution::List(), License::List(), search, sortMode, page, pageSize);
1179}
1180
1182Provider::searchContentsByPerson(const Category::List &categories, const QString &person, const QString &search, SortMode sortMode, uint page, uint pageSize)
1183{
1184 return searchContents(categories, person, Distribution::List(), License::List(), search, sortMode, page, pageSize);
1185}
1186
1188 const QString &person,
1189 const Distribution::List &distributions,
1190 const License::List &licenses,
1191 const QString &search,
1192 SortMode sortMode,
1193 uint page,
1194 uint pageSize)
1195{
1196 if (!isValid()) {
1197 return nullptr;
1198 }
1199
1200 QUrl url = createUrl(QStringLiteral("content/data"));
1201 QUrlQuery q(url);
1202 QStringList categoryIds;
1203 categoryIds.reserve(categories.count());
1204 for (const Category &category : categories) {
1205 categoryIds.append(category.id());
1206 }
1207 q.addQueryItem(QStringLiteral("categories"), categoryIds.join(QLatin1Char('x')));
1208
1209 QStringList distributionIds;
1210 for (const Distribution &distribution : distributions) {
1211 distributionIds.append(QString::number(distribution.id()));
1212 }
1213 q.addQueryItem(QStringLiteral("distribution"), distributionIds.join(QLatin1Char(',')));
1214
1215 QStringList licenseIds;
1216 for (const License &license : licenses) {
1217 licenseIds.append(QString::number(license.id()));
1218 }
1219 q.addQueryItem(QStringLiteral("license"), licenseIds.join(QLatin1Char(',')));
1220
1221 if (!person.isEmpty()) {
1222 q.addQueryItem(QStringLiteral("user"), person);
1223 }
1224
1225 q.addQueryItem(QStringLiteral("search"), search);
1226 QString sortModeString;
1227 switch (sortMode) {
1228 case Newest:
1229 sortModeString = QLatin1String("new");
1230 break;
1231 case Alphabetical:
1232 sortModeString = QLatin1String("alpha");
1233 break;
1234 case Rating:
1235 sortModeString = QLatin1String("high");
1236 break;
1237 case Downloads:
1238 sortModeString = QLatin1String("down");
1239 break;
1240 }
1241
1242 if (!sortModeString.isEmpty()) {
1243 q.addQueryItem(QStringLiteral("sortmode"), sortModeString);
1244 }
1245
1246 q.addQueryItem(QStringLiteral("page"), QString::number(page));
1247 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
1248
1249 url.setQuery(q);
1250 ListJob<Content> *job = new ListJob<Content>(d->m_internals, createRequest(url));
1251 return job;
1252}
1253
1255{
1256 if (!isValid()) {
1257 return nullptr;
1258 }
1259
1260 QUrl url = createUrl(QLatin1String("content/data/") + id);
1261 ItemJob<Content> *job = new ItemJob<Content>(d->m_internals, createRequest(url));
1262 return job;
1263}
1264
1265ItemPostJob<Content> *Provider::addNewContent(const Category &category, const Content &cont)
1266{
1267 if (!isValid() || !category.isValid()) {
1268 return nullptr;
1269 }
1270
1271 QUrl url = createUrl(QLatin1String("content/add"));
1272 StringMap pars(cont.attributes());
1273
1274 pars.insert(QLatin1String("type"), category.id());
1275 pars.insert(QLatin1String("name"), cont.name());
1276
1277 // qCDebug(ATTICA) << "Parameter map: " << pars;
1278
1279 return new ItemPostJob<Content>(d->m_internals, createRequest(url), pars);
1280}
1281
1282ItemPostJob<Content> *Provider::editContent(const Category &updatedCategory, const QString &contentId, const Content &updatedContent)
1283{
1284 if (!isValid()) {
1285 return nullptr;
1286 }
1287
1288 // FIXME I get a server error message here, though the name of the item is changed
1289 QUrl url = createUrl(QLatin1String("content/edit/") + contentId);
1290 StringMap pars(updatedContent.attributes());
1291
1292 pars.insert(QLatin1String("type"), updatedCategory.id());
1293 pars.insert(QLatin1String("name"), updatedContent.name());
1294
1295 // qCDebug(ATTICA) << "Parameter map: " << pars;
1296
1297 return new ItemPostJob<Content>(d->m_internals, createRequest(url), pars);
1298}
1299
1300/*
1301PostJob* Provider::setDownloadFile(const QString& contentId, QIODevice* payload)
1302{
1303 QUrl url = createUrl("content/uploaddownload/" + contentId);
1304 PostFileData postRequest(url);
1305 // FIXME mime type
1306 //postRequest.addFile("localfile", payload, "application/octet-stream");
1307 postRequest.addFile("localfile", payload, "image/jpeg");
1308 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1309}
1310*/
1311
1312PostJob *Provider::deleteContent(const QString &contentId)
1313{
1314 if (!isValid()) {
1315 return nullptr;
1316 }
1317
1318 QUrl url = createUrl(QLatin1String("content/delete/") + contentId);
1319 PostFileData postRequest(url);
1320 postRequest.addArgument(QLatin1String("contentid"), contentId);
1321 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1322}
1323
1324PostJob *Provider::setDownloadFile(const QString &contentId, const QString &fileName, const QByteArray &payload)
1325{
1326 if (!isValid()) {
1327 return nullptr;
1328 }
1329
1330 QUrl url = createUrl(QLatin1String("content/uploaddownload/") + contentId);
1331 PostFileData postRequest(url);
1332 postRequest.addArgument(QLatin1String("contentid"), contentId);
1333 // FIXME mime type
1334 postRequest.addFile(fileName, payload, QLatin1String("application/octet-stream"));
1335 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1336}
1337
1338PostJob *Provider::deleteDownloadFile(const QString &contentId)
1339{
1340 if (!isValid()) {
1341 return nullptr;
1342 }
1343
1344 QUrl url = createUrl(QLatin1String("content/deletedownload/") + contentId);
1345 PostFileData postRequest(url);
1346 postRequest.addArgument(QLatin1String("contentid"), contentId);
1347 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1348}
1349
1350PostJob *Provider::setPreviewImage(const QString &contentId, const QString &previewId, const QString &fileName, const QByteArray &image)
1351{
1352 if (!isValid()) {
1353 return nullptr;
1354 }
1355
1356 QUrl url = createUrl(QLatin1String("content/uploadpreview/") + contentId + QLatin1Char('/') + previewId);
1357
1358 PostFileData postRequest(url);
1359 postRequest.addArgument(QLatin1String("contentid"), contentId);
1360 postRequest.addArgument(QLatin1String("previewid"), previewId);
1361 // FIXME mime type
1362 postRequest.addFile(fileName, image, QLatin1String("application/octet-stream"));
1363
1364 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1365}
1366
1367PostJob *Provider::deletePreviewImage(const QString &contentId, const QString &previewId)
1368{
1369 if (!isValid()) {
1370 return nullptr;
1371 }
1372
1373 QUrl url = createUrl(QLatin1String("content/deletepreview/") + contentId + QLatin1Char('/') + previewId);
1374 PostFileData postRequest(url);
1375 postRequest.addArgument(QLatin1String("contentid"), contentId);
1376 postRequest.addArgument(QLatin1String("previewid"), previewId);
1377 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1378}
1379
1380PostJob *Provider::voteForContent(const QString &contentId, uint rating)
1381{
1382 if (!isValid()) {
1383 return nullptr;
1384 }
1385
1386 // according to OCS API, the rating is 0..100
1387 if (rating > 100) {
1388 qWarning() << "Rating cannot be superior to 100, fallback to 100.";
1389 rating = 100;
1390 }
1391
1392 StringMap postParameters;
1393 postParameters.insert(QLatin1String("vote"), QString::number(rating));
1394 // qCDebug(ATTICA) << "vote: " << QString::number(rating);
1395 return new PostJob(d->m_internals, createRequest(QLatin1String("content/vote/") + contentId), postParameters);
1396}
1397
1398PostJob *Provider::becomeFan(const QString &contentId)
1399{
1400 if (!isValid()) {
1401 return nullptr;
1402 }
1403
1404 QUrl url = createUrl(QLatin1String("fan/add/") + contentId);
1405 PostFileData postRequest(url);
1406 postRequest.addArgument(QLatin1String("contentid"), contentId);
1407 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1408}
1409
1410ListJob<Person> *Provider::requestFans(const QString &contentId, uint page, uint pageSize)
1411{
1412 if (!isValid()) {
1413 return nullptr;
1414 }
1415
1416 QUrl url = createUrl(QLatin1String("fan/data/") + contentId);
1417 QUrlQuery q(url);
1418 q.addQueryItem(QStringLiteral("contentid"), contentId);
1419 q.addQueryItem(QStringLiteral("page"), QString::number(page));
1420 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
1421 url.setQuery(q);
1422 ListJob<Person> *job = new ListJob<Person>(d->m_internals, createRequest(url));
1423 return job;
1424}
1425
1426ListJob<Forum> *Provider::requestForums(uint page, uint pageSize)
1427{
1428 if (!isValid()) {
1429 return nullptr;
1430 }
1431
1432 QUrl url = createUrl(QStringLiteral("forum/list"));
1433 QUrlQuery q(url);
1434 q.addQueryItem(QStringLiteral("page"), QString::number(page));
1435 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
1436 url.setQuery(q);
1437
1438 return doRequestForumList(url);
1439}
1440
1442Provider::requestTopics(const QString &forum, const QString &search, const QString &description, Provider::SortMode mode, int page, int pageSize)
1443{
1444 if (!isValid()) {
1445 return nullptr;
1446 }
1447
1448 QUrl url = createUrl(QStringLiteral("forum/topics/list"));
1449 QUrlQuery q(url);
1450 q.addQueryItem(QStringLiteral("forum"), forum);
1451 q.addQueryItem(QStringLiteral("search"), search);
1452 q.addQueryItem(QStringLiteral("description"), description);
1453 QString sortModeString;
1454 switch (mode) {
1455 case Newest:
1456 sortModeString = QLatin1String("new");
1457 break;
1458 case Alphabetical:
1459 sortModeString = QLatin1String("alpha");
1460 break;
1461 default:
1462 break;
1463 }
1464 if (!sortModeString.isEmpty()) {
1465 q.addQueryItem(QStringLiteral("sortmode"), sortModeString);
1466 }
1467 q.addQueryItem(QStringLiteral("page"), QString::number(page));
1468 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
1469 url.setQuery(q);
1470
1471 return doRequestTopicList(url);
1472}
1473
1474PostJob *Provider::postTopic(const QString &forumId, const QString &subject, const QString &content)
1475{
1476 if (!isValid()) {
1477 return nullptr;
1478 }
1479
1480 StringMap postParameters;
1481 postParameters.insert(QLatin1String("subject"), subject);
1482 postParameters.insert(QLatin1String("content"), content);
1483 postParameters.insert(QLatin1String("forum"), forumId);
1484 return new PostJob(d->m_internals, createRequest(QLatin1String("forum/topic/add")), postParameters);
1485}
1486
1487ItemJob<DownloadItem> *Provider::downloadLink(const QString &contentId, const QString &itemId)
1488{
1489 if (!isValid()) {
1490 return nullptr;
1491 }
1492
1493 QUrl url = createUrl(QLatin1String("content/download/") + contentId + QLatin1Char('/') + itemId);
1494 ItemJob<DownloadItem> *job = new ItemJob<DownloadItem>(d->m_internals, createRequest(url));
1495 return job;
1496}
1497
1498ItemJob<KnowledgeBaseEntry> *Provider::requestKnowledgeBaseEntry(const QString &id)
1499{
1500 if (!isValid()) {
1501 return nullptr;
1502 }
1503
1504 QUrl url = createUrl(QLatin1String("knowledgebase/data/") + id);
1505 ItemJob<KnowledgeBaseEntry> *job = new ItemJob<KnowledgeBaseEntry>(d->m_internals, createRequest(url));
1506 return job;
1507}
1508
1509ListJob<KnowledgeBaseEntry> *Provider::searchKnowledgeBase(const Content &content, const QString &search, Provider::SortMode sortMode, int page, int pageSize)
1510{
1511 if (!isValid()) {
1512 return nullptr;
1513 }
1514
1515 QUrl url = createUrl(QStringLiteral("knowledgebase/data"));
1516 QUrlQuery q(url);
1517 if (content.isValid()) {
1518 q.addQueryItem(QStringLiteral("content"), content.id());
1519 }
1520
1521 q.addQueryItem(QStringLiteral("search"), search);
1522 QString sortModeString;
1523 switch (sortMode) {
1524 case Newest:
1525 sortModeString = QLatin1String("new");
1526 break;
1527 case Alphabetical:
1528 sortModeString = QLatin1String("alpha");
1529 break;
1530 case Rating:
1531 sortModeString = QLatin1String("high");
1532 break;
1533 // FIXME: knowledge base doesn't have downloads
1534 case Downloads:
1535 sortModeString = QLatin1String("new");
1536 break;
1537 }
1538 if (!sortModeString.isEmpty()) {
1539 q.addQueryItem(QStringLiteral("sortmode"), sortModeString);
1540 }
1541
1542 q.addQueryItem(QStringLiteral("page"), QString::number(page));
1543 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
1544 url.setQuery(q);
1545
1546 ListJob<KnowledgeBaseEntry> *job = new ListJob<KnowledgeBaseEntry>(d->m_internals, createRequest(url));
1547 return job;
1548}
1549
1550ItemJob<Event> *Provider::requestEvent(const QString &id)
1551{
1552 if (!isValid()) {
1553 return nullptr;
1554 }
1555
1556 ItemJob<Event> *job = new ItemJob<Event>(d->m_internals, createRequest(QLatin1String("event/data/") + id));
1557 return job;
1558}
1559
1560ListJob<Event> *Provider::requestEvent(const QString &country, const QString &search, const QDate &startAt, Provider::SortMode mode, int page, int pageSize)
1561{
1562 if (!isValid()) {
1563 return nullptr;
1564 }
1565
1566 QUrl url = createUrl(QStringLiteral("event/data"));
1567 QUrlQuery q(url);
1568
1569 if (!search.isEmpty()) {
1570 q.addQueryItem(QStringLiteral("search"), search);
1571 }
1572
1573 QString sortModeString;
1574 switch (mode) {
1575 case Newest:
1576 sortModeString = QLatin1String("new");
1577 break;
1578 case Alphabetical:
1579 sortModeString = QLatin1String("alpha");
1580 break;
1581 default:
1582 break;
1583 }
1584 if (!sortModeString.isEmpty()) {
1585 q.addQueryItem(QStringLiteral("sortmode"), sortModeString);
1586 }
1587
1588 if (!country.isEmpty()) {
1589 q.addQueryItem(QStringLiteral("country"), country);
1590 }
1591
1592 q.addQueryItem(QStringLiteral("startat"), startAt.toString(Qt::ISODate));
1593
1594 q.addQueryItem(QStringLiteral("page"), QString::number(page));
1595 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
1596 url.setQuery(q);
1597
1598 ListJob<Event> *job = new ListJob<Event>(d->m_internals, createRequest(url));
1599 return job;
1600}
1601
1602ListJob<Comment> *Provider::requestComments(const Comment::Type commentType, const QString &id, const QString &id2, int page, int pageSize)
1603{
1604 if (!isValid()) {
1605 return nullptr;
1606 }
1607
1608 QString commentTypeString;
1609 commentTypeString = Comment::commentTypeToString(commentType);
1610 if (commentTypeString.isEmpty()) {
1611 return nullptr;
1612 }
1613
1614 QUrl url = createUrl(QLatin1String("comments/data/") + commentTypeString + QLatin1Char('/') + id + QLatin1Char('/') + id2);
1615
1616 QUrlQuery q(url);
1617 q.addQueryItem(QStringLiteral("page"), QString::number(page));
1618 q.addQueryItem(QStringLiteral("pagesize"), QString::number(pageSize));
1619 url.setQuery(q);
1620
1621 ListJob<Comment> *job = new ListJob<Comment>(d->m_internals, createRequest(url));
1622 return job;
1623}
1624
1625ItemPostJob<Comment> *Provider::addNewComment(const Comment::Type commentType,
1626 const QString &id,
1627 const QString &id2,
1628 const QString &parentId,
1629 const QString &subject,
1630 const QString &message)
1631{
1632 if (!isValid()) {
1633 return nullptr;
1634 }
1635
1636 QString commentTypeString;
1637 commentTypeString = Comment::commentTypeToString(commentType);
1638 if (commentTypeString.isEmpty()) {
1639 return nullptr;
1640 }
1641
1642 QMap<QString, QString> postParameters;
1643
1644 postParameters.insert(QLatin1String("type"), commentTypeString);
1645 postParameters.insert(QLatin1String("content"), id);
1646 postParameters.insert(QLatin1String("content2"), id2);
1647 postParameters.insert(QLatin1String("parent"), parentId);
1648 postParameters.insert(QLatin1String("subject"), subject);
1649 postParameters.insert(QLatin1String("message"), message);
1650
1651 return new ItemPostJob<Comment>(d->m_internals, createRequest(QLatin1String("comments/add")), postParameters);
1652}
1653
1655{
1656 if (!isValid() || (rating > 100)) {
1657 return nullptr;
1658 }
1659
1660 QMap<QString, QString> postParameters;
1661 postParameters.insert(QLatin1String("vote"), QString::number(rating));
1662
1663 QUrl url = createUrl(QLatin1String("comments/vote/") + id);
1664 return new PostJob(d->m_internals, createRequest(url), postParameters);
1665}
1666
1667PostJob *Provider::setPrivateData(const QString &app, const QString &key, const QString &value)
1668{
1669 if (!isValid()) {
1670 return nullptr;
1671 }
1672
1673 QUrl url = createUrl(QLatin1String("privatedata/setattribute/") + app + QLatin1Char('/') + key);
1674 PostFileData postRequest(url);
1675
1676 postRequest.addArgument(QLatin1String("value"), value);
1677
1678 return new PostJob(d->m_internals, postRequest.request(), postRequest.data());
1679}
1680
1682{
1683 if (!isValid()) {
1684 return nullptr;
1685 }
1686
1688 new ItemJob<PrivateData>(d->m_internals, createRequest(QLatin1String("privatedata/getattribute/") + app + QLatin1Char('/') + key));
1689 return job;
1690}
1691
1692QUrl Provider::createUrl(const QString &path)
1693{
1694 QUrl url(d->m_baseUrl.toString() + path);
1695 return url;
1696}
1697
1698QNetworkRequest Provider::createRequest(const QUrl &url)
1699{
1700 QNetworkRequest request(url);
1701 request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded"));
1702
1703 QString agentHeader;
1705 agentHeader = QString::fromLocal8Bit("%1/%2").arg(QCoreApplication::instance()->applicationName(), QCoreApplication::instance()->applicationVersion());
1706 } else {
1707 agentHeader = QString::fromLocal8Bit("Attica/%1").arg(QLatin1String(LIBATTICA_VERSION_STRING));
1708 }
1709 if (!d->m_additionalAgentInformation.isEmpty()) {
1710 agentHeader = QString::fromLocal8Bit("%1 (+%2)").arg(agentHeader, d->m_additionalAgentInformation);
1711 }
1712 request.setHeader(QNetworkRequest::UserAgentHeader, agentHeader);
1713
1714 if (!d->m_credentialsUserName.isEmpty()) {
1715 request.setAttribute((QNetworkRequest::Attribute)BaseJob::UserAttribute, QVariant(d->m_credentialsUserName));
1716 request.setAttribute((QNetworkRequest::Attribute)BaseJob::PasswordAttribute, QVariant(d->m_credentialsPassword));
1717 }
1718 return request;
1719}
1720
1721QNetworkRequest Provider::createRequest(const QString &path)
1722{
1723 return createRequest(createUrl(path));
1724}
1725
1726ItemJob<Config> *Provider::doRequestConfig(const QUrl &url)
1727{
1728 return new ItemJob<Config>(d->m_internals, createRequest(url));
1729}
1730
1731ItemJob<Person> *Provider::doRequestPerson(const QUrl &url)
1732{
1733 return new ItemJob<Person>(d->m_internals, createRequest(url));
1734}
1735
1736ItemJob<AccountBalance> *Provider::doRequestAccountBalance(const QUrl &url)
1737{
1738 return new ItemJob<AccountBalance>(d->m_internals, createRequest(url));
1739}
1740
1741ListJob<Person> *Provider::doRequestPersonList(const QUrl &url)
1742{
1743 return new ListJob<Person>(d->m_internals, createRequest(url));
1744}
1745
1746ListJob<Achievement> *Provider::doRequestAchievementList(const QUrl &url)
1747{
1748 return new ListJob<Achievement>(d->m_internals, createRequest(url));
1749}
1750
1751ListJob<Activity> *Provider::doRequestActivityList(const QUrl &url)
1752{
1753 return new ListJob<Activity>(d->m_internals, createRequest(url));
1754}
1755
1756ListJob<Folder> *Provider::doRequestFolderList(const QUrl &url)
1757{
1758 return new ListJob<Folder>(d->m_internals, createRequest(url));
1759}
1760
1761ListJob<Forum> *Provider::doRequestForumList(const QUrl &url)
1762{
1763 return new ListJob<Forum>(d->m_internals, createRequest(url));
1764}
1765
1766ListJob<Topic> *Provider::doRequestTopicList(const QUrl &url)
1767{
1768 return new ListJob<Topic>(d->m_internals, createRequest(url));
1769}
1770
1771ListJob<Message> *Provider::doRequestMessageList(const QUrl &url)
1772{
1773 return new ListJob<Message>(d->m_internals, createRequest(url));
1774}
1775
1777{
1778 return d->m_achievementVersion;
1779}
1780
1782{
1783 return d->m_activityVersion;
1784}
1786{
1787 return d->m_commentVersion;
1788}
1790{
1791 return d->m_contentVersion;
1792}
1794{
1795 return d->m_fanVersion;
1796}
1798{
1799 return d->m_forumVersion;
1800}
1802{
1803 return d->m_friendVersion;
1804}
1806{
1807 return d->m_knowledgebaseVersion;
1808}
1810{
1811 return d->m_messageVersion;
1812}
1814{
1815 return d->m_personVersion;
1816}
1817
1819{
1820 return !d->m_achievementVersion.isEmpty();
1821}
1822
1824{
1825 return !d->m_activityVersion.isEmpty();
1826}
1828{
1829 return !d->m_commentVersion.isEmpty();
1830}
1832{
1833 return !d->m_contentVersion.isEmpty();
1834}
1836{
1837 return !d->m_fanVersion.isEmpty();
1838}
1840{
1841 return !d->m_forumVersion.isEmpty();
1842}
1844{
1845 return !d->m_friendVersion.isEmpty();
1846}
1848{
1849 return !d->m_knowledgebaseVersion.isEmpty();
1850}
1852{
1853 return !d->m_messageVersion.isEmpty();
1854}
1856{
1857 return !d->m_personVersion.isEmpty();
1858}
Represents an achievement.
Definition achievement.h:28
Represents a build service job.
Represents a single content category.
Definition category.h:24
QString id() const
Gets the id of the Category.
Definition category.cpp:49
Represents a single content.
Definition content.h:33
bool isValid() const
Checks whether this Content has an id.
Definition content.cpp:145
QMap< QString, QString > attributes() const
Get all attributes that are not included in the basis set of attributes exposed by the Content class.
Definition content.cpp:140
QString name() const
Gets the name of the Content.
Definition content.cpp:75
QString id() const
Gets the id of the Content.
Definition content.cpp:65
Represents a delete job.
Definition deletejob.h:26
The Distribution class contains information about one distribution that the server offers.
Represents a single mail folder.
Definition folder.h:25
QString id() const
Gets the id of the Folder.
Definition folder.cpp:52
Represents an item delete job.
Definition itemjob.h:48
Represents an item get job.
Definition itemjob.h:30
Represents an item post job.
Definition itemjob.h:66
Represents an item put job.
Definition itemjob.h:86
The License class contains information about one license that the server offers.
Definition license.h:24
Represents a list job.
Definition listjob.h:28
Represents a message.
Definition message.h:27
Represents a post job.
Definition postjob.h:30
Represents a project.
Definition project.h:30
The Provider class represents one Open Collaboration Service provider.
Definition provider.h:97
bool hasActivityService() const
Test if the server supports the activity part of the API.
ListJob< Distribution > * requestDistributions()
Get a list of distributions (such as Ark, Debian)
QString name() const
A name for the provider that can be displayed to the user.
Definition provider.cpp:340
PostJob * publishBuildJob(const BuildServiceJob &buildjob, const Publisher &publisher)
Publish the result of a completed build job to a publisher.
Definition provider.cpp:801
QString messageServiceVersion() const
Version of the message part of the API.
QString contentServiceVersion() const
Version of the content part of the API.
QString personServiceVersion() const
Version of the person part of the API.
ListJob< Achievement > * requestAchievements(const QString &contentId, const QString &achievementId, const QString &userId)
Get a list of achievements.
Definition provider.cpp:547
PostJob * deleteRemoteAccount(const QString &id)
Deletes a remote account stored on the OCS server.
Definition provider.cpp:981
bool hasCredentials() const
Test if the provider has user name/password available.
Definition provider.cpp:359
ListJob< Category > * requestCategories()
Get a list of categories (such as wallpaper)
QUrl baseUrl() const
A url that identifies this provider.
Definition provider.cpp:302
ItemJob< Config > * requestConfig()
Fetches server config.
Definition provider.cpp:407
QString additionalAgentInformation() const
The custom identifier sent along with requests.
Definition provider.cpp:335
ListJob< Content > * searchContentsByPerson(const Category::List &categories, const QString &person, const QString &search=QString(), SortMode mode=Rating, uint page=0, uint pageSize=10)
Request a list of Contents.
PostJob * setPreviewImage(const QString &contentId, const QString &previewId, const QString &fileName, const QByteArray &image)
Upload an image file as preview for the content.
Provider()
Default construct a Provider.
Definition provider.cpp:174
ItemJob< BuildServiceJob > * requestBuildServiceJob(const QString &id)
Get the information for a specific build service job, such as status and progress.
Definition provider.cpp:827
PostJob * savePublisherField(const Project &project, const PublisherField &field)
Save the value of a single publishing field.
Definition provider.cpp:785
PostJob * voteForComment(const QString &id, uint rating)
Vote a comment item.
PutJob * editAchievement(const QString &contentId, const QString &achievementId, const Achievement &achievement)
Post modifications to an Achievement on the server.
Definition provider.cpp:592
PostJob * deleteProject(const Project &project)
Deletes a project on the server.
Definition provider.cpp:755
bool hasForumService() const
Test if the server supports the forum part of the API.
bool hasMessageService() const
Test if the server supports the message part of the API.
ListJob< RemoteAccount > * requestRemoteAccounts()
Get a list of remote accounts, account for a build service instance which is stored in the OCS servic...
Definition provider.cpp:921
bool saveCredentials(const QString &user, const QString &password)
Sets (and remembers) user name and password for this provider.
Definition provider.cpp:382
bool hasFriendService() const
Test if the server supports the friend part of the API.
ItemPostJob< Achievement > * addNewAchievement(const QString &id, const Achievement &newAchievement)
Add a new achievement.
Definition provider.cpp:560
PostJob * createProject(const Project &project)
Post modifications to a Project on the server.
Definition provider.cpp:737
PostJob * cancelBuildServiceJob(const BuildServiceJob &job)
Cancel a job.
Definition provider.cpp:858
ListJob< BuildService > * requestBuildServices()
Get a list of build service build services.
Definition provider.cpp:888
bool hasAchievementService() const
Test if the server supports the achievement part of the API.
PostJob * editRemoteAccount(const RemoteAccount &account)
Edit an existing remote account.
Definition provider.cpp:951
ItemJob< Project > * requestProject(const QString &id)
Get a Project's data.
Definition provider.cpp:690
bool loadCredentials(QString &user, QString &password)
Load user name and password from the store.
Definition provider.cpp:368
ItemJob< RemoteAccount > * requestRemoteAccount(const QString &id)
Get a remote account by its ID.
Definition provider.cpp:970
ListJob< Publisher > * requestPublishers()
Get a list of publishers.
Definition provider.cpp:899
ItemPostJob< Comment > * addNewComment(const Comment::Type commentType, const QString &id, const QString &id2, const QString &parentId, const QString &subject, const QString &message)
Add a new comment.
ItemJob< BuildService > * requestBuildService(const QString &id)
Get the information for a specific build service instance.
Definition provider.cpp:764
QString fanServiceVersion() const
Version of the fan part of the API.
QString achievementServiceVersion() const
Version of the achievement part of the API.
ListJob< License > * requestLicenses()
Get a list of licenses (such as GPL)
bool isEnabled() const
Test if the provider is enabled by the settings.
Definition provider.cpp:312
ListJob< HomePageType > * requestHomePageTypes()
Get a list of home page types (such as blog, Facebook)
DeleteJob * deleteAchievement(const QString &contentId, const QString &achievementId)
Deletes an achievement on the server.
Definition provider.cpp:628
ItemJob< Publisher > * requestPublisher(const QString &id)
Get the information for a specific publisher.
Definition provider.cpp:774
QString knowledgebaseServiceVersion() const
Version of the knowledgebase part of the API.
bool hasCommentService() const
Test if the server supports the comments part of the API.
ItemJob< Content > * requestContent(const QString &contentId)
Retrieve a single content.
ListJob< Content > * searchContents(const Category::List &categories, const QString &search=QString(), SortMode mode=Rating, uint page=0, uint pageSize=10)
Request a list of Contents.
PostJob * createRemoteAccount(const RemoteAccount &account)
Create a new remote account, an account for a build service instance which is stored in the OCS servi...
Definition provider.cpp:932
QString forumServiceVersion() const
Version of the forum part of the API.
PostJob * checkLogin(const QString &user, const QString &password)
Test if the server accepts the login/password.
Definition provider.cpp:393
void setAdditionalAgentInformation(const QString &additionalInformation)
Set a custom identifier for your application (sent along with the requests as the http agent header i...
Definition provider.cpp:330
bool hasContentService() const
Test if the server supports the content part of the API.
ListJob< Project > * requestProjects()
Get a list of build service projects.
Definition provider.cpp:679
bool isValid() const
Returns true if the provider has been set up and can be used.
Definition provider.cpp:307
bool hasPersonService() const
Test if the server supports the person part of the API.
PostJob * createBuildServiceJob(const BuildServiceJob &job)
Create a new job for a given project on a given buildservice for a given target.
Definition provider.cpp:870
ListJob< Comment > * requestComments(const Comment::Type commentType, const QString &id, const QString &id2, int page, int pageSize)
Request a list of comments for a content / forum / knowledgebase / event.
Attica::PostJob * uploadTarballToBuildService(const QString &projectId, const QString &fileName, const QByteArray &payload)
Upload a tarball to the buildservice.
Definition provider.cpp:991
ItemJob< PrivateData > * requestPrivateData()
Fetches all stored private data.
Definition provider.h:329
PostJob * editProject(const Project &project)
Post modifications to a Project on the server.
Definition provider.cpp:746
QString friendServiceVersion() const
Version of the friend part of the API.
ItemJob< BuildServiceJobOutput > * requestBuildServiceJobOutput(const QString &id)
Get the build output for a specific build service job.
Definition provider.cpp:816
PostJob * setPrivateData(const QString &app, const QString &key, const QString &value)
Sets the value of an attribute.
QString commentServiceVersion() const
Version of the comments part of the API.
bool hasKnowledgebaseService() const
Test if the server supports the knowledgebase part of the API.
PostJob * voteForContent(const QString &contentId, uint rating)
Vote for a content item.
ListJob< BuildServiceJob > * requestBuildServiceJobs(const Project &project)
Get a list of build service projects.
Definition provider.cpp:910
bool hasFanService() const
Test if the server supports the fan part of the API.
QString activityServiceVersion() const
Version of the activity part of the API.
QUrl icon() const
An icon used to visually identify this provider.
Definition provider.cpp:345
Represents a publisher field.
Represents a publisher.
Definition publisher.h:44
Represents a put job.
Definition putjob.h:30
Represents a remote account.
Q_SCRIPTABLE CaptureState status()
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
The Attica namespace,.
QString name(StandardAction id)
KI18NLOCALEDATA_EXPORT KCountry country(const char *ianaId)
QCoreApplication * instance()
QString toString(QStringView format, QCalendar cal) const const
QString toString(QStringView format, QCalendar cal) const const
void append(QList< T > &&value)
qsizetype count() const const
bool isEmpty() const const
void reserve(qsizetype size)
iterator insert(const Key &key, const T &value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
QString fromLocal8Bit(QByteArrayView str)
bool isEmpty() const const
bool isNull() const const
QString number(double n, char format, int precision)
QString join(QChar separator) const const
bool isEmpty() const const
void setQuery(const QString &query, ParsingMode mode)
QString toLocalFile() const const
void addQueryItem(const QString &key, const QString &value)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:36 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.