| 1 | // |
| 2 | // Copyright (C) 2017 James Turner [email protected] |
| 3 | // |
| 4 | // This program is free software; you can redistribute it and/or |
| 5 | // modify it under the terms of the GNU General Public License as |
| 6 | // published by the Free Software Foundation; either version 2 of the |
| 7 | // License, or (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, but |
| 10 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | // General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program; if not, write to the Free Software |
| 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | |
| 18 | #ifndef FGQCANVASIMAGELOADER_H |
| 19 | #define FGQCANVASIMAGELOADER_H |
| 20 | |
| 21 | #include <QObject> |
| 22 | #include <QPixmap> |
| 23 | #include <QMap> |
| 24 | #include <QNetworkReply> |
| 25 | |
| 26 | class QNetworkAccessManager; |
| 27 | |
| 28 | class FGQCanvasImageLoader : public QObject |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | public: |
| 32 | FGQCanvasImageLoader(QNetworkAccessManager* dl, QObject* pr = nullptr); |
| 33 | |
| 34 | |
| 35 | void setHost(QString hostName, int portNumber); |
| 36 | |
| 37 | QPixmap getImage(const QByteArray& imagePath); |
| 38 | |
| 39 | /** |
| 40 | * @brief connectToImageLoaded - allow images to discover when they are loaded |
| 41 | * @param imagePath - FGFS host relative path as found in the canvas (will be resolved |
| 42 | * against aircraft-data, and potentially other places) |
| 43 | * @param receiver - normal connect() receiver object |
| 44 | * @param slot - slot macro |
| 45 | */ |
| 46 | void connectToImageLoaded(const QByteArray& imagePath, QObject* receiver, const char* slot); |
| 47 | signals: |
| 48 | |
| 49 | |
| 50 | private: |
| 51 | |
| 52 | void onDownloadFinished(); |
| 53 | void writeToDiskCache(QByteArray imagePath, QNetworkReply *reply); |
| 54 | |
| 55 | private: |
| 56 | QNetworkAccessManager* m_downloader; |
| 57 | QString m_hostName; |
| 58 | int m_port; |
| 59 | |
| 60 | QMap<QByteArray, QPixmap> m_cache; |
| 61 | QList<QNetworkReply*> m_transfers; |
| 62 | |
| 63 | }; |
| 64 | |
| 65 | #endif // FGQCANVASIMAGELOADER_H |