1 /***************************************************************************
2 filesource.cpp - description
4 begin : Son Feb 10 2002
5 copyright : (C) 2002 by Thomas Kabelmann
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 "filesource.h"
19 #include "ksfilereader.h"
20 #include "kstarsdata.h"
23 FileSource::FileSource(KStarsData
*ksdata
, float magnitude
)
24 : maxMagnitude(magnitude
), data(ksdata
) {
26 // kdDebug() << "new magnitude to load is " << maxMagnitude << endl;
27 // kdDebug() << "count()=" << data->starList.count() << endl;
28 fileNumber
= ksdata
->starList
.count() / 1000 + 1;
29 lineNumber
= ksdata
->starList
.count() % 1000;
30 // the first file contains 12 comment lines at the beginning which must skipped
31 if (fileNumber
== 1) { lineNumber
+= 12; }
32 // kdDebug() << "fileNumber=" << fileNumber << " lineNumber=" << lineNumber << endl;
34 if (fileNumber
<= NHIPFILES
) {
35 // if file opened it's true else false
36 readingData
= data
->openStarFile(fileNumber
);
37 if (data
->starFileReader
->setLine(lineNumber
) == true) {
38 // kdDebug() << "line reset ok" << endl;
40 // kdDebug() << "line reset not ok" << endl;
47 FileSource::~FileSource() {
50 int FileSource::readyToSend() {
51 // readyToSend == 0 -> no data but not end of stream
52 // readyToSend > 0 -> data ready to send
53 // readyToSend == -1 -> end of stream, QDataPump will destroy this FileSource object
54 if (readingData
== true)
60 void FileSource::sendTo(QDataSink
*sink
, int) {
62 while (data
->starFileReader
->hasMoreLines() && counter
< maxLines
) {
63 QString line
= data
->starFileReader
->readLine();
64 float mag
= line
.mid( 46, 5 ).toFloat(); // check magnitude
65 // kdDebug() << "mag=" << mag << " maxmag=" << maxMagnitude << endl;
66 if (mag
> maxMagnitude
) {
70 stringArray
[counter
++] = line
;
73 // open next file if end is reached
74 if (data
->starFileReader
->hasMoreLines() == false && readingData
== true && fileNumber
< NHIPFILES
) {
76 // kdDebug() << "sendTo: open file #" << fileNumber << endl;
77 data
->openStarFile(fileNumber
);
79 // check if more data are available
80 if (readingData
== true && data
->starFileReader
!= 0 && data
->starFileReader
->hasMoreLines() == true) {
85 // send data to StarDataSink
86 sink
->receive((uchar
*) &stringArray
[0], counter
);