PageRenderTime 34ms CodeModel.GetById 18ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llurlaction.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 159 lines | 111 code | 18 blank | 30 comment | 15 complexity | 99bc619efa1a014508e2a801b977acb5 MD5 | raw file
  1/** 
  2 * @file llurlaction.cpp
  3 * @author Martin Reddy
  4 * @brief A set of actions that can performed on Urls
  5 *
  6 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include "linden_common.h"
 29
 30#include "llurlaction.h"
 31#include "llview.h"
 32#include "llwindow.h"
 33#include "llurlregistry.h"
 34
 35// global state for the callback functions
 36LLUrlAction::url_callback_t 		LLUrlAction::sOpenURLCallback;
 37LLUrlAction::url_callback_t 		LLUrlAction::sOpenURLInternalCallback;
 38LLUrlAction::url_callback_t 		LLUrlAction::sOpenURLExternalCallback;
 39LLUrlAction::execute_url_callback_t LLUrlAction::sExecuteSLURLCallback;
 40
 41
 42void LLUrlAction::setOpenURLCallback(url_callback_t cb)
 43{
 44	sOpenURLCallback = cb;
 45}
 46
 47void LLUrlAction::setOpenURLInternalCallback(url_callback_t cb)
 48{
 49	sOpenURLInternalCallback = cb;
 50}
 51
 52void LLUrlAction::setOpenURLExternalCallback(url_callback_t cb)
 53{
 54	sOpenURLExternalCallback = cb;
 55}
 56
 57void LLUrlAction::setExecuteSLURLCallback(execute_url_callback_t cb)
 58{
 59	sExecuteSLURLCallback = cb;
 60}
 61
 62void LLUrlAction::openURL(std::string url)
 63{
 64	if (sOpenURLCallback)
 65	{
 66		sOpenURLCallback(url);
 67	}
 68}
 69
 70void LLUrlAction::openURLInternal(std::string url)
 71{
 72	if (sOpenURLInternalCallback)
 73	{
 74		sOpenURLInternalCallback(url);
 75	}
 76}
 77
 78void LLUrlAction::openURLExternal(std::string url)
 79{
 80	if (sOpenURLExternalCallback)
 81	{
 82		sOpenURLExternalCallback(url);
 83	}
 84}
 85
 86void LLUrlAction::executeSLURL(std::string url)
 87{
 88	if (sExecuteSLURLCallback)
 89	{
 90		sExecuteSLURLCallback(url);
 91	}
 92}
 93
 94void LLUrlAction::clickAction(std::string url)
 95{
 96	// Try to handle as SLURL first, then http Url
 97	if ( (sExecuteSLURLCallback) && !sExecuteSLURLCallback(url) )
 98	{
 99		if (sOpenURLCallback)
100		{
101			sOpenURLCallback(url);
102		}
103	}
104}
105
106void LLUrlAction::teleportToLocation(std::string url)
107{
108	LLUrlMatch match;
109	if (LLUrlRegistry::instance().findUrl(url, match))
110	{
111		if (! match.getLocation().empty())
112		{
113			executeSLURL("secondlife:///app/teleport/" + match.getLocation());
114		}
115	}	
116}
117
118void LLUrlAction::showLocationOnMap(std::string url)
119{
120	LLUrlMatch match;
121	if (LLUrlRegistry::instance().findUrl(url, match))
122	{
123		if (! match.getLocation().empty())
124		{
125			executeSLURL("secondlife:///app/worldmap/" + match.getLocation());
126		}
127	}	
128}
129
130void LLUrlAction::copyURLToClipboard(std::string url)
131{
132	LLView::getWindow()->copyTextToClipboard(utf8str_to_wstring(url));
133}
134
135void LLUrlAction::copyLabelToClipboard(std::string url)
136{
137	LLUrlMatch match;
138	if (LLUrlRegistry::instance().findUrl(url, match))
139	{
140		LLView::getWindow()->copyTextToClipboard(utf8str_to_wstring(match.getLabel()));
141	}	
142}
143
144void LLUrlAction::showProfile(std::string url)
145{
146	// Get id from 'secondlife:///app/{cmd}/{id}/{action}'
147	// and show its profile
148	LLURI uri(url);
149	LLSD path_array = uri.pathArray();
150	if (path_array.size() == 4)
151	{
152		std::string id_str = path_array.get(2).asString();
153		if (LLUUID::validate(id_str))
154		{
155			std::string cmd_str = path_array.get(1).asString();
156			executeSLURL("secondlife:///app/" + cmd_str + "/" + id_str + "/about");
157		}
158	}
159}