moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / filesource.cpp
blob6197793721e63d4b30d41ac24edf72fb3a07ed0d
1 /***************************************************************************
2 filesource.cpp - description
3 -------------------
4 begin : Son Feb 10 2002
5 copyright : (C) 2002 by Thomas Kabelmann
6 email : tk78@gmx.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
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. *
15 * *
16 ***************************************************************************/
18 #include "filesource.h"
19 #include "ksfilereader.h"
20 #include "kstarsdata.h"
21 #include "ksutils.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;
39 } else {
40 // kdDebug() << "line reset not ok" << endl;
42 } else {
43 readingData = false;
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)
55 return 1;
56 else
57 return -1;
60 void FileSource::sendTo(QDataSink *sink, int) {
61 counter = 0;
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) {
67 readingData = false;
68 break;
69 } else {
70 stringArray[counter++] = line;
73 // open next file if end is reached
74 if (data->starFileReader->hasMoreLines() == false && readingData == true && fileNumber < NHIPFILES) {
75 fileNumber++;
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) {
81 readingData = true;
82 } else {
83 readingData = false;
85 // send data to StarDataSink
86 sink->receive((uchar*) &stringArray[0], counter);