moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / ksfilereader.cpp
blob565cdf1bd1b82a98cd82b5ebee1da69f50b21a85
1 /***************************************************************************
2 ksfilereader.cpp - description
3 -------------------
4 begin : Tue Jan 28 2003
5 copyright : (C) 2003 by Heiko Evermann
6 email : heiko@evermann.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 <qfile.h>
19 #include <qstring.h>
21 #include "ksfilereader.h"
23 KSFileReader::KSFileReader(QFile& file) {
24 // read the whole file at once. This works well at least for the smaller files.
25 QByteArray data = file.readAll();
26 QString sAll = QString::fromUtf8( data.data(), data.size() );
27 // split into list of lines
28 lines = QStringList::split( "\n", sAll );
29 // how many lines did we get?
30 numLines = lines.size();
31 // set index to start
32 curLine = 0;
33 // we do not need the file any more
34 file.close();
37 KSFileReader::~KSFileReader(){
40 bool KSFileReader::hasMoreLines() {
41 return (curLine < numLines);
44 QString& KSFileReader::readLine(){
45 // hint: use curLine as index, after that increment curLine
46 // This means that the programming language c++ should better be renamed to ++c,
47 // otherwise the name means: improve the c programming language, but use it the
48 // way it was before the improvements...
49 return lines[curLine++];
52 bool KSFileReader::setLine(int i) {
53 if (i <= numLines) {
54 curLine = i;
55 return true;
56 } else {
57 return false;
61 #include "ksfilereader.moc"