commit before tests

This commit is contained in:
arcan1s 2014-07-28 20:51:10 +04:00
parent cdc33f57eb
commit f20a7ecc1c
12 changed files with 387 additions and 342 deletions

View File

@ -1,64 +1,2 @@
Ver.1.2.0:
+ [all] added icons
+ [all] added support of netctl-auto
+ [dataengine] added debug information (NETCTLGUI_DEBUG=yes)
+ [gui] added support of macvlan
+ [gui] added ability to remove profile
+ [gui] added support of hidden wifi network
+ [gui] added contextual menu to tables
+ [gui] added actions menu
+ [gui] added clear() function to profileTab
+ [gui] added about window
+ [gui] more command line options
+ [gui] added workaround for wireless-wep example
+ [gui] added shell completions
+ [lib] detached backend from frontend
+ [lib] added error checking
+ [lib] added doxygen documentation
+ [plasmoid] added dataengine configuration
+ [plasmoid] added about window
+ [plasmoid] added debug information (NETCTLGUI_DEBUG=yes)
- [gui] fix possible segfaults with null arrays (#5)
* [all] changes in the project architecture
* [all] refactoring
* [gui] more debug information
* [gui] changed lineEdit_profile to comboBox
* [gui] refactoring of configuration interface
* [gui] changed setting of the interface to profile tab
* [gui] rewrited ErrorWindow class
* [lib] more debug information
* [lib] rewrited getSettingsFromProfile() function
* [plasmoid] edited configuration interface
* [plasmoid] changed double click event to click event
Ver.1.1.0 (netctl-1.7 update):
+ [gui] added frequency
+ [plasmoid] added menu title
* [dataengine] changed definition if profile is enabled
* [gui] changed definition if profile is enabled
Ver.1.0.6:
* [gui] fix error checking
Ver.1.0.5:
+ [plasmoid] added "Start WiFi menu" function
* [plasmoid] refactoring
* [plasmoid] edited icon
Ver.1.0.4:
+ [gui] added Qt5 gui (by default)
+ [plasmoid] added notifications
* [plasmoid] fix run command with sudo from plasmoid
Ver.1.0.3:
+ [plasmoid] edited russian translation
* [all] refactoring
Ver.1.0.2:
* [plasmoid] fix layout margins
Ver.1.0.1:
- [all] removed scripts
Ver.1.0: Ver.1.0:
First release First release

View File

@ -11,8 +11,7 @@ Configuration
Edit `src/config.h` header and set up needed variables. Edit `src/config.h` header and set up needed variables.
Main configuration ### Main configuration ###
------------------
Available variables: Available variables:
@ -24,8 +23,7 @@ Available variables:
* `TAG_LABELS` - set this labels to an issue. Labels should be comma separated. It may be used only for GitHub module. This tag will work only if user has push access. If it will be empty, it will be ignored. * `TAG_LABELS` - set this labels to an issue. Labels should be comma separated. It may be used only for GitHub module. This tag will work only if user has push access. If it will be empty, it will be ignored.
* `TAG_MILESTONE` - set this milestone to an issue. It may be used only for GitHub module. This tag will work only if user has push access. If it will be empty, it will be ignored. * `TAG_MILESTONE` - set this milestone to an issue. It may be used only for GitHub module. This tag will work only if user has push access. If it will be empty, it will be ignored.
Send issue over GitHub ### Send issue over GitHub ###
----------------------
User should type own username and password. [GitHub API](https://developer.github.com/v3/issues/) is used for creating issue. The typical POST request is User should type own username and password. [GitHub API](https://developer.github.com/v3/issues/) is used for creating issue. The typical POST request is
@ -39,8 +37,7 @@ Available variables:
This module requires `QtNetwork` module. To enable this module set variable `ENABLE_GITHUB` to `true`. This module requires `QtNetwork` module. To enable this module set variable `ENABLE_GITHUB` to `true`.
Send issue over GitReport ### Send issue over GitReport ###
-------------------------
[GitReport](https://gitreports.com/about) is used for creating issue. Please visit [this page](https://gitreports.com/) and set up it for your repository. [GitReport](https://gitreports.com/about) is used for creating issue. Please visit [this page](https://gitreports.com/) and set up it for your repository.
@ -63,14 +60,12 @@ Dependencies
* qt5-base (if Qt5 is used) or qt4 (if Qt4 is used) * qt5-base (if Qt5 is used) or qt4 (if Qt4 is used)
Optional dependencies ### Optional dependencies ###
---------------------
* qt5-network (if Qt5 is used) (*requires for GitHub module*) * qt5-network (if Qt5 is used) (*requires for GitHub module*)
* qt5-webkit (if Qt5 is used) or qtwebkit (if Qt4 is used) (*requires for GitReport module*) * qt5-webkit (if Qt5 is used) or qtwebkit (if Qt4 is used) (*requires for GitReport module*)
Make dependencies ### Make dependencies ###
-----------------
* automoc4 * automoc4
* cmake * cmake

View File

@ -25,6 +25,8 @@ message (STATUS "Build date: ${CURRENT_DATE}")
# install options # install options
option (USE_QT5 "Use Qt5 instead of Qt4" ON) option (USE_QT5 "Use Qt5 instead of Qt4" ON)
option (BUILD_AS_LIBRARY "Build the application as a shared library" ON) option (BUILD_AS_LIBRARY "Build the application as a shared library" ON)
option (ENABLE_GITHUB "Enable GitHub module" ON)
option (ENABLE_GITREPORT "Enable GitReport module" ON)
# flags # flags
if (CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_COMPILER_IS_GNUCXX)

View File

@ -1,7 +1,9 @@
# set files # set files
file (GLOB SOURCES *.cpp) set (SOURCES main.cpp reportabug.cpp)
file (GLOB HEADERS *.h) set (HEADERS reportabug.h)
file (GLOB FORMS *.ui) set (FORMS reportabug.ui)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
# include_path # include_path
include_directories (${CMAKE_CURRENT_BINARY_DIR}/../ include_directories (${CMAKE_CURRENT_BINARY_DIR}/../
@ -10,15 +12,25 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}/../
if (USE_QT5) if (USE_QT5)
find_package (Qt5Core REQUIRED) find_package (Qt5Core REQUIRED)
find_package (Qt5Network REQUIRED)
find_package (Qt5WebKit REQUIRED)
find_package (Qt5WebKitWidgets REQUIRED)
find_package (Qt5Widgets REQUIRED) find_package (Qt5Widgets REQUIRED)
add_definitions (${Qt5Core_DEFINITIONS}) add_definitions (${Qt5Core_DEFINITIONS})
add_definitions (${Qt5Network_DEFINITIONS})
add_definitions (${Qt5WebKit_DEFINITIONS})
add_definitions (${Qt5WebKitWidgets_DEFINITIONS})
add_definitions (${Qt5Widgets_DEFINITIONS}) add_definitions (${Qt5Widgets_DEFINITIONS})
include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
set (QT_USED_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Widgets_LIBRARIES})
if (ENABLE_GITHUB)
find_package (Qt5Network REQUIRED)
add_definitions (${Qt5Network_DEFINITIONS})
include_directories (${Qt5Network_INCLUDE_DIRS})
set (QT_USED_LIBRARIES ${QT_USED_LIBRARIES} ${Qt5Network_LIBRARIES})
endif ()
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_cpp (MOC_SOURCES ${HEADERS})
qt5_wrap_ui (UI_HEADERS ${FORMS}) qt5_wrap_ui (UI_HEADERS ${FORMS})
@ -26,36 +38,37 @@ if (USE_QT5)
source_group ("Source Files" FILES ${SOURCES}) source_group ("Source Files" FILES ${SOURCES})
source_group ("Generated Files" FILES ${MOC_SOURCES}) source_group ("Generated Files" FILES ${MOC_SOURCES})
include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}
${Qt5WebKit_INCLUDE_DIRS} ${Qt5WebKitWidgets_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS})
if (BUILD_AS_LIBRARY)
add_library (${SUBPROJECT} SHARED ${SOURCES} ${HEADERS} ${MOC_SOURCES})
else ()
add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES})
endif ()
target_link_libraries (${SUBPROJECT} ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES}
${Qt5WebKit_LIBRARIES} ${Qt5WebKitWidgets_LIBRARIES}
${Qt5Widgets_LIBRARIES})
else () else ()
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork QtWebKit REQUIRED) set (QT_USED_COMPONENTS QtCore QtGui)
if (ENABLE_GITHUB)
set (QT_USED_COMPONENTS ${QT_USED_COMPONENTS} QtNetwork)
endif ()
if (ENABLE_GITREPORT)
set (QT_USED_COMPONENTS ${QT_USED_COMPONENTS} QtWebKit)
endif ()
find_package(Qt4 COMPONENTS ${QT_USED_COMPONENTS} REQUIRED)
include (${QT_USE_FILE}) include (${QT_USE_FILE})
set (QT_USED_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
if (ENABLE_GITHUB)
set (QT_USED_LIBRARIES ${QT_USED_LIBRARIES} ${QT_QTNETWORK_LIBRARY})
endif ()
if (ENABLE_GITREPORT)
set (QT_USED_LIBRARIES ${QT_USED_LIBRARIES} ${QT_QTWEBKIT_LIBRARY})
endif ()
qt4_wrap_cpp (MOC_SOURCES ${HEADERS}) qt4_wrap_cpp (MOC_SOURCES ${HEADERS})
qt4_wrap_ui (UI_HEADERS ${FORMS}) qt4_wrap_ui (UI_HEADERS ${FORMS})
source_group ("Header Files" FILES ${HEADERS})
source_group ("Source Files" FILES ${SOURCES})
source_group ("Generated Files" FILES ${MOC_SOURCES})
if (BUILD_AS_LIBRARY)
add_library (${SUBPROJECT} SHARED ${SOURCES} ${HEADERS} ${MOC_SOURCES})
else ()
add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES})
endif ()
target_link_libraries (${SUBPROJECT} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}
${QT_QTNETWORK_LIBRARY} ${QT_QTWEBKIT_LIBRARY})
endif() endif()
source_group ("Header Files" FILES ${HEADERS})
source_group ("Source Files" FILES ${SOURCES})
source_group ("Generated Files" FILES ${MOC_SOURCES})
if (BUILD_AS_LIBRARY)
add_library (${SUBPROJECT} SHARED ${SOURCES} ${HEADERS} ${MOC_SOURCES})
else ()
add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES})
endif ()
target_link_libraries (${SUBPROJECT} ${QT_USED_LIBRARIES})
# install properties # install properties
if (BUILD_AS_LIBRARY) if (BUILD_AS_LIBRARY)
install (TARGETS ${SUBPROJECT} DESTINATION lib) install (TARGETS ${SUBPROJECT} DESTINATION lib)

