Compare commits

..

No commits in common. "f507ec8d67bff2f2e63db8fff42f6a94bd06557c" and "39c4bfb2fdacc9ceb1813bfc516950fbcaeebe8e" have entirely different histories.

5 changed files with 30 additions and 88 deletions

View File

@ -33,7 +33,6 @@ static QWidget *loadUI(QWidget *parent, std::string filename) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
srand(time(0));
QApplication app(argc, argv); QApplication app(argc, argv);
@ -93,6 +92,10 @@ int main(int argc, char *argv[]) {
OCRScene *ocrscene = new OCRScene(); OCRScene *ocrscene = new OCRScene();
OFDScene *ofdscene = new OFDScene(); OFDScene *ofdscene = new OFDScene();
// ofdscene->startHttpServer();
// get_local_ip_address();
sceneLayout->addWidget(mainwindowscene); sceneLayout->addWidget(mainwindowscene);
sceneLayout->addWidget(emailTextScene); sceneLayout->addWidget(emailTextScene);
sceneLayout->addWidget(ocrscene); sceneLayout->addWidget(ocrscene);

View File

@ -17,8 +17,6 @@ OFDScene::OFDScene(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::OFDScene) { , ui(new Ui::OFDScene) {
ui->setupUi(this); ui->setupUi(this);
QObject::connect(this, &OFDScene::httpErrorOccured, this, &OFDScene::notifyHttpServerFailure);
} }
OFDScene::~OFDScene() { OFDScene::~OFDScene() {
@ -27,7 +25,6 @@ OFDScene::~OFDScene() {
void OFDScene::startHttpServer() { void OFDScene::startHttpServer() {
std::string localIp = ""; std::string localIp = "";
try { try {
localIp = get_local_ip_address(); localIp = get_local_ip_address();
} catch(std::exception e) { } catch(std::exception e) {
@ -35,29 +32,13 @@ void OFDScene::startHttpServer() {
return; return;
} }
unsigned short number_of_retries = 0; httplib::Server svr;
//TODO: generate random port from 1024 to 65535 and check if its used.
svr.Get("/", [&](const httplib::Request &, httplib::Response &res){
res.set_redirect("http://"+ localIp +":8080/", 301);
});
do { svr.listen("0.0.0.0", 8080);
if (number_of_retries == 10) {
emit httpErrorOccured();
return;
}
this->port = rand() % (65535 - 1024) + 1024;
httplib::Server svr;
svr.Get("/", [&](const httplib::Request &, httplib::Response &res){
res.set_redirect("http://"+ localIp +":"+ std::to_string(port) +"/", 301);
});
number_of_retries ++;
std::cerr << "Listening on port: " << this->port << std::endl;
if (!svr.listen("0.0.0.0", this->port)) {
std::cerr << "Random port seems to be occupied. Trying to generate another one" << std::endl;
number_of_retries ++;
continue;
}
} while(true);
} }
void OFDScene::on_choose_image_button_clicked() { void OFDScene::on_choose_image_button_clicked() {
@ -72,6 +53,7 @@ void OFDScene::on_choose_image_button_clicked() {
return; return;
} }
ui->info_label->setText(tr("Selected image: ") + filename); ui->info_label->setText(tr("Selected image: ") + filename);
AdjustPictureDialog dialog = AdjustPictureDialog(this, filename.toStdString()); AdjustPictureDialog dialog = AdjustPictureDialog(this, filename.toStdString());
@ -163,19 +145,6 @@ void OFDScene::on_parse_button_clicked() {
void OFDScene::on_binary_eye_button_clicked() { void OFDScene::on_binary_eye_button_clicked() {
http_thread = new std::thread(&OFDScene::startHttpServer, this);
}
void OFDScene::notifyHttpServerFailure() {
QMessageBox *infoDialog = new QMessageBox();
infoDialog->setText(tr("Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn't lucky, please, contact the developer."));
infoDialog->setIcon(QMessageBox::Warning);
infoDialog->setWindowTitle(tr("Could not start http server."));
infoDialog->exec();
delete infoDialog;
}
unsigned int OFDScene::getPort() {
return port;
} }

View File

@ -2,7 +2,6 @@
#define OFDSCENE_H #define OFDSCENE_H
#include <QWidget> #include <QWidget>
#include <thread>
namespace Ui { namespace Ui {
class OFDScene; class OFDScene;
@ -16,8 +15,6 @@ public:
explicit OFDScene(QWidget *parent = nullptr); explicit OFDScene(QWidget *parent = nullptr);
~OFDScene(); ~OFDScene();
void startHttpServer(); void startHttpServer();
unsigned int getPort();
private slots: private slots:
void on_choose_image_button_clicked(); void on_choose_image_button_clicked();
void onDataDecode(std::string data); void onDataDecode(std::string data);
@ -25,16 +22,9 @@ private slots:
void on_parse_button_clicked(); void on_parse_button_clicked();
void on_binary_eye_button_clicked(); void on_binary_eye_button_clicked();
void notifyHttpServerFailure();
signals:
void httpErrorOccured();
private: private:
Ui::OFDScene *ui; Ui::OFDScene *ui;
std::thread *http_thread;
unsigned int port;
}; };
#endif // OFDSCENE_H #endif // OFDSCENE_H

View File

@ -367,57 +367,47 @@
<translation>Parse</translation> <translation>Parse</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="178"/> <location filename="../ofdscene.cpp" line="49"/>
<source>Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn&apos;t lucky, please, contact the developer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ofdscene.cpp" line="180"/>
<source>Could not start http server.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ofdscene.cpp" line="72"/>
<source>Please, select a picture where QR code that contains info about check is present</source> <source>Please, select a picture where QR code that contains info about check is present</source>
<translation>Please, select a picture where QR code that contains info about check is present</translation> <translation>Please, select a picture where QR code that contains info about check is present</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="74"/> <location filename="../ofdscene.cpp" line="51"/>
<source>Picture was not selected</source> <source>Picture was not selected</source>
<translation>Picture was not selected</translation> <translation>Picture was not selected</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="80"/> <location filename="../ofdscene.cpp" line="57"/>
<source>Selected image: </source> <source>Selected image: </source>
<translation>Selected image: </translation> <translation>Selected image: </translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="139"/> <location filename="../ofdscene.cpp" line="116"/>
<source>Captcha was not solved correctly!</source> <source>Captcha was not solved correctly!</source>
<translation>Captcha was not solved correctly!</translation> <translation>Captcha was not solved correctly!</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="141"/> <location filename="../ofdscene.cpp" line="118"/>
<source>Captcha is incorrect</source> <source>Captcha is incorrect</source>
<translation>Captcha is incorrect</translation> <translation>Captcha is incorrect</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="146"/> <location filename="../ofdscene.cpp" line="123"/>
<source>Internal server error. Please, try again later.</source> <source>Internal server error. Please, try again later.</source>
<translation>Internal server error. Please, try again later.</translation> <translation>Internal server error. Please, try again later.</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="148"/> <location filename="../ofdscene.cpp" line="125"/>
<source>Internal server error</source> <source>Internal server error</source>
<translation>Internal server error</translation> <translation>Internal server error</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="153"/> <location filename="../ofdscene.cpp" line="130"/>
<source>Check not found. Please, ensure correctness of entered data.</source> <source>Check not found. Please, ensure correctness of entered data.</source>
<translation>Check not found. Please, ensure correctness of entered data.</translation> <translation>Check not found. Please, ensure correctness of entered data.</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="155"/> <location filename="../ofdscene.cpp" line="132"/>
<source>Check was not found</source> <source>Check was not found</source>
<translation>Check was not found</translation> <translation>Check was not found</translation>
</message> </message>

View File

@ -367,57 +367,47 @@
<translation>Парсить</translation> <translation>Парсить</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="178"/> <location filename="../ofdscene.cpp" line="49"/>
<source>Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn&apos;t lucky, please, contact the developer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ofdscene.cpp" line="180"/>
<source>Could not start http server.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ofdscene.cpp" line="72"/>
<source>Please, select a picture where QR code that contains info about check is present</source> <source>Please, select a picture where QR code that contains info about check is present</source>
<translation>Пожалуйста, выберете изображение, содержащее QR код с информацией о чеке</translation> <translation>Пожалуйста, выберете изображение, содержащее QR код с информацией о чеке</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="74"/> <location filename="../ofdscene.cpp" line="51"/>
<source>Picture was not selected</source> <source>Picture was not selected</source>
<translation>Изображение не было выбрано</translation> <translation>Изображение не было выбрано</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="80"/> <location filename="../ofdscene.cpp" line="57"/>
<source>Selected image: </source> <source>Selected image: </source>
<translation>Выбранное изображение: </translation> <translation>Выбранное изображение: </translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="139"/> <location filename="../ofdscene.cpp" line="116"/>
<source>Captcha was not solved correctly!</source> <source>Captcha was not solved correctly!</source>
<translation>Капча была решена неверно!</translation> <translation>Капча была решена неверно!</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="141"/> <location filename="../ofdscene.cpp" line="118"/>
<source>Captcha is incorrect</source> <source>Captcha is incorrect</source>
<translation>Капча введена неверно</translation> <translation>Капча введена неверно</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="146"/> <location filename="../ofdscene.cpp" line="123"/>
<source>Internal server error. Please, try again later.</source> <source>Internal server error. Please, try again later.</source>
<translation>Внутренняя ошибка сервера. Пожалуйста, попробуйте снова позже.</translation> <translation>Внутренняя ошибка сервера. Пожалуйста, попробуйте снова позже.</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="148"/> <location filename="../ofdscene.cpp" line="125"/>
<source>Internal server error</source> <source>Internal server error</source>
<translation>Внутренняя ошибка сервера</translation> <translation>Внутренняя ошибка сервера</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="153"/> <location filename="../ofdscene.cpp" line="130"/>
<source>Check not found. Please, ensure correctness of entered data.</source> <source>Check not found. Please, ensure correctness of entered data.</source>
<translation>Чек не найден. Пожалуйста, убедитесь в правильности введённых данных.</translation> <translation>Чек не найден. Пожалуйста, убедитесь в правильности введённых данных.</translation>
</message> </message>
<message> <message>
<location filename="../ofdscene.cpp" line="155"/> <location filename="../ofdscene.cpp" line="132"/>
<source>Check was not found</source> <source>Check was not found</source>
<translation>Чек не найден</translation> <translation>Чек не найден</translation>
</message> </message>