parley
exportdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "exportdialog.h"
00015
00016 #include <parleydocument.h>
00017 #include <keduvocdocument.h>
00018 #include <keduvockvtml2writer.h>
00019
00020 #include <KStandardDirs>
00021 #include <KUrl>
00022 #include <KDebug>
00023 #include <KFileDialog>
00024
00025 #include <string.h>
00026 #include <libxml/xmlmemory.h>
00027 #include <libxml/debugXML.h>
00028 #include <libxml/HTMLtree.h>
00029 #include <libxml/xmlIO.h>
00030 #include <libxml/DOCBparser.h>
00031 #include <libxml/xinclude.h>
00032 #include <libxml/catalog.h>
00033 #include <libxslt/xslt.h>
00034 #include <libxslt/xsltInternals.h>
00035 #include <libxslt/transform.h>
00036 #include <libxslt/xsltutils.h>
00037
00038 ExportDialog::ExportDialog(ParleyDocument *doc, QWidget *parent) : KDialog(parent)
00039 {
00040 m_doc = doc;
00041 m_parent = parent;
00042
00043 ui = new Ui::ExportOptions();
00044 ui->setupUi(mainWidget());
00045
00046 setCaption(i18n("Export"));
00047 }
00048
00049 void ExportDialog::accept()
00050 {
00051 KDialog::accept();
00052
00053 if (ui->csvRadio->isChecked()) {
00056 QStringList defaultFilters = KEduVocDocument::pattern(KEduVocDocument::Writing).split('\n');
00057 QString filter = defaultFilters.filter("csv").join("\n");
00058 KUrl filename = getFileName(filter);
00059 if(filename != KUrl()) {
00060 m_doc->saveAs(filename);
00061 }
00062 return;
00063 }
00064
00065 QString xslFile;
00066 if (ui->flashCardRadio->isChecked()) {
00067 xslFile = KStandardDirs::locate( "data", "parley/xslt/flashcards.xsl");
00068 } else {
00069 xslFile = KStandardDirs::locate( "data", "parley/xslt/table.xsl");
00070 }
00071
00072 QString filter = "*.html|" + i18n("HTML document");
00073 KUrl filename = getFileName(filter);
00074 if(filename == KUrl()) {
00075 return;
00076 }
00077
00078 kDebug() << "XSLT starting";
00079
00080 xsltStylesheetPtr cur = NULL;
00081 xmlDocPtr doc, res;
00082
00083 xmlSubstituteEntitiesDefault(1);
00084 xmlLoadExtDtdDefaultValue = 1;
00085 cur = xsltParseStylesheetFile((const xmlChar*) xslFile.toLatin1().constData());
00086
00087 doc = xmlParseDoc( (const xmlChar*) m_doc->document()->toByteArray(m_doc->document()->generator()).constData() );
00088
00089 res = xsltApplyStylesheet(cur, doc, 0);
00090 FILE* result = fopen( (const char*) filename.toLocalFile().toLatin1(), "w");
00091 xsltSaveResultToFile(result, res, cur);
00092 fclose(result);
00093
00094 xsltFreeStylesheet(cur);
00095 xmlFreeDoc(res);
00096 xmlFreeDoc(doc);
00097
00098 xsltCleanupGlobals();
00099 xmlCleanupParser();
00100
00101 kDebug() << "XSLT finished";
00102 }
00103
00104 KUrl ExportDialog::getFileName(const QString& filter)
00105 {
00106
00107 KFileDialog dlg( (m_doc->document()->url().fileName() == i18n("Untitled")) ? "": m_doc->document()->url().toLocalFile(), filter, m_parent );
00108 dlg.setOperationMode( KFileDialog::Saving );
00109 dlg.setMode( KFile::File );
00110 dlg.setWindowTitle(i18n("Export As"));
00111 if (dlg.exec() != QDialog::Accepted) {
00112 return KUrl();
00113 }
00114
00115 return dlg.selectedFile();
00116 }
00117
00118 #include "exportdialog.moc"