• Skip to content
  • Skip to link menu
KDE 4.2 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 "keduvoclesson.h"
00025 #include "keduvocdocument.h"
00026 
00027 KEduVocPaukerReader::KEduVocPaukerReader( KEduVocDocument * doc )
00028 {
00029     m_doc = doc;
00030 }
00031 
00032 
00033 bool KEduVocPaukerReader::read( QIODevice * device )
00034 {
00035     setDevice( device );
00036 
00037     while ( !atEnd() ) {
00038         readNext();
00039 
00040         if ( isStartElement() ) {
00041             if ( name() == "Lesson" )
00042                 readPauker();
00043             else
00044                 raiseError( i18n( "This is not a Pauker document" ) );
00045         }
00046     }
00047 
00048     return !error();
00049 }
00050 
00051 
00052 void KEduVocPaukerReader::readUnknownElement()
00053 {
00054     while ( !atEnd() ) {
00055         readNext();
00056 
00057         if ( isEndElement() )
00058             break;
00059 
00060         if ( isStartElement() )
00061             readUnknownElement();
00062     }
00063 }
00064 
00065 
00066 void KEduVocPaukerReader::readPauker()
00067 {
00068     m_doc->setAuthor( "http://pauker.sf.net" );
00070     m_doc->appendIdentifier();
00071     m_doc->appendIdentifier();
00072 
00073     while ( !atEnd() ) {
00074         readNext();
00075 
00076         if ( isEndElement() )
00077             break;
00078 
00079         if ( isStartElement() ) {
00080             if ( name() == "Description" )
00081                 m_doc->setDocumentComment( readElementText() );
00082             else if ( name() == "Batch" )
00083                 readBatch();
00084             else
00085                 readUnknownElement();
00086         }
00087     }
00088 }
00089 
00090 
00091 void KEduVocPaukerReader::readBatch()
00092 {
00093     while ( !atEnd() ) {
00094         readNext();
00095 
00096         if ( isEndElement() )
00097             break;
00098 
00099         if ( isStartElement() ) {
00100             if ( name() == "Card" )
00101                 readCard();
00102             else
00103                 readUnknownElement();
00104         }
00105     }
00106 }
00107 
00108 
00109 void KEduVocPaukerReader::readCard()
00110 {
00111     QString front;
00112     QString back;
00113 
00114     while ( !atEnd() ) {
00115         readNext();
00116 
00117         if ( isEndElement() )
00118             break;
00119 
00120         if ( isStartElement() ) {
00121             if ( name() == "FrontSide" )
00122                 front = readText();
00123             else if ( name() == "ReverseSide" )
00124                 back = readText();
00125             else
00126                 readUnknownElement();
00127         }
00128     }
00129 
00130     KEduVocLesson* lesson = new KEduVocLesson(i18n("Vocabulary"), m_doc->lesson());
00131     m_doc->lesson()->appendChildContainer(lesson);
00132 
00133     KEduVocExpression* expr = new KEduVocExpression( QStringList() << front << back);
00134     lesson->appendEntry( expr );
00135 }
00136 
00137 
00138 QString KEduVocPaukerReader::readText()
00139 {
00140     QString result;
00141 
00142     while ( !atEnd() ) {
00143         readNext();
00144 
00145         if ( isEndElement() )
00146             break;
00147 
00148         if ( isStartElement() ) {
00149             if ( name() == "Text" )
00150                 result = readElementText();
00151             else
00152                 readUnknownElement();
00153         }
00154     }
00155     return result;
00156 }

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
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
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