Changeset View
Changeset View
Standalone View
Standalone View
src/bugzillaintegration/libbugzilla/comment.cpp
- 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 | #include "comment.h" | ||||
22 | | ||||
23 | namespace Bugzilla { | ||||
24 | | ||||
25 | Comment::Comment(const QVariantHash &object, QObject *parent) | ||||
26 | : QObject(parent) | ||||
27 | { | ||||
28 | for (auto it = object.constBegin(); it != object.constEnd(); ++it) { | ||||
29 | setProperty(qPrintable(it.key()), it.value()); | ||||
30 | } | ||||
31 | } | ||||
32 | | ||||
33 | int Comment::bug_id() const | ||||
34 | { | ||||
35 | return m_bug_id; | ||||
36 | } | ||||
37 | | ||||
38 | void Comment::setBug_id(int bug_id) | ||||
39 | { | ||||
40 | m_bug_id = bug_id; | ||||
41 | } | ||||
42 | | ||||
43 | QString Comment::text() const | ||||
44 | { | ||||
45 | return m_text; | ||||
46 | } | ||||
47 | | ||||
48 | void Comment::setText(const QString &text) | ||||
49 | { | ||||
50 | m_text = text; | ||||
51 | } | ||||
52 | | ||||
53 | | ||||
54 | CommentClient::CommentClient(const Connection &connection) | ||||
55 | : m_connection(connection) | ||||
56 | { | ||||
57 | } | ||||
58 | | ||||
59 | QList<Comment::Ptr> CommentClient::getFromBug(KJob *kjob) | ||||
60 | { | ||||
61 | auto job = qobject_cast<APIJob *>(kjob); | ||||
62 | | ||||
63 | auto document = job->document(); | ||||
64 | QJsonObject bugs = document.object().value(QStringLiteral("bugs")).toObject(); | ||||
65 | qDebug() << bugs; | ||||
66 | Q_ASSERT(bugs.keys().size() == 1); | ||||
67 | qDebug() << bugs.keys().at(0); | ||||
68 | QJsonObject bug = bugs.value(bugs.keys().at(0)).toObject(); | ||||
69 | qDebug() << bug; | ||||
70 | QJsonArray comments = bug.value(QStringLiteral("comments")).toArray(); | ||||
71 | qDebug() << comments; | ||||
72 | | ||||
73 | QList<Comment::Ptr> list; | ||||
74 | for (auto it = comments.constBegin(); it != comments.constEnd(); ++it) { | ||||
75 | list.append(new Comment((*it).toObject().toVariantHash())); | ||||
76 | } | ||||
77 | | ||||
78 | return list; | ||||
79 | } | ||||
80 | | ||||
81 | APIJob *CommentClient::getFromBug(int bugId) | ||||
82 | { | ||||
83 | return m_connection.get(QStringLiteral("/bug/%1/comment").arg(QString::number(bugId))); | ||||
84 | } | ||||
85 | | ||||
86 | #warning fimxe somehow bug should do this, feels super weird to have to ask antoher client to ask for comments. could just be the bug model. but then the bug model knows more? | ||||
87 | APIReply<QList<Comment::Ptr>> *CommentClient::getFromBug2(int bugId) | ||||
88 | { | ||||
89 | auto job = m_connection.get(QStringLiteral("/bug/%1/comment").arg(QString::number(bugId))); | ||||
90 | | ||||
91 | auto reply = new APIReply<QList<Comment::Ptr>>(job); | ||||
92 | reply->constructResult([](KJob *kjob) -> QList<Comment::Ptr> { | ||||
93 | auto job = qobject_cast<APIJob *>(kjob); | ||||
94 | | ||||
95 | auto document = job->document(); | ||||
96 | QJsonObject bugs = document.object().value(QStringLiteral("bugs")).toObject(); | ||||
97 | qDebug() << bugs; | ||||
98 | Q_ASSERT(bugs.keys().size() == 1); | ||||
99 | qDebug() << bugs.keys().at(0); | ||||
100 | QJsonObject bug = bugs.value(bugs.keys().at(0)).toObject(); | ||||
101 | qDebug() << bug; | ||||
102 | QJsonArray comments = bug.value(QStringLiteral("comments")).toArray(); | ||||
103 | qDebug() << comments; | ||||
104 | | ||||
105 | QList<Comment::Ptr> list; | ||||
106 | for (auto it = comments.constBegin(); it != comments.constEnd(); ++it) { | ||||
107 | list.append(new Comment((*it).toObject().toVariantHash())); | ||||
108 | } | ||||
109 | | ||||
110 | return list; | ||||
111 | }); | ||||
112 | | ||||
113 | return reply; | ||||
114 | } | ||||
115 | | ||||
116 | } // namespace Bugzilla |