restructure, change onDataDecode signal and succesfully parsing http request
This commit is contained in:
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() {
|
||||
|
||||
Reference in New Issue
Block a user