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