basic email parsing
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
#ifdef BUILD_OFD_LOCAL_QR_SCAN
|
||||
# include <adjustpicturedialog.h>
|
||||
#include <checkqueuetablemodel.h>
|
||||
# include <checkqueuetablemodel.h>
|
||||
#endif
|
||||
|
||||
#include <outputdialog.h>
|
||||
@@ -26,6 +26,7 @@
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
#include <email_parser/emailparser.h>
|
||||
#endif
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
@@ -49,6 +50,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
#ifdef BUILD_OFD_BINARYEYE_SCAN
|
||||
QObject::connect(this, &MainWindow::httpErrorOccured, this, &MainWindow::notifyHttpServerFailure);
|
||||
connect(this, SIGNAL(httpNewMessage(QString)), this, SLOT(httpNewMessageHandler(QString)));
|
||||
#else
|
||||
ui->or_label_2->hide();
|
||||
ui->binary_eye_button->hide();
|
||||
#endif
|
||||
|
||||
#ifndef BUILD_EMAIL_MODE
|
||||
@@ -56,10 +60,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
ui->or_label_2->hide();
|
||||
#endif
|
||||
|
||||
#ifndef BUILD_OFD_BINARYEYE_SCAN
|
||||
ui->or_label_2->hide();
|
||||
ui->binary_eye_button->hide();
|
||||
#endif
|
||||
#ifndef BUILD_OFD_LOCAL_QR_SCAN
|
||||
ui->or_label_1->hide();
|
||||
ui->choose_image_button->hide();
|
||||
@@ -127,19 +127,7 @@ void MainWindow::httpNewMessageHandler(QString message) {
|
||||
|
||||
//erase /?result= from the string
|
||||
parametersString.erase(0, parametersString.find("=") + 1);
|
||||
//TODO: punycode %26 %3D
|
||||
parametersString = boost::regex_replace(parametersString, boost::regex("%26"), "&");
|
||||
parametersString = boost::regex_replace(parametersString, boost::regex("%3D"), "=");
|
||||
|
||||
std::vector<std::string> parameters = split(parametersString, "&");
|
||||
|
||||
std::map<std::string, std::string> paramsMap;
|
||||
|
||||
for (auto ¶meter : parameters) {
|
||||
std::vector<std::string> values = split(parameter, "=");
|
||||
paramsMap.insert(std::pair<std::string, std::string> (values[0], values[1]));
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> paramsMap = get_params_from_string(parametersString);
|
||||
emit onDataDecode(paramsMap);
|
||||
}
|
||||
|
||||
@@ -167,35 +155,33 @@ void MainWindow::on_choose_image_button_clicked() {
|
||||
#endif //ifdef BUILD_OFD_LOCAL_QR_SCAN
|
||||
|
||||
void MainWindow::onDataDecode(std::map<std::string, std::string> data) {
|
||||
ui->fn_line_edit->setText(QString::fromStdString(data["fn"]));
|
||||
ui->fd_line_edit->setText(QString::fromStdString(data["i"]));
|
||||
ui->fi_line_edit->setText(QString::fromStdString(data["fp"]));
|
||||
|
||||
QString extractedDateTime = QString::fromStdString(data["t"]);
|
||||
//TODO: some QRs contain datetime in format yyyyMMddThhmmss. Perhaps there is more different formats, should write function to detect them.
|
||||
QDateTime datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmm");
|
||||
if (datetime == QDateTime::fromString(extractedDateTime, "20000101T1200")) {
|
||||
datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmmss");
|
||||
}
|
||||
ui->purchase_datetime_edit->setDateTime(datetime);
|
||||
|
||||
int type = std::stoi(data["n"]);
|
||||
ui->operation_type_combo_box->setCurrentIndex(type - 1);
|
||||
|
||||
std::string total = data["s"];
|
||||
|
||||
ui->total_spin_box->setValue(std::stod(total));
|
||||
set_check_params(data);
|
||||
}
|
||||
|
||||
#ifdef BUILD_EMAIL_MODE
|
||||
|
||||
void MainWindow::on_parse_email_button_clicked() {
|
||||
QMessageBox infoDialog;
|
||||
infoDialog.setText(tr("This feature is under development. Wait it to appear in next updates."));
|
||||
infoDialog.setIcon(QMessageBox::Warning);
|
||||
infoDialog.setWindowTitle(tr("Under development"));
|
||||
infoDialog.exec();
|
||||
return;
|
||||
QString filename = QFileDialog::getOpenFileName();
|
||||
|
||||
if (filename == "") {
|
||||
QMessageBox infoDialog;
|
||||
infoDialog.setText(tr("Please, select an e-mail which contains QR code"));
|
||||
infoDialog.setIcon(QMessageBox::Critical);
|
||||
infoDialog.setWindowTitle(tr("E-Mail was not selected"));
|
||||
infoDialog.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
EmailParser email_parser;
|
||||
std::map<std::string, std::string> paramsMap = email_parser.parse_file(filename.toStdString());
|
||||
|
||||
set_check_params(paramsMap);
|
||||
// QMessageBox infoDialog;
|
||||
// infoDialog.setText(tr("This feature is under development. Wait it to appear in next updates."));
|
||||
// infoDialog.setIcon(QMessageBox::Warning);
|
||||
// infoDialog.setWindowTitle(tr("Under development"));
|
||||
// infoDialog.exec();
|
||||
// return;
|
||||
}
|
||||
|
||||
#endif // ifdef BUILD_EMAIL_MODE
|
||||
@@ -270,22 +256,21 @@ Check *MainWindow::parse_new_check() {
|
||||
|
||||
return check;
|
||||
} catch(OfdRequestException e) {
|
||||
QMessageBox infoDialog;
|
||||
if (!strcmp(e.what(), "Incorrect captcha")) {
|
||||
QMessageBox infoDialog;
|
||||
|
||||
infoDialog.setText(tr("Captcha was not solved correctly!"));
|
||||
infoDialog.setIcon(QMessageBox::Critical);
|
||||
infoDialog.setWindowTitle(tr("Captcha is incorrect"));
|
||||
infoDialog.exec();
|
||||
continue;
|
||||
} else if (!strcmp(e.what(), "Internal server error")) {
|
||||
QMessageBox infoDialog;
|
||||
infoDialog.setText(tr("Internal server error. Please, try again later."));
|
||||
infoDialog.setIcon(QMessageBox::Critical);
|
||||
infoDialog.setWindowTitle(tr("Internal server error"));
|
||||
infoDialog.exec();
|
||||
return nullptr;
|
||||
} else if (!strcmp(e.what(), "Does not exist")) {
|
||||
QMessageBox infoDialog;
|
||||
infoDialog.setText(tr("Check not found. Please, ensure correctness of entered data."));
|
||||
infoDialog.setIcon(QMessageBox::Critical);
|
||||
infoDialog.setWindowTitle(tr("Check was not found"));
|
||||
@@ -316,3 +301,24 @@ void MainWindow::on_deleteSelectedButton_clicked() {
|
||||
ui->checkQueueTable->clearSelection();
|
||||
}
|
||||
|
||||
void MainWindow::set_check_params(std::map<std::string, std::string> paramsMap) {
|
||||
ui->fn_line_edit->setText(QString::fromStdString(paramsMap["fn"]));
|
||||
ui->fd_line_edit->setText(QString::fromStdString(paramsMap["i"]));
|
||||
ui->fi_line_edit->setText(QString::fromStdString(paramsMap["fp"]));
|
||||
|
||||
QString extractedDateTime = QString::fromStdString(paramsMap["t"]);
|
||||
//TODO: some QRs contain datetime in format yyyyMMddThhmmss. Perhaps there is more different formats, should write function to detect them.
|
||||
QDateTime datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmm");
|
||||
if (datetime == QDateTime::fromString(extractedDateTime, "20000101T1200")) {
|
||||
datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmmss");
|
||||
}
|
||||
ui->purchase_datetime_edit->setDateTime(datetime);
|
||||
|
||||
int type = std::stoi(paramsMap["n"]);
|
||||
ui->operation_type_combo_box->setCurrentIndex(type - 1);
|
||||
|
||||
std::string total = paramsMap["s"];
|
||||
|
||||
ui->total_spin_box->setValue(std::stod(total));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user