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