/indra/newview/llviewerhelp.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 146 lines · 81 code · 21 blank · 44 comment · 11 complexity · f1fdb51dceb00974fd72169892de9703 MD5 · raw file

  1. /**
  2. * @file llviewerhelp.cpp
  3. * @brief Utility functions for the Help system
  4. * @author Tofu Linden
  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 "llviewerprecompiledheaders.h"
  28. #include "llcommandhandler.h"
  29. #include "llfloaterhelpbrowser.h"
  30. #include "llfloaterreg.h"
  31. #include "llfocusmgr.h"
  32. #include "llviewercontrol.h"
  33. #include "llappviewer.h"
  34. #include "lllogininstance.h"
  35. #include "llviewerhelputil.h"
  36. #include "llviewerhelp.h"
  37. // support for secondlife:///app/help/{TOPIC} SLapps
  38. class LLHelpHandler : public LLCommandHandler
  39. {
  40. public:
  41. // requests will be throttled from a non-trusted browser
  42. LLHelpHandler() : LLCommandHandler("help", UNTRUSTED_THROTTLE) {}
  43. bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
  44. {
  45. LLViewerHelp* vhelp = LLViewerHelp::getInstance();
  46. if (! vhelp)
  47. {
  48. return false;
  49. }
  50. // get the requested help topic name, or use the fallback if none
  51. std::string help_topic = vhelp->defaultTopic();
  52. if (params.size() >= 1)
  53. {
  54. help_topic = params[0].asString();
  55. }
  56. vhelp->showTopic(help_topic);
  57. return true;
  58. }
  59. };
  60. LLHelpHandler gHelpHandler;
  61. //////////////////////////////
  62. // implement LLHelp interface
  63. std::string LLViewerHelp::getURL(const std::string &topic)
  64. {
  65. // allow overriding the help server with a local help file
  66. if( gSavedSettings.getBOOL("HelpUseLocal") )
  67. {
  68. return "__local";
  69. }
  70. // if the help topic is empty, use the default topic
  71. std::string help_topic = topic;
  72. if (help_topic.empty())
  73. {
  74. help_topic = defaultTopic();
  75. }
  76. // f1 help topic means: if the user is not logged in yet, show
  77. // the pre-login topic instead of the default fallback topic,
  78. // otherwise show help for the focused item
  79. if (help_topic == f1HelpTopic())
  80. {
  81. help_topic = getTopicFromFocus();
  82. if (help_topic == defaultTopic() && ! LLLoginInstance::getInstance()->authSuccess())
  83. {
  84. help_topic = preLoginTopic();
  85. }
  86. }
  87. return LLViewerHelpUtil::buildHelpURL( help_topic );
  88. }
  89. void LLViewerHelp::showTopic(const std::string& topic)
  90. {
  91. LLFloaterReg::showInstance("help_browser", topic);
  92. }
  93. std::string LLViewerHelp::defaultTopic()
  94. {
  95. // *hack: to be done properly
  96. return "this_is_fallbacktopic";
  97. }
  98. std::string LLViewerHelp::preLoginTopic()
  99. {
  100. // *hack: to be done properly
  101. return "pre_login_help";
  102. }
  103. std::string LLViewerHelp::f1HelpTopic()
  104. {
  105. // *hack: to be done properly
  106. return "f1_help";
  107. }
  108. //////////////////////////////
  109. // our own interfaces
  110. std::string LLViewerHelp::getTopicFromFocus()
  111. {
  112. // use UI element with viewer's keyboard focus as basis for searching
  113. LLUICtrl* focused = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
  114. if (focused)
  115. {
  116. std::string topic;
  117. if (focused->findHelpTopic(topic))
  118. {
  119. return topic;
  120. }
  121. }
  122. // didn't find a help topic in the UI hierarchy for focused
  123. // element, return the fallback topic name instead.
  124. return defaultTopic();
  125. }