1 /* 2 SPDX-FileCopyrightText: 2015-2017 Pavel Mraz 3 4 SPDX-FileCopyrightText: 2017 Jasem Mutlaq 5 6 SPDX-License-Identifier: GPL-2.0-or-later 7 */ 8 9 #pragma once 10 11 #include "hips.h" 12 #include "opships.h" 13 #include "pixcache.h" 14 #include "urlfiledownload.h" 15 16 #include <QObject> 17 18 #include <memory> 19 20 class RemoveTimer : public QTimer 21 { 22 Q_OBJECT 23 public: RemoveTimer()24 RemoveTimer() 25 { 26 connect(this, SIGNAL(timeout()), this, SLOT(done())); 27 start(5000); 28 } 29 30 void setKey(const pixCacheKey_t &key); 31 32 pixCacheKey_t m_key { 0, 0, 0 }; 33 34 signals: 35 void remove(pixCacheKey_t &key); 36 37 private slots: done()38 void done() 39 { 40 emit remove(m_key); 41 deleteLater(); 42 } 43 }; 44 45 class HIPSManager : public QObject 46 { 47 Q_OBJECT 48 49 public: 50 static HIPSManager *Instance(); 51 52 typedef enum { HIPS_EQUATORIAL_FRAME, HIPS_GALACTIC_FRAME, HIPS_OTHER_FRAME } HIPSFrame; 53 54 QImage *getPix(bool allsky, int level, int pix, bool &freeImage); 55 56 void readSources(); 57 58 void cancelAll(); 59 void clearDiscCache(); 60 61 // Getters getCurrentSource()62 const QMap<QString, QString> &getCurrentSource() const 63 { 64 return m_currentSource; 65 } getHIPSSources()66 const QList<QMap<QString, QString>> &getHIPSSources() const 67 { 68 return m_hipsSources; 69 } 70 PixCache *getCache(); 71 qint64 getDiscCacheSize() const; getCurrentFormat()72 const QString &getCurrentFormat() const 73 { 74 return m_currentFormat; 75 } getCurrentFrame()76 HIPSFrame getCurrentFrame() const 77 { 78 return m_currentFrame; 79 } getCurrentOrder()80 const uint8_t &getCurrentOrder() const 81 { 82 return m_currentOrder; 83 } getCurrentTileWidth()84 const uint16_t &getCurrentTileWidth() const 85 { 86 return m_currentTileWidth; 87 } getCurrentURL()88 const QUrl &getCurrentURL() const 89 { 90 return m_currentURL; 91 } getUID()92 qint64 getUID() const 93 { 94 return m_uid; 95 } 96 97 public slots: 98 bool setCurrentSource(const QString &title); 99 void showSettings(); 100 101 signals: 102 void sigRepaint(); 103 104 private slots: 105 void slotDone(QNetworkReply::NetworkError error, QByteArray &data, pixCacheKey_t &key); 106 void slotApply(); 107 void removeTimer(pixCacheKey_t &key); 108 109 private: 110 HIPSManager(); 111 112 static HIPSManager * _HIPSManager; 113 114 // Cache 115 PixCache m_cache; 116 QSet <pixCacheKey_t> m_downloadMap; 117 118 void addToMemoryCache(pixCacheKey_t &key, pixCacheItem_t *item); 119 pixCacheItem_t *getCacheItem(pixCacheKey_t &key); 120 121 // List of all sources in the database 122 QList<QMap<QString, QString>> m_hipsSources; 123 124 // Current Active Source 125 QMap<QString, QString> m_currentSource; 126 127 std::unique_ptr<OpsHIPS> sourceSettings; 128 std::unique_ptr<OpsHIPSCache> cacheSettings; 129 std::unique_ptr<OpsHIPSDisplay> displaySettings; 130 131 // Handy shortcuts 132 qint64 m_uid { 0 }; 133 QString m_currentFormat; 134 HIPSFrame m_currentFrame { HIPS_OTHER_FRAME }; 135 uint8_t m_currentOrder { 0 }; 136 uint16_t m_currentTileWidth { 0 }; 137 QUrl m_currentURL; 138 }; 139