View File

@ -40,7 +40,7 @@
* configuration of creating an issue using GitHub API * configuration of creating an issue using GitHub API
*/ */
// enable this function // enable this function
#define ENABLE_GITHUB true #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
@ -54,7 +54,7 @@
* and set up it for your repository * and set up it for your repository
*/ */
// enable this function // enable this function
#define ENABLE_GITREPORT true #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

View File

@ -0,0 +1,120 @@
/***************************************************************************
* 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. *
***************************************************************************/
#include "reportabug.h"
#include "ui_reportabug.h"
#include <QDebug>
#include <QMessageBox>
#include <QPushButton>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
#include "config.h"
void Reportabug::sendReportUsingGithub()
{
if (debug) qDebug() << "[Reportabug]" << "[sendReportUsingGithub]";
// authentication
QString username = ui->lineEdit_username->text();
QString password = ui->lineEdit_password->text();
QString concatenated = username + QString(":") + password;
QByteArray userData = concatenated.toLocal8Bit().toBase64();
QString headerData = QString("Basic ") + userData;
// text
QString title = ui->lineEdit_title->text();
QString body = ui->textEdit->toPlainText();
QByteArray text = prepareRequest(title, 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 *)));
}
void Reportabug::githubFinished(QNetworkReply *reply)
{
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]";
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Error state" << reply->error();
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Reply size" << reply->readBufferSize();
int state = true;
QString answer = reply->readAll();
if (debug) qDebug() << "[Reportabug]" << "[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;
}
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) close();
break;
case QMessageBox::Retry:
if (state) updateTabs(ui->comboBox->currentIndex());
break;
default:
break;
}
}

