[Kstars-devel] KDE/kdeedu/kstars/kstars/skycomponents
Jason Harris
kstars at 30doradus.org
Sun Dec 16 17:45:18 CET 2007
SVN commit 749140 by harris:
Add a function DeepSkyComponent::mergeSplitFiles(), which concatenates
ngcic??.dat files into a single ngcic.dat file. Without this
function, KDE4 users would not be able to use the Steinicke NGC/IC
catalog from the get new stuff tool.
TODO: make KStars::slotDownload() use the newly-installed data, so the
user doesn't need to restart the program to see the new stuff.
CCMAIL: kstars-devel at kde.org
M +45 -0 deepskycomponent.cpp
M +2 -0 deepskycomponent.h
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.cpp #749139:749140
@@ -18,8 +18,11 @@
#include "deepskycomponent.h"
#include <QPainter>
+#include <QDir>
+#include <QFile>
#include <klocale.h>
+#include <kstandarddirs.h>
#include "deepskyobject.h"
#include "dms.h"
@@ -62,6 +65,10 @@
void DeepSkyComponent::init(KStarsData *data)
{
+ //Check whether we need to concatenate a plit NGC/IC catalog
+ //(i.e., if user has downloaded the Steinicke catalog)
+ mergeSplitFiles();
+
KSFileReader fileReader;
if ( ! fileReader.open( "ngcic.dat" ) ) return;
@@ -219,7 +226,45 @@
}
}
+void DeepSkyComponent::mergeSplitFiles() {
+ //If user has downloaded the Steinicke NGC/IC catalog, then it is
+ //split into multiple files. Concatenate these into a single file.
+ QString firstFile = KStandardDirs::locateLocal("appdata", "ngcic01.dat");
+ if ( ! QFile::exists( firstFile ) ) return;
+ QDir localDir = QFileInfo( firstFile ).absoluteDir();
+ QStringList catFiles = localDir.entryList( "ngcic??.dat" );
+ kDebug() << "Merging split NGC/IC files" << endl;
+
+ QString buffer;
+ foreach ( QString fname, catFiles ) {
+ QFile f( localDir.absoluteFilePath(fname) );
+ if ( f.open( QIODevice::ReadOnly ) ) {
+ QTextStream stream( &f );
+ buffer += stream.readAll();
+
+ f.close();
+ } else {
+ kDebug() << QString("Error: Could not open %1 for reading").arg(fname) << endl;
+ }
+ }
+
+ QFile fout( localDir.absoluteFilePath( "ngcic.dat" ) );
+ if ( fout.open( QIODevice::WriteOnly ) ) {
+ QTextStream oStream( &fout );
+ oStream << buffer;
+ fout.close();
+
+ //Remove the split-files
+ foreach ( QString fname, catFiles ) {
+ QString fullname = localDir.absoluteFilePath(fname);
+ //DEBUG
+ kDebug() << "Removing " << fullname << " ..." << endl;
+ QFile::remove( fullname );
+ }
+ }
+}
+
void DeepSkyComponent::appendIndex( DeepSkyObject *o, DeepSkyIndex* dsIndex )
{
MeshIterator region( m_skyMesh );
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.h #749139:749140
@@ -118,6 +118,8 @@
bool selected();
private:
+ void mergeSplitFiles();
+
KStarsData* m_data;
SkyMap* m_map;
More information about the Kstars-devel
mailing list