PageRenderTime 36ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloaterdeleteenvpreset.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 285 lines | 195 code | 50 blank | 40 comment | 44 complexity | 7d57fb0073bb09729d7940f57bf82fcc MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaterdeleteenvpreset.cpp
  3. * @brief Floater to delete a water / sky / day cycle preset.
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, 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 "llfloaterdeleteenvpreset.h"
  28. // libs
  29. #include "llbutton.h"
  30. #include "llcombobox.h"
  31. #include "llnotificationsutil.h"
  32. // newview
  33. #include "lldaycyclemanager.h"
  34. #include "llwaterparammanager.h"
  35. static bool confirmation_callback(const LLSD& notification, const LLSD& response, boost::function<void()> cb)
  36. {
  37. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  38. if (option == 0)
  39. {
  40. cb();
  41. }
  42. return false;
  43. }
  44. LLFloaterDeleteEnvPreset::LLFloaterDeleteEnvPreset(const LLSD &key)
  45. : LLFloater(key)
  46. , mPresetCombo(NULL)
  47. {
  48. }
  49. // virtual
  50. BOOL LLFloaterDeleteEnvPreset::postBuild()
  51. {
  52. mPresetCombo = getChild<LLComboBox>("preset_combo");
  53. mPresetCombo->setCommitCallback(boost::bind(&LLFloaterDeleteEnvPreset::postPopulate, this));
  54. getChild<LLButton>("delete")->setCommitCallback(boost::bind(&LLFloaterDeleteEnvPreset::onBtnDelete, this));
  55. getChild<LLButton>("cancel")->setCommitCallback(boost::bind(&LLFloaterDeleteEnvPreset::onBtnCancel, this));
  56. // Listen to user preferences change, in which case we need to rebuild the presets list
  57. // to disable the [new] current preset.
  58. LLEnvManagerNew::instance().setPreferencesChangeCallback(boost::bind(&LLFloaterDeleteEnvPreset::populatePresetsList, this));
  59. // Listen to presets addition/removal.
  60. LLDayCycleManager::instance().setModifyCallback(boost::bind(&LLFloaterDeleteEnvPreset::populateDayCyclesList, this));
  61. LLWLParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterDeleteEnvPreset::populateSkyPresetsList, this));
  62. LLWaterParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterDeleteEnvPreset::populateWaterPresetsList, this));
  63. return TRUE;
  64. }
  65. // virtual
  66. void LLFloaterDeleteEnvPreset::onOpen(const LLSD& key)
  67. {
  68. std::string param = key.asString();
  69. std::string floater_title = getString(std::string("title_") + param);
  70. std::string combo_label = getString(std::string("label_" + param));
  71. // Update floater title.
  72. setTitle(floater_title);
  73. // Update the combobox label.
  74. getChild<LLUICtrl>("label")->setValue(combo_label);
  75. // Populate the combobox.
  76. populatePresetsList();
  77. }
  78. void LLFloaterDeleteEnvPreset::onBtnDelete()
  79. {
  80. std::string param = mKey.asString();
  81. std::string preset_name = mPresetCombo->getValue().asString();
  82. boost::function<void()> confirm_cb;
  83. if (param == "water")
  84. {
  85. // Don't allow deleting system presets.
  86. if (LLWaterParamManager::instance().isSystemPreset(preset_name))
  87. {
  88. LLNotificationsUtil::add("WLNoEditDefault");
  89. return;
  90. }
  91. confirm_cb = boost::bind(&LLFloaterDeleteEnvPreset::onDeleteWaterPresetConfirmation, this);
  92. }
  93. else if (param == "sky")
  94. {
  95. // Don't allow deleting presets referenced by local day cycles.
  96. if (LLDayCycleManager::instance().isSkyPresetReferenced(preset_name))
  97. {
  98. LLNotificationsUtil::add("GenericAlert", LLSD().with("MESSAGE", getString("msg_sky_is_referenced")));
  99. return;
  100. }
  101. LLWLParamManager& wl_mgr = LLWLParamManager::instance();
  102. // Don't allow deleting system presets.
  103. if (wl_mgr.isSystemPreset(preset_name))
  104. {
  105. LLNotificationsUtil::add("WLNoEditDefault");
  106. return;
  107. }
  108. confirm_cb = boost::bind(&LLFloaterDeleteEnvPreset::onDeleteSkyPresetConfirmation, this);
  109. }
  110. else if (param == "day_cycle")
  111. {
  112. LLDayCycleManager& day_mgr = LLDayCycleManager::instance();
  113. // Don't allow deleting system presets.
  114. if (day_mgr.isSystemPreset(preset_name))
  115. {
  116. LLNotificationsUtil::add("WLNoEditDefault");
  117. return;
  118. }
  119. confirm_cb = boost::bind(&LLFloaterDeleteEnvPreset::onDeleteDayCycleConfirmation, this);
  120. }
  121. else
  122. {
  123. llwarns << "Unrecognized key" << llendl;
  124. }
  125. LLSD args;
  126. args["MESSAGE"] = getString("msg_confirm_deletion");
  127. LLNotificationsUtil::add("GenericAlertYesCancel", args, LLSD(),
  128. boost::bind(&confirmation_callback, _1, _2, confirm_cb));
  129. }
  130. void LLFloaterDeleteEnvPreset::onBtnCancel()
  131. {
  132. closeFloater();
  133. }
  134. void LLFloaterDeleteEnvPreset::populatePresetsList()
  135. {
  136. std::string param = mKey.asString();
  137. if (param == "water")
  138. {
  139. populateWaterPresetsList();
  140. }
  141. else if (param == "sky")
  142. {
  143. populateSkyPresetsList();
  144. }
  145. else if (param == "day_cycle")
  146. {
  147. populateDayCyclesList();
  148. }
  149. else
  150. {
  151. llwarns << "Unrecognized key" << llendl;
  152. }
  153. }
  154. void LLFloaterDeleteEnvPreset::populateWaterPresetsList()
  155. {
  156. if (mKey.asString() != "water") return;
  157. mPresetCombo->removeall();
  158. std::string cur_preset;
  159. LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance();
  160. if (!env_mgr.getUseRegionSettings())
  161. {
  162. cur_preset = env_mgr.getWaterPresetName();
  163. }
  164. LLWaterParamManager::preset_name_list_t presets;
  165. LLWaterParamManager::instance().getUserPresetNames(presets); // list only user presets
  166. for (LLWaterParamManager::preset_name_list_t::const_iterator it = presets.begin(); it != presets.end(); ++it)
  167. {
  168. std::string name = *it;
  169. bool enabled = (name != cur_preset); // don't allow deleting current preset
  170. mPresetCombo->add(name, ADD_BOTTOM, enabled);
  171. }
  172. postPopulate();
  173. }
  174. void LLFloaterDeleteEnvPreset::populateSkyPresetsList()
  175. {
  176. if (mKey.asString() != "sky") return;
  177. mPresetCombo->removeall();
  178. std::string cur_preset;
  179. LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance();
  180. if (!env_mgr.getUseRegionSettings() && env_mgr.getUseFixedSky())
  181. {
  182. cur_preset = env_mgr.getSkyPresetName();
  183. }
  184. LLWLParamManager::preset_name_list_t user_presets;
  185. LLWLParamManager::instance().getUserPresetNames(user_presets);
  186. for (LLWLParamManager::preset_name_list_t::const_iterator it = user_presets.begin(); it != user_presets.end(); ++it)
  187. {
  188. const std::string& name = *it;
  189. mPresetCombo->add(name, ADD_BOTTOM, /*enabled = */ name != cur_preset);
  190. }
  191. postPopulate();
  192. }
  193. void LLFloaterDeleteEnvPreset::populateDayCyclesList()
  194. {
  195. if (mKey.asString() != "day_cycle") return;
  196. mPresetCombo->removeall();
  197. std::string cur_day;
  198. LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance();
  199. if (!env_mgr.getUseRegionSettings() && env_mgr.getUseDayCycle())
  200. {
  201. cur_day = env_mgr.getDayCycleName();
  202. }
  203. LLDayCycleManager& day_mgr = LLDayCycleManager::instance();
  204. LLDayCycleManager::preset_name_list_t user_days;
  205. day_mgr.getUserPresetNames(user_days); // list only user presets
  206. for (LLDayCycleManager::preset_name_list_t::const_iterator it = user_days.begin(); it != user_days.end(); ++it)
  207. {
  208. const std::string& name = *it;
  209. mPresetCombo->add(name, ADD_BOTTOM, name != cur_day);
  210. }
  211. postPopulate();
  212. }
  213. void LLFloaterDeleteEnvPreset::postPopulate()
  214. {
  215. // Handle empty list and empty selection.
  216. bool has_selection = mPresetCombo->getItemCount() > 0 && mPresetCombo->getSelectedValue().isDefined();
  217. if (!has_selection)
  218. {
  219. mPresetCombo->setLabel(getString("combo_label"));
  220. }
  221. getChild<LLButton>("delete")->setEnabled(has_selection);
  222. }
  223. void LLFloaterDeleteEnvPreset::onDeleteDayCycleConfirmation()
  224. {
  225. LLDayCycleManager::instance().deletePreset(mPresetCombo->getValue().asString());
  226. }
  227. void LLFloaterDeleteEnvPreset::onDeleteSkyPresetConfirmation()
  228. {
  229. LLWLParamKey key(mPresetCombo->getValue().asString(), LLEnvKey::SCOPE_LOCAL);
  230. LLWLParamManager::instance().removeParamSet(key, true);
  231. }
  232. void LLFloaterDeleteEnvPreset::onDeleteWaterPresetConfirmation()
  233. {
  234. LLWaterParamManager::instance().removeParamSet(mPresetCombo->getValue().asString(), true);
  235. }