File indexing completed on 2024-05-12 05:10:12

0001 /***************************************************************************
0002     Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #ifndef TELLICO_HTMLEXPORTER_H
0026 #define TELLICO_HTMLEXPORTER_H
0027 
0028 #include "exporter.h"
0029 #include "../utils/stringset.h"
0030 
0031 #include <QStringList>
0032 #include <QHash>
0033 
0034 #include <libxml/xmlstring.h>
0035 
0036 class QCheckBox;
0037 
0038 extern "C" {
0039   struct _xmlNode;
0040 }
0041 
0042 class HtmlExporterTest;
0043 
0044 namespace Tellico {
0045   namespace Data {
0046     class Collection;
0047   }
0048   class XSLTHandler;
0049 
0050   namespace Export {
0051 
0052 /**
0053  * @author Robby Stephenson
0054  */
0055 class HTMLExporter : public Exporter {
0056 Q_OBJECT
0057 
0058 friend class ::HtmlExporterTest;
0059 
0060 public:
0061   HTMLExporter(Data::CollPtr coll);
0062   ~HTMLExporter();
0063 
0064   virtual bool exec() Q_DECL_OVERRIDE;
0065   virtual void reset() Q_DECL_OVERRIDE;
0066   virtual QString formatString() const Q_DECL_OVERRIDE;
0067   virtual QString fileFilter() const Q_DECL_OVERRIDE;
0068 
0069   virtual QWidget* widget(QWidget* parent) Q_DECL_OVERRIDE;
0070   virtual void readOptions(KSharedConfigPtr) Q_DECL_OVERRIDE;
0071   virtual void saveOptions(KSharedConfigPtr) Q_DECL_OVERRIDE;
0072 
0073   void setCollectionURL(const QUrl& url) { m_collectionURL = url; m_links.clear(); }
0074   void setXSLTFile(const QString& filename);
0075   void setEntryXSLTFile(const QString& filename);
0076   void setPrintHeaders(bool printHeaders) { m_printHeaders = printHeaders; }
0077   void setPrintGrouped(bool printGrouped) { m_printGrouped = printGrouped; }
0078   void setMaxImageSize(int w, int h) { m_imageWidth = w; m_imageHeight = h; }
0079   void setGroupBy(const QStringList& groupBy) { m_groupBy = groupBy; }
0080   void setSortTitles(const QStringList& l)
0081     { m_sort1 = l[0]; m_sort2 = l[1]; m_sort3 = l[2]; }
0082   void setColumns(const QStringList& columns) { m_columns = columns; }
0083   void setParseDOM(bool parseDOM) { m_parseDOM = parseDOM; reset(); }
0084   void setExportEntryFiles(bool exportEntryFiles) { m_exportEntryFiles = exportEntryFiles; }
0085   void setCustomHtml(const QString& html_) { m_customHtml = html_; }
0086 
0087   QString text();
0088 
0089 public Q_SLOTS:
0090   void slotCancel();
0091 
0092 private:
0093   void setFormattingOptions(Data::CollPtr coll);
0094   void writeImages(Data::CollPtr coll);
0095   bool writeEntryFiles();
0096   QUrl fileDir() const;
0097   QString fileDirName() const;
0098 
0099   void parseDOM(_xmlNode* node);
0100   QString handleLink(const QString& link);
0101   const xmlChar* handleLink(const xmlChar* link);
0102   QString analyzeInternalCSS(const QString& string);
0103   const xmlChar* analyzeInternalCSS(const xmlChar* string);
0104   bool copyFiles();
0105   bool loadXSLTFile();
0106   void createDir();
0107 
0108   XSLTHandler* m_handler;
0109   bool m_printHeaders : 1;
0110   bool m_printGrouped : 1;
0111   bool m_exportEntryFiles : 1;
0112   bool m_cancelled : 1;
0113   bool m_parseDOM : 1;
0114   bool m_checkCreateDir : 1;
0115   bool m_checkCommonFile : 1;
0116   int m_imageWidth;
0117   int m_imageHeight;
0118 
0119   QWidget* m_widget;
0120   QCheckBox* m_checkPrintHeaders;
0121   QCheckBox* m_checkPrintGrouped;
0122   QCheckBox* m_checkExportEntryFiles;
0123   QCheckBox* m_checkExportImages;
0124 
0125   QUrl m_collectionURL;
0126   QString m_xsltFile;
0127   QString m_xsltFilePath;
0128   QString m_dataDir;
0129   QStringList m_groupBy;
0130   QString m_sort1;
0131   QString m_sort2;
0132   QString m_sort3;
0133   QStringList m_columns;
0134   QString m_entryXSLTFile;
0135 
0136   QList<QUrl> m_files;
0137   QHash<QString, QString> m_links;
0138   StringSet m_copiedFiles;
0139   QString m_customHtml;
0140 };
0141 
0142   } // end namespace
0143 } // end namespace
0144 #endif