1 /*******************************************************************
2 * SPDX-FileCopyrightText: 2019-2021 Harald Sitter <sitter@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 ******************************************************************/
6
7 #include "assistantpage_bugzilla_version.h"
8 #include "ui_assistantpage_bugzilla_version.h"
9
10 #include <QGuiApplication>
11
12 #include "bugzillalib.h"
13 #include "crashedapplication.h"
14 #include "drkonqi.h"
15
BugzillaVersionPage(ReportAssistantDialog * parent)16 BugzillaVersionPage::BugzillaVersionPage(ReportAssistantDialog *parent)
17 : ReportAssistantPage(parent)
18 , ui(new Ui::BugzillaVersionPage)
19 , m_item(new KPageWidgetItem(this))
20 {
21 if (!DrKonqi::crashedApplication()->bugReportAddress().isKdeBugzilla()) {
22 appropriate = false;
23 return; // never appropriate as bugzilla doesn't matter
24 }
25 // This item is intentionally not titled. The page should usually not show
26 // up when when it shows up it should focus on the bare essentials!
27 m_item->setIcon(QIcon::fromTheme(QStringLiteral("tools-report-bug")));
28
29 // We are not valid until the version came back!
30 assistant()->setValid(m_item, false);
31
32 ui->setupUi(this);
33
34 ui->errorIconLabel->setPixmap(QIcon::fromTheme(QStringLiteral("state-error")).pixmap(ui->errorIconLabel->size()));
35
36 connect(bugzillaManager(), &BugzillaManager::bugzillaVersionFound, this, [=] {
37 // Don't show this page ever again!
38 appropriate = false;
39 if (assistant()->currentPage() == m_item) {
40 assistant()->next();
41 }
42 });
43 connect(bugzillaManager(), &BugzillaManager::bugzillaVersionError, this, [=](const QString &error) {
44 ui->busyWidget->hide();
45 ui->errorWidget->show();
46 ui->errorLabel->setText(xi18nc("@info %1 is an error message from the backend", "Failed to contact bugs.kde.org: <message>%1</message>", error));
47 });
48 connect(ui->retryButton, &QPushButton::clicked, this, [=] {
49 ui->busyWidget->show();
50 ui->errorWidget->hide();
51 bugzillaManager()->lookupVersion();
52 });
53
54 // Finally trigger the actual load!
55 ui->retryButton->click();
56 }
57
~BugzillaVersionPage()58 BugzillaVersionPage::~BugzillaVersionPage()
59 {
60 delete ui;
61 }
62
isComplete()63 bool BugzillaVersionPage::isComplete()
64 {
65 return false;
66 }
67
isAppropriate()68 bool BugzillaVersionPage::isAppropriate()
69 {
70 return appropriate;
71 }
72
item() const73 KPageWidgetItem *BugzillaVersionPage::item() const
74 {
75 return m_item;
76 }
77