File indexing completed on 2024-05-05 16:28:09
0001 // SPDX-FileCopyrightText: 2003-2010 Jesper K. Pedersen <blackie@kde.org> 0002 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 #ifndef IMAGEMANAGER_ASYNCLOADER_H 0007 #define IMAGEMANAGER_ASYNCLOADER_H 0008 0009 #include "RequestQueue.h" 0010 #include "enums.h" 0011 0012 #include <MainWindow/Window.h> 0013 0014 #include <QImage> 0015 #include <QList> 0016 #include <QMutex> 0017 #include <QWaitCondition> 0018 0019 class QEvent; 0020 0021 namespace ImageManager 0022 { 0023 0024 class ImageRequest; 0025 class ImageClientInterface; 0026 class ImageLoaderThread; 0027 0028 // This class needs to inherit QObject to be capable of receiving events. 0029 class AsyncLoader : public QObject 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 static AsyncLoader *instance(); 0035 0036 // Request to load an image. The Manager takes over the ownership of 0037 // the request (and may delete it anytime). 0038 bool load(ImageRequest *request); 0039 0040 // Stop loading all images requested by the given client. 0041 void stop(ImageClientInterface *, StopAction action = StopAll); 0042 int activeCount() const; 0043 bool isExiting() const; 0044 0045 protected: 0046 void customEvent(QEvent *ev) override; 0047 bool loadVideo(ImageRequest *); 0048 void loadImage(ImageRequest *); 0049 0050 private: 0051 friend class ImageLoaderThread; // may call 'next()' 0052 friend class MainWindow::Window; // may call 'requestExit()' 0053 void init(); 0054 0055 ImageRequest *next(); 0056 0057 void requestExit(); 0058 0059 static AsyncLoader *s_instance; 0060 0061 RequestQueue m_loadList; 0062 QWaitCondition m_sleepers; 0063 // m_lock protects m_loadList and m_currentLoading 0064 mutable QMutex m_lock; 0065 QSet<ImageRequest *> m_currentLoading; 0066 QImage m_brokenImage; 0067 QList<ImageLoaderThread *> m_threadList; 0068 bool m_exitRequested = false; 0069 }; 0070 } 0071 0072 #endif /* IMAGEMANAGER_ASYNCLOADER_H */ 0073 0074 // vi:expandtab:tabstop=4 shiftwidth=4: