1 /*
2     SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #ifndef PRODUCT_H
8 #define PRODUCT_H
9 
10 #include <QObject>
11 
12 #include "connection.h"
13 
14 namespace Bugzilla
15 {
16 class ProductVersion : public QObject
17 {
18     Q_OBJECT
Q_PROPERTY(int id READ id WRITE setId)19     Q_PROPERTY(int id READ id WRITE setId)
20     Q_PROPERTY(QString name READ name WRITE setName)
21     Q_PROPERTY(bool is_active READ isActive WRITE setActive)
22 public:
23     int id() const
24     {
25         return m_id;
26     }
name()27     QString name() const
28     {
29         return m_name;
30     }
isActive()31     bool isActive() const
32     {
33         return m_active;
34     }
35 
36     explicit ProductVersion(const QVariantHash &object, QObject *parent = nullptr);
37 
38 private:
setId(int id)39     void setId(int id)
40     {
41         m_id = id;
42     }
setName(const QString & name)43     void setName(const QString &name)
44     {
45         m_name = name;
46     }
setActive(bool active)47     void setActive(bool active)
48     {
49         m_active = active;
50     }
51 
52     int m_id = -1;
53     QString m_name = QString();
54     bool m_active = false;
55 };
56 
57 class ProductComponent : public QObject
58 {
59     Q_OBJECT
Q_PROPERTY(int id READ id WRITE setId)60     Q_PROPERTY(int id READ id WRITE setId)
61     Q_PROPERTY(QString name READ name WRITE setName)
62 public:
63     int id() const
64     {
65         return m_id;
66     }
name()67     QString name() const
68     {
69         return m_name;
70     }
71 
72     explicit ProductComponent(const QVariantHash &object, QObject *parent = nullptr);
73 
74 private:
setId(int id)75     void setId(int id)
76     {
77         m_id = id;
78     }
setName(const QString & name)79     void setName(const QString &name)
80     {
81         m_name = name;
82     }
83 
84     int m_id = -1;
85     QString m_name = QString();
86 };
87 
88 class Product : public QObject
89 {
90     Q_OBJECT
91     Q_PROPERTY(bool is_active READ isActive WRITE setActive)
92     Q_PROPERTY(QList<Bugzilla::ProductComponent *> components READ components WRITE setComponents)
93     Q_PROPERTY(QList<Bugzilla::ProductVersion *> versions READ versions WRITE setVersions)
94 public:
95     typedef QSharedPointer<Product> Ptr;
96 
97     explicit Product(const QVariantHash &object, const Connection &connection = Bugzilla::connection(), QObject *parent = nullptr);
98     ~Product();
99 
100     bool isActive() const;
101     void setActive(bool active);
102 
103     QList<ProductComponent *> components() const;
104     void setComponents(const QList<ProductComponent *> &components);
105 
106     QList<ProductVersion *> versions() const;
107     void setVersions(const QList<ProductVersion *> &versions);
108 
109     // Convenience methods to get useful content out of the
110     QStringList componentNames() const;
111     QStringList allVersions() const;
112     QStringList inactiveVersions() const;
113 
114 private:
115     static void registerVariantConverters();
116 
117     const Connection &m_connection;
118 
119     bool m_active = false;
120     QList<ProductComponent *> m_components;
121     QList<ProductVersion *> m_versions;
122 };
123 
124 } // namespace Bugzilla
125 
126 Q_DECLARE_METATYPE(Bugzilla::ProductComponent *)
127 Q_DECLARE_METATYPE(QList<Bugzilla::ProductComponent *>)
128 Q_DECLARE_METATYPE(Bugzilla::ProductVersion *)
129 Q_DECLARE_METATYPE(QList<Bugzilla::ProductVersion *>)
130 
131 #endif // PRODUCT_H
132