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