| 1 | /* |
| 2 | This file is part of KDE. |
| 3 | |
| 4 | SPDX-FileCopyrightText: 2008 Cornelius Schumacher <schumacher@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 | */ |
| 8 | #ifndef ATTICA_ATTICABASEJOB_H |
| 9 | #define ATTICA_ATTICABASEJOB_H |
| 10 | |
| 11 | #include <memory> |
| 12 | |
| 13 | #include <QNetworkAccessManager> |
| 14 | #include <QNetworkRequest> |
| 15 | #include <QObject> |
| 16 | #include <QSharedPointer> |
| 17 | #include <QUrl> |
| 18 | |
| 19 | #include "attica_export.h" |
| 20 | #include "metadata.h" |
| 21 | |
| 22 | class QNetworkReply; |
| 23 | |
| 24 | namespace Attica |
| 25 | { |
| 26 | class PlatformDependent; |
| 27 | |
| 28 | /*! |
| 29 | * \class Attica::BaseJob |
| 30 | * \inheaderfile attica/atticabasejob.h |
| 31 | * \inmodule Attica |
| 32 | * |
| 33 | * \brief The baseclass for all job classes. |
| 34 | */ |
| 35 | class ATTICA_EXPORT BaseJob : public QObject |
| 36 | { |
| 37 | Q_OBJECT |
| 38 | |
| 39 | public: |
| 40 | ~BaseJob() override; |
| 41 | |
| 42 | /*! |
| 43 | * |
| 44 | */ |
| 45 | Metadata metadata() const; |
| 46 | |
| 47 | /*! |
| 48 | * \brief UserAttribute |
| 49 | * \brief PasswordAttribute |
| 50 | */ |
| 51 | enum NetworkRequestCustomAttributes { |
| 52 | UserAttribute = QNetworkRequest::User + 1, |
| 53 | PasswordAttribute, |
| 54 | }; |
| 55 | |
| 56 | /*! |
| 57 | * Returns whether abort() has been called on the job |
| 58 | * |
| 59 | * \since 5.87 |
| 60 | */ |
| 61 | bool isAborted() const; |
| 62 | |
| 63 | public Q_SLOTS: |
| 64 | /*! |
| 65 | * |
| 66 | */ |
| 67 | void start(); |
| 68 | |
| 69 | /*! |
| 70 | * |
| 71 | */ |
| 72 | void abort(); |
| 73 | |
| 74 | Q_SIGNALS: |
| 75 | void finished(Attica::BaseJob *job); |
| 76 | |
| 77 | protected Q_SLOTS: |
| 78 | /*! |
| 79 | * |
| 80 | */ |
| 81 | void dataFinished(); |
| 82 | |
| 83 | protected: |
| 84 | BaseJob(PlatformDependent *internals); |
| 85 | |
| 86 | /*! |
| 87 | * |
| 88 | */ |
| 89 | void setMetadata(const Metadata &data) const; |
| 90 | |
| 91 | /*! |
| 92 | * |
| 93 | */ |
| 94 | virtual QNetworkReply *executeRequest() = 0; |
| 95 | |
| 96 | /*! |
| 97 | * |
| 98 | */ |
| 99 | virtual void parse(const QString &xml) = 0; |
| 100 | |
| 101 | /*! |
| 102 | * |
| 103 | */ |
| 104 | PlatformDependent *internals(); |
| 105 | |
| 106 | /*! |
| 107 | * |
| 108 | */ |
| 109 | void setError(int errorCode); |
| 110 | |
| 111 | private Q_SLOTS: |
| 112 | ATTICA_NO_EXPORT void doWork(); |
| 113 | ATTICA_NO_EXPORT void authenticationRequired(QNetworkReply *, QAuthenticator *); |
| 114 | |
| 115 | private: |
| 116 | BaseJob(const BaseJob &other) = delete; |
| 117 | BaseJob &operator=(const BaseJob &other) = delete; |
| 118 | |
| 119 | class Private; |
| 120 | std::unique_ptr<Private> d; |
| 121 | }; |
| 122 | |
| 123 | } |
| 124 | |
| 125 | #endif |
| 126 | |