llpanelcontents.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * @file llpanelcontents.cpp
  3. * @brief Object contents panel in the tools floater.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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 "llpanelcontents.h"
  34. #include "llbutton.h"
  35. #include "llpermissionsflags.h"
  36. #include "llagent.h"
  37. #include "llfloaterbulkpermission.h"
  38. #include "llfloaterperms.h"
  39. #include "llpanelinventory.h"
  40. //MK
  41. #include "mkrlinterface.h"
  42. //mk
  43. #include "llselectmgr.h"
  44. #include "llviewercontrol.h"
  45. #include "llviewerobject.h"
  46. LLPanelContents::LLPanelContents(const std::string& name)
  47. : LLPanel(name),
  48. mPanelInventory(NULL)
  49. {
  50. }
  51. //virtual
  52. bool LLPanelContents::postBuild()
  53. {
  54. setMouseOpaque(false);
  55. mButtonNewScript = getChild<LLButton>("button new script");
  56. mButtonNewScript->setClickedCallback(onClickNewScript, this);
  57. mButtonPermissions = getChild<LLButton>("button permissions");
  58. mButtonPermissions->setClickedCallback(onClickPermissions, this);
  59. return true;
  60. }
  61. void LLPanelContents::getState(LLViewerObject* objectp)
  62. {
  63. if (mPanelInventory)
  64. {
  65. mPanelInventory->refresh();
  66. }
  67. if (!objectp)
  68. {
  69. mButtonNewScript->setEnabled(false);
  70. mButtonPermissions->setEnabled(false);
  71. return;
  72. }
  73. LLUUID group_id;
  74. // sets group_id as a side effect SL-23488
  75. gSelectMgr.selectGetGroup(group_id);
  76. // BUG ? Check for all objects being editable ?
  77. bool editable = gAgent.isGodlike() ||
  78. (objectp->permModify() &&
  79. !objectp->isPermanentEnforced() &&
  80. // solves SL-23488
  81. (objectp->permYouOwner() ||
  82. (group_id.notNull() && gAgent.isInGroup(group_id))));
  83. bool all_volume = gSelectMgr.selectionAllPCode(LL_PCODE_VOLUME);
  84. // Edit script button - ok if object is editable and there's an unambiguous
  85. // destination for the object.
  86. bool enabled = editable && all_volume &&
  87. (gSelectMgr.getSelection()->getRootObjectCount() == 1 ||
  88. gSelectMgr.getSelection()->getObjectCount() == 1);
  89. mButtonNewScript->setEnabled(enabled);
  90. enabled = !objectp->isPermanentEnforced();
  91. mButtonPermissions->setEnabled(enabled);
  92. if (mPanelInventory)
  93. {
  94. mPanelInventory->setEnabled(enabled);
  95. }
  96. }
  97. //virtual
  98. void LLPanelContents::refresh()
  99. {
  100. LLViewerObject* object;
  101. object = gSelectMgr.getSelection()->getFirstRootObject(true);
  102. getState(object);
  103. }
  104. //static
  105. void LLPanelContents::onClickNewScript(void* userdata)
  106. {
  107. LLViewerObject* object;
  108. object = gSelectMgr.getSelection()->getFirstRootObject(true);
  109. if (object)
  110. {
  111. //MK
  112. if (gRLenabled)
  113. {
  114. // Cannot edit objects that we are sitting on, when sit-restricted
  115. if (object->isAgentSeat() &&
  116. (gRLInterface.mContainsUnsit ||
  117. gRLInterface.mSittpMax < EXTREMUM))
  118. {
  119. return;
  120. }
  121. if (!gRLInterface.canDetach(object))
  122. {
  123. return;
  124. }
  125. }
  126. //mk
  127. LLPermissions perm;
  128. perm.init(gAgentID, gAgentID, LLUUID::null, LLUUID::null);
  129. U32 perms = PERM_MOVE | LLFloaterPerms::getNextOwnerPerms();
  130. U32 group_perms = LLFloaterPerms::getGroupPerms();
  131. if (gSavedSettings.getBool("NoModScripts"))
  132. {
  133. perms = perms & ~PERM_MODIFY;
  134. group_perms = PERM_NONE;
  135. }
  136. perm.initMasks(PERM_ALL, PERM_ALL,
  137. LLFloaterPerms::getEveryonePerms(), group_perms, perms);
  138. std::string desc;
  139. LLAssetType::generateDescriptionFor(LLAssetType::AT_LSL_TEXT, desc);
  140. LLPointer<LLViewerInventoryItem> new_item;
  141. new_item = new LLViewerInventoryItem(LLUUID::null, LLUUID::null,
  142. perm, LLUUID::null,
  143. LLAssetType::AT_LSL_TEXT,
  144. LLInventoryType::IT_LSL,
  145. std::string("New Script"),
  146. desc, LLSaleInfo::DEFAULT,
  147. LLViewerInventoryItem::II_FLAGS_NONE,
  148. time_corrected());
  149. object->saveScript(new_item, true, true);
  150. }
  151. }
  152. //static
  153. void LLPanelContents::onClickPermissions(void *userdata)
  154. {
  155. LLPanelContents* self = (LLPanelContents*)userdata;
  156. if (self && gFloaterViewp)
  157. {
  158. LLFloater* parentp = gFloaterViewp->getParentFloater(self);
  159. if (parentp)
  160. {
  161. parentp->addDependentFloater(LLFloaterBulkPermission::showInstance());
  162. }
  163. }
  164. }