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

libkdeedu/keduvocdocument

keduvocpaukerreader.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                      create a KEduVocDocument from a Pauker file
00003     -----------------------------------------------------------------------
00004     copyright     : (C) 2004, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
00005 
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 #include "keduvocpaukerreader.h"
00018 
00019 #include <QIODevice>
00020 
00021 #include <KLocale>
00022 
00023 #include "keduvocexpression.h"
00024 #include "keduvocdocument.h"
00025 
00026 KEduVocPaukerReader::KEduVocPaukerReader( KEduVocDocument * doc )
00027 {
00028     m_doc = doc;
00029 }
00030 
00031 
00032 bool KEduVocPaukerReader::read( QIODevice * device )
00033 {
00034     setDevice( device );
00035 
00036     while ( !atEnd() ) {
00037         readNext();
00038 
00039         if ( isStartElement() ) {
00040             if ( name() == "Lesson" )
00041                 readPauker();
00042             else
00043                 raiseError( i18n( "This is not a Pauker document" ) );
00044         }
00045     }
00046 
00047     return !error();
00048 }
00049 
00050 
00051 void KEduVocPaukerReader::readUnknownElement()
00052 {
00053     while ( !atEnd() ) {
00054         readNext();
00055 
00056         if ( isEndElement() )
00057             break;
00058 
00059         if ( isStartElement() )
00060             readUnknownElement();
00061     }
00062 }
00063 
00064 
00065 void KEduVocPaukerReader::readPauker()
00066 {
00067     m_doc->setAuthor( "http://pauker.sf.net" );
00069     m_doc->appendIdentifier();
00070     m_doc->appendIdentifier();
00071 
00072     while ( !atEnd() ) {
00073         readNext();
00074 
00075         if ( isEndElement() )
00076             break;
00077 
00078         if ( isStartElement() ) {
00079             if ( name() == "Description" )
00080                 m_doc->setDocumentComment( readElementText() );
00081             else if ( name() == "Batch" )
00082                 readBatch();
00083             else
00084                 readUnknownElement();
00085         }
00086     }
00087 }
00088 
00089 
00090 void KEduVocPaukerReader::readBatch()
00091 {
00092     while ( !atEnd() ) {
00093         readNext();
00094 
00095         if ( isEndElement() )
00096             break;
00097 
00098         if ( isStartElement() ) {
00099             if ( name() == "Card" )
00100                 readCard();
00101             else
00102                 readUnknownElement();
00103         }
00104     }
00105 }
00106 
00107 
00108 void KEduVocPaukerReader::readCard()
00109 {
00110     QString front;
00111     QString back;
00112 
00113     while ( !atEnd() ) {
00114         readNext();
00115 
00116         if ( isEndElement() )
00117             break;
00118 
00119         if ( isStartElement() ) {
00120             if ( name() == "FrontSide" )
00121                 front = readText();
00122             else if ( name() == "ReverseSide" )
00123                 back = readText();
00124             else
00125                 readUnknownElement();
00126         }
00127     }
00128 
00129     KEduVocExpression expr = KEduVocExpression( front );
00130     expr.setTranslation( 1, back );
00131     m_doc->appendEntry( &expr );
00132 }
00133 
00134 
00135 QString KEduVocPaukerReader::readText()
00136 {
00137     QString result;
00138 
00139     while ( !atEnd() ) {
00140         readNext();
00141 
00142         if ( isEndElement() )
00143             break;
00144 
00145         if ( isStartElement() ) {
00146             if ( name() == "Text" )
00147                 result = readElementText();
00148             else
00149                 readUnknownElement();
00150         }
00151     }
00152     return result;
00153 }

libkdeedu/keduvocdocument

Skip menu "libkdeedu/keduvocdocument"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal