PageRenderTime 53ms CodeModel.GetById 19ms app.highlight 27ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llfloaterhelpbrowser.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 162 lines | 101 code | 26 blank | 35 comment | 7 complexity | 9436a16c8a22bee21d437eac02cb6899 MD5 | raw file
  1/** 
  2 * @file llfloaterhelpbrowser.cpp
  3 * @brief HTML Help floater - uses embedded web browser control
  4 *
  5 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llfloaterhelpbrowser.h"
 30
 31#include "llfloaterreg.h"
 32#include "llpluginclassmedia.h"
 33#include "llmediactrl.h"
 34#include "llviewerwindow.h"
 35#include "llviewercontrol.h"
 36#include "llweb.h"
 37#include "llui.h"
 38
 39#include "llurlhistory.h"
 40#include "llmediactrl.h"
 41#include "llviewermedia.h"
 42#include "llviewerhelp.h"
 43
 44
 45LLFloaterHelpBrowser::LLFloaterHelpBrowser(const LLSD& key)
 46	: LLFloater(key)
 47{
 48}
 49
 50BOOL LLFloaterHelpBrowser::postBuild()
 51{
 52	mBrowser = getChild<LLMediaCtrl>("browser");
 53	mBrowser->addObserver(this);
 54	mBrowser->setErrorPageURL(gSavedSettings.getString("GenericErrorPageURL"));
 55
 56	childSetAction("open_browser", onClickOpenWebBrowser, this);
 57
 58	buildURLHistory();
 59	return TRUE;
 60}
 61
 62void LLFloaterHelpBrowser::buildURLHistory()
 63{
 64	// Get all of the entries in the "browser" collection
 65	LLSD browser_history = LLURLHistory::getURLHistory("browser");
 66
 67	// initialize URL history in the plugin
 68	LLPluginClassMedia *plugin = mBrowser->getMediaPlugin();
 69	if (plugin)
 70	{
 71		plugin->initializeUrlHistory(browser_history);
 72	}
 73}
 74
 75void LLFloaterHelpBrowser::onOpen(const LLSD& key)
 76{
 77	gSavedSettings.setBOOL("HelpFloaterOpen", TRUE);
 78
 79	std::string topic = key.asString();
 80
 81	if (topic == "__local")
 82	{
 83		mBrowser->navigateToLocalPage( "help-offline" , "index.html" );
 84	}
 85	else
 86	{
 87		mBrowser->navigateTo(LLViewerHelp::instance().getURL(topic));
 88	}
 89}
 90
 91//virtual
 92void LLFloaterHelpBrowser::onClose(bool app_quitting)
 93{
 94	if (!app_quitting)
 95	{
 96		gSavedSettings.setBOOL("HelpFloaterOpen", FALSE);
 97	}
 98	// really really destroy the help browser when it's closed, it'll be recreated.
 99	destroy(); // really destroy this dialog on closure, it's relatively heavyweight.
100}
101
102void LLFloaterHelpBrowser::handleMediaEvent(LLPluginClassMedia* self, EMediaEvent event)
103{
104	switch (event) 
105	{
106	case MEDIA_EVENT_LOCATION_CHANGED:
107		setCurrentURL(self->getLocation());
108		break;
109
110	case MEDIA_EVENT_NAVIGATE_BEGIN:
111		getChild<LLUICtrl>("status_text")->setValue(getString("loading_text"));
112		break;
113		
114	case MEDIA_EVENT_NAVIGATE_COMPLETE:
115		getChild<LLUICtrl>("status_text")->setValue(getString("done_text"));
116		break;
117
118	default:
119		break;
120	}
121}
122
123void LLFloaterHelpBrowser::setCurrentURL(const std::string& url)
124{
125	mCurrentURL = url;
126
127	// redirects will navigate momentarily to about:blank, don't add to history
128	if (mCurrentURL != "about:blank")
129	{
130		// Serialize url history
131		LLURLHistory::removeURL("browser", mCurrentURL);
132		LLURLHistory::addURL("browser", mCurrentURL);
133	}
134}
135
136//static 
137void LLFloaterHelpBrowser::onClickClose(void* user_data)
138{
139	LLFloaterHelpBrowser* self = (LLFloaterHelpBrowser*)user_data;
140
141	self->closeFloater();
142}
143
144//static 
145void LLFloaterHelpBrowser::onClickOpenWebBrowser(void* user_data)
146{
147	LLFloaterHelpBrowser* self = (LLFloaterHelpBrowser*)user_data;
148
149	std::string url = self->mCurrentURL.empty() ? 
150		self->mBrowser->getHomePageUrl() :
151		self->mCurrentURL;
152	LLWeb::loadURLExternal(url);
153}
154
155void LLFloaterHelpBrowser::openMedia(const std::string& media_url)
156{
157	// explicitly make the media mime type for this floater since it will
158	// only ever display one type of content (Web).
159	mBrowser->setHomePageUrl(media_url, "text/html");
160	mBrowser->navigateTo(media_url, "text/html");
161	setCurrentURL(media_url);
162}