• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
exportdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #include "exportdialog.h"
15 
16 #include <parleydocument.h>
17 #include <keduvocdocument.h>
18 #include <keduvockvtml2writer.h>
19 
20 #include <KStandardDirs>
21 #include <KUrl>
22 #include <KDebug>
23 #include <KFileDialog>
24 #include <KMessageBox>
25 
26 #include <string.h>
27 #include <libxml/xmlmemory.h>
28 #include <libxml/debugXML.h>
29 #include <libxml/HTMLtree.h>
30 #include <libxml/xmlIO.h>
31 #include <libxml/xinclude.h>
32 #include <libxml/catalog.h>
33 #include <libxslt/xslt.h>
34 #include <libxslt/xsltInternals.h>
35 #include <libxslt/transform.h>
36 #include <libxslt/xsltutils.h>
37 
38 ExportDialog::ExportDialog(ParleyDocument *doc, QWidget *parent) : KDialog(parent)
39 {
40  m_doc = doc;
41  m_parent = parent;
42 
43  ui = new Ui::ExportOptions();
44  ui->setupUi(mainWidget());
45 
46  setCaption(i18n("Export"));
47 }
48 
49 void ExportDialog::accept()
50 {
51  KDialog::accept();
52 
53  if (ui->csvRadio->isChecked()) {
56  QStringList defaultFilters = KEduVocDocument::pattern(KEduVocDocument::Writing).split('\n');
57  QString filter = defaultFilters.filter("csv").join("\n");
58  KUrl filename = getFileName(filter);
59  if (filename != KUrl()) {
60  m_doc->saveAs(filename);
61  }
62  return;
63  }
64 
65  QString xslFile;
66  if (ui->flashCardRadio->isChecked()) {
67  xslFile = KStandardDirs::locate("data", "parley/xslt/flashcards.xsl");
68  } else {
69  xslFile = KStandardDirs::locate("data", "parley/xslt/table.xsl");
70  }
71 
72  QString filter = "*.html|" + i18n("HTML document");
73  KUrl filename = getFileName(filter);
74  if (filename == KUrl()) {
75  return;
76  }
77 
78  kDebug() << "XSLT starting";
79 
80  xsltStylesheetPtr cur = NULL;
81  xmlDocPtr doc, res;
82 
83  xmlSubstituteEntitiesDefault(1);
84  xmlLoadExtDtdDefaultValue = 1;
85  cur = xsltParseStylesheetFile((const xmlChar*) xslFile.toLatin1().constData());
86 
87  doc = xmlParseDoc((const xmlChar*) m_doc->document()->toByteArray(m_doc->document()->generator()).constData());
88 
89  res = xsltApplyStylesheet(cur, doc, 0);
90  FILE* result = fopen(QFile::encodeName(filename.toLocalFile()).constData(), "w");
91  if (result != NULL) {
92  xsltSaveResultToFile(result, res, cur);
93  fclose(result);
94  } else {
95  KMessageBox::error(this, i18n("Could not write to file \"%1\"", filename.toLocalFile()));
96  }
97 
98  xsltFreeStylesheet(cur);
99  xmlFreeDoc(res);
100  xmlFreeDoc(doc);
101 
102  xsltCleanupGlobals();
103  xmlCleanupParser();
104 
105  kDebug() << "XSLT finished";
106 }
107 
108 KUrl ExportDialog::getFileName(const QString& filter)
109 {
110  return KFileDialog::getSaveUrl((m_doc->document()->url().fileName() == i18n("Untitled")) ? "" : m_doc->document()->url().toLocalFile(),
111  filter, m_parent, i18n("Export As"), KFileDialog::ConfirmOverwrite);
112 }
113 
114 #include "exportdialog.moc"
QWidget
ParleyDocument::document
KEduVocDocument * document()
Definition: parleydocument.cpp:97
KDialog
QStringList::join
QString join(const QString &separator) const
parleydocument.h
ParleyDocument
Definition: parleydocument.h:29
exportdialog.h
QByteArray::constData
const char * constData() const
QString
QStringList
QString::toLatin1
QByteArray toLatin1() const
QStringList::split
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
ExportDialog::ExportDialog
ExportDialog(ParleyDocument *doc, QWidget *parent=0)
Definition: exportdialog.cpp:38
QStringList::filter
QStringList filter(const QString &str, Qt::CaseSensitivity cs) const
ParleyDocument::saveAs
void saveAs(KUrl file=KUrl())
Definition: parleydocument.cpp:381
QFile::encodeName
QByteArray encodeName(const QString &fileName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal