Skip to content
Snippets Groups Projects
llfloaterpreference.cpp 73.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • James Cook's avatar
    James Cook committed
    /** 
     * @file llfloaterpreference.cpp
    
     * @brief Global preferences with and without persistence.
    
    James Cook's avatar
    James Cook committed
     *
    
     * $LicenseInfo:firstyear=2002&license=viewerlgpl$
    
     * Second Life Viewer Source Code
    
     * Copyright (C) 2010, Linden Research, 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
    
     * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
    
     * $/LicenseInfo$
    
    James Cook's avatar
    James Cook committed
     */
    
    /*
     * App-wide preferences.  Note that these are not per-user,
     * because we need to load many preferences before we have
     * a login name.
     */
    
    #include "llviewerprecompiledheaders.h"
    
    #include "llfloaterpreference.h"
    
    #include "message.h"
    
    #include "llagent.h"
    #include "llavatarconstants.h"
    #include "llcheckboxctrl.h"
    
    #include "lldirpicker.h"
    
    #include "llfeaturemanager.h"
    #include "llfocusmgr.h"
    
    #include "llfloaterreg.h"
    
    James Cook's avatar
    James Cook committed
    #include "llfloaterabout.h"
    
    #include "llfloaterhardwaresettings.h"
    
    #include "llfloatersidepanelcontainer.h"
    
    #include "llkeyboard.h"
    #include "llmodaldialog.h"
    
    #include "llnotificationtemplate.h"
    
    #include "llpanelvoicedevicesettings.h"
    
    #include "llradiogroup.h"
    
    Steven Bennetts's avatar
    Steven Bennetts committed
    #include "llsearchcombobox.h"
    
    #include "llscrolllistctrl.h"
    #include "llscrolllistitem.h"
    #include "llsliderctrl.h"
    #include "lltabcontainer.h"
    
    James Cook's avatar
    James Cook committed
    #include "llviewercontrol.h"
    
    #include "llviewercamera.h"
    
    James Cook's avatar
    James Cook committed
    #include "llviewerwindow.h"
    
    #include "llviewermessage.h"
    #include "llviewershadermgr.h"
    
    #include "llvotree.h"
    #include "llvosky.h"
    
    // linden library includes
    
    #include "llavatarnamecache.h"
    
    #include "llerror.h"
    #include "llfontgl.h"
    #include "llrect.h"
    #include "llstring.h"
    
    // project includes
    
    #include "llbutton.h"
    #include "llflexibleobject.h"
    #include "lllineeditor.h"
    #include "llresmgr.h"
    #include "llspinctrl.h"
    #include "llstartup.h"
    #include "lltextbox.h"
    #include "llui.h"
    #include "llviewerobjectlist.h"
    #include "llvoavatar.h"
    #include "llvovolume.h"
    #include "llwindow.h"
    #include "llworld.h"
    #include "pipeline.h"
    #include "lluictrlfactory.h"
    
    #include "llviewermedia.h"
    #include "llpluginclassmedia.h"
    
    Steven Bennetts's avatar
    Steven Bennetts committed
    #include "llteleporthistorystorage.h"
    
    #include "llproxy.h"
    
    #include "lllogininstance.h"        // to check if logged in yet
    
    const F32 MAX_USER_FAR_CLIP = 512.f;
    const F32 MIN_USER_FAR_CLIP = 64.f;
    
    Paul ProductEngine's avatar
    Paul ProductEngine committed
    const F32 BANDWIDTH_UPDATER_TIMEOUT = 0.5f;
    
    //control value for middle mouse as talk2push button
    const static std::string MIDDLE_MOUSE_CV = "MiddleMouse";
    
    
    class LLVoiceSetKeyDialog : public LLModalDialog
    
    {
    public:
    	LLVoiceSetKeyDialog(const LLSD& key);
    	~LLVoiceSetKeyDialog();
    	
    	/*virtual*/ BOOL postBuild();
    	
    	void setParent(LLFloaterPreference* parent) { mParent = parent; }
    	
    	BOOL handleKeyHere(KEY key, MASK mask);
    	static void onCancel(void* user_data);
    
    private:
    	LLFloaterPreference* mParent;
    };
    
    LLVoiceSetKeyDialog::LLVoiceSetKeyDialog(const LLSD& key)
      : LLModalDialog(key),
    	mParent(NULL)
    {
    }
    
    //virtual
    BOOL LLVoiceSetKeyDialog::postBuild()
    
    James Cook's avatar
    James Cook committed
    {
    
    	childSetAction("Cancel", onCancel, this);
    
    	getChild<LLUICtrl>("Cancel")->setFocus(TRUE);
    
    	
    	gFocusMgr.setKeystrokesOnly(TRUE);
    
    LLVoiceSetKeyDialog::~LLVoiceSetKeyDialog()
    
    BOOL LLVoiceSetKeyDialog::handleKeyHere(KEY key, MASK mask)
    
    James Cook's avatar
    James Cook committed
    {
    
    	if (key == 'Q' && mask == MASK_CONTROL)
    
    	{
    		mParent->setKey(key);
    	}
    	closeFloater();
    	return result;
    }
    
    James Cook's avatar
    James Cook committed
    
    
    //static
    void LLVoiceSetKeyDialog::onCancel(void* user_data)
    {
    	LLVoiceSetKeyDialog* self = (LLVoiceSetKeyDialog*)user_data;
    	self->closeFloater();
    }
    
    // helper functions for getting/freeing the web browser media
    // if creating/destroying these is too slow, we'll need to create
    // a static member and update all our static callbacks
    
    James Cook's avatar
    James Cook committed
    
    
    void handleNameTagOptionChanged(const LLSD& newvalue);	
    
    void handleDisplayNamesOptionChanged(const LLSD& newvalue);	
    
    bool callback_clear_browser_cache(const LLSD& notification, const LLSD& response);
    
    bool callback_clear_cache(const LLSD& notification, const LLSD& response);
    
    James Cook's avatar
    James Cook committed
    
    
    //bool callback_skip_dialogs(const LLSD& notification, const LLSD& response, LLFloaterPreference* floater);
    //bool callback_reset_dialogs(const LLSD& notification, const LLSD& response, LLFloaterPreference* floater);
    
    James Cook's avatar
    James Cook committed
    
    
    void fractionFromDecimal(F32 decimal_val, S32& numerator, S32& denominator);
    
    
    bool callback_clear_cache(const LLSD& notification, const LLSD& response)
    {
    	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
    	if ( option == 0 ) // YES
    	{
    		// flag client texture cache for clearing next time the client runs
    		gSavedSettings.setBOOL("PurgeCacheOnNextStartup", TRUE);
    		LLNotificationsUtil::add("CacheWillClear");
    	}
    
    	return false;
    }
    
    
    bool callback_clear_browser_cache(const LLSD& notification, const LLSD& response)
    {
    
    	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
    
    	if ( option == 0 ) // YES
    
    		LLViewerMedia::clearAllCaches();
    		LLViewerMedia::clearAllCookies();
    
    		
    		// clean nav bar history
    		LLNavigationBar::getInstance()->clearHistoryCache();
    		
    		// flag client texture cache for clearing next time the client runs
    		gSavedSettings.setBOOL("PurgeCacheOnNextStartup", TRUE);
    
    		LLNotificationsUtil::add("CacheWillClear");
    
    Steven Bennetts's avatar
    Steven Bennetts committed
    
    		LLSearchHistory::getInstance()->clearHistory();
    		LLSearchHistory::getInstance()->save();
    		LLSearchComboBox* search_ctrl = LLNavigationBar::getInstance()->getChild<LLSearchComboBox>("search_combo_box");
    		search_ctrl->clearHistory();
    
    Steven Bennetts's avatar
    Steven Bennetts committed
    
    		LLTeleportHistoryStorage::getInstance()->purgeItems();
    		LLTeleportHistoryStorage::getInstance()->save();
    
    void handleNameTagOptionChanged(const LLSD& newvalue)
    {
    
    	LLAvatarNameCache::setUseUsernames(gSavedSettings.getBOOL("NameTagShowUsernames"));
    
    	LLVOAvatar::invalidateNameTags();
    
    James Cook's avatar
    James Cook committed
    
    
    void handleDisplayNamesOptionChanged(const LLSD& newvalue)
    {
    	LLAvatarNameCache::setUseDisplayNames(newvalue.asBoolean());
    
    	LLVOAvatar::invalidateNameTags();
    
    /*bool callback_skip_dialogs(const LLSD& notification, const LLSD& response, LLFloaterPreference* floater)
    
    	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
    
    	if (0 == option && floater )
    
    		if ( floater )
    		{
    			floater->setAllIgnored();
    
    			floater->buildPopupLists();
    
    bool callback_reset_dialogs(const LLSD& notification, const LLSD& response, LLFloaterPreference* floater)
    
    	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
    
    	if ( 0 == option && floater )
    
    		if ( floater )
    		{
    			floater->resetAllIgnored();
    
    			floater->buildPopupLists();
    
    
    void fractionFromDecimal(F32 decimal_val, S32& numerator, S32& denominator)
    {
    	numerator = 0;
    	denominator = 0;
    	for (F32 test_denominator = 1.f; test_denominator < 30.f; test_denominator += 1.f)
    	{
    		if (fmodf((decimal_val * test_denominator) + 0.01f, 1.f) < 0.02f)
    		{
    			numerator = llround(decimal_val * test_denominator);
    			denominator = llround(test_denominator);
    			break;
    		}
    	}
    }
    
    // static
    std::string LLFloaterPreference::sSkin = "";
    //////////////////////////////////////////////
    // LLFloaterPreference
    
    LLFloaterPreference::LLFloaterPreference(const LLSD& key)
    	: LLFloater(key),
    	mGotPersonalInfo(false),
    
    	mAvatarDataInitialized(false),
    
    	LLConversationLog::instance().addObserver(this);
    
    
    	//Build Floater is now Called from 	LLFloaterReg::add("preferences", "floater_preferences.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterPreference>);
    
    	
    	static bool registered_dialog = false;
    	if (!registered_dialog)
    	{
    		LLFloaterReg::add("voice_set_key", "floater_select_key.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLVoiceSetKeyDialog>);
    		registered_dialog = true;
    	}
    	
    
    	mCommitCallbackRegistrar.add("Pref.Apply",				boost::bind(&LLFloaterPreference::onBtnApply, this));
    	mCommitCallbackRegistrar.add("Pref.Cancel",				boost::bind(&LLFloaterPreference::onBtnCancel, this));
    	mCommitCallbackRegistrar.add("Pref.OK",					boost::bind(&LLFloaterPreference::onBtnOK, this));
    	
    
    	mCommitCallbackRegistrar.add("Pref.ClearCache",				boost::bind(&LLFloaterPreference::onClickClearCache, this));
    
    	mCommitCallbackRegistrar.add("Pref.WebClearCache",			boost::bind(&LLFloaterPreference::onClickBrowserClearCache, this));
    
    	mCommitCallbackRegistrar.add("Pref.SetCache",				boost::bind(&LLFloaterPreference::onClickSetCache, this));
    	mCommitCallbackRegistrar.add("Pref.ResetCache",				boost::bind(&LLFloaterPreference::onClickResetCache, this));
    	mCommitCallbackRegistrar.add("Pref.ClickSkin",				boost::bind(&LLFloaterPreference::onClickSkin, this,_1, _2));
    	mCommitCallbackRegistrar.add("Pref.SelectSkin",				boost::bind(&LLFloaterPreference::onSelectSkin, this));
    	mCommitCallbackRegistrar.add("Pref.VoiceSetKey",			boost::bind(&LLFloaterPreference::onClickSetKey, this));
    	mCommitCallbackRegistrar.add("Pref.VoiceSetMiddleMouse",	boost::bind(&LLFloaterPreference::onClickSetMiddleMouse, this));
    
    	mCommitCallbackRegistrar.add("Pref.SetSounds",				boost::bind(&LLFloaterPreference::onClickSetSounds, this));
    
    	mCommitCallbackRegistrar.add("Pref.ClickEnablePopup",		boost::bind(&LLFloaterPreference::onClickEnablePopup, this));
    
    	mCommitCallbackRegistrar.add("Pref.ClickDisablePopup",		boost::bind(&LLFloaterPreference::onClickDisablePopup, this));	
    
    	mCommitCallbackRegistrar.add("Pref.LogPath",				boost::bind(&LLFloaterPreference::onClickLogPath, this));
    
    	mCommitCallbackRegistrar.add("Pref.HardwareSettings",		boost::bind(&LLFloaterPreference::onOpenHardwareSettings, this));
    	mCommitCallbackRegistrar.add("Pref.HardwareDefaults",		boost::bind(&LLFloaterPreference::setHardwareDefaults, this));
    	mCommitCallbackRegistrar.add("Pref.VertexShaderEnable",		boost::bind(&LLFloaterPreference::onVertexShaderEnable, this));
    	mCommitCallbackRegistrar.add("Pref.WindowedMod",			boost::bind(&LLFloaterPreference::onCommitWindowedMode, this));
    
    	mCommitCallbackRegistrar.add("Pref.UpdateSliderText",		boost::bind(&LLFloaterPreference::refreshUI,this));
    
    	mCommitCallbackRegistrar.add("Pref.QualityPerformance",		boost::bind(&LLFloaterPreference::onChangeQuality, this, _2));
    
    	mCommitCallbackRegistrar.add("Pref.applyUIColor",			boost::bind(&LLFloaterPreference::applyUIColor, this ,_1, _2));
    	mCommitCallbackRegistrar.add("Pref.getUIColor",				boost::bind(&LLFloaterPreference::getUIColor, this ,_1, _2));
    
    	mCommitCallbackRegistrar.add("Pref.MaturitySettings",		boost::bind(&LLFloaterPreference::onChangeMaturity, this));
    
    	mCommitCallbackRegistrar.add("Pref.BlockList",				boost::bind(&LLFloaterPreference::onClickBlockList, this));
    
    	mCommitCallbackRegistrar.add("Pref.Proxy",					boost::bind(&LLFloaterPreference::onClickProxySettings, this));
    
    	mCommitCallbackRegistrar.add("Pref.TranslationSettings",	boost::bind(&LLFloaterPreference::onClickTranslationSettings, this));
    
    	mCommitCallbackRegistrar.add("Pref.AutoReplace",            boost::bind(&LLFloaterPreference::onClickAutoReplace, this));
    
    	mCommitCallbackRegistrar.add("Pref.SpellChecker",           boost::bind(&LLFloaterPreference::onClickSpellChecker, this));
    
    	sSkin = gSavedSettings.getString("SkinCurrent");
    
    	mCommitCallbackRegistrar.add("Pref.ClickActionChange",		boost::bind(&LLFloaterPreference::onClickActionChange, this));
    
    	gSavedSettings.getControl("NameTagShowUsernames")->getCommitSignal()->connect(boost::bind(&handleNameTagOptionChanged,  _2));	
    
    	gSavedSettings.getControl("NameTagShowFriends")->getCommitSignal()->connect(boost::bind(&handleNameTagOptionChanged,  _2));	
    
    	gSavedSettings.getControl("UseDisplayNames")->getCommitSignal()->connect(boost::bind(&handleDisplayNamesOptionChanged,  _2));
    
    	LLAvatarPropertiesProcessor::getInstance()->addObserver( gAgent.getID(), this );
    
    
    	mCommitCallbackRegistrar.add("Pref.ClearLog",				boost::bind(&LLConversationLog::onClearLog, &LLConversationLog::instance()));
    	mCommitCallbackRegistrar.add("Pref.DeleteTranscripts",      boost::bind(&LLFloaterPreference::onDeleteTranscripts, this));
    
    void LLFloaterPreference::processProperties( void* pData, EAvatarProcessorType type )
    {
    	if ( APT_PROPERTIES == type )
    	{
    		const LLAvatarData* pAvatarData = static_cast<const LLAvatarData*>( pData );
    
    		if (pAvatarData && (gAgent.getID() == pAvatarData->avatar_id) && (pAvatarData->avatar_id != LLUUID::null))
    
    		{
    			storeAvatarProperties( pAvatarData );
    			processProfileProperties( pAvatarData );
    		}
    
    void LLFloaterPreference::storeAvatarProperties( const LLAvatarData* pAvatarData )
    {
    
    	if (LLStartUp::getStartupState() == STATE_STARTED)
    
    		mAvatarProperties.avatar_id		= pAvatarData->avatar_id;
    
    		mAvatarProperties.image_id		= pAvatarData->image_id;
    		mAvatarProperties.fl_image_id   = pAvatarData->fl_image_id;
    		mAvatarProperties.about_text	= pAvatarData->about_text;
    		mAvatarProperties.fl_about_text = pAvatarData->fl_about_text;
    		mAvatarProperties.profile_url   = pAvatarData->profile_url;
    		mAvatarProperties.flags		    = pAvatarData->flags;
    		mAvatarProperties.allow_publish	= pAvatarData->flags & AVATAR_ALLOW_PUBLISH;
    
    		mAvatarDataInitialized = true;
    	}
    
    void LLFloaterPreference::processProfileProperties(const LLAvatarData* pAvatarData )
    {
    
    prep's avatar
    prep committed
    	getChild<LLUICtrl>("online_searchresults")->setValue( (bool)(pAvatarData->flags & AVATAR_ALLOW_PUBLISH) );	
    
    void LLFloaterPreference::saveAvatarProperties( void )
    {
    
    	const BOOL allowPublish = getChild<LLUICtrl>("online_searchresults")->getValue();
    
    	if (allowPublish)
    
    prep's avatar
    prep committed
    	{
    		mAvatarProperties.flags |= AVATAR_ALLOW_PUBLISH;
    	}
    
    	//
    	// NOTE: We really don't want to send the avatar properties unless we absolutely
    	//       need to so we can avoid the accidental profile reset bug, so, if we're
    	//       logged in, the avatar data has been initialized and we have a state change
    	//       for the "allow publish" flag, then set the flag to its new value and send
    	//       the properties update.
    	//
    	// NOTE: The only reason we can not remove this update altogether is because of the
    	//       "allow publish" flag, the last remaining profile setting in the viewer
    	//       that doesn't exist in the web profile.
    	//
    	if ((LLStartUp::getStartupState() == STATE_STARTED) && mAvatarDataInitialized && (allowPublish != mAvatarProperties.allow_publish))
    
    		mAvatarProperties.allow_publish = allowPublish;
    
    
    		LLAvatarPropertiesProcessor::getInstance()->sendAvatarPropertiesUpdate( &mAvatarProperties );
    	}
    
    BOOL LLFloaterPreference::postBuild()
    {
    
    	gSavedSettings.getControl("ChatFontSize")->getSignal()->connect(boost::bind(&LLFloaterIMSessionTab::processChatHistoryStyleUpdate, false));
    
    	gSavedSettings.getControl("ChatFontSize")->getSignal()->connect(boost::bind(&LLViewerChat::signalChatFontChanged));
    
    
    	gSavedSettings.getControl("ChatBubbleOpacity")->getSignal()->connect(boost::bind(&LLFloaterPreference::onNameTagOpacityChange, this, _2));
    
    
    	gSavedSettings.getControl("PreferredMaturity")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeMaturity, this));
    
    
    	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
    	if (!tabcontainer->selectTab(gSavedSettings.getS32("LastPrefTab")))
    		tabcontainer->selectFirstTab();
    
    	getChild<LLUICtrl>("cache_location")->setEnabled(FALSE); // make it read-only but selectable (STORM-227)
    
    	std::string cache_location = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
    
    	getChild<LLUICtrl>("log_path_string")->setEnabled(FALSE); // make it read-only but selectable
    
    
    	getChild<LLComboBox>("language_combobox")->setCommitCallback(boost::bind(&LLFloaterPreference::onLanguageChange, this));
    
    
    	getChild<LLComboBox>("FriendIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"FriendIMOptions"));
    	getChild<LLComboBox>("NonFriendIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"NonFriendIMOptions"));
    	getChild<LLComboBox>("ConferenceIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"ConferenceIMOptions"));
    	getChild<LLComboBox>("GroupChatOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"GroupChatOptions"));
    	getChild<LLComboBox>("NearbyChatOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"NearbyChatOptions"));
    
    	getChild<LLComboBox>("ObjectIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"ObjectIMOptions"));
    
    	// if floater is opened before login set default localized do not disturb message
    
    	if (LLStartUp::getStartupState() < STATE_STARTED)
    	{
    
    		gSavedPerAccountSettings.setString("DoNotDisturbModeResponse", LLTrans::getString("DoNotDisturbModeResponseDefault"));
    
    	// set 'enable' property for 'Clear log...' button
    	changed();
    
    	LLLogChat::setSaveHistorySignal(boost::bind(&LLFloaterPreference::onLogChatHistorySaved, this));
    
    
    void LLFloaterPreference::updateDeleteTranscriptsButton()
    {
    	std::vector<std::string> list_of_transcriptions_file_names;
    	LLLogChat::getListOfTranscriptFiles(list_of_transcriptions_file_names);
    	getChild<LLButton>("delete_transcripts")->setEnabled(list_of_transcriptions_file_names.size() > 0);
    }
    
    
    void LLFloaterPreference::onDoNotDisturbResponseChanged()
    
    	// set "DoNotDisturbResponseChanged" TRUE if user edited message differs from default, FALSE otherwise
    	bool response_changed_flag =
    			LLTrans::getString("DoNotDisturbModeResponseDefault")
    					!= getChild<LLUICtrl>("do_not_disturb_response")->getValue().asString();
    
    	gSavedPerAccountSettings.setBOOL("DoNotDisturbResponseChanged", response_changed_flag );
    
    LLFloaterPreference::~LLFloaterPreference()
    {
    
    	// clean up user data
    	LLComboBox* ctrl_window_size = getChild<LLComboBox>("windowsize combo");
    	for (S32 i = 0; i < ctrl_window_size->getItemCount(); i++)
    	{
    		ctrl_window_size->setCurrentByIndex(i);
    	}
    
    
    	LLConversationLog::instance().removeObserver(this);
    
    void LLFloaterPreference::draw()
    {
    	BOOL has_first_selected = (getChildRef<LLScrollListCtrl>("disabled_popups").getFirstSelected()!=NULL);
    	gSavedSettings.setBOOL("FirstSelectedDisabledPopups", has_first_selected);
    
    	
    	has_first_selected = (getChildRef<LLScrollListCtrl>("enabled_popups").getFirstSelected()!=NULL);
    	gSavedSettings.setBOOL("FirstSelectedEnabledPopups", has_first_selected);
    	
    
    void LLFloaterPreference::saveSettings()
    {
    	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
    	child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
    	child_list_t::const_iterator end = tabcontainer->getChildList()->end();
    	for ( ; iter != end; ++iter)
    	{
    		LLView* view = *iter;
    		LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
    		if (panel)
    			panel->saveSettings();
    	}
    }	
    
    
    void LLFloaterPreference::apply()
    {
    
    	LLAvatarPropertiesProcessor::getInstance()->addObserver( gAgent.getID(), this );
    	
    
    	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
    	if (sSkin != gSavedSettings.getString("SkinCurrent"))
    
    		LLNotificationsUtil::add("ChangeSkin");
    
    	// Call apply() on all panels that derive from LLPanelPreference
    	for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
    		 iter != tabcontainer->getChildList()->end(); ++iter)
    
    		LLView* view = *iter;
    		LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
    		if (panel)
    			panel->apply();
    
    	LLFloaterHardwareSettings* hardware_settings = LLFloaterReg::getTypedInstance<LLFloaterHardwareSettings>("prefs_hardware_settings");
    
    	if (hardware_settings)
    	{
    		hardware_settings->apply();
    	}
    
    	
    	gViewerWindow->requestResolutionUpdate(); // for UIScaleFactor
    
    	LLSliderCtrl* fov_slider = getChild<LLSliderCtrl>("camera_fov");
    	fov_slider->setMinValue(LLViewerCamera::getInstance()->getMinView());
    	fov_slider->setMaxValue(LLViewerCamera::getInstance()->getMaxView());
    	
    	std::string cache_location = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
    
    	LLViewerMedia::setCookiesEnabled(getChild<LLUICtrl>("cookies_enabled")->getValue());
    
    	if (hasChild("web_proxy_enabled", TRUE) &&hasChild("web_proxy_editor", TRUE) && hasChild("web_proxy_port", TRUE))
    
    		bool proxy_enable = getChild<LLUICtrl>("web_proxy_enabled")->getValue();
    		std::string proxy_address = getChild<LLUICtrl>("web_proxy_editor")->getValue();
    		int proxy_port = getChild<LLUICtrl>("web_proxy_port")->getValue();
    
    		LLViewerMedia::setProxyConfig(proxy_enable, proxy_address, proxy_port);
    
    	if (mGotPersonalInfo)
    
    		bool new_im_via_email = getChild<LLUICtrl>("send_im_to_email")->getValue().asBoolean();
    		bool new_hide_online = getChild<LLUICtrl>("online_visibility")->getValue().asBoolean();		
    
    		if ((new_im_via_email != mOriginalIMViaEmail)
    
    			||(new_hide_online != mOriginalHideOnlineStatus))
    		{
    			// This hack is because we are representing several different 	 
    			// possible strings with a single checkbox. Since most users 	 
    			// can only select between 2 values, we represent it as a 	 
    			// checkbox. This breaks down a little bit for liaisons, but 	 
    			// works out in the end. 	 
    
    			if (new_hide_online != mOriginalHideOnlineStatus)
    			{
    				if (new_hide_online) mDirectoryVisibility = VISIBILITY_HIDDEN;
    
    				else mDirectoryVisibility = VISIBILITY_DEFAULT;
    			 //Update showonline value, otherwise multiple applys won't work
    				mOriginalHideOnlineStatus = new_hide_online;
    
    			gAgent.sendAgentUpdateUserInfo(new_im_via_email,mDirectoryVisibility);
    		}
    	}
    
    		updateClickActionSettings();
    		mClickActionDirty = false;
    
    }
    
    void LLFloaterPreference::cancel()
    {
    	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
    	// Call cancel() on all panels that derive from LLPanelPreference
    	for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
    		iter != tabcontainer->getChildList()->end(); ++iter)
    
    		LLView* view = *iter;
    		LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
    		if (panel)
    			panel->cancel();
    
    	// hide joystick pref floater
    	LLFloaterReg::hideInstance("pref_joystick");
    
    
    	// hide translation settings floater
    	LLFloaterReg::hideInstance("prefs_translation");
    
    	// hide spellchecker settings folder
    	LLFloaterReg::hideInstance("prefs_spellchecker");
    	
    
    	LLFloaterHardwareSettings* hardware_settings = LLFloaterReg::getTypedInstance<LLFloaterHardwareSettings>("prefs_hardware_settings");
    
    	if (hardware_settings)
    	{
    		hardware_settings->cancel();
    	}
    
    	
    	// reverts any changes to current skin
    	gSavedSettings.setString("SkinCurrent", sSkin);
    
    		updateClickActionControls();
    		mClickActionDirty = false;
    
    	LLFloaterPreferenceProxy * advanced_proxy_settings = LLFloaterReg::findTypedInstance<LLFloaterPreferenceProxy>("prefs_proxy");
    	if (advanced_proxy_settings)
    
    		advanced_proxy_settings->cancel();
    
    	//Need to reload the navmesh if the pathing console is up
    	LLHandle<LLFloaterPathfindingConsole> pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle();
    	if ( !pathfindingConsoleHandle.isDead() )
    	{
    		LLFloaterPathfindingConsole* pPathfindingConsole = pathfindingConsoleHandle.get();
    		pPathfindingConsole->onRegionBoundaryCross();
    	}
    
    }
    
    void LLFloaterPreference::onOpen(const LLSD& key)
    {
    
    	// this variable and if that follows it are used to properly handle do not disturb mode response message
    
    	// if user is logged in and we haven't initialized do not disturb mode response yet, do it
    
    	if (!initialized && LLStartUp::getStartupState() == STATE_STARTED)
    	{
    
    		// Special approach is used for do not disturb response localization, because "DoNotDisturbModeResponse" is
    
    		// in non-localizable xml, and also because it may be changed by user and in this case it shouldn't be localized.
    
    		// To keep track of whether do not disturb response is default or changed by user additional setting DoNotDisturbResponseChanged
    
    		// was added into per account settings.
    
    		// initialization should happen once,so setting variable to TRUE
    		initialized = TRUE;
    
    		// this connection is needed to properly set "DoNotDisturbResponseChanged" setting when user makes changes in
    		// do not disturb response message.
    		gSavedPerAccountSettings.getControl("DoNotDisturbModeResponse")->getSignal()->connect(boost::bind(&LLFloaterPreference::onDoNotDisturbResponseChanged, this));
    
    	gAgent.sendAgentUserInfoRequest();
    
    	/////////////////////////// From LLPanelGeneral //////////////////////////
    	// if we have no agent, we can't let them choose anything
    	// if we have an agent, then we only let them choose if they have a choice
    
    	bool can_choose_maturity =
    
    		gAgent.getID().notNull() &&
    		(gAgent.isMature() || gAgent.isGodlike());
    
    	LLComboBox* maturity_combo = getChild<LLComboBox>("maturity_desired_combobox");
    
    	LLAvatarPropertiesProcessor::getInstance()->sendAvatarPropertiesRequest( gAgent.getID() );
    
    		// if they're not adult or a god, they shouldn't see the adult selection, so delete it
    
    		if (!gAgent.isAdult() && !gAgent.isGodlikeWithoutAdminMenuFakery())
    
    			// we're going to remove the adult entry from the combo
    			LLScrollListCtrl* maturity_list = maturity_combo->findChild<LLScrollListCtrl>("ComboBox");
    			if (maturity_list)
    			{
    				maturity_list->deleteItems(LLSD(SIM_ACCESS_ADULT));
    			}
    
    		getChildView("maturity_desired_combobox")->setVisible( true);
    		getChildView("maturity_desired_textbox")->setVisible( false);
    
    		getChild<LLUICtrl>("maturity_desired_textbox")->setValue(maturity_combo->getSelectedItemLabel());
    		getChildView("maturity_desired_combobox")->setVisible( false);
    
    	// Forget previous language changes.
    	mLanguageChanged = false;
    
    
    	// Display selected maturity icons.
    	onChangeMaturity();
    
    	// Load (double-)click to walk/teleport settings.
    	updateClickActionControls();
    
    	// Enabled/disabled popups, might have been changed by user actions
    	// while preferences floater was closed.
    	buildPopupLists();
    
    
    
    	//get the options that were checked
    	onNotificationsChange("FriendIMOptions");
    	onNotificationsChange("NonFriendIMOptions");
    	onNotificationsChange("ConferenceIMOptions");
    	onNotificationsChange("GroupChatOptions");
    	onNotificationsChange("NearbyChatOptions");
    
    	onNotificationsChange("ObjectIMOptions");
    
    	LLPanelLogin::setAlwaysRefresh(true);
    
    	
    	// Make sure the current state of prefs are saved away when
    	// when the floater is opened.  That will make cancel do its
    	// job
    	saveSettings();
    
    }
    
    void LLFloaterPreference::onVertexShaderEnable()
    {
    	refreshEnabledGraphics();
    }
    
    
    void LLFloaterPreference::initDoNotDisturbResponse()
    
    		if (!gSavedPerAccountSettings.getBOOL("DoNotDisturbResponseChanged"))
    
    			//LLTrans::getString("DoNotDisturbModeResponseDefault") is used here for localization (EXT-5885)
    			gSavedPerAccountSettings.setString("DoNotDisturbModeResponse", LLTrans::getString("DoNotDisturbModeResponseDefault"));
    
    void LLFloaterPreference::setHardwareDefaults()
    {
    	LLFeatureManager::getInstance()->applyRecommendedSettings();
    	refreshEnabledGraphics();
    
    	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
    	child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
    	child_list_t::const_iterator end = tabcontainer->getChildList()->end();
    	for ( ; iter != end; ++iter)
    	{
    		LLView* view = *iter;
    		LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
    		if (panel)
    			panel->setHardwareDefaults();
    	}
    
    //virtual
    void LLFloaterPreference::onClose(bool app_quitting)
    
    {
    	gSavedSettings.setS32("LastPrefTab", getChild<LLTabContainer>("pref core")->getCurrentPanelIndex());
    	LLPanelLogin::setAlwaysRefresh(false);
    
    void LLFloaterPreference::onOpenHardwareSettings()
    {
    
    	LLFloater* floater = LLFloaterReg::showInstance("prefs_hardware_settings");
    	addDependentFloater(floater, FALSE);
    
    }
    // static 
    void LLFloaterPreference::onBtnOK()
    {
    	// commit any outstanding text entry
    	if (hasFocus())
    
    		LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
    
    Tofu Linden's avatar
    Tofu Linden committed
    		if (cur_focus && cur_focus->acceptsTextInput())
    
    		apply();
    		closeFloater(false);
    
    		//Conversation transcript and log path changed so reload conversations based on new location
    
    		if(mPriorInstantMessageLogPath.length())
    
    			if(moveTranscriptsAndLog())
    			{
    				//When floaters are empty but have a chat history files, reload chat history into them
    				LLFloaterIMSessionTab::reloadEmptyFloaters();
    			}
    
    			//Couldn't move files so restore the old path and show a notification
    
    			{
    				gSavedPerAccountSettings.setString("InstantMessageLogPath", mPriorInstantMessageLogPath);
    				LLNotificationsUtil::add("PreferenceChatPathChanged");
    			}
    			mPriorInstantMessageLogPath.clear();
    
    		LLUIColorTable::instance().saveUserSettings();
    
    		gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
    
    		
    		//Only save once logged in and loaded per account settings
    		if(mGotPersonalInfo)
    		{
    			gSavedPerAccountSettings.saveToFile(gSavedSettings.getString("PerAccountSettingsFile"), TRUE);
    
    Gilbert Gonzales's avatar
    Gilbert Gonzales committed
    	}
    
    		// Show beep, pop up dialog, etc.
    		llinfos << "Can't close preferences!" << llendl;
    
    	LLPanelLogin::updateLocationSelectorsVisibility();	
    	//Need to reload the navmesh if the pathing console is up
    	LLHandle<LLFloaterPathfindingConsole> pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle();
    	if ( !pathfindingConsoleHandle.isDead() )
    	{
    		LLFloaterPathfindingConsole* pPathfindingConsole = pathfindingConsoleHandle.get();
    		pPathfindingConsole->onRegionBoundaryCross();
    	}
    	
    
    // static 
    void LLFloaterPreference::onBtnApply( )
    
    James Cook's avatar
    James Cook committed
    {
    
    		LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
    
    Tofu Linden's avatar
    Tofu Linden committed
    		if (cur_focus && cur_focus->acceptsTextInput())
    
    	LLPanelLogin::updateLocationSelectorsVisibility();
    
    // static 
    void LLFloaterPreference::onBtnCancel()
    {
    	if (hasFocus())
    
    		LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
    
    Tofu Linden's avatar
    Tofu Linden committed
    		if (cur_focus && cur_focus->acceptsTextInput())
    
    void LLFloaterPreference::updateUserInfo(const std::string& visibility, bool im_via_email)
    
    James Cook's avatar
    James Cook committed
    {
    
    	LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
    
    		instance->setPersonalInfo(visibility, im_via_email);	
    
    
    void LLFloaterPreference::refreshEnabledGraphics()
    {
    	LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
    
    		instance->refresh();
    		//instance->refreshEnabledState();
    
    	LLFloaterHardwareSettings* hardware_settings = LLFloaterReg::getTypedInstance<LLFloaterHardwareSettings>("prefs_hardware_settings");
    
    	if (hardware_settings)
    	{
    		hardware_settings->refreshEnabledState();
    	}
    
    James Cook's avatar
    James Cook committed
    }
    
    void LLFloaterPreference::onClickClearCache()
    {
    	LLNotificationsUtil::add("ConfirmClearCache", LLSD(), LLSD(), callback_clear_cache);
    }
    
    
    void LLFloaterPreference::onClickBrowserClearCache()
    
    James Cook's avatar
    James Cook committed
    {
    
    	LLNotificationsUtil::add("ConfirmClearBrowserCache", LLSD(), LLSD(), callback_clear_browser_cache);
    
    // Called when user changes language via the combobox.
    void LLFloaterPreference::onLanguageChange()
    {
    	// Let the user know that the change will only take effect after restart.
    	// Do it only once so that we're not too irritating.
    	if (!mLanguageChanged)
    	{
    		LLNotificationsUtil::add("ChangeLanguage");
    		mLanguageChanged = true;
    	}
    }
    
    
    void LLFloaterPreference::onNotificationsChange(const std::string& OptionName)
    {
    	mNotificationOptions[OptionName] = getChild<LLComboBox>(OptionName)->getSelectedItemLabel();
    
    	bool show_notifications_alert = true;
    	for (notifications_map::iterator it_notification = mNotificationOptions.begin(); it_notification != mNotificationOptions.end(); it_notification++)
    	{
    
    		if(it_notification->second != "No action")
    
    		{
    			show_notifications_alert = false;
    			break;
    		}
    	}
    
    	getChild<LLTextBox>("notifications_alert")->setVisible(show_notifications_alert);
    }
    
    
    void LLFloaterPreference::onNameTagOpacityChange(const LLSD& newvalue)
    {
    	LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>("background");
    	if (color_swatch)
    	{
    		LLColor4 new_color = color_swatch->get();
    		color_swatch->set( new_color.setAlpha(newvalue.asReal()) );
    	}
    }
    
    
    void LLFloaterPreference::onClickSetCache()
    
    James Cook's avatar
    James Cook committed
    {
    
    	std::string cur_name(gSavedSettings.getString("CacheLocation"));
    
    //	std::string cur_top_folder(gDirUtilp->getBaseFileName(cur_name));
    	
    
    	std::string proposed_name(cur_name);
    
    James Cook's avatar
    James Cook committed
    
    
    	LLDirPicker& picker = LLDirPicker::instance();
    	if (! picker.getDir(&proposed_name ) )
    
    James Cook's avatar
    James Cook committed
    	{
    
    	std::string dir_name = picker.getDirName();
    	if (!dir_name.empty() && dir_name != cur_name)
    	{
    
    		std::string new_top_folder(gDirUtilp->getBaseFileName(dir_name));	
    
    		LLNotificationsUtil::add("CacheWillBeMoved");
    
    		gSavedSettings.setString("NewCacheLocation", dir_name);
    
    		gSavedSettings.setString("NewCacheLocationTopFolder", new_top_folder);
    
    	}
    	else
    	{
    		std::string cache_location = gDirUtilp->getCacheDir();
    
    		gSavedSettings.setString("CacheLocation", cache_location);
    		std::string top_folder(gDirUtilp->getBaseFileName(cache_location));
    		gSavedSettings.setString("CacheLocationTopFolder", top_folder);
    
    void LLFloaterPreference::onClickResetCache()
    
    James Cook's avatar
    James Cook committed
    {
    
    	if (gDirUtilp->getCacheDir(false) == gDirUtilp->getCacheDir(true))
    
    		// The cache location was already the default.
    		return;
    
    	gSavedSettings.setString("NewCacheLocation", "");
    	gSavedSettings.setString("NewCacheLocationTopFolder", "");
    
    	LLNotificationsUtil::add("CacheWillBeMoved");
    
    	std::string cache_location = gDirUtilp->getCacheDir(false);
    
    	gSavedSettings.setString("CacheLocation", cache_location);
    	std::string top_folder(gDirUtilp->getBaseFileName(cache_location));
    	gSavedSettings.setString("CacheLocationTopFolder", top_folder);