[kstars] kstars/tools: Make images and thumbnail names consistent. Now full-scale images are named image-* and thumbnail are thumb-* and all are appended with .png from the get-go. This would _break_ downloaded existing images for users, but it is a good long term stable solution.
Jasem Mutlaq
null at kde.org
Fri Apr 14 09:26:26 UTC 2017
Git commit 1dd2945c5418cd2ed59008dff4768f208d1aa199 by Jasem Mutlaq.
Committed on 14/04/2017 at 09:24.
Pushed by mutlaqja into branch 'master'.
Make images and thumbnail names consistent. Now full-scale images are named image-* and thumbnail are thumb-* and all are appended with .png from the get-go. This would _break_ downloaded existing images for users, but it is a good long term stable solution.
CCMAIL:kstars-devel at kde.org
M +32 -24 kstars/tools/observinglist.cpp
M +1 -1 kstars/tools/observinglist.h
M +2 -2 kstars/tools/whatsinteresting/skyobjitem.cpp
https://commits.kde.org/kstars/1dd2945c5418cd2ed59008dff4768f208d1aa199
diff --git a/kstars/tools/observinglist.cpp b/kstars/tools/observinglist.cpp
index cdcaa6f69..28a1b8aa8 100644
--- a/kstars/tools/observinglist.cpp
+++ b/kstars/tools/observinglist.cpp
@@ -628,13 +628,7 @@ void ObservingList::slotNewSelection()
ui->NotesEdit->setEnabled( false );
ui->SearchImage->setEnabled( false );
}
- QString ImagePath = getCurrentImagePath();
- if( QFile::exists( getCurrentImagePath() ) )
- {
- ;
- }
- else
- ImagePath = QString();
+ QString ImagePath = KSPaths::locate( QStandardPaths::GenericDataLocation , m_currentImageFileName );
if( !ImagePath.isEmpty() )
{
//If the image is present, show it!
@@ -1375,9 +1369,28 @@ void ObservingList::downloadReady( bool success )
void ObservingList::setCurrentImage( const SkyObject * o )
{
- QString sanitizedName = o->name().remove(' ').remove( '\'' ).remove( '\"' );
- m_currentImageFileName = "Image_" + sanitizedName;
- ThumbImage = "thumb-" + sanitizedName.toLower() + ".png";
+ QString sanitizedName = o->name().remove(' ').remove( '\'' ).remove( '\"' ).toLower();
+
+ // JM: Always use .png across all platforms. No JPGs at all?
+ m_currentImageFileName = "image-" + sanitizedName + ".png";
+
+ m_currentThumbImageFileName = "thumb-" + sanitizedName + ".png";
+
+ // Does full image exists in the path?
+ QString currentImagePath = KSPaths::locate( QStandardPaths::GenericDataLocation , m_currentImageFileName );
+
+ // Let's try to fallback to thumb-* images if they exist
+ if (currentImagePath.isEmpty())
+ {
+ currentImagePath = KSPaths::locate( QStandardPaths::GenericDataLocation , m_currentThumbImageFileName);
+
+ // If thumb image exists, let's use it
+ if (currentImagePath.isEmpty() == false)
+ m_currentImageFileName = m_currentThumbImageFileName;
+ }
+
+ // 2017-04-14: Unnamed stars already unsupported in observing list
+ /*
if( o->name() == "star" )
{
QString RAString( o->ra0().toHMSString() );
@@ -1387,21 +1400,17 @@ void ObservingList::setCurrentImage( const SkyObject * o )
// QChar decsgn = ( (o->dec0().Degrees() < 0.0 ) ? '-' : '+' );
// m_currentImageFileName = m_currentImageFileName.remove('+').remove('-') + decsgn;
}
- QString imagePath;
- if ( QFile::exists( imagePath = getCurrentImagePath() ) ) // New convention -- append filename extension so file is usable on Windows etc.
+ */
+
+ // 2017-04-14 JM: If we use .png always, let us use it across all platforms.
+ /*
+ QString imagePath = getCurrentImagePath();
+ if ( QFile::exists( imagePath)) // New convention -- append filename extension so file is usable on Windows etc.
{
QFile::rename( imagePath, imagePath + ".png" );
}
m_currentImageFileName += ".png";
- // 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)");
-
- // QString RA, Dec;
- // RA = RA.sprintf( "ra=%f", o->ra0().Degrees() );
- // Dec = Dec.sprintf( "&dec=%f", o->dec0().Degrees() );
-
- // SDSSUrl = UrlPrefix + RA + Dec + UrlSuffix;
+ */
}
QString ObservingList::getCurrentImagePath()
@@ -1413,7 +1422,6 @@ QString ObservingList::getCurrentImagePath()
}
else
return ( KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + m_currentImageFileName );
-
}
void ObservingList::slotSaveAllImages()
@@ -1594,11 +1602,11 @@ void ObservingList::slotDeleteCurrentImage()
void ObservingList::saveThumbImage()
{
- if( ! QFile::exists( KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + ThumbImage ) )
+ if( ! QFile::exists( KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + m_currentThumbImageFileName ) )
{
QImage img( getCurrentImagePath() );
img = img.scaled( 200, 200, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
- img.save( KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + ThumbImage ) ;
+ img.save( KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + m_currentThumbImageFileName ) ;
}
}
diff --git a/kstars/tools/observinglist.h b/kstars/tools/observinglist.h
index c1ea3ad63..69e1aa06c 100644
--- a/kstars/tools/observinglist.h
+++ b/kstars/tools/observinglist.h
@@ -441,7 +441,7 @@ class ObservingList : public QDialog
QList<QSharedPointer<SkyObject>> m_WishList, m_SessionList;
SkyObject * LogObject, *m_CurrentObject;
bool isModified, bIsLarge, sessionView, dss, singleSelection, showScope, noSelection;
- QString m_listFileName, m_currentImageFileName, ThumbImage;
+ QString m_listFileName, m_currentImageFileName, m_currentThumbImageFileName;
KStarsDateTime dt;
GeoLocation * geo;
QStandardItemModel * m_WishListModel, *m_SessionModel;
diff --git a/kstars/tools/whatsinteresting/skyobjitem.cpp b/kstars/tools/whatsinteresting/skyobjitem.cpp
index 870212b28..425f77129 100644
--- a/kstars/tools/whatsinteresting/skyobjitem.cpp
+++ b/kstars/tools/whatsinteresting/skyobjitem.cpp
@@ -120,7 +120,7 @@ QString SkyObjItem::getImageURL(bool preferThumb) const
return "";
}
QString thumbName = KSPaths::locate(QStandardPaths::GenericDataLocation, "thumb-" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
- QString fullSizeName = KSPaths::locate(QStandardPaths::GenericDataLocation, "Image_" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
+ QString fullSizeName = KSPaths::locate(QStandardPaths::GenericDataLocation, "image-" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
//First try to return the preferred file
if(thumbName!=""&&preferThumb)
@@ -129,7 +129,7 @@ QString SkyObjItem::getImageURL(bool preferThumb) const
return fullSizeName;
//If that fails, try to return the large image first, then the thumb and then if it is a planet, the xplanet image.
- QString fname = KSPaths::locate(QStandardPaths::GenericDataLocation, "Image_" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
+ QString fname = KSPaths::locate(QStandardPaths::GenericDataLocation, "image-" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
if(fname=="")
fname = KSPaths::locate(QStandardPaths::GenericDataLocation, "thumb-" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
if(fname=="" && m_Type==Planet){
More information about the Kstars-devel
mailing list