PageRenderTime 86ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llcommandmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 172 lines | 103 code | 32 blank | 37 comment | 6 complexity | a985540305a1322d284930f4daaf329e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcommandmanager.cpp
  3. * @brief LLCommandManager class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. // A control that displays the name of the chosen item, which when
  27. // clicked shows a scrolling box of options.
  28. #include "linden_common.h"
  29. #include "llcommandmanager.h"
  30. #include "lldir.h"
  31. #include "llerror.h"
  32. #include "llxuiparser.h"
  33. #include <boost/foreach.hpp>
  34. //
  35. // LLCommandId class
  36. //
  37. const LLCommandId LLCommandId::null = LLCommandId("null command");
  38. //
  39. // LLCommand class
  40. //
  41. LLCommand::Params::Params()
  42. : available_in_toybox("available_in_toybox", false)
  43. , icon("icon")
  44. , label_ref("label_ref")
  45. , name("name")
  46. , tooltip_ref("tooltip_ref")
  47. , execute_function("execute_function")
  48. , execute_parameters("execute_parameters")
  49. , execute_stop_function("execute_stop_function")
  50. , execute_stop_parameters("execute_stop_parameters")
  51. , is_enabled_function("is_enabled_function")
  52. , is_enabled_parameters("is_enabled_parameters")
  53. , is_running_function("is_running_function")
  54. , is_running_parameters("is_running_parameters")
  55. , is_starting_function("is_starting_function")
  56. , is_starting_parameters("is_starting_parameters")
  57. {
  58. }
  59. LLCommand::LLCommand(const LLCommand::Params& p)
  60. : mIdentifier(p.name)
  61. , mAvailableInToybox(p.available_in_toybox)
  62. , mIcon(p.icon)
  63. , mLabelRef(p.label_ref)
  64. , mName(p.name)
  65. , mTooltipRef(p.tooltip_ref)
  66. , mExecuteFunction(p.execute_function)
  67. , mExecuteParameters(p.execute_parameters)
  68. , mExecuteStopFunction(p.execute_stop_function)
  69. , mExecuteStopParameters(p.execute_stop_parameters)
  70. , mIsEnabledFunction(p.is_enabled_function)
  71. , mIsEnabledParameters(p.is_enabled_parameters)
  72. , mIsRunningFunction(p.is_running_function)
  73. , mIsRunningParameters(p.is_running_parameters)
  74. , mIsStartingFunction(p.is_starting_function)
  75. , mIsStartingParameters(p.is_starting_parameters)
  76. {
  77. }
  78. //
  79. // LLCommandManager class
  80. //
  81. LLCommandManager::LLCommandManager()
  82. {
  83. }
  84. LLCommandManager::~LLCommandManager()
  85. {
  86. for (CommandVector::iterator cmdIt = mCommands.begin(); cmdIt != mCommands.end(); ++cmdIt)
  87. {
  88. LLCommand * command = *cmdIt;
  89. delete command;
  90. }
  91. }
  92. U32 LLCommandManager::commandCount() const
  93. {
  94. return mCommands.size();
  95. }
  96. LLCommand * LLCommandManager::getCommand(U32 commandIndex)
  97. {
  98. return mCommands[commandIndex];
  99. }
  100. LLCommand * LLCommandManager::getCommand(const LLCommandId& commandId)
  101. {
  102. LLCommand * command_match = NULL;
  103. CommandIndexMap::const_iterator found = mCommandIndices.find(commandId.uuid());
  104. if (found != mCommandIndices.end())
  105. {
  106. command_match = mCommands[found->second];
  107. }
  108. return command_match;
  109. }
  110. void LLCommandManager::addCommand(LLCommand * command)
  111. {
  112. LLCommandId command_id = command->id();
  113. mCommandIndices[command_id.uuid()] = mCommands.size();
  114. mCommands.push_back(command);
  115. lldebugs << "Successfully added command: " << command->name() << llendl;
  116. }
  117. //static
  118. bool LLCommandManager::load()
  119. {
  120. LLCommandManager& mgr = LLCommandManager::instance();
  121. std::string commands_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "commands.xml");
  122. LLCommandManager::Params commandsParams;
  123. LLSimpleXUIParser parser;
  124. if (!parser.readXUI(commands_file, commandsParams))
  125. {
  126. llerrs << "Unable to load xml file: " << commands_file << llendl;
  127. return false;
  128. }
  129. if (!commandsParams.validateBlock())
  130. {
  131. llerrs << "Invalid commands file: " << commands_file << llendl;
  132. return false;
  133. }
  134. BOOST_FOREACH(LLCommand::Params& commandParams, commandsParams.commands)
  135. {
  136. LLCommand * command = new LLCommand(commandParams);
  137. mgr.addCommand(command);
  138. }
  139. return true;
  140. }