Changeset View
Changeset View
Standalone View
Standalone View
src/bugzillaintegration/libbugzilla/product.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2019 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library 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 GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef PRODUCT_H | ||||
22 | #define PRODUCT_H | ||||
23 | | ||||
24 | #include <QObject> | ||||
25 | | ||||
26 | #include "connection.h" | ||||
27 | | ||||
28 | namespace Bugzilla { | ||||
29 | | ||||
30 | class ProductVersion : public QObject | ||||
31 | { | ||||
32 | Q_OBJECT | ||||
33 | Q_PROPERTY(int id READ id WRITE setId CONSTANT) | ||||
34 | Q_PROPERTY(QString name READ name WRITE setName CONSTANT) | ||||
35 | Q_PROPERTY(bool active READ isActive WRITE setActive CONSTANT) | ||||
36 | public: | ||||
37 | int id() const { return m_id; } | ||||
38 | QString name() const { return m_name; } | ||||
39 | bool isActive() const { return m_active; } | ||||
40 | | ||||
41 | explicit ProductVersion(const QVariantHash &object, QObject *parent = nullptr); | ||||
42 | private: | ||||
43 | void setId(int id) { m_id = id; } | ||||
44 | void setName(const QString &name) { m_name = name; } | ||||
45 | void setActive(bool active) { m_active = active; } | ||||
46 | | ||||
47 | int m_id = -1; | ||||
48 | QString m_name = QString(); | ||||
49 | bool m_active = false; | ||||
50 | }; | ||||
51 | | ||||
52 | class ProductComponent : public QObject | ||||
53 | { | ||||
54 | Q_OBJECT | ||||
55 | Q_PROPERTY(int id READ id WRITE setId CONSTANT) | ||||
56 | Q_PROPERTY(QString name READ name WRITE setName CONSTANT) | ||||
57 | public: | ||||
58 | int id() const { return m_id; } | ||||
59 | QString name() const { return m_name; } | ||||
60 | | ||||
61 | explicit ProductComponent(const QVariantHash &object, QObject *parent = nullptr); | ||||
62 | private: | ||||
63 | void setId(int id) { m_id = id; } | ||||
64 | void setName(const QString &name) { m_name = name; } | ||||
65 | | ||||
66 | int m_id = -1; | ||||
67 | QString m_name = QString(); | ||||
68 | }; | ||||
69 | | ||||
70 | class Product : public QObject | ||||
71 | { | ||||
72 | Q_OBJECT | ||||
73 | Q_PROPERTY(bool is_active READ isActive WRITE setActive CONSTANT) | ||||
74 | Q_PROPERTY(QList<Bugzilla::ProductComponent *> components READ getComponents WRITE setComponents CONSTANT) | ||||
75 | Q_PROPERTY(QList<Bugzilla::ProductVersion *> versions READ versions WRITE setVersions CONSTANT) | ||||
76 | public: | ||||
77 | typedef QSharedPointer<Product> Ptr; | ||||
78 | | ||||
79 | explicit Product(const QVariantHash &object, | ||||
80 | const Connection &connection = Bugzilla::connection(), | ||||
81 | QObject *parent = nullptr); | ||||
82 | ~Product(); | ||||
83 | | ||||
84 | QStringList components() const; | ||||
85 | QStringList allVersions() const; | ||||
86 | QStringList activeVersions() const; | ||||
87 | QStringList inactiveVersions() const; | ||||
88 | | ||||
89 | bool isActive() const; | ||||
90 | void setActive(bool active); | ||||
91 | | ||||
92 | QList<ProductComponent *> getComponents() const; | ||||
93 | void setComponents(const QList<ProductComponent *> &components); | ||||
94 | | ||||
95 | QList<ProductVersion *> versions() const; | ||||
96 | void setVersions(const QList<ProductVersion *> &versions); | ||||
97 | | ||||
98 | private: | ||||
99 | const Connection &m_connection; | ||||
100 | | ||||
101 | bool m_active = false; | ||||
102 | QList<ProductComponent *> m_components; | ||||
103 | QList<ProductVersion *> m_versions; | ||||
104 | }; | ||||
105 | | ||||
106 | class ProductClient | ||||
107 | { | ||||
108 | public: | ||||
109 | explicit ProductClient(const Connection &connection = Bugzilla::connection()); | ||||
110 | | ||||
111 | // Gets a single Product by its name | ||||
112 | Product::Ptr get(KJob *kjob); | ||||
113 | KJob *get(const QString &idOrName); | ||||
114 | | ||||
115 | private: | ||||
116 | const Connection &m_connection; | ||||
117 | }; | ||||
118 | | ||||
119 | | ||||
120 | } // namespace Bugzilla | ||||
121 | | ||||
122 | Q_DECLARE_METATYPE(Bugzilla::ProductComponent *) | ||||
123 | Q_DECLARE_METATYPE(QList<Bugzilla::ProductComponent *>) | ||||
124 | | ||||
125 | #endif // PRODUCT_H |