finally implement bug reporting (#104)

This commit is contained in:
2016-08-25 13:33:08 +03:00
parent 5b9984d950
commit 80d926290c
10 changed files with 137 additions and 31 deletions

View File

@ -21,6 +21,7 @@
#include <KNotifications/KNotification>
#include <QDesktopServices>
#include <QFile>
#include <QProcess>
#include <QUrl>
@ -56,6 +57,23 @@ void AWActions::checkUpdates(const bool showAnyway)
}
QString AWActions::getFileContent(const QString path) const
{
qCDebug(LOG_AW) << "Get content from file" << path;
QFile inputFile(path);
if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qCWarning(LOG_AW) << "Could not open file as text"
<< inputFile.fileName();
return QString();
}
QString output = inputFile.readAll();
inputFile.close();
return output;
}
// HACK: since QML could not use QLoggingCategory I need this hack
bool AWActions::isDebugEnabled() const
{

View File

@ -33,6 +33,7 @@ public:
explicit AWActions(QObject *parent = nullptr);
virtual ~AWActions();
Q_INVOKABLE void checkUpdates(const bool showAnyway = false);
Q_INVOKABLE QString getFileContent(const QString path) const;
Q_INVOKABLE bool isDebugEnabled() const;
Q_INVOKABLE bool runCmd(const QString cmd = QString("/usr/bin/true")) const;
Q_INVOKABLE void showReadme() const;

View File

@ -34,9 +34,6 @@ AWBugReporter::AWBugReporter(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
connect(this, SIGNAL(replyReceived(const int, const QString)), this,
SLOT(showInformation(const int, const QString)));
}
@ -46,20 +43,32 @@ AWBugReporter::~AWBugReporter()
}
void AWBugReporter::doConnect()
{
// additional method for testing needs
connect(this, SIGNAL(replyReceived(const int, const QString)), this,
SLOT(showInformation(const int, const QString)));
}
QString AWBugReporter::generateText(const QString description,
const QString reproduce,
const QString expected)
const QString expected,
const QString logs) const
{
// do not log logs here, it may have quite large size
qCDebug(LOG_AW) << "Generate text with description" << description
<< "steps" << reproduce << "and expected result"
<< expected;
QString output;
output += QString("**Description**\n\n%1\n").arg(description);
output += QString("**Step to reproduce**\n\n%1\n").arg(reproduce);
output += QString("**Expected result**\n\n%1\n").arg(expected);
output
+= QString("**Version**\n\n%1").arg(getBuildData().join(QString("\n")));
output += QString("**Description**\n\n%1\n\n").arg(description);
output += QString("**Step to reproduce**\n\n%1\n\n").arg(reproduce);
output += QString("**Expected result**\n\n%1\n\n").arg(expected);
output += QString("**Version**\n\n%1\n\n")
.arg(getBuildData().join(QString("\n")));
// append logs
output += QString("**Logs**\n\n%1").arg(logs);
return output;
}
@ -122,16 +131,33 @@ void AWBugReporter::showInformation(const int number, const QString url)
qCDebug(LOG_AW) << "Created issue with number" << number << "and url"
<< url;
// cache url first
m_lastBugUrl = url;
QMessageBox *msgBox = new QMessageBox(nullptr);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->setWindowTitle(i18n("Issue created"));
msgBox->setText(i18n("Issue %1 has been created"));
msgBox->setText(i18n("Issue %1 has been created", number));
msgBox->setStandardButtons(QMessageBox::Open | QMessageBox::Close);
msgBox->setIcon(QMessageBox::Information);
connect(msgBox, &QMessageBox::accepted,
[this, url]() { return QDesktopServices::openUrl(url); });
return msgBox->open();
msgBox->open(this, SLOT(userReplyOnBugReport(QAbstractButton *)));
}
void AWBugReporter::userReplyOnBugReport(QAbstractButton *button)
{
QMessageBox::ButtonRole ret
= static_cast<QMessageBox *>(sender())->buttonRole(button);
qCInfo(LOG_AW) << "User select" << ret;
switch (ret) {
case QMessageBox::AcceptRole:
QDesktopServices::openUrl(m_lastBugUrl);
break;
case QMessageBox::RejectRole:
default:
break;
}
}

View File

@ -22,6 +22,7 @@
#include <QObject>
class QAbstractButton;
class QNetworkReply;
class AWBugReporter : public QObject
@ -31,9 +32,11 @@ class AWBugReporter : public QObject
public:
explicit AWBugReporter(QObject *parent = nullptr);
virtual ~AWBugReporter();
Q_INVOKABLE void doConnect();
Q_INVOKABLE QString generateText(const QString description,
const QString reproduce,
const QString expected);
const QString expected,
const QString logs) const;
Q_INVOKABLE void sendBugReport(const QString title, const QString body);
signals:
@ -42,8 +45,10 @@ signals:
private slots:
void issueReplyRecieved(QNetworkReply *reply);
void showInformation(const int number, const QString url);
void userReplyOnBugReport(QAbstractButton *button);
private:
QString m_lastBugUrl;
};