View File

@ -0,0 +1,129 @@
/***************************************************************************
* 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. *
***************************************************************************/
#include "reportabug.h"
#include "ui_reportabug.h"
#include <QUrl>
#include <QWebElement>
#include <QWebFrame>
#include <QWebView>
#include "config.h"
void Reportabug::sendReportUsingGitreport()
{
if (debug) qDebug() << "[Reportabug]" << "[sendReportUsingGitreport]";
QWebElement document = webView->page()->mainFrame()->documentElement();
QWebElement captcha = document.findFirst(QString("input#captcha"));
QWebElement captchaImg = document.findFirst(QString("img#[alt=captcha]"));
QWebElement captchaKey = document.findFirst(QString("input#captcha_key"));
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"), ui->lineEdit_username->text());
emailInput.setAttribute(QString("value"), ui->lineEdit_password->text());
textArea.setPlainText(ui->textEdit->toPlainText());
// captcha
captchaImg.setAttribute(QString("src"), QString("/simple_captcha?code=%1&amp;time=%2")
.arg(QString(CAPTCHA_KEY))
.arg(QString(CAPTCHA_TIME)));
captchaKey.setAttribute(QString("value"), QString(CAPTCHA_KEY));
captcha.setAttribute(QString("value"), QString(CAPTCHA_TEXT));
// 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)));
}
void Reportabug::gitreportLoaded(const bool state)
{
if (debug) qDebug() << "[Reportabug]" << "[gitreportLoaded]";
if (debug) qDebug() << "[Reportabug]" << "[gitreportLoaded]" << ":" << "State" << state;
if (state) {
ui->widget_auth->setHidden(false);
ui->widget_title->setHidden(true);
ui->textEdit->setHidden(false);
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 {
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();
}
}
void Reportabug::gitreportFinished(const bool state)
{
if (debug) qDebug() << "[Reportabug]" << "[gitreportFinished]";
if (debug) qDebug() << "[Reportabug]" << "[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) close();
break;
case QMessageBox::Retry:
if (state) updateTabs(ui->comboBox->currentIndex());
break;
default:
break;
}
}

View File

@ -27,6 +27,6 @@ int main(int argc, char *argv[])
QApplication a(argc, argv); QApplication a(argc, argv);
Reportabug w(0, true); Reportabug w(0, true);
w.show(); w.showWindow();
return a.exec(); return a.exec();
} }

View File

@ -20,15 +20,16 @@
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QPushButton> #include <QPushButton>
#include <QUrl>
#include <QWebElement>
#include <QWebFrame>
#include "config.h" #include "config.h"
#include "version.h"
#ifdef ENABLE_GITHUB
#include "githubmodule.cpp"
#endif /* ENABLE_GITHUB */
#ifdef ENABLE_GITREPORT
#include "gitreportmodule.cpp"
#endif /* ENABLE_GITREPORT */
Reportabug::Reportabug(QWidget *parent, bool debugCmd) Reportabug::Reportabug(QWidget *parent, bool debugCmd)
@ -37,9 +38,15 @@ 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();
createComboBox(); createComboBox();
createActions(); createActions();
updateTabs(ui->comboBox->currentIndex());
} }
@ -47,6 +54,9 @@ Reportabug::~Reportabug()
{ {
if (debug) qDebug() << "[Reportabug]" << "[~Reportabug]"; if (debug) qDebug() << "[Reportabug]" << "[~Reportabug]";
#ifdef ENABLE_GITREPORT
delete webView;
#endif /* ENABLE_GITREPORT */
delete ui; delete ui;
} }
@ -66,9 +76,9 @@ void Reportabug::createComboBox()
if (debug) qDebug() << "[Reportabug]" << "[createComboBox]"; if (debug) qDebug() << "[Reportabug]" << "[createComboBox]";
ui->comboBox->clear(); ui->comboBox->clear();
if (ENABLE_GITHUB) if (modules[0])
ui->comboBox->addItem(QString(GITHUB_COMBOBOX)); ui->comboBox->addItem(QString(GITHUB_COMBOBOX));
if (ENABLE_GITREPORT) if (modules[1])
ui->comboBox->addItem(QString(GITREPORT_COMBOBOX)); ui->comboBox->addItem(QString(GITREPORT_COMBOBOX));
} }
@ -81,13 +91,13 @@ int Reportabug::getNumberByIndex(const int index)
if (index == -1) if (index == -1)
// nothing to do // nothing to do
return -1; return -1;
else if ((ENABLE_GITHUB) && (ENABLE_GITREPORT)) else if ((modules[0]) && (modules[1]))
// both are enabled // both are enabled
return index; return index;
else if (ENABLE_GITHUB) else if (modules[0])
// only github is enabled // only github is enabled
return 0; return 0;
else if (ENABLE_GITREPORT) else if (modules[1])
// only gitreport is enabled // only gitreport is enabled
return 1; return 1;
else else
@ -96,7 +106,22 @@ int Reportabug::getNumberByIndex(const int index)
} }
// ESC press event void Reportabug::initModules()
{
if (debug) qDebug() << "[Reportabug]" << "[initModules]";
modules[0] = false;
modules[1] = false;
#ifdef ENABLE_GITHUB
modules[0] = true;
#endif /* ENABLE_GITHUB */
#ifdef ENABLE_GITREPORT
modules[1] = true;
#endif /* ENABLE_GITREPORT */
}
void Reportabug::keyPressEvent(QKeyEvent *pressedKey) void Reportabug::keyPressEvent(QKeyEvent *pressedKey)
{ {
if (debug) qDebug() << "[Reportabug]" << "[keyPressEvent]"; if (debug) qDebug() << "[Reportabug]" << "[keyPressEvent]";
@ -163,10 +188,21 @@ void Reportabug::sendReport()
if (number == -1) if (number == -1)
return; return;
#ifdef ENABLE_GITHUB
else if (number == 0) else if (number == 0)
sendReportUsingGithub(); sendReportUsingGithub();
#endif /* ENABLE_GITHUB */
#ifdef ENABLE_GITREPORT
else if (number == 1) else if (number == 1)
sendReportUsingGitreport(); sendReportUsingGitreport();
#endif /* ENABLE_GITREPORT */
}
void Reportabug::showWindow()
{
updateTabs(ui->comboBox->currentIndex());
show();
} }
@ -177,17 +213,20 @@ void Reportabug::updateTabs(const int index)
int number = getNumberByIndex(index); int number = getNumberByIndex(index);
// it is out of conditional because I don't want a lot of ifdef/endif
#ifdef ENABLE_GITREPORT
webView->setHidden(true);
#endif /* ENABLE_GITREPORT */
if (number == -1) { if (number == -1) {
ui->widget_auth->setHidden(true); ui->widget_auth->setHidden(true);
ui->widget_title->setHidden(true); ui->widget_title->setHidden(true);
ui->textEdit->setHidden(true); ui->textEdit->setHidden(true);
ui->webView->setHidden(true);
} }
#ifdef ENABLE_GITHUB
else if (number == 0) { else if (number == 0) {
ui->widget_auth->setHidden(false); ui->widget_auth->setHidden(false);
ui->widget_title->setHidden(false); ui->widget_title->setHidden(false);
ui->textEdit->setHidden(false); ui->textEdit->setHidden(false);
ui->webView->setHidden(true);
ui->label_password->setText(QApplication::translate("Reportabug", "Password")); ui->label_password->setText(QApplication::translate("Reportabug", "Password"));
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"));
@ -198,212 +237,20 @@ void Reportabug::updateTabs(const int index)
ui->lineEdit_title->setText(QString(TAG_TITLE)); ui->lineEdit_title->setText(QString(TAG_TITLE));
ui->textEdit->setPlainText(QString(TAG_BODY)); ui->textEdit->setPlainText(QString(TAG_BODY));
} }
#endif /* ENABLE_GITHUB */
#ifdef ENABLE_GITREPORT
else if (number == 1) { else if (number == 1) {
ui->widget_auth->setHidden(true); ui->widget_auth->setHidden(true);
ui->widget_title->setHidden(true); ui->widget_title->setHidden(true);
ui->textEdit->setHidden(true); ui->textEdit->setHidden(true);
ui->webView->setHidden(true);
ui->lineEdit_username->clear(); ui->lineEdit_username->clear();
ui->lineEdit_password->clear(); ui->lineEdit_password->clear();
ui->textEdit->setPlainText(QString(TAG_BODY)); ui->textEdit->setPlainText(QString(TAG_BODY));
ui->webView->load(QUrl(parseString(QString(PUBLIC_URL)))); webView->load(QUrl(parseString(QString(PUBLIC_URL))));
disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool))); disconnect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool)));
disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool))); disconnect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool)));
connect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool))); connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool)));
} }
} #endif /* ENABLE_GITREPORT */
void Reportabug::githubFinished(QNetworkReply *reply)
{
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]";
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Error state" << reply->error();
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Reply size" << reply->readBufferSize();
int state = true;
QString answer = reply->readAll();
if (debug) qDebug() << "[Reportabug]" << "[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;
}
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) close();
break;
case QMessageBox::Retry:
if (state) updateTabs(ui->comboBox->currentIndex());
break;
default:
break;
}
}
void Reportabug::gitreportLoaded(const bool state)
{
if (debug) qDebug() << "[Reportabug]" << "[gitreportLoaded]";
if (debug) qDebug() << "[Reportabug]" << "[gitreportLoaded]" << ":" << "State" << state;
if (state) {
ui->widget_auth->setHidden(false);
ui->widget_title->setHidden(true);
ui->textEdit->setHidden(false);
ui->webView->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);
}
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();
}
}
void Reportabug::gitreportFinished(const bool state)
{
if (debug) qDebug() << "[Reportabug]" << "[gitreportFinished]";
if (debug) qDebug() << "[Reportabug]" << "[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) close();
break;
case QMessageBox::Retry:
if (state) updateTabs(ui->comboBox->currentIndex());
break;
default:
break;
}
}
void Reportabug::sendReportUsingGithub()
{
if (debug) qDebug() << "[Reportabug]" << "[sendReportUsingGithub]";
// authentication
QString username = ui->lineEdit_username->text();
QString password = ui->lineEdit_password->text();
QString concatenated = username + QString(":") + password;
QByteArray userData = concatenated.toLocal8Bit().toBase64();
QString headerData = QString("Basic ") + userData;
// text
QString title = ui->lineEdit_title->text();
QString body = ui->textEdit->toPlainText();
QByteArray text = prepareRequest(title, 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 *)));
}
void Reportabug::sendReportUsingGitreport()
{
if (debug) qDebug() << "[Reportabug]" << "[sendReportUsingGitreport]";
QWebElement document = ui->webView->page()->mainFrame()->documentElement();
QWebElement captcha = document.findFirst(QString("input#captcha"));
QWebElement captchaImg = document.findFirst(QString("img#[alt=captcha]"));
QWebElement captchaKey = document.findFirst(QString("input#captcha_key"));
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"), ui->lineEdit_username->text());
emailInput.setAttribute(QString("value"), ui->lineEdit_password->text());
textArea.setPlainText(ui->textEdit->toPlainText());
// captcha
captchaImg.setAttribute(QString("src"), QString("/simple_captcha?code=%1&amp;time=%2")
.arg(QString(CAPTCHA_KEY))
.arg(QString(CAPTCHA_TIME)));
captchaKey.setAttribute(QString("value"), QString(CAPTCHA_KEY));
captcha.setAttribute(QString("value"), QString(CAPTCHA_TEXT));
// send request
document.findFirst(QString("input[name=commit]")).evaluateJavaScript("this.click()");
disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool)));
disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool)));
connect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool)));
} }

