rewrite utils with moduled approach, butfixes

This commit is contained in:
leca 2025-03-17 23:39:08 +03:00
parent b966d7fcf5
commit b57a542161
6 changed files with 94 additions and 88 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(checks-parser VERSION 0.1 LANGUAGES CXX)
project(checks-parser VERSION 0.0.4 LANGUAGES CXX)
option(BUILD_TRANSLATIONS "Build translations?" ON)
option(BUILD_EMAIL_TO_TEXT_MODE "Build email-to-text mode?" ON)
@ -90,6 +90,9 @@ set(PROJECT_SOURCES
if (BUILD_OCR_MODE)
list(APPEND PROJECT_SOURCES image/checkimage.h image/checkimage.cpp)
endif()
if (BUILD_OFD_LOCAL_QR_SCAN)
list(APPEND PROJECT_SOURCES image_redactor/imageredactor.h image_redactor/imageredactor.cpp)
endif()
@ -187,9 +190,7 @@ endif()
if (BUILD_OCR_MODE)
target_link_libraries(checks-parser PRIVATE -ltesseract)
endif()
if (BUILD_OFD_BINARYEYE_SCAN OR BUILD_OFD_LOCAL_QR_SCAN)
target_link_libraries(checks-parser PRIVATE -lcurl)
endif()
target_link_libraries(checks-parser PRIVATE -lcurl)
if (BUILD_OCR_MODE OR BUILD_OFD_LOCAL_QR_SCAN OR BUILD_OFD_BINARYEYE_SCAN)
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs)

View File

@ -13,65 +13,42 @@
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>450</x>
<y>450</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QSlider" name="contrastSlider">
<property name="geometry">
<rect>
<x>10</x>
<y>460</y>
<width>591</width>
<height>16</height>
</rect>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>0</y>
<width>511</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Please, zoom to qr code and adjust contrast so that qr code looks sharp</string>
</property>
</widget>
<widget class="ImageRedactor" name="graphicsView">
<property name="geometry">
<rect>
<x>5</x>
<y>21</y>
<width>801</width>
<height>421</height>
</rect>
</property>
</widget>
<zorder>buttonBox</zorder>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="ImageRedactor" name="graphicsView"/>
</item>
<item row="2" column="0">
<widget class="QSlider" name="contrastSlider">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Please, zoom to qr code and adjust contrast so that qr code looks sharp</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
</layout>
<zorder>label</zorder>
<zorder>contrastSlider</zorder>
<zorder>graphicsView</zorder>
<zorder>buttonBox</zorder>
</widget>
<customwidgets>
<customwidget>

View File

@ -9,7 +9,7 @@
<translation>Dialog</translation>
</message>
<message>
<location filename="../scenes/adjustpicturedialog.ui" line="58"/>
<location filename="../scenes/adjustpicturedialog.ui" line="33"/>
<source>Please, zoom to qr code and adjust contrast so that qr code looks sharp</source>
<translation>Please, zoom to qr code and adjust contrast so that qr code looks sharp</translation>
</message>
@ -27,36 +27,43 @@
<context>
<name>EmailTextScene</name>
<message>
<location filename="../scenes/emailtextscene.ui" line="14"/>
<source>Form</source>
<translation type="vanished">Form</translation>
<translation>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 type="vanished">Check content</translation>
<translation>Check content</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="33"/>
<source>Parse</source>
<translation type="vanished">Parse</translation>
<translation>Parse</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="46"/>
<source>Store:</source>
<translation type="vanished">Store:</translation>
<translation>Store:</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="62"/>
<source>Back</source>
<translation type="vanished">Back</translation>
<translation>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 type="vanished">An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer.</translation>
<translation>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 type="vanished">Error in parsing</translation>
<translation>Error in parsing</translation>
</message>
</context>
<context>

View File

