Commit 99dffed8 authored by Jérome SONRIER's avatar Jérome SONRIER
Browse files

Add menu entry to update comets.dat file.

CCMAIL: kstars-devel@kde.org
CCBUG: 254573
parent 509a33ae
......@@ -579,6 +579,9 @@ private slots:
void slotExecute();
/**Update comets orbital elements*/
void slotUpdateComets();
private:
/** Load FOV information and repopulate menu. */
void repopulateFOV();
......
......@@ -89,6 +89,8 @@
#include "skycomponents/customcatalogcomponent.h"
#include "skycomponents/skymapcomposite.h"
#include "skycomponents/solarsystemcomposite.h"
#include "skycomponents/cometscomponent.h"
#ifdef HAVE_CFITSIO_H
#include "fitsviewer/fitsviewer.h"
......@@ -1029,3 +1031,7 @@ void KStars::slotShowPositionBar(SkyPoint* p ) {
statusBar()->changeItem( s, 2 );
}
}
void KStars::slotUpdateComets() {
data()->skyComposite()->solarSystemComposite()->cometsComponent()->updateDataFile();
}
......@@ -335,6 +335,10 @@ void KStars::initActions() {
<< i18n("Startup Wizard..." )
<< KIcon("tools-wizard" );
// Updates actions
actionCollection()->addAction( "update_comets", this, SLOT( slotUpdateComets() ) )
<< i18n( "Update comets orbital elements" );
//Tools Menu:
actionCollection()->addAction("astrocalculator", this, SLOT( slotCalculator() ) )
<< i18n("Calculator...")
......
......@@ -97,6 +97,10 @@
<Action name="fovsymbols" /> <!-- This is a KMenuAction-->
<Action name="opengl" />
<Separator />
<Menu name="updates"><text>&amp;Updates</text>
<Action name="update_comets" />
</Menu>
<Separator />
<Action name="ewriter"/>
<Action name="obsadd"/>
<Separator />
......
......@@ -93,6 +93,10 @@
<Action name="fovsymbols" /> <!-- This is a KMenuAction-->
<Action name="opengl" />
<Separator />
<Menu name="updates"><text>&amp;Updates</text>
<Action name="update_comets" />
</Menu>
<Separator />
<Action name="ewriter"/>
<Action name="obsadd"/>
<Separator />
......
......@@ -89,6 +89,10 @@
<Action name="fovsymbols" /> <!-- This is a KMenuAction-->
<Action name="opengl" />
<Separator />
<Menu name="updates"><text>&amp;Updates</text>
<Action name="update_comets" />
</Menu>
<Separator />
<Action name="ewriter"/>
<Action name="obsadd"/>
<Separator />
......
......@@ -31,6 +31,10 @@
#include "skylabeler.h"
#include "skypainter.h"
#include "projections/projector.h"
#include <kio/job.h>
#include <kio/netaccess.h>
#include <kio/jobuidelegate.h>
#include <kstandarddirs.h>
CometsComponent::CometsComponent( SolarSystemComposite *parent )
: SolarSystemListComponent( parent )
......@@ -70,6 +74,10 @@ void CometsComponent::loadData() {
if ( KSUtils::openDataFile( file, "comets.dat" ) ) {
emitProgressText( i18n("Loading comets") );
// Clear lists
m_ObjectList.clear();
objectNames( SkyObject::COMET ).clear();
KSFileReader fileReader( file );
while( fileReader.hasMoreLines() ) {
QString line, name;
......@@ -135,3 +143,33 @@ void CometsComponent::draw( SkyPainter *skyp )
SkyLabeler::AddLabel( com, SkyLabeler::COMET_LABEL );
}
}
void CometsComponent::updateDataFile()
{
KUrl url = KUrl( "http://ssd.jpl.nasa.gov/sbdb_query.cgi" );
QByteArray post_data = QByteArray( "obj_group=all&obj_kind=com&obj_numbered=all&OBJ_field=0&OBJ_op=0&OBJ_value=&ORB_field=0&ORB_op=0&ORB_value=&combine_mode=AND&c1_group=OBJ&c1_item=Af&c1_op=!%3D&c1_value=D&c2_group=OBJ&c2_item=Ae&c2_op=!%3D&c2_value=SOHO&c_fields=AcBdBiBgBjBlBkBqBbAiAjAgAkAlApAqArAsBsBtCh&table_format=CSV&max_rows=10&format_option=full&query=Generate%20Table&.cgifields=format_option&.cgifields=field_list&.cgifields=obj_kind&.cgifields=obj_group&.cgifields=obj_numbered&.cgifields=combine_mode&.cgifields=ast_orbit_class&.cgifields=table_format&.cgifields=ORB_field_set&.cgifields=OBJ_field_set&.cgifields=preset_field_set&.cgifields=com_orbit_class" );
QString content_type = "Content-Type: application/x-www-form-urlencoded";
// Download file
KIO::StoredTransferJob* get_job = KIO::storedHttpPost( post_data, url );
get_job->addMetaData("content-type", content_type );
if( KIO::NetAccess::synchronousRun( get_job, 0 ) ) {
// Comment the first line
QByteArray data = get_job->data();
data.insert( 0, '#' );
// Write data to comets.dat
QFile file( KStandardDirs::locateLocal( "appdata", "comets.dat" ) );
file.open( QIODevice::WriteOnly|QIODevice::Truncate|QIODevice::Text );
file.write( data );
file.close();
// Reload comets
loadData();
KStars::Instance()->data()->setFullTimeUpdate();
} else {
get_job->ui()->showErrorMessage();
}
}
......@@ -40,6 +40,7 @@ public:
virtual ~CometsComponent();
virtual bool selected();
virtual void draw( SkyPainter *skyp );
void updateDataFile();
private:
void loadData();
};
......
......@@ -528,4 +528,9 @@ SatellitesComponent* SkyMapComposite::satellites() {
return m_Satellites;
}
SolarSystemComposite* SkyMapComposite::solarSystemComposite()
{
return m_SolarSystem;
}
#include "skymapcomposite.moc"
......@@ -190,6 +190,8 @@ public:
ConstellationBoundaryLines* getConstellationBoundary() { return m_CBoundLines; }
inline TargetListComponent *getStarHopRouteList() { return m_StarHopRouteList; }
SolarSystemComposite *solarSystemComposite();
signals:
void progressText( const QString &message );
......
......@@ -118,3 +118,9 @@ const QList<SkyObject*>& SolarSystemComposite::asteroids() const {
const QList<SkyObject*>& SolarSystemComposite::comets() const {
return m_CometsComponent->objectList();
}
CometsComponent* SolarSystemComposite::cometsComponent()
{
return m_CometsComponent;
}
......@@ -58,6 +58,8 @@ public:
void drawTrails( SkyPainter *skyp );
CometsComponent* cometsComponent();
private:
KSPlanet *m_Earth;
KSSun *m_Sun;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment