llfloateropenobject.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. * @file llfloateropenobject.cpp
  3. * @brief LLFloaterOpenObject class implementation
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloateropenobject.h"
  34. #include "llnotifications.h"
  35. #include "lltextbox.h"
  36. #include "lluictrlfactory.h"
  37. #include "llagent.h"
  38. #include "llfloaterinventory.h"
  39. #include "llinventorybridge.h"
  40. #include "llpanelinventory.h"
  41. //MK
  42. #include "mkrlinterface.h"
  43. //mk
  44. #include "llselectmgr.h"
  45. #include "llviewercontrol.h"
  46. #include "llviewerobject.h"
  47. //static
  48. void* LLFloaterOpenObject::createPanelInventory(void* data)
  49. {
  50. LLFloaterOpenObject* self = (LLFloaterOpenObject*)data;
  51. self->mPanelInventory = new LLPanelInventory("Object contents", LLRect());
  52. return self->mPanelInventory;
  53. }
  54. LLFloaterOpenObject::LLFloaterOpenObject(const LLSD&)
  55. : mPanelInventory(NULL),
  56. mLastCount(0),
  57. mDirty(true)
  58. {
  59. LLCallbackMap::map_t factory_map;
  60. factory_map["object_contents"] = LLCallbackMap(createPanelInventory, this);
  61. LLUICtrlFactory::getInstance()->buildFloater(this, "floater_openobject.xml",
  62. &factory_map);
  63. }
  64. //virtual
  65. bool LLFloaterOpenObject::postBuild()
  66. {
  67. mDescription = getChild<LLTextBox>("object_name");
  68. childSetAction("copy_to_inventory_button", onClickMoveToInventory, this);
  69. if (gSavedSettings.getBool("EnableCopyAndWear"))
  70. {
  71. childSetAction("copy_and_wear_button", onClickMoveAndWear, this);
  72. }
  73. else
  74. {
  75. childSetVisible("copy_and_wear_button", false);
  76. }
  77. center();
  78. return true;
  79. }
  80. //virtual
  81. void LLFloaterOpenObject::refresh()
  82. {
  83. mPanelInventory->refresh();
  84. LLSelectNode* node = mObjectSelection->getFirstRootNode();
  85. if (node)
  86. {
  87. static std::string item = getString("item");
  88. static std::string items = getString("items");
  89. mLastCount = mPanelInventory->getViewsCount();
  90. #if 0 // WARNING: UTF-8 characters encoding issues at play: you cannot just
  91. // use node->mName or item(s) within llformat(), else you get bogus
  92. // characters... HB
  93. mDescription->setText(llformat("%s (%d %s)", node->mName, mLastCount,
  94. (mLastCount > 1 ? items : item)));
  95. #else
  96. mDescription->setText(node->mName + llformat(" (%d ", mLastCount) +
  97. (mLastCount > 1 ? items : item) + ")");
  98. #endif
  99. }
  100. }
  101. //virtual
  102. void LLFloaterOpenObject::draw()
  103. {
  104. if (mDirty || mPanelInventory->getViewsCount() != mLastCount)
  105. {
  106. refresh();
  107. mDirty = false;
  108. }
  109. LLFloater::draw();
  110. }
  111. void LLFloaterOpenObject::moveToInventory(bool wear)
  112. {
  113. if (mObjectSelection->getRootObjectCount() != 1)
  114. {
  115. gNotifications.add("OnlyCopyContentsOfSingleItem");
  116. return;
  117. }
  118. LLSelectNode* nodep = mObjectSelection->getFirstRootNode();
  119. if (!nodep) return;
  120. LLViewerObject* objectp = nodep->getObject();
  121. if (!objectp) return;
  122. // Either create a sub-folder for worn clothing, or of the root folder.
  123. LLUUID parent_cat_id;
  124. if (wear)
  125. {
  126. parent_cat_id =
  127. gInventory.findCategoryUUIDForType(LLFolderType::FT_CLOTHING);
  128. }
  129. else
  130. {
  131. parent_cat_id = gInventory.getRootFolderID();
  132. }
  133. inventory_func_t func =
  134. boost::bind(LLFloaterOpenObject::callbackCreateCategory, _1,
  135. objectp->getID(), wear);
  136. gInventory.createNewCategory(parent_cat_id, LLFolderType::FT_NONE,
  137. nodep->mName, func);
  138. }
  139. //static
  140. void LLFloaterOpenObject::dirty()
  141. {
  142. LLFloaterOpenObject* self = findInstance();
  143. if (self)
  144. {
  145. self->mDirty = true;
  146. }
  147. }
  148. //static
  149. void LLFloaterOpenObject::show()
  150. {
  151. LLObjectSelectionHandle object_selection = gSelectMgr.getSelection();
  152. if (object_selection->getRootObjectCount() != 1)
  153. {
  154. gNotifications.add("UnableToViewContentsMoreThanOne");
  155. return;
  156. }
  157. //MK
  158. if (gRLenabled && gRLInterface.mContainsEdit)
  159. {
  160. LLViewerObject* objp = gSelectMgr.getSelection()->getPrimaryObject();
  161. if (objp && !gRLInterface.canEdit(objp))
  162. {
  163. return;
  164. }
  165. }
  166. //mk
  167. LLFloaterOpenObject* self = getInstance(); // Create new instance if needed
  168. self->open();
  169. self->setFocus(true);
  170. self->mObjectSelection = gSelectMgr.getEditSelection();
  171. }
  172. //static
  173. void LLFloaterOpenObject::callbackCreateCategory(const LLUUID& cat_id,
  174. LLUUID object_id, bool wear)
  175. {
  176. if (cat_id.isNull())
  177. {
  178. gNotifications.add("CantCreateRequestedInvFolder");
  179. return;
  180. }
  181. LLCatAndWear* datap = new LLCatAndWear;
  182. datap->mCatID = cat_id;
  183. datap->mWear = wear;
  184. datap->mFolderResponded = true;
  185. // Copy and/or move the items into the newly created folder. Ignore any
  186. // "You are going to break this item" messages.
  187. if (!move_inv_category_world_to_agent(object_id, cat_id, true,
  188. callbackMoveInventory,
  189. (void*)datap))
  190. {
  191. gNotifications.add("OpenObjectCannotCopy");
  192. delete datap;
  193. }
  194. }
  195. //static
  196. void LLFloaterOpenObject::callbackMoveInventory(S32 result, void* userdata)
  197. {
  198. LLCatAndWear* datap = (LLCatAndWear*)userdata;
  199. if (datap && result == 0)
  200. {
  201. LLFloaterInventory::showAgentInventory();
  202. LLFloaterInventory* floaterp = LLFloaterInventory::getActiveFloater();
  203. if (floaterp)
  204. {
  205. floaterp->getPanel()->setSelection(datap->mCatID, TAKE_FOCUS_NO);
  206. }
  207. }
  208. delete datap;
  209. }
  210. //static
  211. void LLFloaterOpenObject::onClickMoveToInventory(void* data)
  212. {
  213. LLFloaterOpenObject* self = (LLFloaterOpenObject*)data;
  214. if (self)
  215. {
  216. self->moveToInventory(false);
  217. self->close();
  218. }
  219. }
  220. //static
  221. void LLFloaterOpenObject::onClickMoveAndWear(void* data)
  222. {
  223. LLFloaterOpenObject* self = (LLFloaterOpenObject*)data;
  224. if (self)
  225. {
  226. //MK
  227. if (gRLenabled && gRLInterface.mContainsDetach)
  228. {
  229. self->moveToInventory(false);
  230. }
  231. else
  232. {
  233. self->moveToInventory(true);
  234. }
  235. //mk
  236. self->close();
  237. }
  238. }