1
/***************************************************************************
2
* Copyright (C) 2004-2009 by Thomas Fischer *
3
* fischer@unix-ag.uni-kl.de *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
21
#include <qstringlist.h>
25
#include <fileexporterbibtex.h>
26
#include "fileexporterrtf.h"
31
FileExporterRTF::FileExporterRTF() : FileExporterToolchain(), m_latexLanguage( "english" ), m_latexBibStyle( "plain" )
33
laTeXFilename = QString( workingDir ).append( "/bibtex-to-rtf.tex" );
34
bibTeXFilename = QString( workingDir ).append( "/bibtex-to-rtf.bib" );
35
outputFilename = QString( workingDir ).append( "/bibtex-to-rtf.rtf" );
38
FileExporterRTF::~FileExporterRTF()
43
bool FileExporterRTF::save( QIODevice* iodevice, const File* bibtexfile, QStringList *errorLog )
48
QFile bibtexFile( bibTeXFilename );
49
if ( bibtexFile.open( IO_WriteOnly ) )
51
FileExporter * bibtexExporter = new FileExporterBibTeX();
52
result = bibtexExporter->save( &bibtexFile, bibtexfile, errorLog );
54
delete bibtexExporter;
58
result = generateRTF( iodevice, errorLog );
64
bool FileExporterRTF::save( QIODevice* iodevice, const Element* element, QStringList *errorLog )
69
QFile bibtexFile( bibTeXFilename );
70
if ( bibtexFile.open( IO_WriteOnly ) )
72
FileExporter * bibtexExporter = new FileExporterBibTeX();
73
result = bibtexExporter->save( &bibtexFile, element, errorLog );
75
delete bibtexExporter;
79
result = generateRTF( iodevice, errorLog );
85
void FileExporterRTF::setLaTeXLanguage( const QString& language )
87
m_latexLanguage = language;
90
void FileExporterRTF::setLaTeXBibliographyStyle( const QString& bibStyle )
92
m_latexBibStyle = bibStyle;
95
bool FileExporterRTF::generateRTF( QIODevice* iodevice, QStringList *errorLog )
97
QStringList cmdLines = QStringList::split( '|', "latex bibtex-to-rtf.tex|bibtex bibtex-to-rtf|latex bibtex-to-rtf.tex|latex2rtf bibtex-to-rtf.tex" );
99
if ( writeLatexFile( laTeXFilename ) && runProcesses( cmdLines, errorLog ) && writeFileToIODevice( outputFilename, iodevice ) )
105
bool FileExporterRTF::writeLatexFile( const QString &filename )
107
QFile latexFile( filename );
108
if ( latexFile.open( IO_WriteOnly ) )
110
QTextStream ts( &latexFile );
111
ts.setEncoding( QTextStream::UnicodeUTF8 );
112
ts << "\\documentclass{article}\n";
113
if ( kpsewhich( "t1enc.dfu" ) )
114
ts << "\\usepackage[T1]{fontenc}\n";
115
if ( kpsewhich( "babel.sty" ) )
116
ts << "\\usepackage[" << m_latexLanguage << "]{babel}\n";
117
if ( kpsewhich( "url.sty" ) )
118
ts << "\\usepackage{url}\n";
119
if ( m_latexBibStyle.startsWith( "apacite" ) && kpsewhich( "apacite.sty" ) )
120
ts << "\\usepackage[bibnewpage]{apacite}\n";
121
ts << "\\bibliographystyle{" << m_latexBibStyle << "}\n";
122
ts << "\\begin{document}\n";
123
ts << "\\nocite{*}\n";
124
ts << "\\bibliography{bibtex-to-rtf}\n";
125
ts << "\\end{document}\n";