1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef CONFIGUTIL_H |
6 | #define CONFIGUTIL_H |
7 | |
8 | #include "services/project/projectservice.h" |
9 | |
10 | #include <QObject> |
11 | #include <QVector> |
12 | #include <QMap> |
13 | |
14 | namespace config { |
15 | |
16 | struct ItemInfo { |
17 | QString name; |
18 | QString path; |
19 | |
20 | friend QDataStream &operator<<(QDataStream &stream, const ItemInfo &data) |
21 | { |
22 | stream << data.name; |
23 | stream << data.path; |
24 | |
25 | return stream; |
26 | } |
27 | |
28 | friend QDataStream &operator>>(QDataStream &stream, ItemInfo &data) |
29 | { |
30 | stream >> data.name; |
31 | stream >> data.path; |
32 | |
33 | return stream; |
34 | } |
35 | |
36 | void clear() |
37 | { |
38 | name.clear(); |
39 | path.clear(); |
40 | } |
41 | }; |
42 | |
43 | struct ConfigureParam { |
44 | QString kit; |
45 | QString language; |
46 | QString projectPath; |
47 | ItemInfo jsVersion; |
48 | |
49 | friend QDataStream &operator<<(QDataStream &stream, const ConfigureParam &data) |
50 | { |
51 | stream << data.kit; |
52 | stream << data.language; |
53 | stream << data.projectPath; |
54 | stream << data.jsVersion; |
55 | |
56 | return stream; |
57 | } |
58 | |
59 | friend QDataStream &operator>>(QDataStream &stream, ConfigureParam &data) |
60 | { |
61 | stream >> data.kit; |
62 | stream >> data.language; |
63 | stream >> data.projectPath; |
64 | stream >> data.jsVersion; |
65 | |
66 | return stream; |
67 | } |
68 | |
69 | void clear() |
70 | { |
71 | kit.clear(); |
72 | language.clear(); |
73 | projectPath.clear(); |
74 | jsVersion.clear(); |
75 | } |
76 | }; |
77 | |
78 | class ConfigUtilPrivate; |
79 | class ConfigUtil final: public QObject |
80 | { |
81 | Q_OBJECT |
82 | public: |
83 | static ConfigUtil *instance(); |
84 | |
85 | ConfigUtil(const ConfigUtil &) = delete; |
86 | ConfigUtil &operator=(const ConfigUtil &) = delete; |
87 | |
88 | QString getConfigPath(const QString &projectPath); |
89 | |
90 | ConfigureParam *getConfigureParamPointer(); |
91 | |
92 | bool getProjectInfo(const ConfigureParam *param, dpfservice::ProjectInfo &info); |
93 | |
94 | void readConfig(const QString &filePath, ConfigureParam ¶m); |
95 | void saveConfig(const QString &filePath, const ConfigureParam ¶m); |
96 | |
97 | void updateProjectInfo(dpfservice::ProjectInfo &info, const ConfigureParam *param); |
98 | signals: |
99 | |
100 | private: |
101 | explicit ConfigUtil(QObject *parent = nullptr); |
102 | ~ConfigUtil(); |
103 | |
104 | ConfigUtilPrivate *const d; |
105 | }; |
106 | |
107 | } //namespace config |
108 | |
109 | #endif // CONFIGUTIL_H |
110 |