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

libkdeedu/keduvocdocument

keduvocwqlreader.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                      read a KEduVocDocument from a WQL file
00003     -----------------------------------------------------------------------
00004     copyright     : (C) 2004, 2007, 2008 Peter Hedlund <peter.hedlund@kdemail.net>
00005                     (C) 2005 Eric Pignet
00006                     (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
00007 
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "keduvocwqlreader.h"
00020 
00021 #include <QTextStream>
00022 #include <QIODevice>
00023 #include <QFont>
00024 
00025 #include <KLocale>
00026 
00027 #include "keduvocdocument.h"
00028 #include "keduvocexpression.h"
00029 
00030 KEduVocWqlReader::KEduVocWqlReader( QIODevice *file )
00031 {
00032     // the file must be already open
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" ); //("ISO-8851-1");
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     //int ps = s.toInt(0);
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     //bool it = (s == "1");
00088 
00089     //m_doc->setFont(new QFont(fam, ps, b, it));
00090 
00091     /* TODO
00092       while (inputStream.readLine() != "[Character Info]");
00093       s = inputStream.readLine();
00094       p = s.find("=", 0);
00095       m_specialCharacters = s.right(s.length() - (p + 1));
00096     */
00097     while ( !inputStream.atEnd() && inputStream.readLine() != "[Grid Info]" ) ;
00098     if ( inputStream.atEnd() )
00099         return false;
00100     inputStream.readLine(); //skip value for width of row headers
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     /* TODO
00113       s = inputStream.readLine();
00114       p = s.find("=", 0);
00115       s = s.right(s.length() - (p + 1));
00116       m_numRows = (s.toInt() - 1); //We need to reduce by one since the header is not included
00117       // Selection
00118       s = inputStream.readLine();
00119       p = s.find("=", 0);
00120       s = s.right(s.length() - (p + 1));
00121       m_topLeft =s.toInt(0, 10) - 1;
00122 
00123       s = inputStream.readLine();
00124       p = s.find("=", 0);
00125       s = s.right(s.length() - (p + 1));
00126       m_topRight =s.toInt(0, 10) - 1;
00127 
00128       s = inputStream.readLine();
00129       p = s.find("=", 0);
00130       s = s.right(s.length() - (p + 1));
00131       m_bottomLeft =s.toInt(0, 10) - 1;
00132 
00133       s = inputStream.readLine();
00134       p = s.find("=", 0);
00135       s = s.right(s.length() - (p + 1));
00136       m_bottomRight =s.toInt(0, 10) - 1 ;
00137     */
00138     while ( !inputStream.atEnd() && inputStream.readLine() != "[Vocabulary]" ) ;
00139     if ( inputStream.atEnd() )
00140         return false;
00141 
00142     KEduVocLesson* lesson = new KEduVocLesson( i18n("Vocabulary"), m_doc->lesson());
00143     m_doc->lesson()->appendChildContainer(lesson);
00144 
00145     s = inputStream.readLine();
00146     p = s.indexOf( "   [", 0 );
00147     s = s.left( p );
00148     s = s.simplified();
00149     m_doc->appendIdentifier();
00150     m_doc->identifier(0).setLocale( s );
00151     m_doc->identifier(0).setName( s );
00152     s = inputStream.readLine();
00153     m_doc->appendIdentifier();
00154     m_doc->identifier(1).setLocale( s );
00155     m_doc->identifier(1).setName( s );
00156 
00157     while ( !s.isNull() ) {
00158         s = inputStream.readLine();
00159         p = s.indexOf( "[", 0 );
00160         //QString r = s.mid(p + 1, 10);
00161         //int h = r.toInt();
00162         s = s.left( p );
00163         s = s.simplified();
00164         QString b;
00165         b = inputStream.readLine();
00166 
00167         KEduVocExpression * expr = new KEduVocExpression( s );
00168         expr->setTranslation( 1, b );
00169         lesson->appendEntry( expr );
00170     }
00171     return true;
00172 }

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