mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-10 04:15:51 +00:00
add github issue reporing backend (#104)
This commit is contained in:
87
sources/awesome-widget/plugin/awbugreporter.cpp
Normal file
87
sources/awesome-widget/plugin/awbugreporter.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets 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 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awbugreporter.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWBugReporter::AWBugReporter(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
AWBugReporter::~AWBugReporter()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void AWBugReporter::sendBugReport(const QString title, const QString body)
|
||||
{
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(issueReplyRecieved(QNetworkReply *)));
|
||||
|
||||
QNetworkRequest request(QUrl(BUGTRACKER_API));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
// generate payload
|
||||
QVariantMap payload;
|
||||
payload[QString("title")] = title;
|
||||
payload[QString("body")] = body;
|
||||
payload[QString("labels")] = QStringList() << QString("from application");
|
||||
// convert to QByteArray to send request
|
||||
QByteArray data
|
||||
= QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
|
||||
qCInfo(LOG_AW) << "Send request with body" << data.data() << "and size"
|
||||
<< data.size();
|
||||
|
||||
manager->post(request, data);
|
||||
}
|
||||
|
||||
|
||||
void AWBugReporter::issueReplyRecieved(QNetworkReply *reply)
|
||||
{
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << reply->error()
|
||||
<< "with message" << reply->errorString();
|
||||
return emit(replyReceived(false, QString()));
|
||||
}
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_AW) << "Parse error" << error.errorString();
|
||||
return emit(replyReceived(false, QString()));
|
||||
}
|
||||
reply->deleteLater();
|
||||
|
||||
// convert to map
|
||||
QVariantMap response = jsonDoc.toVariant().toMap();
|
||||
QString url = response[QString("html_url")].toString();
|
||||
|
||||
return emit(replyReceived(true, url));
|
||||
}
|
46
sources/awesome-widget/plugin/awbugreporter.h
Normal file
46
sources/awesome-widget/plugin/awbugreporter.h
Normal file
@ -0,0 +1,46 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets 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 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef AWBUGREPORTER_H
|
||||
#define AWBUGREPORTER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class AWBugReporter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWBugReporter(QObject *parent = nullptr);
|
||||
virtual ~AWBugReporter();
|
||||
Q_INVOKABLE void sendBugReport(const QString title, const QString body);
|
||||
|
||||
signals:
|
||||
void replyReceived(bool status, QString url);
|
||||
|
||||
private slots:
|
||||
void issueReplyRecieved(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWBUGREPORTER_H */
|
@ -23,7 +23,6 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QPixmap>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <QtQml>
|
||||
|
||||
#include "awactions.h"
|
||||
#include "awbugreporter.h"
|
||||
#include "awconfighelper.h"
|
||||
#include "awformatterconfigfactory.h"
|
||||
#include "awkeys.h"
|
||||
@ -30,6 +31,7 @@ void AWPlugin::registerTypes(const char *uri)
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.awesomewidget"));
|
||||
|
||||
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
|
||||
qmlRegisterType<AWBugReporter>(uri, 1, 0, "AWBugReporter");
|
||||
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
|
||||
qmlRegisterType<AWFormatterConfigFactory>(uri, 1, 0,
|
||||
"AWFormatterConfigFactory");
|
||||
|
Reference in New Issue
Block a user