Kstars

ksdssdownloader.h
1 /*
2  SPDX-FileCopyrightText: 2016 Akarsh Simha <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "ksdssimage.h"
10 
11 #include <QObject>
12 #include <QString>
13 #include <QStringList>
14 #include <QTemporaryFile>
15 #include <QUrl>
16 
17 #include <functional>
18 
19 class FileDownloader;
20 class SkyPoint;
21 class dms;
22 
23 /**
24  * @class KSDssDownloader
25  * @short Helps download a DSS image
26  * @author Akarsh Simha <[email protected]>
27  *
28  * @note This object is designed to commit suicide (calls
29  * QObject::deleteLater() )! Never allocate this using anything but
30  * new -- do not allocate it on the stack! This is ideal for its
31  * operation, as it deletes itself after downloading.
32  */
33 
34 class KSDssDownloader : public QObject
35 {
36  Q_OBJECT
37 
38  public:
39  /** @short Constructor */
40  explicit KSDssDownloader(QObject *parent = nullptr);
41 
42  /**
43  * @short Constructor that initiates a "standard" DSS download job, calls the downloadReady slot, and finally self destructs
44  * @note Very important that if you create with this constructor,
45  * the object will self-destruct. Avoid keeping pointers to it, or
46  * things may segfault!
47  */
48  KSDssDownloader(const SkyPoint *const p, const QString &destFileName,
49  const std::function<void(bool)> &slotDownloadReady, QObject *parent = nullptr);
50 
51  /**
52  * @short Stateful single-download of a supplied URL. Use when the flexibility is required
53  * @note Does not self-delete this object. Construct with default constructor, and delete as usual.
54  * @param srcUrl source DSS URL to download
55  * @param destFileName destination image file (will be of PNG format)
56  * @param md DSS image metadata to write into image file
57  * @note emits downloadComplete with success state when done
58  */
59  void startSingleDownload(const QUrl srcUrl, const QString &destFileName, KSDssImage::Metadata &md);
60 
61  /**
62  * @short High-level method to create a URL to obtain a DSS image for a given SkyPoint
63  * @note If SkyPoint is a DeepSkyObject, this method automatically
64  * decides the image size required to fit the object.
65  * @note Moved from namespace KSUtils (--asimha, Jan 5 2016)
66  */
67  static QString getDSSURL(const SkyPoint *const p, const QString &version = "all",
68  struct KSDssImage::Metadata *md = nullptr);
69 
70  /**
71  * @short High-level method to create a URL to obtain a DSS image for a given SkyPoint
72  * @note This method includes an option to set the height, but uses default values for many parameters
73  */
74  static QString getDSSURL(const SkyPoint *const p, float width, float height = 0, const QString &version = "all",
75  struct KSDssImage::Metadata *md = nullptr);
76 
77  /**
78  * @short Create a URL to obtain a DSS image for a given RA, Dec
79  * @param ra The J2000.0 Right Ascension of the point
80  * @param dec The J2000.0 Declination of the point
81  * @param width The width of the image in arcminutes
82  * @param height The height of the image in arcminutes
83  * @param type_ The image type, either gif or fits.
84  * @param version_ string describing which version to get
85  * @param md If a valid pointer is provided, fill with metadata
86  * @note This method resets height and width to fall within the range accepted by DSS
87  * @note Moved from namespace KSUtils (--asimha, Jan 5 2016)
88  *
89  * @note Valid versions are: dss1, poss2ukstu_red, poss2ukstu_ir,
90  * poss2ukstu_blue, poss1_blue, poss1_red, all, quickv,
91  * phase2_gsc2, phase2_gsc1. Of these, dss1 uses POSS1 Red in the
92  * north and POSS2/UKSTU Blue in the south. all uses the best of a
93  * combined list of all plates.
94  *
95  */
96  static QString getDSSURL(const dms &ra, const dms &dec, float width = 0, float height = 0,
97  const QString &type_ = "gif", const QString &version_ = "all",
98  struct KSDssImage::Metadata *md = nullptr);
99 
100  /** @short Write image metadata into file */
101  static bool writeImageWithMetadata(const QString &srcFile, const QString &destFile, const KSDssImage::Metadata &md);
102 
103  signals:
104  void downloadComplete(bool success);
105  void downloadCanceled();
106 
107  private slots:
108  void downloadAttemptFinished();
109  void singleDownloadFinished();
110  void downloadError(const QString &errorString);
111 
112  private:
113  void startDownload(const SkyPoint *const p, const QString &destFileName);
114  void initiateSingleDownloadAttempt(QUrl srcUrl);
115  bool writeImageFile();
116 
117  QStringList m_VersionPreference;
118  int m_attempt { 0 };
119  struct KSDssImage::Metadata m_AttemptData;
120  QString m_FileName;
121  QTemporaryFile m_TempFile;
122  FileDownloader *downloadJob { nullptr };
123 };
Q_OBJECTQ_OBJECT
void startSingleDownload(const QUrl srcUrl, const QString &destFileName, KSDssImage::Metadata &md)
Stateful single-download of a supplied URL.
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
Helps download a DSS image.
Structure to hold some DSS image metadata.
Definition: ksdssimage.h:35
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
KSDssDownloader(QObject *parent=nullptr)
Constructor.
static bool writeImageWithMetadata(const QString &srcFile, const QString &destFile, const KSDssImage::Metadata &md)
Write image metadata into file.
static QString getDSSURL(const SkyPoint *const p, const QString &version="all", struct KSDssImage::Metadata *md=nullptr)
High-level method to create a URL to obtain a DSS image for a given SkyPoint.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Oct 1 2023 04:02:40 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.