swift
urllog.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_NETWORK_URLLOG_H
7 #define SWIFT_MISC_NETWORK_URLLOG_H
8 
9 #include <QJsonObject>
10 #include <QString>
11 
12 #include "misc/network/url.h"
13 #include "misc/propertyindexref.h"
14 #include "misc/swiftmiscexport.h"
15 #include "misc/timestampbased.h"
16 #include "misc/valueobject.h"
17 
18 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::network, CUrlLog)
19 
20 namespace swift::misc::network
21 {
23  class SWIFT_MISC_EXPORT CUrlLog : public CValueObject<CUrlLog>, public ITimestampBased
24  {
25  public:
28  {
29  IndexId = CPropertyIndexRef::GlobalIndexCUrlLog,
30  IndexSuccess,
31  IndexUrl,
32  IndexResponseTimestamp,
33  IndexResponseTime
34  };
35 
37  CUrlLog(const CUrl &url = {});
38 
40  int getId() const { return this->m_id; }
41 
43  const CUrl &getUrl() const { return m_url; }
44 
46  QDateTime getResponseTimestamp() const { return QDateTime::fromMSecsSinceEpoch(m_responseTimeMSecsSinceEpoch); }
47 
49  qint64 getResponseTimeMSecsSinceEpoch() const { return m_responseTimeMSecsSinceEpoch; }
50 
52  void setResponseTimestampToNow();
53 
55  qint64 getResponseTimeMs() const { return m_responseTimeMs; }
56 
58  bool isPending() const;
59 
61  bool isSuccess() const { return m_success; }
62 
64  void setSuccess(bool s) { m_success = s; }
65 
67  QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
68 
70  void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
71 
73  QString convertToQString(bool i18n = false) const;
74 
76  static const char *propertyNameId();
77 
78  private:
79  int m_id = -1;
80  CUrl m_url;
81  bool m_success = false;
82  qint64 m_responseTimeMSecsSinceEpoch = -1;
83  qint64 m_responseTimeMs = -1;
84 
87  static int uniqueId();
88 
90  CUrlLog,
91  SWIFT_METAMEMBER(id),
92  SWIFT_METAMEMBER(url),
93  SWIFT_METAMEMBER(success),
94  SWIFT_METAMEMBER(responseTimeMSecsSinceEpoch),
95  SWIFT_METAMEMBER(responseTimeMs));
96  };
97 } // namespace swift::misc::network
98 
99 Q_DECLARE_METATYPE(swift::misc::network::CUrlLog)
100 
101 #endif // SWIFT_MISC_NETWORK_URLLOG_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Entity with timestamp.
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition: url.h:27
Information about accessing one URL over the network.
Definition: urllog.h:24
QDateTime getResponseTimestamp() const
Response timestamp.
Definition: urllog.h:46
qint64 getResponseTimeMs() const
Response time.
Definition: urllog.h:55
void setSuccess(bool s)
Set success.
Definition: urllog.h:64
bool isSuccess() const
Success?
Definition: urllog.h:61
qint64 getResponseTimeMSecsSinceEpoch() const
Response timestamp milliseconds since epoch.
Definition: urllog.h:49
int getId() const
Unique id.
Definition: urllog.h:40
const CUrl & getUrl() const
Get URL.
Definition: urllog.h:43
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65