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