File indexing completed on 2024-07-14 14:25:34

0001 /*
0002     This file is part of KDE.
0003 
0004     SPDX-FileCopyrightText: 2008 Cornelius Schumacher <schumacher@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 #ifndef ATTICA_ATTICABASEJOB_H
0009 #define ATTICA_ATTICABASEJOB_H
0010 
0011 #include <QNetworkAccessManager>
0012 #include <QNetworkRequest>
0013 #include <QObject>
0014 #include <QSharedPointer>
0015 #include <QUrl>
0016 
0017 #include "attica_export.h"
0018 #include "metadata.h"
0019 
0020 class QNetworkReply;
0021 
0022 namespace Attica
0023 {
0024 class PlatformDependent;
0025 
0026 /**
0027  * @class BaseJob atticabasejob.h
0028  *
0029  * The baseclass for all job classes.
0030  */
0031 class ATTICA_EXPORT BaseJob : public QObject
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     ~BaseJob() override;
0037 
0038     Metadata metadata() const;
0039 
0040     enum NetworkRequestCustomAttributes {
0041         UserAttribute = QNetworkRequest::User + 1,
0042         PasswordAttribute,
0043     };
0044 
0045     /**
0046      * @returns whether abort() has been called on the job
0047      *
0048      * @since 5.87
0049      */
0050     bool isAborted() const;
0051 
0052 public Q_SLOTS:
0053     void start();
0054     void abort();
0055 
0056 Q_SIGNALS:
0057     void finished(Attica::BaseJob *job);
0058 
0059 protected Q_SLOTS:
0060     void dataFinished();
0061 
0062 protected:
0063     BaseJob(PlatformDependent *internals);
0064 
0065     void setMetadata(const Metadata &data) const;
0066 
0067     virtual QNetworkReply *executeRequest() = 0;
0068     virtual void parse(const QString &xml) = 0;
0069     PlatformDependent *internals();
0070     void setError(int errorCode);
0071 
0072 private Q_SLOTS:
0073     ATTICA_NO_EXPORT void doWork();
0074     ATTICA_NO_EXPORT void authenticationRequired(QNetworkReply *, QAuthenticator *);
0075 
0076 private:
0077     BaseJob(const BaseJob &other) = delete;
0078     BaseJob &operator=(const BaseJob &other) = delete;
0079 
0080     class Private;
0081     Private *d;
0082 };
0083 
0084 }
0085 
0086 #endif