From 213985ca0d045252ad49d9d45f77d0727fa9008f Mon Sep 17 00:00:00 2001
From: callum <none@none>
Date: Mon, 10 Oct 2011 17:29:04 -0700
Subject: [PATCH] EXP-1302 PARTIAL Make the Speak button work as a toolbar
 button First pass - no Push-To-Talk functionality.

---
 indra/newview/app_settings/commands.xml |  4 +--
 indra/newview/llagent.cpp               | 38 ++++++++++++++++++++++++-
 indra/newview/llagent.h                 | 16 ++++++++++-
 indra/newview/llbottomtray.cpp          |  3 ++
 4 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/indra/newview/app_settings/commands.xml b/indra/newview/app_settings/commands.xml
index dab57d44bd3..139eabcae4d 100644
--- a/indra/newview/app_settings/commands.xml
+++ b/indra/newview/app_settings/commands.xml
@@ -207,11 +207,11 @@
            icon="Command_Speak_Icon"
            label_ref="Command_Speak_Label"
            tooltip_ref="Command_Speak_Tooltip"
-           execute_function="Floater.ToolbarToggle"
+           execute_function="Agent.ToggleMicrophone"
            execute_parameters="speak"
            is_enabled_function="Agent.IsActionAllowed"
            is_enabled_parameters="speak"
-           is_running_function="Floater.IsOpen"
+           is_running_function="Agent.IsMicrophoneOn"
            is_running_parameters="speak"
            />
   <command name="view"
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index ed29ac79609..8303a5942da 100755
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -174,12 +174,43 @@ bool LLAgent::isActionAllowed(const LLSD& sdname)
 	}
 	else if (param == "speak")
 	{
-		retval = true;
+		if ( gAgent.isVoiceConnected() )
+		{
+			retval = true;
+		}
+		else
+		{
+			retval = false;
+		}
 	}
 
 	return retval;
 }
 
+// static 
+void LLAgent::toggleMicrophone(const LLSD& name)
+{
+	gAgent.mMicrophoneOn = ! gAgent.mMicrophoneOn;
+
+	if ( gAgent.mMicrophoneOn )
+	{
+		LLFirstUse::speak(false);
+
+		LLVoiceClient::getInstance()->inputUserControlState(true);
+		LLVoiceClient::getInstance()->inputUserControlState(false);
+	}
+	else
+	{
+		LLVoiceClient::getInstance()->inputUserControlState(false);
+		LLVoiceClient::getInstance()->inputUserControlState(true);
+	}
+}
+
+// static
+bool LLAgent::isMicrophoneOn(const LLSD& sdname)
+{
+	return gAgent.mMicrophoneOn;
+}
 
 // ************************************************************
 // Enabled this definition to compile a 'hacked' viewer that
@@ -261,6 +292,9 @@ LLAgent::LLAgent() :
 	mCurrentFidget(0),
 	mFirstLogin(FALSE),
 	mGenderChosen(FALSE),
+	
+	mVoiceConnected(false),
+	mMicrophoneOn(false),
 
 	mAppearanceSerialNum(0),
 
@@ -280,6 +314,8 @@ LLAgent::LLAgent() :
 	LLViewerParcelMgr::getInstance()->addAgentParcelChangedCallback(boost::bind(&LLAgent::parcelChangedCallback));
 
 	LLUICtrl::EnableCallbackRegistry::currentRegistrar().add("Agent.IsActionAllowed", boost::bind(&LLAgent::isActionAllowed, _2));
+	LLUICtrl::CommitCallbackRegistry::currentRegistrar().add("Agent.ToggleMicrophone", boost::bind(&LLAgent::toggleMicrophone, _2));
+	LLUICtrl::EnableCallbackRegistry::currentRegistrar().add("Agent.IsMicrophoneOn", boost::bind(&LLAgent::isMicrophoneOn, _2));
 }
 
 // Requires gSavedSettings to be initialized.
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index 1775a0235cc..0355e68b6e5 100644
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -282,7 +282,21 @@ class LLAgent : public LLOldEvents::LLObservable
 	static void		toggleFlying();
 	static bool		enableFlying();
 	BOOL			canFly(); 			// Does this parcel allow you to fly?
-	
+
+	//--------------------------------------------------------------------
+	// Voice
+	//--------------------------------------------------------------------
+public:
+	bool 			isVoiceConnected() const { return mVoiceConnected; }
+	void			setVoiceConnected(const bool b)	{ mVoiceConnected = b; }
+
+	static void		toggleMicrophone(const LLSD& name);
+	static bool		isMicrophoneOn(const LLSD& sdname);
+
+private:
+	bool			mVoiceConnected;
+	bool			mMicrophoneOn;
+
 	//--------------------------------------------------------------------
 	// Chat
 	//--------------------------------------------------------------------
diff --git a/indra/newview/llbottomtray.cpp b/indra/newview/llbottomtray.cpp
index 98712f13348..af91702f9b8 100644
--- a/indra/newview/llbottomtray.cpp
+++ b/indra/newview/llbottomtray.cpp
@@ -387,6 +387,9 @@ void LLBottomTray::onChange(EStatusType status, const std::string &channelURI, b
 	if (status != STATUS_JOINING && status!= STATUS_LEFT_CHANNEL)
 	{
 		bool voice_status = LLVoiceClient::getInstance()->voiceEnabled() && LLVoiceClient::getInstance()->isVoiceWorking();
+
+		gAgent.setVoiceConnected(voice_status);
+
 		getChild<LLButton>("speak_flyout_btn")->setEnabled(voice_status);
 		gMenuBarView->getChild<LLView>("Nearby Voice")->setEnabled(voice_status);
 		if (voice_status)
-- 
GitLab