summaryrefslogtreecommitdiff
path: root/indra/newview/llfloatertranslationsettings.cpp
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2023-07-17 23:34:59 +0300
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2023-07-17 23:34:59 +0300
commitacf82867b61535b7b39b89f71a282e3ce3d0673e (patch)
tree2795aa7a92d291d5535d935ab0782cfdf6ec45e4 /indra/newview/llfloatertranslationsettings.cpp
parentd3233e787aaf1ba0558a714d5216ea70c7249c36 (diff)
parentec4135da63a3f3877222fba4ecb59b15650371fe (diff)
Merge branch 'main' (DRTVWR-580) into DRTVWR-567
# Conflicts: # indra/llui/llfolderviewitem.cpp # indra/newview/llinventorymodel.cpp # indra/newview/llinventorymodelbackgroundfetch.cpp
Diffstat (limited to 'indra/newview/llfloatertranslationsettings.cpp')
-rw-r--r--indra/newview/llfloatertranslationsettings.cpp248
1 files changed, 189 insertions, 59 deletions
diff --git a/indra/newview/llfloatertranslationsettings.cpp b/indra/newview/llfloatertranslationsettings.cpp
index 082bb888b1..d29ecbbf95 100644
--- a/indra/newview/llfloatertranslationsettings.cpp
+++ b/indra/newview/llfloatertranslationsettings.cpp
@@ -45,15 +45,9 @@
LLFloaterTranslationSettings::LLFloaterTranslationSettings(const LLSD& key)
: LLFloater(key)
, mMachineTranslationCB(NULL)
-, mLanguageCombo(NULL)
-, mTranslationServiceRadioGroup(NULL)
-, mBingAPIKeyEditor(NULL)
-, mGoogleAPIKeyEditor(NULL)
-, mBingVerifyBtn(NULL)
-, mGoogleVerifyBtn(NULL)
-, mOKBtn(NULL)
-, mBingKeyVerified(false)
+, mAzureKeyVerified(false)
, mGoogleKeyVerified(false)
+, mDeepLKeyVerified(false)
{
}
@@ -63,24 +57,54 @@ BOOL LLFloaterTranslationSettings::postBuild()
mMachineTranslationCB = getChild<LLCheckBoxCtrl>("translate_chat_checkbox");
mLanguageCombo = getChild<LLComboBox>("translate_language_combo");
mTranslationServiceRadioGroup = getChild<LLRadioGroup>("translation_service_rg");
- mBingAPIKeyEditor = getChild<LLLineEditor>("bing_api_key");
+ mAzureAPIEndpointEditor = getChild<LLComboBox>("azure_api_endpoint_combo");
+ mAzureAPIKeyEditor = getChild<LLLineEditor>("azure_api_key");
+ mAzureAPIRegionEditor = getChild<LLLineEditor>("azure_api_region");
mGoogleAPIKeyEditor = getChild<LLLineEditor>("google_api_key");
- mBingVerifyBtn = getChild<LLButton>("verify_bing_api_key_btn");
+ mDeepLAPIDomainCombo = getChild<LLComboBox>("deepl_api_domain_combo");
+ mDeepLAPIKeyEditor = getChild<LLLineEditor>("deepl_api_key");
+ mAzureVerifyBtn = getChild<LLButton>("verify_azure_api_key_btn");
mGoogleVerifyBtn = getChild<LLButton>("verify_google_api_key_btn");
+ mDeepLVerifyBtn = getChild<LLButton>("verify_deepl_api_key_btn");
mOKBtn = getChild<LLButton>("ok_btn");
mMachineTranslationCB->setCommitCallback(boost::bind(&LLFloaterTranslationSettings::updateControlsEnabledState, this));
mTranslationServiceRadioGroup->setCommitCallback(boost::bind(&LLFloaterTranslationSettings::updateControlsEnabledState, this));
mOKBtn->setClickedCallback(boost::bind(&LLFloaterTranslationSettings::onBtnOK, this));
getChild<LLButton>("cancel_btn")->setClickedCallback(boost::bind(&LLFloater::closeFloater, this, false));
- mBingVerifyBtn->setClickedCallback(boost::bind(&LLFloaterTranslationSettings::onBtnBingVerify, this));
+ mAzureVerifyBtn->setClickedCallback(boost::bind(&LLFloaterTranslationSettings::onBtnAzureVerify, this));
mGoogleVerifyBtn->setClickedCallback(boost::bind(&LLFloaterTranslationSettings::onBtnGoogleVerify, this));
+ mDeepLVerifyBtn->setClickedCallback(boost::bind(&LLFloaterTranslationSettings::onBtnDeepLVerify, this));
+
+ mAzureAPIKeyEditor->setFocusReceivedCallback(boost::bind(&LLFloaterTranslationSettings::onEditorFocused, this, _1));
+ mAzureAPIKeyEditor->setKeystrokeCallback(boost::bind(&LLFloaterTranslationSettings::onAzureKeyEdited, this), NULL);
+ mAzureAPIRegionEditor->setFocusReceivedCallback(boost::bind(&LLFloaterTranslationSettings::onEditorFocused, this, _1));
+ mAzureAPIRegionEditor->setKeystrokeCallback(boost::bind(&LLFloaterTranslationSettings::onAzureKeyEdited, this), NULL);
+
+ mAzureAPIEndpointEditor->setFocusLostCallback([this](LLFocusableElement*)
+ {
+ setAzureVerified(false, false, 0);
+ });
+ mAzureAPIEndpointEditor->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param)
+ {
+ setAzureVerified(false, false, 0);
+ });
- mBingAPIKeyEditor->setFocusReceivedCallback(boost::bind(&LLFloaterTranslationSettings::onEditorFocused, this, _1));
- mBingAPIKeyEditor->setKeystrokeCallback(boost::bind(&LLFloaterTranslationSettings::onBingKeyEdited, this), NULL);
mGoogleAPIKeyEditor->setFocusReceivedCallback(boost::bind(&LLFloaterTranslationSettings::onEditorFocused, this, _1));
mGoogleAPIKeyEditor->setKeystrokeCallback(boost::bind(&LLFloaterTranslationSettings::onGoogleKeyEdited, this), NULL);
+ mDeepLAPIKeyEditor->setFocusReceivedCallback(boost::bind(&LLFloaterTranslationSettings::onEditorFocused, this, _1));
+ mDeepLAPIKeyEditor->setKeystrokeCallback(boost::bind(&LLFloaterTranslationSettings::onDeepLKeyEdited, this), NULL);
+
+ mDeepLAPIDomainCombo->setFocusLostCallback([this](LLFocusableElement*)
+ {
+ setDeepLVerified(false, false, 0);
+ });
+ mDeepLAPIDomainCombo->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param)
+ {
+ setDeepLVerified(false, false, 0);
+ });
+
center();
return TRUE;
}
@@ -92,17 +116,28 @@ void LLFloaterTranslationSettings::onOpen(const LLSD& key)
mLanguageCombo->setSelectedByValue(gSavedSettings.getString("TranslateLanguage"), TRUE);
mTranslationServiceRadioGroup->setSelectedByValue(gSavedSettings.getString("TranslationService"), TRUE);
- std::string bing_key = gSavedSettings.getString("BingTranslateAPIKey");
- if (!bing_key.empty())
+ LLSD azure_key = gSavedSettings.getLLSD("AzureTranslateAPIKey");
+ if (azure_key.isMap() && !azure_key["id"].asString().empty())
{
- mBingAPIKeyEditor->setText(bing_key);
- mBingAPIKeyEditor->setTentative(FALSE);
- verifyKey(LLTranslate::SERVICE_BING, bing_key, false);
+ mAzureAPIKeyEditor->setText(azure_key["id"].asString());
+ mAzureAPIKeyEditor->setTentative(false);
+ if (azure_key.has("region") && !azure_key["region"].asString().empty())
+ {
+ mAzureAPIRegionEditor->setText(azure_key["region"].asString());
+ mAzureAPIRegionEditor->setTentative(false);
+ }
+ else
+ {
+ mAzureAPIRegionEditor->setTentative(true);
+ }
+ mAzureAPIEndpointEditor->setValue(azure_key["endpoint"]);
+ verifyKey(LLTranslate::SERVICE_AZURE, azure_key, false);
}
else
{
- mBingAPIKeyEditor->setTentative(TRUE);
- mBingKeyVerified = FALSE;
+ mAzureAPIKeyEditor->setTentative(TRUE);
+ mAzureAPIRegionEditor->setTentative(true);
+ mAzureKeyVerified = FALSE;
}
std::string google_key = gSavedSettings.getString("GoogleTranslateAPIKey");
@@ -118,39 +153,74 @@ void LLFloaterTranslationSettings::onOpen(const LLSD& key)
mGoogleKeyVerified = FALSE;
}
+ LLSD deepl_key = gSavedSettings.getLLSD("DeepLTranslateAPIKey");
+ if (deepl_key.isMap() && !deepl_key["id"].asString().empty())
+ {
+ mDeepLAPIKeyEditor->setText(deepl_key["id"].asString());
+ mDeepLAPIKeyEditor->setTentative(false);
+ mDeepLAPIDomainCombo->setValue(deepl_key["domain"]);
+ verifyKey(LLTranslate::SERVICE_DEEPL, deepl_key, false);
+ }
+ else
+ {
+ mDeepLAPIKeyEditor->setTentative(TRUE);
+ mDeepLKeyVerified = FALSE;
+ }
+
updateControlsEnabledState();
}
-void LLFloaterTranslationSettings::setBingVerified(bool ok, bool alert)
+void LLFloaterTranslationSettings::setAzureVerified(bool ok, bool alert, S32 status)
{
if (alert)
{
- showAlert(ok ? "bing_api_key_verified" : "bing_api_key_not_verified");
+ showAlert(ok ? "azure_api_key_verified" : "azure_api_key_not_verified", status);
}
- mBingKeyVerified = ok;
+ mAzureKeyVerified = ok;
updateControlsEnabledState();
}
-void LLFloaterTranslationSettings::setGoogleVerified(bool ok, bool alert)
+void LLFloaterTranslationSettings::setGoogleVerified(bool ok, bool alert, S32 status)
{
if (alert)
{
- showAlert(ok ? "google_api_key_verified" : "google_api_key_not_verified");
+ showAlert(ok ? "google_api_key_verified" : "google_api_key_not_verified", status);
}
mGoogleKeyVerified = ok;
updateControlsEnabledState();
}
+void LLFloaterTranslationSettings::setDeepLVerified(bool ok, bool alert, S32 status)
+{
+ if (alert)
+ {
+ showAlert(ok ? "deepl_api_key_verified" : "deepl_api_key_not_verified", status);
+ }
+
+ mDeepLKeyVerified = ok;
+ updateControlsEnabledState();
+}
+
std::string LLFloaterTranslationSettings::getSelectedService() const
{
return mTranslationServiceRadioGroup->getSelectedValue().asString();
}
-std::string LLFloaterTranslationSettings::getEnteredBingKey() const
+LLSD LLFloaterTranslationSettings::getEnteredAzureKey() const
{
- return mBingAPIKeyEditor->getTentative() ? LLStringUtil::null : mBingAPIKeyEditor->getText();
+ LLSD key;
+ if (!mAzureAPIKeyEditor->getTentative())
+ {
+ key["endpoint"] = mAzureAPIEndpointEditor->getValue();
+ key["id"] = mAzureAPIKeyEditor->getText();
+ if (!mAzureAPIRegionEditor->getTentative())
+ {
+ key["region"] = mAzureAPIRegionEditor->getText();
+ }
+ }
+ return key;
}
std::string LLFloaterTranslationSettings::getEnteredGoogleKey() const
@@ -158,10 +228,26 @@ std::string LLFloaterTranslationSettings::getEnteredGoogleKey() const
return mGoogleAPIKeyEditor->getTentative() ? LLStringUtil::null : mGoogleAPIKeyEditor->getText();
}
-void LLFloaterTranslationSettings::showAlert(const std::string& msg_name) const
+LLSD LLFloaterTranslationSettings::getEnteredDeepLKey() const
+{
+ LLSD key;
+ if (!mDeepLAPIKeyEditor->getTentative())
+ {
+ key["domain"] = mDeepLAPIDomainCombo->getValue();
+ key["id"] = mDeepLAPIKeyEditor->getText();
+ }
+ return key;
+}
+
+void LLFloaterTranslationSettings::showAlert(const std::string& msg_name, S32 status) const
{
+ LLStringUtil::format_map_t string_args;
+ // For now just show an http error code, whole 'reason' string might be added later
+ string_args["[STATUS]"] = llformat("%d", status);
+ std::string message = getString(msg_name, string_args);
+
LLSD args;
- args["MESSAGE"] = getString(msg_name);
+ args["MESSAGE"] = message;
LLNotificationsUtil::add("GenericAlert", args);
}
@@ -170,34 +256,51 @@ void LLFloaterTranslationSettings::updateControlsEnabledState()
// Enable/disable controls based on the checkbox value.
bool on = mMachineTranslationCB->getValue().asBoolean();
std::string service = getSelectedService();
- bool bing_selected = service == "bing";
+ bool azure_selected = service == "azure";
bool google_selected = service == "google";
+ bool deepl_selected = service == "deepl";
mTranslationServiceRadioGroup->setEnabled(on);
mLanguageCombo->setEnabled(on);
- getChild<LLTextBox>("bing_api_key_label")->setEnabled(on);
- mBingAPIKeyEditor->setEnabled(on);
+ // MS Azure
+ getChild<LLTextBox>("azure_api_endoint_label")->setEnabled(on);
+ mAzureAPIEndpointEditor->setEnabled(on && azure_selected);
+ getChild<LLTextBox>("azure_api_key_label")->setEnabled(on);
+ mAzureAPIKeyEditor->setEnabled(on && azure_selected);
+ getChild<LLTextBox>("azure_api_region_label")->setEnabled(on);
+ mAzureAPIRegionEditor->setEnabled(on && azure_selected);
- getChild<LLTextBox>("google_api_key_label")->setEnabled(on);
- mGoogleAPIKeyEditor->setEnabled(on);
+ mAzureVerifyBtn->setEnabled(on && azure_selected &&
+ !mAzureKeyVerified && getEnteredAzureKey().isMap());
- mBingAPIKeyEditor->setEnabled(on && bing_selected);
- mGoogleAPIKeyEditor->setEnabled(on && google_selected);
+ // Google
+ getChild<LLTextBox>("google_api_key_label")->setEnabled(on);
+ mGoogleAPIKeyEditor->setEnabled(on && google_selected);
- mBingVerifyBtn->setEnabled(on && bing_selected &&
- !mBingKeyVerified && !getEnteredBingKey().empty());
mGoogleVerifyBtn->setEnabled(on && google_selected &&
!mGoogleKeyVerified && !getEnteredGoogleKey().empty());
- bool service_verified = (bing_selected && mBingKeyVerified) || (google_selected && mGoogleKeyVerified);
+ // DeepL
+ getChild<LLTextBox>("deepl_api_domain_label")->setEnabled(on);
+ mDeepLAPIDomainCombo->setEnabled(on && deepl_selected);
+ getChild<LLTextBox>("deepl_api_key_label")->setEnabled(on);
+ mDeepLAPIKeyEditor->setEnabled(on && deepl_selected);
+
+ mDeepLVerifyBtn->setEnabled(on && deepl_selected &&
+ !mDeepLKeyVerified && getEnteredDeepLKey().isMap());
+
+ bool service_verified =
+ (azure_selected && mAzureKeyVerified)
+ || (google_selected && mGoogleKeyVerified)
+ || (deepl_selected && mDeepLKeyVerified);
gSavedPerAccountSettings.setBOOL("TranslatingEnabled", service_verified);
mOKBtn->setEnabled(!on || service_verified);
}
/*static*/
-void LLFloaterTranslationSettings::setVerificationStatus(int service, bool ok, bool alert)
+void LLFloaterTranslationSettings::setVerificationStatus(int service, bool ok, bool alert, S32 status)
{
LLFloaterTranslationSettings* floater =
LLFloaterReg::getTypedInstance<LLFloaterTranslationSettings>("prefs_translation");
@@ -210,20 +313,23 @@ void LLFloaterTranslationSettings::setVerificationStatus(int service, bool ok, b
switch (service)
{
- case LLTranslate::SERVICE_BING:
- floater->setBingVerified(ok, alert);
+ case LLTranslate::SERVICE_AZURE:
+ floater->setAzureVerified(ok, alert, status);
break;
case LLTranslate::SERVICE_GOOGLE:
- floater->setGoogleVerified(ok, alert);
+ floater->setGoogleVerified(ok, alert, status);
+ break;
+ case LLTranslate::SERVICE_DEEPL:
+ floater->setDeepLVerified(ok, alert, status);
break;
}
}
-void LLFloaterTranslationSettings::verifyKey(int service, const std::string& key, bool alert)
+void LLFloaterTranslationSettings::verifyKey(int service, const LLSD& key, bool alert)
{
LLTranslate::verifyKey(static_cast<LLTranslate::EService>(service), key,
- boost::bind(&LLFloaterTranslationSettings::setVerificationStatus, _1, _2, alert));
+ boost::bind(&LLFloaterTranslationSettings::setVerificationStatus, _1, _2, alert, _3));
}
void LLFloaterTranslationSettings::onEditorFocused(LLFocusableElement* control)
@@ -239,11 +345,13 @@ void LLFloaterTranslationSettings::onEditorFocused(LLFocusableElement* control)
}
}
-void LLFloaterTranslationSettings::onBingKeyEdited()
+void LLFloaterTranslationSettings::onAzureKeyEdited()
{
- if (mBingAPIKeyEditor->isDirty())
+ if (mAzureAPIKeyEditor->isDirty()
+ || mAzureAPIRegionEditor->isDirty())
{
- setBingVerified(false, false);
+ // todo: verify mAzureAPIEndpointEditor url
+ setAzureVerified(false, false, 0);
}
}
@@ -251,16 +359,24 @@ void LLFloaterTranslationSettings::onGoogleKeyEdited()
{
if (mGoogleAPIKeyEditor->isDirty())
{
- setGoogleVerified(false, false);
+ setGoogleVerified(false, false, 0);
}
}
-void LLFloaterTranslationSettings::onBtnBingVerify()
+void LLFloaterTranslationSettings::onDeepLKeyEdited()
{
- std::string key = getEnteredBingKey();
- if (!key.empty())
+ if (mDeepLAPIKeyEditor->isDirty())
+ {
+ setDeepLVerified(false, false, 0);
+ }
+}
+
+void LLFloaterTranslationSettings::onBtnAzureVerify()
+{
+ LLSD key = getEnteredAzureKey();
+ if (key.isMap())
{
- verifyKey(LLTranslate::SERVICE_BING, key);
+ verifyKey(LLTranslate::SERVICE_AZURE, key);
}
}
@@ -269,26 +385,40 @@ void LLFloaterTranslationSettings::onBtnGoogleVerify()
std::string key = getEnteredGoogleKey();
if (!key.empty())
{
- verifyKey(LLTranslate::SERVICE_GOOGLE, key);
+ verifyKey(LLTranslate::SERVICE_GOOGLE, LLSD(key));
}
}
+
+void LLFloaterTranslationSettings::onBtnDeepLVerify()
+{
+ LLSD key = getEnteredDeepLKey();
+ if (key.isMap())
+ {
+ verifyKey(LLTranslate::SERVICE_DEEPL, key);
+ }
+}
+
void LLFloaterTranslationSettings::onClose(bool app_quitting)
{
std::string service = gSavedSettings.getString("TranslationService");
- bool bing_selected = service == "bing";
+ bool azure_selected = service == "azure";
bool google_selected = service == "google";
+ bool deepl_selected = service == "deepl";
- bool service_verified = (bing_selected && mBingKeyVerified) || (google_selected && mGoogleKeyVerified);
- gSavedPerAccountSettings.setBOOL("TranslatingEnabled", service_verified);
-
+ bool service_verified =
+ (azure_selected && mAzureKeyVerified)
+ || (google_selected && mGoogleKeyVerified)
+ || (deepl_selected && mDeepLKeyVerified);
+ gSavedPerAccountSettings.setBOOL("TranslatingEnabled", service_verified);
}
void LLFloaterTranslationSettings::onBtnOK()
{
gSavedSettings.setBOOL("TranslateChat", mMachineTranslationCB->getValue().asBoolean());
gSavedSettings.setString("TranslateLanguage", mLanguageCombo->getSelectedValue().asString());
gSavedSettings.setString("TranslationService", getSelectedService());
- gSavedSettings.setString("BingTranslateAPIKey", getEnteredBingKey());
+ gSavedSettings.setLLSD("AzureTranslateAPIKey", getEnteredAzureKey());
gSavedSettings.setString("GoogleTranslateAPIKey", getEnteredGoogleKey());
+ gSavedSettings.setLLSD("DeepLTranslateAPIKey", getEnteredDeepLKey());
closeFloater(false);
}