• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
ksfilereader.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ksfilereader.cpp - description
3  -------------------
4  begin : 2007-07-16
5  copyright : (C) 2007 James B. Bowlin
6  email : bowlin@mindspring.com
7  ***************************************************************************/
8 
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  ***************************************************************************/
17 
18 #include "ksfilereader.h"
19 
20 #include <QApplication>
21 #include <QObject>
22 #include <QFile>
23 
24 #include "kdebug.h"
25 #include "kstars.h"
26 #include "kstarsdata.h"
27 #include "ksutils.h"
28 
29 #ifndef MAXUINT
30  #define MAXUINT (~0)
31 #endif
32 
33 KSFileReader::KSFileReader( qint64 maxLen ) :
34  QTextStream(), m_maxLen(maxLen), m_curLine(0), m_targetLine(MAXUINT)
35 {}
36 
37 KSFileReader::KSFileReader( QFile& file, qint64 maxLen ) :
38  QTextStream(), m_maxLen(maxLen), m_curLine(0), m_targetLine(MAXUINT)
39 {
40  QIODevice* device = (QIODevice*) & file;
41  QTextStream::setDevice( device );
42  QTextStream::setCodec("UTF-8");
43  m_targetLine = MAXUINT;
44 }
45 
46 bool KSFileReader::open( const QString& fname )
47 {
48  if ( !KSUtils::openDataFile( m_file, fname ) ) {
49  kWarning() << QString("Couldn't open(%1)").arg(fname);
50  return false;
51  }
52  QTextStream::setDevice( &m_file );
53  QTextStream::setCodec("UTF-8");
54  return true;
55 }
56 
57 bool KSFileReader::openFullPath( const QString& fname )
58 {
59  if ( !fname.isNull() ) {
60  m_file.setFileName( fname );
61  if ( !m_file.open( QIODevice::ReadOnly ))
62  return false;
63  }
64  QTextStream::setDevice( &m_file );
65  QTextStream::setCodec("UTF-8");
66  return true;
67 }
68 
69 void KSFileReader::setProgress( QString label,
70  unsigned int totalLines,
71  unsigned int numUpdates )
72 {
73  m_label = label;
74  m_totalLines = totalLines;
75  if ( m_totalLines < 1 ) m_totalLines = 1;
76  m_targetLine = m_totalLines / 100;
77  m_targetIncrement = m_totalLines / numUpdates;
78 
79  connect( this, SIGNAL( progressText( const QString & ) ),
80  KStarsData::Instance(), SIGNAL( progressText( const QString & ) ) );
81 }
82 
83 void KSFileReader::showProgress()
84 {
85  if ( m_curLine < m_targetLine ) return;
86  if ( m_targetLine < m_targetIncrement )
87  m_targetLine = m_targetIncrement;
88  else
89  m_targetLine += m_targetIncrement;
90 
91  int percent = int(.5 + (m_curLine * 100.0) / m_totalLines);
92  //printf("%8d %8d %3d\n", m_curLine, m_totalLines, percent );
93  if ( percent > 100 ) percent = 100;
94  emit progressText( QString("%1 (%2%)").arg( m_label ).arg( percent ) );
95  qApp->processEvents();
96 }
97 
98 
99 #include "ksfilereader.moc"
MAXUINT
#define MAXUINT
Definition: ksfilereader.cpp:30
KSFileReader::KSFileReader
KSFileReader(qint64 maxLen=1024)
Definition: ksfilereader.cpp:33
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
KSUtils::openDataFile
bool openDataFile(QFile &file, const QString &filename)
Attempt to open the data file named filename, using the QFile object "file".
KSFileReader::open
bool open(const QString &fname)
Definition: ksfilereader.cpp:46
KSFileReader::showProgress
void showProgress()
Definition: ksfilereader.cpp:83
KSFileReader::progressText
void progressText(const QString &message)
QTextStream
ksfilereader.h
KSFileReader::setProgress
void setProgress(QString label, unsigned int lastLine, unsigned int numUpdates=10)
Definition: ksfilereader.cpp:69
kstarsdata.h
KSFileReader::openFullPath
bool openFullPath(const QString &fname)
Definition: ksfilereader.cpp:57
ksutils.h
kstars.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal