diff options
Diffstat (limited to 'linden/indra/newview/llviewermessage.cpp')
-rwxr-xr-x | linden/indra/newview/llviewermessage.cpp | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/linden/indra/newview/llviewermessage.cpp b/linden/indra/newview/llviewermessage.cpp index 45280e4..45fd772 100755 --- a/linden/indra/newview/llviewermessage.cpp +++ b/linden/indra/newview/llviewermessage.cpp | |||
@@ -138,6 +138,7 @@ | |||
138 | #include "llfloaterworldmap.h" | 138 | #include "llfloaterworldmap.h" |
139 | #include "llviewerdisplay.h" | 139 | #include "llviewerdisplay.h" |
140 | #include "llkeythrottle.h" | 140 | #include "llkeythrottle.h" |
141 | #include "lltranslate.h" | ||
141 | 142 | ||
142 | #include "panelradarentry.h" | 143 | #include "panelradarentry.h" |
143 | 144 | ||
@@ -2698,6 +2699,83 @@ void process_decline_callingcard(LLMessageSystem* msg, void**) | |||
2698 | LLNotifications::instance().add("CallingCardDeclined"); | 2699 | LLNotifications::instance().add("CallingCardDeclined"); |
2699 | } | 2700 | } |
2700 | 2701 | ||
2702 | class ChatTranslationReceiver : public LLTranslate::TranslationReceiver | ||
2703 | { | ||
2704 | public : | ||
2705 | ChatTranslationReceiver(const std::string &fromLang, const std::string &toLang, LLChat *chat, | ||
2706 | const BOOL history) | ||
2707 | : LLTranslate::TranslationReceiver(fromLang, toLang), | ||
2708 | m_chat(chat), | ||
2709 | m_history(history) | ||
2710 | { | ||
2711 | } | ||
2712 | |||
2713 | static boost::intrusive_ptr<ChatTranslationReceiver> build(const std::string &fromLang, const std::string &toLang, LLChat *chat, const BOOL history) | ||
2714 | { | ||
2715 | return boost::intrusive_ptr<ChatTranslationReceiver>(new ChatTranslationReceiver(fromLang, toLang, chat, history)); | ||
2716 | } | ||
2717 | |||
2718 | protected: | ||
2719 | void handleResponse(const std::string &translation, const std::string &detectedLanguage) | ||
2720 | { | ||
2721 | if (m_toLang != detectedLanguage) | ||
2722 | m_chat->mText += " (" + translation + ")"; | ||
2723 | |||
2724 | add_floater_chat(*m_chat, m_history); | ||
2725 | |||
2726 | delete m_chat; | ||
2727 | } | ||
2728 | |||
2729 | void handleFailure() | ||
2730 | { | ||
2731 | LLTranslate::TranslationReceiver::handleFailure(); | ||
2732 | |||
2733 | m_chat->mText += " (?)"; | ||
2734 | |||
2735 | add_floater_chat(*m_chat, m_history); | ||
2736 | |||
2737 | delete m_chat; | ||
2738 | } | ||
2739 | |||
2740 | private: | ||
2741 | LLChat *m_chat; | ||
2742 | const BOOL m_history; | ||
2743 | }; | ||
2744 | |||
2745 | void add_floater_chat(const LLChat &chat, const BOOL history) | ||
2746 | { | ||
2747 | if (history) | ||
2748 | { | ||
2749 | // just add to history | ||
2750 | LLFloaterChat::addChatHistory(chat); | ||
2751 | } | ||
2752 | else | ||
2753 | { | ||
2754 | // show on screen and add to history | ||
2755 | LLFloaterChat::addChat(chat, FALSE, FALSE); | ||
2756 | } | ||
2757 | } | ||
2758 | |||
2759 | void check_translate_chat(const std::string &mesg, LLChat &chat, const BOOL history) | ||
2760 | { | ||
2761 | const bool translate = LLUI::sConfigGroup->getBOOL("TranslateChat"); | ||
2762 | |||
2763 | if (translate && chat.mSourceType != CHAT_SOURCE_SYSTEM) | ||
2764 | { | ||
2765 | // fromLang hardcoded to "" (autodetection) pending implementation of | ||
2766 | // SVC-4879 | ||
2767 | const std::string &fromLang = ""; | ||
2768 | const std::string &toLang = LLTranslate::getTranslateLanguage(); | ||
2769 | LLChat *newChat = new LLChat(chat); | ||
2770 | |||
2771 | LLHTTPClient::ResponderPtr result = ChatTranslationReceiver::build(fromLang, toLang, newChat, history); | ||
2772 | LLTranslate::translateMessage(result, fromLang, toLang, mesg); | ||
2773 | } | ||
2774 | else | ||
2775 | { | ||
2776 | add_floater_chat(chat, history); | ||
2777 | } | ||
2778 | } | ||
2701 | 2779 | ||
2702 | void process_chat_from_simulator(LLMessageSystem *msg, void **user_data) | 2780 | void process_chat_from_simulator(LLMessageSystem *msg, void **user_data) |
2703 | { | 2781 | { |
@@ -3061,12 +3139,12 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data) | |||
3061 | && (is_linden || !is_busy || is_owned_by_me)) | 3139 | && (is_linden || !is_busy || is_owned_by_me)) |
3062 | { | 3140 | { |
3063 | // show on screen and add to history | 3141 | // show on screen and add to history |
3064 | LLFloaterChat::addChat(chat, FALSE, FALSE); | 3142 | check_translate_chat(mesg, chat, FALSE); |
3065 | } | 3143 | } |
3066 | else | 3144 | else |
3067 | { | 3145 | { |
3068 | // just add to chat history | 3146 | // just add to chat history |
3069 | LLFloaterChat::addChatHistory(chat); | 3147 | check_translate_chat(mesg, chat, TRUE); |
3070 | } | 3148 | } |
3071 | } | 3149 | } |
3072 | } | 3150 | } |