restructure, change onDataDecode signal and succesfully parsing http request
This commit is contained in:
parent
f507ec8d67
commit
2b2127e3b5
|
@ -41,7 +41,13 @@ void AdjustPictureDialog::accept() {
|
|||
infoDialog.setWindowTitle(tr("No QR code"));
|
||||
infoDialog.exec();
|
||||
} else {
|
||||
emit decodedData(result);
|
||||
std::map<std::string, std::string> paramsMap;
|
||||
std::vector<std::string> dataSplit = split(result, "&");
|
||||
for (std::string &pair : dataSplit) {
|
||||
std::vector<std::string> values = split(pair, "=");
|
||||
paramsMap.insert(std::pair<std::string, std::string>(values[0], values[1]));
|
||||
}
|
||||
emit decodedData(paramsMap);
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
void computeContrastLookupTable();
|
||||
std::vector<unsigned short> contrastLUT[100];
|
||||
signals:
|
||||
void decodedData(std::string data);
|
||||
void decodedData(std::map<std::string, std::string> data);
|
||||
|
||||
private slots:
|
||||
|
||||
|
|
50
ofdscene.cpp
50
ofdscene.cpp
|
@ -13,6 +13,8 @@
|
|||
|
||||
#include <exceptions/ofdrequestexception.h>
|
||||
|
||||
#include <bits/basic_string.h>
|
||||
|
||||
OFDScene::OFDScene(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::OFDScene) {
|
||||
|
@ -46,8 +48,20 @@ void OFDScene::startHttpServer() {
|
|||
|
||||
httplib::Server svr;
|
||||
|
||||
svr.Get("/", [&](const httplib::Request &, httplib::Response &res){
|
||||
res.set_redirect("http://"+ localIp +":"+ std::to_string(port) +"/", 301);
|
||||
svr.Get("/", [&](const httplib::Request &req, httplib::Response &res){
|
||||
if (req.params.size() < 6) {
|
||||
res.set_redirect("binaryeye://scan/?ret=http://"+ localIp +":"+ std::to_string(port) +"/", 301);
|
||||
std::cerr << "Too few params: " << req.params.size() << std::endl;
|
||||
return;
|
||||
}
|
||||
std::map<std::string, std::string> paramsMap;
|
||||
for (auto ¶m : req.params) {
|
||||
paramsMap.insert(std::pair<std::string, std::string>(param.first, param.second));
|
||||
}
|
||||
|
||||
emit onDataDecode(paramsMap);
|
||||
|
||||
res.set_redirect("binaryeye://scan/?ret=http://"+ localIp +":"+ std::to_string(port) +"/", 301);
|
||||
});
|
||||
|
||||
number_of_retries ++;
|
||||
|
@ -79,22 +93,26 @@ void OFDScene::on_choose_image_button_clicked() {
|
|||
dialog.exec();
|
||||
}
|
||||
|
||||
void OFDScene::onDataDecode(std::string data) {
|
||||
std::vector<std::string> dataSplit = split(data, "&");
|
||||
void OFDScene::onDataDecode(std::map<std::string, std::string> data) {
|
||||
// std::vector<std::string> dataSplit = split(data, "&");
|
||||
|
||||
ui->fn_line_edit->setText(QString::fromStdString(split(dataSplit[2], "=")[1]));
|
||||
ui->fd_line_edit->setText(QString::fromStdString(split(dataSplit[3], "=")[1]));
|
||||
ui->fi_line_edit->setText(QString::fromStdString(split(dataSplit[4], "=")[1]));
|
||||
|
||||
QString extractedDateTime = QString::fromStdString(split(dataSplit[0], "=")[1]);
|
||||
ui->fn_line_edit->setText(QString::fromStdString(data["fn"]));
|
||||
ui->fd_line_edit->setText(QString::fromStdString(data["i"]));
|
||||
ui->fi_line_edit->setText(QString::fromStdString(data["fp"]));
|
||||
|
||||
QString extractedDateTime = QString::fromStdString(data["t"]);
|
||||
//TODO: some QRs contain datetime in format yyyyMMddThhmmss. Perhaps there is more different formats, should write function to detect them.
|
||||
QDateTime datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmm");
|
||||
if (datetime == QDateTime::fromString(extractedDateTime, "20000101T1200")) {
|
||||
datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmmss");
|
||||
}
|
||||
ui->purchase_datetime_edit->setDateTime(datetime);
|
||||
|
||||
int type = std::stoi(split(dataSplit[5], "=")[1]);
|
||||
int type = std::stoi(data["n"]);
|
||||
ui->operation_type_combo_box->setCurrentIndex(type - 1);
|
||||
|
||||
std::string total = split(dataSplit[1], "=")[1];
|
||||
std::string total = data["s"];
|
||||
|
||||
ui->total_spin_box->setValue(std::stod(total));
|
||||
}
|
||||
|
@ -158,7 +176,6 @@ void OFDScene::on_parse_button_clicked() {
|
|||
OutputDialog d = OutputDialog(this, check);
|
||||
d.exec();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,12 +184,11 @@ void OFDScene::on_binary_eye_button_clicked() {
|
|||
}
|
||||
|
||||
void OFDScene::notifyHttpServerFailure() {
|
||||
QMessageBox *infoDialog = new QMessageBox();
|
||||
infoDialog->setText(tr("Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn't lucky, please, contact the developer."));
|
||||
infoDialog->setIcon(QMessageBox::Warning);
|
||||
infoDialog->setWindowTitle(tr("Could not start http server."));
|
||||
infoDialog->exec();
|
||||
delete infoDialog;
|
||||
QMessageBox infoDialog = QMessageBox();
|
||||
infoDialog.setText(tr("Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn't lucky, please, contact the developer."));
|
||||
infoDialog.setIcon(QMessageBox::Warning);
|
||||
infoDialog.setWindowTitle(tr("Could not start http server."));
|
||||
infoDialog.exec();
|
||||
}
|
||||
|
||||
unsigned int OFDScene::getPort() {
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
unsigned int getPort();
|
||||
private slots:
|
||||
void on_choose_image_button_clicked();
|
||||
void onDataDecode(std::string data);
|
||||
void onDataDecode(std::map<std::string, std::string>);
|
||||
|
||||
void on_parse_button_clicked();
|
||||
|
||||
|
@ -28,6 +28,7 @@ private slots:
|
|||
void notifyHttpServerFailure();
|
||||
|
||||
signals:
|
||||
|
||||
void httpErrorOccured();
|
||||
|
||||
private:
|
||||
|
|
|
@ -367,57 +367,57 @@
|
|||
<translation>Parse</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="178"/>
|
||||
<location filename="../ofdscene.cpp" line="188"/>
|
||||
<source>Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn't lucky, please, contact the developer.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="180"/>
|
||||
<location filename="../ofdscene.cpp" line="190"/>
|
||||
<source>Could not start http server.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="72"/>
|
||||
<location filename="../ofdscene.cpp" line="82"/>
|
||||
<source>Please, select a picture where QR code that contains info about check is present</source>
|
||||
<translation>Please, select a picture where QR code that contains info about check is present</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="74"/>
|
||||
<location filename="../ofdscene.cpp" line="84"/>
|
||||
<source>Picture was not selected</source>
|
||||
<translation>Picture was not selected</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="80"/>
|
||||
<location filename="../ofdscene.cpp" line="89"/>
|
||||
<source>Selected image: </source>
|
||||
<translation>Selected image: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="139"/>
|
||||
<location filename="../ofdscene.cpp" line="152"/>
|
||||
<source>Captcha was not solved correctly!</source>
|
||||
<translation>Captcha was not solved correctly!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="141"/>
|
||||
<location filename="../ofdscene.cpp" line="154"/>
|
||||
<source>Captcha is incorrect</source>
|
||||
<translation>Captcha is incorrect</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="146"/>
|
||||
<location filename="../ofdscene.cpp" line="159"/>
|
||||
<source>Internal server error. Please, try again later.</source>
|
||||
<translation>Internal server error. Please, try again later.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="148"/>
|
||||
<location filename="../ofdscene.cpp" line="161"/>
|
||||
<source>Internal server error</source>
|
||||
<translation>Internal server error</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="153"/>
|
||||
<location filename="../ofdscene.cpp" line="166"/>
|
||||
<source>Check not found. Please, ensure correctness of entered data.</source>
|
||||
<translation>Check not found. Please, ensure correctness of entered data.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="155"/>
|
||||
<location filename="../ofdscene.cpp" line="168"/>
|
||||
<source>Check was not found</source>
|
||||
<translation>Check was not found</translation>
|
||||
</message>
|
||||
|
|
|
@ -367,57 +367,57 @@
|
|||
<translation>Парсить</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="178"/>
|
||||
<location filename="../ofdscene.cpp" line="188"/>
|
||||
<source>Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn't lucky, please, contact the developer.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="180"/>
|
||||
<location filename="../ofdscene.cpp" line="190"/>
|
||||
<source>Could not start http server.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="72"/>
|
||||
<location filename="../ofdscene.cpp" line="82"/>
|
||||
<source>Please, select a picture where QR code that contains info about check is present</source>
|
||||
<translation>Пожалуйста, выберете изображение, содержащее QR код с информацией о чеке</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="74"/>
|
||||
<location filename="../ofdscene.cpp" line="84"/>
|
||||
<source>Picture was not selected</source>
|
||||
<translation>Изображение не было выбрано</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="80"/>
|
||||
<location filename="../ofdscene.cpp" line="89"/>
|
||||
<source>Selected image: </source>
|
||||
<translation>Выбранное изображение: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="139"/>
|
||||
<location filename="../ofdscene.cpp" line="152"/>
|
||||
<source>Captcha was not solved correctly!</source>
|
||||
<translation>Капча была решена неверно!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="141"/>
|
||||
<location filename="../ofdscene.cpp" line="154"/>
|
||||
<source>Captcha is incorrect</source>
|
||||
<translation>Капча введена неверно</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="146"/>
|
||||
<location filename="../ofdscene.cpp" line="159"/>
|
||||
<source>Internal server error. Please, try again later.</source>
|
||||
<translation>Внутренняя ошибка сервера. Пожалуйста, попробуйте снова позже.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="148"/>
|
||||
<location filename="../ofdscene.cpp" line="161"/>
|
||||
<source>Internal server error</source>
|
||||
<translation>Внутренняя ошибка сервера</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="153"/>
|
||||
<location filename="../ofdscene.cpp" line="166"/>
|
||||
<source>Check not found. Please, ensure correctness of entered data.</source>
|
||||
<translation>Чек не найден. Пожалуйста, убедитесь в правильности введённых данных.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ofdscene.cpp" line="155"/>
|
||||
<location filename="../ofdscene.cpp" line="168"/>
|
||||
<source>Check was not found</source>
|
||||
<translation>Чек не найден</translation>
|
||||
</message>
|
||||
|
|
Loading…
Reference in New Issue