libkdeedu/keduvocdocument
keduvoccsvwriter.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 #include "keduvoccsvwriter.h"
00019
00020 #include <QFile>
00021 #include <QTextStream>
00022
00023 #include <KLocale>
00024
00025 #include "keduvocdocument.h"
00026 #include "keduvocexpression.h"
00027
00028 KEduVocCsvWriter::KEduVocCsvWriter( QFile *file )
00029 {
00030
00031 m_outputFile = file;
00032 }
00033
00034
00035 bool KEduVocCsvWriter::writeDoc( KEduVocDocument *doc, const QString &generator )
00036 {
00037 Q_UNUSED( generator );
00038
00039 m_doc = doc;
00040
00041 QString separator = m_doc->csvDelimiter();
00042 ;
00043
00044 QTextStream outputStream;
00045 outputStream.setDevice( m_outputFile );
00046 outputStream.setCodec( "UTF-8" );
00047
00048 outputStream << i18nc( "@item:intable the title of the document will be written here", "Title:" ) << separator << m_doc->title() << "\n";
00049 outputStream << i18nc( "@item:intable the author will be written here", "Author:" ) << separator << m_doc->author() << "\n";
00050
00051 KEduVocExpression *expression;
00052 int idCount = m_doc->identifierCount();
00053 QString currentRow;
00054
00055 for ( int e = 0; e < m_doc->entryCount(); e++ ) {
00056 expression = m_doc->entry( e );
00057 currentRow = "";
00058 bool sep = false;
00059
00060 for ( int i = 0; i < idCount; i++ ) {
00061 if ( !sep )
00062 sep = true;
00063 else
00064 currentRow += separator;
00065
00066 currentRow += expression->translation( i ).text();
00067 }
00068
00069 if ( !currentRow.isEmpty() )
00070 outputStream << currentRow << "\n";
00071 }
00072
00073 return true;
00074 }
00075