PageRenderTime 37ms CodeModel.GetById 11ms app.highlight 20ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llurlentry.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 429 lines | 238 code | 51 blank | 140 comment | 0 complexity | 8d0a0247294f25cc8b311cae4b5918c9 MD5 | raw file
  1/** 
  2 * @file llurlentry.h
  3 * @author Martin Reddy
  4 * @brief Describes the Url types that can be registered in LLUrlRegistry
  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#ifndef LL_LLURLENTRY_H
 29#define LL_LLURLENTRY_H
 30
 31#include "lluuid.h"
 32#include "lluicolor.h"
 33#include "llstyle.h"
 34
 35#include "llhost.h" // for resolving parcel name by parcel id
 36
 37#include <boost/signals2.hpp>
 38#include <boost/regex.hpp>
 39#include <string>
 40#include <map>
 41
 42class LLAvatarName;
 43
 44typedef boost::signals2::signal<void (const std::string& url,
 45									  const std::string& label,
 46									  const std::string& icon)> LLUrlLabelSignal;
 47typedef LLUrlLabelSignal::slot_type LLUrlLabelCallback;
 48
 49///
 50/// LLUrlEntryBase is the base class of all Url types registered in the 
 51/// LLUrlRegistry. Each derived classes provides a regular expression
 52/// to match the Url type (e.g., http://... or secondlife://...) along
 53/// with an optional icon to display next to instances of the Url in
 54/// a text display and a XUI file to use for any context menu popup.
 55/// Functions are also provided to compute an appropriate label and
 56/// tooltip/status bar text for the Url.
 57///
 58/// Some derived classes of LLUrlEntryBase may wish to compute an
 59/// appropriate label for a Url by asking the server for information.
 60/// You must therefore provide a callback method, so that you can be
 61/// notified when an updated label has been received from the server.
 62/// This label should then be used to replace any previous label
 63/// that you received from getLabel() for the Url in question.
 64///
 65class LLUrlEntryBase
 66{
 67public:
 68	LLUrlEntryBase();
 69	virtual ~LLUrlEntryBase();
 70	
 71	/// Return the regex pattern that matches this Url 
 72	boost::regex getPattern() const { return mPattern; }
 73
 74	/// Return the url from a string that matched the regex
 75	virtual std::string getUrl(const std::string &string) const;
 76
 77	/// Given a matched Url, return a label for the Url
 78	virtual std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) { return url; }
 79
 80	/// Return an icon that can be displayed next to Urls of this type
 81	virtual std::string getIcon(const std::string &url);
 82
 83	/// Return the style to render the displayed text
 84	virtual LLStyle::Params getStyle() const;
 85
 86	/// Given a matched Url, return a tooltip string for the hyperlink
 87	virtual std::string getTooltip(const std::string &string) const { return mTooltip; }
 88
 89	/// Return the name of a XUI file containing the context menu items
 90	std::string getMenuName() const { return mMenuName; }
 91
 92	/// Return the name of a SL location described by this Url, if any
 93	virtual std::string getLocation(const std::string &url) const { return ""; }
 94
 95	/// Should this link text be underlined only when mouse is hovered over it?
 96	virtual bool underlineOnHoverOnly(const std::string &string) const { return false; }
 97
 98	virtual LLUUID	getID(const std::string &string) const { return LLUUID::null; }
 99
100	bool isLinkDisabled() const;
101
102protected:
103	std::string getIDStringFromUrl(const std::string &url) const;
104	std::string escapeUrl(const std::string &url) const;
105	std::string unescapeUrl(const std::string &url) const;
106	std::string getLabelFromWikiLink(const std::string &url) const;
107	std::string getUrlFromWikiLink(const std::string &string) const;
108	void addObserver(const std::string &id, const std::string &url, const LLUrlLabelCallback &cb); 
109	virtual void callObservers(const std::string &id, const std::string &label, const std::string& icon);
110
111	typedef struct {
112		std::string url;
113		LLUrlLabelSignal *signal;
114	} LLUrlEntryObserver;
115
116	boost::regex                                   	mPattern;
117	std::string                                    	mIcon;
118	std::string                                    	mMenuName;
119	std::string                                    	mTooltip;
120	std::multimap<std::string, LLUrlEntryObserver>	mObservers;
121};
122
123///
124/// LLUrlEntryHTTP Describes generic http: and https: Urls
125///
126class LLUrlEntryHTTP : public LLUrlEntryBase
127{
128public:
129	LLUrlEntryHTTP();
130	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
131};
132
133///
134/// LLUrlEntryHTTPLabel Describes generic http: and https: Urls with custom labels
135///
136class LLUrlEntryHTTPLabel : public LLUrlEntryBase
137{
138public:
139	LLUrlEntryHTTPLabel();
140	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
141	/*virtual*/ std::string getTooltip(const std::string &string) const;
142	/*virtual*/ std::string getUrl(const std::string &string) const;
143};
144
145///
146/// LLUrlEntryHTTPNoProtocol Describes generic Urls like www.google.com
147///
148class LLUrlEntryHTTPNoProtocol : public LLUrlEntryBase
149{
150public:
151	LLUrlEntryHTTPNoProtocol();
152	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
153	/*virtual*/ std::string getUrl(const std::string &string) const;
154};
155
156///
157/// LLUrlEntrySLURL Describes http://slurl.com/... Urls
158///
159class LLUrlEntrySLURL : public LLUrlEntryBase
160{
161public:
162	LLUrlEntrySLURL();
163	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
164	/*virtual*/ std::string getLocation(const std::string &url) const;
165};
166
167///
168/// LLUrlEntryAgent Describes a Second Life agent Url, e.g.,
169/// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/about
170class LLUrlEntryAgent : public LLUrlEntryBase
171{
172public:
173	LLUrlEntryAgent();
174	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
175	/*virtual*/ std::string getIcon(const std::string &url);
176	/*virtual*/ std::string getTooltip(const std::string &string) const;
177	/*virtual*/ LLStyle::Params getStyle() const;
178	/*virtual*/ LLUUID	getID(const std::string &string) const;
179	/*virtual*/ bool underlineOnHoverOnly(const std::string &string) const;
180protected:
181	/*virtual*/ void callObservers(const std::string &id, const std::string &label, const std::string& icon);
182private:
183	void onAvatarNameCache(const LLUUID& id, const LLAvatarName& av_name);
184};
185
186///
187/// LLUrlEntryAgentName Describes a Second Life agent name Url, e.g.,
188/// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/(completename|displayname|username)
189/// that displays various forms of user name
190/// This is a base class for the various implementations of name display
191class LLUrlEntryAgentName : public LLUrlEntryBase, public boost::signals2::trackable
192{
193public:
194	LLUrlEntryAgentName();
195	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
196	/*virtual*/ LLStyle::Params getStyle() const;
197protected:
198	// override this to pull out relevant name fields
199	virtual std::string getName(const LLAvatarName& avatar_name) = 0;
200private:
201	void onAvatarNameCache(const LLUUID& id, const LLAvatarName& av_name);
202};
203
204
205///
206/// LLUrlEntryAgentCompleteName Describes a Second Life agent name Url, e.g.,
207/// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/completename
208/// that displays the full display name + user name for an avatar
209/// such as "James Linden (james.linden)"
210class LLUrlEntryAgentCompleteName : public LLUrlEntryAgentName
211{
212public:
213	LLUrlEntryAgentCompleteName();
214private:
215	/*virtual*/ std::string getName(const LLAvatarName& avatar_name);
216};
217
218///
219/// LLUrlEntryAgentDisplayName Describes a Second Life agent display name Url, e.g.,
220/// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/displayname
221/// that displays the just the display name for an avatar
222/// such as "James Linden"
223class LLUrlEntryAgentDisplayName : public LLUrlEntryAgentName
224{
225public:
226	LLUrlEntryAgentDisplayName();
227private:
228	/*virtual*/ std::string getName(const LLAvatarName& avatar_name);
229};
230
231///
232/// LLUrlEntryAgentUserName Describes a Second Life agent username Url, e.g.,
233/// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/username
234/// that displays the just the display name for an avatar
235/// such as "james.linden"
236class LLUrlEntryAgentUserName : public LLUrlEntryAgentName
237{
238public:
239	LLUrlEntryAgentUserName();
240private:
241	/*virtual*/ std::string getName(const LLAvatarName& avatar_name);
242};
243
244///
245/// LLUrlEntryGroup Describes a Second Life group Url, e.g.,
246/// secondlife:///app/group/00005ff3-4044-c79f-9de8-fb28ae0df991/about
247///
248class LLUrlEntryGroup : public LLUrlEntryBase
249{
250public:
251	LLUrlEntryGroup();
252	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
253	/*virtual*/ LLStyle::Params getStyle() const;
254	/*virtual*/ LLUUID	getID(const std::string &string) const;
255private:
256	void onGroupNameReceived(const LLUUID& id, const std::string& name, bool is_group);
257};
258
259///
260/// LLUrlEntryInventory Describes a Second Life inventory Url, e.g.,
261/// secondlife:///app/inventory/0e346d8b-4433-4d66-a6b0-fd37083abc4c/select
262///
263class LLUrlEntryInventory : public LLUrlEntryBase
264{
265public:
266	LLUrlEntryInventory();
267	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
268private:
269};
270
271///
272/// LLUrlEntryObjectIM Describes a Second Life inspector for the object Url, e.g.,
273/// secondlife:///app/objectim/7bcd7864-da6b-e43f-4486-91d28a28d95b?name=Object&owner=3de548e1-57be-cfea-2b78-83ae3ad95998&slurl=Danger!%20Danger!/200/200/30/&groupowned=1
274///
275class LLUrlEntryObjectIM : public LLUrlEntryBase
276{
277public:
278	LLUrlEntryObjectIM();
279	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
280	/*virtual*/ std::string getLocation(const std::string &url) const;
281private:
282};
283
284///
285/// LLUrlEntryParcel Describes a Second Life parcel Url, e.g.,
286/// secondlife:///app/parcel/0000060e-4b39-e00b-d0c3-d98b1934e3a8/about
287///
288class LLUrlEntryParcel : public LLUrlEntryBase
289{
290public:
291	struct LLParcelData
292	{
293		LLUUID		parcel_id;
294		std::string	name;
295		std::string	sim_name;
296		F32			global_x;
297		F32			global_y;
298		F32			global_z;
299	};
300
301	LLUrlEntryParcel();
302	~LLUrlEntryParcel();
303	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
304
305	// Sends a parcel info request to sim.
306	void sendParcelInfoRequest(const LLUUID& parcel_id);
307
308	// Calls observers of certain parcel id providing them with parcel label.
309	void onParcelInfoReceived(const std::string &id, const std::string &label);
310
311	// Processes parcel label and triggers notifying observers.
312	static void processParcelInfo(const LLParcelData& parcel_data);
313
314	// Next 4 setters are used to update agent and viewer connection information
315	// upon events like user login, viewer disconnect and user changing region host.
316	// These setters are made public to be accessible from newview and should not be
317	// used in other cases.
318	static void setAgentID(const LLUUID& id) { sAgentID = id; }
319	static void setSessionID(const LLUUID& id) { sSessionID = id; }
320	static void setRegionHost(const LLHost& host) { sRegionHost = host; }
321	static void setDisconnected(bool disconnected) { sDisconnected = disconnected; }
322
323private:
324	static LLUUID						sAgentID;
325	static LLUUID						sSessionID;
326	static LLHost						sRegionHost;
327	static bool							sDisconnected;
328	static std::set<LLUrlEntryParcel*>	sParcelInfoObservers;
329};
330
331///
332/// LLUrlEntryPlace Describes a Second Life location Url, e.g.,
333/// secondlife://Ahern/50/50/50
334///
335class LLUrlEntryPlace : public LLUrlEntryBase
336{
337public:
338	LLUrlEntryPlace();
339	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
340	/*virtual*/ std::string getLocation(const std::string &url) const;
341};
342
343///
344/// LLUrlEntryRegion Describes a Second Life location Url, e.g.,
345/// secondlife:///app/region/Ahern/128/128/0
346///
347class LLUrlEntryRegion : public LLUrlEntryBase
348{
349public:
350	LLUrlEntryRegion();
351	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
352	/*virtual*/ std::string getLocation(const std::string &url) const;
353};
354
355///
356/// LLUrlEntryTeleport Describes a Second Life teleport Url, e.g.,
357/// secondlife:///app/teleport/Ahern/50/50/50/
358///
359class LLUrlEntryTeleport : public LLUrlEntryBase
360{
361public:
362	LLUrlEntryTeleport();
363	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
364	/*virtual*/ std::string getLocation(const std::string &url) const;
365};
366
367///
368/// LLUrlEntrySL Describes a generic SLURL, e.g., a Url that starts
369/// with secondlife:// (used as a catch-all for cases not matched above)
370///
371class LLUrlEntrySL : public LLUrlEntryBase
372{
373public:
374	LLUrlEntrySL();
375	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
376};
377
378///
379/// LLUrlEntrySLLabel Describes a generic SLURL, e.g., a Url that starts
380/// with secondlife:// with the ability to specify a custom label.
381///
382class LLUrlEntrySLLabel : public LLUrlEntryBase
383{
384public:
385	LLUrlEntrySLLabel();
386	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
387	/*virtual*/ std::string getUrl(const std::string &string) const;
388	/*virtual*/ std::string getTooltip(const std::string &string) const;
389	/*virtual*/ bool underlineOnHoverOnly(const std::string &string) const;
390};
391
392///
393/// LLUrlEntryWorldMap Describes a Second Life worldmap Url, e.g.,
394/// secondlife:///app/worldmap/Ahern/50/50/50
395///
396class LLUrlEntryWorldMap : public LLUrlEntryBase
397{
398public:
399	LLUrlEntryWorldMap();
400	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
401	/*virtual*/ std::string getLocation(const std::string &url) const;
402};
403
404///
405/// LLUrlEntryNoLink lets us turn of URL detection with <nolink>...</nolink> tags
406///
407class LLUrlEntryNoLink : public LLUrlEntryBase
408{
409public:
410	LLUrlEntryNoLink();
411	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
412	/*virtual*/ std::string getUrl(const std::string &string) const;
413	/*virtual*/ LLStyle::Params getStyle() const;
414};
415
416///
417/// LLUrlEntryIcon describes an icon with <icon>...</icon> tags
418///
419class LLUrlEntryIcon : public LLUrlEntryBase
420{
421public:
422	LLUrlEntryIcon();
423	/*virtual*/ std::string getUrl(const std::string &string) const;
424	/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
425	/*virtual*/ std::string getIcon(const std::string &url);
426};
427
428
429#endif