PageRenderTime 34ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloatermediasettings.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 314 lines | 203 code | 46 blank | 65 comment | 18 complexity | 7bf76fa964ae09ef01e6bbbec2af9803 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloatermediasettings.cpp
  3. * @brief Tabbed dialog for media settings - class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #include "llviewerprecompiledheaders.h"
  27. #include "llfloaterreg.h"
  28. #include "llfloatermediasettings.h"
  29. #include "llpanelmediasettingsgeneral.h"
  30. #include "llpanelmediasettingssecurity.h"
  31. #include "llpanelmediasettingspermissions.h"
  32. #include "llviewercontrol.h"
  33. #include "lluictrlfactory.h"
  34. #include "llbutton.h"
  35. #include "llselectmgr.h"
  36. #include "llsdutil.h"
  37. LLFloaterMediaSettings* LLFloaterMediaSettings::sInstance = NULL;
  38. ////////////////////////////////////////////////////////////////////////////////
  39. //
  40. LLFloaterMediaSettings::LLFloaterMediaSettings(const LLSD& key)
  41. : LLFloater(key),
  42. mTabContainer(NULL),
  43. mPanelMediaSettingsGeneral(NULL),
  44. mPanelMediaSettingsSecurity(NULL),
  45. mPanelMediaSettingsPermissions(NULL),
  46. mWaitingToClose( false ),
  47. mIdenticalHasMediaInfo( true ),
  48. mMultipleMedia(false),
  49. mMultipleValidMedia(false)
  50. {
  51. }
  52. ////////////////////////////////////////////////////////////////////////////////
  53. //
  54. LLFloaterMediaSettings::~LLFloaterMediaSettings()
  55. {
  56. if ( mPanelMediaSettingsGeneral )
  57. {
  58. delete mPanelMediaSettingsGeneral;
  59. mPanelMediaSettingsGeneral = NULL;
  60. }
  61. if ( mPanelMediaSettingsSecurity )
  62. {
  63. delete mPanelMediaSettingsSecurity;
  64. mPanelMediaSettingsSecurity = NULL;
  65. }
  66. if ( mPanelMediaSettingsPermissions )
  67. {
  68. delete mPanelMediaSettingsPermissions;
  69. mPanelMediaSettingsPermissions = NULL;
  70. }
  71. sInstance = NULL;
  72. }
  73. ////////////////////////////////////////////////////////////////////////////////
  74. //
  75. BOOL LLFloaterMediaSettings::postBuild()
  76. {
  77. mApplyBtn = getChild<LLButton>("Apply");
  78. mApplyBtn->setClickedCallback(onBtnApply, this);
  79. mCancelBtn = getChild<LLButton>("Cancel");
  80. mCancelBtn->setClickedCallback(onBtnCancel, this);
  81. mOKBtn = getChild<LLButton>("OK");
  82. mOKBtn->setClickedCallback(onBtnOK, this);
  83. mTabContainer = getChild<LLTabContainer>( "tab_container" );
  84. mPanelMediaSettingsGeneral = new LLPanelMediaSettingsGeneral();
  85. mTabContainer->addTabPanel(
  86. LLTabContainer::TabPanelParams().
  87. panel(mPanelMediaSettingsGeneral));
  88. mPanelMediaSettingsGeneral->setParent( this );
  89. // note that "permissions" tab is really "Controls" tab - refs to 'perms' and
  90. // 'permissions' not changed to 'controls' since we don't want to change
  91. // shared files in server code and keeping everything the same seemed best.
  92. mPanelMediaSettingsPermissions = new LLPanelMediaSettingsPermissions();
  93. mTabContainer->addTabPanel(
  94. LLTabContainer::TabPanelParams().
  95. panel(mPanelMediaSettingsPermissions));
  96. mPanelMediaSettingsSecurity = new LLPanelMediaSettingsSecurity();
  97. mTabContainer->addTabPanel(
  98. LLTabContainer::TabPanelParams().
  99. panel(mPanelMediaSettingsSecurity));
  100. mPanelMediaSettingsSecurity->setParent( this );
  101. // restore the last tab viewed from persistance variable storage
  102. if (!mTabContainer->selectTab(gSavedSettings.getS32("LastMediaSettingsTab")))
  103. {
  104. mTabContainer->selectFirstTab();
  105. };
  106. sInstance = this;
  107. return TRUE;
  108. }
  109. //static
  110. LLFloaterMediaSettings* LLFloaterMediaSettings::getInstance()
  111. {
  112. if ( !sInstance )
  113. {
  114. sInstance = (LLFloaterReg::getTypedInstance<LLFloaterMediaSettings>("media_settings"));
  115. }
  116. return sInstance;
  117. }
  118. //static
  119. void LLFloaterMediaSettings::apply()
  120. {
  121. if (sInstance->haveValuesChanged())
  122. {
  123. LLSD settings;
  124. sInstance->mPanelMediaSettingsGeneral->preApply();
  125. sInstance->mPanelMediaSettingsGeneral->getValues( settings, false );
  126. sInstance->mPanelMediaSettingsSecurity->preApply();
  127. sInstance->mPanelMediaSettingsSecurity->getValues( settings, false );
  128. sInstance->mPanelMediaSettingsPermissions->preApply();
  129. sInstance->mPanelMediaSettingsPermissions->getValues( settings, false );
  130. LLSelectMgr::getInstance()->selectionSetMedia( LLTextureEntry::MF_HAS_MEDIA, settings );
  131. sInstance->mPanelMediaSettingsGeneral->postApply();
  132. sInstance->mPanelMediaSettingsSecurity->postApply();
  133. sInstance->mPanelMediaSettingsPermissions->postApply();
  134. }
  135. }
  136. ////////////////////////////////////////////////////////////////////////////////
  137. void LLFloaterMediaSettings::onClose(bool app_quitting)
  138. {
  139. if(mPanelMediaSettingsGeneral)
  140. {
  141. mPanelMediaSettingsGeneral->onClose(app_quitting);
  142. }
  143. LLFloaterReg::hideInstance("whitelist_entry");
  144. }
  145. ////////////////////////////////////////////////////////////////////////////////
  146. //static
  147. void LLFloaterMediaSettings::initValues( const LLSD& media_settings, bool editable )
  148. {
  149. if (sInstance->hasFocus()) return;
  150. sInstance->clearValues(editable);
  151. // update all panels with values from simulator
  152. sInstance->mPanelMediaSettingsGeneral->
  153. initValues( sInstance->mPanelMediaSettingsGeneral, media_settings, editable );
  154. sInstance->mPanelMediaSettingsSecurity->
  155. initValues( sInstance->mPanelMediaSettingsSecurity, media_settings, editable );
  156. sInstance->mPanelMediaSettingsPermissions->
  157. initValues( sInstance->mPanelMediaSettingsPermissions, media_settings, editable );
  158. // Squirrel away initial values
  159. sInstance->mInitialValues.clear();
  160. sInstance->mPanelMediaSettingsGeneral->getValues( sInstance->mInitialValues );
  161. sInstance->mPanelMediaSettingsSecurity->getValues( sInstance->mInitialValues );
  162. sInstance->mPanelMediaSettingsPermissions->getValues( sInstance->mInitialValues );
  163. sInstance->mApplyBtn->setEnabled(editable);
  164. sInstance->mOKBtn->setEnabled(editable);
  165. }
  166. ////////////////////////////////////////////////////////////////////////////////
  167. //
  168. void LLFloaterMediaSettings::commitFields()
  169. {
  170. if (hasFocus())
  171. {
  172. LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
  173. if (cur_focus && cur_focus->acceptsTextInput())
  174. {
  175. cur_focus->onCommit();
  176. };
  177. };
  178. }
  179. ////////////////////////////////////////////////////////////////////////////////
  180. //static
  181. void LLFloaterMediaSettings::clearValues( bool editable)
  182. {
  183. if (sInstance)
  184. {
  185. // clean up all panels before updating
  186. sInstance->mPanelMediaSettingsGeneral ->clearValues(sInstance->mPanelMediaSettingsGeneral, editable);
  187. sInstance->mPanelMediaSettingsSecurity ->clearValues(sInstance->mPanelMediaSettingsSecurity, editable);
  188. sInstance->mPanelMediaSettingsPermissions->clearValues(sInstance->mPanelMediaSettingsPermissions, editable);
  189. }
  190. }
  191. ////////////////////////////////////////////////////////////////////////////////
  192. // static
  193. void LLFloaterMediaSettings::onBtnOK( void* userdata )
  194. {
  195. sInstance->commitFields();
  196. sInstance->apply();
  197. sInstance->closeFloater();
  198. }
  199. ////////////////////////////////////////////////////////////////////////////////
  200. // static
  201. void LLFloaterMediaSettings::onBtnApply( void* userdata )
  202. {
  203. sInstance->commitFields();
  204. sInstance->apply();
  205. sInstance->mInitialValues.clear();
  206. sInstance->mPanelMediaSettingsGeneral->getValues( sInstance->mInitialValues );
  207. sInstance->mPanelMediaSettingsSecurity->getValues( sInstance->mInitialValues );
  208. sInstance->mPanelMediaSettingsPermissions->getValues( sInstance->mInitialValues );
  209. }
  210. ////////////////////////////////////////////////////////////////////////////////
  211. // static
  212. void LLFloaterMediaSettings::onBtnCancel( void* userdata )
  213. {
  214. sInstance->closeFloater();
  215. }
  216. ////////////////////////////////////////////////////////////////////////////////
  217. // static
  218. void LLFloaterMediaSettings::onTabChanged(void* user_data, bool from_click)
  219. {
  220. LLTabContainer* self = (LLTabContainer*)user_data;
  221. gSavedSettings.setS32("LastMediaSettingsTab", self->getCurrentPanelIndex());
  222. }
  223. ////////////////////////////////////////////////////////////////////////////////
  224. //
  225. const std::string LLFloaterMediaSettings::getHomeUrl()
  226. {
  227. if ( mPanelMediaSettingsGeneral )
  228. return mPanelMediaSettingsGeneral->getHomeUrl();
  229. else
  230. return std::string( "" );
  231. }
  232. ////////////////////////////////////////////////////////////////////////////////
  233. // virtual
  234. void LLFloaterMediaSettings::draw()
  235. {
  236. if (NULL != mApplyBtn)
  237. {
  238. // Set the enabled state of the "Apply" button if values changed
  239. mApplyBtn->setEnabled( haveValuesChanged() );
  240. }
  241. LLFloater::draw();
  242. }
  243. //private
  244. bool LLFloaterMediaSettings::haveValuesChanged() const
  245. {
  246. bool values_changed = false;
  247. // *NOTE: The code below is very inefficient. Better to do this
  248. // only when data change.
  249. // Every frame, check to see what the values are. If they are not
  250. // the same as the initial media data, enable the OK/Apply buttons
  251. LLSD settings;
  252. sInstance->mPanelMediaSettingsGeneral->getValues( settings );
  253. sInstance->mPanelMediaSettingsSecurity->getValues( settings );
  254. sInstance->mPanelMediaSettingsPermissions->getValues( settings );
  255. LLSD::map_const_iterator iter = settings.beginMap();
  256. LLSD::map_const_iterator end = settings.endMap();
  257. for ( ; iter != end; ++iter )
  258. {
  259. const std::string &current_key = iter->first;
  260. const LLSD &current_value = iter->second;
  261. if ( ! llsd_equals(current_value, mInitialValues[current_key]))
  262. {
  263. values_changed = true;
  264. break;
  265. }
  266. }
  267. return values_changed;
  268. }