libkdeedu/keduvocdocument
keduvocwqlreader.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 #include "keduvocwqlreader.h"
00020
00021 #include <QTextStream>
00022 #include <QIODevice>
00023 #include <QFont>
00024
00025 #include <klocale.h>
00026
00027 #include "keduvocdocument.h"
00028 #include "keduvocexpression.h"
00029
00030 KEduVocWqlReader::KEduVocWqlReader( QIODevice *file )
00031 {
00032
00033 m_inputFile = file;
00034 m_errorMessage = "";
00035 }
00036
00037
00038 bool KEduVocWqlReader::readDoc( KEduVocDocument *doc )
00039 {
00040 m_doc = doc;
00041
00042 QTextStream inputStream( m_inputFile );
00043 inputStream.setCodec( "Windows-1252" );
00044 inputStream.setAutoDetectUnicode( false );
00045 inputStream.seek( 0 );
00046
00047 QString s = "";
00048 s=inputStream.readLine();
00049 if ( s != "WordQuiz" ) {
00050 m_errorMessage = i18n( "This does not appear to be a (K)WordQuiz file" );
00051 return false;
00052 }
00053 s = inputStream.readLine();
00054 s = s.left( 1 );
00055 int iFV = s.toInt( 0 );
00056 if ( iFV != 5 ) {
00057 m_errorMessage = i18n( "Only files created by WordQuiz 5.x or later can be opened" );
00058 return false;
00059 }
00060
00061 m_errorMessage = i18n( "Error while reading file" );
00062
00063 while ( !inputStream.atEnd() && inputStream.readLine() != "[Font Info]" );
00064 if ( inputStream.atEnd() )
00065 return false;
00066 s = inputStream.readLine();
00067 int p = s.indexOf( "=", 0 );
00068 QString fam = s.right( s.length() - ( p + 1 ) );
00069 fam = fam.mid( 1, fam.length() - 2 );
00070
00071 s = inputStream.readLine();
00072 p = s.indexOf( "=", 0 );
00073 s = s.right( s.length() - ( p + 1 ) );
00074
00075
00076 s = inputStream.readLine();
00077 p = s.indexOf( "=", 0 );
00078 s = s.right( s.length() - ( p + 1 ) );
00079 int b = 0;
00080 if ( s == "1" ) {
00081 b = QFont::Bold;
00082 }
00083
00084 s = inputStream.readLine();
00085 p = s.indexOf( "=", 0 );
00086 s = s.right( s.length() - ( p + 1 ) );
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 while ( !inputStream.atEnd() && inputStream.readLine() != "[Grid Info]" );
00098 if ( inputStream.atEnd() )
00099 return false;
00100 inputStream.readLine();
00101
00102 s = inputStream.readLine();
00103 p = s.indexOf( "=", 0 );
00104 s = s.right( s.length() - ( p + 1 ) );
00105 m_doc->setSizeHint( 0, s.toInt() );
00106
00107 s = inputStream.readLine();
00108 p = s.indexOf( "=", 0 );
00109 s = s.right( s.length() - ( p + 1 ) );
00110 m_doc->setSizeHint( 1, s.toInt() );
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 while ( !inputStream.atEnd() && inputStream.readLine() != "[Vocabulary]" );
00139 if ( inputStream.atEnd() )
00140 return false;
00141 s = inputStream.readLine();
00142 p = s.indexOf( " [", 0 );
00143 s = s.left( p );
00144 s = s.simplified();
00145 m_doc->appendIdentifier();
00146 m_doc->identifier(0).setLocale( s );
00147 m_doc->identifier(0).setName( s );
00148 s = inputStream.readLine();
00149 m_doc->appendIdentifier();
00150 m_doc->identifier(1).setLocale( s );
00151 m_doc->identifier(1).setName( s );
00152
00153 while ( !s.isNull() ) {
00154 s = inputStream.readLine();
00155 p = s.indexOf( "[", 0 );
00156
00157
00158 s = s.left( p );
00159 s = s.simplified();
00160
00161 QString b;
00162 b = inputStream.readLine();
00163
00164 KEduVocExpression expr = KEduVocExpression( s );
00165 expr.setTranslation( 1, b );
00166 m_doc->appendEntry( &expr );
00167 }
00168 return true;
00169 }