CuteLogger
Fast and simple logging solution for Qt based applications
mltxmlchecker.h
1 /*
2  * Copyright (c) 2014-2021 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MLTXMLCHECKER_H
19 #define MLTXMLCHECKER_H
20 
21 #include <QXmlStreamReader>
22 #include <QXmlStreamWriter>
23 #include <QTemporaryFile>
24 #include <QString>
25 #include <QFileInfo>
26 #include <QStandardItemModel>
27 #include <QVector>
28 #include <QPair>
29 #include <QVersionNumber>
30 
31 class QUIDevice;
32 
33 class MltXmlChecker
34 {
35 public:
36 
37  enum {
38  ShotcutHashRole = Qt::UserRole + 1
39  };
40 
41  enum {
42  MissingColumn = 0,
43  ReplacementColumn,
44  ColumnCount
45  };
46 
47  MltXmlChecker();
48  bool check(const QString& fileName);
49  QString errorString() const;
50  bool needsGPU() const { return m_needsGPU; }
51  bool needsCPU() const { return m_needsCPU; }
52  bool hasEffects() const { return m_hasEffects; }
53  bool isCorrected() const { return m_isCorrected; }
54  bool isUpdated() const { return m_isUpdated; }
55  QTemporaryFile& tempFile() const { return *m_tempFile; }
56  QStandardItemModel& unlinkedFilesModel() { return m_unlinkedFilesModel; }
57  void setLocale();
58  bool usesLocale() const { return m_usesLocale; }
59  QString shotcutVersion() const { return m_shotcutVersion; }
60 
61 private:
62  typedef QPair<QString, QString> MltProperty;
63 
64  void readMlt();
65  void processProperties();
66  void checkInAndOutPoints();
67  bool checkNumericString(QString& value);
68  bool fixWebVfxPath(QString& resource);
69  bool readResourceProperty(const QString& name, QString& value);
70  void checkGpuEffects(const QString& mlt_service);
71  void checkCpuEffects(const QString& mlt_service);
72  void checkUnlinkedFile(const QString& mlt_service);
73  bool fixUnlinkedFile(QString& value);
74  void fixStreamIndex(MltProperty& property);
75  bool fixVersion1701WindowsPathBug(QString& value);
76  void checkIncludesSelf(QVector<MltProperty>& properties);
77  void checkLumaAlphaOver(const QString& mlt_service, QVector<MltProperty>& properties);
78  void replaceWebVfxCropFilters(QString& mlt_service, QVector<MltProperty>& properties);
79  void replaceWebVfxChoppyFilter(QString& mlt_service, QVector<MltProperty>& properties);
80  void checkForProxy(const QString& mlt_service, QVector<MltProperty>& properties);
81  bool checkMltVersion();
82 
83  QXmlStreamReader m_xml;
84  QXmlStreamWriter m_newXml;
85  bool m_needsGPU;
86  bool m_needsCPU;
87  bool m_hasEffects;
88  bool m_isCorrected;
89  bool m_isUpdated;
90  bool m_usesLocale;
91  QChar m_decimalPoint;
92  QScopedPointer<QTemporaryFile> m_tempFile;
93  bool m_numericValueChanged;
94  QFileInfo m_fileInfo;
95  QStandardItemModel m_unlinkedFilesModel;
96  QString mlt_class;
97  QVector<MltProperty> m_properties;
98  struct MltXmlResource {
99  QFileInfo info;
100  QString hash;
101  QString newHash;
102  QString newDetail;
103  QString prefix;
104  int audio_index, video_index;
105 
106  void clear() {
107  info.setFile(QString());
108  hash.clear();
109  newHash.clear();
110  newDetail.clear();
111  prefix.clear();
112  audio_index = video_index = -1;
113  }
114  } m_resource;
115  QVersionNumber m_mltVersion;
116  QString m_shotcutVersion;
117 };
118 
119 #endif // MLTXMLCHECKER_H