davjobbase.h 2.28 KB
Newer Older
1
/*
2
    SPDX-FileCopyrightText: 2014 Gregory Oestreicher <greg@kamago.net>
3

4
    SPDX-License-Identifier: LGPL-2.0-or-later
5 6
*/

7 8
#ifndef KDAV_DAVJOBBASE_H
#define KDAV_DAVJOBBASE_H
9

10
#include "kdav_export.h"
Sandro Knauß's avatar
Sandro Knauß committed
11

12
#include <KJob>
13

14
#include <memory>
Volker Krause's avatar
Volker Krause committed
15

16 17
class DavJobBasePrivate;

Laurent Montel's avatar
Laurent Montel committed
18
namespace KDAV {
19
class Error;
20

21 22 23
/**
 * @short base class for the jobs used by the resource.
 */
24
class KDAV_EXPORT DavJobBase : public KJob
25
{
Laurent Montel's avatar
Laurent Montel committed
26
    Q_OBJECT
27

Laurent Montel's avatar
Laurent Montel committed
28
public:
Sandro Knauß's avatar
Sandro Knauß committed
29
    explicit DavJobBase(QObject *parent = nullptr);
30
    ~DavJobBase();
31 32 33 34 35 36 37 38

    /**
     * Get the latest response code.
     *
     * If no response code has been set then 0 will be returned, but will
     * be meaningless unless error() is non-zero. In that case this means
     * that the latest error was not at the HTTP level.
     */
Laurent Montel's avatar
Laurent Montel committed
39
    Q_REQUIRED_RESULT int latestResponseCode() const;
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

    /**
     * Check if the job can be retried later.
     *
     * This will return true for transient errors, i.e. if the response code
     * is either zero and error() is set or if the HTTP response code hints
     * at a temporary error.
     *
     * The HTTP response codes considered retryable are:
     *   - 401
     *   - 402
     *   - 407
     *   - 408
     *   - 423
     *   - 429
     *   - 501 to 504, inclusive
     *   - 507
     *   - 511
     */
Laurent Montel's avatar
Laurent Montel committed
59
    Q_REQUIRED_RESULT bool canRetryLater() const;
60

61 62 63
    /**
     * Check if the job failed because of a conflict
     */
Laurent Montel's avatar
Laurent Montel committed
64
    Q_REQUIRED_RESULT bool hasConflict() const;
65

66 67 68
    /**
     * Returns a instance of the KDAV:Error to be able to translate the error
     */
Laurent Montel's avatar
Laurent Montel committed
69
    Q_REQUIRED_RESULT Error davError() const;
70

Laurent Montel's avatar
Laurent Montel committed
71
protected:
72 73 74 75 76 77 78 79
    /**
     * Sets the latest response code received.
     *
     * Only really useful in case of error, though success codes can
     * also be set.
     *
     * @param code The code to set, should be a valid HTTP response code or zero.
     */
80
    Q_DECL_HIDDEN void setLatestResponseCode(int code);
81

82 83 84 85
    Q_DECL_HIDDEN void setJobErrorText(const QString &errorText);
    Q_DECL_HIDDEN void setJobError(int jobErrorCode);
    Q_DECL_HIDDEN void setErrorTextFromDavError();
    Q_DECL_HIDDEN void setDavError(const Error &error);
86

87 88
    Q_DECL_HIDDEN explicit DavJobBase(DavJobBasePrivate *dd, QObject *parent = nullptr);
    std::unique_ptr<DavJobBasePrivate> d_ptr;
Laurent Montel's avatar
Laurent Montel committed
89
private:
90
    Q_DECLARE_PRIVATE(DavJobBase)
91
};
92 93 94
}

#endif