diff --git a/CHANGELOG b/CHANGELOG index e38907f..432b69a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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: First release diff --git a/README.md b/README.md index 3ecb5b0..ccba9ea 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ Configuration Edit `src/config.h` header and set up needed variables. -Main configuration ------------------- +### Main configuration ### 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_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 @@ -39,8 +37,7 @@ Available variables: 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. @@ -63,14 +60,12 @@ Dependencies * 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-webkit (if Qt5 is used) or qtwebkit (if Qt4 is used) (*requires for GitReport module*) -Make dependencies ------------------ +### Make dependencies ### * automoc4 * cmake diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 79873e8..60b7fc6 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -25,6 +25,8 @@ message (STATUS "Build date: ${CURRENT_DATE}") # install options option (USE_QT5 "Use Qt5 instead of Qt4" 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 if (CMAKE_COMPILER_IS_GNUCXX) diff --git a/sources/src/CMakeLists.txt b/sources/src/CMakeLists.txt index 2d7d065..9b6c9d6 100644 --- a/sources/src/CMakeLists.txt +++ b/sources/src/CMakeLists.txt @@ -1,7 +1,9 @@ # set files -file (GLOB SOURCES *.cpp) -file (GLOB HEADERS *.h) -file (GLOB FORMS *.ui) +set (SOURCES main.cpp reportabug.cpp) +set (HEADERS reportabug.h) +set (FORMS reportabug.ui) + +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) # include_path include_directories (${CMAKE_CURRENT_BINARY_DIR}/../ @@ -10,15 +12,25 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}/../ if (USE_QT5) find_package (Qt5Core REQUIRED) - find_package (Qt5Network REQUIRED) - find_package (Qt5WebKit REQUIRED) - find_package (Qt5WebKitWidgets REQUIRED) find_package (Qt5Widgets REQUIRED) add_definitions (${Qt5Core_DEFINITIONS}) - add_definitions (${Qt5Network_DEFINITIONS}) - add_definitions (${Qt5WebKit_DEFINITIONS}) - add_definitions (${Qt5WebKitWidgets_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_ui (UI_HEADERS ${FORMS}) @@ -26,36 +38,37 @@ if (USE_QT5) source_group ("Source Files" FILES ${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 () - 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}) + 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_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() +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 if (BUILD_AS_LIBRARY) install (TARGETS ${SUBPROJECT} DESTINATION lib) diff --git a/sources/src/config.h b/sources/src/config.h.in similarity index 97% rename from sources/src/config.h rename to sources/src/config.h.in index 40fd9fe..142db44 100644 --- a/sources/src/config.h +++ b/sources/src/config.h.in @@ -40,7 +40,7 @@ * configuration of creating an issue using GitHub API */ // enable this function -#define ENABLE_GITHUB true +#cmakedefine ENABLE_GITHUB // 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 @@ -54,7 +54,7 @@ * and set up it for your repository */ // enable this function -#define ENABLE_GITREPORT true +#cmakedefine ENABLE_GITREPORT // 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 diff --git a/sources/src/githubmodule.cpp b/sources/src/githubmodule.cpp new file mode 100644 index 0000000..cb55c49 --- /dev/null +++ b/sources/src/githubmodule.cpp @@ -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 +#include +#include +#include +#include +#include +#include + +#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; iaddItem(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; + } +} diff --git a/sources/src/gitreportmodule.cpp b/sources/src/gitreportmodule.cpp new file mode 100644 index 0000000..55b8e86 --- /dev/null +++ b/sources/src/gitreportmodule.cpp @@ -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 +#include +#include +#include + +#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&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; + } +} diff --git a/sources/src/main.cpp b/sources/src/main.cpp index 4e2f3bb..7b76d99 100644 --- a/sources/src/main.cpp +++ b/sources/src/main.cpp @@ -27,6 +27,6 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); Reportabug w(0, true); - w.show(); + w.showWindow(); return a.exec(); } diff --git a/sources/src/reportabug.cpp b/sources/src/reportabug.cpp index e7e538b..70244b8 100644 --- a/sources/src/reportabug.cpp +++ b/sources/src/reportabug.cpp @@ -20,15 +20,16 @@ #include #include -#include -#include -#include #include -#include -#include -#include #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) @@ -37,9 +38,15 @@ Reportabug::Reportabug(QWidget *parent, bool debugCmd) ui(new Ui::Reportabug) { 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(); createActions(); - updateTabs(ui->comboBox->currentIndex()); } @@ -47,6 +54,9 @@ Reportabug::~Reportabug() { if (debug) qDebug() << "[Reportabug]" << "[~Reportabug]"; +#ifdef ENABLE_GITREPORT + delete webView; +#endif /* ENABLE_GITREPORT */ delete ui; } @@ -66,9 +76,9 @@ void Reportabug::createComboBox() if (debug) qDebug() << "[Reportabug]" << "[createComboBox]"; ui->comboBox->clear(); - if (ENABLE_GITHUB) + if (modules[0]) ui->comboBox->addItem(QString(GITHUB_COMBOBOX)); - if (ENABLE_GITREPORT) + if (modules[1]) ui->comboBox->addItem(QString(GITREPORT_COMBOBOX)); } @@ -81,13 +91,13 @@ int Reportabug::getNumberByIndex(const int index) if (index == -1) // nothing to do return -1; - else if ((ENABLE_GITHUB) && (ENABLE_GITREPORT)) + else if ((modules[0]) && (modules[1])) // both are enabled return index; - else if (ENABLE_GITHUB) + else if (modules[0]) // only github is enabled return 0; - else if (ENABLE_GITREPORT) + else if (modules[1]) // only gitreport is enabled return 1; 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) { if (debug) qDebug() << "[Reportabug]" << "[keyPressEvent]"; @@ -163,10 +188,21 @@ void Reportabug::sendReport() if (number == -1) return; +#ifdef ENABLE_GITHUB else if (number == 0) sendReportUsingGithub(); +#endif /* ENABLE_GITHUB */ +#ifdef ENABLE_GITREPORT else if (number == 1) 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); + // 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) { ui->widget_auth->setHidden(true); ui->widget_title->setHidden(true); ui->textEdit->setHidden(true); - ui->webView->setHidden(true); } +#ifdef ENABLE_GITHUB else if (number == 0) { ui->widget_auth->setHidden(false); ui->widget_title->setHidden(false); ui->textEdit->setHidden(false); - ui->webView->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")); @@ -198,212 +237,20 @@ void Reportabug::updateTabs(const int index) ui->lineEdit_title->setText(QString(TAG_TITLE)); ui->textEdit->setPlainText(QString(TAG_BODY)); } +#endif /* ENABLE_GITHUB */ +#ifdef ENABLE_GITREPORT else if (number == 1) { ui->widget_auth->setHidden(true); ui->widget_title->setHidden(true); ui->textEdit->setHidden(true); - ui->webView->setHidden(true); ui->lineEdit_username->clear(); ui->lineEdit_password->clear(); ui->textEdit->setPlainText(QString(TAG_BODY)); - ui->webView->load(QUrl(parseString(QString(PUBLIC_URL)))); - 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(gitreportLoaded(bool))); + webView->load(QUrl(parseString(QString(PUBLIC_URL)))); + disconnect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool))); + disconnect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool))); + connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool))); } -} - - -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; iaddItem(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&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))); +#endif /* ENABLE_GITREPORT */ } diff --git a/sources/src/reportabug.h b/sources/src/reportabug.h index 4dd224f..b8727be 100644 --- a/sources/src/reportabug.h +++ b/sources/src/reportabug.h @@ -21,9 +21,14 @@ #include #include +#include "config.h" +#ifdef ENABLE_GITHUB class QNetworkReply; - +#endif /* ENABLE_GITHUB */ +#ifdef ENABLE_GITREPORT +class QWebView; +#endif /* ENABLE_GITREPORT */ namespace Ui { class Reportabug; } @@ -39,22 +44,32 @@ public: public slots: void sendReport(); - void sendReportUsingGithub(); - void sendReportUsingGitreport(); + void showWindow(); void updateTabs(const int index); private slots: +#ifdef ENABLE_GITHUB + void sendReportUsingGithub(); void githubFinished(QNetworkReply *reply); +#endif /* ENABLE_GITHUB */ +#ifdef ENABLE_GITREPORT + void sendReportUsingGitreport(); void gitreportFinished(const bool state); void gitreportLoaded(const bool state); +#endif /* ENABLE_GITREPORT */ private: bool debug; + bool modules[2]; +#ifdef ENABLE_GITREPORT + // add webview which is required by gitreport module + QWebView *webView; +#endif /* ENABLE_GITREPORT */ Ui::Reportabug *ui; void createActions(); void createComboBox(); int getNumberByIndex(const int index); - // ESC pressed event + void initModules(); void keyPressEvent(QKeyEvent *pressedKey); QString parseString(QString line); QByteArray prepareRequest(const QString title, const QString body); diff --git a/sources/src/reportabug.ui b/sources/src/reportabug.ui index 9176d96..eb8e9c0 100644 --- a/sources/src/reportabug.ui +++ b/sources/src/reportabug.ui @@ -109,15 +109,6 @@ - - - - - about:blank - - - - @@ -147,13 +138,6 @@ - - - QWebView - QWidget -
QtWebKitWidgets/QWebView
-
-
diff --git a/sources/version.h.in b/sources/version.h.in index 60b2a3c..024eb9d 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -18,5 +18,7 @@ #define CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" #define SUBPROJECT_USE_QT5 "@USE_QT5@" #define SUBPROJECT_LIBRARY "@BUILD_AS_LIBRARY@" +#define SUBPROJECT_GITHUB_MODULE "@ENABLE_GITHUB@" +#define SUBPROJECT_GITREPORT_MODULE "@ENABLE_GITREPORT@" #endif /* VERSION_H */