kstars
ksnewstuff.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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
00068
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
00078 ks->setCursor(QCursor(Qt::WaitCursor));
00079
00080
00081
00082 if ( !NGCUpdated && qd[0].contains( "ngcic" ) ) {
00083
00084 KProgressDialog prog( 0, "newstuffprogdialog",
00085 i18n( "Please Wait" ), i18n( "Installing Steinicke NGC/IC catalog..." ), false );
00086 prog.setAllowCancel( false );
00087 prog.setMinimumDuration( 0 );
00088 prog.progressBar()->setTotalSteps( 0 );
00089 prog.show();
00090 kapp->processEvents(1000);
00091
00092
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
00099 ks->data()->deepSkyListMessier.clear();
00100 ks->data()->deepSkyListNGC.clear();
00101 ks->data()->deepSkyListIC.clear();
00102 ks->data()->deepSkyListOther.clear();
00103
00104
00105 ks->data()->deepSkyList.clear();
00106
00107
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
00112 ks->data()->readDeepSkyData();
00113
00114
00115 NGCUpdated = true;
00116
00117
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
00127
00128
00129
00130 if ( qd[0] == "asteroids.dat" || qd[0] == "comets.dat" ) {
00131
00132 KProgressDialog prog( 0, "newstuffprogdialog",
00133 i18n( "Please Wait" ), i18n( "Installing comet and asteroid ephemerides..." ), true );
00134 prog.setAllowCancel( false );
00135 prog.setMinimumDuration( 50 );
00136 prog.progressBar()->setTotalSteps( 0 );
00137
00138
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
00149 ks->data()->asteroidList.clear();
00150 ks->data()->cometList.clear();
00151
00152
00153 connect( ks->data(), SIGNAL( progressText(QString) ), ks->data(), SLOT( slotConsoleMessage(QString) ) );
00154
00155
00156 ks->data()->readAsteroidData();
00157 ks->data()->readCometData();
00158
00159
00160 ks->data()->setFullTimeUpdate();
00161 ks->data()->updateTime( ks->geo(), ks->map() );
00162 ks->map()->forceUpdate();
00163 }
00164
00165
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