Add report issue dialog.
This commit is contained in:
parent
0a3a307d39
commit
691a16e9ad
103
app/reportissuedialog.cpp
Normal file
103
app/reportissuedialog.cpp
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
#include "reportissuedialog.h"
|
||||||
|
#include "qjsonarray.h"
|
||||||
|
#include "ui_reportissuedialog.h"
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
|
||||||
|
ReportIssueDialog::ReportIssueDialog(const QString &giteaBaseUrl,
|
||||||
|
const QString &repoOwner,
|
||||||
|
const QString &repoName,
|
||||||
|
const QString &accessToken,
|
||||||
|
QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::ReportIssueDialog),
|
||||||
|
networkManager(new QNetworkAccessManager(this)),
|
||||||
|
giteaBaseUrl(giteaBaseUrl),
|
||||||
|
repoOwner(repoOwner),
|
||||||
|
repoName(repoName),
|
||||||
|
accessToken(accessToken)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(networkManager, &QNetworkAccessManager::finished, this, &ReportIssueDialog::onNetworkReplyFinished);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportIssueDialog::~ReportIssueDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportIssueDialog::on_buttonSend_clicked()
|
||||||
|
{
|
||||||
|
QString title = ui->lineEditSummary->text().trimmed();
|
||||||
|
QString details = ui->textEditDetails->toPlainText().trimmed();
|
||||||
|
QString contact = ui->lineEditContact->text().trimmed();
|
||||||
|
|
||||||
|
if (title.isEmpty()) {
|
||||||
|
QMessageBox::warning(this, tr("Input Error"), tr("Please enter a summary/title for the issue."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString body = details;
|
||||||
|
if (!contact.isEmpty()) {
|
||||||
|
body += QString("\n\nContact info:\n%1").arg(contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->buttonSend->setEnabled(false);
|
||||||
|
sendIssueReport(title, body, contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportIssueDialog::on_buttonCancel_clicked()
|
||||||
|
{
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportIssueDialog::sendIssueReport(const QString &title, const QString &body, const QString &/*contact*/)
|
||||||
|
{
|
||||||
|
// Compose URL: e.g. https://gitea.example.com/api/v1/repos/{owner}/{repo}/issues
|
||||||
|
QUrl url(QString("%1/api/v1/repos/%2/%3/issues").arg(giteaBaseUrl).arg(repoOwner).arg(repoName));
|
||||||
|
|
||||||
|
QNetworkRequest request(url);
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
|
|
||||||
|
if (!accessToken.isEmpty()) {
|
||||||
|
request.setRawHeader("Authorization", "token " + accessToken.toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compose JSON body
|
||||||
|
QJsonObject json;
|
||||||
|
json["title"] = title;
|
||||||
|
json["body"] = body;
|
||||||
|
json["labels"] = QJsonArray{12};
|
||||||
|
|
||||||
|
QJsonDocument doc(json);
|
||||||
|
QByteArray data = doc.toJson();
|
||||||
|
|
||||||
|
networkManager->post(request, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportIssueDialog::onNetworkReplyFinished(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
ui->buttonSend->setEnabled(true);
|
||||||
|
|
||||||
|
QByteArray responseData = reply->readAll();
|
||||||
|
QString responseStr = QString::fromUtf8(responseData);
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
QString errorStr = reply->errorString();
|
||||||
|
if (errorStr.isEmpty()) errorStr = "Unknown network error";
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("Failed to send issue report:\n%1\nResponse:\n%2").arg(errorStr).arg(responseStr));
|
||||||
|
} else {
|
||||||
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
if (status == 201) {
|
||||||
|
QMessageBox::information(this, tr("Success"), tr("Issue reported successfully!"));
|
||||||
|
accept();
|
||||||
|
} else {
|
||||||
|
QMessageBox::warning(this, tr("Failed"), tr("Unexpected response from server (%1):\n%2").arg(status).arg(responseStr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reply->deleteLater();
|
||||||
|
}
|
||||||
43
app/reportissuedialog.h
Normal file
43
app/reportissuedialog.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#ifndef REPORTISSUEDIALOG_H
|
||||||
|
#define REPORTISSUEDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ReportIssueDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReportIssueDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ReportIssueDialog(const QString &giteaBaseUrl,
|
||||||
|
const QString &repoOwner,
|
||||||
|
const QString &repoName,
|
||||||
|
const QString &accessToken,
|
||||||
|
QWidget *parent = nullptr);
|
||||||
|
~ReportIssueDialog();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_buttonSend_clicked();
|
||||||
|
void on_buttonCancel_clicked();
|
||||||
|
|
||||||
|
void onNetworkReplyFinished(QNetworkReply *reply);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::ReportIssueDialog *ui;
|
||||||
|
|
||||||
|
QNetworkAccessManager *networkManager;
|
||||||
|
|
||||||
|
QString giteaBaseUrl;
|
||||||
|
QString repoOwner;
|
||||||
|
QString repoName;
|
||||||
|
QString accessToken;
|
||||||
|
|
||||||
|
void sendIssueReport(const QString &title, const QString &body, const QString &contact);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // REPORTISSUEDIALOG_H
|
||||||
84
app/reportissuedialog.ui
Normal file
84
app/reportissuedialog.ui
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ReportIssueDialog</class>
|
||||||
|
<widget class="QDialog" name="ReportIssueDialog">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Report a Problem</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelInstructions">
|
||||||
|
<property name="text">
|
||||||
|
<string>Please describe the problem you encountered. We’ll use this info to help fix it.</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelSummary">
|
||||||
|
<property name="text">
|
||||||
|
<string>Summary (short title):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEditSummary" />
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelDetails">
|
||||||
|
<property name="text">
|
||||||
|
<string>Details (what happened?):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="textEditDetails" />
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelContact">
|
||||||
|
<property name="text">
|
||||||
|
<string>Your contact (email or name, optional):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEditContact" />
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="buttonLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Expanding</enum>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonSend">
|
||||||
|
<property name="text">
|
||||||
|
<string>Send Report</string>
|
||||||
|
</property>
|
||||||
|
<property name="default">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonCancel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Loading…
x
Reference in New Issue
Block a user