libkdeedu/keduvocdocument
keduvocvokabelnreader.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00087 if (comment.isEmpty()) {
00088 titles = title.split( "\"," );
00089 m_doc->setTitle(titles[0].mid(1));
00090 }
00091
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();
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
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 }