View File

@ -21,9 +21,14 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QMainWindow> #include <QMainWindow>
#include "config.h"
#ifdef ENABLE_GITHUB
class QNetworkReply; class QNetworkReply;
#endif /* ENABLE_GITHUB */
#ifdef ENABLE_GITREPORT
class QWebView;
#endif /* ENABLE_GITREPORT */
namespace Ui { namespace Ui {
class Reportabug; class Reportabug;
} }
@ -39,22 +44,32 @@ public:
public slots: public slots:
void sendReport(); void sendReport();
void sendReportUsingGithub(); void showWindow();
void sendReportUsingGitreport();
void updateTabs(const int index); void updateTabs(const int index);
private slots: private slots:
#ifdef ENABLE_GITHUB
void sendReportUsingGithub();
void githubFinished(QNetworkReply *reply); void githubFinished(QNetworkReply *reply);
#endif /* ENABLE_GITHUB */
#ifdef ENABLE_GITREPORT
void sendReportUsingGitreport();
void gitreportFinished(const bool state); void gitreportFinished(const bool state);
void gitreportLoaded(const bool state); void gitreportLoaded(const bool state);
#endif /* ENABLE_GITREPORT */
private: private:
bool debug; bool debug;
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;
void createActions(); void createActions();
void createComboBox(); void createComboBox();
int getNumberByIndex(const int index); int getNumberByIndex(const int index);
// ESC pressed event 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); QByteArray prepareRequest(const QString title, const QString body);

View File

@ -109,15 +109,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
@ -147,13 +138,6 @@
</property> </property>
</action> </action>
</widget> </widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKitWidgets/QWebView</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -18,5 +18,7 @@
#define CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" #define CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
#define SUBPROJECT_USE_QT5 "@USE_QT5@" #define SUBPROJECT_USE_QT5 "@USE_QT5@"
#define SUBPROJECT_LIBRARY "@BUILD_AS_LIBRARY@" #define SUBPROJECT_LIBRARY "@BUILD_AS_LIBRARY@"
#define SUBPROJECT_GITHUB_MODULE "@ENABLE_GITHUB@"
#define SUBPROJECT_GITREPORT_MODULE "@ENABLE_GITREPORT@"
#endif /* VERSION_H */ #endif /* VERSION_H */