1 | /* |
2 | This file is part of KNewStuff2. |
3 | SPDX-FileCopyrightText: 2006, 2007 Josef Spillner <spillner@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-or-later |
6 | */ |
7 | |
8 | #ifndef KNEWSTUFF3_IMAGELOADER_P_H |
9 | #define KNEWSTUFF3_IMAGELOADER_P_H |
10 | |
11 | #include <QByteArray> |
12 | #include <QObject> |
13 | |
14 | #include "entry.h" |
15 | #include "jobs/httpjob.h" |
16 | |
17 | class KJob; |
18 | |
19 | namespace KNSCore |
20 | { |
21 | /** |
22 | * Convenience class for images with remote sources. |
23 | * |
24 | * This class represents a fire-and-forget approach of loading images |
25 | * in applications. The image will load itself. |
26 | * Using this class also requires using QAsyncFrame or similar UI |
27 | * elements which allow for asynchronous image loading. |
28 | * |
29 | * This class is used internally by the DownloadDialog class. |
30 | * |
31 | * @internal |
32 | */ |
33 | class KNEWSTUFFCORE_EXPORT ImageLoader : public QObject |
34 | { |
35 | Q_OBJECT |
36 | public: |
37 | explicit ImageLoader(const Entry &entry, Entry::PreviewType type, QObject *parent); |
38 | void start(); |
39 | /** |
40 | * Get the job doing the image loading in the background (to have progress information available) |
41 | * @return the job |
42 | */ |
43 | KJob *job(); |
44 | |
45 | Q_SIGNALS: |
46 | void signalPreviewLoaded(const KNSCore::Entry &, KNSCore::Entry::PreviewType); |
47 | void signalError(const KNSCore::Entry &, KNSCore::Entry::PreviewType, const QString &); |
48 | |
49 | private Q_SLOTS: |
50 | void slotDownload(KJob *job); |
51 | void slotData(KJob *job, const QByteArray &buf); |
52 | |
53 | private: |
54 | Entry m_entry; |
55 | const Entry::PreviewType m_previewType; |
56 | QByteArray m_buffer; |
57 | HTTPJob *m_job = nullptr; |
58 | }; |
59 | } |
60 | #endif |
61 | |