/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. #include "linden_common.h"
  28. #include "llurlaction.h"
  29. #include "llview.h"
  30. #include "llwindow.h"
  31. #include "llurlregistry.h"
  32. // global state for the callback functions
  33. LLUrlAction::url_callback_t LLUrlAction::sOpenURLCallback;
  34. LLUrlAction::url_callback_t LLUrlAction::sOpenURLInternalCallback;
  35. LLUrlAction::url_callback_t LLUrlAction::sOpenURLExternalCallback;
  36. LLUrlAction::execute_url_callback_t LLUrlAction::sExecuteSLURLCallback;
  37. void LLUrlAction::setOpenURLCallback(url_callback_t cb)
  38. {
  39. sOpenURLCallback = cb;
  40. }
  41. void LLUrlAction::setOpenURLInternalCallback(url_callback_t cb)
  42. {
  43. sOpenURLInternalCallback = cb;
  44. }
  45. void LLUrlAction::setOpenURLExternalCallback(url_callback_t cb)
  46. {
  47. sOpenURLExternalCallback = cb;
  48. }
  49. void LLUrlAction::setExecuteSLURLCallback(execute_url_callback_t cb)
  50. {
  51. sExecuteSLURLCallback = cb;
  52. }
  53. void LLUrlAction::openURL(std::string url)
  54. {
  55. if (sOpenURLCallback)
  56. {
  57. sOpenURLCallback(url);
  58. }
  59. }
  60. void LLUrlAction::openURLInternal(std::string url)
  61. {
  62. if (sOpenURLInternalCallback)
  63. {
  64. sOpenURLInternalCallback(url);
  65. }
  66. }
  67. void LLUrlAction::openURLExternal(std::string url)
  68. {
  69. if (sOpenURLExternalCallback)
  70. {
  71. sOpenURLExternalCallback(url);
  72. }
  73. }
  74. void LLUrlAction::executeSLURL(std::string url)
  75. {
  76. if (sExecuteSLURLCallback)
  77. {
  78. sExecuteSLURLCallback(url);
  79. }
  80. }
  81. void LLUrlAction::clickAction(std::string url)
  82. {
  83. // Try to handle as SLURL first, then http Url
  84. if ( (sExecuteSLURLCallback) && !sExecuteSLURLCallback(url) )
  85. {
  86. if (sOpenURLCallback)
  87. {
  88. sOpenURLCallback(url);
  89. }
  90. }
  91. }
  92. void LLUrlAction::teleportToLocation(std::string url)
  93. {
  94. LLUrlMatch match;
  95. if (LLUrlRegistry::instance().findUrl(url, match))
  96. {
  97. if (! match.getLocation().empty())
  98. {
  99. executeSLURL("secondlife:///app/teleport/" + match.getLocation());
  100. }
  101. }
  102. }
  103. void LLUrlAction::showLocationOnMap(std::string url)
  104. {
  105. LLUrlMatch match;
  106. if (LLUrlRegistry::instance().findUrl(url, match))
  107. {
  108. if (! match.getLocation().empty())
  109. {
  110. executeSLURL("secondlife:///app/worldmap/" + match.getLocation());
  111. }
  112. }
  113. }
  114. void LLUrlAction::copyURLToClipboard(std::string url)
  115. {
  116. LLView::getWindow()->copyTextToClipboard(utf8str_to_wstring(url));
  117. }
  118. void LLUrlAction::copyLabelToClipboard(std::string url)
  119. {
  120. LLUrlMatch match;
  121. if (LLUrlRegistry::instance().findUrl(url, match))
  122. {
  123. LLView::getWindow()->copyTextToClipboard(utf8str_to_wstring(match.getLabel()));
  124. }
  125. }
  126. void LLUrlAction::showProfile(std::string url)
  127. {
  128. // Get id from 'secondlife:///app/{cmd}/{id}/{action}'
  129. // and show its profile
  130. LLURI uri(url);
  131. LLSD path_array = uri.pathArray();
  132. if (path_array.size() == 4)
  133. {
  134. std::string id_str = path_array.get(2).asString();
  135. if (LLUUID::validate(id_str))
  136. {
  137. std::string cmd_str = path_array.get(1).asString();
  138. executeSLURL("secondlife:///app/" + cmd_str + "/" + id_str + "/about");
  139. }
  140. }
  141. }