1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef CODEPORTING_H |
6 | #define CODEPORTING_H |
7 | |
8 | #include "common/widget/outputpane.h" |
9 | |
10 | #include <QProcess> |
11 | #include <QObject> |
12 | |
13 | class CodePorting : public QObject |
14 | { |
15 | Q_OBJECT |
16 | public: |
17 | enum PortingStatus { |
18 | kNoRuning, |
19 | kRuning, |
20 | kSuccessful, |
21 | kFailed |
22 | }; |
23 | |
24 | enum ReportItems { |
25 | kFilePath, |
26 | kCodeRange, |
27 | kKey, |
28 | kSuggestion, |
29 | kFileType, |
30 | kItemsCount |
31 | }; |
32 | |
33 | using Report = QMap<QString, QList<QStringList>>; |
34 | using ReportIterator = QMapIterator<QString, QList<QStringList>>; |
35 | |
36 | explicit CodePorting(QObject *parent = nullptr); |
37 | |
38 | bool start(const QString &projectSrcPath, const QString &srcCPU, const QString &buildDir, const QString &destCPU); |
39 | bool abort(); |
40 | |
41 | PortingStatus getStatus() const; |
42 | bool isRunning(); |
43 | const Report &getReport() const; |
44 | const QStringList &getSrcItemNames() const; |
45 | const QStringList &getLibItemNames() const; |
46 | |
47 | const QList<QStringList> getSourceReport() const; |
48 | const QList<QStringList> getDependLibReport() const; |
49 | |
50 | signals: |
51 | QString outputInformation(const QString &line, OutputPane::OutputFormat format, OutputPane::AppendMode mode = OutputPane::Normal); |
52 | void notifyPortingStatus(PortingStatus status); |
53 | |
54 | public slots: |
55 | private: |
56 | QString getPython(); |
57 | void resetUI(); |
58 | void updateStatus(PortingStatus _status); |
59 | QString parseReportPath(const QString &line); |
60 | OutputPane::AppendMode parseFormat(const QString &line); |
61 | bool parseReportFromFile(const QString &reportPath); |
62 | |
63 | QProcess process; |
64 | |
65 | QString pythonCmd; |
66 | Report report; |
67 | QString projSrcPath; |
68 | |
69 | PortingStatus status { kNoRuning }; |
70 | }; |
71 | |
72 | #endif // CODEPORTING_H |
73 | |