From 33fdd14e798a4a116ca1077b477f1587a891773e Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 31 Jul 2014 15:27:01 +0400 Subject: [PATCH] release 1.0.1 * fix captcha --- CHANGELOG | 3 +++ README.md | 8 +++---- sources/CMakeLists.txt | 2 +- sources/src/CMakeLists.txt | 22 +++++------------ sources/src/config.h.in | 6 ++--- sources/src/githubmodule.cpp | 3 ++- sources/src/gitreportmodule.cpp | 42 +++++++++++++++++++++++++-------- sources/src/gitreportmodule.h | 14 +++++++++-- sources/src/reportabug.cpp | 18 +++++++++++++- sources/src/reportabug.h | 5 ++++ sources/src/reportabug.ui | 20 ++++++++++++++-- 11 files changed, 101 insertions(+), 42 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 432b69a..bdc1839 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,5 @@ +Ver.1.0.1: +* fix captcha + Ver.1.0: First release diff --git a/README.md b/README.md index f8bfc58..2a89d09 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,11 @@ This module requires `QtNetwork` module. To enable this module set up your token Available variables: -* `CAPTCHA_KEY` - captcha key. It may be found in the source of the `PUBLIC_URL` page. Default is `7f6ef90bce7389088a52c5c9101aad206b21b56d`. -* `CAPTCHA_TEXT` - captcha text. It may be found in the source of the `PUBLIC_URL` page. Default is `QJNZXY`. -* `CAPTCHA_TIME` - captcha time. It may be found in the source of the `PUBLIC_URL` page. Default is `1406531273`. +* `CAPTCHA_URL` - captcha url, in the most cases do not touch it. Default is `https://gitreports.com/simple_captcha?code=`. * `GITREPORT_COMBOBOX` - text of this module into comboBox. * `PUBLIC_URL` - issues url, in the most cases do not touch it. Default is `https://gitreports.com/issue/$OWNER/$PROJECT`. Available tags here are `$PROJECT`, `$OWNER`. -This module requires `QtWebKit` module. To disable this module use `-DENABLE_GITREPORT=0` cmake flag. +This module requires `QtWebKit` and `QtNetwork` modules. To disable this module use `-DENABLE_GITREPORT=0` cmake flag. Instruction =========== @@ -65,10 +63,10 @@ Dependencies ------------ * qt5-base (if Qt5 is used) or qt4 (if Qt4 is used) +* qt5-network (if Qt5 is used) ### 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)* * doxygen *(developers documentation)* diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 2925c6f..f2bf809 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -13,7 +13,7 @@ set (SUBPROJECT_CONTACT "esalexeev@gmail.com") set (SUBPROJECT_LICENSE "LGPLv3") set (SUBPROJECT_VERSION_MAJOR 1) set (SUBPROJECT_VERSION_MINOR 0) -set (SUBPROJECT_VERSION_PATCH 0) +set (SUBPROJECT_VERSION_PATCH 1) 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") diff --git a/sources/src/CMakeLists.txt b/sources/src/CMakeLists.txt index 4a929f1..4fd3a0d 100644 --- a/sources/src/CMakeLists.txt +++ b/sources/src/CMakeLists.txt @@ -22,16 +22,12 @@ include_directories (${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}) - include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) - set (QT_USED_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Widgets_LIBRARIES}) - if (ENABLE_GITHUB OR USE_OWN_TOKEN) - find_package (Qt5Network REQUIRED) - add_definitions (${Qt5Network_DEFINITIONS}) - include_directories (${Qt5Network_INCLUDE_DIRS}) - set (QT_USED_LIBRARIES ${QT_USED_LIBRARIES} ${Qt5Network_LIBRARIES}) - endif () + 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) @@ -48,19 +44,13 @@ if (USE_QT5) source_group ("Generated Files" FILES ${MOC_SOURCES}) else () - set (QT_USED_COMPONENTS QtCore QtGui) - if (ENABLE_GITHUB OR USE_OWN_TOKEN) - set (QT_USED_COMPONENTS ${QT_USED_COMPONENTS} QtNetwork) - endif () + 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}) - if (ENABLE_GITHUB OR USE_OWN_TOKEN) - set (QT_USED_LIBRARIES ${QT_USED_LIBRARIES} ${QT_QTNETWORK_LIBRARY}) - endif () + 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 () diff --git a/sources/src/config.h.in b/sources/src/config.h.in index 2d6e7f3..53a6e7c 100644 --- a/sources/src/config.h.in +++ b/sources/src/config.h.in @@ -69,10 +69,8 @@ // 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 -#define CAPTCHA_KEY "7f6ef90bce7389088a52c5c9101aad206b21b56d" -#define CAPTCHA_TEXT "QJNZXY" -#define CAPTCHA_TIME "1406531273" +// captcha url; in the most cases do not touch it +#define CAPTCHA_URL "https://gitreports.com/simple_captcha?code=" #endif /* CONFIG_H */ diff --git a/sources/src/githubmodule.cpp b/sources/src/githubmodule.cpp index 3ea7f5a..e71e6c5 100644 --- a/sources/src/githubmodule.cpp +++ b/sources/src/githubmodule.cpp @@ -159,7 +159,7 @@ void GithubModule::githubFinished(QNetworkReply *reply) if (debug) qDebug() << "[GithubModule]" << "[githubFinished]" << ":" << "Error state" << reply->error(); if (debug) qDebug() << "[GithubModule]" << "[githubFinished]" << ":" << "Reply size" << reply->readBufferSize(); - int state = true; + bool state = true; QString answer = reply->readAll(); if (debug) qDebug() << "[GithubModule]" << "[replyFinished]" << ":" << answer; QString messageBody, messageTitle; @@ -189,6 +189,7 @@ void GithubModule::githubFinished(QNetworkReply *reply) icon = QMessageBox::Critical; state = false; } + reply->deleteLater(); QMessageBox messageBox; messageBox.setText(messageTitle); diff --git a/sources/src/gitreportmodule.cpp b/sources/src/gitreportmodule.cpp index 8ee3f51..d8690c2 100644 --- a/sources/src/gitreportmodule.cpp +++ b/sources/src/gitreportmodule.cpp @@ -29,6 +29,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -71,9 +74,7 @@ void GitreportModule::sendReportUsingGitreport(const QMap info if (debug) qDebug() << "[GitreportModule]" << "[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 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")); @@ -82,12 +83,7 @@ void GitreportModule::sendReportUsingGitreport(const QMap info usernameInput.setAttribute(QString("value"), info[QString("username")]); emailInput.setAttribute(QString("value"), info[QString("password")]); textArea.setPlainText(info[QString("body")]); - // 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)); + captchaKey.setAttribute(QString("value"), info[QString("captcha")]); // send request document.findFirst(QString("input[name=commit]")).evaluateJavaScript("this.click()"); @@ -105,8 +101,17 @@ void GitreportModule::gitreportLoaded(const bool state) if (debug) qDebug() << "[GitreportModule]" << "[gitreportLoaded]"; if (debug) qDebug() << "[GitreportModule]" << "[gitreportLoaded]" << ":" << "State" << state; - if (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!")); @@ -165,3 +170,20 @@ void GitreportModule::gitreportFinished(const bool state) 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(); +} diff --git a/sources/src/gitreportmodule.h b/sources/src/gitreportmodule.h index 021b921..aa55013 100644 --- a/sources/src/gitreportmodule.h +++ b/sources/src/gitreportmodule.h @@ -29,6 +29,7 @@ #include #include +class QNetworkAccessManager; class Reportabug; /** @@ -37,7 +38,7 @@ class Reportabug; * creating an issue. Please visit [this page](https://gitreports.com/) * and set up it for your repository. * - * This module depends on QtWebKit module. + * This module depends on QtWebKit and QtNetwork modules. */ class GitreportModule : public QObject { @@ -81,6 +82,11 @@ private slots: * @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: /** @@ -90,7 +96,11 @@ private: /** * @brief Reportabug class */ - Reportabug *mainWindow;; + Reportabug *mainWindow; + /** + * @brief manager for getting captcha + */ + QNetworkAccessManager manager; }; diff --git a/sources/src/reportabug.cpp b/sources/src/reportabug.cpp index 38b9db6..5c43483 100644 --- a/sources/src/reportabug.cpp +++ b/sources/src/reportabug.cpp @@ -84,6 +84,17 @@ void Reportabug::externalUpdateTab() } +/** + * @fn setCaptchaImage + */ +void Reportabug::setCaptchaImage(QPixmap captcha) +{ + if (debug) qDebug() << "[Reportabug]" << "[setCaptchaImage]"; + + ui->label_captcha->setPixmap(captcha); +} + + /** * @fn createActions */ @@ -167,7 +178,7 @@ void Reportabug::initModules() modules[1] = true; gitreport = new GitreportModule(this, debug); // 4 is a magic number. Seriously - ui->verticalLayout->insertWidget(4, gitreport->webView); + ui->verticalLayout->insertWidget(5, gitreport->webView); #endif /* ENABLE_GITREPORT */ #ifdef OWN_GITHUB_TOKEN modules[2] = true; @@ -218,6 +229,7 @@ void Reportabug::sendReport() int number = getNumberByIndex(ui->comboBox->currentIndex()); QMap 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(); @@ -264,6 +276,7 @@ void Reportabug::updateTabs(const int index) 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 @@ -273,12 +286,14 @@ void Reportabug::updateTabs(const int index) 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")); @@ -290,6 +305,7 @@ void Reportabug::updateTabs(const int index) 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")); diff --git a/sources/src/reportabug.h b/sources/src/reportabug.h index 855ae20..28acd39 100644 --- a/sources/src/reportabug.h +++ b/sources/src/reportabug.h @@ -59,6 +59,11 @@ public: * @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: /** diff --git a/sources/src/reportabug.ui b/sources/src/reportabug.ui index aac9412..13846ff 100644 --- a/sources/src/reportabug.ui +++ b/sources/src/reportabug.ui @@ -6,8 +6,8 @@ 0 0 - 543 - 374 + 541 + 372 @@ -109,6 +109,22 @@ + + + + + + + + + + + + + + + +