This commit is contained in:
2025-05-08 21:02:56 +03:00
parent 6706cbec45
commit 86a11faf70
24 changed files with 1022 additions and 460 deletions

View File

@@ -15,6 +15,7 @@
#include <net/net.h>
#include <utils/utils.h>
#include <exceptions/ofdrequestexception.h>
#include <checklistviewwidget.h>
#ifdef BUILD_OFD_BINARYEYE_SCAN
# include <qrencode.h>
@@ -31,6 +32,13 @@ MainWindow::MainWindow(QWidget *parent)
ui->setupUi(this);
ui->stop_server_button->hide();
QVBoxLayout *layout = new QVBoxLayout;
ui->scrollAreaWidgetContents->setLayout(layout);
QLabel a = QLabel("123");
layout->addWidget(&a);
// ui->checks_to_parse_label->hide();
// ui->checks_scroll_area->hide();
#ifdef BUILD_OFD_BINARYEYE_SCAN
QObject::connect(this, &MainWindow::httpErrorOccured, this, &MainWindow::notifyHttpServerFailure);
connect(this, SIGNAL(httpNewMessage(QString)), this, SLOT(httpNewMessageHandler(QString)));
@@ -170,19 +178,65 @@ void MainWindow::onDataDecode(std::map<std::string, std::string> data) {
ui->total_spin_box->setValue(std::stod(total));
}
#ifdef BUILD_EMAIL_MODE
void MainWindow::on_parse_email_button_clicked() {
QMessageBox infoDialog;
infoDialog.setText(tr("This feature is under development. Wait it to appear in next updates."));
infoDialog.setIcon(QMessageBox::Warning);
infoDialog.setWindowTitle(tr("Under development"));
infoDialog.exec();
return;
}
#endif // ifdef BUILD_EMAIL_MODE
void MainWindow::on_parse_button_clicked() {
// if (checks.empty()) {
// QMessageBox infoDialog;
// infoDialog.setText(tr("Please, add check(s) to parse"));
// infoDialog.setIcon(QMessageBox::Warning);
// infoDialog.setWindowTitle(tr("No checks to parse"));
// infoDialog.exec();
// return;
// }
OutputDialog d = OutputDialog(this, &checks);
d.exec();
}
void MainWindow::on_add_new_check_button_clicked() {
Check *new_check = parse_new_check();
if (new_check == nullptr) {
return;
}
checks.push_back(*new_check);
CheckListViewWidget check_list_widget(this, *new_check);
auto a = QLabel("123");
ui->scrollAreaWidgetContents->layout()->addWidget(&a);
delete new_check;
if (checks.size() == 1) {
ui->checks_scroll_area->show();
ui->checks_to_parse_label->show();
}
}
Check *MainWindow::parse_new_check() {
Net net;
net.get_captcha_from_ofdru();
std::string solved_captcha = "";
bool success = true;
bool is_captcha_solved = true;
Check check;
do {
for (unsigned short i = 0; i < 5; i ++) {
// Will be repaced with neural network to solve captchas as soon as I train it.
net.get_captcha_from_ofdru();
SolveCaptchaDialog dialog = SolveCaptchaDialog(this, &solved_captcha);
dialog.exec();
is_captcha_solved = true;
Check* check = new Check();
try {
std::string check_content = net.fetch_check_data_from_ofdru(
@@ -195,44 +249,36 @@ void MainWindow::on_parse_button_clicked() {
ui->total_spin_box->text().toDouble() * 100,
solved_captcha);
check = parseOfdRuAnswer(check_content);
(*check) = parseOfdRuAnswer(check_content);
return check;
} catch(OfdRequestException e) {
success = false;
if (!strcmp(e.what(), "Incorrect captcha")) {
is_captcha_solved = false;
QMessageBox infoDialog;
infoDialog.setText(tr("Captcha was not solved correctly!"));
infoDialog.setIcon(QMessageBox::Critical);
infoDialog.setWindowTitle(tr("Captcha is incorrect"));
infoDialog.exec();
break;
continue;
} else if (!strcmp(e.what(), "Internal server error")) {
QMessageBox infoDialog;
infoDialog.setText(tr("Internal server error. Please, try again later."));
infoDialog.setIcon(QMessageBox::Critical);
infoDialog.setWindowTitle(tr("Internal server error"));
infoDialog.exec();
return;
return nullptr;
} else if (!strcmp(e.what(), "Does not exist")) {
QMessageBox infoDialog;
infoDialog.setText(tr("Check not found. Please, ensure correctness of entered data."));
infoDialog.setIcon(QMessageBox::Critical);
infoDialog.setWindowTitle(tr("Check was not found"));
infoDialog.exec();
return;
return nullptr;
}
}
} while (!is_captcha_solved);
if (success) {
OutputDialog *d = new OutputDialog(this, check);
d->exec();
delete d;
}
return nullptr;
}
MainWindow::~MainWindow() {
delete ui;
}