1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/***************************************************************************
ksnewstuff.cpp - description
-------------------
begin : Wed 21 May 2004
copyright : (C) 2004 by Jason Harris
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <tdeversion.h>
#if KDE_IS_VERSION( 3, 2, 90 )
#include <kapplication.h>
#include <kaction.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kdirwatch.h>
#include <kprogress.h>
#include <ktar.h>
#include <tqdir.h>
#include <tqcursor.h>
#include <tqregexp.h>
#include "ksnewstuff.h"
#include "kstars.h"
#include "kstarsdata.h"
#include "deepskyobject.h"
#include "objectnamelist.h"
#include "skymap.h"
KSNewStuff::KSNewStuff( TQWidget *parent ) :
TQObject(), KNewStuff( "kstars", parent ), NGCUpdated( false )
{
ks = (KStars*)parent;
kdw = new KDirWatch( this );
kdw->addDir( TDEGlobal::dirs()->saveLocation("data", kapp->instanceName(), true) );
}
bool KSNewStuff::install( const TQString &fileName )
{
kdDebug() << "KSNewStuff::install(): " << fileName << endl;
KTar archive( fileName );
if ( !archive.open( IO_ReadOnly ) )
return false;
const KArchiveDirectory *archiveDir = archive.directory();
const TQString destDir = TDEGlobal::dirs()->saveLocation("data", kapp->instanceName(), true);
KStandardDirs::makeDir( destDir );
//monitor destDir for changes; inform updateData when files are created.
connect( kdw, TQT_SIGNAL( dirty( const TQString & ) ), this, TQT_SLOT( updateData( const TQString & ) ) );
archiveDir->copyTo(destDir);
archive.close();
kapp->processEvents(10000);
//read the new data into the program
//this return might be the result of checking if everything is installed ok
return true;
}
void KSNewStuff::updateData( const TQString &path ) {
TQDir qd( path );
qd.setSorting( TQDir::Time );
qd.setFilter( TQDir::Files );
//Show the Wait cursor
ks->setCursor(TQCursor(TQt::WaitCursor));
//Handle the Steinicke NGC/IC catalog
if ( !NGCUpdated && qd[0].contains( "ngcic" ) ) {
//Build a progress dialog to show during data installation.
KProgressDialog prog( 0, "newstuffprogdialog",
i18n( "Please Wait" ), i18n( "Installing Steinicke NGC/IC catalog..." ), false /*modal*/ );
prog.setAllowCancel( false );
prog.setMinimumDuration( 0 /*millisec*/ );
prog.progressBar()->setTotalSteps( 0 ); //show generic progress activity
prog.show();
kapp->processEvents(1000);
//First, remove the existing NGC/IC objects from the ObjectNameList.
for ( DeepSkyObject *o = ks->data()->deepSkyList.first(); o; o = ks->data()->deepSkyList.next() ) {
if ( o->hasLongName() && o->longname() != o->name() ) ks->data()->ObjNames.remove( o->longname() );
ks->data()->ObjNames.remove( o->name() );
}
//We can safely clear the Messier/NGC/IC/Other lists, since their pointers are secondary
ks->data()->deepSkyListMessier.clear();
ks->data()->deepSkyListNGC.clear();
ks->data()->deepSkyListIC.clear();
ks->data()->deepSkyListOther.clear();
//Finally, we can clear deepSkyList. This will automatically delete the SkyObjects
ks->data()->deepSkyList.clear();
//Send progress messages to the console
connect( ks->data(), TQT_SIGNAL( progressText(TQString) ), ks->data(), TQT_SLOT( slotConsoleMessage(TQString) ) );
connect( ks->data(), TQT_SIGNAL( progressText(TQString) ), ks->data(), TQT_SLOT( slotProcessEvents() ) );
//We are now ready to read the new NGC/IC catalog
ks->data()->readDeepSkyData();
//Avoid redundant installs
NGCUpdated = true;
//Re-assign image/info links. 3rd param means deep-sky objects only
ks->data()->readURLData( "image_url.dat", 0, true );
ks->data()->readURLData( "info_url.dat", 1, true );
ks->data()->setFullTimeUpdate();
ks->data()->updateTime( ks->geo(), ks->map() );
ks->map()->forceUpdate();
}
//Handle the inline Messier images
// **No action required**
//Handle the ephemerides
if ( qd[0] == "asteroids.dat" || qd[0] == "comets.dat" ) {
//Build a progress dialog to show during data installation.
KProgressDialog prog( 0, "newstuffprogdialog",
i18n( "Please Wait" ), i18n( "Installing comet and asteroid ephemerides..." ), true /*modal*/ );
prog.setAllowCancel( false );
prog.setMinimumDuration( 50 /*millisec*/ );
prog.progressBar()->setTotalSteps( 0 ); //generic progress activity
//First, remove the existing asteroids and comets from the ObjectNameList.
for ( SkyObject *o = (SkyObject*)(ks->data()->asteroidList.first()); o; o = (SkyObject*)(ks->data()->asteroidList.next()) ) {
if ( o->hasLongName() && o->longname() != o->name() ) ks->data()->ObjNames.remove( o->longname() );
ks->data()->ObjNames.remove( o->name() );
}
for ( SkyObject *o = (SkyObject*)(ks->data()->cometList.first()); o; o = (SkyObject*)(ks->data()->cometList.next()) ) {
if ( o->hasLongName() && o->longname() != o->name() ) ks->data()->ObjNames.remove( o->longname() );
ks->data()->ObjNames.remove( o->name() );
}
//Clear the asteroids and comets lists
ks->data()->asteroidList.clear();
ks->data()->cometList.clear();
//Send progress messages to the console
connect( ks->data(), TQT_SIGNAL( progressText(TQString) ), ks->data(), TQT_SLOT( slotConsoleMessage(TQString) ) );
//add new asteroids and comets
ks->data()->readAsteroidData();
ks->data()->readCometData();
//Do a full update
ks->data()->setFullTimeUpdate();
ks->data()->updateTime( ks->geo(), ks->map() );
ks->map()->forceUpdate();
}
//Restore arrow cursor
ks->setCursor(TQCursor(TQt::ArrowCursor));
}
void KSNewStuff::slotProcessEvents() { kapp->processEvents( 500 ); }
#include "ksnewstuff.moc"
#endif // KDE >= 3.2.90
|