PageRenderTime 80ms CodeModel.GetById 20ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llfloateropenobject.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 255 lines | 174 code | 41 blank | 40 comment | 16 complexity | 968ea3adce911e7eb12f7f5c11ab1569 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloateropenobject.cpp
  3. * @brief LLFloaterOpenObject class implementation
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, 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. /*
  27. * Shows the contents of an object.
  28. * A floater wrapper for LLPanelObjectInventory
  29. */
  30. #include "llviewerprecompiledheaders.h"
  31. #include "llfloateropenobject.h"
  32. #include "llcachename.h"
  33. #include "llbutton.h"
  34. #include "llnotificationsutil.h"
  35. #include "lltextbox.h"
  36. #include "llinventorybridge.h"
  37. #include "llfloaterinventory.h"
  38. #include "llinventorymodel.h"
  39. #include "llinventorypanel.h"
  40. #include "llpanelobjectinventory.h"
  41. #include "llfloaterreg.h"
  42. #include "llselectmgr.h"
  43. #include "lluiconstants.h"
  44. #include "llviewerobject.h"
  45. #include "lluictrlfactory.h"
  46. #include "llviewerwindow.h"
  47. LLFloaterOpenObject::LLFloaterOpenObject(const LLSD& key)
  48. : LLFloater(key),
  49. mPanelInventoryObject(NULL),
  50. mDirty(TRUE)
  51. {
  52. mCommitCallbackRegistrar.add("OpenObject.MoveToInventory", boost::bind(&LLFloaterOpenObject::onClickMoveToInventory, this));
  53. mCommitCallbackRegistrar.add("OpenObject.MoveAndWear", boost::bind(&LLFloaterOpenObject::onClickMoveAndWear, this));
  54. }
  55. LLFloaterOpenObject::~LLFloaterOpenObject()
  56. {
  57. // sInstance = NULL;
  58. }
  59. // virtual
  60. BOOL LLFloaterOpenObject::postBuild()
  61. {
  62. getChild<LLUICtrl>("object_name")->setTextArg("[DESC]", std::string("Object") ); // *Note: probably do not want to translate this
  63. mPanelInventoryObject = getChild<LLPanelObjectInventory>("object_contents");
  64. refresh();
  65. return TRUE;
  66. }
  67. void LLFloaterOpenObject::onOpen(const LLSD& key)
  68. {
  69. LLObjectSelectionHandle object_selection = LLSelectMgr::getInstance()->getSelection();
  70. if (object_selection->getRootObjectCount() != 1)
  71. {
  72. LLNotificationsUtil::add("UnableToViewContentsMoreThanOne");
  73. closeFloater();
  74. return;
  75. }
  76. if(!(object_selection->getPrimaryObject()))
  77. {
  78. closeFloater();
  79. return;
  80. }
  81. mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
  82. refresh();
  83. }
  84. void LLFloaterOpenObject::refresh()
  85. {
  86. mPanelInventoryObject->refresh();
  87. std::string name = "";
  88. BOOL enabled = FALSE;
  89. LLSelectNode* node = mObjectSelection->getFirstRootNode();
  90. if (node)
  91. {
  92. name = node->mName;
  93. enabled = TRUE;
  94. }
  95. else
  96. {
  97. name = "";
  98. enabled = FALSE;
  99. }
  100. getChild<LLUICtrl>("object_name")->setTextArg("[DESC]", name);
  101. getChildView("copy_to_inventory_button")->setEnabled(enabled);
  102. getChildView("copy_and_wear_button")->setEnabled(enabled);
  103. }
  104. void LLFloaterOpenObject::draw()
  105. {
  106. if (mDirty)
  107. {
  108. refresh();
  109. mDirty = FALSE;
  110. }
  111. LLFloater::draw();
  112. }
  113. void LLFloaterOpenObject::dirty()
  114. {
  115. mDirty = TRUE;
  116. }
  117. void LLFloaterOpenObject::moveToInventory(bool wear)
  118. {
  119. if (mObjectSelection->getRootObjectCount() != 1)
  120. {
  121. LLNotificationsUtil::add("OnlyCopyContentsOfSingleItem");
  122. return;
  123. }
  124. LLSelectNode* node = mObjectSelection->getFirstRootNode();
  125. if (!node) return;
  126. LLViewerObject* object = node->getObject();
  127. if (!object) return;
  128. LLUUID object_id = object->getID();
  129. std::string name = node->mName;
  130. // Either create a sub-folder of clothing, or of the root folder.
  131. LLUUID parent_category_id;
  132. if (wear)
  133. {
  134. parent_category_id = gInventory.findCategoryUUIDForType(
  135. LLFolderType::FT_CLOTHING);
  136. }
  137. else
  138. {
  139. parent_category_id = gInventory.getRootFolderID();
  140. }
  141. LLCategoryCreate* cat_data = new LLCategoryCreate(object_id, wear);
  142. LLUUID category_id = gInventory.createNewCategory(parent_category_id,
  143. LLFolderType::FT_NONE,
  144. name,
  145. callbackCreateInventoryCategory,
  146. (void*)cat_data);
  147. //If we get a null category ID, we are using a capability in createNewCategory and we will
  148. //handle the following in the callbackCreateInventoryCategory routine.
  149. if ( category_id.notNull() )
  150. {
  151. delete cat_data;
  152. LLCatAndWear* data = new LLCatAndWear;
  153. data->mCatID = category_id;
  154. data->mWear = wear;
  155. data->mFolderResponded = false;
  156. // Copy and/or move the items into the newly created folder.
  157. // Ignore any "you're going to break this item" messages.
  158. BOOL success = move_inv_category_world_to_agent(object_id, category_id, TRUE,
  159. callbackMoveInventory,
  160. (void*)data);
  161. if (!success)
  162. {
  163. delete data;
  164. data = NULL;
  165. LLNotificationsUtil::add("OpenObjectCannotCopy");
  166. }
  167. }
  168. }
  169. // static
  170. void LLFloaterOpenObject::callbackCreateInventoryCategory(const LLSD& result, void* data)
  171. {
  172. LLCategoryCreate* cat_data = (LLCategoryCreate*)data;
  173. LLUUID category_id = result["folder_id"].asUUID();
  174. LLCatAndWear* wear_data = new LLCatAndWear;
  175. wear_data->mCatID = category_id;
  176. wear_data->mWear = cat_data->mWear;
  177. wear_data->mFolderResponded = true;
  178. // Copy and/or move the items into the newly created folder.
  179. // Ignore any "you're going to break this item" messages.
  180. BOOL success = move_inv_category_world_to_agent(cat_data->mObjectID, category_id, TRUE,
  181. callbackMoveInventory,
  182. (void*)wear_data);
  183. if (!success)
  184. {
  185. delete wear_data;
  186. wear_data = NULL;
  187. LLNotificationsUtil::add("OpenObjectCannotCopy");
  188. }
  189. delete cat_data;
  190. }
  191. // static
  192. void LLFloaterOpenObject::callbackMoveInventory(S32 result, void* data)
  193. {
  194. LLCatAndWear* cat = (LLCatAndWear*)data;
  195. if (result == 0)
  196. {
  197. LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
  198. if (active_panel)
  199. {
  200. active_panel->setSelection(cat->mCatID, TAKE_FOCUS_NO);
  201. }
  202. }
  203. delete cat;
  204. }
  205. void LLFloaterOpenObject::onClickMoveToInventory()
  206. {
  207. moveToInventory(false);
  208. closeFloater();
  209. }
  210. void LLFloaterOpenObject::onClickMoveAndWear()
  211. {
  212. moveToInventory(true);
  213. closeFloater();
  214. }