PageRenderTime 17ms CodeModel.GetById 6ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llurlregistry.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 97 lines | 30 code | 13 blank | 54 comment | 0 complexity | 394c38263d27e6686a3e317ab07636e9 MD5 | raw file
 1/** 
 2 * @file llurlregistry.h
 3 * @author Martin Reddy
 4 * @brief Contains a set of Url types that can be matched in a string
 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_LLURLREGISTRY_H
29#define LL_LLURLREGISTRY_H
30
31#include "llurlentry.h"
32#include "llurlmatch.h"
33#include "llsingleton.h"
34#include "llstring.h"
35
36#include <string>
37#include <vector>
38
39/// This default callback for findUrl() simply ignores any label updates
40void LLUrlRegistryNullCallback(const std::string &url,
41							   const std::string &label,
42							   const std::string &icon);
43
44///
45/// LLUrlRegistry is a singleton that contains a set of Url types that
46/// can be matched in string. E.g., http:// or secondlife:// Urls.
47///
48/// Clients call the findUrl() method on a string to locate the first
49/// occurence of a supported Urls in that string. If findUrl() returns
50/// true, the LLUrlMatch object will be updated to describe the Url
51/// that was matched, including a label that can be used to hyperlink
52/// the Url, an icon to display next to the Url, and a XUI menu that
53/// can be used as a popup context menu for that Url.
54///
55/// New Url types can be added to the registry with the registerUrl
56/// method. E.g., to add support for a new secondlife:///app/ Url.
57///
58/// Computing the label for a Url could involve a roundtrip request
59/// to the server (e.g., to find the actual agent or group name).
60/// As such, you can provide a callback method that will get invoked
61/// when a new label is available for one of your matched Urls.
62///
63class LLUrlRegistry : public LLSingleton<LLUrlRegistry>
64{
65public:
66	~LLUrlRegistry();
67
68	/// add a new Url handler to the registry (will be freed on destruction)
69	/// optionally force it to the front of the list, making it take
70	/// priority over other regular expression matches for URLs
71	void registerUrl(LLUrlEntryBase *url, bool force_front = false);
72
73	/// get the next Url in an input string, starting at a given character offset
74	/// your callback is invoked if the matched Url's label changes in the future
75	bool findUrl(const std::string &text, LLUrlMatch &match,
76				 const LLUrlLabelCallback &cb = &LLUrlRegistryNullCallback);
77
78	/// a slightly less efficient version of findUrl for wide strings
79	bool findUrl(const LLWString &text, LLUrlMatch &match,
80				 const LLUrlLabelCallback &cb = &LLUrlRegistryNullCallback);
81
82	// return true if the given string contains a URL that findUrl would match
83	bool hasUrl(const std::string &text);
84	bool hasUrl(const LLWString &text);
85
86	// return true if the given string is a URL that findUrl would match
87	bool isUrl(const std::string &text);
88	bool isUrl(const LLWString &text);
89
90private:
91	LLUrlRegistry();
92	friend class LLSingleton<LLUrlRegistry>;
93
94	std::vector<LLUrlEntryBase *> mUrlEntry;
95};
96
97#endif