1 /***************************************************************************
2 ksnewstuff.cpp - description
4 begin : Wed 21 May 2004
5 copyright : (C) 2004 by Jason Harris
6 email : kstars@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include <kdeversion.h>
19 #if KDE_IS_VERSION( 3, 2, 90 )
21 #include <kapplication.h>
25 #include <kstandarddirs.h>
26 #include <kdirwatch.h>
27 #include <kprogress.h>
33 #include "ksnewstuff.h"
35 #include "kstarsdata.h"
36 #include "deepskyobject.h"
37 #include "objectnamelist.h"
40 KSNewStuff::KSNewStuff( QWidget
*parent
) :
41 QObject(), KNewStuff( "kstars", parent
)
44 kdw
= new KDirWatch( this );
45 kdw
->addDir( KGlobal::dirs()->saveLocation("data", kapp
->instanceName(), true) );
48 bool KSNewStuff::install( const QString
&fileName
)
50 kdDebug() << "KSNewStuff::install(): " << fileName
<< endl
;
52 KTar
archive( fileName
);
53 if ( !archive
.open( IO_ReadOnly
) )
56 const KArchiveDirectory
*archiveDir
= archive
.directory();
57 const QString destDir
= KGlobal::dirs()->saveLocation("data", kapp
->instanceName(), true);
58 KStandardDirs::makeDir( destDir
);
60 //monitor destDir for changes; inform updateData when files are created.
61 connect( kdw
, SIGNAL( dirty( const QString
& ) ), this, SLOT( updateData( const QString
& ) ) );
63 archiveDir
->copyTo(destDir
);
65 kapp
->processEvents(10000);
67 //read the new data into the program
68 //this return might be the result of checking if everything is installed ok
72 void KSNewStuff::updateData( const QString
&path
) {
74 qd
.setSorting( QDir::Time
);
75 qd
.setFilter( QDir::Files
);
77 //Show the Wait cursor
78 ks
->setCursor(QCursor(Qt::WaitCursor
));
81 //Handle the Steinicke NGC/IC catalog
82 if ( qd
[0].contains( "ngcic" ) ) {
83 //Build a progress dialog to show during data installation.
84 KProgressDialog
prog( 0, "newstuffprogdialog",
85 i18n( "Please Wait" ), i18n( "Installing Steinicke NGC/IC catalog..." ), false /*modal*/ );
86 prog
.setAllowCancel( false );
87 prog
.setMinimumDuration( 0 /*millisec*/ );
88 prog
.progressBar()->setTotalSteps( 0 ); //show generic progress activity
90 kapp
->processEvents(100);
92 //First, remove the existing NGC/IC objects from the ObjectNameList.
93 for ( DeepSkyObject
*o
= ks
->data()->deepSkyList
.first(); o
; o
= ks
->data()->deepSkyList
.next() ) {
94 if ( o
->hasLongName() && o
->longname() != o
->name() ) ks
->data()->ObjNames
.remove( o
->longname() );
95 ks
->data()->ObjNames
.remove( o
->name() );
98 //We can safely clear the Messier/NGC/IC/Other lists, since their pointers are secondary
99 ks
->data()->deepSkyListMessier
.clear();
100 ks
->data()->deepSkyListNGC
.clear();
101 ks
->data()->deepSkyListIC
.clear();
102 ks
->data()->deepSkyListOther
.clear();
104 //Finally, we can clear deepSkyList. This will automatically delete the SkyObjects
105 ks
->data()->deepSkyList
.clear();
107 //Send progress messages to the console
108 connect( ks
->data(), SIGNAL( progressText(QString
) ), ks
->data(), SLOT( slotConsoleMessage(QString
) ) );
110 //We are now ready to read the new NGC/IC catalog
111 ks
->data()->readDeepSkyData();
113 //Re-assign image/info links. 3rd param means deep-sky objects only
114 ks
->data()->readURLData( "image_url.dat", 0, true );
115 ks
->data()->readURLData( "info_url.dat", 1, true );
117 ks
->data()->setFullTimeUpdate();
118 ks
->data()->updateTime( ks
->geo(), ks
->map() );
119 ks
->map()->forceUpdate();
122 //Handle the inline Messier images
123 // **No action required**
125 //Handle the ephemerides
126 if ( qd
[0] == "asteroids.dat" || qd
[0] == "comets.dat" ) {
127 //Build a progress dialog to show during data installation.
128 KProgressDialog
prog( 0, "newstuffprogdialog",
129 i18n( "Please Wait" ), i18n( "Installing comet and asteroid ephemerides..." ), true /*modal*/ );
130 prog
.setAllowCancel( false );
131 prog
.setMinimumDuration( 50 /*millisec*/ );
132 prog
.progressBar()->setTotalSteps( 0 ); //generic progress activity
134 //First, remove the existing asteroids and comets from the ObjectNameList.
135 for ( SkyObject
*o
= (SkyObject
*)(ks
->data()->asteroidList
.first()); o
; o
= (SkyObject
*)(ks
->data()->asteroidList
.next()) ) {
136 if ( o
->hasLongName() && o
->longname() != o
->name() ) ks
->data()->ObjNames
.remove( o
->longname() );
137 ks
->data()->ObjNames
.remove( o
->name() );
139 for ( SkyObject
*o
= (SkyObject
*)(ks
->data()->cometList
.first()); o
; o
= (SkyObject
*)(ks
->data()->cometList
.next()) ) {
140 if ( o
->hasLongName() && o
->longname() != o
->name() ) ks
->data()->ObjNames
.remove( o
->longname() );
141 ks
->data()->ObjNames
.remove( o
->name() );
144 //Clear the asteroids and comets lists
145 ks
->data()->asteroidList
.clear();
146 ks
->data()->cometList
.clear();
148 //Send progress messages to the console
149 connect( ks
->data(), SIGNAL( progressText(QString
) ), ks
->data(), SLOT( slotConsoleMessage(QString
) ) );
151 //add new asteroids and comets
152 ks
->data()->readAsteroidData();
153 ks
->data()->readCometData();
156 //Restore arrow cursor
157 ks
->setCursor(QCursor(Qt::ArrowCursor
));
160 #include "ksnewstuff.moc"
162 #endif // KDE >= 3.2.90