[Kstars-devel] [kstars] kstars: Created new classes to handle DSS images and downloading of DSS images

Akarsh Simha akarsh at kde.org
Tue Jan 5 13:59:02 UTC 2016


Git commit b3d246616c8df094c2ec1bf8b8c6dfcbd5ccbf75 by Akarsh Simha.
Committed on 05/01/2016 at 13:42.
Pushed by asimha into branch 'master'.

Created new classes to handle DSS images and downloading of DSS images

1. Moved KSUtils::getDSSURL() to KSDssDownloader::getDSSURL() with
   expanded, but backward-compatible options.

2. Created a new class KSDssImage to load and hold a DSS Image as a
   QImage along with a metadata structure. The metadata struct is
   designed to supplement information about the DSS image (eg: size in
   arcminutes, center RA/Dec, photometric band, generation of DSS
   etc.)

3. Created a new class KSDssDownloader which completely takes care of
   downloading DSS images given a SkyPoint and a destination file. It:

   - Formats the URL
   - Sets up a download job
   - Tries alternate versions if the download failed
   - Writes the file along with metadata as a compressed PNG image

4. Employed this new machinery in ObservingList

5. Regression: partial removal of (anyway broken) SDSS support

Motivation:

+ DSS images are heavily used by visual astronomers to compare what
  they see in the eyepiece with imagery. These are far superior to
  "photoshopped" / HDR-ed astrophotographs since the brightness is
  roughly a real measure of brightness.

+ Visual astronomers prefer blue images to red images since they
  closer approximate what may be seen with the eye. However,
  sometimes, blue images are not available, so it is inevitable to
  fall back to red. In these times, it is important to know what plate
  is being looked at (blue or red)

+ We intend to eventually be able to overlay DSS images on the sky
  map. A system for caching and rendering compressed (PNG as opposed
  to FITS) DSS images may be important, and this requires proper
  metadata.

Solutions:

+ KSDssImage ensures that image and metadata are kept together. The
  width and height are important meta data for any DSS image. While
  these could be figured using a pixels/arcminute ratio, this ratio is
  not the same across various generations of the DSS.

+ KSDssDownloader goes through a sequence of attempts at downloading
  DSS images in an order that is set by us, rather then set by the
  MAST website (which would be the case if we did not specify which
  version we want). The MAST website prefers POSS II Red > POSS II
  Blue > POSS I Red etc. whereas we would want to prefer POSS II Blue
  > POSS II Red > ...; More powerfully, this sequence may be a
  configurable option later.

  The other advantage of doing this sequence, instead of letting the
  DSS search find a version for us, is that of knowing what we've
  got. The gif from MAST website has no metadata in it (although GIF
  does support metadata). This means we don't know which version of
  the survey we got.

+ Test cases: Palomar 6 is an interesting test case because POSS II
  blue plate is unavailable. The script figures out that the blue
  plate failed, and fetches the red plate instead. The advantage of
  KSDssDownloader is that we now know that we are holding a red plate
  -- it's in the PNG metadata.

Future:

+ Need to expand to SDSS. Then, allow for proper detection of whether
  the coordinates fell in SDSS footprint or not. Then, use the same
  falling-through to fall-back to DSS after SDSS.

+ Ability to compose a closest approximation to visual view from R/B
  plates

+ DSSimage SkyComponent that holds multiple DSS Images along with
  their respective coordinates.

CCMAIL: kstars-devel at kde.org

M  +2    -0    kstars/CMakeLists.txt
A  +246  -0    kstars/auxiliary/ksdssdownloader.cpp     [License: GPL (v2+)]
A  +114  -0    kstars/auxiliary/ksdssdownloader.h     [License: GPL (v2+)]
A  +45   -0    kstars/auxiliary/ksdssimage.cpp     [License: GPL (v2+)]
A  +95   -0    kstars/auxiliary/ksdssimage.h     [License: GPL (v2+)]
M  +3    -3    kstars/kstarsdbus.cpp
M  +3    -2    kstars/skymap.cpp
M  +26   -7    kstars/tools/observinglist.cpp
M  +1    -1    kstars/tools/observinglist.h

