File indexing completed on 2024-03-24 15:17:04

0001 /*
0002     SPDX-FileCopyrightText: 2015-2017 Pavel Mraz
0003 
0004     SPDX-FileCopyrightText: 2017 Jasem Mutlaq
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include "hips.h"
0012 #include "opships.h"
0013 #include "pixcache.h"
0014 #include "urlfiledownload.h"
0015 
0016 #include <QObject>
0017 
0018 #include <memory>
0019 
0020 class RemoveTimer : public QTimer
0021 {
0022         Q_OBJECT
0023     public:
0024         RemoveTimer()
0025         {
0026             connect(this, SIGNAL(timeout()), this, SLOT(done()));
0027             start(5000);
0028         }
0029 
0030         void setKey(const pixCacheKey_t &key);
0031 
0032         pixCacheKey_t m_key { 0, 0, 0 };
0033 
0034     signals:
0035         void remove(pixCacheKey_t &key);
0036 
0037     private slots:
0038         void done()
0039         {
0040             emit remove(m_key);
0041             deleteLater();
0042         }
0043 };
0044 
0045 class HIPSManager : public QObject
0046 {
0047         Q_OBJECT
0048 
0049     public:
0050         static HIPSManager *Instance();
0051 
0052         typedef enum { HIPS_EQUATORIAL_FRAME, HIPS_GALACTIC_FRAME, HIPS_OTHER_FRAME } HIPSFrame;
0053 
0054         QImage *getPix(bool allsky, int level, int pix, bool &freeImage);
0055 
0056         void readSources();
0057 
0058         void cancelAll();
0059         void clearDiscCache();
0060 
0061         // Getters
0062         const QMap<QString, QString> &getCurrentSource() const
0063         {
0064             return m_currentSource;
0065         }
0066         const QList<QMap<QString, QString>> &getHIPSSources() const
0067         {
0068             return m_hipsSources;
0069         }
0070         int getUsableLevel(int level) const;
0071         int getUsableOfflineLevel(int level) const;
0072         PixCache *getCache();
0073         qint64 getDiscCacheSize() const;
0074         const QString &getCurrentFormat() const
0075         {
0076             return m_currentFormat;
0077         }
0078         HIPSFrame getCurrentFrame() const
0079         {
0080             return m_currentFrame;
0081         }
0082         const uint8_t &getCurrentOrder() const
0083         {
0084             return m_currentOrder;
0085         }
0086         const uint16_t &getCurrentTileWidth() const
0087         {
0088             return m_currentTileWidth;
0089         }
0090         const QUrl &getCurrentURL() const
0091         {
0092             return m_currentURL;
0093         }
0094         qint64 getUID() const
0095         {
0096             return m_uid;
0097         }
0098         void setOfflineLevels(const QStringList &value);
0099 
0100     public slots:
0101         bool setCurrentSource(const QString &title);
0102         void showSettings();
0103 
0104     signals:
0105         void sigRepaint();
0106 
0107     private slots:
0108         void slotDone(QNetworkReply::NetworkError error, QByteArray &data, pixCacheKey_t &key);
0109         void slotApply();
0110         void removeTimer(pixCacheKey_t &key);
0111 
0112     private:
0113         HIPSManager();
0114 
0115         static HIPSManager * _HIPSManager;
0116 
0117         // Cache
0118         PixCache m_cache;
0119         QSet <pixCacheKey_t> m_downloadMap;
0120 
0121         void addToMemoryCache(pixCacheKey_t &key, pixCacheItem_t *item);
0122         pixCacheItem_t *getCacheItem(pixCacheKey_t &key);
0123 
0124         // List of all sources in the database
0125         QList<QMap<QString, QString>> m_hipsSources;
0126 
0127         // Current Active Source
0128         QMap<QString, QString> m_currentSource;
0129 
0130         std::unique_ptr<OpsHIPS> sourceSettings;
0131         std::unique_ptr<OpsHIPSCache> cacheSettings;
0132         std::unique_ptr<OpsHIPSDisplay> displaySettings;
0133 
0134         // Handy shortcuts
0135         qint64 m_uid { 0 };
0136         QString m_currentFormat;
0137         HIPSFrame m_currentFrame { HIPS_OTHER_FRAME };
0138         uint8_t m_currentOrder { 0 };
0139         uint16_t m_currentTileWidth { 0 };
0140         QUrl m_currentURL;
0141         QMap<int, int> m_OfflineLevelsMap;
0142 };