From 43a6a3bee69acdeac864c93130156b33358a9a30 Mon Sep 17 00:00:00 2001
From: Cinders <cinder@cinderblocks.biz>
Date: Thu, 13 Aug 2015 14:03:25 -0600
Subject: [PATCH] Add a generic text floater and use it for dumping debug info
 for gridInfo and sim features

---
 indra/newview/CMakeLists.txt                  |  2 +
 indra/newview/llfloatergenerictext.cpp        | 61 +++++++++++++++++++
 indra/newview/llfloatergenerictext.h          | 51 ++++++++++++++++
 indra/newview/llfloaterpreference.cpp         | 13 +++-
 indra/newview/llviewerfloaterreg.cpp          |  3 +-
 indra/newview/llviewermenu.cpp                | 19 ++++++
 indra/newview/llviewernetwork.cpp             |  5 ++
 indra/newview/llviewernetwork.h               |  3 +
 .../default/xui/en/floater_generic_text.xml   | 52 ++++++++++++++++
 .../skins/default/xui/en/menu_viewer.xml      |  6 ++
 .../xui/en/panel_preferences_grids.xml        |  4 +-
 .../newview/skins/default/xui/en/strings.xml  |  2 +
 12 files changed, 217 insertions(+), 4 deletions(-)
 create mode 100644 indra/newview/llfloatergenerictext.cpp
 create mode 100644 indra/newview/llfloatergenerictext.h
 create mode 100644 indra/newview/skins/default/xui/en/floater_generic_text.xml

diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index d485dc3bb9..3a7ffbf9a3 100755
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -265,6 +265,7 @@ set(viewer_SOURCE_FILES
     llfloaterfacebook.cpp
     llfloaterflickr.cpp
     llfloaterfonttest.cpp
+    llfloatergenerictext.cpp
     llfloatergesture.cpp
     llfloatergodtools.cpp
     llfloatergotoline.cpp
@@ -907,6 +908,7 @@ set(viewer_HEADER_FILES
     llfloaterfacebook.h
     llfloaterflickr.h
     llfloaterfonttest.h
+    llfloatergenerictext.h
     llfloatergesture.h
     llfloatergodtools.h
     llfloatergotoline.h
diff --git a/indra/newview/llfloatergenerictext.cpp b/indra/newview/llfloatergenerictext.cpp
new file mode 100644
index 0000000000..6cd6118ec4
--- /dev/null
+++ b/indra/newview/llfloatergenerictext.cpp
@@ -0,0 +1,61 @@
+/**
+ * @file llfloatergenerictext.cpp
+ * @brief A generic text floater for dumping info (usually debug info)
+ *
+ * Copyright (c) 2015, Cinder Roxley <cinder@sdf.org>
+ *
+ * Permission is hereby granted, free of charge, to any person or organization
+ * obtaining a copy of the software and accompanying documentation covered by
+ * this license (the "Software") to use, reproduce, display, distribute,
+ * execute, and transmit the Software, and to prepare derivative works of the
+ * Software, and to permit third-parties to whom the Software is furnished to
+ * do so, all subject to the following:
+ *
+ * The copyright notices in the Software and this entire statement, including
+ * the above license grant, this restriction and the following disclaimer,
+ * must be included in all copies of the Software, in whole or in part, and
+ * all derivative works of the Software, unless such copies or derivative
+ * works are solely in the form of machine-executable object code generated by
+ * a source language processor.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+ * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+ * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "llviewerprecompiledheaders.h"
+#include "llfloatergenerictext.h"
+#include "llclipboard.h"
+#include "lltexteditor.h"
+
+LLFloaterGenericText::LLFloaterGenericText(const LLSD& key)
+:	LLFloater(key)
+{
+	mTitle = key["title"].asString();
+	mContents = key["data"].asString();
+	
+	mCommitCallbackRegistrar.add("GenericText.Close", boost::bind(&LLFloaterGenericText::onClickClose, this));
+	mCommitCallbackRegistrar.add("GenericText.Copy", boost::bind(&LLFloaterGenericText::onClickCopy, this));
+}
+
+BOOL LLFloaterGenericText::postBuild()
+{
+	setTitle(mTitle);
+	getChild<LLTextEditor>("payload")->setText(mContents);
+	return TRUE;
+}
+
+void LLFloaterGenericText::onClickClose()
+{
+	closeFloater();
+}
+
+void LLFloaterGenericText::onClickCopy()
+{
+	LLClipboard::instance().copyToClipboard(utf8str_to_wstring(mContents, mContents.length()), 0, mContents.length());
+}
diff --git a/indra/newview/llfloatergenerictext.h b/indra/newview/llfloatergenerictext.h
new file mode 100644
index 0000000000..e738e6c8a1
--- /dev/null
+++ b/indra/newview/llfloatergenerictext.h
@@ -0,0 +1,51 @@
+/**
+ * @file llfloatergenerictext.h
+ * @brief A generic text floater for dumping info (usually debug info)
+ *
+ * Copyright (c) 2015, Cinder Roxley <cinder@sdf.org>
+ *
+ * Permission is hereby granted, free of charge, to any person or organization
+ * obtaining a copy of the software and accompanying documentation covered by
+ * this license (the "Software") to use, reproduce, display, distribute,
+ * execute, and transmit the Software, and to prepare derivative works of the
+ * Software, and to permit third-parties to whom the Software is furnished to
+ * do so, all subject to the following:
+ *
+ * The copyright notices in the Software and this entire statement, including
+ * the above license grant, this restriction and the following disclaimer,
+ * must be included in all copies of the Software, in whole or in part, and
+ * all derivative works of the Software, unless such copies or derivative
+ * works are solely in the form of machine-executable object code generated by
+ * a source language processor.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+ * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+ * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef LL_FLOATERGENERICTEXT_H
+#define LL_FLOATERGENERICTEXT_H
+
+#include "llfloater.h"
+
+class LLFloaterGenericText : public LLFloater
+{
+public:
+	LLFloaterGenericText(const LLSD& key);
+	BOOL postBuild() override;
+private:
+	~LLFloaterGenericText() {};
+	void onClickClose();
+	void onClickCopy();
+	
+	std::string mTitle;
+	std::string mContents;
+	
+};
+
+#endif // LL_FLOATERGENERICTEXT_H
diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp
index 9916f60645..3459c32e07 100755
--- a/indra/newview/llfloaterpreference.cpp
+++ b/indra/newview/llfloaterpreference.cpp
@@ -98,6 +98,7 @@
 #include "llui.h"
 #include "llviewernetwork.h"
 #include "llviewerobjectlist.h"
+#include "llviewerregion.h"
 #include "llvoavatar.h"
 #include "llvovolume.h"
 #include "llwindow.h"
@@ -379,6 +380,7 @@ LLFloaterPreference::LLFloaterPreference(const LLSD& key)
 	mCommitCallbackRegistrar.add("Pref.AddGrid", boost::bind(&LLFloaterPreference::onClickAddGrid, this));
 	mCommitCallbackRegistrar.add("Pref.RemoveGrid", boost::bind(&LLFloaterPreference::onClickRemoveGrid, this));
 	mCommitCallbackRegistrar.add("Pref.RefreshGrid", boost::bind(&LLFloaterPreference::onClickRefreshGrid, this));
+	mCommitCallbackRegistrar.add("Pref.DebugGrid", boost::bind(&LLFloaterPreference::onClickDebugGrid, this));
 	mCommitCallbackRegistrar.add("Pref.SelectGrid", boost::bind(&LLFloaterPreference::onSelectGrid, this, _2));
 }
 
@@ -573,7 +575,14 @@ void LLFloaterPreference::onClickRefreshGrid()
 
 void LLFloaterPreference::onClickDebugGrid()
 {
-	// no-op for now
+	LLSD args;
+	std::stringstream data_str;
+	const std::string& grid = getChild<LLScrollListCtrl>("grid_list")->getSelectedValue().asString().c_str();
+	LLSD gridInfo = LLGridManager::getInstance()->getGridInfo(grid);
+	LLSDSerialize::toPrettyXML(gridInfo, data_str);
+	args["title"] = llformat("%s - %s", LLTrans::getString("GridInfoTitle").c_str(), grid.c_str());
+	args["data"] = data_str.str();
+	LLFloaterReg::showInstance("generic_text", args);
 }
 
 void LLFloaterPreference::onSelectGrid(const LLSD& data)
@@ -581,6 +590,7 @@ void LLFloaterPreference::onSelectGrid(const LLSD& data)
 	getChild<LLUICtrl>("remove_grid")->setEnabled(LLGridManager::getInstance()->getGrid() != data.asString()
 												  && !LLGridManager::getInstance()->isSystemGrid(data.asString()));
 	getChild<LLUICtrl>("refresh_grid")->setEnabled(!LLGridManager::getInstance()->isSystemGrid(data.asString()));
+	getChild<LLUICtrl>("debug_grid")->setEnabled(!data.asString().empty());
 }
 
 bool LLFloaterPreference::handleRemoveGridCB(const LLSD& notification, const LLSD& response)
@@ -904,6 +914,7 @@ void LLFloaterPreference::onOpenHardwareSettings()
 	LLFloater* floater = LLFloaterReg::showInstance("prefs_hardware_settings");
 	addDependentFloater(floater, FALSE);
 }
+
 // static 
 void LLFloaterPreference::onBtnOK()
 {
diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp
index 72ed388bd6..d870da54af 100755
--- a/indra/newview/llviewerfloaterreg.cpp
+++ b/indra/newview/llviewerfloaterreg.cpp
@@ -70,6 +70,7 @@
 #include "llfloaterfacebook.h"
 #include "llfloaterflickr.h"
 #include "llfloaterfonttest.h"
+#include "llfloatergenerictext.h"
 #include "llfloatergesture.h"
 #include "llfloatergodtools.h"
 #include "llfloatergroups.h"
@@ -233,7 +234,7 @@ void LLViewerFloaterReg::registerFloaters()
 	LLFloaterReg::add("experience_search", "floater_experience_search.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterExperiencePicker>);
 
 	LLFloaterReg::add("font_test", "floater_font_test.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterFontTest>);
-
+	LLFloaterReg::add("generic_text", "floater_generic_text.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterGenericText>);
 	LLFloaterReg::add("gestures", "floater_gesture.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterGesture>);
 	LLFloaterReg::add("god_tools", "floater_god_tools.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterGodTools>);
 	LLFloaterReg::add("group_picker", "floater_choose_group.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterGroupPicker>);
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index ad2bb5988f..022c7d61d4 100755
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -3279,6 +3279,24 @@ class LLEditParticleSource : public view_listener_t
 	}
 };
 
+class LLSpawnDebugSimFeatures : public view_listener_t
+{
+	bool handleEvent(const LLSD& userdata)
+	{
+		if (LLViewerRegion* regionp = gAgent.getRegion())
+		{
+			LLSD sim_features, args;
+			std::stringstream features_str;
+			regionp->getSimulatorFeatures(sim_features);
+			LLSDSerialize::toPrettyXML(sim_features, features_str);
+			args["title"] = llformat("%s - %s", LLTrans::getString("SimulatorFeaturesTitle").c_str(), regionp->getName().c_str());
+			args["data"] = features_str.str();
+			LLFloaterReg::showInstance("generic_text", args);
+		}
+		return true;
+	}
+};
+
 class LLSyncAnimations : public view_listener_t
 {
 	bool handleEvent(const LLSD& userdata)
@@ -9401,6 +9419,7 @@ void initialize_menus()
 	view_listener_t::addMenu(new LLRefreshTexturesObject(), "Object.RefreshTex");
     view_listener_t::addMenu(new LLEditParticleSource(), "Object.EditParticles");
     view_listener_t::addMenu(new LLEnableEditParticleSource(), "Object.EnableEditParticles");
+    view_listener_t::addMenu(new LLSpawnDebugSimFeatures(), "Advanced.DebugSimFeatures");
 	view_listener_t::addMenu(new LLSyncAnimations(), "Tools.ResyncAnimations");
 	view_listener_t::addMenu(new ALMarkViewerEffectsDead(), "Tools.AllVEDead");
 
diff --git a/indra/newview/llviewernetwork.cpp b/indra/newview/llviewernetwork.cpp
index 9273fb1feb..e1e7a0d92f 100755
--- a/indra/newview/llviewernetwork.cpp
+++ b/indra/newview/llviewernetwork.cpp
@@ -882,6 +882,11 @@ std::string LLGridManager::getUpdateServiceURL() const
 	return update_url_base;
 }
 
+LLSD LLGridManager::getGridInfo(const std::string& grid) const
+{
+	return mGridList.has(grid) ? mGridList[grid] : LLSD();
+}
+
 void LLGridManager::updateIsInProductionGrid()
 {
 	// *NOTE:Mani This used to compare GRID_INFO_AGNI to gGridChoice,
diff --git a/indra/newview/llviewernetwork.h b/indra/newview/llviewernetwork.h
index 13d165ad6f..5c8aacd21a 100755
--- a/indra/newview/llviewernetwork.h
+++ b/indra/newview/llviewernetwork.h
@@ -107,6 +107,9 @@ class LLGridManager : public LLSingleton<LLGridManager>
 	
 	/// Get the user-friendly long form descriptor for the selected grid
 	std::string getGridLabel() const { return getGridLabel(mGrid); }
+	
+	/// Returns gridInfo for a given grid as an LLSD map
+	LLSD getGridInfo(const std::string& grid) const;
 
 	/// Retrieve a map of grid-name -> label
 	std::map<std::string, std::string> getKnownGrids() const;
diff --git a/indra/newview/skins/default/xui/en/floater_generic_text.xml b/indra/newview/skins/default/xui/en/floater_generic_text.xml
new file mode 100644
index 0000000000..c0f6ed0b04
--- /dev/null
+++ b/indra/newview/skins/default/xui/en/floater_generic_text.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<floater can_close="true"
+ single_instance="false"
+ can_drag_on_left="false"
+ can_minimize="true"
+ can_resize="true"
+ height="258"
+ width="258"
+ min_width="214"
+ min_height="100"
+ name="floater_generic_text"
+ title="INFO">
+  <text_editor
+   type="string"
+   length="1"
+   enabled="false"
+   follows="left|top|right|bottom"
+   font="SansSerif"
+   height="200"
+   layout="topleft"
+   top="4"
+   bottom="-32"
+   left="4"
+   right="-4"
+   max_length="65536"
+   name="payload"
+   word_wrap="true">
+It doesn't matter what comes, fresh goes better in life, with Mentos fresh and full of Life! Nothing gets to you, stayin' fresh, stayin' cool, with Mentos fresh and full of life! Fresh goes better! Mentos freshness! Fresh goes better with Mentos, fresh and full of life! Mentos! The Freshmaker!
+  </text_editor>
+  <button
+   follows="right|bottom"
+   label="Copy"
+   name="copy_btn"
+   left="49"
+   top_pad="2"
+   height="26"
+   width="100">
+    <button.commit_callback
+     function="GenericText.Copy" />
+  </button>
+  <button
+   follows="right|bottom"
+   label="Close"
+   name="close_btn"
+   left_pad="4"
+   top_delta="0"
+   height="26"
+   width="100">
+    <button.commit_callback
+     function="GenericText.Close" />
+  </button>
+</floater>
diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml
index ea5c423625..b1966e43a9 100755
--- a/indra/newview/skins/default/xui/en/menu_viewer.xml
+++ b/indra/newview/skins/default/xui/en/menu_viewer.xml
@@ -2403,6 +2403,12 @@
                  function="Advanced.DumpInfoToConsole"
                  parameter="capabilities" />
             </menu_item_call>
+            <menu_item_call
+             label="View Simulator Features"
+             name="View Simulator Features">
+                <menu_item_call.on_click
+                 function="Advanced.DebugSimFeatures" />
+            </menu_item_call>
 
             <menu_item_separator/>
 
diff --git a/indra/newview/skins/default/xui/en/panel_preferences_grids.xml b/indra/newview/skins/default/xui/en/panel_preferences_grids.xml
index bfdbc1c8cf..7ec804f305 100644
--- a/indra/newview/skins/default/xui/en/panel_preferences_grids.xml
+++ b/indra/newview/skins/default/xui/en/panel_preferences_grids.xml
@@ -103,7 +103,7 @@
     <button.commit_callback
      function="Pref.RemoveGrid" />
   </button>
-  <!--<button
+  <button
    enabled="false"
    follows="left|top"
    height="19"
@@ -115,5 +115,5 @@
    width="75">
     <button.commit_callback
      function="Pref.DebugGrid" />
-  </button>-->
+  </button>
 </panel>
diff --git a/indra/newview/skins/default/xui/en/strings.xml b/indra/newview/skins/default/xui/en/strings.xml
index 232153dbbd..ba515dbf21 100755
--- a/indra/newview/skins/default/xui/en/strings.xml
+++ b/indra/newview/skins/default/xui/en/strings.xml
@@ -4243,6 +4243,8 @@ Try enclosing path to the editor with double quotes.
   <string name="NotifyIncomingMessage">Incoming message from [NAME]...</string>
   <string name="NearbyChatTitleChannel">Nearby chat (on channel [CHANNEL])</string>
   <string name="NowPlaying">Now Playing</string>
+  <string name="SimulatorFeaturesTitle">SIMULATOR FEATURES</string>
+  <string name="GridInfoTitle">GRID INFO</string>
   <string name="AvatarTyping">Typing</string>
 
 
-- 
GitLab