File indexing completed on 2024-04-28 04:42:43

0001 /*
0002  * SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003  * SPDX-License-Identifier: LGPL-2.0-or-later
0004  */
0005 
0006 #ifndef KWEATHERCORE_REPLY_H
0007 #define KWEATHERCORE_REPLY_H
0008 
0009 #include <kweathercore/kweathercore_export.h>
0010 
0011 #include <QObject>
0012 
0013 #include <memory>
0014 
0015 namespace KWeatherCore
0016 {
0017 
0018 class ReplyPrivate;
0019 
0020 /** Base class for all asynchronous jobs.
0021  *  @since 0.6
0022  */
0023 class KWEATHERCORE_EXPORT Reply : public QObject
0024 {
0025     Q_OBJECT
0026 public:
0027     ~Reply() override;
0028 
0029     /** Possible error states of the job. */
0030     enum Error {
0031         NoError,
0032         NetworkError, ///< Network operation failed
0033         RateLimitExceeded, ///< Remote API rate limited exceeded
0034         NotFound, ///< The queried information could not be found by the backend (e.g. unknown location).
0035         NoService, ///< There is no service available for obtaining the requested information.
0036     };
0037 
0038     /** Error state of the job. */
0039     Error error() const;
0040 
0041     /** Error message of the job.
0042      *  Only valid if error() returns something other than NoError.
0043      */
0044     QString errorMessage() const;
0045 
0046 Q_SIGNALS:
0047     /**
0048      * Emitted once the job has been finished, either successfully or with an error.
0049      *
0050      * Connect to this signal for every job you create to obtain its result and
0051      * delete it eventually.
0052      */
0053     void finished();
0054 
0055 protected:
0056     explicit Reply(ReplyPrivate *dd, QObject *parent);
0057 
0058     Q_DECLARE_PRIVATE(Reply)
0059     std::unique_ptr<ReplyPrivate> d_ptr;
0060 };
0061 
0062 }
0063 
0064 #endif // KWEATHERCORE_REPLY_H