moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / filesource.h
blob39fb83bdad8fe9adec3ab79e81b4da6c02ea264a
1 /***************************************************************************
2 filesource.h - 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 #ifndef FILESOURCE_H
19 #define FILESOURCE_H
21 /**@class FileSource
22 *FileSource is an asynchronous class for reloading star data while running
23 *the program. It's basing on QDataSource class and implements the function
24 *for reading a file step by step and send these data to an QDataSink object.
25 *KStarsData uses this class for asynchronous io.
26 *@author Thomas Kabelmann
27 *@version 1.0
30 #include <qasyncio.h>
31 #include <qstring.h>
33 class KStarsData;
34 class KSFileReader;
36 class FileSource : public QDataSource {
38 public:
39 /**constructor needs an KStarsData object, a file name and the new magnitude
41 FileSource( KStarsData *ksdata, float magnitude );
43 /** destructor */
44 ~FileSource();
46 /**send a value indicating whether the object is ready to send data.
47 *@return 1 if data is ready to send; return -1 if the stream is finished.
49 int readyToSend();
51 /**Is this object rewindable?
52 *@return false, because it's not needed to rewind.
54 bool rewindable() { return false; }
56 /**The function for sending data to an QDataSink object. Here will all data
57 *operations defined. Because this function is virtual, we need a second int
58 *parameter, but we don't use it, so it's unnamed.
59 *@p sink pointer to the QDataSink object which will receive the data stream
61 void sendTo( QDataSink *sink, int );
63 /**@return current magnitude to load (always returns maxMagnitude)
65 float magnitude() { return maxMagnitude; }
67 private:
69 bool readingData;
71 KSFileReader *fileReader;
73 // which sao file should be opened and which line
74 int fileNumber, lineNumber;
76 // counts blocksize
77 int counter;
79 // new magnitude to load
80 float maxMagnitude;
82 KStarsData *data;
84 /**maxLines defines how many lines in data file should be read and
85 *send to QDataSink. This is only needed if a data block is longer
86 *than the max defined lines. I figured out this value of 500
87 *on a fast system, so if it is to high the value might be decreased.
88 *A high value means faster reloading but perhaps on slow systems this
89 *might interrupt the main event loop.
90 *A low value needs longer to reload data, but it doesn't interrupt the
91 *main event loop (it's smoother).
92 *But it's important to know that 500 lines to read is very fast, but
93 *appending to QList in StarDataSink will take the most time and this
94 *will also defined with this value.
96 #define maxLines 500
98 /**The loaded data will stored in a string array and a pointer to first
99 *object in array will send to StarDataSink.
101 QString stringArray[ maxLines ];
105 #endif