• 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
keduvocxdxfreader.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  create a KEduVocDocument from a XDXF file
3  -----------------------------------------------------------------------
4  copyright : (C) 2007 Peter Hedlund <peter.hedlund@kdemail.net>
5 
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "keduvocxdxfreader.h"
18 
19 #include <QIODevice>
20 
21 #include <KLocale>
22 
23 #include "keduvocexpression.h"
24 #include "keduvocdocument.h"
25 
26 KEduVocXdxfReader::KEduVocXdxfReader( KEduVocDocument *doc )
27 {
28  m_doc = doc;
29 }
30 
31 
32 bool KEduVocXdxfReader::read( QIODevice *device )
33 {
34  setDevice( device );
35 
36  while ( !atEnd() ) {
37  readNext();
38 
39  if ( isStartElement() ) {
40  if ( name() == "xdxf" )
41  readXdxf();
42  else
43  raiseError( i18n( "This is not a XDXF document" ) );
44  }
45  }
46 
47  return !error();
48 }
49 
50 
51 void KEduVocXdxfReader::readUnknownElement()
52 {
53  while ( !atEnd() ) {
54  readNext();
55 
56  if ( isEndElement() )
57  break;
58 
59  if ( isStartElement() )
60  readUnknownElement();
61  }
62 }
63 
64 
65 void KEduVocXdxfReader::readXdxf()
66 {
68  QStringRef id1 = attributes().value( "lang_from" );
69  m_doc->appendIdentifier();
70  if ( !id1.isNull() ) {
71  m_doc->identifier(0).setLocale( id1.toString().toLower() );
72  m_doc->identifier(0).setName( id1.toString().toLower() );
73  }
74  QStringRef id2 = attributes().value( "lang_to" );
75  m_doc->appendIdentifier();
76  if ( !id2.isNull() ) {
77  m_doc->identifier(1).setLocale( id2.toString().toLower() );
78  m_doc->identifier(1).setName( id2.toString().toLower() );
79  }
80 
81  while ( !atEnd() ) {
82  readNext();
83 
84  if ( isEndElement() )
85  break;
86 
87  if ( isStartElement() ) {
88  if ( name() == "description" )
89  m_doc->setDocumentComment( readElementText() );
90  else if ( name() == "full_name" )
91  m_doc->setTitle( readElementText() );
92  else if ( name() == "ar" )
93  readEntry();
94  else
95  readUnknownElement();
96  }
97  }
98 
99  m_doc->setAuthor( "http://xdxf.sf.net" );
100 }
101 
102 
103 void KEduVocXdxfReader::readEntry()
104 {
105  QString front;
106  QString back;
107 
108  while ( !( isEndElement() && name() == "ar" ) ) {
109  readNext();
110  if ( isStartElement() && name() == "k" )
111  front = readElementText();
112  else if ( isCharacters() || isEntityReference() )
113  back.append( text().toString() );
114  }
115 
116  KEduVocExpression expr = KEduVocExpression( front );
117  expr.setTranslation( 1, back );
118  m_doc->lesson()->appendEntry( &expr );
119 }
KEduVocLesson::appendEntry
void appendEntry(KEduVocExpression *entry)
append an entry to the lesson
Definition: keduvoclesson.cpp:67
keduvocexpression.h
keduvocdocument.h
KEduVocDocument::setAuthor
void setAuthor(const QString &author)
Set the author of the file.
Definition: keduvocdocument.cpp:761
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
KEduVocXdxfReader::read
bool read(QIODevice *device)
Definition: keduvocxdxfreader.cpp:32
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
KEduVocXdxfReader::KEduVocXdxfReader
KEduVocXdxfReader(KEduVocDocument *doc)
Definition: keduvocxdxfreader.cpp:26
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
keduvocxdxfreader.h
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