mirror of
https://github.com/arcan1s/reportabug.git
synced 2025-04-24 15:27:18 +00:00
rewrited functions
This commit is contained in:
parent
f20a7ecc1c
commit
df92573ff8
18
README.md
18
README.md
@ -4,12 +4,12 @@ reportabug
|
|||||||
Information
|
Information
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
A simple Qt application/library which allows users to create an issue for GitHub projects. It may work over [GitHub](https://github.com) or [GitReport](https://gitreports.com/). For the developer configuration please use `config.h` header.
|
A simple Qt application/library which allows users to create an issue for GitHub projects. It may work over [GitHub](https://github.com) or [GitReport](https://gitreports.com/). For the developer configuration please use `config.h.in` header.
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Edit `src/config.h` header and set up needed variables.
|
Edit `src/config.h.in` header and set up needed variables.
|
||||||
|
|
||||||
### Main configuration ###
|
### Main configuration ###
|
||||||
|
|
||||||
@ -31,11 +31,10 @@ User should type own username and password. [GitHub API](https://developer.githu
|
|||||||
|
|
||||||
Available variables:
|
Available variables:
|
||||||
|
|
||||||
* `ENABLE_GITHUB` - enable this module. Default is `true`.
|
|
||||||
* `GITHUB_COMBOBOX` - text of this module into comboBox.
|
* `GITHUB_COMBOBOX` - text of this module into comboBox.
|
||||||
* `ISSUES_URL` - issues url, in the most cases do not touch it. Default is `https://api.github.com/repos/$OWNER/$PROJECT/issues`. Available tags here are `$PROJECT`, `$OWNER`.
|
* `ISSUES_URL` - issues url, in the most cases do not touch it. Default is `https://api.github.com/repos/$OWNER/$PROJECT/issues`. Available tags here are `$PROJECT`, `$OWNER`.
|
||||||
|
|
||||||
This module requires `QtNetwork` module. To enable this module set variable `ENABLE_GITHUB` to `true`.
|
This module requires `QtNetwork` module. To disable this module use `-DENABLE_GITHUB=0` cmake flag.
|
||||||
|
|
||||||
### Send issue over GitReport ###
|
### Send issue over GitReport ###
|
||||||
|
|
||||||
@ -46,11 +45,10 @@ Available variables:
|
|||||||
* `CAPTCHA_KEY` - captcha key. It may be found in the source of the `PUBLIC_URL` page. Default is `7f6ef90bce7389088a52c5c9101aad206b21b56d`.
|
* `CAPTCHA_KEY` - captcha key. It may be found in the source of the `PUBLIC_URL` page. Default is `7f6ef90bce7389088a52c5c9101aad206b21b56d`.
|
||||||
* `CAPTCHA_TEXT` - captcha text. It may be found in the source of the `PUBLIC_URL` page. Default is `QJNZXY`.
|
* `CAPTCHA_TEXT` - captcha text. It may be found in the source of the `PUBLIC_URL` page. Default is `QJNZXY`.
|
||||||
* `CAPTCHA_TIME` - captcha time. It may be found in the source of the `PUBLIC_URL` page. Default is `1406531273`.
|
* `CAPTCHA_TIME` - captcha time. It may be found in the source of the `PUBLIC_URL` page. Default is `1406531273`.
|
||||||
* `ENABLE_GITREPORT` - enable this module. Default is `true`.
|
|
||||||
* `GITREPORT_COMBOBOX` - text of this module into comboBox.
|
* `GITREPORT_COMBOBOX` - text of this module into comboBox.
|
||||||
* `PUBLIC_URL` - issues url, in the most cases do not touch it. Default is `https://gitreports.com/issue/$OWNER/$PROJECT`. Available tags here are `$PROJECT`, `$OWNER`.
|
* `PUBLIC_URL` - issues url, in the most cases do not touch it. Default is `https://gitreports.com/issue/$OWNER/$PROJECT`. Available tags here are `$PROJECT`, `$OWNER`.
|
||||||
|
|
||||||
This module requires `QtWebKit` module. To enable this module set variable `ENABLE_GITREPORT` to `true`.
|
This module requires `QtWebKit` module. To disable this module use `-DENABLE_GITREPORT=0` cmake flag.
|
||||||
|
|
||||||
Instruction
|
Instruction
|
||||||
===========
|
===========
|
||||||
@ -93,11 +91,19 @@ Installation
|
|||||||
|
|
||||||
add_subdirectory (reportabug)
|
add_subdirectory (reportabug)
|
||||||
|
|
||||||
|
* declare class in you sources. For example:
|
||||||
|
|
||||||
|
Reportabug *reportWindow = new Reportabug(this, false);
|
||||||
|
reportWindow->showWindow();
|
||||||
|
|
||||||
* link your application with this library
|
* link your application with this library
|
||||||
|
|
||||||
### Available cmake flags ###
|
### Available cmake flags ###
|
||||||
|
|
||||||
* `-DBUILD_AS_LIBRARY:BOOL=0` - build the application but not a shared library
|
* `-DBUILD_AS_LIBRARY:BOOL=0` - build the application but not a shared library
|
||||||
|
* `-DBUILD_DOCS:BOOL=0` - do not build developer documentation
|
||||||
|
* `-DENABLE_GITHUB=0` - disable GitHub module
|
||||||
|
* `-DENABLE_GITREPORT=0` - disable GitReport module
|
||||||
* `-DUSE_QT5:BOOL=0` - use Qt4 instead of Qt5 for GUI
|
* `-DUSE_QT5:BOOL=0` - use Qt4 instead of Qt5 for GUI
|
||||||
|
|
||||||
Additional information
|
Additional information
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
set (SOURCES main.cpp reportabug.cpp)
|
set (SOURCES main.cpp reportabug.cpp)
|
||||||
set (HEADERS reportabug.h)
|
set (HEADERS reportabug.h)
|
||||||
set (FORMS reportabug.ui)
|
set (FORMS reportabug.ui)
|
||||||
|
if (ENABLE_GITHUB)
|
||||||
|
set (SOURCES ${SOURCES} githubmodule.cpp)
|
||||||
|
set (HEADERS ${HEADERS} githubmodule.h)
|
||||||
|
endif ()
|
||||||
|
if (ENABLE_GITREPORT)
|
||||||
|
set (SOURCES ${SOURCES} gitreportmodule.cpp)
|
||||||
|
set (HEADERS ${HEADERS} gitreportmodule.h)
|
||||||
|
endif ()
|
||||||
|
|
||||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||||
|
|
||||||
|
@ -35,12 +35,14 @@
|
|||||||
#define TAG_MILESTONE ""
|
#define TAG_MILESTONE ""
|
||||||
// comma separated
|
// comma separated
|
||||||
#define TAG_LABELS "auto,bug"
|
#define TAG_LABELS "auto,bug"
|
||||||
|
// modules. Please use -DENABLE_GITHUB and -DENABLE_GITREPORT cmake flags
|
||||||
|
// DO NOT EDIT THEM!
|
||||||
|
#cmakedefine ENABLE_GITHUB
|
||||||
|
#cmakedefine ENABLE_GITREPORT
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* configuration of creating an issue using GitHub API
|
* configuration of creating an issue using GitHub API
|
||||||
*/
|
*/
|
||||||
// enable this function
|
|
||||||
#cmakedefine ENABLE_GITHUB
|
|
||||||
// combobox text
|
// combobox text
|
||||||
#define GITHUB_COMBOBOX "I want to report a bug using my GitHub account"
|
#define GITHUB_COMBOBOX "I want to report a bug using my GitHub account"
|
||||||
// issues url; in the most cases do not touch it
|
// issues url; in the most cases do not touch it
|
||||||
@ -53,8 +55,6 @@
|
|||||||
* please, visit https://gitreports.com/
|
* please, visit https://gitreports.com/
|
||||||
* and set up it for your repository
|
* and set up it for your repository
|
||||||
*/
|
*/
|
||||||
// enable this function
|
|
||||||
#cmakedefine ENABLE_GITREPORT
|
|
||||||
// combobox text
|
// combobox text
|
||||||
#define GITREPORT_COMBOBOX "GitHub? I don't understand what do you want from me!"
|
#define GITREPORT_COMBOBOX "GitHub? I don't understand what do you want from me!"
|
||||||
// public link; in the most cases do not touch it
|
// public link; in the most cases do not touch it
|
||||||
|
@ -15,10 +15,12 @@
|
|||||||
* License along with this library. *
|
* License along with this library. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "githubmodule.h"
|
||||||
#include "reportabug.h"
|
#include "reportabug.h"
|
||||||
#include "ui_reportabug.h"
|
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QGridLayout>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
@ -29,20 +31,79 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::sendReportUsingGithub()
|
GithubModule::GithubModule(QWidget *parent, bool debugCmd)
|
||||||
|
: QObject(parent),
|
||||||
|
debug(debugCmd),
|
||||||
|
mainWindow((Reportabug *)parent)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[sendReportUsingGithub]";
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GithubModule::~GithubModule()
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << "[GithubModule]" << "[~GithubModule]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QByteArray GithubModule::prepareRequest(const QString title, const QString body)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << "[GithubModule]" << "[prepareRequest]";
|
||||||
|
if (debug) qDebug() << "[GithubModule]" << "[prepareRequest]" << ":" << "Title" << title;
|
||||||
|
if (debug) qDebug() << "[GithubModule]" << "[prepareRequest]" << ":" << "Title" << body;
|
||||||
|
|
||||||
|
QStringList requestList;
|
||||||
|
requestList.append(QString("\"title\":\"") + title + QString("\""));
|
||||||
|
QString fixBody = body;
|
||||||
|
fixBody.replace(QString("\n"), QString("<br>"));
|
||||||
|
requestList.append(QString("\"body\":\"") + fixBody + QString("\""));
|
||||||
|
if (!QString(TAG_ASSIGNEE).isEmpty())
|
||||||
|
requestList.append(QString("\"assignee\":\"") + parseString(QString(TAG_ASSIGNEE)) + QString("\""));
|
||||||
|
if (!QString(TAG_MILESTONE).isEmpty())
|
||||||
|
requestList.append(QString("\"milestone\":") + QString(TAG_MILESTONE));
|
||||||
|
if (!QString(TAG_LABELS).isEmpty()) {
|
||||||
|
QStringList labels = QString(TAG_LABELS).split(QChar(','));
|
||||||
|
for (int i=0; i<labels.count(); i++)
|
||||||
|
labels[i] = QString("\"") + labels[i] + QString("\"");
|
||||||
|
requestList.append(QString("\"labels\":[") + labels.join(QChar(',')) + QString("]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString request;
|
||||||
|
request += QString("{");
|
||||||
|
request += requestList.join(QChar(','));
|
||||||
|
request += QString("}");
|
||||||
|
|
||||||
|
return request.toLocal8Bit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString GithubModule::parseString(QString line)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << "[GithubModule]" << "[parseString]";
|
||||||
|
if (debug) qDebug() << "[GithubModule]" << "[parseString]" << ":" << "Parse line" << line;
|
||||||
|
|
||||||
|
if (line.contains(QString("$OWNER")))
|
||||||
|
line = line.split(QString("$OWNER"))[0] +
|
||||||
|
QString(OWNER) +
|
||||||
|
line.split(QString("$OWNER"))[1];
|
||||||
|
if (line.contains(QString("$PROJECT")))
|
||||||
|
line = line.split(QString("$PROJECT"))[0] +
|
||||||
|
QString(PROJECT) +
|
||||||
|
line.split(QString("$PROJECT"))[1];
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GithubModule::sendReportUsingGithub(const QMap<QString, QString> info)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << "[GithubModule]" << "[sendReportUsingGithub]";
|
||||||
|
|
||||||
// authentication
|
// authentication
|
||||||
QString username = ui->lineEdit_username->text();
|
QString concatenated = info[QString("username")] + QString(":") + info[QString("password")];
|
||||||
QString password = ui->lineEdit_password->text();
|
|
||||||
QString concatenated = username + QString(":") + password;
|
|
||||||
QByteArray userData = concatenated.toLocal8Bit().toBase64();
|
QByteArray userData = concatenated.toLocal8Bit().toBase64();
|
||||||
QString headerData = QString("Basic ") + userData;
|
QString headerData = QString("Basic ") + userData;
|
||||||
// text
|
// text
|
||||||
QString title = ui->lineEdit_title->text();
|
QByteArray text = prepareRequest(info[QString("title")], info[QString("body")]);
|
||||||
QString body = ui->textEdit->toPlainText();
|
|
||||||
QByteArray text = prepareRequest(title, body);
|
|
||||||
QByteArray textSize = QByteArray::number(text.size());
|
QByteArray textSize = QByteArray::number(text.size());
|
||||||
// sending request
|
// sending request
|
||||||
QNetworkRequest request = QNetworkRequest(parseString(QString(ISSUES_URL)));
|
QNetworkRequest request = QNetworkRequest(parseString(QString(ISSUES_URL)));
|
||||||
@ -59,15 +120,15 @@ void Reportabug::sendReportUsingGithub()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::githubFinished(QNetworkReply *reply)
|
void GithubModule::githubFinished(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]";
|
if (debug) qDebug() << "[GithubModule]" << "[githubFinished]";
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Error state" << reply->error();
|
if (debug) qDebug() << "[GithubModule]" << "[githubFinished]" << ":" << "Error state" << reply->error();
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Reply size" << reply->readBufferSize();
|
if (debug) qDebug() << "[GithubModule]" << "[githubFinished]" << ":" << "Reply size" << reply->readBufferSize();
|
||||||
|
|
||||||
int state = true;
|
int state = true;
|
||||||
QString answer = reply->readAll();
|
QString answer = reply->readAll();
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[replyFinished]" << ":" << answer;
|
if (debug) qDebug() << "[GithubModule]" << "[replyFinished]" << ":" << answer;
|
||||||
QString messageBody, messageTitle;
|
QString messageBody, messageTitle;
|
||||||
QMessageBox::Icon icon = QMessageBox::NoIcon;
|
QMessageBox::Icon icon = QMessageBox::NoIcon;
|
||||||
if (answer.contains(QString("\"html_url\":"))) {
|
if (answer.contains(QString("\"html_url\":"))) {
|
||||||
@ -109,10 +170,10 @@ void Reportabug::githubFinished(QNetworkReply *reply)
|
|||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case QMessageBox::Ok:
|
case QMessageBox::Ok:
|
||||||
if (state) close();
|
if (state) mainWindow->close();
|
||||||
break;
|
break;
|
||||||
case QMessageBox::Retry:
|
case QMessageBox::Retry:
|
||||||
if (state) updateTabs(ui->comboBox->currentIndex());
|
if (state) mainWindow->externalUpdateTab();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
51
sources/src/githubmodule.h
Normal file
51
sources/src/githubmodule.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of reportabug *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 3.0 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef GITHUBMODULE_H
|
||||||
|
#define GITHUBMODULE_H
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
class Reportabug;
|
||||||
|
class QNetworkReply;
|
||||||
|
|
||||||
|
class GithubModule : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GithubModule(QWidget *parent = 0,
|
||||||
|
bool debugCmd = false);
|
||||||
|
~GithubModule();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void sendReportUsingGithub(const QMap<QString, QString> info);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void githubFinished(QNetworkReply *reply);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool debug;
|
||||||
|
Reportabug *mainWindow;
|
||||||
|
QString parseString(QString line);
|
||||||
|
QByteArray prepareRequest(const QString title, const QString body);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* GITHUBMODULE_H */
|
@ -15,20 +15,41 @@
|
|||||||
* License along with this library. *
|
* License along with this library. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "gitreportmodule.h"
|
||||||
#include "reportabug.h"
|
#include "reportabug.h"
|
||||||
#include "ui_reportabug.h"
|
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QWebElement>
|
#include <QWebElement>
|
||||||
#include <QWebFrame>
|
#include <QWebFrame>
|
||||||
#include <QWebView>
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::sendReportUsingGitreport()
|
GitreportModule::GitreportModule(QWidget *parent, bool debugCmd)
|
||||||
|
: QObject(parent),
|
||||||
|
debug(debugCmd),
|
||||||
|
mainWindow((Reportabug *)parent)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[sendReportUsingGitreport]";
|
webView = new QWebView();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GitreportModule::~GitreportModule()
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << "[GitreportModule]" << "[~GitreportModule]";
|
||||||
|
|
||||||
|
delete webView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GitreportModule::sendReportUsingGitreport(const QMap<QString, QString> info)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << "[GitreportModule]" << "[sendReportUsingGitreport]";
|
||||||
|
|
||||||
QWebElement document = webView->page()->mainFrame()->documentElement();
|
QWebElement document = webView->page()->mainFrame()->documentElement();
|
||||||
QWebElement captcha = document.findFirst(QString("input#captcha"));
|
QWebElement captcha = document.findFirst(QString("input#captcha"));
|
||||||
@ -39,9 +60,9 @@ void Reportabug::sendReportUsingGitreport()
|
|||||||
QWebElement usernameInput = document.findFirst(QString("input#name"));
|
QWebElement usernameInput = document.findFirst(QString("input#name"));
|
||||||
|
|
||||||
// input
|
// input
|
||||||
usernameInput.setAttribute(QString("value"), ui->lineEdit_username->text());
|
usernameInput.setAttribute(QString("value"), info[QString("username")]);
|
||||||
emailInput.setAttribute(QString("value"), ui->lineEdit_password->text());
|
emailInput.setAttribute(QString("value"), info[QString("password")]);
|
||||||
textArea.setPlainText(ui->textEdit->toPlainText());
|
textArea.setPlainText(info[QString("body")]);
|
||||||
// captcha
|
// captcha
|
||||||
captchaImg.setAttribute(QString("src"), QString("/simple_captcha?code=%1&time=%2")
|
captchaImg.setAttribute(QString("src"), QString("/simple_captcha?code=%1&time=%2")
|
||||||
.arg(QString(CAPTCHA_KEY))
|
.arg(QString(CAPTCHA_KEY))
|
||||||
@ -57,21 +78,13 @@ void Reportabug::sendReportUsingGitreport()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::gitreportLoaded(const bool state)
|
void GitreportModule::gitreportLoaded(const bool state)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[gitreportLoaded]";
|
if (debug) qDebug() << "[GitreportModule]" << "[gitreportLoaded]";
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[gitreportLoaded]" << ":" << "State" << state;
|
if (debug) qDebug() << "[GitreportModule]" << "[gitreportLoaded]" << ":" << "State" << state;
|
||||||
|
|
||||||
if (state) {
|
if (state)
|
||||||
ui->widget_auth->setHidden(false);
|
|
||||||
ui->widget_title->setHidden(true);
|
|
||||||
ui->textEdit->setHidden(false);
|
|
||||||
webView->setHidden(!debug);
|
webView->setHidden(!debug);
|
||||||
ui->label_password->setText(QApplication::translate("Reportabug", "Email"));
|
|
||||||
ui->label_password->setToolTip(QApplication::translate("Reportabug", "Your email"));
|
|
||||||
ui->lineEdit_password->setPlaceholderText(QApplication::translate("Reportabug", "email"));
|
|
||||||
ui->lineEdit_password->setEchoMode(QLineEdit::Normal);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
QMessageBox messageBox;
|
QMessageBox messageBox;
|
||||||
messageBox.setText(QApplication::translate("Reportabug", "Error!"));
|
messageBox.setText(QApplication::translate("Reportabug", "Error!"));
|
||||||
@ -87,10 +100,10 @@ void Reportabug::gitreportLoaded(const bool state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::gitreportFinished(const bool state)
|
void GitreportModule::gitreportFinished(const bool state)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[gitreportFinished]";
|
if (debug) qDebug() << "[GitreportModule]" << "[gitreportFinished]";
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[gitreportFinished]" << ":" << "State" << state;
|
if (debug) qDebug() << "[GitreportModule]" << "[gitreportFinished]" << ":" << "State" << state;
|
||||||
|
|
||||||
QString messageBody, messageTitle;
|
QString messageBody, messageTitle;
|
||||||
QMessageBox::Icon icon = QMessageBox::NoIcon;
|
QMessageBox::Icon icon = QMessageBox::NoIcon;
|
||||||
@ -118,10 +131,10 @@ void Reportabug::gitreportFinished(const bool state)
|
|||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case QMessageBox::Ok:
|
case QMessageBox::Ok:
|
||||||
if (state) close();
|
if (state) mainWindow->close();
|
||||||
break;
|
break;
|
||||||
case QMessageBox::Retry:
|
case QMessageBox::Retry:
|
||||||
if (state) updateTabs(ui->comboBox->currentIndex());
|
if (state) mainWindow->externalUpdateTab();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
50
sources/src/gitreportmodule.h
Normal file
50
sources/src/gitreportmodule.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of reportabug *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 3.0 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef GITREPORTMODULE_H
|
||||||
|
#define GITREPORTMODULE_H
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWebView>
|
||||||
|
|
||||||
|
class Reportabug;
|
||||||
|
|
||||||
|
class GitreportModule : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GitreportModule(QWidget *parent = 0,
|
||||||
|
bool debugCmd = false);
|
||||||
|
~GitreportModule();
|
||||||
|
QWebView *webView;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void sendReportUsingGitreport(const QMap<QString, QString> info);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void gitreportFinished(const bool state);
|
||||||
|
void gitreportLoaded(const bool state);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool debug;
|
||||||
|
Reportabug *mainWindow;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* GITREPORTMODULE_H */
|
@ -19,17 +19,16 @@
|
|||||||
#include "ui_reportabug.h"
|
#include "ui_reportabug.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "version.h"
|
|
||||||
#ifdef ENABLE_GITHUB
|
#ifdef ENABLE_GITHUB
|
||||||
#include "githubmodule.cpp"
|
#include "githubmodule.h"
|
||||||
#endif /* ENABLE_GITHUB */
|
#endif /* ENABLE_GITHUB */
|
||||||
#ifdef ENABLE_GITREPORT
|
#ifdef ENABLE_GITREPORT
|
||||||
#include "gitreportmodule.cpp"
|
#include "gitreportmodule.h"
|
||||||
#endif /* ENABLE_GITREPORT */
|
#endif /* ENABLE_GITREPORT */
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
|
||||||
Reportabug::Reportabug(QWidget *parent, bool debugCmd)
|
Reportabug::Reportabug(QWidget *parent, bool debugCmd)
|
||||||
@ -38,12 +37,6 @@ Reportabug::Reportabug(QWidget *parent, bool debugCmd)
|
|||||||
ui(new Ui::Reportabug)
|
ui(new Ui::Reportabug)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
// add webview which is required by gitreport module
|
|
||||||
#ifdef ENABLE_GITREPORT
|
|
||||||
webView = new QWebView(this);
|
|
||||||
// 4 is a magic number. Seriously
|
|
||||||
ui->verticalLayout->insertWidget(4, webView);
|
|
||||||
#endif /* ENABLE_GITREPORT */
|
|
||||||
initModules();
|
initModules();
|
||||||
createComboBox();
|
createComboBox();
|
||||||
createActions();
|
createActions();
|
||||||
@ -54,13 +47,24 @@ Reportabug::~Reportabug()
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[~Reportabug]";
|
if (debug) qDebug() << "[Reportabug]" << "[~Reportabug]";
|
||||||
|
|
||||||
|
#ifdef ENABLE_GITHUB
|
||||||
|
delete github;
|
||||||
|
#endif /* ENABLE_GITHUB */
|
||||||
#ifdef ENABLE_GITREPORT
|
#ifdef ENABLE_GITREPORT
|
||||||
delete webView;
|
delete gitreport;
|
||||||
#endif /* ENABLE_GITREPORT */
|
#endif /* ENABLE_GITREPORT */
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Reportabug::externalUpdateTab()
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << "[Reportabug]" << "[externalUpdateTab]";
|
||||||
|
|
||||||
|
return updateTabs(ui->comboBox->currentIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::createActions()
|
void Reportabug::createActions()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[createActions]";
|
if (debug) qDebug() << "[Reportabug]" << "[createActions]";
|
||||||
@ -115,9 +119,13 @@ void Reportabug::initModules()
|
|||||||
|
|
||||||
#ifdef ENABLE_GITHUB
|
#ifdef ENABLE_GITHUB
|
||||||
modules[0] = true;
|
modules[0] = true;
|
||||||
|
github = new GithubModule(this, debug);
|
||||||
#endif /* ENABLE_GITHUB */
|
#endif /* ENABLE_GITHUB */
|
||||||
#ifdef ENABLE_GITREPORT
|
#ifdef ENABLE_GITREPORT
|
||||||
modules[1] = true;
|
modules[1] = true;
|
||||||
|
gitreport = new GitreportModule(this, debug);
|
||||||
|
// 4 is a magic number. Seriously
|
||||||
|
ui->verticalLayout->insertWidget(4, gitreport->webView);
|
||||||
#endif /* ENABLE_GITREPORT */
|
#endif /* ENABLE_GITREPORT */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,59 +157,33 @@ QString Reportabug::parseString(QString line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QByteArray Reportabug::prepareRequest(const QString title, const QString body)
|
|
||||||
{
|
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[prepareRequest]";
|
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[prepareRequest]" << ":" << "Title" << title;
|
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[prepareRequest]" << ":" << "Title" << body;
|
|
||||||
|
|
||||||
QStringList requestList;
|
|
||||||
requestList.append(QString("\"title\":\"") + title + QString("\""));
|
|
||||||
QString fixBody = body;
|
|
||||||
fixBody.replace(QString("\n"), QString("<br>"));
|
|
||||||
requestList.append(QString("\"body\":\"") + fixBody + QString("\""));
|
|
||||||
if (!QString(TAG_ASSIGNEE).isEmpty())
|
|
||||||
requestList.append(QString("\"assignee\":\"") + parseString(QString(TAG_ASSIGNEE)) + QString("\""));
|
|
||||||
if (!QString(TAG_MILESTONE).isEmpty())
|
|
||||||
requestList.append(QString("\"milestone\":") + QString(TAG_MILESTONE));
|
|
||||||
if (!QString(TAG_LABELS).isEmpty()) {
|
|
||||||
QStringList labels = QString(TAG_LABELS).split(QChar(','));
|
|
||||||
for (int i=0; i<labels.count(); i++)
|
|
||||||
labels[i] = QString("\"") + labels[i] + QString("\"");
|
|
||||||
requestList.append(QString("\"labels\":[") + labels.join(QChar(',')) + QString("]"));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString request;
|
|
||||||
request += QString("{");
|
|
||||||
request += requestList.join(QChar(','));
|
|
||||||
request += QString("}");
|
|
||||||
|
|
||||||
return request.toLatin1();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::sendReport()
|
void Reportabug::sendReport()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << "[Reportabug]" << "[sendReport]";
|
if (debug) qDebug() << "[Reportabug]" << "[sendReport]";
|
||||||
|
|
||||||
int number = getNumberByIndex(ui->comboBox->currentIndex());
|
int number = getNumberByIndex(ui->comboBox->currentIndex());
|
||||||
|
QMap<QString, QString> info;
|
||||||
|
info[QString("username")] = ui->lineEdit_username->text();
|
||||||
|
info[QString("password")] = ui->lineEdit_password->text();
|
||||||
|
info[QString("title")] = ui->lineEdit_title->text();
|
||||||
|
info[QString("body")] = ui->textEdit->toPlainText();
|
||||||
|
|
||||||
if (number == -1)
|
if (number == -1)
|
||||||
return;
|
return;
|
||||||
#ifdef ENABLE_GITHUB
|
#ifdef ENABLE_GITHUB
|
||||||
else if (number == 0)
|
else if (number == 0)
|
||||||
sendReportUsingGithub();
|
github->sendReportUsingGithub(info);
|
||||||
#endif /* ENABLE_GITHUB */
|
#endif /* ENABLE_GITHUB */
|
||||||
#ifdef ENABLE_GITREPORT
|
#ifdef ENABLE_GITREPORT
|
||||||
else if (number == 1)
|
else if (number == 1)
|
||||||
sendReportUsingGitreport();
|
gitreport->sendReportUsingGitreport(info);
|
||||||
#endif /* ENABLE_GITREPORT */
|
#endif /* ENABLE_GITREPORT */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::showWindow()
|
void Reportabug::showWindow()
|
||||||
{
|
{
|
||||||
updateTabs(ui->comboBox->currentIndex());
|
externalUpdateTab();
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,10 +194,14 @@ void Reportabug::updateTabs(const int index)
|
|||||||
if (debug) qDebug() << "[Reportabug]" << "[updateTabs]" << ":" << "Index" << index;
|
if (debug) qDebug() << "[Reportabug]" << "[updateTabs]" << ":" << "Index" << index;
|
||||||
|
|
||||||
int number = getNumberByIndex(index);
|
int number = getNumberByIndex(index);
|
||||||
|
ui->lineEdit_username->clear();
|
||||||
|
ui->lineEdit_password->clear();
|
||||||
|
ui->lineEdit_title->setText(QString(TAG_TITLE));
|
||||||
|
ui->textEdit->setPlainText(QString(TAG_BODY));
|
||||||
|
|
||||||
// it is out of conditional because I don't want a lot of ifdef/endif
|
// it is out of conditional because I don't want a lot of ifdef/endif
|
||||||
#ifdef ENABLE_GITREPORT
|
#ifdef ENABLE_GITREPORT
|
||||||
webView->setHidden(true);
|
gitreport->webView->setHidden(true);
|
||||||
#endif /* ENABLE_GITREPORT */
|
#endif /* ENABLE_GITREPORT */
|
||||||
if (number == -1) {
|
if (number == -1) {
|
||||||
ui->widget_auth->setHidden(true);
|
ui->widget_auth->setHidden(true);
|
||||||
@ -231,26 +217,22 @@ void Reportabug::updateTabs(const int index)
|
|||||||
ui->label_password->setToolTip(QApplication::translate("Reportabug", "GitHub account password"));
|
ui->label_password->setToolTip(QApplication::translate("Reportabug", "GitHub account password"));
|
||||||
ui->lineEdit_password->setPlaceholderText(QApplication::translate("Reportabug", "password"));
|
ui->lineEdit_password->setPlaceholderText(QApplication::translate("Reportabug", "password"));
|
||||||
ui->lineEdit_password->setEchoMode(QLineEdit::Password);
|
ui->lineEdit_password->setEchoMode(QLineEdit::Password);
|
||||||
|
|
||||||
ui->lineEdit_username->clear();
|
|
||||||
ui->lineEdit_password->clear();
|
|
||||||
ui->lineEdit_title->setText(QString(TAG_TITLE));
|
|
||||||
ui->textEdit->setPlainText(QString(TAG_BODY));
|
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_GITHUB */
|
#endif /* ENABLE_GITHUB */
|
||||||
#ifdef ENABLE_GITREPORT
|
#ifdef ENABLE_GITREPORT
|
||||||
else if (number == 1) {
|
else if (number == 1) {
|
||||||
ui->widget_auth->setHidden(true);
|
ui->widget_auth->setHidden(false);
|
||||||
ui->widget_title->setHidden(true);
|
ui->widget_title->setHidden(true);
|
||||||
ui->textEdit->setHidden(true);
|
ui->textEdit->setHidden(false);
|
||||||
|
ui->label_password->setText(QApplication::translate("Reportabug", "Email"));
|
||||||
|
ui->label_password->setToolTip(QApplication::translate("Reportabug", "Your email"));
|
||||||
|
ui->lineEdit_password->setPlaceholderText(QApplication::translate("Reportabug", "email"));
|
||||||
|
ui->lineEdit_password->setEchoMode(QLineEdit::Normal);
|
||||||
|
|
||||||
ui->lineEdit_username->clear();
|
gitreport->webView->load(QUrl(parseString(QString(PUBLIC_URL))));
|
||||||
ui->lineEdit_password->clear();
|
disconnect(gitreport->webView, SIGNAL(loadFinished(bool)), gitreport, SLOT(gitreportLoaded(bool)));
|
||||||
ui->textEdit->setPlainText(QString(TAG_BODY));
|
disconnect(gitreport->webView, SIGNAL(loadFinished(bool)), gitreport, SLOT(gitreportFinished(bool)));
|
||||||
webView->load(QUrl(parseString(QString(PUBLIC_URL))));
|
connect(gitreport->webView, SIGNAL(loadFinished(bool)), gitreport, SLOT(gitreportLoaded(bool)));
|
||||||
disconnect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool)));
|
|
||||||
disconnect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool)));
|
|
||||||
connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool)));
|
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_GITREPORT */
|
#endif /* ENABLE_GITREPORT */
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,9 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef ENABLE_GITHUB
|
class GithubModule;
|
||||||
class QNetworkReply;
|
class GitreportModule;
|
||||||
#endif /* ENABLE_GITHUB */
|
|
||||||
#ifdef ENABLE_GITREPORT
|
|
||||||
class QWebView;
|
|
||||||
#endif /* ENABLE_GITREPORT */
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Reportabug;
|
class Reportabug;
|
||||||
}
|
}
|
||||||
@ -41,38 +38,26 @@ public:
|
|||||||
explicit Reportabug(QWidget *parent = 0,
|
explicit Reportabug(QWidget *parent = 0,
|
||||||
bool debugCmd = false);
|
bool debugCmd = false);
|
||||||
~Reportabug();
|
~Reportabug();
|
||||||
|
void externalUpdateTab();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sendReport();
|
void sendReport();
|
||||||
void showWindow();
|
void showWindow();
|
||||||
void updateTabs(const int index);
|
void updateTabs(const int index);
|
||||||
|
|
||||||
private slots:
|
|
||||||
#ifdef ENABLE_GITHUB
|
|
||||||
void sendReportUsingGithub();
|
|
||||||
void githubFinished(QNetworkReply *reply);
|
|
||||||
#endif /* ENABLE_GITHUB */
|
|
||||||
#ifdef ENABLE_GITREPORT
|
|
||||||
void sendReportUsingGitreport();
|
|
||||||
void gitreportFinished(const bool state);
|
|
||||||
void gitreportLoaded(const bool state);
|
|
||||||
#endif /* ENABLE_GITREPORT */
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool debug;
|
bool debug;
|
||||||
bool modules[2];
|
bool modules[2];
|
||||||
#ifdef ENABLE_GITREPORT
|
|
||||||
// add webview which is required by gitreport module
|
|
||||||
QWebView *webView;
|
|
||||||
#endif /* ENABLE_GITREPORT */
|
|
||||||
Ui::Reportabug *ui;
|
Ui::Reportabug *ui;
|
||||||
|
// modules
|
||||||
|
GithubModule *github;
|
||||||
|
GitreportModule *gitreport;
|
||||||
void createActions();
|
void createActions();
|
||||||
void createComboBox();
|
void createComboBox();
|
||||||
int getNumberByIndex(const int index);
|
int getNumberByIndex(const int index);
|
||||||
void initModules();
|
void initModules();
|
||||||
void keyPressEvent(QKeyEvent *pressedKey);
|
void keyPressEvent(QKeyEvent *pressedKey);
|
||||||
QString parseString(QString line);
|
QString parseString(QString line);
|
||||||
QByteArray prepareRequest(const QString title, const QString body);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user