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

Jérome SONRIER jsid at emor3j.fr.eu.org
Sun Apr 17 03:21:18 CEST 2011


Git commit 99dffed883213ae4354a5a07e6ba65b868f86fa5 by Jérome SONRIER.
Committed on 12/04/2011 at 19:46.
Pushed by jsonrier into branch 'master'.

Add menu entry to update comets.dat file.

CCMAIL: kstars-devel at kde.org
CCBUG: 254573

M  +3    -0    kstars/kstars.h     
M  +6    -0    kstars/kstarsactions.cpp     
M  +4    -0    kstars/kstarsinit.cpp     
M  +4    -0    kstars/kstarsui-indi.rc     
M  +4    -0    kstars/kstarsui-win.rc     
M  +4    -0    kstars/kstarsui.rc     
M  +38   -0    kstars/skycomponents/cometscomponent.cpp     
M  +1    -0    kstars/skycomponents/cometscomponent.h     
M  +5    -0    kstars/skycomponents/skymapcomposite.cpp     
M  +2    -0    kstars/skycomponents/skymapcomposite.h     
M  +6    -0    kstars/skycomponents/solarsystemcomposite.cpp     
M  +2    -0    kstars/skycomponents/solarsystemcomposite.h     

http://commits.kde.org/kstars/99dffed883213ae4354a5a07e6ba65b868f86fa5

diff --git a/kstars/kstars.h b/kstars/kstars.h
index 099f0c3..06fc805 100644
--- a/kstars/kstars.h
+++ b/kstars/kstars.h
@@ -579,6 +579,9 @@ private slots:
 
     void slotExecute();
 
+    /**Update comets orbital elements*/
+    void slotUpdateComets();
+
 private:
     /** Load FOV information and repopulate menu. */
     void repopulateFOV();
diff --git a/kstars/kstarsactions.cpp b/kstars/kstarsactions.cpp
index ae42857..f5658ea 100644
--- a/kstars/kstarsactions.cpp
+++ b/kstars/kstarsactions.cpp
@@ -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();
+}
diff --git a/kstars/kstarsinit.cpp b/kstars/kstarsinit.cpp
index f2b1b1a..0895cc1 100644
--- a/kstars/kstarsinit.cpp
+++ b/kstars/kstarsinit.cpp
@@ -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...")
diff --git a/kstars/kstarsui-indi.rc b/kstars/kstarsui-indi.rc
index ada7945..88fa1c2 100644
--- a/kstars/kstarsui-indi.rc
+++ b/kstars/kstarsui-indi.rc
@@ -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 />
diff --git a/kstars/kstarsui-win.rc b/kstars/kstarsui-win.rc
index b1c387e..38f7865 100644
--- a/kstars/kstarsui-win.rc
+++ b/kstars/kstarsui-win.rc
@@ -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 />
diff --git a/kstars/kstarsui.rc b/kstars/kstarsui.rc
index dd583e0..472a8b7 100644
--- a/kstars/kstarsui.rc
+++ b/kstars/kstarsui.rc
@@ -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 />
diff --git a/kstars/skycomponents/cometscomponent.cpp b/kstars/skycomponents/cometscomponent.cpp
index ef9a605..1fa539b 100644
--- a/kstars/skycomponents/cometscomponent.cpp
+++ b/kstars/skycomponents/cometscomponent.cpp
@@ -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();
+    }
+}
diff --git a/kstars/skycomponents/cometscomponent.h b/kstars/skycomponents/cometscomponent.h
index 7269c05..f682629 100644
--- a/kstars/skycomponents/cometscomponent.h
+++ b/kstars/skycomponents/cometscomponent.h
@@ -40,6 +40,7 @@ public:
     virtual ~CometsComponent();
     virtual bool selected();
     virtual void draw( SkyPainter *skyp );
+    void updateDataFile();
 private:
     void loadData();
 };
diff --git a/kstars/skycomponents/skymapcomposite.cpp b/kstars/skycomponents/skymapcomposite.cpp
index 47a0391..82fef8a 100644
--- a/kstars/skycomponents/skymapcomposite.cpp
+++ b/kstars/skycomponents/skymapcomposite.cpp
@@ -528,4 +528,9 @@ SatellitesComponent* SkyMapComposite::satellites() {
     return m_Satellites;
 }
 
+SolarSystemComposite* SkyMapComposite::solarSystemComposite()
+{
+    return m_SolarSystem;
+}
+
 #include "skymapcomposite.moc"
diff --git a/kstars/skycomponents/skymapcomposite.h b/kstars/skycomponents/skymapcomposite.h
index cd32655..adf496d 100644
--- a/kstars/skycomponents/skymapcomposite.h
+++ b/kstars/skycomponents/skymapcomposite.h
@@ -190,6 +190,8 @@ public:
     ConstellationBoundaryLines* getConstellationBoundary() { return m_CBoundLines; }
     inline TargetListComponent *getStarHopRouteList() { return m_StarHopRouteList; }
 
+    SolarSystemComposite *solarSystemComposite();
+
 signals:
     void progressText( const QString &message );
 
diff --git a/kstars/skycomponents/solarsystemcomposite.cpp b/kstars/skycomponents/solarsystemcomposite.cpp
index 91fec7a..31441ea 100644
--- a/kstars/skycomponents/solarsystemcomposite.cpp
+++ b/kstars/skycomponents/solarsystemcomposite.cpp
@@ -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;
+}
+
diff --git a/kstars/skycomponents/solarsystemcomposite.h b/kstars/skycomponents/solarsystemcomposite.h
index 2948bd1..f39b729 100644
--- a/kstars/skycomponents/solarsystemcomposite.h
+++ b/kstars/skycomponents/solarsystemcomposite.h
@@ -58,6 +58,8 @@ public:
 
     void drawTrails( SkyPainter *skyp );
 
+    CometsComponent* cometsComponent();
+
 private:
     KSPlanet *m_Earth;
     KSSun *m_Sun;



More information about the Kstars-devel mailing list