mirror of
https://github.com/FirestormViewer/phoenix-firestorm.git
synced 2026-08-14 00:48:30 +00:00
191 lines
5.8 KiB
C++
191 lines
5.8 KiB
C++
/**
|
|
* @file llpaneldirweb.cpp
|
|
* @brief Web panel in the legacy Search directory.
|
|
*
|
|
* $LicenseInfo:firstyear=2025&license=viewerlgpl$
|
|
* Second Life Viewer Source Code
|
|
* Copyright (C) 2025, 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$
|
|
*/
|
|
|
|
#include "llviewerprecompiledheaders.h"
|
|
|
|
#include "llpaneldirweb.h"
|
|
|
|
#include "llagent.h"
|
|
#include "llbutton.h"
|
|
#include "llfloaterdirectory.h"
|
|
#include "lltextbox.h"
|
|
#include "lluri.h" // <FS:PP> FIRE-36483 Menu, navbar and toolbar button must open the same search window
|
|
#include "llviewercontrol.h"
|
|
#include "llweb.h"
|
|
|
|
// <FS:TJ> Get the correct SearchURL from the login response if available
|
|
#include "lfsimfeaturehandler.h"
|
|
#include "llviewernetwork.h"
|
|
// </FS:TJ>
|
|
|
|
static LLPanelInjector<LLPanelDirWeb> t_panel_dir_web("panel_dir_web");
|
|
|
|
LLPanelDirWeb::LLPanelDirWeb()
|
|
: LLPanel(),
|
|
mFloaterDirectory(nullptr),
|
|
mWebBrowser(nullptr)
|
|
{
|
|
}
|
|
|
|
bool LLPanelDirWeb::postBuild()
|
|
{
|
|
childSetAction("home_btn", onClickHome, this);
|
|
|
|
mBtnBack = getChild<LLButton>("back_btn");
|
|
mBtnForward = getChild<LLButton>("forward_btn");
|
|
mStatusBarText = getChild<LLTextBox>("statusbartext");
|
|
|
|
mBtnBack->setClickedCallback([this](LLUICtrl*, const LLSD&) { mWebBrowser->navigateBack(); });
|
|
mBtnForward->setClickedCallback([this](LLUICtrl*, const LLSD&) { mWebBrowser->navigateForward(); });
|
|
|
|
mWebBrowser = findChild<LLMediaCtrl>("web_search");
|
|
// <FS:PP> Load openID cookie and log in the user
|
|
mWebBrowser->setErrorPageURL(gSavedSettings.getString("GenericErrorPageURL"));
|
|
LLViewerMedia::getInstance()->getOpenIDCookie(mWebBrowser);
|
|
// </FS:PP>
|
|
|
|
navigateToDefaultPage();
|
|
mWebBrowser->addObserver(this);
|
|
|
|
return true;
|
|
}
|
|
|
|
void LLPanelDirWeb::draw()
|
|
{
|
|
// Asynchronous so we need to keep checking
|
|
mBtnBack->setEnabled(mWebBrowser->canNavigateBack());
|
|
mBtnForward->setEnabled(mWebBrowser->canNavigateForward());
|
|
|
|
LLPanel::draw();
|
|
}
|
|
|
|
LLPanelDirWeb::~LLPanelDirWeb()
|
|
{
|
|
}
|
|
|
|
// When we show any browser-based view, we want to hide all
|
|
// the right-side XUI detail panels.
|
|
// virtual
|
|
void LLPanelDirWeb::onVisibilityChange(bool new_visibility)
|
|
{
|
|
if (new_visibility && mFloaterDirectory)
|
|
{
|
|
mFloaterDirectory->hideAllDetailPanels();
|
|
}
|
|
LLPanel::onVisibilityChange(new_visibility);
|
|
}
|
|
|
|
void LLPanelDirWeb::navigateToDefaultPage()
|
|
{
|
|
// <FS:PP> FIRE-36483 Menu, navbar and toolbar button must open the same search window
|
|
navigateToSearchPage("standard", "");
|
|
}
|
|
|
|
void LLPanelDirWeb::navigateToSearchPage(const std::string& category, const std::string& query, const std::string& collection)
|
|
{
|
|
// </FS:PP>
|
|
// <FS:TJ> Get the correct SearchURL from the login response if available
|
|
//std::string url = gSavedSettings.getString("SearchURL");
|
|
std::string url = LFSimFeatureHandler::instance().searchURL();
|
|
if (url.empty())
|
|
{
|
|
url = LLGridManager::getInstance()->isInSecondLife() ? gSavedSettings.getString("SearchURL") : gSavedSettings.getString("SearchURLOpenSim");
|
|
}
|
|
// </FS:TJ>
|
|
|
|
LLSD subs;
|
|
// <FS:PP> FIRE-36483 Menu, navbar and toolbar button must open the same search window
|
|
// subs["QUERY"] = "";
|
|
// subs["TYPE"] = "standard";
|
|
subs["QUERY"] = LLURI::escape(query);
|
|
subs["TYPE"] = category.empty() ? "standard" : category;
|
|
subs["COLLECTION"] = "";
|
|
if (subs["TYPE"].asString() == "standard" && !collection.empty())
|
|
{
|
|
subs["COLLECTION"] = "&collection_chosen=" + collection;
|
|
}
|
|
// </FS:PP>
|
|
// Default to PG
|
|
std::string maturity = "g";
|
|
if (gAgent.prefersAdult())
|
|
{
|
|
// PG,Mature,Adult
|
|
maturity = "gma";
|
|
}
|
|
else if (gAgent.prefersMature())
|
|
{
|
|
// PG,Mature
|
|
maturity = "gm";
|
|
}
|
|
subs["MATURITY"] = maturity;
|
|
url = LLWeb::expandURLSubstitutions(url, subs);
|
|
mWebBrowser->navigateTo(url, HTTP_CONTENT_TEXT_HTML);
|
|
}
|
|
|
|
// static
|
|
void LLPanelDirWeb::onClickHome( void* data )
|
|
{
|
|
LLPanelDirWeb* self = (LLPanelDirWeb*)data;
|
|
if (!self)
|
|
return;
|
|
self->navigateToDefaultPage();
|
|
}
|
|
|
|
void LLPanelDirWeb::handleMediaEvent(LLPluginClassMedia* self, EMediaEvent event)
|
|
{
|
|
if (event == MEDIA_EVENT_LOCATION_CHANGED)
|
|
{
|
|
const std::string url = self->getLocation();
|
|
if (url.length())
|
|
mStatusBarText->setText(url);
|
|
}
|
|
else if (event == MEDIA_EVENT_NAVIGATE_COMPLETE)
|
|
{
|
|
// we populate the status bar with URLs as they change so clear it now we're done
|
|
const std::string end_str = "";
|
|
mStatusBarText->setText(end_str);
|
|
}
|
|
else if (event == MEDIA_EVENT_STATUS_TEXT_CHANGED)
|
|
{
|
|
const std::string text = self->getStatusText();
|
|
if (text.length())
|
|
mStatusBarText->setText(text);
|
|
}
|
|
else if (event == MEDIA_EVENT_LINK_HOVERED)
|
|
{
|
|
const std::string link = self->getHoverLink();
|
|
mStatusBarText->setText(link);
|
|
}
|
|
}
|
|
|
|
// <FS:Ansariel> Select default search element on tab change
|
|
bool LLPanelDirWeb::focusFirstItem(bool prefer_text_fields, bool focus_flash)
|
|
{
|
|
mWebBrowser->setFocus(true);
|
|
return true;
|
|
}
|
|
// </FS:Ansariel>
|