Kstars

hipsmanager.h
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:
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:
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
62  const QMap<QString, QString> &getCurrentSource() const
63  {
64  return m_currentSource;
65  }
66  const QList<QMap<QString, QString>> &getHIPSSources() const
67  {
68  return m_hipsSources;
69  }
70  int getUsableLevel(int level) const;
71  PixCache *getCache();
72  qint64 getDiscCacheSize() const;
73  const QString &getCurrentFormat() const
74  {
75  return m_currentFormat;
76  }
77  HIPSFrame getCurrentFrame() const
78  {
79  return m_currentFrame;
80  }
81  const uint8_t &getCurrentOrder() const
82  {
83  return m_currentOrder;
84  }
85  const uint16_t &getCurrentTileWidth() const
86  {
87  return m_currentTileWidth;
88  }
89  const QUrl &getCurrentURL() const
90  {
91  return m_currentURL;
92  }
93  qint64 getUID() const
94  {
95  return m_uid;
96  }
97  void setOfflineLevels(const QStringList &value);
98 
99  public slots:
100  bool setCurrentSource(const QString &title);
101  void showSettings();
102 
103  signals:
104  void sigRepaint();
105 
106  private slots:
107  void slotDone(QNetworkReply::NetworkError error, QByteArray &data, pixCacheKey_t &key);
108  void slotApply();
109  void removeTimer(pixCacheKey_t &key);
110 
111  private:
112  HIPSManager();
113 
114  static HIPSManager * _HIPSManager;
115 
116  // Cache
117  PixCache m_cache;
118  QSet <pixCacheKey_t> m_downloadMap;
119 
120  void addToMemoryCache(pixCacheKey_t &key, pixCacheItem_t *item);
121  pixCacheItem_t *getCacheItem(pixCacheKey_t &key);
122 
123  // List of all sources in the database
124  QList<QMap<QString, QString>> m_hipsSources;
125 
126  // Current Active Source
127  QMap<QString, QString> m_currentSource;
128 
129  std::unique_ptr<OpsHIPS> sourceSettings;
130  std::unique_ptr<OpsHIPSCache> cacheSettings;
131  std::unique_ptr<OpsHIPSDisplay> displaySettings;
132 
133  // Handy shortcuts
134  qint64 m_uid { 0 };
135  QString m_currentFormat;
136  HIPSFrame m_currentFrame { HIPS_OTHER_FRAME };
137  uint8_t m_currentOrder { 0 };
138  uint16_t m_currentTileWidth { 0 };
139  QUrl m_currentURL;
140  QMap<int, int> m_OfflineLevelsMap;
141 };
Q_OBJECTQ_OBJECT
void start()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void deleteLater()
void timeout()
KGuiItem remove()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 03:59:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.