diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ set(drkonqi_SRCS ${drkonqi_SRCS} + bugzillaintegration/assistantpage_bugzilla_version.cpp bugzillaintegration/bugzillalib.cpp bugzillaintegration/reportassistantdialog.cpp bugzillaintegration/reportassistantpage.cpp @@ -77,6 +78,7 @@ bugzillaintegration/ui/assistantpage_bugzilla_information.ui bugzillaintegration/ui/assistantpage_bugzilla_preview.ui bugzillaintegration/ui/assistantpage_bugzilla_send.ui + bugzillaintegration/ui/assistantpage_bugzilla_version.ui ) ecm_qt_declare_logging_category(drkonqi_SRCS HEADER drkonqi_debug.h IDENTIFIER DRKONQI_LOG CATEGORY_NAME org.kde.drkonqi) diff --git a/src/bugzillaintegration/assistantpage_bugzilla_version.h b/src/bugzillaintegration/assistantpage_bugzilla_version.h new file mode 100644 --- /dev/null +++ b/src/bugzillaintegration/assistantpage_bugzilla_version.h @@ -0,0 +1,46 @@ +/******************************************************************* +* Copyright 2019 Harald Sitter +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +******************************************************************/ + +#ifndef ASSISTANTPAGE_BUGZILLA_VERSION_H +#define ASSISTANTPAGE_BUGZILLA_VERSION_H + +#include + +#include "reportassistantpage.h" + +class ReportAssistantDialog; +namespace Ui { +class BugzillaVersionPage; +} + +class BugzillaVersionPage : public ReportAssistantPage +{ + Q_OBJECT + +public: + explicit BugzillaVersionPage(ReportAssistantDialog *parent = nullptr); + ~BugzillaVersionPage(); + + KPageWidgetItem *item() const; + virtual bool isComplete() override; + +private: + Ui::BugzillaVersionPage *ui = nullptr; + KPageWidgetItem *m_item = nullptr; +}; + +#endif // ASSISTANTPAGE_BUGZILLA_VERSION_H diff --git a/src/bugzillaintegration/assistantpage_bugzilla_version.cpp b/src/bugzillaintegration/assistantpage_bugzilla_version.cpp new file mode 100644 --- /dev/null +++ b/src/bugzillaintegration/assistantpage_bugzilla_version.cpp @@ -0,0 +1,81 @@ +/******************************************************************* +* Copyright 2019 Harald Sitter +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +******************************************************************/ + +#include "assistantpage_bugzilla_version.h" +#include "ui_assistantpage_bugzilla_version.h" + +#include + +#include "bugzillalib.h" + +BugzillaVersionPage::BugzillaVersionPage(ReportAssistantDialog *parent) + : ReportAssistantPage(parent) + , ui(new Ui::BugzillaVersionPage) + , m_item(new KPageWidgetItem(this)) +{ + // This item is intentionally not titled. The page should usually not show + // up when when it shows up it should focus on the bare essentials! + m_item->setIcon(QIcon::fromTheme(QStringLiteral("tools-report-bug"))); + + // We are not valid until the version came back! + assistant()->setValid(m_item, false); + + ui->setupUi(this); + + ui->errorIconLabel->setPixmap(QIcon::fromTheme(QStringLiteral("state-error")).pixmap(ui->errorIconLabel->size())); + + connect(bugzillaManager(), &BugzillaManager::bugzillaVersionFound, + this, [=] { + // Don't show this page ever again! + assistant()->setAppropriate(m_item, false); + if (assistant()->currentPage() == m_item) { + assistant()->next(); + } + }); + connect(bugzillaManager(), &BugzillaManager::bugzillaVersionError, + this, [=](const QString &error) { + ui->busyWidget->hide(); + ui->errorWidget->show(); + ui->errorLabel->setText(xi18nc("@info %1 is an error message from the backend", + "Failed to contact bugs.kde.org: %1", + error)); + }); + connect(ui->retryButton, &QPushButton::clicked, + this, [=] { + ui->busyWidget->show(); + ui->errorWidget->hide(); + bugzillaManager()->lookupVersion(); + }); + + // Finally trigger the actual load! + ui->retryButton->click(); +} + +BugzillaVersionPage::~BugzillaVersionPage() +{ + delete ui; +} + +bool BugzillaVersionPage::isComplete() +{ + return false; +} + +KPageWidgetItem *BugzillaVersionPage::item() const +{ + return m_item; +} diff --git a/src/bugzillaintegration/bugzillalib.h b/src/bugzillaintegration/bugzillalib.h --- a/src/bugzillaintegration/bugzillalib.h +++ b/src/bugzillaintegration/bugzillalib.h @@ -64,8 +64,6 @@ void stopCurrentSearch(); void fetchComments(const Bugzilla::Bug::Ptr &bug, QObject *jobOwner); - -private Q_SLOTS: void lookupVersion(); Q_SIGNALS: @@ -90,6 +88,7 @@ void attachToReportError(const QString &errorMsg, const QString &extendedErrorMsg = QString()); void addMeToCCError(const QString &errorMsg, const QString &extendedErrorMsg = QString()); void productInfoError(); + void bugzillaVersionError(const QString &errorMsg); private: QString m_bugTrackerUrl; diff --git a/src/bugzillaintegration/bugzillalib.cpp b/src/bugzillaintegration/bugzillalib.cpp --- a/src/bugzillaintegration/bugzillalib.cpp +++ b/src/bugzillaintegration/bugzillalib.cpp @@ -102,12 +102,6 @@ { Q_ASSERT(bugTrackerUrl.endsWith(QLatin1Char('/'))); Bugzilla::setConnection(new Bugzilla::HTTPConnection(QUrl(m_bugTrackerUrl + QStringLiteral("rest")))); - // Allow constructors for ReportInterface and assistant dialogs to finish. - // Otherwise we may have a race on our hand if the lookup finishes before - // the constructors. - // I am not sure why this is so weirdly done TBH. Might deserve some looking - // into. - QMetaObject::invokeMethod(this, &BugzillaManager::lookupVersion, Qt::QueuedConnection); } void BugzillaManager::lookupVersion() @@ -122,6 +116,7 @@ // Version detection problems simply mean we'll not mark the version // found and the UI will not allow reporting. qCWarning(DRKONQI_LOG) << e.whatString(); + emit bugzillaVersionError(e.whatString()); } }); } diff --git a/src/bugzillaintegration/reportassistantdialog.h b/src/bugzillaintegration/reportassistantdialog.h --- a/src/bugzillaintegration/reportassistantdialog.h +++ b/src/bugzillaintegration/reportassistantdialog.h @@ -45,6 +45,10 @@ void setAboutToSend(bool aboutTo); +public Q_SLOTS: + void next() override; + void back() override; + private Q_SLOTS: void currentPageChanged_slot(KPageWidgetItem *, KPageWidgetItem *); @@ -56,9 +60,6 @@ void showHelp(); - void next() override; - void back() override; - //Override default reject method void reject() override; diff --git a/src/bugzillaintegration/reportassistantdialog.cpp b/src/bugzillaintegration/reportassistantdialog.cpp --- a/src/bugzillaintegration/reportassistantdialog.cpp +++ b/src/bugzillaintegration/reportassistantdialog.cpp @@ -32,6 +32,7 @@ #include "debuggermanager.h" #include "backtracegenerator.h" +#include "assistantpage_bugzilla_version.h" #include "crashedapplication.h" #include "aboutbugreportingdialog.h" #include "reportassistantpages_base.h" @@ -105,6 +106,10 @@ m_conclusionsPage->setIcon(QIcon::fromTheme(QStringLiteral("dialog-information"))); connect(m_conclusions, &ConclusionPage::finished, this, &ReportAssistantDialog::assistantFinished); + // Version check page + BugzillaVersionPage *versionPage = new BugzillaVersionPage(this); + m_pageWidgetMap.insert(QLatin1String(PAGE_BZVERSION_ID), versionPage->item()); + //-Bugzilla Login BugzillaLoginPage * m_bugzillaLogin = new BugzillaLoginPage(this); connectSignals(m_bugzillaLogin); @@ -159,6 +164,7 @@ addPage(m_awarenessPage); addPage(m_backtracePage); addPage(m_conclusionsPage); + addPage(versionPage->item()); addPage(m_bugzillaLoginPage); addPage(m_bugzillaDuplicatesPage); addPage(m_bugzillaInformationPage); @@ -267,6 +273,13 @@ //Override KAssistantDialog "next" page implementation void ReportAssistantDialog::next() { + // FIXME: this entire function is a bit weird. It'd likely make more sense to + // use the page appropriateness more globally. i.e. mark pages inappropriate + // when they are not applicable based on earlier settings done (e.g. put + // a conclusion page under/after the awareness page but only mark it + // appropriate if the data is not useful. that way kassistantdialog would + // just skip over the page). + //Allow the widget to Ask a question to the user before changing the page ReportAssistantPage * page = dynamic_cast(currentPage()->widget()); if (page) { @@ -296,7 +309,11 @@ if (m_reportInterface->isWorthReporting() && DrKonqi::crashedApplication()->bugReportAddress().isKdeBugzilla()) { - setCurrentPage(m_pageWidgetMap.value(QLatin1String(PAGE_BZLOGIN_ID))); + // Depending on whether the page is appropriate either go to version + // check page or login page. + const auto versionPage = m_pageWidgetMap.value(QLatin1String(PAGE_BZVERSION_ID)); + const auto loginPage = m_pageWidgetMap.value(QLatin1String(PAGE_BZLOGIN_ID)); + setCurrentPage(isAppropriate(versionPage) ? versionPage : loginPage); return; } } else if (name == QLatin1String(PAGE_BZDUPLICATES_ID)) { diff --git a/src/bugzillaintegration/reportassistantpages_bugzilla.h b/src/bugzillaintegration/reportassistantpages_bugzilla.h --- a/src/bugzillaintegration/reportassistantpages_bugzilla.h +++ b/src/bugzillaintegration/reportassistantpages_bugzilla.h @@ -46,7 +46,6 @@ bool isComplete() override; private Q_SLOTS: - void bugzillaVersionFound(); void loginClicked(); bool canLogin() const; void login(); diff --git a/src/bugzillaintegration/reportassistantpages_bugzilla.cpp b/src/bugzillaintegration/reportassistantpages_bugzilla.cpp --- a/src/bugzillaintegration/reportassistantpages_bugzilla.cpp +++ b/src/bugzillaintegration/reportassistantpages_bugzilla.cpp @@ -20,6 +20,7 @@ #include "reportassistantpages_bugzilla.h" +#include #include #include #include @@ -64,10 +65,9 @@ BugzillaLoginPage::BugzillaLoginPage(ReportAssistantDialog * parent) : ReportAssistantPage(parent), - m_wallet(nullptr), m_walletWasOpenedBefore(false), - m_bugzillaVersionFound(false) + m_wallet(nullptr), + m_walletWasOpenedBefore(false) { - connect(bugzillaManager(), &BugzillaManager::bugzillaVersionFound, this, &BugzillaLoginPage::bugzillaVersionFound); connect(bugzillaManager(), &BugzillaManager::loginFinished, this, &BugzillaLoginPage::loginFinished); connect(bugzillaManager(), &BugzillaManager::loginError, this, &BugzillaLoginPage::loginError); @@ -114,18 +114,9 @@ return bugzillaManager()->getLogged(); } -void BugzillaLoginPage::bugzillaVersionFound() -{ - // Login depends on first knowing the Bugzilla software version number. - m_bugzillaVersionFound = true; - updateLoginButtonStatus(); -} - void BugzillaLoginPage::updateLoginButtonStatus() { - ui.m_loginButton->setEnabled( !ui.m_userEdit->text().isEmpty() && - !ui.m_passwordEdit->password().isEmpty() && - m_bugzillaVersionFound ); + ui.m_loginButton->setEnabled(canLogin()); } void BugzillaLoginPage::loginError(const QString & err, const QString & extendedMessage) @@ -280,7 +271,8 @@ bool BugzillaLoginPage::canLogin() const { - return (!(ui.m_userEdit->text().isEmpty() || ui.m_passwordEdit->password().isEmpty())); + return (!(ui.m_userEdit->text().isEmpty() || + ui.m_passwordEdit->password().isEmpty())); } void BugzillaLoginPage::login() diff --git a/src/bugzillaintegration/ui/assistantpage_bugzilla_version.ui b/src/bugzillaintegration/ui/assistantpage_bugzilla_version.ui new file mode 100644 --- /dev/null +++ b/src/bugzillaintegration/ui/assistantpage_bugzilla_version.ui @@ -0,0 +1,158 @@ + + + BugzillaVersionPage + + + + 0 + 0 + 409 + 319 + + + + Form + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 0 + + + 0 + + + -1 + + + + + + + Trying to contact bugs.kde.org... + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + //icon// + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + //Error// + + + Qt::AlignCenter + + + true + + + + + + + + + + 0 + 0 + + + + Retry + + + + .. + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + diff --git a/src/drkonqi_globals.h b/src/drkonqi_globals.h --- a/src/drkonqi_globals.h +++ b/src/drkonqi_globals.h @@ -43,6 +43,7 @@ #define PAGE_CRASHINFORMATION_ID "BacktraceID" #define PAGE_AWARENESS_ID "AwarenessID" #define PAGE_CONCLUSIONS_ID "ConclusionsID" +#define PAGE_BZVERSION_ID "BugzillaVersionID" #define PAGE_BZLOGIN_ID "BugzillaLoginID" #define PAGE_BZDUPLICATES_ID "BugzillaDuplicatesID" #define PAGE_BZDETAILS_ID "BugzillaDetailsID"