[Kstars-devel] [kstars] kstars: Add menu entry to update asteroids.dat file.

Jérome SONRIER jsid at emor3j.fr.eu.org
Mon Apr 18 03:14:11 CEST 2011


Git commit 8883e80595c386b97548450989118c37c54be1da by Jérome SONRIER.
Committed on 18/04/2011 at 01:01.
Pushed by jsonrier into branch 'master'.

Add menu entry to update asteroids.dat file.

CCMAIL: kstars-devel at kde.org

M  +3    -0    kstars/kstars.h     
M  +5    -0    kstars/kstarsactions.cpp     
M  +2    -0    kstars/kstarsinit.cpp     
M  +1    -0    kstars/kstarsui-indi.rc     
M  +1    -0    kstars/kstarsui-win.rc     
M  +1    -0    kstars/kstarsui.rc     
M  +34   -0    kstars/skycomponents/asteroidscomponent.cpp     
M  +1    -0    kstars/skycomponents/asteroidscomponent.h     
M  +4    -0    kstars/skycomponents/solarsystemcomposite.cpp     
M  +2    -0    kstars/skycomponents/solarsystemcomposite.h     

http://commits.kde.org/kstars/8883e80595c386b97548450989118c37c54be1da

diff --git a/kstars/kstars.h b/kstars/kstars.h
index 06fc805..1d9d3dc 100644
--- a/kstars/kstars.h
+++ b/kstars/kstars.h
@@ -582,6 +582,9 @@ private slots:
     /**Update comets orbital elements*/
     void slotUpdateComets();
 
+    /**Update asteroids orbital elements*/
+    void slotUpdateAsteroids();
+
 private:
     /** Load FOV information and repopulate menu. */
     void repopulateFOV();
diff --git a/kstars/kstarsactions.cpp b/kstars/kstarsactions.cpp
index f5658ea..51bc9de 100644
--- a/kstars/kstarsactions.cpp
+++ b/kstars/kstarsactions.cpp
@@ -91,6 +91,7 @@
 #include "skycomponents/skymapcomposite.h"
 #include "skycomponents/solarsystemcomposite.h"
 #include "skycomponents/cometscomponent.h"
+#include "skycomponents/asteroidscomponent.h"
 
 #ifdef HAVE_CFITSIO_H
 #include "fitsviewer/fitsviewer.h"
