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

libkdeedu/keduvocdocument

keduvocvokabelnreader.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003                    create a KEduVocDocument from a Vokabeln file
00004 
00005     -----------------------------------------------------------------------
00006 
00007     begin        : Wed Jun 15 19:32:00 PDT 2005
00008 
00009     copyright    : (C) 2005, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
00010                    (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
00011 
00012     -----------------------------------------------------------------------
00013 
00014  ***************************************************************************/
00015 
00016 /***************************************************************************
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  ***************************************************************************/
00024 
00025 #include "keduvocvokabelnreader.h"
00026 
00027 #include <QIODevice>
00028 
00029 #include <klocale.h>
00030 #include <kdebug.h>
00031 
00032 #include "keduvocdocument.h"
00033 #include "keduvocexpression.h"
00034 
00035 KEduVocVokabelnReader::KEduVocVokabelnReader( QIODevice *file )
00036 {
00037     // the file must be already open
00038     m_inputFile = file;
00039     m_errorMessage = "";
00040 }
00041 
00042 
00043 bool KEduVocVokabelnReader::readDoc( KEduVocDocument *doc )
00044 {
00045     m_doc = doc;
00046 
00047     m_doc->setAuthor( "http://www.vokabeln.de" );
00048 
00049     QTextStream inputStream( m_inputFile );
00050     inputStream.setCodec( "ISO-8859-1" );
00051     inputStream.setAutoDetectUnicode( false );
00052     inputStream.seek( 0 );
00053 
00054     QString title;
00055     QString lang1;
00056     QString lang2;
00057     QString expression;
00058     QString original;
00059     QString translation;
00060     QString temp;
00061     QString comment;
00062 
00063     int i;
00064     int wordCount;
00065     int lessonNumber;
00066 
00067     int lines = 10000;
00068 
00069     QStringList titles;
00070     QStringList languages;
00071     QStringList words;
00072 
00073     temp = inputStream.readLine();
00074 
00075     if ( temp.startsWith ( QChar::fromLatin1 ( '"' ) ) ) {
00076         while ( temp != QChar::fromLatin1('0') ) {
00077             if ( title.isEmpty() ) {
00078                 title = temp;
00079             } else {
00080                 comment.append( temp.append('\n') );
00081             }
00082             temp = inputStream.readLine();
00083         }
00084     }
00085 
00086     // 1 line header
00087     if (comment.isEmpty()) {
00088         titles = title.split( "\"," );
00089         m_doc->setTitle(titles[0].mid(1));
00090     }
00091     // longer header
00092     else {
00093         titles = comment.split( "\"," );
00094         m_doc->setDocumentComment(titles[0]);
00095         m_doc->setTitle(title.mid(1));
00096     }
00097 
00098     wordCount = titles[1].section( ',', 0, 0 ).toInt();
00099 
00100     inputStream.readLine();
00101 
00102     lang1 = inputStream.readLine();
00103     languages = lang1.split( "\"," );
00104 
00105     m_doc->appendIdentifier();
00106     m_doc->identifier(0).setLocale( languages[0].mid( 1 ) );
00107     m_doc->identifier(0).setName( languages[0].mid( 1 ) );
00108     m_doc->appendIdentifier();
00109     m_doc->identifier(1).setLocale( languages[1].mid( 1 ) );
00110     m_doc->identifier(1).setName( languages[1].mid( 1 ) );
00111 
00112     while ( !temp.contains("8. Lernhilfe") ) {
00113         temp = inputStream.readLine(); //DO NOT translate
00114     }
00115 
00116     for ( i = 0; i <= 14; i++ ) {
00117         inputStream.readLine();
00118     }
00119 
00120 
00121     for ( i = 0; i < wordCount - 1; i++ ) {
00122         int c = 0;
00123         expression.clear();
00124 
00125         while ( c < 2 ) {
00126             temp = inputStream.readLine();
00127             c+= temp.count( "\",", Qt::CaseSensitive );
00128             expression.append( temp );
00129             if ( c < 2 ) {
00130                 expression.append( " " );
00131             }
00132         }
00133 
00134         words = expression.split( "\"," );
00135         original = words[0].mid( 1 );
00136         translation = words[1].mid( 1 );
00137         lessonNumber = words[2].toInt() - 1;
00138 
00139         // fallback if it's not read correctly
00140         if (lessonNumber < 0) {
00141             lessonNumber = 0;
00142         }
00143 
00144         while(m_doc->lesson()->childContainerCount() < lessonNumber) {
00145             KEduVocLesson* lesson = new KEduVocLesson(i18n("Lesson %1", lessonNumber), m_doc->lesson());
00146             m_doc->lesson()->appendChildContainer(lesson);
00147         }
00148 
00149         KEduVocExpression* kve = new KEduVocExpression;
00150         kve->setTranslation( 0, original );
00151         kve->setTranslation( 1, translation );
00152 
00153         static_cast<KEduVocLesson*>(m_doc->lesson()->childContainer(lessonNumber))->appendEntry(kve);
00154 
00155         inputStream.readLine();
00156         inputStream.readLine();
00157     }
00158 
00159     inputStream.readLine();
00160     inputStream.readLine();
00161     inputStream.readLine();
00162 
00163     for ( int i = 0; !inputStream.atEnd() && i < lines; i++ ) {
00164         QString lessonDescr = inputStream.readLine();
00165         lessonDescr = lessonDescr.mid( 1, lessonDescr.length() - 2 );
00166         m_doc->lesson()->childContainer(i)->setName(lessonDescr);
00167         if ( lessonDescr.isEmpty() ) {
00168             break;
00169         }
00170         inputStream.readLine();
00171     }
00172 
00173     return true;
00174 }

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