mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-12 21:35:51 +00:00
add reportabug 1.0.2
This commit is contained in:
73
sources/reportabug/CMakeLists.txt
Normal file
73
sources/reportabug/CMakeLists.txt
Normal file
@ -0,0 +1,73 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
|
||||
cmake_policy (SET CMP0003 OLD)
|
||||
cmake_policy (SET CMP0002 OLD)
|
||||
cmake_policy (SET CMP0011 NEW)
|
||||
cmake_policy (SET CMP0015 NEW)
|
||||
cmake_policy (SET CMP0048 OLD)
|
||||
|
||||
project (reportabug)
|
||||
|
||||
set (SUBPROJECT reportabug)
|
||||
set (SUBPROJECT_AUTHOR "Evgeniy Alekseev")
|
||||
set (SUBPROJECT_CONTACT "esalexeev@gmail.com")
|
||||
set (SUBPROJECT_LICENSE "LGPLv3")
|
||||
set (SUBPROJECT_VERSION_MAJOR 1)
|
||||
set (SUBPROJECT_VERSION_MINOR 0)
|
||||
set (SUBPROJECT_VERSION_PATCH 2)
|
||||
set (SUBPROJECT_VERSION ${SUBPROJECT_VERSION_MAJOR}.${SUBPROJECT_VERSION_MINOR}.${SUBPROJECT_VERSION_PATCH})
|
||||
string (TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M" UTC)
|
||||
string (TIMESTAMP CURRENT_YEAR "%Y")
|
||||
|
||||
message (STATUS "Subproject: ${SUBPROJECT}")
|
||||
message (STATUS "Version: ${SUBPROJECT_VERSION}")
|
||||
message (STATUS "Build date: ${CURRENT_DATE}")
|
||||
|
||||
# install options
|
||||
set (BUILD_AS_LIBRARY ON CACHE BOOL "Build the application as a shared library")
|
||||
set (BUILD_DOCS OFF CACHE BOOL "Build developers documentation")
|
||||
set (ENABLE_GITHUB ON CACHE BOOL "Enable GitHub module")
|
||||
set (ENABLE_GITREPORT ON CACHE BOOL "Enable GitReport module")
|
||||
set (USE_QT5 ON CACHE BOOL "Use Qt5 instead of Qt4")
|
||||
set (OWN_GITHUB_TOKEN "" CACHE STRING "Use own GitHub token instead of GitReport")
|
||||
# set flags
|
||||
if (OWN_GITHUB_TOKEN STREQUAL "")
|
||||
set (USE_OWN_TOKEN OFF)
|
||||
else ()
|
||||
set (USE_OWN_TOKEN ON)
|
||||
endif ()
|
||||
if (USE_OWN_TOKEN)
|
||||
set (ENABLE_GITREPORT OFF)
|
||||
endif ()
|
||||
|
||||
# flags
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set (ADD_CXX_FLAGS "-Wall")
|
||||
set (CMAKE_CXX_FLAGS "-O0 ${ADD_CXX_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
else ()
|
||||
message (STATUS "Unknown compiler")
|
||||
endif ()
|
||||
|
||||
configure_file (${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
|
||||
|
||||
# build
|
||||
# set directories
|
||||
set (SUBPROJECT_BINARY_DIR bin)
|
||||
set (SUBPROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
# executable path
|
||||
set (EXECUTABLE_OUTPUT_PATH ${SUBPROJECT_BINARY_DIR})
|
||||
|
||||
# additional targets
|
||||
set (TARGETS "")
|
||||
set (HEADERS "")
|
||||
|
||||
add_subdirectory (${SUBPROJECT_SOURCE_DIR})
|
||||
|
||||
if (BUILD_DOCS)
|
||||
include (docs.cmake)
|
||||
endif ()
|
||||
if (NOT BUILD_AS_LIBRARY)
|
||||
install (FILES ${SUBPROJECT}.desktop DESTINATION share/applications/)
|
||||
endif ()
|
21
sources/reportabug/docs.cmake
Normal file
21
sources/reportabug/docs.cmake
Normal file
@ -0,0 +1,21 @@
|
||||
# include files
|
||||
install (FILES ${HEADERS} DESTINATION include/${SUBPROJECT})
|
||||
|
||||
# doxygen documentation
|
||||
find_package (Doxygen)
|
||||
if (NOT DOXYGEN_FOUND)
|
||||
message (STATUS "WARNING: Doxygen not found - Reference manual will not be created")
|
||||
return ()
|
||||
endif ()
|
||||
|
||||
configure_file (doxygen.conf.in ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf)
|
||||
add_custom_target (oxygen-docs ALL COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf)
|
||||
|
||||
# man pages
|
||||
# workaround for man pages
|
||||
set (MAN_DIR ${CMAKE_CURRENT_BINARY_DIR}/docs/man/man3)
|
||||
install (FILES ${MAN_DIR}/Reportabug.3 DESTINATION share/man/man3 RENAME ${SUBPROJECT}_Reportabug.3)
|
||||
install (FILES ${MAN_DIR}/GithubModule.3 DESTINATION share/man/man3 RENAME ${SUBPROJECT}_GithubModule.3)
|
||||
install (FILES ${MAN_DIR}/GitreportModule.3 DESTINATION share/man/man3 RENAME ${SUBPROJECT}_GitreportModule.3)
|
||||
# html docs
|
||||
install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs/html DESTINATION share/doc/${SUBPROJECT})
|
2321
sources/reportabug/doxygen.conf.in
Normal file
2321
sources/reportabug/doxygen.conf.in
Normal file
File diff suppressed because it is too large
Load Diff
10
sources/reportabug/reportabug.desktop
Normal file
10
sources/reportabug/reportabug.desktop
Normal file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env xdg-open
|
||||
[Desktop Entry]
|
||||
Name=Report a bug
|
||||
Comment=A simple Qt application which allows users to create an issue for GitHub projects
|
||||
Exec=reportabug
|
||||
Icon=tools-report-bug
|
||||
Terminal=false
|
||||
Encoding=UTF-8
|
||||
Type=Application
|
||||
Categories=system
|
1
sources/reportabug/reportabug.h
Symbolic link
1
sources/reportabug/reportabug.h
Symbolic link
@ -0,0 +1 @@
|
||||
src/reportabug.h
|
66
sources/reportabug/src/CMakeLists.txt
Normal file
66
sources/reportabug/src/CMakeLists.txt
Normal file
@ -0,0 +1,66 @@
|
||||
# set files
|
||||
set (SOURCES ${SUBPROJECT_SOURCE_DIR}/main.cpp ${SUBPROJECT_SOURCE_DIR}/reportabug.cpp)
|
||||
set (HEADERS ${SUBPROJECT_SOURCE_DIR}/reportabug.h ${SUBPROJECT_SOURCE_DIR}/config.h)
|
||||
set (FORMS ${SUBPROJECT_SOURCE_DIR}/reportabug.ui)
|
||||
if (ENABLE_GITHUB OR USE_OWN_TOKEN)
|
||||
set (SOURCES ${SOURCES} ${SUBPROJECT_SOURCE_DIR}/githubmodule.cpp)
|
||||
set (HEADERS ${HEADERS} ${SUBPROJECT_SOURCE_DIR}/githubmodule.h)
|
||||
endif ()
|
||||
if (ENABLE_GITREPORT)
|
||||
set (SOURCES ${SOURCES} ${SUBPROJECT_SOURCE_DIR}/gitreportmodule.cpp)
|
||||
set (HEADERS ${HEADERS} ${SUBPROJECT_SOURCE_DIR}/gitreportmodule.h)
|
||||
endif ()
|
||||
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/inconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/inconfig.h)
|
||||
|
||||
# include_path
|
||||
include_directories (${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
if (USE_QT5)
|
||||
find_package (Qt5Core REQUIRED)
|
||||
find_package (Qt5Widgets REQUIRED)
|
||||
find_package (Qt5Network REQUIRED)
|
||||
add_definitions (${Qt5Core_DEFINITIONS})
|
||||
add_definitions (${Qt5Widgets_DEFINITIONS})
|
||||
add_definitions (${Qt5Network_DEFINITIONS})
|
||||
include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS})
|
||||
set (QT_USED_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES})
|
||||
if (ENABLE_GITREPORT)
|
||||
find_package (Qt5WebKit REQUIRED)
|
||||
find_package (Qt5WebKitWidgets REQUIRED)
|
||||
add_definitions (${Qt5WebKit_DEFINITIONS})
|
||||
add_definitions (${Qt5WebKitWidgets_DEFINITIONS})
|
||||
include_directories (${Qt5WebKit_INCLUDE_DIRS} ${Qt5WebKitWidgets_INCLUDE_DIRS})
|
||||
set (QT_USED_LIBRARIES ${QT_USED_LIBRARIES} ${Qt5WebKit_LIBRARIES} ${Qt5WebKitWidgets_LIBRARIES})
|
||||
endif ()
|
||||
qt5_wrap_cpp (MOC_SOURCES ${HEADERS})
|
||||
qt5_wrap_ui (UI_HEADERS ${FORMS})
|
||||
else ()
|
||||
set (QT_USED_COMPONENTS QtCore QtGui QtNetwork)
|
||||
if (ENABLE_GITREPORT)
|
||||
set (QT_USED_COMPONENTS ${QT_USED_COMPONENTS} QtWebKit)
|
||||
endif ()
|
||||
find_package(Qt4 COMPONENTS ${QT_USED_COMPONENTS} REQUIRED)
|
||||
include (${QT_USE_FILE})
|
||||
set (QT_USED_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTNETWORK_LIBRARY})
|
||||
if (ENABLE_GITREPORT)
|
||||
set (QT_USED_LIBRARIES ${QT_USED_LIBRARIES} ${QT_QTWEBKIT_LIBRARY})
|
||||
endif ()
|
||||
qt4_wrap_cpp (MOC_SOURCES ${HEADERS})
|
||||
qt4_wrap_ui (UI_HEADERS ${FORMS})
|
||||
endif()
|
||||
|
||||
if (BUILD_AS_LIBRARY)
|
||||
add_library (${SUBPROJECT} SHARED ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${UI_HEADERS})
|
||||
else ()
|
||||
add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES})
|
||||
endif ()
|
||||
target_link_libraries (${SUBPROJECT} ${QT_USED_LIBRARIES})
|
||||
# install properties
|
||||
if (BUILD_AS_LIBRARY)
|
||||
install (TARGETS ${SUBPROJECT} DESTINATION lib)
|
||||
else ()
|
||||
install (TARGETS ${SUBPROJECT} DESTINATION bin)
|
||||
endif ()
|
76
sources/reportabug/src/config.h
Normal file
76
sources/reportabug/src/config.h
Normal file
@ -0,0 +1,76 @@
|
||||
/***************************************************************************
|
||||
* 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 CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <inconfig.h>
|
||||
|
||||
|
||||
/*
|
||||
* Main configuration
|
||||
*/
|
||||
// the owner of the source repository
|
||||
#define OWNER "arcan1s"
|
||||
// project name
|
||||
#define PROJECT "netctl-gui"
|
||||
// tags defaults
|
||||
#define TAG_TITLE "A new bug"
|
||||
#define TAG_BODY "Some error occurs"
|
||||
// the following tags will work only if user has push access
|
||||
// if they will be empty, they will be ignored
|
||||
#define TAG_ASSIGNEE "$OWNER"
|
||||
#define TAG_MILESTONE ""
|
||||
// comma separated
|
||||
#define TAG_LABELS ""
|
||||
|
||||
/*
|
||||
* Configuration of creating an issue using GitHub API
|
||||
*/
|
||||
// combobox text
|
||||
#define GITHUB_COMBOBOX "I want to report a bug using my GitHub account"
|
||||
// issues url; in the most cases do not touch it
|
||||
// available tags are $PROJECT, $OWNER
|
||||
#define ISSUES_URL "https://api.github.com/repos/$OWNER/$PROJECT/issues"
|
||||
|
||||
/*
|
||||
* Configuration of creating an issue using GitHub API and own token
|
||||
*
|
||||
* This module will be used instead of GitReport module.
|
||||
* To create a token please visit https://github.com/settings/applications
|
||||
* and generate new one. Needed scopes are public_repo
|
||||
* (or repo if you will use it for a private repository).
|
||||
* Please keep in mind that passing the token in the clear,
|
||||
* you may discredit your account.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Configuration of creating an issue using GitReports
|
||||
*
|
||||
* Please, visit https://gitreports.com/
|
||||
* and set up it for your repository.
|
||||
*/
|
||||
// combobox text
|
||||
#define GITREPORT_COMBOBOX "GitHub? I don't understand what do you want from me!"
|
||||
// public link; in the most cases do not touch it
|
||||
// available tags are $PROJECT, $OWNER
|
||||
#define PUBLIC_URL "https://gitreports.com/issue/$OWNER/$PROJECT"
|
||||
// captcha url; in the most cases do not touch it
|
||||
#define CAPTCHA_URL "https://gitreports.com/simple_captcha?code="
|
||||
|
||||
|
||||
#endif /* CONFIG_H */
|
215
sources/reportabug/src/githubmodule.cpp
Normal file
215
sources/reportabug/src/githubmodule.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
/***************************************************************************
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
/**
|
||||
* @file githubmodule.cpp
|
||||
* Source code of reportabug
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright LGPLv3
|
||||
* @bug https://github.com/arcan1s/reportabug/issues
|
||||
*/
|
||||
|
||||
#include "githubmodule.h"
|
||||
#include "reportabug.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QGridLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
/**
|
||||
* @class GithubModule
|
||||
*/
|
||||
/**
|
||||
* @fn GithubModule
|
||||
*/
|
||||
GithubModule::GithubModule(QWidget *parent, bool debugCmd)
|
||||
: QObject(parent),
|
||||
debug(debugCmd),
|
||||
mainWindow((Reportabug *)parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn ~GithubModule
|
||||
*/
|
||||
GithubModule::~GithubModule()
|
||||
{
|
||||
if (debug) qDebug() << "[GithubModule]" << "[~GithubModule]";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn prepareRequest
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn parseString
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn sendReportUsingGithub
|
||||
*/
|
||||
void GithubModule::sendReportUsingGithub(const QMap<QString, QString> info)
|
||||
{
|
||||
if (debug) qDebug() << "[GithubModule]" << "[sendReportUsingGithub]";
|
||||
|
||||
// authentication
|
||||
QString headerData;
|
||||
if (info.contains(QString("userdata")))
|
||||
headerData = QString("token ") + info[QString("userdata")];
|
||||
else {
|
||||
QString concatenated = info[QString("username")] + QString(":") + info[QString("password")];
|
||||
QByteArray userData = concatenated.toLocal8Bit().toBase64();
|
||||
headerData = QString("Basic ") + userData;
|
||||
}
|
||||
// text
|
||||
QByteArray text = prepareRequest(info[QString("title")], info[QString("body")]);
|
||||
QByteArray textSize = QByteArray::number(text.size());
|
||||
// sending request
|
||||
QNetworkRequest request = QNetworkRequest(parseString(QString(ISSUES_URL)));
|
||||
request.setRawHeader("Authorization", headerData.toLocal8Bit());
|
||||
request.setRawHeader("User-Agent", "reportabug");
|
||||
request.setRawHeader("Host", "api.github.com");
|
||||
request.setRawHeader("Accept", "*/*");
|
||||
request.setRawHeader("Content-Type", "application/vnd.github.VERSION.raw+json");
|
||||
request.setRawHeader("Content-Length", textSize);
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager;
|
||||
manager->post(request, text);
|
||||
disconnect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(githubFinished(QNetworkReply *)));
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(githubFinished(QNetworkReply *)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn githubFinished
|
||||
*/
|
||||
void GithubModule::githubFinished(QNetworkReply *reply)
|
||||
{
|
||||
if (debug) qDebug() << "[GithubModule]" << "[githubFinished]";
|
||||
if (debug) qDebug() << "[GithubModule]" << "[githubFinished]" << ":" << "Error state" << reply->error();
|
||||
if (debug) qDebug() << "[GithubModule]" << "[githubFinished]" << ":" << "Reply size" << reply->readBufferSize();
|
||||
|
||||
bool state = true;
|
||||
QString answer = reply->readAll();
|
||||
if (debug) qDebug() << "[GithubModule]" << "[replyFinished]" << ":" << answer;
|
||||
QString messageBody, messageTitle;
|
||||
QMessageBox::Icon icon = QMessageBox::NoIcon;
|
||||
if (answer.contains(QString("\"html_url\":"))) {
|
||||
QString url;
|
||||
for (int i=0; i<answer.split(QChar(',')).count(); i++)
|
||||
if (answer.split(QChar(','))[i].split(QChar(':'))[0] == QString("\"html_url\"")) {
|
||||
url = answer.split(QChar(','))[i].split(QString("\"html_url\":"))[1].remove(QChar('"'));
|
||||
break;
|
||||
}
|
||||
messageBody += QString("%1\n").arg(QApplication::translate("Reportabug", "Message has been sended"));
|
||||
messageBody += QString("Url: %2").arg(url);
|
||||
messageTitle = QApplication::translate("Reportabug", "Done!");
|
||||
icon = QMessageBox::Information;
|
||||
state = true;
|
||||
}
|
||||
else if (answer.contains(QString("\"Bad credentials\""))) {
|
||||
messageBody += QApplication::translate("Reportabug", "Incorrect username or password");
|
||||
messageTitle = QApplication::translate("Reportabug", "Error!");
|
||||
icon = QMessageBox::Critical;
|
||||
state = false;
|
||||
}
|
||||
else {
|
||||
messageBody += QApplication::translate("Reportabug", "An error occurs");
|
||||
messageTitle = QApplication::translate("Reportabug", "Error!");
|
||||
icon = QMessageBox::Critical;
|
||||
state = false;
|
||||
}
|
||||
reply->deleteLater();
|
||||
|
||||
QMessageBox messageBox;
|
||||
messageBox.setText(messageTitle);
|
||||
messageBox.setInformativeText(messageBody);
|
||||
messageBox.setIcon(icon);
|
||||
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Retry);
|
||||
messageBox.setDefaultButton(QMessageBox::Ok);
|
||||
QSpacerItem *horizontalSpacer = new QSpacerItem(400, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
QGridLayout *layout = (QGridLayout *)messageBox.layout();
|
||||
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
|
||||
int ret = messageBox.exec();
|
||||
|
||||
switch (ret) {
|
||||
case QMessageBox::Ok:
|
||||
if (state) mainWindow->close();
|
||||
break;
|
||||
case QMessageBox::Retry:
|
||||
if (state) mainWindow->externalUpdateTab();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
114
sources/reportabug/src/githubmodule.h
Normal file
114
sources/reportabug/src/githubmodule.h
Normal file
@ -0,0 +1,114 @@
|
||||
/***************************************************************************
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
/**
|
||||
* @file githubmodule.h
|
||||
* Source code of reportabug
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright LGPLv3
|
||||
* @bug https://github.com/arcan1s/reportabug/issues
|
||||
*/
|
||||
|
||||
#ifndef GITHUBMODULE_H
|
||||
#define GITHUBMODULE_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class Reportabug;
|
||||
class QNetworkReply;
|
||||
|
||||
/**
|
||||
* @brief The GithubModule class creates issue over GitHub.
|
||||
* @details The GitHub API is used for creating issue. Please visit
|
||||
* [the API page](https://developer.github.com/v3/issues/) for more details.
|
||||
* This module requires an users authentication. The typical POST request is:
|
||||
* @code
|
||||
* curl -X POST -u user:pass -d '{"title":"A new bug","body":"Some error occurs"}' \
|
||||
* https://api.github.com/repos/owner/repo/issues
|
||||
* @endcode
|
||||
*
|
||||
* The module also may send request using given token. In this case request is:
|
||||
* @code
|
||||
* curl -X POST -H "Authorization: token token" -d '{"title":"A new bug","body":"Some error occurs"}' \
|
||||
* https://api.github.com/repos/owner/repo/issues
|
||||
* @endcode
|
||||
*
|
||||
* This module depends on QtNetwork module.
|
||||
*/
|
||||
class GithubModule : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief GithubModule class constructor
|
||||
* @param parent parent object
|
||||
* @param debugCmd show debug messages
|
||||
*/
|
||||
explicit GithubModule(QWidget *parent = 0,
|
||||
bool debugCmd = false);
|
||||
/**
|
||||
* @brief GithubModule class destructor
|
||||
*/
|
||||
~GithubModule();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief method which creates an issue
|
||||
* @param info issue details. Needed keys are:
|
||||
* body (body of an issue),
|
||||
* password (GitHub password),
|
||||
* title (title of an issue),
|
||||
* userdata (given GitHub token, it is optional key),
|
||||
* username (GitHub user name),
|
||||
*/
|
||||
void sendReportUsingGithub(const QMap<QString, QString> info);
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* @brief method which will be called after sending POST request
|
||||
* @param reply reply of the request
|
||||
*/
|
||||
void githubFinished(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief show debug messages
|
||||
*/
|
||||
bool debug;
|
||||
/**
|
||||
* @brief Reportabug class
|
||||
*/
|
||||
Reportabug *mainWindow;
|
||||
/**
|
||||
* @brief method which parses string and replace known tags
|
||||
* @param line source line
|
||||
* @return replaced line
|
||||
*/
|
||||
QString parseString(QString line);
|
||||
/**
|
||||
* @brief method which prepares raw issue details for sending request
|
||||
* @param title title of an issue
|
||||
* @param body body of an issue
|
||||
* @return JSON string
|
||||
*/
|
||||
QByteArray prepareRequest(const QString title, const QString body);
|
||||
};
|
||||
|
||||
|
||||
#endif /* GITHUBMODULE_H */
|
189
sources/reportabug/src/gitreportmodule.cpp
Normal file
189
sources/reportabug/src/gitreportmodule.cpp
Normal file
@ -0,0 +1,189 @@
|
||||
/***************************************************************************
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
/**
|
||||
* @file gitreportmodule.cpp
|
||||
* Source code of reportabug
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright LGPLv3
|
||||
* @bug https://github.com/arcan1s/reportabug/issues
|
||||
*/
|
||||
|
||||
#include "gitreportmodule.h"
|
||||
#include "reportabug.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QGridLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QPushButton>
|
||||
#include <QUrl>
|
||||
#include <QWebElement>
|
||||
#include <QWebFrame>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
/**
|
||||
* @class GitreportModule
|
||||
*/
|
||||
/**
|
||||
* @fn GitreportModule
|
||||
*/
|
||||
GitreportModule::GitreportModule(QWidget *parent, bool debugCmd)
|
||||
: QObject(parent),
|
||||
debug(debugCmd),
|
||||
mainWindow((Reportabug *)parent)
|
||||
{
|
||||
webView = new QWebView();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn ~GitreportModule
|
||||
*/
|
||||
GitreportModule::~GitreportModule()
|
||||
{
|
||||
if (debug) qDebug() << "[GitreportModule]" << "[~GitreportModule]";
|
||||
|
||||
delete webView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn sendReportUsingGitreport
|
||||
*/
|
||||
void GitreportModule::sendReportUsingGitreport(const QMap<QString, QString> info)
|
||||
{
|
||||
if (debug) qDebug() << "[GitreportModule]" << "[sendReportUsingGitreport]";
|
||||
|
||||
QWebElement document = webView->page()->mainFrame()->documentElement();
|
||||
QWebElement captchaKey = document.findFirst(QString("input#captcha"));
|
||||
QWebElement emailInput = document.findFirst(QString("input#email"));
|
||||
QWebElement textArea = document.findFirst(QString("textarea#details"));
|
||||
QWebElement usernameInput = document.findFirst(QString("input#name"));
|
||||
|
||||
// input
|
||||
usernameInput.setAttribute(QString("value"), info[QString("username")]);
|
||||
emailInput.setAttribute(QString("value"), info[QString("password")]);
|
||||
textArea.setPlainText(info[QString("body")]);
|
||||
captchaKey.setAttribute(QString("value"), info[QString("captcha")]);
|
||||
|
||||
// send request
|
||||
document.findFirst(QString("input[name=commit]")).evaluateJavaScript("this.click()");
|
||||
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(gitreportFinished(bool)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn gitreportLoaded
|
||||
*/
|
||||
void GitreportModule::gitreportLoaded(const bool state)
|
||||
{
|
||||
if (debug) qDebug() << "[GitreportModule]" << "[gitreportLoaded]";
|
||||
if (debug) qDebug() << "[GitreportModule]" << "[gitreportLoaded]" << ":" << "State" << state;
|
||||
|
||||
if (state) {
|
||||
webView->setHidden(!debug);
|
||||
// captcha
|
||||
QWebElement document = webView->page()->mainFrame()->documentElement();
|
||||
QWebElement captchaImg = document.findFirst(QString("input#captcha_key"));
|
||||
QString captchaUrl = QString(CAPTCHA_URL) + captchaImg.attribute(QString("value"));
|
||||
QNetworkRequest request(captchaUrl);
|
||||
manager.get(request);
|
||||
disconnect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(setCaptcha(QNetworkReply *)));
|
||||
connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(setCaptcha(QNetworkReply *)));
|
||||
}
|
||||
else {
|
||||
QMessageBox messageBox;
|
||||
messageBox.setText(QApplication::translate("Reportabug", "Error!"));
|
||||
messageBox.setInformativeText(QApplication::translate("Reportabug", "An error occurs"));
|
||||
messageBox.setIcon(QMessageBox::Critical);
|
||||
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Retry);
|
||||
messageBox.setDefaultButton(QMessageBox::Ok);
|
||||
QSpacerItem *horizontalSpacer = new QSpacerItem(400, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
QGridLayout *layout = (QGridLayout *)messageBox.layout();
|
||||
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
|
||||
messageBox.exec();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn gitreportFinished
|
||||
*/
|
||||
void GitreportModule::gitreportFinished(const bool state)
|
||||
{
|
||||
if (debug) qDebug() << "[GitreportModule]" << "[gitreportFinished]";
|
||||
if (debug) qDebug() << "[GitreportModule]" << "[gitreportFinished]" << ":" << "State" << state;
|
||||
|
||||
QString messageBody, messageTitle;
|
||||
QMessageBox::Icon icon = QMessageBox::NoIcon;
|
||||
if (state) {
|
||||
messageBody += QApplication::translate("Reportabug", "Message has been sended");
|
||||
messageTitle = QApplication::translate("Reportabug", "Done!");
|
||||
icon = QMessageBox::Information;
|
||||
}
|
||||
else {
|
||||
messageBody += QApplication::translate("Reportabug", "An error occurs");
|
||||
messageTitle = QApplication::translate("Reportabug", "Error!");
|
||||
icon = QMessageBox::Critical;
|
||||
}
|
||||
|
||||
QMessageBox messageBox;
|
||||
messageBox.setText(messageTitle);
|
||||
messageBox.setInformativeText(messageBody);
|
||||
messageBox.setIcon(icon);
|
||||
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Retry);
|
||||
messageBox.setDefaultButton(QMessageBox::Ok);
|
||||
QSpacerItem *horizontalSpacer = new QSpacerItem(400, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
QGridLayout *layout = (QGridLayout *)messageBox.layout();
|
||||
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
|
||||
int ret = messageBox.exec();
|
||||
|
||||
switch (ret) {
|
||||
case QMessageBox::Ok:
|
||||
if (state) mainWindow->close();
|
||||
break;
|
||||
case QMessageBox::Retry:
|
||||
if (state) mainWindow->externalUpdateTab();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setCaptcha
|
||||
*/
|
||||
void GitreportModule::setCaptcha(QNetworkReply *reply)
|
||||
{
|
||||
if (debug) qDebug() << "[setCaptcha]" << "[setCaptcha]";
|
||||
if (debug) qDebug() << "[setCaptcha]" << "[setCaptcha]" << ":" << "Error state" << reply->error();
|
||||
if (debug) qDebug() << "[setCaptcha]" << "[setCaptcha]" << ":" << "Reply size" << reply->readBufferSize();
|
||||
|
||||
QByteArray answer = reply->readAll();
|
||||
QPixmap captcha;
|
||||
captcha.loadFromData(answer);
|
||||
mainWindow->setCaptchaImage(captcha);
|
||||
reply->deleteLater();
|
||||
}
|
107
sources/reportabug/src/gitreportmodule.h
Normal file
107
sources/reportabug/src/gitreportmodule.h
Normal file
@ -0,0 +1,107 @@
|
||||
/***************************************************************************
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
/**
|
||||
* @file gitreportmodule.h
|
||||
* Source code of reportabug
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright LGPLv3
|
||||
* @bug https://github.com/arcan1s/reportabug/issues
|
||||
*/
|
||||
|
||||
#ifndef GITREPORTMODULE_H
|
||||
#define GITREPORTMODULE_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QWebView>
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class Reportabug;
|
||||
|
||||
/**
|
||||
* @brief The GitreportModule class creates issue over GitReports
|
||||
* @details This module uses [GitReport](https://gitreports.com/about) for
|
||||
* creating an issue. Please visit [this page](https://gitreports.com/)
|
||||
* and set up it for your repository.
|
||||
*
|
||||
* This module depends on QtWebKit and QtNetwork modules.
|
||||
*/
|
||||
class GitreportModule : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief GitreportModule class constructor
|
||||
* @param parent parent object
|
||||
* @param debugCmd show debug messages
|
||||
*/
|
||||
explicit GitreportModule(QWidget *parent = 0,
|
||||
bool debugCmd = false);
|
||||
/**
|
||||
* @brief GitreportModule class destructor
|
||||
*/
|
||||
~GitreportModule();
|
||||
/**
|
||||
* @brief Webkit item which is used for loading web page
|
||||
*/
|
||||
QWebView *webView;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief method which creates an issue
|
||||
* @param info issue details. Needed keys are:
|
||||
* body (body of an issue)
|
||||
* password (user email),
|
||||
* username (user name),
|
||||
*/
|
||||
void sendReportUsingGitreport(const QMap<QString, QString> info);
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* @brief method which will be called after sending request
|
||||
* @param bool state of web page loading
|
||||
*/
|
||||
void gitreportFinished(const bool state);
|
||||
/**
|
||||
* @brief method which will be called after loading of web page
|
||||
* @param bool state of web page loading
|
||||
*/
|
||||
void gitreportLoaded(const bool state);
|
||||
/**
|
||||
* @brief method which will be called after loading captcha image
|
||||
* @param reply reply of the request
|
||||
*/
|
||||
void setCaptcha(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief show debug messages
|
||||
*/
|
||||
bool debug;
|
||||
/**
|
||||
* @brief Reportabug class
|
||||
*/
|
||||
Reportabug *mainWindow;
|
||||
/**
|
||||
* @brief manager for getting captcha
|
||||
*/
|
||||
QNetworkAccessManager manager;
|
||||
};
|
||||
|
||||
|
||||
#endif /* GITREPORTMODULE_H */
|
35
sources/reportabug/src/inconfig.h.in
Normal file
35
sources/reportabug/src/inconfig.h.in
Normal file
@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
* 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 INCONFIG_H
|
||||
#define INCONFIG_H
|
||||
|
||||
|
||||
// DO NOT EDIT THIS FILE
|
||||
|
||||
/*
|
||||
* Main configuration
|
||||
*/
|
||||
// modules. Please use -DENABLE_GITHUB= and -DENABLE_GITREPORT= cmake flags
|
||||
#cmakedefine ENABLE_GITHUB
|
||||
#cmakedefine ENABLE_GITREPORT
|
||||
// please use -DOWN_GITHUB_TOKEN= cmake flag to define it
|
||||
// if it is empty, it will be ignored
|
||||
#cmakedefine OWN_GITHUB_TOKEN "@OWN_GITHUB_TOKEN@"
|
||||
|
||||
|
||||
#endif /* INCONFIG_H */
|
44
sources/reportabug/src/main.cpp
Normal file
44
sources/reportabug/src/main.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/***************************************************************************
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
/**
|
||||
* @file main.cpp
|
||||
* Source code of reportabug
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright LGPLv3
|
||||
* @bug https://github.com/arcan1s/reportabug/issues
|
||||
*/
|
||||
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "reportabug.h"
|
||||
#include "version.h"
|
||||
|
||||
/**
|
||||
* @fn main
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
/**
|
||||
* @return QApplication.exec()
|
||||
*/
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
Reportabug w(0, true);
|
||||
w.showWindow();
|
||||
return a.exec();
|
||||
}
|
327
sources/reportabug/src/reportabug.cpp
Normal file
327
sources/reportabug/src/reportabug.cpp
Normal file
@ -0,0 +1,327 @@
|
||||
/***************************************************************************
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
/**
|
||||
* @file reportabug.cpp
|
||||
* Source code of reportabug
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright LGPLv3
|
||||
* @bug https://github.com/arcan1s/reportabug/issues
|
||||
*/
|
||||
|
||||
#include "reportabug.h"
|
||||
#include "ui_reportabug.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "config.h"
|
||||
#if defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN)
|
||||
#include "githubmodule.h"
|
||||
#endif /* defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN) */
|
||||
#ifdef ENABLE_GITREPORT
|
||||
#include "gitreportmodule.h"
|
||||
#endif /* ENABLE_GITREPORT */
|
||||
#include "version.h"
|
||||
|
||||
|
||||
/**
|
||||
* @class Reportabug
|
||||
*/
|
||||
/**
|
||||
* @fn Reportabug
|
||||
*/
|
||||
Reportabug::Reportabug(QWidget *parent, bool debugCmd)
|
||||
: QMainWindow(parent),
|
||||
debug(debugCmd),
|
||||
ui(new Ui::Reportabug)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
initModules();
|
||||
createComboBox();
|
||||
createActions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn ~Reportabug
|
||||
*/
|
||||
Reportabug::~Reportabug()
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[~Reportabug]";
|
||||
|
||||
#if defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN)
|
||||
delete github;
|
||||
#endif /* defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN) */
|
||||
#ifdef ENABLE_GITREPORT
|
||||
delete gitreport;
|
||||
#endif /* ENABLE_GITREPORT */
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn externalUpdateTab
|
||||
*/
|
||||
void Reportabug::externalUpdateTab()
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[externalUpdateTab]";
|
||||
|
||||
return updateTabs(ui->comboBox->currentIndex());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setCaptchaImage
|
||||
*/
|
||||
void Reportabug::setCaptchaImage(QPixmap captcha)
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[setCaptchaImage]";
|
||||
|
||||
ui->label_captcha->setPixmap(captcha);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn createActions
|
||||
*/
|
||||
void Reportabug::createActions()
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[createActions]";
|
||||
|
||||
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTabs(int)));
|
||||
connect(ui->buttonBox->button(QDialogButtonBox::Close), SIGNAL(clicked(bool)), this, SLOT(close()));
|
||||
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(sendReport()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn createComboBox
|
||||
*/
|
||||
void Reportabug::createComboBox()
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[createComboBox]";
|
||||
|
||||
ui->comboBox->clear();
|
||||
if (modules[0])
|
||||
ui->comboBox->addItem(GITHUB_COMBOBOX);
|
||||
if (modules[1] || modules[2])
|
||||
ui->comboBox->addItem(GITREPORT_COMBOBOX);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn getNumberByIndex
|
||||
*/
|
||||
int Reportabug::getNumberByIndex(const int index)
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[getNumberByIndex]";
|
||||
if (debug) qDebug() << "[Reportabug]" << "[getNumberByIndex]" << ":" << "Index" << index;
|
||||
|
||||
if ((modules[0]) && (modules[1])) {
|
||||
if (index == 0)
|
||||
return 0;
|
||||
else if (index == 1)
|
||||
return 1;
|
||||
}
|
||||
else if ((modules[0]) && (modules[2])) {
|
||||
if (index == 0)
|
||||
return 0;
|
||||
else if (index == 1)
|
||||
return 2;
|
||||
}
|
||||
else if ((modules[1]) && (modules[2]))
|
||||
// wtf??
|
||||
return -1;
|
||||
else if (modules[0])
|
||||
return 0;
|
||||
else if (modules[1])
|
||||
return 1;
|
||||
else if (modules[2])
|
||||
return 2;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn initModules
|
||||
*/
|
||||
void Reportabug::initModules()
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[initModules]";
|
||||
|
||||
modules[0] = false;
|
||||
modules[1] = false;
|
||||
modules[2] = false;
|
||||
|
||||
#if defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN)
|
||||
github = new GithubModule(this, debug);
|
||||
#endif /* defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN) */
|
||||
#ifdef ENABLE_GITHUB
|
||||
modules[0] = true;
|
||||
#endif /* ENABLE_GITHUB */
|
||||
#ifdef ENABLE_GITREPORT
|
||||
modules[1] = true;
|
||||
gitreport = new GitreportModule(this, debug);
|
||||
// 4 is a magic number. Seriously
|
||||
ui->verticalLayout->insertWidget(5, gitreport->webView);
|
||||
#endif /* ENABLE_GITREPORT */
|
||||
#ifdef OWN_GITHUB_TOKEN
|
||||
modules[2] = true;
|
||||
#endif /* OWN_GITHUB_TOKEN */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn keyPressEvent
|
||||
*/
|
||||
void Reportabug::keyPressEvent(QKeyEvent *pressedKey)
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[keyPressEvent]";
|
||||
|
||||
if (pressedKey->key() == Qt::Key_Escape)
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn parseString
|
||||
*/
|
||||
QString Reportabug::parseString(QString line)
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[parseString]";
|
||||
if (debug) qDebug() << "[Reportabug]" << "[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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn sendReport
|
||||
*/
|
||||
void Reportabug::sendReport()
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[sendReport]";
|
||||
|
||||
int number = getNumberByIndex(ui->comboBox->currentIndex());
|
||||
QMap<QString, QString> info;
|
||||
info[QString("body")] = ui->textEdit->toPlainText();
|
||||
info[QString("captcha")] = ui->lineEdit_captcha->text();
|
||||
info[QString("password")] = ui->lineEdit_password->text();
|
||||
info[QString("title")] = ui->lineEdit_title->text();
|
||||
info[QString("username")] = ui->lineEdit_username->text();
|
||||
|
||||
if (number == -1)
|
||||
return;
|
||||
#ifdef ENABLE_GITHUB
|
||||
else if (number == 0)
|
||||
github->sendReportUsingGithub(info);
|
||||
#endif /* ENABLE_GITHUB */
|
||||
#ifdef ENABLE_GITREPORT
|
||||
else if (number == 1)
|
||||
gitreport->sendReportUsingGitreport(info);
|
||||
#endif /* ENABLE_GITREPORT */
|
||||
#ifdef OWN_GITHUB_TOKEN
|
||||
else if (number == 2) {
|
||||
info[QString("userdata")] = QString(OWN_GITHUB_TOKEN);
|
||||
github->sendReportUsingGithub(info);
|
||||
}
|
||||
#endif /* OWN_GITHUB_TOKEN */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn showWindow
|
||||
*/
|
||||
void Reportabug::showWindow()
|
||||
{
|
||||
externalUpdateTab();
|
||||
show();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn updateTabs
|
||||
*/
|
||||
void Reportabug::updateTabs(const int index)
|
||||
{
|
||||
if (debug) qDebug() << "[Reportabug]" << "[updateTabs]";
|
||||
if (debug) qDebug() << "[Reportabug]" << "[updateTabs]" << ":" << "Index" << 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));
|
||||
ui->lineEdit_captcha->clear();
|
||||
|
||||
// it is out of conditional because I don't want a lot of ifdef/endif
|
||||
#ifdef ENABLE_GITREPORT
|
||||
gitreport->webView->setHidden(true);
|
||||
#endif /* ENABLE_GITREPORT */
|
||||
if (number == -1) {
|
||||
ui->widget_auth->setHidden(true);
|
||||
ui->widget_title->setHidden(true);
|
||||
ui->textEdit->setHidden(true);
|
||||
ui->widget_captcha->setHidden(true);
|
||||
}
|
||||
#ifdef ENABLE_GITHUB
|
||||
else if (number == 0) {
|
||||
ui->widget_auth->setHidden(false);
|
||||
ui->widget_title->setHidden(false);
|
||||
ui->textEdit->setHidden(false);
|
||||
ui->widget_captcha->setHidden(true);
|
||||
ui->label_password->setText(QApplication::translate("Reportabug", "Password"));
|
||||
ui->label_password->setToolTip(QApplication::translate("Reportabug", "GitHub account password"));
|
||||
ui->lineEdit_password->setPlaceholderText(QApplication::translate("Reportabug", "password"));
|
||||
ui->lineEdit_password->setEchoMode(QLineEdit::Password);
|
||||
}
|
||||
#endif /* ENABLE_GITHUB */
|
||||
#ifdef ENABLE_GITREPORT
|
||||
else if (number == 1) {
|
||||
ui->widget_auth->setHidden(false);
|
||||
ui->widget_title->setHidden(true);
|
||||
ui->textEdit->setHidden(false);
|
||||
ui->widget_captcha->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);
|
||||
|
||||
gitreport->webView->load(QUrl(parseString(QString(PUBLIC_URL))));
|
||||
disconnect(gitreport->webView, SIGNAL(loadFinished(bool)), gitreport, SLOT(gitreportLoaded(bool)));
|
||||
disconnect(gitreport->webView, SIGNAL(loadFinished(bool)), gitreport, SLOT(gitreportFinished(bool)));
|
||||
connect(gitreport->webView, SIGNAL(loadFinished(bool)), gitreport, SLOT(gitreportLoaded(bool)));
|
||||
}
|
||||
#endif /* ENABLE_GITREPORT */
|
||||
#ifdef OWN_GITHUB_TOKEN
|
||||
else if (number == 2) {
|
||||
ui->widget_auth->setHidden(true);
|
||||
ui->widget_title->setHidden(false);
|
||||
ui->textEdit->setHidden(false);
|
||||
}
|
||||
#endif /* OWN_GITHUB_TOKEN */
|
||||
}
|
140
sources/reportabug/src/reportabug.h
Normal file
140
sources/reportabug/src/reportabug.h
Normal file
@ -0,0 +1,140 @@
|
||||
/***************************************************************************
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
/**
|
||||
* @file reportabug.h
|
||||
* Source code of reportabug
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright LGPLv3
|
||||
* @bug https://github.com/arcan1s/reportabug/issues
|
||||
*/
|
||||
|
||||
#ifndef REPORTABUG_H
|
||||
#define REPORTABUG_H
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QLocale>
|
||||
#include <QMainWindow>
|
||||
|
||||
|
||||
class GithubModule;
|
||||
class GitreportModule;
|
||||
|
||||
namespace Ui {
|
||||
class Reportabug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The Reportabug class is a main class of the application
|
||||
*/
|
||||
class Reportabug : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Reportabug class constructor
|
||||
* @param parent parent object
|
||||
* @param debugCmd show debug messages
|
||||
*/
|
||||
explicit Reportabug(QWidget *parent = 0,
|
||||
bool debugCmd = false);
|
||||
/**
|
||||
* @brief Reportabug class destructor
|
||||
*/
|
||||
~Reportabug();
|
||||
/**
|
||||
* @brief method which is used for update tabs from external classes
|
||||
*/
|
||||
void externalUpdateTab();
|
||||
/**
|
||||
* @brief method which sets captcha image
|
||||
* @param captcha captcha image
|
||||
*/
|
||||
void setCaptchaImage(QPixmap captcha);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief method which creates an issue
|
||||
*/
|
||||
void sendReport();
|
||||
/**
|
||||
* @brief method which updates text and shows window
|
||||
*/
|
||||
void showWindow();
|
||||
/**
|
||||
* @brief method which updates text
|
||||
* @param index the current combobox index
|
||||
*/
|
||||
void updateTabs(const int index);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief show debug messages
|
||||
*/
|
||||
bool debug;
|
||||
/**
|
||||
* @brief contains information about enabled modules
|
||||
*/
|
||||
bool modules[3];
|
||||
/**
|
||||
* @brief class user interface
|
||||
*/
|
||||
Ui::Reportabug *ui;
|
||||
// modules
|
||||
/**
|
||||
* @brief GitHub module
|
||||
*/
|
||||
GithubModule *github;
|
||||
/**
|
||||
* @brief GitReports module
|
||||
*/
|
||||
GitreportModule *gitreport;
|
||||
/**
|
||||
* @brief method which creates the window actions
|
||||
*/
|
||||
void createActions();
|
||||
/**
|
||||
* @brief method which adds a text into combobox
|
||||
*/
|
||||
void createComboBox();
|
||||
/**
|
||||
* @brief method which parses combobox content
|
||||
* @param index the current combobox index
|
||||
* @return -1 if there is no any selected modules
|
||||
* @return 0 if the GitHub module is selected
|
||||
* @return 1 if the GitReports module is selected
|
||||
*/
|
||||
int getNumberByIndex(const int index);
|
||||
/**
|
||||
* @brief method which initializates modules
|
||||
*/
|
||||
void initModules();
|
||||
/**
|
||||
* @brief method which monitors on pressed keys
|
||||
* @param pressedKey the current pressed key
|
||||
*/
|
||||
void keyPressEvent(QKeyEvent *pressedKey);
|
||||
/**
|
||||
* @brief method which parses string and replace known tags
|
||||
* @param line source line
|
||||
* @return replaced line
|
||||
*/
|
||||
QString parseString(QString line);
|
||||
};
|
||||
|
||||
|
||||
#endif /* REPORTABUG_H */
|
150
sources/reportabug/src/reportabug.ui
Normal file
150
sources/reportabug/src/reportabug.ui
Normal file
@ -0,0 +1,150 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Reportabug</class>
|
||||
<widget class="QMainWindow" name="Reportabug">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>541</width>
|
||||
<height>372</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Report a bug</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_auth" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_auth">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_username">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Username</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_username">
|
||||
<property name="toolTip">
|
||||
<string>Your GitHub account</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>username</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_password">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_password">
|
||||
<property name="toolTip">
|
||||
<string>GitHub account password</string>
|
||||
</property>
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_title" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_title">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_title">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_title">
|
||||
<property name="toolTip">
|
||||
<string>Title of the report</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="toolTip">
|
||||
<string>Text of the report</string>
|
||||
</property>
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_captcha" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_captcha">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_captcha">
|
||||
<property name="placeholderText">
|
||||
<string>captcha</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionClose">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
26
sources/reportabug/version.h.in
Normal file
26
sources/reportabug/version.h.in
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
|
||||
#define NAME "Report a Bug"
|
||||
#define VERSION "@SUBPROJECT_VERSION@"
|
||||
#define AUTHOR "@SUBPROJECT_AUTHOR@"
|
||||
#define EMAIL "@SUBPROJECT_CONTACT@"
|
||||
#define LICENSE "@SUBPROJECT_LICENSE@"
|
||||
|
||||
#define HOMEPAGE "https://github.com/arcan1s/reportabug"
|
||||
#define REPOSITORY "https://github.com/arcan1s/reportabug"
|
||||
#define BUGTRACKER "https://github.com/arcan1s/reportabug/issues"
|
||||
|
||||
#define BUILD_DATE "@CURRENT_DATE@"
|
||||
#define DATE "2014-@CURRENT_YEAR@"
|
||||
|
||||
#define CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@"
|
||||
#define CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
|
||||
#define SUBPROJECT_DOCS "@BUILD_DOCS@"
|
||||
#define SUBPROJECT_LIBRARY "@BUILD_AS_LIBRARY@"
|
||||
#define SUBPROJECT_GITHUB_MODULE "@ENABLE_GITHUB@"
|
||||
#define SUBPROJECT_GITREPORT_MODULE "@ENABLE_GITREPORT@"
|
||||
#define SUBPROJECT_OWN_GITHUB_TOKEN "@OWN_GITHUB_TOKEN@"
|
||||
#define SUBPROJECT_USE_QT5 "@USE_QT5@"
|
||||
|
||||
#endif /* VERSION_H */
|
Reference in New Issue
Block a user