@@ -1035,3 +1036,7 @@ void KStars::slotShowPositionBar(SkyPoint* p ) {
 void KStars::slotUpdateComets() {
     data()->skyComposite()->solarSystemComposite()->cometsComponent()->updateDataFile();
 }
+
+void KStars::slotUpdateAsteroids() {
+    data()->skyComposite()->solarSystemComposite()->asteroidsComponent()->updateDataFile();
+}
diff --git a/kstars/kstarsinit.cpp b/kstars/kstarsinit.cpp
index 0895cc1..c76d2f0 100644
--- a/kstars/kstarsinit.cpp
+++ b/kstars/kstarsinit.cpp
@@ -338,6 +338,8 @@ void KStars::initActions() {
     // Updates actions
     actionCollection()->addAction( "update_comets", this, SLOT( slotUpdateComets() ) )
         << i18n( "Update comets orbital elements" );
+    actionCollection()->addAction( "update_asteroids", this, SLOT( slotUpdateAsteroids() ) )
+        << i18n( "Update asteroids orbital elements" );
 
     //Tools Menu:
     actionCollection()->addAction("astrocalculator", this, SLOT( slotCalculator() ) )
diff --git a/kstars/kstarsui-indi.rc b/kstars/kstarsui-indi.rc
index 88fa1c2..bf6d215 100644
--- a/kstars/kstarsui-indi.rc
+++ b/kstars/kstarsui-indi.rc
@@ -99,6 +99,7 @@
 		<Separator />
         <Menu name="updates"><text>&amp;Updates</text>
             <Action name="update_comets" />
+            <Action name="update_asteroids" />
         </Menu>
 		<Separator />
         <Action name="ewriter"/>
diff --git a/kstars/kstarsui-win.rc b/kstars/kstarsui-win.rc
index 38f7865..1f70cf5 100644
--- a/kstars/kstarsui-win.rc
+++ b/kstars/kstarsui-win.rc
@@ -95,6 +95,7 @@
 		<Separator />
 		<Menu name="updates"><text>&amp;Updates</text>
             <Action name="update_comets" />
+            <Action name="update_asteroids" />
         </Menu>
         <Separator />
         <Action name="ewriter"/>
diff --git a/kstars/kstarsui.rc b/kstars/kstarsui.rc
index 472a8b7..9345e43 100644
--- a/kstars/kstarsui.rc
+++ b/kstars/kstarsui.rc
@@ -91,6 +91,7 @@
 		<Separator />
 		<Menu name="updates"><text>&amp;Updates</text>
             <Action name="update_comets" />
+            <Action name="update_asteroids" />
         </Menu>
 		<Separator />
         <Action name="ewriter"/>
diff --git a/kstars/skycomponents/asteroidscomponent.cpp b/kstars/skycomponents/asteroidscomponent.cpp
index 1f0912b..dc170fb 100644
--- a/kstars/skycomponents/asteroidscomponent.cpp
+++ b/kstars/skycomponents/asteroidscomponent.cpp
@@ -19,6 +19,10 @@
 
 #include <QPen>
 #include <kglobal.h>
+#include <kio/job.h>
+#include <kio/netaccess.h>
+#include <kio/jobuidelegate.h>
+#include <kstandarddirs.h>
 
 #include "skycomponent.h"
 
@@ -33,6 +37,7 @@
 #include "skypainter.h"
 #include "projections/projector.h"
 
+
 AsteroidsComponent::AsteroidsComponent(SolarSystemComposite *parent ) :
     SolarSystemListComponent(parent)
 {
@@ -163,3 +168,32 @@ SkyObject* AsteroidsComponent::objectNearest( SkyPoint *p, double &maxrad ) {
     return oBest;
 }
 
+void AsteroidsComponent::updateDataFile()
+{
+    KUrl url = KUrl( "http://ssd.jpl.nasa.gov/sbdb_query.cgi" );
+    QByteArray post_data = QByteArray( "obj_group=all&obj_kind=ast&obj_numbered=num&OBJ_field=0&ORB_field=0&c1_group=OBJ&c1_item=Ai&c1_op=%3C&c1_value=12&c_fields=AcBdBhBgBjBlBkBmBqBbAiAjAgAkAlApAqArAsBsBtCh&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 asteroids.dat
+        QFile file( KStandardDirs::locateLocal( "appdata", "asteroids.dat" ) );
+        file.open( QIODevice::WriteOnly|QIODevice::Truncate|QIODevice::Text );
+        file.write( data );
+        file.close();
+
+        // Reload asteroids
+        loadData();
+
+        KStars::Instance()->data()->setFullTimeUpdate();
+    } else {
+        get_job->ui()->showErrorMessage();
+    }
+}
diff --git a/kstars/skycomponents/asteroidscomponent.h b/kstars/skycomponents/asteroidscomponent.h
index e47b5ab..da3d589 100644
--- a/kstars/skycomponents/asteroidscomponent.h
+++ b/kstars/skycomponents/asteroidscomponent.h
@@ -40,6 +40,7 @@ public:
     virtual void draw( SkyPainter *skyp );
     virtual bool selected();
     virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+    void updateDataFile();
 private:
     void loadData();
 };
diff --git a/kstars/skycomponents/solarsystemcomposite.cpp b/kstars/skycomponents/solarsystemcomposite.cpp
index 31441ea..426e838 100644
--- a/kstars/skycomponents/solarsystemcomposite.cpp
+++ b/kstars/skycomponents/solarsystemcomposite.cpp
@@ -124,3 +124,7 @@ CometsComponent* SolarSystemComposite::cometsComponent()
     return m_CometsComponent;
 }
 
+AsteroidsComponent* SolarSystemComposite::asteroidsComponent()
+{
+    return m_AsteroidsComponent;
+}
diff --git a/kstars/skycomponents/solarsystemcomposite.h b/kstars/skycomponents/solarsystemcomposite.h
index f39b729..ad8462c 100644
--- a/kstars/skycomponents/solarsystemcomposite.h
+++ b/kstars/skycomponents/solarsystemcomposite.h
@@ -60,6 +60,8 @@ public:
 
     CometsComponent* cometsComponent();
 
+    AsteroidsComponent* asteroidsComponent();
+
 private:
     KSPlanet *m_Earth;
     KSSun *m_Sun;



More information about the Kstars-devel mailing list