phoenix-firestorm/indra/newview/fspanelprefs.cpp

258 lines
7.9 KiB
C++

/**
* @file fspanelprefs.h
*
* $LicenseInfo:firstyear=2011&license=fsviewerlgpl$
* Phoenix Firestorm Viewer Source Code
* Copyright (C) 2011, The Phoenix Firestorm Project, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
* http://www.firestormviewer.org
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "fspanelprefs.h"
#include "lggbeamcolormapfloater.h"
#include "lggbeammapfloater.h"
#include "lggbeammaps.h"
#include "llcheckboxctrl.h"
#include "llcolorswatch.h"
#include "llcombobox.h"
#include "lldiriterator.h" // <FS:CR> for populating the cloud combo
#include "llfloaterreg.h"
#include "llinventorymodel.h"
#include "llspinctrl.h"
#include "lltexturectrl.h"
#include "llviewercontrol.h"
#include "llvoavatar.h"
#include "llvoavatarself.h"
static LLPanelInjector<FSPanelPrefs> t_pref_fs("panel_preference_firestorm");
FSPanelPrefs::FSPanelPrefs() : LLPanelPreference()
{
mCommitCallbackRegistrar.add("Perms.Copy", boost::bind(&FSPanelPrefs::onCommitCopy, this));
mCommitCallbackRegistrar.add("Perms.Trans", boost::bind(&FSPanelPrefs::onCommitTrans, this));
mCommitCallbackRegistrar.add("FS.CheckContactListColumnMode", boost::bind(&FSPanelPrefs::onCheckContactListColumnMode, this));
}
BOOL FSPanelPrefs::postBuild()
{
// LGG's Color Beams
refreshBeamLists();
// Beam Colors
getChild<LLUICtrl>("BeamColor_new")->setCommitCallback(boost::bind(&FSPanelPrefs::onBeamColor_new, this));
getChild<LLUICtrl>("BeamColor_refresh")->setCommitCallback(boost::bind(&FSPanelPrefs::refreshBeamLists, this));
getChild<LLUICtrl>("BeamColor_delete")->setCommitCallback(boost::bind(&FSPanelPrefs::onBeamColorDelete, this));
// Beam Shapes
getChild<LLUICtrl>("custom_beam_btn")->setCommitCallback(boost::bind(&FSPanelPrefs::onBeam_new, this));
getChild<LLUICtrl>("refresh_beams")->setCommitCallback(boost::bind(&FSPanelPrefs::refreshBeamLists, this));
getChild<LLUICtrl>("delete_beam")->setCommitCallback(boost::bind(&FSPanelPrefs::onBeamDelete, this));
populateCloudCombo();
LLTextureCtrl* tex_ctrl = getChild<LLTextureCtrl>("texture control");
tex_ctrl->setCommitCallback(boost::bind(&FSPanelPrefs::onCommitTexture, this, _2));
tex_ctrl->setDefaultImageAssetID(LLUUID(gSavedSettings.getString("DefaultObjectTexture")));
onCheckContactListColumnMode();
return LLPanelPreference::postBuild();
}
void FSPanelPrefs::apply()
{
LLPanelPreference::apply();
}
void FSPanelPrefs::cancel()
{
LLPanelPreference::cancel();
}
void FSPanelPrefs::refreshBeamLists()
{
LLComboBox* comboBox = findChild<LLComboBox>("FSBeamShape_combo");
if (comboBox)
{
comboBox->removeall();
comboBox->add("===OFF===");
string_vec_t names = gLggBeamMaps.getFileNames();
for (string_vec_t::iterator it = names.begin(); it != names.end(); ++it)
{
comboBox->add(*it);
}
comboBox->setSimple(gSavedSettings.getString("FSBeamShape"));
}
comboBox = findChild<LLComboBox>("BeamColor_combo");
if (comboBox)
{
comboBox->removeall();
comboBox->add("===OFF===");
string_vec_t names = gLggBeamMaps.getColorsFileNames();
for (string_vec_t::iterator it = names.begin(); it != names.end(); ++it)
{
comboBox->add(*it);
}
comboBox->setSimple(gSavedSettings.getString("FSBeamColorFile"));
}
}
void FSPanelPrefs::onBeamColor_new()
{
lggBeamColorMapFloater* colorMapFloater = (lggBeamColorMapFloater*)LLFloaterReg::showInstance("lgg_beamcolormap");
colorMapFloater->setData(this);
}
void FSPanelPrefs::onBeam_new()
{
lggBeamMapFloater* beamMapFloater = (lggBeamMapFloater*)LLFloaterReg::showInstance("lgg_beamshape");
beamMapFloater->setData(this);
}
void FSPanelPrefs::onBeamColorDelete()
{
LLComboBox* comboBox = findChild<LLComboBox>("BeamColor_combo");
if (comboBox)
{
std::string filename = comboBox->getValue().asString()+".xml";
std::string path_name1(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "beamsColors", filename));
std::string path_name2(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "beamsColors", filename));
if (gDirUtilp->fileExists(path_name1))
{
LLFile::remove(path_name1);
gSavedSettings.setString("FSBeamColorFile", "===OFF===");
}
if (gDirUtilp->fileExists(path_name2))
{
LLFile::remove(path_name2);
gSavedSettings.setString("FSBeamColorFile", "===OFF===");
}
}
refreshBeamLists();
}
void FSPanelPrefs::onBeamDelete()
{
LLComboBox* comboBox = findChild<LLComboBox>("FSBeamShape_combo");
if (comboBox)
{
std::string filename = comboBox->getValue().asString() + ".xml";
std::string path_name1(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "beams", filename));
std::string path_name2(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "beams", filename));
if (gDirUtilp->fileExists(path_name1))
{
LLFile::remove(path_name1);
gSavedSettings.setString("FSBeamShape", "===OFF===");
}
if (gDirUtilp->fileExists(path_name2))
{
LLFile::remove(path_name2);
gSavedSettings.setString("FSBeamShape", "===OFF===");
}
}
refreshBeamLists();
}
void FSPanelPrefs::populateCloudCombo()
{
LLComboBox* cloud_combo = findChild<LLComboBox>("cloud_combo");
if (cloud_combo)
{
const std::string cloudDir(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight" + gDirUtilp->getDirDelimiter() + "clouds"));
LLDirIterator dir_iter(cloudDir, "*.tga");
std::string file;
while (dir_iter.next(file))
{
cloud_combo->add(file);
}
cloud_combo->setSimple(gSavedSettings.getString("FSCloudTexture"));
}
}
void FSPanelPrefs::onCommitTexture(const LLSD& data)
{
LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>("texture control");
if (!texture_ctrl)
{
return;
}
if (!texture_ctrl->getTentative())
{
// we grab the item id first, because we want to do a
// permissions check
LLUUID id = texture_ctrl->getImageItemID();
if (id.isNull())
{
id = texture_ctrl->getImageAssetID();
}
// Texture picker defaults aren't inventory items
// * Don't need to worry about permissions for them
LLViewerInventoryItem* item = gInventory.getItem(id);
if (item && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()))
{
// Do not have permission to copy the texture.
return;
}
gSavedSettings.setString("FSDefaultObjectTexture", texture_ctrl->getImageAssetID().asString());
}
}
void FSPanelPrefs::onCommitCopy()
{
// Implements fair use
BOOL copyable = gSavedSettings.getBOOL("NextOwnerCopy");
if (!copyable)
{
gSavedSettings.setBOOL("NextOwnerTransfer", TRUE);
}
LLCheckBoxCtrl* xfer = getChild<LLCheckBoxCtrl>("next_owner_transfer");
xfer->setEnabled(copyable);
}
void FSPanelPrefs::onCommitTrans()
{
BOOL transferable = gSavedSettings.getBOOL("NextOwnerTransfer");
if (!transferable)
{
gSavedSettings.setBOOL("NextOwnerCopy", TRUE);
}
}
void FSPanelPrefs::onCheckContactListColumnMode()
{
childSetEnabled("FSFriendListColumnShowUserName", gSavedSettings.getBOOL("FSFriendListColumnShowDisplayName") || gSavedSettings.getBOOL("FSFriendListColumnShowFullName"));
childSetEnabled("FSFriendListColumnShowDisplayName", gSavedSettings.getBOOL("FSFriendListColumnShowUserName") || gSavedSettings.getBOOL("FSFriendListColumnShowFullName"));
childSetEnabled("FSFriendListColumnShowFullName", gSavedSettings.getBOOL("FSFriendListColumnShowUserName") || gSavedSettings.getBOOL("FSFriendListColumnShowDisplayName"));
}