-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSettingClass.cpp
115 lines (108 loc) · 4.98 KB
/
SettingClass.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "stdafx.h"
#include "SettingClass.h"
#include "AzureSpeechAPI.h"
#include <QCloseEvent>
#include "DatabaseAPIClass.h"
SettingClass::SettingClass(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
this->setWindowTitle("Setting");
AzureSpeechAPI *API = API->getInstance();
key = QString::fromStdString(API->getKey());
region = QString::fromStdString(API->getRegion());
std::map<std::string, language> supportedLanguages = API->getSupportedLanguage();
ui.APIKeyInput->setText(key);
ui.APIRegionInput->setText(region);
std::vector<std::string> vec;
for (auto& index : supportedLanguages) {
QString languageName = QString::fromStdString(index.first);
ui.detectionLanguageComboBox->addItem(languageName);
if (std::find(vec.begin(), vec.end(), index.second.name) == vec.end()){
vec.push_back(index.second.name);
ui.translationLanguageComboBox->addItem(QString::fromStdString(index.second.name));
}
detectionLanguage = (index.second.recognitionCode == API->getDetectionLanguageCode()) ? QString::fromStdString(index.first) : detectionLanguage;
translationLanguage = (index.second.translationCode == API->getTranslationLanguageCode()) ? QString::fromStdString(index.second.name) : translationLanguage;
}
ui.detectionLanguageComboBox->setCurrentText(detectionLanguage);
ui.translationLanguageComboBox->setCurrentText(translationLanguage);
/*recordState = API->getSavingResultState();
ui.saveRecordCheckBox->setChecked(recordState);*/
engineMode = API->getEngineMode();
ui.engineModeComboBox->setCurrentIndex(engineMode);
if (engineMode == 0) {
ui.translationLanguageComboBox->setEnabled(false);
ui.showSingleLanguageCheckBox->setEnabled(false);
}
showSingleLanguage = API->getShowSingleLanguage();
ui.showSingleLanguageCheckBox->setChecked(showSingleLanguage);
connect(ui.APIKeyInput, SIGNAL(textChanged(QString)), this, SLOT(checkInputChanges()));
connect(ui.APIRegionInput, SIGNAL(textChanged(QString)), this, SLOT(checkInputChanges()));
connect(ui.detectionLanguageComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(checkInputChanges()));
connect(ui.translationLanguageComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(checkInputChanges()));
//connect(ui.saveRecordCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkInputChanges()));
connect(ui.engineModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(checkInputChanges()));
connect(ui.showSingleLanguageCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkInputChanges()));
}
SettingClass::~SettingClass()
{}
void SettingClass::on_saveButton_clicked() {
key = ui.APIKeyInput->text();
region = ui.APIRegionInput->text();
AzureSpeechAPI* API = API->getInstance();
std::map<std::string, language> supportedLanguages = API->getSupportedLanguage();
std::string recognitionLanguageCode;
std::string translationLanguageCode;
for (auto& index : supportedLanguages) {
detectionLanguage = ui.detectionLanguageComboBox->currentText();
translationLanguage = ui.translationLanguageComboBox->currentText();
recognitionLanguageCode = (index.first == detectionLanguage.toStdString()) ? index.second.recognitionCode : recognitionLanguageCode;
translationLanguageCode = (index.second.name == translationLanguage.toStdString()) ? index.second.translationCode : translationLanguageCode;
}
//recordState = ui.saveRecordCheckBox->isChecked();
recordState = false;
std::string recordStateStr = (recordState) ? "1" : "0";
engineMode = ui.engineModeComboBox->currentIndex();
showSingleLanguage = ui.showSingleLanguageCheckBox->isChecked();
std::string singleLanguageStateStr = (showSingleLanguage) ? "1" : "0";
DatabaseAPI* dbAPI = new DatabaseAPI();
dbAPI->save_engine_state(key.toStdString(), region.toStdString(), recognitionLanguageCode, translationLanguageCode, recordStateStr,to_string(engineMode),singleLanguageStateStr);
emit updateAPIConfig(key.toStdString(), region.toStdString(),recognitionLanguageCode,translationLanguageCode, recordState, engineMode, showSingleLanguage);
QMessageBox::information(this, "Save Setting", "The setting has been saved.");
this->hide();
}
void SettingClass::closeEvent(QCloseEvent* event) {
this->hide();
}
void SettingClass::updateEngineMode(int mode)
{
ui.engineModeComboBox->setCurrentIndex(mode);
}
void SettingClass::checkInputChanges()
{
if (ui.APIKeyInput->text() != key ||
ui.APIRegionInput->text() != region ||
ui.detectionLanguageComboBox->currentText() != detectionLanguage ||
ui.translationLanguageComboBox->currentText() != translationLanguage ||
ui.engineModeComboBox->currentIndex() != engineMode ||
ui.showSingleLanguageCheckBox->isChecked() != showSingleLanguage
)
{
ui.saveButton -> setEnabled(true);
}
else {
ui.saveButton->setEnabled(false);
}
}
void SettingClass::on_engineModeComboBox_currentIndexChanged(int mode)
{
if (mode == 0) {
ui.translationLanguageComboBox->setEnabled(false);
ui.showSingleLanguageCheckBox->setEnabled(false);
}
if (mode == 1) {
ui.translationLanguageComboBox->setEnabled(true);
ui.showSingleLanguageCheckBox->setEnabled(true);
}
}