• 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
keduvocvokabelnreader.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  create a KEduVocDocument from a Vokabeln file
4 
5  -----------------------------------------------------------------------
6 
7  begin : Wed Jun 15 19:32:00 PDT 2005
8 
9  copyright : (C) 2005, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
10  (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
11 
12  -----------------------------------------------------------------------
13 
14  ***************************************************************************/
15 
16 /***************************************************************************
17  * *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or *
21  * (at your option) any later version. *
22  * *
23  ***************************************************************************/
24 
25 #include "keduvocvokabelnreader.h"
26 
27 #include <QIODevice>
28 
29 #include <klocale.h>
30 #include <kdebug.h>
31 
32 #include "keduvocdocument.h"
33 #include "keduvocexpression.h"
34 
35 KEduVocVokabelnReader::KEduVocVokabelnReader( QIODevice *file )
36 {
37  // the file must be already open
38  m_inputFile = file;
39  m_errorMessage = "";
40 }
41 
42 
43 bool KEduVocVokabelnReader::readDoc( KEduVocDocument *doc )
44 {
45  kDebug() << "Reading vokabeln.de document...";
46  m_doc = doc;
47 
48  m_doc->setAuthor( "http://www.vokabeln.de" );
49 
50  QTextStream inputStream( m_inputFile );
51  inputStream.setCodec( "ISO-8859-1" );
52  inputStream.setAutoDetectUnicode( false );
53  inputStream.seek( 0 );
54 
55  QString title;
56  QString lang1;
57  QString lang2;
58  QString expression;
59  QString original;
60  QString translation;
61  QString temp;
62  QString comment;
63 
64  int i;
65  int wordCount;
66  int lessonNumber;
67 
68  int lines = 10000;
69 
70  QStringList titles;
71  QStringList languages;
72  QStringList words;
73 
74  temp = inputStream.readLine();
75 
76  if ( temp.startsWith ( QChar::fromLatin1 ( '"' ) ) ) {
77  while ( temp != QChar::fromLatin1('0') ) {
78  if ( title.isEmpty() ) {
79  title = temp;
80  } else {
81  comment.append( temp.append('\n') );
82  }
83  temp = inputStream.readLine();
84  }
85  }
86 
87  // 1 line header
88  if (comment.isEmpty()) {
89  titles = title.split( "\"," );
90  m_doc->setTitle(titles[0].mid(1));
91  }
92  // longer header
93  else {
94  titles = comment.split( "\"," );
95  m_doc->setDocumentComment(titles[0]);
96  m_doc->setTitle(title.mid(1));
97  }
98 
99  wordCount = titles[1].section( ',', 0, 0 ).toInt();
100 
101  inputStream.readLine();
102 
103  lang1 = inputStream.readLine();
104  languages = lang1.split( "\"," );
105 
106  m_doc->appendIdentifier();
107  QString language = languages[0].mid( 1 );
108  m_doc->identifier(0).setLocale(language);
109  m_doc->identifier(0).setName(language);
110  kDebug() << "First language: " << language;
111 
112  m_doc->appendIdentifier();
113  language = languages[1].mid( 1 );
114  m_doc->identifier(1).setLocale(language);
115  m_doc->identifier(1).setName(language);
116  kDebug() << "Second language: " << language;
117 
118  while ( !temp.contains("8. Lernhilfe") ) {
119  temp = inputStream.readLine(); //DO NOT translate
120  }
121 
122  for ( i = 0; i <= 14; ++i ) {
123  inputStream.readLine();
124  }
125 
126 
127  for ( i = 0; i < wordCount - 1; ++i ) {
128  int c = 0;
129  expression.clear();
130 
131  while ( c < 2 ) {
132  temp = inputStream.readLine();
133  c+= temp.count( "\",", Qt::CaseSensitive );
134  expression.append( temp );
135  if ( c < 2 ) {
136  expression.append( ' ' );
137  }
138  }
139 
140  words = expression.split( "\"," );
141  original = words[0].mid( 1 );
142  translation = words[1].mid( 1 );
143  lessonNumber = words[2].toInt() - 1;
144 
145  kDebug() << "Reading entry: " << original << " - " << translation << " Lesson: " << lessonNumber;
146 
147  // fallback if it's not read correctly
148  if (lessonNumber < 0) {
149  kDebug() << "Warning, invalid lesson found!";
150  lessonNumber = 0;
151  }
152 
153  while(m_doc->lesson()->childContainerCount() <= lessonNumber) {
154  KEduVocLesson* lesson = new KEduVocLesson(i18n("Lesson %1", lessonNumber), m_doc->lesson());
155  m_doc->lesson()->appendChildContainer(lesson);
156  kDebug() << "Created lesson " << lessonNumber;
157  }
158 
159  KEduVocExpression* kve = new KEduVocExpression;
160  kve->setTranslation( 0, original );
161  kve->setTranslation( 1, translation );
162 
163  static_cast<KEduVocLesson*>(m_doc->lesson()->childContainer(lessonNumber))->appendEntry(kve);
164 
165  inputStream.readLine();
166  inputStream.readLine();
167  }
168 
169  inputStream.readLine();
170  inputStream.readLine();
171  inputStream.readLine();
172 
173  for ( int i = 0; !inputStream.atEnd() && i < lines; i++ ) {
174  QString lessonDescr = inputStream.readLine();
175  lessonDescr = lessonDescr.mid( 1, lessonDescr.length() - 2 );
176  m_doc->lesson()->childContainer(i)->setName(lessonDescr);
177  if ( lessonDescr.isEmpty() ) {
178  break;
179  }
180  inputStream.readLine();
181  }
182 
183  return true;
184 }
keduvocexpression.h
keduvocdocument.h
KEduVocLesson
class to store information about a lesson
Definition: keduvoclesson.h:27
keduvocvokabelnreader.h
KEduVocContainer::setName
void setName(const QString &name)
set the container name
Definition: keduvoccontainer.cpp:151
KEduVocDocument::setAuthor
void setAuthor(const QString &author)
Set the author of the file.
Definition: keduvocdocument.cpp:761
SharedKvtmlFiles::languages
KEDUVOCDOCUMENT_EXPORT QStringList languages()
get list of all languages found in any files
Definition: sharedkvtmlfiles.cpp:112
KEduVocDocument::setDocumentComment
void setDocumentComment(const QString &comment)
Set the comment of the file.
Definition: keduvocdocument.cpp:819
KEduVocDocument::appendIdentifier
int appendIdentifier(const KEduVocIdentifier &identifier=KEduVocIdentifier())
Appends a new identifier (usually a language)
Definition: keduvocdocument.cpp:699
KEduVocVokabelnReader::readDoc
bool readDoc(KEduVocDocument *doc)
Definition: keduvocvokabelnreader.cpp:43
KEduVocContainer::childContainer
KEduVocContainer * childContainer(int row)
Definition: keduvoccontainer.cpp:85
KEduVocExpression::setTranslation
void setTranslation(int index, KEduVocTranslation *translation)
KEduVocDocument::identifier
KEduVocIdentifier & identifier(int index)
Returns the identifier of translation index.
Definition: keduvocdocument.cpp:654
KEduVocContainer::childContainerCount
int childContainerCount() const
Find a child container.
Definition: keduvoccontainer.cpp:122
KEduVocExpression::KEduVocExpression
KEduVocExpression()
default constructor for an empty vocabulary expression
Definition: keduvocexpression.cpp:73
KEduVocIdentifier::setName
void setName(const QString &name)
Set the name.
Definition: keduvocidentifier.cpp:86
SharedKvtmlFiles::titles
KEDUVOCDOCUMENT_EXPORT QStringList titles(const QString &language=QString())
get the list of document titles found of a given language
Definition: sharedkvtmlfiles.cpp:124
KEduVocExpression::lesson
KEduVocLesson * lesson() const
return the lesson
Definition: keduvocexpression.cpp:144
KEduVocExpression
This class contains one vocabulary expression as an original with one or more translations.
Definition: keduvocexpression.h:37
KEduVocVokabelnReader::KEduVocVokabelnReader
KEduVocVokabelnReader(QIODevice *file)
Definition: keduvocvokabelnreader.cpp:35
KEduVocContainer::appendChildContainer
void appendChildContainer(KEduVocContainer *child)
Definition: keduvoccontainer.cpp:77
KEduVocExpression::translation
KEduVocTranslation * translation(int index)
Get a pointer to the translation.
Definition: keduvocexpression.cpp:182
KEduVocExpression::KEduVocLesson
friend class KEduVocLesson
Definition: keduvocexpression.h:120
KEduVocDocument::setTitle
void setTitle(const QString &title)
Set the title of the file.
Definition: keduvocdocument.cpp:749
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