http://commits.kde.org/kstars/b3d246616c8df094c2ec1bf8b8c6dfcbd5ccbf75

diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index 3a3c50e..6ce1d79 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -415,6 +415,8 @@ set(kstars_extra_SRCS
         auxiliary/binfilehelper.cpp
         auxiliary/imageexporter.cpp
         auxiliary/ksutils.cpp
+        auxiliary/ksdssimage.cpp
+        auxiliary/ksdssdownloader.cpp
         auxiliary/kswizard.cpp
         auxiliary/qcustomplot.cpp
         time/simclock.cpp
diff --git a/kstars/auxiliary/ksdssdownloader.cpp b/kstars/auxiliary/ksdssdownloader.cpp
new file mode 100644
index 0000000..0bc98b9
--- /dev/null
+++ b/kstars/auxiliary/ksdssdownloader.cpp
@@ -0,0 +1,246 @@
+/***************************************************************************
+                 ksdssdownloader.cpp  -  K Desktop Planetarium
+                             -------------------
+    begin                : Tue 05 Jan 2016 03:39:18 CST
+    copyright            : (c) 2016 by Akarsh Simha
+    email                : akarsh.simha at kdemail.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+
+/* Project Includes */
+#include "ksdssdownloader.h"
+#include "ksdssimage.h"
+#include "skypoint.h"
+#include "skyobject.h"
+#include "deepskyobject.h"
+#include "dms.h"
+#include "Options.h"
+
+/* KDE Includes */
+#include <KIO/Job>
+#include <KIO/CopyJob>
+
+/* Qt Includes */
+#include <QString>
+#include <QImage>
+#include <QImageWriter>
+#include <QUrl>
+#include <QMimeDatabase>
+#include <QMimeType>
+#include <QTemporaryFile>
+
+
+KSDssDownloader::KSDssDownloader(const SkyPoint * const p, const QString &destFileName, QObject *parent ) : QObject( parent ) {
+    // Initialize version preferences. FIXME: This must be made a
+    // user-changeable option just in case someone likes red
+    m_VersionPreference << "poss2ukstu_blue" << "poss2ukstu_red" << "poss1_blue" << "poss1_red" << "quickv" << "poss2ukstu_ir";
+    m_TempFile.open();
+    startDownload( p, destFileName );
+}
+
+QString KSDssDownloader::getDSSURL( const SkyPoint * const p, const QString &version, struct KSDssImage::Metadata *md ) {
+        const DeepSkyObject *dso = 0;
+        double height, width;
+
+        double dss_default_size = Options::defaultDSSImageSize();
+        double dss_padding = Options::dSSPadding();
+
+        Q_ASSERT( p );
+        Q_ASSERT( dss_default_size > 0.0 && dss_padding >= 0.0 );
+
+        dso = dynamic_cast<const DeepSkyObject *>( p );
+
+        // Decide what to do about the height and width
+        if( dso ) {
+            // For deep-sky objects, use their height and width information
+            double a, b, pa;
+            a = dso->a();
+            b = dso->a() * dso->e(); // Use a * e instead of b, since e() returns 1 whenever one of the dimensions is zero. This is important for circular objects
+            pa = dso->pa() * dms::DegToRad;
+
+            // We now want to convert a, b, and pa into an image
+            // height and width -- i.e. a dRA and dDec.
+            // DSS uses dDec for height and dRA for width. (i.e. "top" is north in the DSS images, AFAICT)
+            // From some trigonometry, assuming we have a rectangular object (worst case), we need:
+            width = a * sin( pa ) + b * cos( pa );
+            height = a * cos( pa ) + b * sin( pa );
+            // 'a' and 'b' are in arcminutes, so height and width are in arcminutes
+
+            // Pad the RA and Dec, so that we show more of the sky than just the object.
+            height += dss_padding;
+            width += dss_padding;
+        }
+        else {
+            // For a generic sky object, we don't know what to do. So
+            // we just assume the default size.
+            height = width = dss_default_size;
+        }
+        // There's no point in tiny DSS images that are smaller than dss_default_size
+        if( height < dss_default_size )
+            height = dss_default_size;
+        if( width < dss_default_size )
+            width = dss_default_size;
+
+        QString URL = getDSSURL( p->ra0(), p->dec0(), width, height, "gif", version, md );
+        if( md ) {
+            const SkyObject *obj = 0;
+            obj = dynamic_cast<const SkyObject *>( p );
+            if( obj && obj->hasName() )
+                md->object = obj->name();
+        }
+        return URL;
+}
+
+QString KSDssDownloader::getDSSURL( const dms &ra, const dms &dec, float width, float height, const QString & type_, const QString & version_, struct KSDssImage::Metadata *md ) {
+
+    const double dss_default_size = Options::defaultDSSImageSize();
+
+    QString version = version_.toLower();
+    QString type = type_.toLower();
+    QString URLprefix = QString( "http://archive.stsci.edu/cgi-bin/dss_search?v=%1&" ).arg(version);
+    QString URLsuffix = QString( "&e=J2000&f=%1&c=none&fov=NONE" ).arg(type);
+
+    char decsgn = ( dec.Degrees() < 0.0 ) ? '-' : '+';
+    int dd = abs( dec.degree() );
+    int dm = abs( dec.arcmin() );
+    int ds = abs( dec.arcsec() );
+
+    // Infinite and NaN sizes are replaced by the default size and tiny DSS images are resized to default size
+    if( !qIsFinite( height ) || height <= 0.0 )
+        height = dss_default_size;
+    if( !qIsFinite( width ) || width <= 0.0)
+        width = dss_default_size;
+
+    // DSS accepts images that are no larger than 75 arcminutes
+    if( height > 75.0 )
+        height = 75.0;
+    if( width > 75.0 )
+        width = 75.0;
+
+    QString RAString, DecString, SizeString;
+    DecString = DecString.sprintf( "&d=%c%02d+%02d+%02d", decsgn, dd, dm, ds );
+    RAString  = RAString.sprintf( "r=%02d+%02d+%02d", ra.hour(), ra.minute(), ra.second() );
+    SizeString = SizeString.sprintf( "&h=%02.1f&w=%02.1f", height, width );
+
+    if( md ) {
+        md->src = KSDssImage::Metadata::DSS;
+        md->width = width;
+        md->height = height;
+        md->ra0 = ra;
+        md->dec0 = dec;
+        md->version = version;
+        md->format = ( type.contains( "fit" ) ? KSDssImage::Metadata::FITS : KSDssImage::Metadata::GIF );
+        md->height = height;
+        md->width = width;
+
+        if( version.contains( "poss2" ) )
+            md->gen = 2;
+        else if( version.contains( "poss1" ) )
+            md->gen = 1;
+        else if( version.contains( "quickv" ) )
+            md->gen = 4;
+        else
+            md->gen = -1;
+
+        if( version.contains( "red" ) )
+            md->band='R';
+        else if( version.contains( "blue" ) )
+            md->band='B';
+        else if( version.contains( "ir" ) )
+            md->band='I';
+        else if( version.contains( "quickv" ) )
+            md->band='V';
+        else
+            md->band='?';
+
+        md->object = QString();
+    }
+
+    return ( URLprefix + RAString + DecString + SizeString + URLsuffix );
+}
+
+void KSDssDownloader::initiateSingleDownloadAttempt( QUrl srcUrl ) {
+    qDebug() << "Temp file is at " << m_TempFile.fileName();
+    QUrl fileUrl = QUrl::fromLocalFile( m_TempFile.fileName() );
+    qDebug() << "Attempt #" << m_attempt << "downloading DSS Image. URL: " << srcUrl << " to " << fileUrl;
+    m_DownloadJob = KIO::copy( srcUrl, fileUrl, KIO::Overwrite ) ; // FIXME: Can be done with pure Qt
+    connect ( m_DownloadJob, SIGNAL ( result (KJob *) ), SLOT ( downloadAttemptFinished() ) );
+}
+
+void KSDssDownloader::startDownload( const SkyPoint * const p, const QString &destFileName ) {
+    QUrl srcUrl;
+    m_FileName = destFileName;
+    m_attempt = 0;
+    srcUrl.setUrl( getDSSURL( p, m_VersionPreference[m_attempt], &m_AttemptData ) );
+    initiateSingleDownloadAttempt( srcUrl );
+}
+
+void KSDssDownloader::downloadAttemptFinished() {
+    // Check if there was an error downloading itself
+    if( m_DownloadJob->error() != 0 ) {
+        qDebug() << "Error " << m_DownloadJob->error() << " downloading DSS images!";
+        emit downloadComplete( false );
+        deleteLater();
+        return;
+    }
+
+    if( m_AttemptData.src == KSDssImage::Metadata::SDSS ) {
+        // FIXME: do SDSS-y things
+        emit downloadComplete( false );
+        deleteLater();
+        return;
+    }
+    else {
+        // Check if we have a proper DSS image or the DSS server failed
+        QMimeDatabase mdb;
+        QMimeType mt = mdb.mimeTypeForFile( m_TempFile.fileName(), QMimeDatabase::MatchContent );
+        if( mt.name().contains( "image", Qt::CaseInsensitive ) ) {
+            qDebug() << "DSS download was successful";
+            emit downloadComplete( writeImageFile() );
+            deleteLater();
+            return;
+        }
+
+        // We must have failed, try the next attempt
+        QUrl srcUrl;
+        m_attempt++;
+        if( m_attempt == m_VersionPreference.count() ) {
+            // Nothing downloaded... very strange. Fail.
+            qDebug() << "Error downloading DSS images: All alternatives failed!";
+            emit downloadComplete( false );
+            deleteLater();
+            return;
+        }
+        srcUrl.setUrl( getDSSURL( m_AttemptData.ra0, m_AttemptData.dec0, m_AttemptData.width, m_AttemptData.height,
+                                  ( ( m_AttemptData.format == KSDssImage::Metadata::FITS ) ? "fits" : "gif" ),
+                                  m_VersionPreference[ m_attempt ], &m_AttemptData ) );
+        initiateSingleDownloadAttempt( srcUrl );
+    }
+}
+
+bool KSDssDownloader::writeImageFile() {
+    // Write the temporary file into an image file with metadata
+    QImage img( m_TempFile.fileName() );
+    QImageWriter writer( m_FileName, "png" );
+    writer.setText( "Source", QString::number( KSDssImage::Metadata::DSS ) );
+    writer.setText( "Format", QString::number( KSDssImage::Metadata::PNG ) );
+    writer.setText( "Version", m_AttemptData.version );
+    writer.setText( "Object", m_AttemptData.object );
+    writer.setText( "RA", m_AttemptData.ra0.toHMSString() );
+    writer.setText( "Dec", m_AttemptData.dec0.toDMSString() );
+    writer.setText( "Width", QString::number( m_AttemptData.width ) );
+    writer.setText( "Height", QString::number( m_AttemptData.height ) );
+    writer.setText( "Band", QString() + m_AttemptData.band );
+    writer.setText( "Generation", QString::number( m_AttemptData.gen ) );
+    writer.setText( "Author", "KStars KSDssDownloader" );
+    return writer.write( img );
+}
diff --git a/kstars/auxiliary/ksdssdownloader.h b/kstars/auxiliary/ksdssdownloader.h
new file mode 100644
index 0000000..39a95b2
--- /dev/null
+++ b/kstars/auxiliary/ksdssdownloader.h
@@ -0,0 +1,114 @@
+/***************************************************************************
+                   ksdssdownloader.h  -  K Desktop Planetarium
+                             -------------------
+    begin                : Tue 05 Jan 2016 03:22:50 CST
+    copyright            : (c) 2016 by Akarsh Simha
+    email                : akarsh.simha at kdemail.net
+***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+
+
+#ifndef KSDSSDOWNLOADER_H
+#define KSDSSDOWNLOADER_H
+
+#include "ksdssimage.h"
+
+#include <KIO/Job>
+
+#include <QObject>
+#include <QString>
+#include <QStringList>
+#include <QTemporaryFile>
+
+class SkyPoint;
+class dms;
+
+/**
+ * @class KSDssDownloader
+ * @short Helps download a DSS image
+ * @author Akarsh Simha <akarsh.simha at kdemail.net>
+ *
+ * @note This object is designed to commit suicide (calls
+ * QObject::deleteLater() )! Never allocate this using anything but
+ * new -- do not allocate it on the stack! This is ideal for its
+ * operation, as it deletes itself after downloading.
+ */
+
+class KSDssDownloader : public QObject {
+
+    Q_OBJECT;
+
+ public:
+
+    /**
+     * @short Constructor
+     */
+    KSDssDownloader( const SkyPoint * const p, const QString &destFileName, QObject *parent = 0 );
+
+    /**
+     *@short High-level method to create a URL to obtain a DSS image for a given SkyPoint
+     *@note If SkyPoint is a DeepSkyObject, this method automatically
+     *decides the image size required to fit the object.
+     *@note Moved from namespace KSUtils (--asimha, Jan 5 2016)
+     *@note Avoid using these functions within KStars. Good for DBus
+     *calls and if DSS URL is to be provided to external
+     *applications. Prefer the download methods since they include
+     *metadata
+     */
+    static QString getDSSURL( const SkyPoint * const p, const QString &version = "all", struct KSDssImage::Metadata *md = 0 );
+
+    /**
+     *@short Create a URL to obtain a DSS image for a given RA, Dec
+     *@param RA The J2000.0 Right Ascension of the point
+     *@param Dec The J2000.0 Declination of the point
+     *@param width The width of the image in arcminutes
+     *@param height The height of the image in arcminutes
+     *@param version string describing which version to get
+     *@param type The image type, either gif or fits.
+     *@param md If a valid pointer is provided, fill with metadata
+     *@note This method resets height and width to fall within the range accepted by DSS
+     *@note Moved from namespace KSUtils (--asimha, Jan 5 2016)
+     *@note Avoid using these functions within KStars. Good for DBus
+     *calls and if DSS URL is to be provided to external
+     *applications. Prefer the download methods since they include
+     *metadata in the file after download.
+     *
+     *@note Valid versions are: dss1, poss2ukstu_red, poss2ukstu_ir,
+     *poss2ukstu_blue, poss1_blue, poss1_red, all, quickv,
+     *phase2_gsc2, phase2_gsc1. Of these, dss1 uses POSS1 Red in the
+     *north and POSS2/UKSTU Blue in the south. all uses the best of a
+     *combined list of all plates.
+     *
+     */
+    static QString getDSSURL( const dms &ra, const dms &dec, float width = 0, float height = 0, const QString & type_ = "gif", const QString & version_ = "all", struct KSDssImage::Metadata *md = 0 );
+
+ signals:
+     void downloadComplete( bool success );
+
+ private slots:
+     void downloadAttemptFinished();
+
+ private:
+     void startDownload( const SkyPoint * const p, const QString &destFileName );
+     void initiateSingleDownloadAttempt( QUrl srcUrl );
+     bool writeImageFile();
+
+     QStringList m_VersionPreference;
+     int m_attempt;
+     struct KSDssImage::Metadata m_AttemptData;
+     QString m_FileName;
+     QTemporaryFile m_TempFile;
+     KIO::Job *m_DownloadJob;
+
+};
+
+#endif
diff --git a/kstars/auxiliary/ksdssimage.cpp b/kstars/auxiliary/ksdssimage.cpp
new file mode 100644
index 0000000..f821134
--- /dev/null
+++ b/kstars/auxiliary/ksdssimage.cpp
@@ -0,0 +1,45 @@
+/***************************************************************************
+                     ksdssimage.cpp  -  K Desktop Planetarium
+                             -------------------
+    begin                : Tue 05 Jan 2016 00:29:22 CST
+    copyright            : (c) 2016 by Akarsh Simha
+    email                : akarsh.simha at kdemail.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+
+/* Project Includes */
+#include "ksdssimage.h"
+
+/* KDE Includes */
+
+/* Qt Includes */
+#include <QString>
+#include <QChar>
+#include <QImageReader>
+#include <QImage>
+
+KSDssImage::KSDssImage( const QString &fileName ) {
+    m_FileName = fileName;
+    QImageReader reader( m_FileName );
+    m_Metadata.src = (KSDssImage::Metadata::Source) reader.text( "Source" ).toInt();
+    m_Metadata.format = ( reader.format().toLower().contains( "png" ) ? KSDssImage::Metadata::PNG : KSDssImage::Metadata::GIF );
+    m_Metadata.version = reader.text( "Version" );
+    m_Metadata.object = reader.text( "Object" );
+    m_Metadata.ra0.setFromString( reader.text( "RA" ), false );
+    m_Metadata.dec0.setFromString( reader.text( "Dec" ), true );
+    m_Metadata.width = reader.text( "Width" ).toFloat();
+    m_Metadata.height = reader.text( "Height" ).toFloat();
+    m_Metadata.band = reader.text( "Band" ).at(0).toLatin1();
+    m_Metadata.gen = reader.text( "Generation" ).toInt();
+
+    m_Image = reader.read();
+}
diff --git a/kstars/auxiliary/ksdssimage.h b/kstars/auxiliary/ksdssimage.h
new file mode 100644
index 0000000..75aca01
--- /dev/null
+++ b/kstars/auxiliary/ksdssimage.h
@@ -0,0 +1,95 @@
+/***************************************************************************
+                          ksdssimage.h  -  K Desktop Planetarium
+                             -------------------
+    begin                : Tue 05 Jan 2016 00:24:07 CST
+    copyright            : (c) 2016 by Akarsh Simha
+    email                : akarsh at kde.org
+***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+
+
+#ifndef KSDSSIMAGE_H
+#define KSDSSIMAGE_H
+
+#include "dms.h"
+
+#include <QString>
+#include <QImage>
+
+/**
+ * @class KSDssImage
+ * @short Provides a class to hold a DSS Image along with its metadata
+ * @author Akarsh Simha <akarsh at kde.org>
+ */
+
+class KSDssImage {
+
+ public:
+
+    /**
+     * @short Constructor
+     */
+    KSDssImage( const QString &fileName );
+
+    /**
+     * @struct KSDssImage::Metadata
+     * @short Structure to hold some DSS image metadata
+     *
+     * @note Some fields in the structure are redundant. The methods
+     * that fill this structure must be designed to fill in the
+     * redundancies correctly!
+     *
+     */
+    struct Metadata {
+        /**
+         * @enum KSDssImage::Metadata::Source
+         * @short Contains possible sources for digitized sky-survey images
+         */
+        enum Source { DSS, SDSS };
+        /**
+         * @enum KSDssImage::Metadata::FileFormat
+         * @short Contains possible file formats for images
+         *
+         * @note Although DSS website provides us GIF, we may convert
+         * to PNG to incorporate metadata, since by default Qt has no
+         * write support for GIF. Besides, PNG compresses better.
+         *
+         */
+        enum FileFormat { FITS, GIF, PNG };
+
+        QString version; // Used for DSS -- Indicates which version of scans to pull
+        QString object; // Name / identifier of the object. Added to metadata
+        FileFormat format; // File format used.
+        Source src; // DSS / SDSS -- source of the image
+        dms ra0; // Center RA (J2000.0)
+        dms dec0; // Center Dec (J2000.0)
+        float height; // height in arcminutes
+        float width; // width in arcminutes
+        char band; // photometric band (UBVRI...) Use "?" for unknown.
+        int gen; // generation for DSS images, data release for SDSS; use -1 for unknown.
+    };
+
+    inline QImage getImage() const { return m_Image; }
+    inline KSDssImage::Metadata getMetadata() const { return m_Metadata; }
+    inline QString getFileName() const { return m_FileName; }
+
+    // TODO: Implement methods to load and read FITS image data and metadata
+
+ private:
+    // TODO: Add support for FITS
+    QString m_FileName;
+    QImage m_Image;
+    Metadata m_Metadata;
+
+};
+
+#endif
diff --git a/kstars/kstarsdbus.cpp b/kstars/kstarsdbus.cpp
index fcd6589..177e26b 100644
--- a/kstars/kstarsdbus.cpp
+++ b/kstars/kstarsdbus.cpp
@@ -35,7 +35,7 @@
 #include "colorscheme.h"
 #include "kstars.h"
 #include "kstarsdata.h"
-#include "ksutils.h"
+#include "ksdssdownloader.h"
 #include "skymap.h"
 #include "skyobjects/skyobject.h"
 #include "skyobjects/ksplanetbase.h"
@@ -432,13 +432,13 @@ QString KStars::getDSSURL( const QString &objectName ) {
         return QString( "ERROR" );
     }
     else {
-        return KSUtils::getDSSURL( target );
+        return KSDssDownloader::getDSSURL( target );
     }
 }
 
 QString KStars::getDSSURL( double RA_J2000, double Dec_J2000, float width, float height ) {
     dms ra( RA_J2000 ),  dec( Dec_J2000 );
-    return KSUtils::getDSSURL( ra, dec, width, height );
+    return KSDssDownloader::getDSSURL( ra, dec, width, height );
 }
 
 QString KStars::getObjectDataXML( const QString &objectName ) {
diff --git a/kstars/skymap.cpp b/kstars/skymap.cpp
index 323df7f..e88a69a 100644
--- a/kstars/skymap.cpp
+++ b/kstars/skymap.cpp
@@ -47,6 +47,7 @@
 #include "kstars.h"
 #include "kstarsdata.h"
 #include "ksutils.h"
+#include "ksdssdownloader.h"
 #include "imageviewer.h"
 #include "dialogs/detaildialog.h"
 #include "kspopupmenu.h"
@@ -444,12 +445,12 @@ void SkyMap::slotDSS() {
     //ra and dec must be the coordinates at J2000.  If we clicked on an object, just use the object's ra0, dec0 coords
     //if we clicked on empty sky, we need to precess to J2000.
     if ( clickedObject() ) {
-        urlstring = KSUtils::getDSSURL( clickedObject() );
+        urlstring = KSDssDownloader::getDSSURL( clickedObject() );
     } else {
         SkyPoint deprecessedPoint = clickedPoint()->deprecess( data->updateNum() );
         ra  = deprecessedPoint.ra();
         dec = deprecessedPoint.dec();
-        urlstring = KSUtils::getDSSURL( ra, dec ); // Use default size for non-objects
+        urlstring = KSDssDownloader::getDSSURL( ra, dec ); // Use default size for non-objects
     }
 
     QUrl url ( urlstring );
diff --git a/kstars/tools/observinglist.cpp b/kstars/tools/observinglist.cpp
index a5afbc4..8c931a8 100644
--- a/kstars/tools/observinglist.cpp
+++ b/kstars/tools/observinglist.cpp
@@ -25,6 +25,8 @@
 #include "kstars.h"
 #include "kstarsdata.h"
 #include "ksutils.h"
+#include "ksdssimage.h"
+#include "ksdssdownloader.h"
 #include "dialogs/locationdialog.h"
 #include "skyobjects/skyobject.h"
 #include "skyobjects/starobject.h"
@@ -1045,23 +1047,37 @@ void ObservingList::slotGetImage( bool _dss ) {
         setCurrentImage( currentObject(), true );
     QFile::remove( QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + CurrentImage ) ;
     QUrl url;
+    dss = true;
+    qDebug() << "FIXME: Removed support for SDSS. Until reintroduction, we will supply a DSS image";
+    /*
     if( dss ) {
         url.setUrl( DSSUrl );
     } else {
         url.setUrl( SDSSUrl );
     }
-    QUrl fileURL = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + CurrentImage);
+    */
+    KSDssDownloader *dler = new KSDssDownloader( currentObject(), QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + CurrentImage );
+    connect( dler, SIGNAL( downloadComplete( bool ) ), SLOT( downloadReady( bool ) ) );
+    /*
     downloadJob = KIO::copy ( url, fileURL ) ;
     connect ( downloadJob, SIGNAL ( result (KJob *) ), SLOT ( downloadReady() ) );
+    */
 }
 
-void ObservingList::downloadReady() {
+void ObservingList::downloadReady( bool success ) {
     // set downloadJob to 0, but don't delete it - the job will be deleted automatically
-    downloadJob = 0;
-    if( QFile( QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + CurrentImage ).size() > 13000)
-    {//The default image is around 8689 bytes
+    //    downloadJob = 0;
+    if( !success ) {
+        KMessageBox::sorry(0, i18n( "Failed to download DSS/SDSS image!" ) );
+    }
+    else {
+
+        /*
+          if( QFile( QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + CurrentImage ).size() > 13000)
+          //The default image is around 8689 bytes
+        */
         CurrentImagePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + CurrentImage;
-        ui->ImagePreview->showPreview( QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + CurrentImage ) ) ;
+        ui->ImagePreview->showPreview( QUrl::fromLocalFile( CurrentImagePath ) );
         saveThumbImage();
         ui->ImagePreview->show();
         ui->ImagePreview->setCursor( Qt::PointingHandCursor );
@@ -1071,8 +1087,11 @@ void ObservingList::downloadReady() {
         }
         ui->DeleteImage->setEnabled( true );
     }
+    /*
+    // FIXME: Implement a priority order SDSS > DSS in the DSS downloader
     else if( ! dss )
         slotGetImage( true );
+    */
 }
 
 void ObservingList::setCurrentImage( const SkyObject *o, bool temp  ) {
@@ -1097,7 +1116,7 @@ void ObservingList::setCurrentImage( const SkyObject *o, bool temp  ) {
     }
     CurrentImagePath = QStandardPaths::locate( QStandardPaths::DataLocation , CurrentImage );
     CurrentTempPath = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + "Temp_" + CurrentImage ; // FIXME: Eh? -- asimha
-    DSSUrl = KSUtils::getDSSURL( o );
+    DSSUrl = KSDssDownloader::getDSSURL( o );
     QString UrlPrefix("http://casjobs.sdss.org/ImgCutoutDR6/getjpeg.aspx?"); // FIXME: Upgrade to use SDSS Data Release 9 / 10. DR6 is well outdated.
     QString UrlSuffix("&scale=1.0&width=600&height=600&opt=GST&query=SR(10,20)");
 
diff --git a/kstars/tools/observinglist.h b/kstars/tools/observinglist.h
index a20dd10..aa2a27a 100644
--- a/kstars/tools/observinglist.h
+++ b/kstars/tools/observinglist.h
@@ -349,7 +349,7 @@ public slots:
 
 protected slots:
     void slotClose();
-    void downloadReady();
+    void downloadReady( bool success );
 
 private:
 


More information about the Kstars-devel mailing list