File: internalerror.h

package info (click to toggle)
syncthingtray 1.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,804 kB
  • sloc: cpp: 31,085; xml: 1,694; java: 570; sh: 81; javascript: 53; makefile: 25
file content (61 lines) | stat: -rw-r--r-- 1,696 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef SYNCTHINGWIDGETS_INTERNAL_ERROR_H
#define SYNCTHINGWIDGETS_INTERNAL_ERROR_H

#include "../global.h"

#include <c++utilities/chrono/datetime.h>

#include <QByteArray>
#include <QObject>
#include <QString>
#include <QUrl>

namespace Data {
class SyncthingConnection;
enum class SyncthingErrorCategory;
} // namespace Data

namespace QtGui {

struct SYNCTHINGWIDGETS_EXPORT InternalError {
    Q_GADGET
    Q_PROPERTY(QString message MEMBER message CONSTANT)
    Q_PROPERTY(QUrl url MEMBER url CONSTANT)
    Q_PROPERTY(QByteArray response MEMBER response CONSTANT)
    Q_PROPERTY(QString when READ whenToString CONSTANT)

public:
    explicit InternalError(const QString &message = QString(), const QUrl &url = QUrl(), const QByteArray &response = QByteArray());

    static bool isRelevant(const Data::SyncthingConnection &connection, Data::SyncthingErrorCategory category, const QString &message,
        int networkError, bool useGlobalSettings = true);
    QString whenToString() const;

    QString message;
    QUrl url;
    QByteArray response;
    CppUtilities::DateTime when;
};

/*!
 * \brief Constructs a new error suitable for display purposes (password in \a url is redacted).
 */
inline InternalError::InternalError(const QString &message, const QUrl &url, const QByteArray &response)
    : message(message)
    , url(url)
    , response(response)
    , when(CppUtilities::DateTime::now())
{
    if (!this->url.password().isEmpty()) {
        this->url.setPassword(QStringLiteral("redacted"));
    }
}

inline QString InternalError::whenToString() const
{
    return QString::fromStdString(when.toString());
}

} // namespace QtGui

#endif // SYNCTHINGWIDGETS_INTERNAL_ERROR_H