• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

ksnewstuff.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           ksnewstuff.cpp  -  description
00003                              -------------------
00004     begin                : Wed 21 May 2004
00005     copyright            : (C) 2004 by Jason Harris
00006     email                : kstars@30doradus.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <kdeversion.h>
00019 #if KDE_IS_VERSION( 3, 2, 90 )
00020 
00021 #include <kapplication.h>
00022 #include <kaction.h>
00023 #include <kdebug.h>
00024 #include <kglobal.h>
00025 #include <kstandarddirs.h>
00026 #include <kdirwatch.h>
00027 #include <kprogress.h>
00028 #include <ktar.h>
00029 #include <qdir.h>
00030 #include <qcursor.h>
00031 #include <qregexp.h>
00032 
00033 #include "ksnewstuff.h"
00034 #include "kstars.h"
00035 #include "kstarsdata.h"
00036 #include "deepskyobject.h"
00037 #include "objectnamelist.h"
00038 #include "skymap.h"
00039 
00040 KSNewStuff::KSNewStuff( QWidget *parent ) :
00041   QObject(), KNewStuff( "kstars", parent ), NGCUpdated( false )
00042 {
00043     ks = (KStars*)parent;
00044     kdw = new KDirWatch( this );
00045     kdw->addDir( KGlobal::dirs()->saveLocation("data", kapp->instanceName(), true) );
00046 }
00047 
00048 bool KSNewStuff::install( const QString &fileName )
00049 {
00050     kdDebug() << "KSNewStuff::install(): " << fileName << endl;
00051     
00052     KTar archive( fileName );
00053     if ( !archive.open( IO_ReadOnly ) )
00054             return false;
00055     
00056     const KArchiveDirectory *archiveDir = archive.directory();
00057     const QString destDir = KGlobal::dirs()->saveLocation("data", kapp->instanceName(), true);      
00058     KStandardDirs::makeDir( destDir );
00059 
00060     //monitor destDir for changes; inform updateData when files are created.
00061     connect( kdw, SIGNAL( dirty( const QString & ) ), this, SLOT( updateData( const QString & ) ) );
00062 
00063     archiveDir->copyTo(destDir);
00064     archive.close();
00065     kapp->processEvents(10000);
00066     
00067     //read the new data into the program
00068     //this return might be the result of checking if everything is installed ok
00069     return true;
00070 }
00071 
00072 void KSNewStuff::updateData( const QString &path ) {
00073     QDir qd( path );
00074     qd.setSorting( QDir::Time );
00075     qd.setFilter( QDir::Files );
00076 
00077     //Show the Wait cursor
00078     ks->setCursor(QCursor(Qt::WaitCursor));
00079     
00080     
00081     //Handle the Steinicke NGC/IC catalog
00082     if ( !NGCUpdated && qd[0].contains( "ngcic" ) ) {
00083         //Build a progress dialog to show during data installation.
00084         KProgressDialog prog( 0, "newstuffprogdialog", 
00085                 i18n( "Please Wait" ), i18n( "Installing Steinicke NGC/IC catalog..." ), false /*modal*/ );
00086         prog.setAllowCancel( false );
00087         prog.setMinimumDuration( 0 /*millisec*/ );
00088         prog.progressBar()->setTotalSteps( 0 );  //show generic progress activity
00089         prog.show();
00090         kapp->processEvents(1000);
00091         
00092         //First, remove the existing NGC/IC objects from the ObjectNameList.
00093         for ( DeepSkyObject *o = ks->data()->deepSkyList.first(); o; o = ks->data()->deepSkyList.next() ) {
00094             if ( o->hasLongName() && o->longname() != o->name() ) ks->data()->ObjNames.remove( o->longname() );
00095             ks->data()->ObjNames.remove( o->name() );
00096         }
00097         
00098         //We can safely clear the Messier/NGC/IC/Other lists, since their pointers are secondary
00099         ks->data()->deepSkyListMessier.clear();
00100         ks->data()->deepSkyListNGC.clear();
00101         ks->data()->deepSkyListIC.clear();
00102         ks->data()->deepSkyListOther.clear();
00103         
00104         //Finally, we can clear deepSkyList.  This will automatically delete the SkyObjects
00105         ks->data()->deepSkyList.clear();
00106         
00107         //Send progress messages to the console
00108         connect( ks->data(), SIGNAL( progressText(QString) ), ks->data(), SLOT( slotConsoleMessage(QString) ) );
00109         connect( ks->data(), SIGNAL( progressText(QString) ), ks->data(), SLOT( slotProcessEvents() ) );
00110         
00111         //We are now ready to read the new NGC/IC catalog
00112         ks->data()->readDeepSkyData();
00113         
00114         //Avoid redundant installs
00115         NGCUpdated = true;
00116 
00117         //Re-assign image/info links.  3rd param means deep-sky objects only
00118         ks->data()->readURLData( "image_url.dat", 0, true ); 
00119         ks->data()->readURLData( "info_url.dat", 1, true ); 
00120         
00121         ks->data()->setFullTimeUpdate();
00122         ks->data()->updateTime( ks->geo(), ks->map() );
00123         ks->map()->forceUpdate();
00124     }
00125     
00126     //Handle the inline Messier images
00127     // **No action required**
00128     
00129     //Handle the ephemerides
00130     if ( qd[0] == "asteroids.dat" || qd[0] == "comets.dat" ) {
00131         //Build a progress dialog to show during data installation.
00132         KProgressDialog prog( 0, "newstuffprogdialog", 
00133                 i18n( "Please Wait" ), i18n( "Installing comet and asteroid ephemerides..." ), true /*modal*/ );
00134         prog.setAllowCancel( false );
00135         prog.setMinimumDuration( 50 /*millisec*/ );
00136         prog.progressBar()->setTotalSteps( 0 );  //generic progress activity
00137         
00138         //First, remove the existing asteroids and comets from the ObjectNameList.
00139         for ( SkyObject *o = (SkyObject*)(ks->data()->asteroidList.first()); o; o = (SkyObject*)(ks->data()->asteroidList.next()) ) {
00140             if ( o->hasLongName() && o->longname() != o->name() ) ks->data()->ObjNames.remove( o->longname() );
00141             ks->data()->ObjNames.remove( o->name() );
00142         }
00143         for ( SkyObject *o = (SkyObject*)(ks->data()->cometList.first()); o; o = (SkyObject*)(ks->data()->cometList.next()) ) {
00144             if ( o->hasLongName() && o->longname() != o->name() ) ks->data()->ObjNames.remove( o->longname() );
00145             ks->data()->ObjNames.remove( o->name() );
00146         }
00147         
00148         //Clear the asteroids and comets lists
00149         ks->data()->asteroidList.clear();
00150         ks->data()->cometList.clear();
00151         
00152         //Send progress messages to the console
00153         connect( ks->data(), SIGNAL( progressText(QString) ), ks->data(), SLOT( slotConsoleMessage(QString) ) );
00154         
00155         //add new asteroids and comets
00156         ks->data()->readAsteroidData();
00157         ks->data()->readCometData();
00158 
00159         //Do a full update
00160         ks->data()->setFullTimeUpdate();
00161         ks->data()->updateTime( ks->geo(), ks->map() );
00162         ks->map()->forceUpdate();
00163     }
00164 
00165     //Restore arrow cursor
00166     ks->setCursor(QCursor(Qt::ArrowCursor));
00167 }
00168 
00169 void KSNewStuff::slotProcessEvents() { kapp->processEvents( 500 ); }
00170 
00171 #include "ksnewstuff.moc"
00172 
00173 #endif // KDE >= 3.2.90

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal