From d17695a7fa052a8f4c6cb86d68f74616f89cea87 Mon Sep 17 00:00:00 2001 From: leca Date: Sun, 23 Mar 2025 20:55:34 +0300 Subject: [PATCH] settings and bugfixes --- CMakeLists.txt | 1 + .../{ubuntu.Dockerfile => ubuntu/Dockerfile} | 0 deploy/debian/Dockerfile | 2 +- docker-compose.yml | 2 +- main.cpp | 14 +- scenes.qrc | 1 + scenes/mainwindow.ui | 67 ++-- scenes/settingsdialog.ui | 290 +++++++++++++++++ settingsdialog.cpp | 22 +- settingsdialog.h | 2 + settingsdialog.ui | 306 ------------------ translations/en_US.ts | 81 +++-- translations/ru_RU.ts | 81 +++-- utils/utils.cpp | 13 +- 14 files changed, 487 insertions(+), 395 deletions(-) rename deploy/base-docker/{ubuntu.Dockerfile => ubuntu/Dockerfile} (100%) create mode 100644 scenes/settingsdialog.ui delete mode 100644 settingsdialog.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index f87a7c2..9212bf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,7 @@ set(TRANSLATION_SOURCES main.cpp mainwindow.cpp mainwindow.h scenes/mainwindow.ui outputdialog.h outputdialog.cpp scenes/outputdialog.ui + settingsdialog.h settingsdialog.cpp scenes/settingsdialog.ui ) if (BUILD_EMAIL_TO_TEXT_MODE) diff --git a/deploy/base-docker/ubuntu.Dockerfile b/deploy/base-docker/ubuntu/Dockerfile similarity index 100% rename from deploy/base-docker/ubuntu.Dockerfile rename to deploy/base-docker/ubuntu/Dockerfile diff --git a/deploy/debian/Dockerfile b/deploy/debian/Dockerfile index 4b590be..d36c7dd 100644 --- a/deploy/debian/Dockerfile +++ b/deploy/debian/Dockerfile @@ -1,4 +1,4 @@ -from checks_parser_base_ubuntu +FROM checks_parser_base_ubuntu #for envsubst RUN DEBIAN_FRONTEND=noninteractive apt install -y gettext diff --git a/docker-compose.yml b/docker-compose.yml index c409ec1..f39c1d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: image: checks_parser_base_ubuntu:latest build: context: . - dockerfile: deploy/base-docker/ubuntu.Dockerfile + dockerfile: deploy/base-docker/ubuntu/Dockerfile appimage: image: checks_parser_appimage:latest build: diff --git a/main.cpp b/main.cpp index 17b4226..1d556f6 100644 --- a/main.cpp +++ b/main.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef BUILD_EMAIL_TO_TEXT_MODE # include #endif @@ -69,8 +70,6 @@ int main(int argc, char *argv[]) { translator.load(":/translation/" + lang + ".qm"); app.installTranslator(&translator); - - QUiLoader loader; #endif QWidget *window = new QWidget(); @@ -81,7 +80,16 @@ int main(int argc, char *argv[]) { sceneLayout->addWidget(mainwindowscene); - for (auto btn : ((MainWindow *)mainwindowscene)->findChildren()) { + //Settings button setup + QPushButton *settingsButton = ((MainWindow *)mainwindowscene)->findChild("settings_button"); + QObject::connect(settingsButton, &QPushButton::clicked, [&]() { + SettingsDialog d; + d.show(); + d.exec(); + }); + + for (auto &btn : ((MainWindow *)mainwindowscene)->findChildren()) { + if (btn->objectName() == "settings_button") continue; btn->hide(); } diff --git a/scenes.qrc b/scenes.qrc index 4704a99..dc42550 100644 --- a/scenes.qrc +++ b/scenes.qrc @@ -5,6 +5,7 @@ scenes/ocrscene.ui scenes/mainwindow.ui scenes/ofdscene.ui + scenes/settingsdialog.ui scenes/solvecaptchadialog.ui diff --git a/scenes/mainwindow.ui b/scenes/mainwindow.ui index 152d9b6..dc48141 100644 --- a/scenes/mainwindow.ui +++ b/scenes/mainwindow.ui @@ -31,32 +31,6 @@ 6 - - - - - 0 - 0 - - - - Optical Character Recognition - - - - - - - :/icons/assets/icons/OCR.svg:/icons/assets/icons/OCR.svg - - - - 128 - 128 - - - - @@ -101,7 +75,33 @@ - + + + + + 0 + 0 + + + + Optical Character Recognition + + + + + + + :/icons/assets/icons/OCR.svg:/icons/assets/icons/OCR.svg + + + + 128 + 128 + + + + + @@ -124,6 +124,19 @@ + + + + + 0 + 0 + + + + Settings + + + diff --git a/scenes/settingsdialog.ui b/scenes/settingsdialog.ui new file mode 100644 index 0000000..1e8912b --- /dev/null +++ b/scenes/settingsdialog.ui @@ -0,0 +1,290 @@ + + + settingsdialog + + + + 0 + 0 + 693 + 786 + + + + Dialog + + + + + + true + + + + + 0 + 0 + 673 + 724 + + + + + + + + + + + + + + + + Goods net weight position + + + + + + + + + + Stores modules url + + + + + + + Goods quantity position + + + + + + + + + + OFD modules url + + + + + + + Print header + + + + + + + + + + + + + Goods quantity alias + + + + + + + OFD modules directory + + + + + + + + + + Print total + + + + + + + + + + + + + Goods net weight alias + + + + + + + + + + + + + Goods total alias + + + + + + + + + + + + + + + + + + + Goods name position + + + + + + + + + + + + + + Goods name alias + + + + + + + Goods price per unit position + + + + + + + Stores modules directory + + + + + + + Goods total position + + + + + + + Choose + + + + + + + + + + Goods price per unit alias + + + + + + + Choose + + + + + + + Language + + + + + + + + en_US + + + + + ru_RU + + + + + + + + + + + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Save + + + + + + + + + buttonBox + accepted() + settingsdialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + settingsdialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/settingsdialog.cpp b/settingsdialog.cpp index f74a101..9b92f07 100644 --- a/settingsdialog.cpp +++ b/settingsdialog.cpp @@ -1,7 +1,10 @@ #include "settingsdialog.h" -#include "settings/settings.h" #include "ui_settingsdialog.h" -#include "utils/utils.h" + +#include +#include + +#include #include @@ -34,10 +37,14 @@ SettingsDialog::SettingsDialog(QWidget *parent) ui->printHeaderCheckBox->setChecked(this->settings.get_all_settings()["print_header"]); ui->printTotalCheckBox->setChecked(this->settings.get_all_settings()["print_total"]); - + std::cout << settings.get_all_settings() << std::endl; int currentLanguageIndex = 0; - if (!this->settings.get_all_settings().contains("language")) { + bool languageSettingPresent = false; + + //TODO: check that "language" exists before getting its value + languageSettingPresent = settings.get_all_settings().find("language") != settings.get_all_settings().end(); + if (languageSettingPresent) { currentLanguageIndex = ui->languageComboBox->findText(QLocale::system().name()); if (currentLanguageIndex < 0) { currentLanguageIndex = ui->languageComboBox->findText("en_US"); @@ -137,7 +144,11 @@ void SettingsDialog::on_buttonBox_accepted() { this->settings.flush(); } void SettingsDialog::on_buttonBox_rejected() { this->close(); } void SettingsDialog::on_languageComboBox_currentTextChanged(const QString &changed) { - if (this->settings.get_all_settings().contains("language")) { + bool languageSettingPresent = false; + + languageSettingPresent = settings.get_all_settings().find("language") != settings.get_all_settings().end(); + + if (languageSettingPresent) { if (changed == QString::fromStdString(this->settings.get_all_settings()["language"])) return; } else { if (changed == QLocale::system().name()) return; @@ -151,4 +162,3 @@ void SettingsDialog::on_languageComboBox_currentTextChanged(const QString &chang infoDialog.setWindowTitle(tr("Restart required")); infoDialog.exec(); } - diff --git a/settingsdialog.h b/settingsdialog.h index d3aceb6..137e8c5 100644 --- a/settingsdialog.h +++ b/settingsdialog.h @@ -56,6 +56,8 @@ private slots: private: Ui::settingsdialog *ui; +public: + bool settingsExist(); }; #endif // SETTINGSDIALOG_H diff --git a/settingsdialog.ui b/settingsdialog.ui deleted file mode 100644 index a239e0f..0000000 --- a/settingsdialog.ui +++ /dev/null @@ -1,306 +0,0 @@ - - - settingsdialog - - - - 0 - 0 - 599 - 799 - - - - Dialog - - - - - 310 - 740 - 251 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Save - - - - - - 10 - 0 - 541 - 741 - - - - true - - - - - 0 - 0 - 539 - 739 - - - - - - 0 - 0 - 531 - 731 - - - - - - - - - - - - - - Goods net weight position - - - - - - - - - - Stores modules url - - - - - - - Goods quantity position - - - - - - - - - - OFD modules url - - - - - - - Print header - - - - - - - - - - - - - Goods quantity alias - - - - - - - OFD modules directory - - - - - - - - - - Print total - - - - - - - - - - - - - Goods net weight alias - - - - - - - - - - - - - Goods total alias - - - - - - - - - - - - - - - - - - - Goods name position - - - - - - - - - - - - - - Goods name alias - - - - - - - Goods price per unit position - - - - - - - Stores modules directory - - - - - - - Goods total position - - - - - - - Choose - - - - - - - - - - Goods price per unit alias - - - - - - - Choose - - - - - - - TextLabel - - - - - - - - en_US - - - - - ru_RU - - - - - - - - - - - - - buttonBox - accepted() - settingsdialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - settingsdialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/translations/en_US.ts b/translations/en_US.ts index 4e51be1..5fd5505 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -211,12 +211,17 @@ Form - + Optical Character Recognition Optical Character Recognition - + + Settings + + + + Text from E-Mail Text from E-Mail @@ -557,12 +562,14 @@ SettingsDialog + You need to restart program to apply language changes - You need to restart program to apply language changes + You need to restart program to apply language changes + Restart required - Restart required + Restart required @@ -586,88 +593,114 @@ settingsdialog + Dialog - Dialog + Dialog + Goods name position - Goods name position + Goods name position + Goods price per unit alias - Goods price per unit alias + Goods price per unit alias + + + + Language + TextLabel Language + en_US - en_US + en_US + ru_RU - ru_RU + ru_RU + + Choose - Choose + Choose + Print header - Print header + Print header + Goods net weight alias - Goods net weight alias + Goods net weight alias + Stores modules url - Stores modules url + Stores modules url + Goods total alias - Goods total alias + Goods total alias + Goods name alias - Goods name alias + Goods name alias + Goods quantity alias - Goods quantity alias + Goods quantity alias + Stores modules directory - Stores modules directory + Stores modules directory + OFD modules directory - OFD modules directory + OFD modules directory + Goods price per unit position - Goods price per unit position + Goods price per unit position + Goods net weight position - Goods net weight position + Goods net weight position + OFD modules url - OFD modules url + OFD modules url + Goods total position - Goods total position + Goods total position + Goods quantity position - Goods quantity position + Goods quantity position + Print total - Print total + Print total diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index 1eebc78..819e47c 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -211,12 +211,17 @@ Форма - + Optical Character Recognition Оптическое распознавание символов - + + Settings + + + + Text from E-Mail Текст из электронного письма @@ -557,12 +562,14 @@ SettingsDialog + You need to restart program to apply language changes - Требуется перезагрузить программу, чтобы применить изменения языка + Требуется перезагрузить программу, чтобы применить изменения языка + Restart required - Требуется перезагрузка + Требуется перезагрузка @@ -586,88 +593,114 @@ settingsdialog + Dialog - Диалог + Диалог + Goods name position - Позиция имени товара + Позиция имени товара + Goods price per unit alias - Алиас цены товара + Алиас цены товара + + + + Language + TextLabel Язык + en_US - en_US + en_US + ru_RU - ru_RU + ru_RU + + Choose - Выбрать + Выбрать + Print header - Печатать заголовок + Печатать заголовок + Goods net weight alias - Алиас массы нетто товара + Алиас массы нетто товара + Stores modules url - URL модулей магазина + URL модулей магазина + Goods total alias - Алиас всего за продукт + Алиас всего за продукт + Goods name alias - Алиас имени товара + Алиас имени товара + Goods quantity alias - Алиас количества товара + Алиас количества товара + Stores modules directory - Директория модулей магазина + Директория модулей магазина + OFD modules directory - Директория модулей ОФД + Директория модулей ОФД + Goods price per unit position - Позиция центы товара + Позиция центы товара + Goods net weight position - Позиция массы нетто товара + Позиция массы нетто товара + OFD modules url - URL модулей ОФД + URL модулей ОФД + Goods total position - Позиция всего за товар + Позиция всего за товар + Goods quantity position - Позиция количества товара + Позиция количества товара + Print total - Печатать Итого + Печатать Итого diff --git a/utils/utils.cpp b/utils/utils.cpp index af35aaa..f40ce3b 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -145,16 +145,16 @@ std::vector find_in_html(std::string& html, std::string regex, std it != end; it++) { std::wstring found_entry = from_utf8(it->str()); - std::wcout << "Found: " << found_entry << std::endl; + std::cout << "Found: " << to_utf8(found_entry) << std::endl; std::wstring extracted = substring_from_to(found_entry, from_utf8(html_start), from_utf8(html_end)); - std::wcout << "Extracted: " << extracted << std::endl; + std::cout << "Extracted: " << to_utf8(extracted) << std::endl; parsed.push_back(extracted); } return parsed; } std::vector find_products_in_html(std::string html) { - return find_in_html(html, "
.{10,100}<\\/b><\\/div>", "
", "<\\/b><\\/div>"); + return find_in_html(html, "
.{2,100}<\\/b><\\/div>", "
", "<\\/b><\\/div>"); } std::vector find_amounts_in_html(std::string html) { @@ -170,11 +170,16 @@ std::vector find_net_weights_in_names(std::vector &n std::vector result; for (std::wstring &name : names ) { boost::wregex regexp(from_utf8("((\\d+(.|,)?\\d?((м|)л|(к|м|)г|т|ц|шт|(pc|)s|(m|k|)g|(m|)l|t)).?)+"), boost::regex_constants::collate); + bool found = false; for (boost::wsregex_iterator it{name.begin(), name.end(), regexp}, end{}; it != end; it++) { result.push_back(it->str()); + found = true; break; } + if (!found) { + result.push_back(from_utf8("?")); + } } return result; } @@ -247,6 +252,8 @@ Check parseOfdRuAnswer(std::string html) { Check c; for (int i = 0; i < products.size(); i ++) { + std::cout << "Adding to check: "; + std::cout << to_utf8(products[i]) << " " << to_utf8(prices[i]) << " " << to_utf8(net_weights[i]) << " " << to_utf8(amounts[i]) << std::endl; Goods goods(to_utf8(products[i]), std::stod(prices[i]), to_utf8(net_weights[i]), std::stod(amounts[i])); c.add_goods(goods); }