• Skip to content
  • Skip to link menu
KDE 4.0 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 #include "keduvocgrade.h"
00035 
00036 KEduVocVokabelnReader::KEduVocVokabelnReader( QIODevice *file )
00037 {
00038     // the file must be already open
00039     m_inputFile = file;
00040     m_errorMessage = "";
00041 }
00042 
00043 
00044 bool KEduVocVokabelnReader::readDoc( KEduVocDocument *doc )
00045 {
00046     m_doc = doc;
00047 
00048     m_doc->setAuthor( "http://www.vokabeln.de" );
00049 
00050     QTextStream inputStream( m_inputFile );
00051     inputStream.setCodec( "ISO-8859-1" );
00052     inputStream.setAutoDetectUnicode( false );
00053     inputStream.seek( 0 );
00054 
00055     QString title;
00056     QString lang1;
00057     QString lang2;
00058     QString expression;
00059     QString original;
00060     QString translation;
00061     QString lessonDescr;
00062     QString temp;
00063     QString comment;
00064 
00065     int i;
00066     int wordCount;
00067     int lesson;
00068 
00069     int lines = 10000;
00070 
00071     QStringList titles;
00072     QStringList languages;
00073     QStringList words;
00074 
00075     temp = inputStream.readLine();
00076 
00077     if ( temp.startsWith ( QChar::fromLatin1 ( '"' ) ) ) {
00078         while ( temp != QChar::fromLatin1('0') ) {
00079             if ( title.isEmpty() ) {
00080                 title = temp;
00081             } else {
00082                 comment.append( temp.append('\n') );
00083             }
00084             temp = inputStream.readLine();
00085         }
00086     }
00087 
00088     // 1 line header
00089     if (comment.isEmpty()) {
00090         titles = title.split( "\"," );
00091         m_doc->setTitle(titles[0].mid(1));
00092     }
00093     // longer header
00094     else {
00095         titles = comment.split( "\"," );
00096         m_doc->setDocumentComment(titles[0]);
00097         m_doc->setTitle(title.mid(1));
00098     }
00099 
00100     wordCount = titles[1].section( ',', 0, 0 ).toInt();
00101 
00102     inputStream.readLine();
00103 
00104     lang1 = inputStream.readLine();
00105     languages = lang1.split( "\"," );
00106 
00107     m_doc->appendIdentifier();
00108     m_doc->identifier(0).setLocale( languages[0].mid( 1 ) );
00109     m_doc->identifier(0).setName( languages[0].mid( 1 ) );
00110     m_doc->appendIdentifier();
00111     m_doc->identifier(1).setLocale( languages[1].mid( 1 ) );
00112     m_doc->identifier(1).setName( languages[1].mid( 1 ) );
00113 
00114     while ( !temp.contains("8. Lernhilfe") ) {
00115         temp = inputStream.readLine(); //DO NOT translate
00116     }
00117 
00118     for ( i = 0; i <= 14; i++ ) {
00119         inputStream.readLine();
00120     }
00121 
00122     for ( i = 0; i < wordCount - 1; i++ ) {
00123         int c = 0;
00124         expression.clear();
00125 
00126         while ( c < 2 ) {
00127             temp = inputStream.readLine();
00128             c+= temp.count( "\",", Qt::CaseSensitive );
00129             expression.append( temp );
00130             if ( c < 2 ) {
00131                 expression.append( " " );
00132             }
00133         }
00134 
00135         words = expression.split( "\"," );
00136         original = words[0].mid( 1 );
00137         translation = words[1].mid( 1 );
00138         lesson = words[2].toInt() - 1;
00139 
00140         KEduVocExpression kve;
00141         kve.setTranslation( 0, original );
00142         kve.setTranslation( 1, translation );
00143         kve.translation( 1 ).gradeFrom( 0 ).setGrade( 0 );
00144         kve.translation( 0 ).gradeFrom( 1 ).setGrade( 0 );
00145         kve.setLesson( lesson );
00146 
00147         m_doc->appendEntry( &kve );
00148 
00149         inputStream.readLine();
00150         inputStream.readLine();
00151     }
00152 
00153     inputStream.readLine();
00154     inputStream.readLine();
00155     inputStream.readLine();
00156 
00157     for ( int i = 0; !inputStream.atEnd() && i < lines; i++ ) {
00158         lessonDescr = inputStream.readLine();
00159         lessonDescr = lessonDescr.mid( 1, lessonDescr.length() - 2 );
00160         if ( !lessonDescr.isEmpty() )
00161             m_doc->appendLesson( lessonDescr );
00162         else
00163             break;
00164         inputStream.readLine();
00165     }
00166 
00167     return true;
00168 }

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