restructure, change onDataDecode signal and succesfully parsing http request

This commit is contained in:
leca 2025-03-15 00:48:46 +03:00
parent f507ec8d67
commit 2b2127e3b5
6 changed files with 65 additions and 42 deletions

View File

@ -41,7 +41,13 @@ void AdjustPictureDialog::accept() {
infoDialog.setWindowTitle(tr("No QR code")); infoDialog.setWindowTitle(tr("No QR code"));
infoDialog.exec(); infoDialog.exec();
} else { } 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(); QDialog::accept();
} }

View File

@ -22,7 +22,7 @@ public:
void computeContrastLookupTable(); void computeContrastLookupTable();
std::vector<unsigned short> contrastLUT[100]; std::vector<unsigned short> contrastLUT[100];
signals: signals:
void decodedData(std::string data); void decodedData(std::map<std::string, std::string> data);
private slots: private slots:

View File

@ -13,6 +13,8 @@
#include <exceptions/ofdrequestexception.h> #include <exceptions/ofdrequestexception.h>
#include <bits/basic_string.h>
OFDScene::OFDScene(QWidget *parent) OFDScene::OFDScene(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::OFDScene) { , ui(new Ui::OFDScene) {
@ -46,8 +48,20 @@ void OFDScene::startHttpServer() {
httplib::Server svr; httplib::Server svr;
svr.Get("/", [&](const httplib::Request &, httplib::Response &res){ svr.Get("/", [&](const httplib::Request &req, httplib::Response &res){
res.set_redirect("http://"+ localIp +":"+ std::to_string(port) +"/", 301); 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 &param : 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 ++; number_of_retries ++;
@ -79,22 +93,26 @@ void OFDScene::on_choose_image_button_clicked() {
dialog.exec(); dialog.exec();
} }
void OFDScene::onDataDecode(std::string data) { void OFDScene::onDataDecode(std::map<std::string, std::string> data) {
std::vector<std::string> dataSplit = split(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. //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"); QDateTime datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmm");
if (datetime == QDateTime::fromString(extractedDateTime, "20000101T1200")) {
datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmmss");
}
ui->purchase_datetime_edit->setDateTime(datetime); 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); 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)); ui->total_spin_box->setValue(std::stod(total));
} }
@ -158,7 +176,6 @@ void OFDScene::on_parse_button_clicked() {
OutputDialog d = OutputDialog(this, check); OutputDialog d = OutputDialog(this, check);
d.exec(); d.exec();
} }
} }
@ -167,12 +184,11 @@ void OFDScene::on_binary_eye_button_clicked() {
} }
void OFDScene::notifyHttpServerFailure() { void OFDScene::notifyHttpServerFailure() {
QMessageBox *infoDialog = new QMessageBox(); 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.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.setIcon(QMessageBox::Warning);
infoDialog->setWindowTitle(tr("Could not start http server.")); infoDialog.setWindowTitle(tr("Could not start http server."));
infoDialog->exec(); infoDialog.exec();
delete infoDialog;
} }
unsigned int OFDScene::getPort() { unsigned int OFDScene::getPort() {

View File

@ -20,7 +20,7 @@ public:
unsigned int getPort(); unsigned int getPort();
private slots: private slots:
void on_choose_image_button_clicked(); void on_choose_image_button_clicked();
void onDataDecode(std::string data); void onDataDecode(std::map<std::string, std::string>);
void on_parse_button_clicked(); void on_parse_button_clicked();
@ -28,6 +28,7 @@ private slots:
void notifyHttpServerFailure(); void notifyHttpServerFailure();
signals: signals:
void httpErrorOccured(); void httpErrorOccured();
private: private:

View File

@ -367,57 +367,57 @@
<translation>Parse</translation> <translation>Parse</translation>
</message> </message>
<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&apos;t lucky, please, contact the developer.</source> <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&apos;t lucky, please, contact the developer.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="180"/> <location filename="../ofdscene.cpp" line="190"/>
<source>Could not start http server.</source> <source>Could not start http server.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<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> <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> <translation>Please, select a picture where QR code that contains info about check is present</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="74"/> <location filename="../ofdscene.cpp" line="84"/>
<source>Picture was not selected</source> <source>Picture was not selected</source>
<translation>Picture was not selected</translation> <translation>Picture was not selected</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="80"/> <location filename="../ofdscene.cpp" line="89"/>
<source>Selected image: </source> <source>Selected image: </source>
<translation>Selected image: </translation> <translation>Selected image: </translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="139"/> <location filename="../ofdscene.cpp" line="152"/>
<source>Captcha was not solved correctly!</source> <source>Captcha was not solved correctly!</source>
<translation>Captcha was not solved correctly!</translation> <translation>Captcha was not solved correctly!</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="141"/> <location filename="../ofdscene.cpp" line="154"/>
<source>Captcha is incorrect</source> <source>Captcha is incorrect</source>
<translation>Captcha is incorrect</translation> <translation>Captcha is incorrect</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="146"/> <location filename="../ofdscene.cpp" line="159"/>
<source>Internal server error. Please, try again later.</source> <source>Internal server error. Please, try again later.</source>
<translation>Internal server error. Please, try again later.</translation> <translation>Internal server error. Please, try again later.</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="148"/> <location filename="../ofdscene.cpp" line="161"/>
<source>Internal server error</source> <source>Internal server error</source>
<translation>Internal server error</translation> <translation>Internal server error</translation>
</message> </message>
<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> <source>Check not found. Please, ensure correctness of entered data.</source>
<translation>Check not found. Please, ensure correctness of entered data.</translation> <translation>Check not found. Please, ensure correctness of entered data.</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="155"/> <location filename="../ofdscene.cpp" line="168"/>
<source>Check was not found</source> <source>Check was not found</source>
<translation>Check was not found</translation> <translation>Check was not found</translation>
</message> </message>

View File

@ -367,57 +367,57 @@
<translation>Парсить</translation> <translation>Парсить</translation>
</message> </message>
<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&apos;t lucky, please, contact the developer.</source> <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&apos;t lucky, please, contact the developer.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="180"/> <location filename="../ofdscene.cpp" line="190"/>
<source>Could not start http server.</source> <source>Could not start http server.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<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> <source>Please, select a picture where QR code that contains info about check is present</source>
<translation>Пожалуйста, выберете изображение, содержащее QR код с информацией о чеке</translation> <translation>Пожалуйста, выберете изображение, содержащее QR код с информацией о чеке</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="74"/> <location filename="../ofdscene.cpp" line="84"/>
<source>Picture was not selected</source> <source>Picture was not selected</source>
<translation>Изображение не было выбрано</translation> <translation>Изображение не было выбрано</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="80"/> <location filename="../ofdscene.cpp" line="89"/>
<source>Selected image: </source> <source>Selected image: </source>
<translation>Выбранное изображение: </translation> <translation>Выбранное изображение: </translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="139"/> <location filename="../ofdscene.cpp" line="152"/>
<source>Captcha was not solved correctly!</source> <source>Captcha was not solved correctly!</source>
<translation>Капча была решена неверно!</translation> <translation>Капча была решена неверно!</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="141"/> <location filename="../ofdscene.cpp" line="154"/>
<source>Captcha is incorrect</source> <source>Captcha is incorrect</source>
<translation>Капча введена неверно</translation> <translation>Капча введена неверно</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="146"/> <location filename="../ofdscene.cpp" line="159"/>
<source>Internal server error. Please, try again later.</source> <source>Internal server error. Please, try again later.</source>
<translation>Внутренняя ошибка сервера. Пожалуйста, попробуйте снова позже.</translation> <translation>Внутренняя ошибка сервера. Пожалуйста, попробуйте снова позже.</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="148"/> <location filename="../ofdscene.cpp" line="161"/>
<source>Internal server error</source> <source>Internal server error</source>
<translation>Внутренняя ошибка сервера</translation> <translation>Внутренняя ошибка сервера</translation>
</message> </message>
<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> <source>Check not found. Please, ensure correctness of entered data.</source>
<translation>Чек не найден. Пожалуйста, убедитесь в правильности введённых данных.</translation> <translation>Чек не найден. Пожалуйста, убедитесь в правильности введённых данных.</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="155"/> <location filename="../ofdscene.cpp" line="168"/>
<source>Check was not found</source> <source>Check was not found</source>
<translation>Чек не найден</translation> <translation>Чек не найден</translation>
</message> </message>