implemented modular build for email text and ocr
This commit is contained in:
159
main.cpp
159
main.cpp
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user