libkdeedu/keduvocdocument
keduvoccsvreader.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 00003 create a KEduVocDocument from a text file 00004 00005 ----------------------------------------------------------------------- 00006 00007 begin : Sat Sep 06 11:00:53 MET 1999 00008 00009 copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> 00010 00011 (C) 2005, 2007 Peter Hedlund <peter.hedlund@kdemail.net> 00012 00013 ----------------------------------------------------------------------- 00014 00015 ***************************************************************************/ 00016 00017 /*************************************************************************** 00018 * * 00019 * This program is free software; you can redistribute it and/or modify * 00020 * it under the terms of the GNU General Public License as published by * 00021 * the Free Software Foundation; either version 2 of the License, or * 00022 * (at your option) any later version. * 00023 * * 00024 ***************************************************************************/ 00025 00026 #include "keduvoccsvreader.h" 00027 00028 #include <QIODevice> 00029 #include <QTextStream> 00030 00031 #include <klocale.h> 00032 00033 #include "keduvocdocument.h" 00034 #include "keduvocexpression.h" 00035 00036 KEduVocCsvReader::KEduVocCsvReader( QIODevice *file ) 00037 { 00038 // the file must be already open 00039 m_inputFile = file; 00040 m_errorMessage = ""; 00041 } 00042 00043 00044 bool KEduVocCsvReader::readDoc( KEduVocDocument *doc ) 00045 { 00046 m_doc = doc; 00047 00048 QString separator = m_doc->csvDelimiter(); 00049 00050 QTextStream inputStream( m_inputFile ); 00051 inputStream.setCodec( "UTF-8" ); 00052 inputStream.setAutoDetectUnicode( true ); 00053 inputStream.seek( 0 ); 00054 00055 int languageCount = 0; 00056 00057 while ( !inputStream.atEnd() ) { 00058 QString s = inputStream.readLine(); 00059 00060 if ( !s.simplified().isEmpty() ) { 00061 KEduVocExpression expression( s.split(separator) ); 00062 languageCount = qMax( languageCount, expression.translationIndices().count() ); 00063 m_doc->appendEntry( &expression ); 00064 } 00065 } 00066 00067 for ( int j = 0; j < languageCount; j++ ) 00068 { 00069 m_doc->appendIdentifier(); 00070 } 00071 00072 return true; 00073 }
KDE 4.0 API Reference