KPublicTransport

reply.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "reply.h"
8#include "reply_p.h"
9#include "assetrepository_p.h"
10#include "datatypes/attributionutil_p.h"
11
12#include <QDebug>
13#include <QUrl>
14
15using namespace KPublicTransport;
16
17void ReplyPrivate::emitFinishedIfDone(Reply *q)
18{
19 if (pendingOps == 0 && (!needToWaitForAssets() || AssetRepository::instance()->isQueueEmpty())) {
20 finalizeResult();
21 // delayed, as this is trigged from the backend settings results on us, which can be a multi-step process
23 }
24}
25
26void ReplyPrivate::emitUpdated(Reply *q)
27{
28 shouldClearError = true;
29 // delayed, as this is trigged from immediate cache lookup in Manager, when signals are not yet connected
31}
32
33bool ReplyPrivate::needToWaitForAssets() const
34{
35 return false;
36}
37
38Reply::Reply(ReplyPrivate *dd, QObject *parent)
39 : QObject(parent)
40 , d_ptr(dd)
41{
42}
43
44Reply::~Reply() = default;
45
47{
48 if (d_ptr->shouldClearError) {
49 return Reply::NoError;
50 }
51 return d_ptr->error;
52}
53
55{
56 if (d_ptr->shouldClearError) {
57 return {};
58 }
59 return d_ptr->errorMsg;
60}
61
62void Reply::addError(Reply::Error error, const QString &errorMsg)
63{
64 d_ptr->error = error;
65 d_ptr->errorMsg = errorMsg;
66 d_ptr->pendingOps--;
67 d_ptr->emitFinishedIfDone(this);
68}
69
70void Reply::setPendingOps(int ops)
71{
72 Q_ASSERT(d_ptr->pendingOps <= -1);
73 Q_ASSERT(ops >= 0);
74 d_ptr->pendingOps = ops;
75 if (ops == 0) {
77 }
78
79 if (d_ptr->needToWaitForAssets()) {
80 connect(AssetRepository::instance(), &AssetRepository::downloadFinished, this, [this]() { d_ptr->emitFinishedIfDone(this); });
81 }
82}
83
84const std::vector<Attribution>& Reply::attributions() const
85{
86 return d_ptr->attributions;
87}
88
89std::vector<Attribution>&& Reply::takeAttributions()
90{
91 return std::move(d_ptr->attributions);
92}
93
94void Reply::addAttributions(std::vector<Attribution>&& attributions)
95{
96 AttributionUtil::merge(d_ptr->attributions, std::move(attributions));
97}
98
99void Reply::addAttribution(const Attribution &attr)
100{
101 AttributionUtil::merge(d_ptr->attributions, attr);
102}
103
104void Reply::addAttributions(const std::vector<Attribution> &attributions)
105{
106 AttributionUtil::merge(d_ptr->attributions, attributions);
107}
Copyright and license information about the provided data.
Definition attribution.h:29
Query response base class.
Definition reply.h:25
void finished()
Emitted whenever the corresponding search has been completed.
void updated()
Emitted whenever new results are available, even before the search has been completed.
const std::vector< Attribution > & attributions() const
Returns the attributions for the provided data.
Definition reply.cpp:84
QString errorString() const
Textual error message.
Definition reply.cpp:54
std::vector< Attribution > && takeAttributions()
Returns the attributions for the provided data for moving them elsewhere.
Definition reply.cpp:89
Error error() const
Error code.
Definition reply.cpp:46
Error
Error types.
Definition reply.h:31
@ NoError
Nothing went wrong.
Definition reply.h:32
Query operations and data types for accessing realtime public transport information from online servi...
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QueuedConnection
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:57:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.