-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
76 lines (63 loc) · 3.16 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QScrollBar>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
settings.beginGroup("pathes");
ui->nllbInferencePath->setText(settings.value("nllbInferencePath", "").toString());
ui->modelPath->setText(settings.value("modelPath", "").toString());
settings.endGroup();
settings.beginGroup("languages");
ui->sourceLanguage->setCurrentIndex(settings.value("sourceLanguage", 0).toInt());
ui->targetLanguage->setCurrentIndex(settings.value("targetLanguage", 0).toInt());
settings.endGroup();
settings.beginGroup("lastRun");
ui->source->setPlainText(settings.value("sourceText", "").toString());
ui->target->setPlainText(settings.value("targetText", "").toString());
settings.endGroup();
}
MainWindow::~MainWindow()
{
settings.beginGroup("pathes");
settings.setValue("nllbInferencePath", ui->nllbInferencePath->text());
settings.setValue("modelPath", ui->modelPath->text());
settings.endGroup();
settings.beginGroup("languages");
settings.setValue("targetLanguage", ui->targetLanguage->currentIndex());
settings.setValue("sourceLanguage", ui->sourceLanguage->currentIndex());
settings.endGroup();
settings.beginGroup("lastRun");
settings.setValue("sourceText", ui->source->toPlainText());
settings.setValue("targetText", ui->target->toPlainText());
settings.endGroup();
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString formatedSource = ui->source->toPlainText().toUtf8().toBase64(); // because of quotes and other symbols
//QString comand = "bash "+ui->nllbInferencePath->text()+" "+ui->modelPath->text()+" "+languages[ui->sourceLanguage->currentText()]+" "+languages[ui->targetLanguage->currentText()]+" <<< '"+formatedSource+"'";
QString comand = "bash "+ui->nllbInferencePath->text()+" "+ui->modelPath->text()+" "+languages[ui->sourceLanguage->currentText()]+" "+languages[ui->targetLanguage->currentText()]+" <<< `echo '"+formatedSource+"' | base64 --decode`";
ui->target->setPlainText("sh -c "+comand+"\n");
ui->target->verticalScrollBar()->setValue(ui->target->verticalScrollBar()->maximum());
c_output = new QProcess(this);
connect(c_output, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()));
connect(c_output, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()));
c_output->start("sh", QStringList() << "-c" << comand);
}
void MainWindow::processOutput(){
ui->target->setPlainText(ui->target->toPlainText()+c_output->readAllStandardOutput());
ui->target->setPlainText(ui->target->toPlainText()+c_output->readAllStandardError());
ui->target->verticalScrollBar()->setValue(ui->target->verticalScrollBar()->maximum());
}
void MainWindow::on_pushButton_3_clicked()
{
ui->modelPath->setText(QFileDialog::getOpenFileName(this, "Open nllb model", QString(), "Checkpoint file (*.pt)"));
}
void MainWindow::on_pushButton_2_clicked()
{
ui->nllbInferencePath->setText(QFileDialog::getOpenFileName(this, "Open nllb-inference script file", QString(), "Script file (translate.sh)"));
}