KPublicTransport

reply.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 Volker Krause <[email protected]>
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 
15 using namespace KPublicTransport;
16 
17 void 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 
26 void 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 
33 bool ReplyPrivate::needToWaitForAssets() const
34 {
35  return false;
36 }
37 
38 Reply::Reply(ReplyPrivate *dd, QObject *parent)
39  : QObject(parent)
40  , d_ptr(dd)
41 {
42 }
43 
44 Reply::~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 
62 void 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 
70 void 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 
84 const std::vector<Attribution>& Reply::attributions() const
85 {
86  return d_ptr->attributions;
87 }
88 
89 std::vector<Attribution>&& Reply::takeAttributions()
90 {
91  return std::move(d_ptr->attributions);
92 }
93 
94 void Reply::addAttributions(std::vector<Attribution>&& attributions)
95 {
96  AttributionUtil::merge(d_ptr->attributions, std::move(attributions));
97 }
98 
99 void Reply::addAttribution(const Attribution &attr)
100 {
101  AttributionUtil::merge(d_ptr->attributions, attr);
102 }
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
const std::vector< Attribution > & attributions() const
Returns the attributions for the provided data.
Definition: reply.cpp:84
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.
Error error() const
Error code.
Definition: reply.cpp:46
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
Error
Error types.
Definition: reply.h:31
Nothing went wrong.
Definition: reply.h:32
Copyright and license information about the provided data.
Definition: attribution.h:28
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
QueuedConnection
Query response base class.
Definition: reply.h:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 23:07:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.