summaryrefslogtreecommitdiff
path: root/indra/newview/llfloatertranslationsettings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llfloatertranslationsettings.cpp')
-rw-r--r--indra/newview/llfloatertranslationsettings.cpp254
1 files changed, 127 insertions, 127 deletions
diff --git a/indra/newview/llfloatertranslationsettings.cpp b/indra/newview/llfloatertranslationsettings.cpp
index d29ecbbf95..61c4e05183 100644
--- a/indra/newview/llfloatertranslationsettings.cpp
+++ b/indra/newview/llfloatertranslationsettings.cpp
@@ -1,25 +1,25 @@
-/**
+/**
* @file llfloatertranslationsettings.cpp
* @brief Machine translation settings for chat
*
* $LicenseInfo:firstyear=2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2011, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -43,41 +43,41 @@
#include "llradiogroup.h"
LLFloaterTranslationSettings::LLFloaterTranslationSettings(const LLSD& key)
-: LLFloater(key)
-, mMachineTranslationCB(NULL)
-, mAzureKeyVerified(false)
-, mGoogleKeyVerified(false)
-, mDeepLKeyVerified(false)
+: LLFloater(key)
+, mMachineTranslationCB(NULL)
+, mAzureKeyVerified(false)
+, mGoogleKeyVerified(false)
+, mDeepLKeyVerified(false)
{
}
// virtual
BOOL LLFloaterTranslationSettings::postBuild()
{
- mMachineTranslationCB = getChild<LLCheckBoxCtrl>("translate_chat_checkbox");
- mLanguageCombo = getChild<LLComboBox>("translate_language_combo");
- mTranslationServiceRadioGroup = getChild<LLRadioGroup>("translation_service_rg");
+ mMachineTranslationCB = getChild<LLCheckBoxCtrl>("translate_chat_checkbox");
+ mLanguageCombo = getChild<LLComboBox>("translate_language_combo");
+ mTranslationServiceRadioGroup = getChild<LLRadioGroup>("translation_service_rg");
mAzureAPIEndpointEditor = getChild<LLComboBox>("azure_api_endpoint_combo");
- mAzureAPIKeyEditor = getChild<LLLineEditor>("azure_api_key");
+ mAzureAPIKeyEditor = getChild<LLLineEditor>("azure_api_key");
mAzureAPIRegionEditor = getChild<LLLineEditor>("azure_api_region");
- mGoogleAPIKeyEditor = getChild<LLLineEditor>("google_api_key");
+ mGoogleAPIKeyEditor = getChild<LLLineEditor>("google_api_key");
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");
+ 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));
- mAzureVerifyBtn->setClickedCallback(boost::bind(&LLFloaterTranslationSettings::onBtnAzureVerify, this));
- mGoogleVerifyBtn->setClickedCallback(boost::bind(&LLFloaterTranslationSettings::onBtnGoogleVerify, this));
+ 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));
+ 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);
+ 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);
@@ -90,8 +90,8 @@ BOOL LLFloaterTranslationSettings::postBuild()
setAzureVerified(false, false, 0);
});
- mGoogleAPIKeyEditor->setFocusReceivedCallback(boost::bind(&LLFloaterTranslationSettings::onEditorFocused, this, _1));
- mGoogleAPIKeyEditor->setKeystrokeCallback(boost::bind(&LLFloaterTranslationSettings::onGoogleKeyEdited, 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);
@@ -105,22 +105,22 @@ BOOL LLFloaterTranslationSettings::postBuild()
setDeepLVerified(false, false, 0);
});
- center();
- return TRUE;
+ center();
+ return TRUE;
}
// virtual
void LLFloaterTranslationSettings::onOpen(const LLSD& key)
{
- mMachineTranslationCB->setValue(gSavedSettings.getBOOL("TranslateChat"));
- mLanguageCombo->setSelectedByValue(gSavedSettings.getString("TranslateLanguage"), TRUE);
- mTranslationServiceRadioGroup->setSelectedByValue(gSavedSettings.getString("TranslationService"), TRUE);
-
- LLSD azure_key = gSavedSettings.getLLSD("AzureTranslateAPIKey");
- if (azure_key.isMap() && !azure_key["id"].asString().empty())
- {
- mAzureAPIKeyEditor->setText(azure_key["id"].asString());
- mAzureAPIKeyEditor->setTentative(false);
+ mMachineTranslationCB->setValue(gSavedSettings.getBOOL("TranslateChat"));
+ mLanguageCombo->setSelectedByValue(gSavedSettings.getString("TranslateLanguage"), TRUE);
+ mTranslationServiceRadioGroup->setSelectedByValue(gSavedSettings.getString("TranslationService"), TRUE);
+
+ LLSD azure_key = gSavedSettings.getLLSD("AzureTranslateAPIKey");
+ if (azure_key.isMap() && !azure_key["id"].asString().empty())
+ {
+ 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());
@@ -131,27 +131,27 @@ void LLFloaterTranslationSettings::onOpen(const LLSD& key)
mAzureAPIRegionEditor->setTentative(true);
}
mAzureAPIEndpointEditor->setValue(azure_key["endpoint"]);
- verifyKey(LLTranslate::SERVICE_AZURE, azure_key, false);
- }
- else
- {
- mAzureAPIKeyEditor->setTentative(TRUE);
+ verifyKey(LLTranslate::SERVICE_AZURE, azure_key, false);
+ }
+ else
+ {
+ mAzureAPIKeyEditor->setTentative(TRUE);
mAzureAPIRegionEditor->setTentative(true);
- mAzureKeyVerified = FALSE;
- }
-
- std::string google_key = gSavedSettings.getString("GoogleTranslateAPIKey");
- if (!google_key.empty())
- {
- mGoogleAPIKeyEditor->setText(google_key);
- mGoogleAPIKeyEditor->setTentative(FALSE);
- verifyKey(LLTranslate::SERVICE_GOOGLE, google_key, false);
- }
- else
- {
- mGoogleAPIKeyEditor->setTentative(TRUE);
- mGoogleKeyVerified = FALSE;
- }
+ mAzureKeyVerified = FALSE;
+ }
+
+ std::string google_key = gSavedSettings.getString("GoogleTranslateAPIKey");
+ if (!google_key.empty())
+ {
+ mGoogleAPIKeyEditor->setText(google_key);
+ mGoogleAPIKeyEditor->setTentative(FALSE);
+ verifyKey(LLTranslate::SERVICE_GOOGLE, google_key, false);
+ }
+ else
+ {
+ mGoogleAPIKeyEditor->setTentative(TRUE);
+ mGoogleKeyVerified = FALSE;
+ }
LLSD deepl_key = gSavedSettings.getLLSD("DeepLTranslateAPIKey");
if (deepl_key.isMap() && !deepl_key["id"].asString().empty())
@@ -167,29 +167,29 @@ void LLFloaterTranslationSettings::onOpen(const LLSD& key)
mDeepLKeyVerified = FALSE;
}
- updateControlsEnabledState();
+ updateControlsEnabledState();
}
void LLFloaterTranslationSettings::setAzureVerified(bool ok, bool alert, S32 status)
{
- if (alert)
- {
- showAlert(ok ? "azure_api_key_verified" : "azure_api_key_not_verified", status);
- }
+ if (alert)
+ {
+ showAlert(ok ? "azure_api_key_verified" : "azure_api_key_not_verified", status);
+ }
- mAzureKeyVerified = ok;
- updateControlsEnabledState();
+ mAzureKeyVerified = ok;
+ updateControlsEnabledState();
}
void LLFloaterTranslationSettings::setGoogleVerified(bool ok, bool alert, S32 status)
{
- if (alert)
- {
- showAlert(ok ? "google_api_key_verified" : "google_api_key_not_verified", status);
- }
+ if (alert)
+ {
+ showAlert(ok ? "google_api_key_verified" : "google_api_key_not_verified", status);
+ }
- mGoogleKeyVerified = ok;
- updateControlsEnabledState();
+ mGoogleKeyVerified = ok;
+ updateControlsEnabledState();
}
void LLFloaterTranslationSettings::setDeepLVerified(bool ok, bool alert, S32 status)
@@ -205,7 +205,7 @@ void LLFloaterTranslationSettings::setDeepLVerified(bool ok, bool alert, S32 sta
std::string LLFloaterTranslationSettings::getSelectedService() const
{
- return mTranslationServiceRadioGroup->getSelectedValue().asString();
+ return mTranslationServiceRadioGroup->getSelectedValue().asString();
}
LLSD LLFloaterTranslationSettings::getEnteredAzureKey() const
@@ -220,12 +220,12 @@ LLSD LLFloaterTranslationSettings::getEnteredAzureKey() const
key["region"] = mAzureAPIRegionEditor->getText();
}
}
- return key;
+ return key;
}
std::string LLFloaterTranslationSettings::getEnteredGoogleKey() const
{
- return mGoogleAPIKeyEditor->getTentative() ? LLStringUtil::null : mGoogleAPIKeyEditor->getText();
+ return mGoogleAPIKeyEditor->getTentative() ? LLStringUtil::null : mGoogleAPIKeyEditor->getText();
}
LLSD LLFloaterTranslationSettings::getEnteredDeepLKey() const
@@ -246,22 +246,22 @@ void LLFloaterTranslationSettings::showAlert(const std::string& msg_name, S32 st
string_args["[STATUS]"] = llformat("%d", status);
std::string message = getString(msg_name, string_args);
- LLSD args;
- args["MESSAGE"] = message;
- LLNotificationsUtil::add("GenericAlert", args);
+ LLSD args;
+ args["MESSAGE"] = message;
+ LLNotificationsUtil::add("GenericAlert", args);
}
void LLFloaterTranslationSettings::updateControlsEnabledState()
{
- // Enable/disable controls based on the checkbox value.
- bool on = mMachineTranslationCB->getValue().asBoolean();
- std::string service = getSelectedService();
- bool azure_selected = service == "azure";
- bool google_selected = service == "google";
+ // Enable/disable controls based on the checkbox value.
+ bool on = mMachineTranslationCB->getValue().asBoolean();
+ std::string service = getSelectedService();
+ bool azure_selected = service == "azure";
+ bool google_selected = service == "google";
bool deepl_selected = service == "deepl";
- mTranslationServiceRadioGroup->setEnabled(on);
- mLanguageCombo->setEnabled(on);
+ mTranslationServiceRadioGroup->setEnabled(on);
+ mLanguageCombo->setEnabled(on);
// MS Azure
getChild<LLTextBox>("azure_api_endoint_label")->setEnabled(on);
@@ -278,8 +278,8 @@ void LLFloaterTranslationSettings::updateControlsEnabledState()
getChild<LLTextBox>("google_api_key_label")->setEnabled(on);
mGoogleAPIKeyEditor->setEnabled(on && google_selected);
- mGoogleVerifyBtn->setEnabled(on && google_selected &&
- !mGoogleKeyVerified && !getEnteredGoogleKey().empty());
+ mGoogleVerifyBtn->setEnabled(on && google_selected &&
+ !mGoogleKeyVerified && !getEnteredGoogleKey().empty());
// DeepL
getChild<LLTextBox>("deepl_api_domain_label")->setEnabled(on);
@@ -291,12 +291,12 @@ void LLFloaterTranslationSettings::updateControlsEnabledState()
!mDeepLKeyVerified && getEnteredDeepLKey().isMap());
bool service_verified =
- (azure_selected && mAzureKeyVerified)
+ (azure_selected && mAzureKeyVerified)
|| (google_selected && mGoogleKeyVerified)
|| (deepl_selected && mDeepLKeyVerified);
- gSavedPerAccountSettings.setBOOL("TranslatingEnabled", service_verified);
+ gSavedPerAccountSettings.setBOOL("TranslatingEnabled", service_verified);
- mOKBtn->setEnabled(!on || service_verified);
+ mOKBtn->setEnabled(!on || service_verified);
}
/*static*/
@@ -334,33 +334,33 @@ void LLFloaterTranslationSettings::verifyKey(int service, const LLSD& key, bool
void LLFloaterTranslationSettings::onEditorFocused(LLFocusableElement* control)
{
- LLLineEditor* editor = dynamic_cast<LLLineEditor*>(control);
- if (editor && editor->hasTabStop()) // if enabled. getEnabled() doesn't work
- {
- if (editor->getTentative())
- {
- editor->setText(LLStringUtil::null);
- editor->setTentative(FALSE);
- }
- }
+ LLLineEditor* editor = dynamic_cast<LLLineEditor*>(control);
+ if (editor && editor->hasTabStop()) // if enabled. getEnabled() doesn't work
+ {
+ if (editor->getTentative())
+ {
+ editor->setText(LLStringUtil::null);
+ editor->setTentative(FALSE);
+ }
+ }
}
void LLFloaterTranslationSettings::onAzureKeyEdited()
{
- if (mAzureAPIKeyEditor->isDirty()
+ if (mAzureAPIKeyEditor->isDirty()
|| mAzureAPIRegionEditor->isDirty())
- {
+ {
// todo: verify mAzureAPIEndpointEditor url
- setAzureVerified(false, false, 0);
- }
+ setAzureVerified(false, false, 0);
+ }
}
void LLFloaterTranslationSettings::onGoogleKeyEdited()
{
- if (mGoogleAPIKeyEditor->isDirty())
- {
- setGoogleVerified(false, false, 0);
- }
+ if (mGoogleAPIKeyEditor->isDirty())
+ {
+ setGoogleVerified(false, false, 0);
+ }
}
void LLFloaterTranslationSettings::onDeepLKeyEdited()
@@ -373,20 +373,20 @@ void LLFloaterTranslationSettings::onDeepLKeyEdited()
void LLFloaterTranslationSettings::onBtnAzureVerify()
{
- LLSD key = getEnteredAzureKey();
- if (key.isMap())
- {
- verifyKey(LLTranslate::SERVICE_AZURE, key);
- }
+ LLSD key = getEnteredAzureKey();
+ if (key.isMap())
+ {
+ verifyKey(LLTranslate::SERVICE_AZURE, key);
+ }
}
void LLFloaterTranslationSettings::onBtnGoogleVerify()
{
- std::string key = getEnteredGoogleKey();
- if (!key.empty())
- {
- verifyKey(LLTranslate::SERVICE_GOOGLE, LLSD(key));
- }
+ std::string key = getEnteredGoogleKey();
+ if (!key.empty())
+ {
+ verifyKey(LLTranslate::SERVICE_GOOGLE, LLSD(key));
+ }
}
void LLFloaterTranslationSettings::onBtnDeepLVerify()
@@ -400,9 +400,9 @@ void LLFloaterTranslationSettings::onBtnDeepLVerify()
void LLFloaterTranslationSettings::onClose(bool app_quitting)
{
- std::string service = gSavedSettings.getString("TranslationService");
- bool azure_selected = service == "azure";
- bool google_selected = service == "google";
+ std::string service = gSavedSettings.getString("TranslationService");
+ bool azure_selected = service == "azure";
+ bool google_selected = service == "google";
bool deepl_selected = service == "deepl";
bool service_verified =
@@ -413,12 +413,12 @@ void LLFloaterTranslationSettings::onClose(bool app_quitting)
}
void LLFloaterTranslationSettings::onBtnOK()
{
- gSavedSettings.setBOOL("TranslateChat", mMachineTranslationCB->getValue().asBoolean());
- gSavedSettings.setString("TranslateLanguage", mLanguageCombo->getSelectedValue().asString());
- gSavedSettings.setString("TranslationService", getSelectedService());
- gSavedSettings.setLLSD("AzureTranslateAPIKey", getEnteredAzureKey());
- gSavedSettings.setString("GoogleTranslateAPIKey", getEnteredGoogleKey());
+ gSavedSettings.setBOOL("TranslateChat", mMachineTranslationCB->getValue().asBoolean());
+ gSavedSettings.setString("TranslateLanguage", mLanguageCombo->getSelectedValue().asString());
+ gSavedSettings.setString("TranslationService", getSelectedService());
+ gSavedSettings.setLLSD("AzureTranslateAPIKey", getEnteredAzureKey());
+ gSavedSettings.setString("GoogleTranslateAPIKey", getEnteredGoogleKey());
gSavedSettings.setLLSD("DeepLTranslateAPIKey", getEnteredDeepLKey());
- closeFloater(false);
+ closeFloater(false);
}