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

libkdeedu/keduvocdocument

  • sources
  • kde-4.12
  • kdeedu
  • libkdeedu
  • keduvocdocument
keduvocwqlreader.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  read a KEduVocDocument from a WQL file
3  -----------------------------------------------------------------------
4  copyright : (C) 2004, 2007, 2008 Peter Hedlund <peter.hedlund@kdemail.net>
5  (C) 2005 Eric Pignet
6  (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "keduvocwqlreader.h"
20 
21 #include <QTextStream>
22 #include <QIODevice>
23 #include <QFont>
24 
25 #include <KLocale>
26 
27 #include "keduvocdocument.h"
28 #include "keduvocexpression.h"
29 
30 KEduVocWqlReader::KEduVocWqlReader( QIODevice *file )
31 {
32  // the file must be already open
33  m_inputFile = file;
34  m_errorMessage = "";
35 }
36 
37 
38 bool KEduVocWqlReader::readDoc( KEduVocDocument *doc )
39 {
40  m_doc = doc;
41 
42  QTextStream inputStream( m_inputFile );
43  inputStream.setCodec( "Windows-1252" ); //("ISO-8851-1");
44  inputStream.setAutoDetectUnicode( false );
45  inputStream.seek( 0 );
46 
47  QString s = "";
48  s=inputStream.readLine();
49  if ( s != "WordQuiz" ) {
50  m_errorMessage = i18n( "This does not appear to be a (K)WordQuiz file" );
51  return false;
52  }
53  s = inputStream.readLine();
54  s = s.left( 1 );
55  int iFV = s.toInt( 0 );
56  if ( iFV != 5 ) {
57  m_errorMessage = i18n( "Only files created by WordQuiz 5.x or later can be opened" );
58  return false;
59  }
60 
61  m_errorMessage = i18n( "Error while reading file" );
62 
63  while ( !inputStream.atEnd() && inputStream.readLine() != "[Font Info]" ) ;
64  if ( inputStream.atEnd() )
65  return false;
66  s = inputStream.readLine();
67  int p = s.indexOf( "=", 0 );
68  QString fam = s.right( s.length() - ( p + 1 ) );
69  fam = fam.mid( 1, fam.length() - 2 );
70 
71  s = inputStream.readLine();
72  p = s.indexOf( "=", 0 );
73  s = s.right( s.length() - ( p + 1 ) );
74  //int ps = s.toInt(0);
75 
76  s = inputStream.readLine();
77  p = s.indexOf( "=", 0 );
78  s = s.right( s.length() - ( p + 1 ) );
79  int b = 0;
80  if ( s == "1" ) {
81  b = QFont::Bold;
82  }
83 
84  s = inputStream.readLine();
85  p = s.indexOf( "=", 0 );
86  s = s.right( s.length() - ( p + 1 ) );
87  //bool it = (s == "1");
88 
89  //m_doc->setFont(new QFont(fam, ps, b, it));
90 
91  /* TODO
92  while (inputStream.readLine() != "[Character Info]");
93  s = inputStream.readLine();
94  p = s.find("=", 0);
95  m_specialCharacters = s.right(s.length() - (p + 1));
96  */
97  while ( !inputStream.atEnd() && inputStream.readLine() != "[Grid Info]" ) ;
98  if ( inputStream.atEnd() )
99  return false;
100  inputStream.readLine(); //skip value for width of row headers
101 
102  s = inputStream.readLine();
103  p = s.indexOf( "=", 0 );
104  s = s.right( s.length() - ( p + 1 ) );
105 // m_doc->setSizeHint( 0, s.toInt() );
106 
107  s = inputStream.readLine();
108  p = s.indexOf( "=", 0 );
109  s = s.right( s.length() - ( p + 1 ) );
110 // m_doc->setSizeHint( 1, s.toInt() );
111 
112  /* TODO
113  s = inputStream.readLine();
114  p = s.find("=", 0);
115  s = s.right(s.length() - (p + 1));
116  m_numRows = (s.toInt() - 1); //We need to reduce by one since the header is not included
117  // Selection
118  s = inputStream.readLine();
119  p = s.find("=", 0);
120  s = s.right(s.length() - (p + 1));
121  m_topLeft =s.toInt(0, 10) - 1;
122 
123  s = inputStream.readLine();
124  p = s.find("=", 0);
125  s = s.right(s.length() - (p + 1));
126  m_topRight =s.toInt(0, 10) - 1;
127 
128  s = inputStream.readLine();
129  p = s.find("=", 0);
130  s = s.right(s.length() - (p + 1));
131  m_bottomLeft =s.toInt(0, 10) - 1;
132 
133  s = inputStream.readLine();
134  p = s.find("=", 0);
135  s = s.right(s.length() - (p + 1));
136  m_bottomRight =s.toInt(0, 10) - 1 ;
137  */
138  while ( !inputStream.atEnd() && inputStream.readLine() != "[Vocabulary]" ) ;
139  if ( inputStream.atEnd() )
140  return false;
141 
142  KEduVocLesson* lesson = new KEduVocLesson( i18n("Vocabulary"), m_doc->lesson());
143  m_doc->lesson()->appendChildContainer(lesson);
144 
145  s = inputStream.readLine();
146  p = s.indexOf( " [", 0 );
147  s = s.left( p );
148  s = s.simplified();
149  m_doc->appendIdentifier();
150  m_doc->identifier(0).setLocale( s );
151  m_doc->identifier(0).setName( s );
152  s = inputStream.readLine();
153  m_doc->appendIdentifier();
154  m_doc->identifier(1).setLocale( s );
155  m_doc->identifier(1).setName( s );
156 
157  while ( !s.isNull() ) {
158  s = inputStream.readLine();
159  p = s.indexOf( "[", 0 );
160  //QString r = s.mid(p + 1, 10);
161  //int h = r.toInt();
162  s = s.left( p );
163  s = s.simplified();
164  QString b;
165  b = inputStream.readLine();
166 
167  KEduVocExpression * expr = new KEduVocExpression( s );
168  expr->setTranslation( 1, b );
169  lesson->appendEntry( expr );
170  }
171  return true;
172 }
KEduVocLesson::appendEntry
void appendEntry(KEduVocExpression *entry)
append an entry to the lesson
Definition: keduvoclesson.cpp:67
keduvocexpression.h
keduvocdocument.h
KEduVocLesson
class to store information about a lesson
Definition: keduvoclesson.h:27
KEduVocDocument::appendIdentifier
int appendIdentifier(const KEduVocIdentifier &identifier=KEduVocIdentifier())
Appends a new identifier (usually a language)
Definition: keduvocdocument.cpp:699
KEduVocTranslation::KEduVocExpression
friend class KEduVocExpression
Definition: keduvoctranslation.h:307
KEduVocWqlReader::readDoc
bool readDoc(KEduVocDocument *doc)
Definition: keduvocwqlreader.cpp:38
KEduVocExpression::setTranslation
void setTranslation(int index, KEduVocTranslation *translation)
KEduVocDocument::identifier
KEduVocIdentifier & identifier(int index)
Returns the identifier of translation index.
Definition: keduvocdocument.cpp:654
KEduVocIdentifier::setName
void setName(const QString &name)
Set the name.
Definition: keduvocidentifier.cpp:86
KEduVocExpression
This class contains one vocabulary expression as an original with one or more translations.
Definition: keduvocexpression.h:37
keduvocwqlreader.h
KEduVocContainer::appendChildContainer
void appendChildContainer(KEduVocContainer *child)
Definition: keduvoccontainer.cpp:77
KEduVocWqlReader::KEduVocWqlReader
KEduVocWqlReader(QIODevice *file)
Definition: keduvocwqlreader.cpp:30
KEduVocDocument::lesson
KEduVocLesson * lesson()
Get the lesson root object.
Definition: keduvocdocument.cpp:716
KEduVocDocument
This class contains the expressions of your vocabulary as well as other information about the vocabul...
Definition: keduvocdocument.h:44
KEduVocIdentifier::setLocale
void setLocale(const QString &name)
Set the locale.
Definition: keduvocidentifier.cpp:96
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:37:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdeedu/keduvocdocument

Skip menu "libkdeedu/keduvocdocument"
  • 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