libkdeedu/keduvocdocument
keduvoccsvwriter.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 export a KEduVocDocument to a delimited text file 00003 ----------------------------------------------------------------------- 00004 copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> 00005 00006 (C) 2007 Peter Hedlund <peter.hedlund@kdemail.net> 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "keduvoccsvwriter.h" 00019 00020 #include <QFile> 00021 #include <QTextStream> 00022 00023 #include <KLocale> 00024 00025 #include "keduvocdocument.h" 00026 #include "keduvoclesson.h" 00027 #include "keduvocexpression.h" 00028 00029 KEduVocCsvWriter::KEduVocCsvWriter( QFile *file ) 00030 { 00031 // the file must be already open 00032 m_outputFile = file; 00033 } 00034 00035 00036 bool KEduVocCsvWriter::writeDoc( KEduVocDocument *doc, const QString &generator ) 00037 { 00038 Q_UNUSED( generator ); 00039 00040 m_doc = doc; 00041 00042 QString separator = m_doc->csvDelimiter(); 00043 ; 00044 00045 QTextStream outputStream; 00046 outputStream.setDevice( m_outputFile ); 00047 outputStream.setCodec( "UTF-8" ); 00048 00049 outputStream << i18nc( "@item:intable the title of the document will be written here", "Title:" ) << separator << m_doc->title() << "\n"; 00050 outputStream << i18nc( "@item:intable the author will be written here", "Author:" ) << separator << m_doc->author() << "\n"; 00051 00052 KEduVocExpression *expression; 00053 int idCount = m_doc->identifierCount(); 00054 QString currentRow; 00055 00056 for ( int e = 0; e < m_doc->lesson()->entryCount(KEduVocLesson::Recursive); e++ ) { 00057 expression = m_doc->lesson()->entries(KEduVocLesson::Recursive).value( e ); 00058 currentRow = ""; 00059 bool sep = false; 00060 00061 for ( int i = 0; i < idCount; i++ ) { 00062 if ( !sep ) 00063 sep = true; 00064 else 00065 currentRow += separator; 00066 00067 currentRow += expression->translation( i )->text(); 00068 } 00069 00070 if ( !currentRow.isEmpty() ) 00071 outputStream << currentRow << "\n"; 00072 } 00073 00074 return true; 00075 } 00076
KDE 4.2 API Reference