@ -9,7 +9,7 @@
<translation>Диалог</translation>
</message>
<message>
<location filename="../scenes/adjustpicturedialog.ui" line="58"/>
<location filename="../scenes/adjustpicturedialog.ui" line="33"/>
<source>Please, zoom to qr code and adjust contrast so that qr code looks sharp</source>
<translation>Пожалуйста, приблизьте QR код и настройте контраст, чтобы он читался</translation>
</message>
@ -27,36 +27,43 @@
<context>
<name>EmailTextScene</name>
<message>
<location filename="../scenes/emailtextscene.ui" line="14"/>
<source>Form</source>
<translation type="vanished">Форма</translation>
<translation>Форма</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 type="vanished">Контент чека</translation>
<translation>Контент чека</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="33"/>
<source>Parse</source>
<translation type="vanished">Парсить</translation>
<translation>Парсить</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="46"/>
<source>Store:</source>
<translation type="vanished">Магазин:</translation>
<translation>Магазин:</translation>
</message>
<message>
<location filename="../scenes/emailtextscene.ui" line="62"/>
<source>Back</source>
<translation type="vanished">Назад</translation>
<translation>Назад</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 type="vanished">Произошла ошибка. Чек был прочитан неверно. Размеры векторов различаются. Пожалуйста, сообщите об этом разработчику.</translation>
<translation>Произошла ошибка. Чек был прочитан неверно. Размеры векторов различаются. Пожалуйста, сообщите об этом разработчику.</translation>
</message>
<message>
<location filename="../emailtextscene.cpp" line="33"/>
<source>Error in parsing</source>
<translation type="vanished">Ошибка в парсинге</translation>
<translation>Ошибка в парсинге</translation>
</message>
</context>
<context>

View File

@ -1,24 +1,30 @@
#include "utils.h"
#include <arpa/inet.h>
#ifdef BUILD_OFD_BINARYEYE_SCAN
# include <arpa/inet.h>
# include <qrencode.h>
# include <ifaddrs.h>
# include <netinet/in.h>
#endif
#ifdef BUILD_OFD_MODULE
# include "../exceptions/ofdrequestexception.h"
#endif
#include <codecvt>
#include <cstring>
#include <iostream>
#include <locale>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <qrencode.h>
#if defined(BUILD_OCR_MODE) || defined(BUILD_OFD_MODE)
# include <opencv2/core/mat.hpp>
# include <opencv2/imgcodecs.hpp>
# include <opencv2/imgproc.hpp>
#endif
#include <regex>
#include <string>
#include "../exceptions/ofdrequestexception.h"
#include "settings/settings.h"
#include <QWidget>
#include <fstream>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <opencv2/opencv.hpp>
#ifdef BUILD_OFD_BINARYEYE_SCAN
std::string get_local_ip_address() {
struct ifaddrs * ifAddrStruct=NULL;
struct ifaddrs * ifa=NULL;
@ -44,6 +50,7 @@ std::string get_local_ip_address() {
throw std::runtime_error(QWidget::tr("Could not find any usable local IP address. If you beleive that this is problem with the program, please, contact the developer.").toStdString());
}
#endif
std::string to_utf8(std::wstring wide_string) {
static std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_conv;
@ -114,7 +121,7 @@ std::wstring substring_from_to(std::wstring& text, std::wstring from, std::wstri
return substring;
}
#ifdef BUILD_OFD_MODE
std::wstring trim_html_response(std::wstring& check) {
std::wstring begin_check_marker = from_utf8("<!-- Products -->");
std::wstring end_check_marker = from_utf8("<!-- \\/Products -->");
@ -219,7 +226,9 @@ Check parseOfdRuAnswer(std::string html) {
return c;
}
#endif // ifdef BUILD_OFD_MODE
#ifdef BUILD_OFD_BINARYEYE_SCAN
void generate_qr_code(std::string data) {
QRcode *qrCode = QRcode_encodeString(data.c_str(), 2, QR_ECLEVEL_L, QR_MODE_8, 1);
if (qrCode == NULL) {
@ -244,3 +253,4 @@ void generate_qr_code(std::string data) {
cv::imwrite(get_path_relative_to_home(".local/share/checks_parser/binaryeye_connection.png"), qrCodeImage);
QRcode_free(qrCode);
}
#endif // ifdef BUILD_OFD_BINARYEYE_SCAN

View File

@ -5,7 +5,6 @@
#include <vector>
#include "../check/check.h"
std::string get_local_ip_address();
std::string to_utf8(std::wstring wide_string);
std::wstring from_utf8(std::string string);
@ -16,10 +15,15 @@ bool vector_contains_element(const std::vector<T> &vector, const T &to_find);
std::vector<std::string> split(std::string, std::string);
#ifdef BUILD_OFD_MODULE
Check parseOfdRuAnswer(std::string);
std::wstring trim_html_response(std::wstring& check);
#endif
#ifdef BUILD_OFD_BINARYEYE_SCAN
void generate_qr_code(std::string data);
std::string get_local_ip_address();
#endif
#endif // UTILS_H