1 /* SPDX-FileCopyrightText: 2003-2010 Jesper K. Pedersen <blackie@kde.org> 2 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 6 #ifndef IMAGEMANAGER_ASYNCLOADER_H 7 #define IMAGEMANAGER_ASYNCLOADER_H 8 9 #include "RequestQueue.h" 10 #include "enums.h" 11 12 #include <MainWindow/Window.h> 13 14 #include <QImage> 15 #include <QList> 16 #include <QMutex> 17 #include <QWaitCondition> 18 19 class QEvent; 20 21 namespace ImageManager 22 { 23 24 class ImageRequest; 25 class ImageClientInterface; 26 class ImageLoaderThread; 27 28 // This class needs to inherit QObject to be capable of receiving events. 29 class AsyncLoader : public QObject 30 { 31 Q_OBJECT 32 33 public: 34 static AsyncLoader *instance(); 35 36 // Request to load an image. The Manager takes over the ownership of 37 // the request (and may delete it anytime). 38 bool load(ImageRequest *request); 39 40 // Stop loading all images requested by the given client. 41 void stop(ImageClientInterface *, StopAction action = StopAll); 42 int activeCount() const; 43 bool isExiting() const; 44 45 protected: 46 void customEvent(QEvent *ev) override; 47 bool loadVideo(ImageRequest *); 48 void loadImage(ImageRequest *); 49 50 private: 51 friend class ImageLoaderThread; // may call 'next()' 52 friend class MainWindow::Window; // may call 'requestExit()' 53 void init(); 54 55 ImageRequest *next(); 56 57 void requestExit(); 58 59 static AsyncLoader *s_instance; 60 61 RequestQueue m_loadList; 62 QWaitCondition m_sleepers; 63 // m_lock protects m_loadList and m_currentLoading 64 mutable QMutex m_lock; 65 QSet<ImageRequest *> m_currentLoading; 66 QImage m_brokenImage; 67 QList<ImageLoaderThread *> m_threadList; 68 bool m_exitRequested; 69 int m_exitRequestsProcessed; 70 }; 71 } 72 73 #endif /* IMAGEMANAGER_ASYNCLOADER_H */ 74 75 // vi:expandtab:tabstop=4 shiftwidth=4: 76