implemented modular build for email text and ocr

This commit is contained in:
leca 2025-03-17 23:18:35 +03:00
parent cb8041c928
commit b966d7fcf5
5 changed files with 88 additions and 157 deletions

View File

@ -13,6 +13,10 @@ if (NOT (BUILD_EMAIL_TO_TEXT_MODE OR BUILD_OCR_MODE OR BUILD_OFD_LOCAL_QR_SCAN O
return()
endif()
if (BUILD_OFD_LOCAL_QR_SCAN OR BUILD_OFD_BINARYEYE_SCAN)
add_compile_definitions(BUILD_OFD_MODE)
endif()
if (BUILD_EMAIL_TO_TEXT_MODE)
add_compile_definitions(BUILD_EMAIL_TO_TEXT_MODE)
endif()
@ -68,9 +72,6 @@ if (BUILD_OFD_LOCAL_QR_SCAN OR BUILD_OFD_BINARYEYE_SCAN)
list(APPEND TRANSLATION_SOURCES ofdscene.cpp ofdscene.h scenes/ofdscene.ui)
endif()
message(STATUS ${TRANSLATION_SOURCES})
set(PROJECT_SOURCES
goods/goods.h goods/goods.cpp
check/check.h check/check.cpp
@ -146,9 +147,9 @@ endif()
target_link_libraries(checks-parser PRIVATE Qt5::Widgets Qt5::UiTools)
# if (BUILD_OFD_LOCAL_QR_SCAN)
if (BUILD_OFD_LOCAL_QR_SCAN)
target_include_directories(checks-parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/image_redactor)
# endif()
endif()
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER org.foxarmy.checks-parser)

159
main.cpp
View File

@ -3,7 +3,10 @@
#include "settings/settings.h"
#include "utils/utils.h"
#include <QApplication>
#include <curl/curl.h>
#ifdef BUILD_OFD_MODE
# include <curl/curl.h>
# include <ofdscene.h>
#endif
#include <iostream>
#if __GNUC__ < 8 && __clang_major__ < 17
# include <experimental/filesystem>
@ -17,9 +20,12 @@
#include <QStackedLayout>
#include <QTextStream>
#include <QTranslator>
#include <emailtextscene.h>
#include <ocrscene.h>
#include <ofdscene.h>
#ifdef BUILD_EMAIL_TO_TEXT_MODE
# include <emailtextscene.h>
#endif
#ifdef BUILD_OCR_MODE
# include <ocrscene.h>
#endif
#include <qpushbutton.h>
#include <parser/parser.h>
@ -66,37 +72,50 @@ int main(int argc, char *argv[]) {
// Main Window setup
QWidget *mainwindowscene = loadUI(window, ":/scenes/scenes/mainwindow.ui");
// Main Window buttons setup
QPushButton *text_from_email_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("text_from_email_button");
QPushButton *ocr_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("ocr_button");
QPushButton *ofd_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("ofd_button");
sceneLayout->addWidget(mainwindowscene);
for (auto btn : ((MainWindow *)mainwindowscene)->findChildren<QPushButton *>()) {
btn->hide();
}
// Main Window buttons setup
#ifdef BUILD_EMAIL_TO_TEXT_MODE
QPushButton *text_from_email_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("text_from_email_button");
text_from_email_button->show();
EmailTextScene *emailTextScene = new EmailTextScene();
sceneLayout->addWidget(emailTextScene);
QObject::connect(text_from_email_button, &QPushButton::clicked, [&]() {
// Text from email scene
sceneLayout->setCurrentIndex(1);
sceneLayout->widget(1)->show();
int index = sceneLayout->indexOf(emailTextScene);
sceneLayout->setCurrentIndex(index);
sceneLayout->widget(index)->show();
});
#endif
#ifdef BUILD_OCR_MODE
QPushButton *ocr_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("ocr_button");
ocr_button->show();
OCRScene *ocrscene = new OCRScene();
sceneLayout->addWidget(ocrscene);
QObject::connect(ocr_button, &QPushButton::clicked, [&]() {
// OCR scene
sceneLayout->setCurrentIndex(2);
sceneLayout->widget(2)->show();
int index = sceneLayout->indexOf(ocrscene);
sceneLayout->setCurrentIndex(index);
sceneLayout->widget(index)->show();
});
#endif
#ifdef BUILD_OFD_MODE
QPushButton *ofd_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("ofd_button");
ofd_button->show();
OFDScene *ofdscene = new OFDScene();
sceneLayout->addWidget(ofdscene);
QObject::connect(ofd_button, &QPushButton::clicked, [&]() {
// OFD scene
sceneLayout->setCurrentIndex(3);
sceneLayout->widget(3)->show();
int index = sceneLayout->indexOf(ofdscene);
sceneLayout->setCurrentIndex(index);
sceneLayout->widget(index)->show();
});
EmailTextScene *emailTextScene = new EmailTextScene();
OCRScene *ocrscene = new OCRScene();
OFDScene *ofdscene = new OFDScene();
sceneLayout->addWidget(mainwindowscene);
sceneLayout->addWidget(emailTextScene);
sceneLayout->addWidget(ocrscene);
sceneLayout->addWidget(ofdscene);
#endif
//Setting all back buttons
for (uint32_t sceneIndex = 0; sceneIndex < sceneLayout->count(); sceneIndex ++) {
@ -110,98 +129,8 @@ int main(int argc, char *argv[]) {
});
}
window->setLayout(sceneLayout);
window->show();
app.exec();
return 0;
// QApplication app(argc, argv);
// QWidget *window = new QWidget;
// QStackedLayout *stackedLayout = new QStackedLayout;
// QWidget *scene1 = new QWidget;
// QWidget *scene2 = new QWidget;
// // Add some widgets to each scene
// QPushButton *button1 = new QPushButton("Switch to Scene 2");
// scene1->setLayout(new QVBoxLayout);
// scene1->layout()->addWidget(button1);
// QPushButton *button2 = new QPushButton("Switch to Scene 1");
// scene2->setLayout(new QVBoxLayout);
// scene2->layout()->addWidget(button2);
// // Add the scenes to the stacked layout
// stackedLayout->addWidget(scene1);
// stackedLayout->addWidget(scene2);
// // Set the layout of the window
// window->setLayout(stackedLayout);
// // Connect the buttons to switch scenes
// QObject::connect(button1, &QPushButton::clicked, [&]() {
// stackedLayout->setCurrentIndex(1);
// });
// QObject::connect(button2, &QPushButton::clicked, [&]() {
// stackedLayout->setCurrentIndex(0);
// });
// window->show();
// app.exec();
// return 0;
curl_global_init(CURL_GLOBAL_ALL);
std::string program_data_path = get_path_relative_to_home(".local/share/checks_parser");
create_directories(program_data_path);
// std::string settings_file_path =
// get_path_relative_to_home(".local/share/checks_parser/settings.json");
// Settings s(settings_file_path);
Net n;
Parser p;
std::vector<std::string> stores_updates = p.check_updates();
for (const std::string &update : stores_updates) {
std::cout << "Downloading "
<< s.get_setting("stores_modules_url") + update << " to "
<< get_path_relative_to_home(s.get_setting("stores_modules_dir") +
"/" + update)
<< std::endl;
n.get_file(s.get_setting("stores_modules_url") + "/" + update,
get_path_relative_to_home(s.get_setting("stores_modules_dir") +
"/" + update));
}
QApplication a(argc, argv);
// QTranslator translator;
// QString lang = "en_US";
// if (s.get_all_settings().contains("language")) {
// lang = QString::fromStdString(s.get_all_settings()["language"]);
// } else if (translator.load(":/translation/"+QLocale::system().name()+".qm")) {
// lang = QLocale::system().name();
// } else {
// lang = QString::fromStdString("en_US");
// }
// std::cout << "Using locale: " << lang.toStdString() << std::endl;
// translator.load(":/translation/" + lang + ".qm");
// a.installTranslator(&translator);
MainWindow w;
w.update();
w.show();
return a.exec();
return app.exec();
}

View File

@ -33,6 +33,12 @@
</property>
<item row="0" column="1">
<widget class="QPushButton" name="ocr_button">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Optical Character Recognition</string>
</property>
@ -40,7 +46,7 @@
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="../build/Desktop-Debug/media.qrc">
<normaloff>:/icons/assets/icons/OCR.svg</normaloff>:/icons/assets/icons/OCR.svg</iconset>
</property>
<property name="iconSize">
@ -54,7 +60,7 @@
<item row="0" column="0">
<widget class="QPushButton" name="text_from_email_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -69,7 +75,7 @@
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="../build/Desktop-Debug/media.qrc">
<normaloff>:/icons/assets/icons/email-text.svg</normaloff>:/icons/assets/icons/email-text.svg</iconset>
</property>
<property name="iconSize">
@ -97,11 +103,17 @@
</item>
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="ofd_button">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="../build/Desktop-Debug/media.qrc">
<normaloff>:/icons/assets/icons/OFD.svg</normaloff>:/icons/assets/icons/OFD.svg</iconset>
</property>
<property name="iconSize">
@ -116,6 +128,9 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../build/Desktop-Debug/media.qrc"/>
<include location="../build/Desktop-Debug/media.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -27,43 +27,36 @@
<context>
<name>EmailTextScene</name>
<message>
<location filename="../scenes/emailtextscene.ui" line="14"/>
<source>Form</source>
<translation>Form</translation>
<translation type="vanished">Form</translation>
</message>
<message>
<source>Store type</source>
<translation type="obsolete">Store type</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="26"/>
<source>Check content</source>
<translation>Check content</translation>
<translation type="vanished">Check content</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="33"/>
<source>Parse</source>
<translation>Parse</translation>
<translation type="vanished">Parse</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="46"/>
<source>Store:</source>
<translation>Store:</translation>
<translation type="vanished">Store:</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="62"/>
<source>Back</source>
<translation>Back</translation>
<translation type="vanished">Back</translation>
</message>
<message>
<location filename="../emailtextscene.cpp" line="31"/>
<source>An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer.</source>
<translation>An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer.</translation>
<translation type="vanished">An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer.</translation>
</message>
<message>
<location filename="../emailtextscene.cpp" line="33"/>
<source>Error in parsing</source>
<translation>Error in parsing</translation>
<translation type="vanished">Error in parsing</translation>
</message>
</context>
<context>
@ -211,12 +204,12 @@
<translation>Form</translation>
</message>
<message>
<location filename="../scenes/mainwindow.ui" line="37"/>
<location filename="../scenes/mainwindow.ui" line="43"/>
<source>Optical Character Recognition</source>
<translation>Optical Character Recognition</translation>
</message>
<message>
<location filename="../scenes/mainwindow.ui" line="63"/>
<location filename="../scenes/mainwindow.ui" line="69"/>
<source>Text from E-Mail</source>
<translation>Text from E-Mail</translation>
</message>

View File

@ -27,43 +27,36 @@
<context>
<name>EmailTextScene</name>
<message>
<location filename="../scenes/emailtextscene.ui" line="14"/>
<source>Form</source>
<translation>Форма</translation>
<translation type="vanished">Форма</translation>
</message>
<message>
<source>Store type</source>
<translation type="obsolete">Магазин</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="26"/>
<source>Check content</source>
<translation>Контент чека</translation>
<translation type="vanished">Контент чека</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="33"/>
<source>Parse</source>
<translation>Парсить</translation>
<translation type="vanished">Парсить</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="46"/>
<source>Store:</source>
<translation>Магазин:</translation>
<translation type="vanished">Магазин:</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="62"/>
<source>Back</source>
<translation>Назад</translation>
<translation type="vanished">Назад</translation>
</message>
<message>
<location filename="../emailtextscene.cpp" line="31"/>
<source>An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer.</source>
<translation>Произошла ошибка. Чек был прочитан неверно. Размеры векторов различаются. Пожалуйста, сообщите об этом разработчику.</translation>
<translation type="vanished">Произошла ошибка. Чек был прочитан неверно. Размеры векторов различаются. Пожалуйста, сообщите об этом разработчику.</translation>
</message>
<message>
<location filename="../emailtextscene.cpp" line="33"/>
<source>Error in parsing</source>
<translation>Ошибка в парсинге</translation>
<translation type="vanished">Ошибка в парсинге</translation>
</message>
</context>
<context>
@ -211,12 +204,12 @@
<translation>Форма</translation>
</message>
<message>
<location filename="../scenes/mainwindow.ui" line="37"/>
<location filename="../scenes/mainwindow.ui" line="43"/>
<source>Optical Character Recognition</source>
<translation>Оптическое распознавание символов</translation>
</message>
<message>
<location filename="../scenes/mainwindow.ui" line="63"/>
<location filename="../scenes/mainwindow.ui" line="69"/>
<source>Text from E-Mail</source>
<translation>Текст из электронного письма</translation>
</message>