PageRenderTime 285ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llpanelmediasettingspermissions.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 284 lines | 186 code | 29 blank | 69 comment | 21 complexity | 591ecbf8ebdf005d4a2ac744b365b0e2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelmediasettingspermissions.cpp
  3. * @brief LLPanelMediaSettingsPermissions class implementation
  4. *
  5. * note that "permissions" tab is really "Controls" tab - refs to 'perms' and
  6. * 'permissions' not changed to 'controls' since we don't want to change
  7. * shared files in server code and keeping everything the same seemed best.
  8. *
  9. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  10. * Second Life Viewer Source Code
  11. * Copyright (C) 2010, Linden Research, Inc.
  12. *
  13. * This library is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation;
  16. * version 2.1 of the License only.
  17. *
  18. * This library is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with this library; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  28. * $/LicenseInfo$
  29. */
  30. #include "llviewerprecompiledheaders.h"
  31. #include "llpanelmediasettingspermissions.h"
  32. #include "llpanelcontents.h"
  33. #include "llcombobox.h"
  34. #include "llcheckboxctrl.h"
  35. #include "llspinctrl.h"
  36. #include "llurlhistory.h"
  37. #include "lluictrlfactory.h"
  38. #include "llwindow.h"
  39. #include "llviewerwindow.h"
  40. #include "llsdutil.h"
  41. #include "llselectmgr.h"
  42. #include "llmediaentry.h"
  43. #include "llnamebox.h"
  44. #include "lltrans.h"
  45. #include "llfloatermediasettings.h"
  46. ////////////////////////////////////////////////////////////////////////////////
  47. //
  48. LLPanelMediaSettingsPermissions::LLPanelMediaSettingsPermissions() :
  49. mControls( NULL ),
  50. mPermsOwnerInteract( 0 ),
  51. mPermsOwnerControl( 0 ),
  52. mPermsGroupName( 0 ),
  53. mPermsGroupInteract( 0 ),
  54. mPermsGroupControl( 0 ),
  55. mPermsWorldInteract( 0 ),
  56. mPermsWorldControl( 0 )
  57. {
  58. // build dialog from XML
  59. buildFromFile( "panel_media_settings_permissions.xml");
  60. }
  61. ////////////////////////////////////////////////////////////////////////////////
  62. //
  63. BOOL LLPanelMediaSettingsPermissions::postBuild()
  64. {
  65. // connect member vars with UI widgets
  66. mControls = getChild< LLComboBox >( LLMediaEntry::CONTROLS_KEY );
  67. mPermsOwnerInteract = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_OWNER_INTERACT_KEY );
  68. mPermsOwnerControl = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_OWNER_CONTROL_KEY );
  69. mPermsGroupInteract = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_GROUP_INTERACT_KEY );
  70. mPermsGroupControl = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_GROUP_CONTROL_KEY );
  71. mPermsWorldInteract = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_ANYONE_INTERACT_KEY );
  72. mPermsWorldControl = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_ANYONE_CONTROL_KEY );
  73. mPermsGroupName = getChild< LLNameBox >( "perms_group_name" );
  74. return true;
  75. }
  76. ////////////////////////////////////////////////////////////////////////////////
  77. // virtual
  78. LLPanelMediaSettingsPermissions::~LLPanelMediaSettingsPermissions()
  79. {
  80. }
  81. ////////////////////////////////////////////////////////////////////////////////
  82. // virtual
  83. void LLPanelMediaSettingsPermissions::draw()
  84. {
  85. // housekeeping
  86. LLPanel::draw();
  87. getChild<LLUICtrl>("perms_group_name")->setValue(LLStringUtil::null);
  88. LLUUID group_id;
  89. BOOL groups_identical = LLSelectMgr::getInstance()->selectGetGroup(group_id);
  90. if (groups_identical)
  91. {
  92. if(mPermsGroupName)
  93. {
  94. mPermsGroupName->setNameID(group_id, true);
  95. }
  96. }
  97. else
  98. {
  99. if(mPermsGroupName)
  100. {
  101. mPermsGroupName->setNameID(LLUUID::null, TRUE);
  102. mPermsGroupName->refresh(LLUUID::null, std::string(), true);
  103. }
  104. }
  105. }
  106. ////////////////////////////////////////////////////////////////////////////////
  107. // static
  108. void LLPanelMediaSettingsPermissions::clearValues( void* userdata, bool editable)
  109. {
  110. LLPanelMediaSettingsPermissions *self =(LLPanelMediaSettingsPermissions *)userdata;
  111. self->mControls->clear();
  112. self->mPermsOwnerInteract->clear();
  113. self->mPermsOwnerControl->clear();
  114. self->mPermsGroupInteract->clear();
  115. self->mPermsGroupControl->clear();
  116. self->mPermsWorldInteract->clear();
  117. self->mPermsWorldControl->clear();
  118. self->mControls->setEnabled(editable);
  119. self->mPermsOwnerInteract->setEnabled(editable);
  120. self->mPermsOwnerControl->setEnabled(editable);
  121. self->mPermsGroupInteract->setEnabled(editable);
  122. self->mPermsGroupControl->setEnabled(editable);
  123. self->mPermsWorldInteract->setEnabled(editable);
  124. self->mPermsWorldControl->setEnabled(editable);
  125. self->getChild< LLTextBox >("controls_label")->setEnabled(editable);
  126. self->getChild< LLTextBox >("owner_label")->setEnabled(editable);
  127. self->getChild< LLTextBox >("group_label")->setEnabled(editable);
  128. self->getChild< LLNameBox >("perms_group_name")->setEnabled(editable);
  129. self->getChild< LLTextBox >("anyone_label")->setEnabled(editable);
  130. }
  131. ////////////////////////////////////////////////////////////////////////////////
  132. // static
  133. void LLPanelMediaSettingsPermissions::initValues( void* userdata, const LLSD& media_settings , bool editable)
  134. {
  135. LLPanelMediaSettingsPermissions *self =(LLPanelMediaSettingsPermissions *)userdata;
  136. std::string base_key( "" );
  137. std::string tentative_key( "" );
  138. struct
  139. {
  140. std::string key_name;
  141. LLUICtrl* ctrl_ptr;
  142. std::string ctrl_type;
  143. } data_set [] =
  144. {
  145. { LLMediaEntry::CONTROLS_KEY, self->mControls, "LLComboBox" },
  146. { LLPanelContents::PERMS_OWNER_INTERACT_KEY, self->mPermsOwnerInteract, "LLCheckBoxCtrl" },
  147. { LLPanelContents::PERMS_OWNER_CONTROL_KEY, self->mPermsOwnerControl, "LLCheckBoxCtrl" },
  148. { LLPanelContents::PERMS_GROUP_INTERACT_KEY, self->mPermsGroupInteract, "LLCheckBoxCtrl" },
  149. { LLPanelContents::PERMS_GROUP_CONTROL_KEY, self->mPermsGroupControl, "LLCheckBoxCtrl" },
  150. { LLPanelContents::PERMS_ANYONE_INTERACT_KEY, self->mPermsWorldInteract, "LLCheckBoxCtrl" },
  151. { LLPanelContents::PERMS_ANYONE_CONTROL_KEY, self->mPermsWorldControl, "LLCheckBoxCtrl" },
  152. { "", NULL , "" }
  153. };
  154. for( int i = 0; data_set[ i ].key_name.length() > 0; ++i )
  155. {
  156. base_key = std::string( data_set[ i ].key_name );
  157. tentative_key = base_key + std::string( LLPanelContents::TENTATIVE_SUFFIX );
  158. // TODO: CP - I bet there is a better way to do this using Boost
  159. if ( media_settings[ base_key ].isDefined() )
  160. {
  161. if ( data_set[ i ].ctrl_type == "LLCheckBoxCtrl" )
  162. {
  163. // Most recent change to the "sense" of these checkboxes
  164. // means the value in the checkbox matches that on the server
  165. static_cast< LLCheckBoxCtrl* >( data_set[ i ].ctrl_ptr )->
  166. setValue( media_settings[ base_key ].asBoolean() );
  167. }
  168. else
  169. if ( data_set[ i ].ctrl_type == "LLComboBox" )
  170. static_cast< LLComboBox* >( data_set[ i ].ctrl_ptr )->
  171. setCurrentByIndex( media_settings[ base_key ].asInteger() );
  172. data_set[ i ].ctrl_ptr->setEnabled(editable);
  173. data_set[ i ].ctrl_ptr->setTentative( media_settings[ tentative_key ].asBoolean() );
  174. };
  175. };
  176. // *NOTE: If any of a particular flavor is tentative, we have to disable
  177. // them all because of an architectural issue: namely that we represent
  178. // these as a bit field, and we can't selectively apply only one bit to all selected
  179. // faces if they don't match. Also see the *NOTE below.
  180. if ( self->mPermsOwnerInteract->getTentative() ||
  181. self->mPermsGroupInteract->getTentative() ||
  182. self->mPermsWorldInteract->getTentative())
  183. {
  184. self->mPermsOwnerInteract->setEnabled(false);
  185. self->mPermsGroupInteract->setEnabled(false);
  186. self->mPermsWorldInteract->setEnabled(false);
  187. }
  188. if ( self->mPermsOwnerControl->getTentative() ||
  189. self->mPermsGroupControl->getTentative() ||
  190. self->mPermsWorldControl->getTentative())
  191. {
  192. self->mPermsOwnerControl->setEnabled(false);
  193. self->mPermsGroupControl->setEnabled(false);
  194. self->mPermsWorldControl->setEnabled(false);
  195. }
  196. self->getChild< LLTextBox >("controls_label")->setEnabled(editable);
  197. self->getChild< LLTextBox >("owner_label")->setEnabled(editable);
  198. self->getChild< LLTextBox >("group_label")->setEnabled(editable);
  199. self->getChild< LLNameBox >("perms_group_name")->setEnabled(editable);
  200. self->getChild< LLTextBox >("anyone_label")->setEnabled(editable);
  201. }
  202. ////////////////////////////////////////////////////////////////////////////////
  203. //
  204. void LLPanelMediaSettingsPermissions::preApply()
  205. {
  206. // no-op
  207. }
  208. ////////////////////////////////////////////////////////////////////////////////
  209. //
  210. void LLPanelMediaSettingsPermissions::getValues( LLSD &fill_me_in, bool include_tentative )
  211. {
  212. // moved over from the 'General settings' tab
  213. if (include_tentative || !mControls->getTentative()) fill_me_in[LLMediaEntry::CONTROLS_KEY] = (LLSD::Integer)mControls->getCurrentIndex();
  214. // *NOTE: For some reason, gcc does not like these symbol references in the
  215. // expressions below (inside the static_casts). I have NO idea why :(.
  216. // For some reason, assigning them to const temp vars here fixes the link
  217. // error. Bizarre.
  218. const U8 none = LLMediaEntry::PERM_NONE;
  219. const U8 owner = LLMediaEntry::PERM_OWNER;
  220. const U8 group = LLMediaEntry::PERM_GROUP;
  221. const U8 anyone = LLMediaEntry::PERM_ANYONE;
  222. const LLSD::Integer control = static_cast<LLSD::Integer>(
  223. (mPermsOwnerControl->getValue() ? owner : none ) |
  224. (mPermsGroupControl->getValue() ? group: none ) |
  225. (mPermsWorldControl->getValue() ? anyone : none ));
  226. const LLSD::Integer interact = static_cast<LLSD::Integer>(
  227. (mPermsOwnerInteract->getValue() ? owner: none ) |
  228. (mPermsGroupInteract->getValue() ? group : none ) |
  229. (mPermsWorldInteract->getValue() ? anyone : none ));
  230. // *TODO: This will fill in the values of all permissions values, even if
  231. // one or more is tentative. This is not quite the user expectation...what
  232. // it should do is only change the bit that was made "untentative", but in
  233. // a multiple-selection situation, this isn't possible given the architecture
  234. // for how settings are applied.
  235. if (include_tentative ||
  236. !mPermsOwnerControl->getTentative() ||
  237. !mPermsGroupControl->getTentative() ||
  238. !mPermsWorldControl->getTentative())
  239. {
  240. fill_me_in[LLMediaEntry::PERMS_CONTROL_KEY] = control;
  241. }
  242. if (include_tentative ||
  243. !mPermsOwnerInteract->getTentative() ||
  244. !mPermsGroupInteract->getTentative() ||
  245. !mPermsWorldInteract->getTentative())
  246. {
  247. fill_me_in[LLMediaEntry::PERMS_INTERACT_KEY] = interact;
  248. }
  249. }
  250. ////////////////////////////////////////////////////////////////////////////////
  251. //
  252. void LLPanelMediaSettingsPermissions::postApply()
  253. {
  254. // no-op
  255. }