1 /************************************************************************ 2 ** 3 ** Copyright (C) 2014-2019 Kevin B. Hendricks, Stratford Ontario Canada 4 ** 5 ** This file is part of Sigil. 6 ** 7 ** Sigil 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 3 of the License, or 10 ** (at your option) any later version. 11 ** 12 ** Sigil is distributed in the hope that it will be useful, 13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ** GNU General Public License for more details. 16 ** 17 ** You should have received a copy of the GNU General Public License 18 ** along with Sigil. If not, see <http://www.gnu.org/licenses/>. 19 ** 20 *************************************************************************/ 21 22 #ifndef PLUGINRUNNER_H 23 #define PLUGINRUNNER_H 24 25 #include <QString> 26 #include <QStringList> 27 #include <QDialog> 28 #include <QProgressBar> 29 #include <QProcess> 30 // #include <QDebug> 31 32 #include "Misc/TempFolder.h" 33 #include "Misc/ValidationResult.h" 34 #include "ResourceObjects/CSSResource.h" 35 #include "ResourceObjects/FontResource.h" 36 #include "ResourceObjects/HTMLResource.h" 37 #include "ResourceObjects/ImageResource.h" 38 #include "ResourceObjects/MiscTextResource.h" 39 #include "ResourceObjects/SVGResource.h" 40 #include "ResourceObjects/OPFResource.h" 41 #include "ResourceObjects/NCXResource.h" 42 #include "ResourceObjects/VideoResource.h" 43 #include "ResourceObjects/AudioResource.h" 44 #include "ResourceObjects/VideoResource.h" 45 #include "ResourceObjects/XMLResource.h" 46 47 #include "ui_PluginRunner.h" 48 49 class MainWindow; 50 class TabManager; 51 class Book; 52 class BookBrowser; 53 class FolderKeeper; 54 class Resource; 55 class OPFResource; 56 class NCXResource; 57 class TempFolder; 58 59 class PluginRunner : public QDialog 60 61 { 62 Q_OBJECT 63 64 public: 65 enum FileInfoFields { 66 hrefField = 0, 67 idField = 1, 68 mimeField = 2 69 }; 70 71 PluginRunner(TabManager *tabMgr, QWidget *parent); 72 ~PluginRunner(); 73 74 static QStringList SupportedEngines(); 75 getPluginType()76 QString getPluginType() { return m_pluginType; } getResult()77 QString getResult() { return m_result; } getValidationErrorCount()78 int getValidationErrorCount() { return m_validationResults.count(); } 79 80 public slots: 81 int exec(const QString &name); 82 void reject(); 83 84 private slots: 85 void startPlugin(); 86 void cancelPlugin(); 87 void processError(); 88 void processError(QProcess::ProcessError error); 89 void processOutput(); 90 void pluginFinished(int exitcode, QProcess::ExitStatus exitstatus ); 91 void showConsole(); 92 93 private: 94 95 bool processResultXML(); 96 bool checkIsWellFormed(); 97 bool deleteFiles(const QStringList &); 98 bool addFiles(const QStringList &); 99 bool modifyFiles(const QStringList &); 100 void writeSigilCFG(); 101 102 103 void connectSignalsToSlots(); 104 105 QProcess m_process; 106 107 MainWindow *m_mainWindow; 108 TabManager *m_tabManager; 109 QSharedPointer<Book> m_book; 110 BookBrowser *m_bookBrowser; 111 112 TempFolder m_folder; 113 QString m_outputDir; 114 115 QString m_launcherPath; 116 QString m_enginePath; 117 QString m_engine; 118 QString m_pluginName; 119 QString m_pluginPath; 120 QString m_pluginsFolder; 121 QString m_bookRoot; 122 QString m_pluginType; 123 QString m_pluginAutoClose; 124 QByteArray m_pluginOutput; 125 QString m_algorithm; 126 127 QStringList m_filesToDelete; 128 QStringList m_filesToAdd; 129 QStringList m_filesToModify; 130 QList<ValidationResult> m_validationResults; 131 QString m_result; 132 133 int m_xhtml_net_change; 134 135 QHash <QString, Resource *> m_hrefToRes; 136 QHash <QString, Resource *> m_xhtmlFiles; 137 138 bool m_ready; 139 140 static const QString SEP; 141 static const QString OPFFILEINFO; 142 static const QString NCXFILEINFO; 143 static const QStringList CHANGESTAGS; 144 145 Ui::PluginRunner ui; 146 147 }; 148 149 #endif 150