File indexing completed on 2024-04-21 03:56:23
0001 /* 0002 This file is part of KNewStuff2. 0003 SPDX-FileCopyrightText: 2006, 2007 Josef Spillner <spillner@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #ifndef KNEWSTUFF3_IMAGELOADER_P_H 0009 #define KNEWSTUFF3_IMAGELOADER_P_H 0010 0011 #include <QByteArray> 0012 #include <QObject> 0013 0014 #include "entry.h" 0015 #include "jobs/httpjob.h" 0016 0017 class KJob; 0018 0019 namespace KNSCore 0020 { 0021 /** 0022 * Convenience class for images with remote sources. 0023 * 0024 * This class represents a fire-and-forget approach of loading images 0025 * in applications. The image will load itself. 0026 * Using this class also requires using QAsyncFrame or similar UI 0027 * elements which allow for asynchronous image loading. 0028 * 0029 * This class is used internally by the DownloadDialog class. 0030 * 0031 * @internal 0032 */ 0033 class KNEWSTUFFCORE_EXPORT ImageLoader : public QObject 0034 { 0035 Q_OBJECT 0036 public: 0037 explicit ImageLoader(const Entry &entry, Entry::PreviewType type, QObject *parent); 0038 void start(); 0039 /** 0040 * Get the job doing the image loading in the background (to have progress information available) 0041 * @return the job 0042 */ 0043 KJob *job(); 0044 0045 Q_SIGNALS: 0046 void signalPreviewLoaded(const KNSCore::Entry &, KNSCore::Entry::PreviewType); 0047 void signalError(const KNSCore::Entry &, KNSCore::Entry::PreviewType, const QString &); 0048 0049 private Q_SLOTS: 0050 void slotDownload(KJob *job); 0051 void slotData(KJob *job, const QByteArray &buf); 0052 0053 private: 0054 Entry m_entry; 0055 const Entry::PreviewType m_previewType; 0056 QByteArray m_buffer; 0057 HTTPJob *m_job = nullptr; 0058 }; 0059 } 0060 #endif