Skip to content
Snippets Groups Projects
llfloaterpreference.cpp 51.1 KiB
Newer Older
	refresh();
}

void LLFloaterPreference::onChangeQuality(const LLSD& data)
{
	U32 level = (U32)(data.asReal());
	LLFeatureManager::getInstance()->setGraphicsLevel(level, true);
	refreshEnabledGraphics();
	refresh();
}

// static
// DEV-24146 -  needs to be removed at a later date. jan-2009
void LLFloaterPreference::cleanupBadSetting()
{
	if (gSavedPerAccountSettings.getString("BusyModeResponse2") == "|TOKEN COPY BusyModeResponse|")
James Cook's avatar
James Cook committed
	{
		llwarns << "cleaning old BusyModeResponse" << llendl;
		gSavedPerAccountSettings.setString("BusyModeResponse2", gSavedPerAccountSettings.getText("BusyModeResponse"));
James Cook's avatar
James Cook committed
	}
void LLFloaterPreference::onClickSetKey()
{
	LLVoiceSetKeyDialog* dialog = new LLVoiceSetKeyDialog(this);
	dialog->startModal();
void LLFloaterPreference::setKey(KEY key)
{
	childSetValue("modifier_combo", LLKeyboard::stringFromKey(key));
}
James Cook's avatar
James Cook committed

void LLFloaterPreference::onClickSetMiddleMouse()
James Cook's avatar
James Cook committed
{
	childSetValue("modifier_combo", "MiddleMouse");
void LLFloaterPreference::onClickSkipDialogs()
{
	LLNotifications::instance().add("SkipShowNextTimeDialogs", LLSD(), LLSD(), boost::bind(&callback_skip_dialogs, _1, _2, this));
}
James Cook's avatar
James Cook committed

void LLFloaterPreference::onClickResetDialogs()
James Cook's avatar
James Cook committed
{
	LLNotifications::instance().add("ResetShowNextTimeDialogs", LLSD(), LLSD(), boost::bind(&callback_reset_dialogs, _1, _2, this));
}

void LLFloaterPreference::onClickEnablePopup()
{	
	LLScrollListCtrl& disabled_popups = getChildRef<LLScrollListCtrl>("disabled_popups");
	
	std::vector<LLScrollListItem*> items = disabled_popups.getAllSelected();
	std::vector<LLScrollListItem*>::iterator itor;
	for (itor = items.begin(); itor != items.end(); ++itor)
James Cook's avatar
James Cook committed
	{
		LLNotificationTemplatePtr templatep = LLNotifications::instance().getTemplate(*(std::string*)((*itor)->getUserdata()));
		//gSavedSettings.setWarning(templatep->mName, TRUE);
		std::string notification_name = templatep->mName;
		LLUI::sSettingGroups["ignores"]->setBOOL(notification_name, TRUE);
	}
	
	buildLists(this);
}

void LLFloaterPreference::onClickDisablePopup()
{	
	LLScrollListCtrl& enabled_popups = getChildRef<LLScrollListCtrl>("enabled_popups");
	
	std::vector<LLScrollListItem*> items = enabled_popups.getAllSelected();
	std::vector<LLScrollListItem*>::iterator itor;
	for (itor = items.begin(); itor != items.end(); ++itor)
	{
		LLNotificationTemplatePtr templatep = LLNotifications::instance().getTemplate(*(std::string*)((*itor)->getUserdata()));
		//gSavedSettings.setWarning(templatep->mName, TRUE);
		std::string notification_name = templatep->mName;
		LLUI::sSettingGroups["ignores"]->setBOOL(notification_name, FALSE);
	}
	
	buildLists(this);
}
void LLFloaterPreference::resetAllIgnored()
{
	for (LLNotifications::TemplateMap::const_iterator iter = LLNotifications::instance().templatesBegin();
		 iter != LLNotifications::instance().templatesEnd();
		 ++iter)
	{
		if (iter->second->mForm->getIgnoreType() != LLNotificationForm::IGNORE_NO)
James Cook's avatar
James Cook committed
		{
			LLUI::sSettingGroups["ignores"]->setBOOL(iter->first, TRUE);
		}
	}
}

void LLFloaterPreference::setAllIgnored()
{
	for (LLNotifications::TemplateMap::const_iterator iter = LLNotifications::instance().templatesBegin();
		 iter != LLNotifications::instance().templatesEnd();
		 ++iter)
	{
		if (iter->second->mForm->getIgnoreType() != LLNotificationForm::IGNORE_NO)
		{
			LLUI::sSettingGroups["ignores"]->setBOOL(iter->first, FALSE);
James Cook's avatar
James Cook committed

void LLFloaterPreference::onClickLogPath()
{
	std::string proposed_name(gSavedPerAccountSettings.getString("InstantMessageLogPath"));	 
	
	LLDirPicker& picker = LLDirPicker::instance();
	if (!picker.getDir(&proposed_name ) )
James Cook's avatar
James Cook committed
	{
	std::string chat_log_dir = picker.getDirName();
	std::string chat_log_top_folder= gDirUtilp->getBaseFileName(chat_log_dir);
	gSavedPerAccountSettings.setString("InstantMessageLogPath",chat_log_dir);
	gSavedPerAccountSettings.setString("InstantMessageLogFolder",chat_log_top_folder);
James Cook's avatar
James Cook committed

void LLFloaterPreference::onCommitLogging()
{
	enableHistory();
}
void LLFloaterPreference::enableHistory()
{
	if (childGetValue("log_instant_messages").asBoolean())
		childEnable("log_path_button");
		childEnable("show_timestamps_check_im");
		childDisable("log_path_button");
		childDisable("show_timestamps_check_im");
void LLFloaterPreference::setPersonalInfo(const std::string& visibility, bool im_via_email, const std::string& email)
James Cook's avatar
James Cook committed
{
	mGotPersonalInfo = true;
	mOriginalIMViaEmail = im_via_email;
	mDirectoryVisibility = visibility;
	
	if(visibility == VISIBILITY_DEFAULT)
James Cook's avatar
James Cook committed
	{
		mOriginalHideOnlineStatus = false;
		childEnable("online_visibility"); 	 
	}
	else if(visibility == VISIBILITY_HIDDEN)
	{
		mOriginalHideOnlineStatus = true;
		childEnable("online_visibility"); 	 
James Cook's avatar
James Cook committed
	}
	else
	{
		mOriginalHideOnlineStatus = true;
	}
	
	childEnable("include_im_in_chat_history");
	childEnable("show_timestamps_check_im");
	childEnable("friends_online_notify_checkbox");
	
	childSetValue("online_visibility", mOriginalHideOnlineStatus); 	 
	childSetLabelArg("online_visibility", "[DIR_VIS]", mDirectoryVisibility);
	childEnable("send_im_to_email");
	childSetValue("send_im_to_email", im_via_email);
	childEnable("log_instant_messages");
	childEnable("busy_response");
//	childEnable("log_instant_messages_timestamp");
//	childEnable("log_chat_timestamp");
	childEnable("log_chat_IM");
	childEnable("log_date_timestamp");
	
	childSetText("busy_response", gSavedPerAccountSettings.getString("BusyModeResponse2"));
	
	enableHistory();
	std::string display_email(email);
	childSetText("email_address",display_email);
void LLFloaterPreference::onUpdateSliderText(LLUICtrl* ctrl, const LLSD& name)
{
	if(name.asString() =="" || !hasChild("name"))
		return;
	
	LLTextBox* text_box = getChild<LLTextBox>(name.asString());
	LLSliderCtrl* slider = dynamic_cast<LLSliderCtrl*>(ctrl);
	updateSliderText(slider, text_box);
}

void LLFloaterPreference::updateSliderText(LLSliderCtrl* ctrl, LLTextBox* text_box)
{
	if(text_box == NULL || ctrl== NULL)
		return;
	
	// get range and points when text should change
	F32 value = (F32)ctrl->getValue().asReal();
	F32 min = ctrl->getMinValue();
	F32 max = ctrl->getMaxValue();
	F32 range = max - min;
	llassert(range > 0);
	F32 midPoint = min + range / 3.0f;
	F32 highPoint = min + (2.0f * range / 3.0f);
	
	// choose the right text
	if(value < midPoint)
	{
		text_box->setText(LLTrans::getString("GraphicsQualityLow"));
	} 
	else if (value < highPoint)
	{
		text_box->setText(LLTrans::getString("GraphicsQualityMid"));
	}
	else
	{
		text_box->setText(LLTrans::getString("GraphicsQualityHigh"));
	}
}

void LLFloaterPreference::onKeystrokeAspectRatio()
{
	getChild<LLCheckBoxCtrl>("aspect_auto_detect")->set(FALSE);
}

void LLFloaterPreference::applyWindowSize()
{
	LLComboBox* ctrl_windowSize = getChild<LLComboBox>("windowsize combo");
	if (ctrl_windowSize->getVisible() && (ctrl_windowSize->getCurrentIndex() != -1))
	{
		U32 width = 0;
		U32 height = 0;
		if (extractWindowSizeFromString(ctrl_windowSize->getValue().asString().c_str(), width,height))
		{
			LLViewerWindow::movieSize(width, height);
		}
	}
}

void LLFloaterPreference::applyResolution()
{
	LLComboBox* ctrl_aspect_ratio = getChild<LLComboBox>( "aspect_ratio");
	gGL.flush();
	char aspect_ratio_text[ASPECT_RATIO_STR_LEN];		/*Flawfinder: ignore*/
	if (ctrl_aspect_ratio->getCurrentIndex() == -1)
	{
		// *Can't pass const char* from c_str() into strtok
		strncpy(aspect_ratio_text, ctrl_aspect_ratio->getSimple().c_str(), sizeof(aspect_ratio_text) -1);	/*Flawfinder: ignore*/
		aspect_ratio_text[sizeof(aspect_ratio_text) -1] = '\0';
		char *element = strtok(aspect_ratio_text, ":/\\");
		if (!element)
		{
			sAspectRatio = 0.f; // will be clamped later
		}
		else
		{
			LLLocale locale(LLLocale::USER_LOCALE);
			sAspectRatio = (F32)atof(element);
		}
		
		// look for denominator
		element = strtok(NULL, ":/\\");
		if (element)
		{
			LLLocale locale(LLLocale::USER_LOCALE);
			
			F32 denominator = (F32)atof(element);
			if (denominator != 0.f)
			{
				sAspectRatio /= denominator;
			}
		}
	}
	else
	{
		sAspectRatio = (F32)ctrl_aspect_ratio->getValue().asReal();
	}
	
	// presumably, user entered a non-numeric value if aspect_ratio == 0.f
	if (sAspectRatio != 0.f)
	{
		sAspectRatio = llclamp(sAspectRatio, 0.2f, 5.f);
		gSavedSettings.setF32("FullScreenAspectRatio", sAspectRatio);
	}
	
	// Screen resolution
	S32 num_resolutions;
	LLWindow::LLWindowResolution* supported_resolutions = 
	gViewerWindow->getWindow()->getSupportedResolutions(num_resolutions);
	S32 resIndex = getChild<LLComboBox>("fullscreen combo")->getCurrentIndex();
	if (resIndex == -1)
	{
		// use highest resolution if nothing selected
		resIndex = num_resolutions - 1;
	}
	gSavedSettings.setS32("FullScreenWidth", supported_resolutions[resIndex].mWidth);
	gSavedSettings.setS32("FullScreenHeight", supported_resolutions[resIndex].mHeight);
	
	gViewerWindow->requestResolutionUpdate(gSavedSettings.getBOOL("WindowFullScreen"));
	
	send_agent_update(TRUE);
	
	// Update enable/disable
	refresh();
}

void LLFloaterPreference::initWindowSizeControls(LLPanel* panelp)
{
	// Window size
	//	mWindowSizeLabel = getChild<LLTextBox>("WindowSizeLabel");
	LLComboBox* ctrl_window_size = panelp->getChild<LLComboBox>("windowsize combo");
	
	// Look to see if current window size matches existing window sizes, if so then
	// just set the selection value...
	const U32 height = gViewerWindow->getWindowDisplayHeight();
	const U32 width = gViewerWindow->getWindowDisplayWidth();
	for (S32 i=0; i < ctrl_window_size->getItemCount(); i++)
	{
		U32 height_test = 0;
		U32 width_test = 0;
		ctrl_window_size->setCurrentByIndex(i);
		if (extractWindowSizeFromString(ctrl_window_size->getValue().asString(), width_test, height_test))
		{
			if ((height_test == height) && (width_test == width))
			{
				return;
			}
		}
	}
	// ...otherwise, add a new entry with the current window height/width.
	LLUIString resolution_label = panelp->getString("resolution_format");
	resolution_label.setArg("[RES_X]", llformat("%d", width));
	resolution_label.setArg("[RES_Y]", llformat("%d", height));
	ctrl_window_size->add(resolution_label, ADD_TOP);
	ctrl_window_size->setCurrentByIndex(0);
}


//----------------------------------------------------------------------------
static LLRegisterPanelClassWrapper<LLPanelPreference> t_places("panel_preference");
LLPanelPreference::LLPanelPreference()
: LLPanel()
	//
	mCommitCallbackRegistrar.add("setControlFalse",		boost::bind(&LLPanelPreference::setControlFalse,this, _2));
James Cook's avatar
James Cook committed
}

static void applyUIColor(const std::string& color_name, LLUICtrl* ctrl, const LLSD& param)
{
	LLUIColorTable::instance().setColor(color_name, LLColor4(param));
}

//virtual
BOOL LLPanelPreference::postBuild()
{
	if (hasChild("maturity_desired_combobox"))
	{
		/////////////////////////// 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 canChoose = gAgent.getID().notNull() &&
			(gAgent.isMature() || gAgent.isGodlike());
James Cook's avatar
James Cook committed

		if (canChoose)
		{

			// if they're not adult or a god, they shouldn't see the adult selection, so delete it
			if (!gAgent.isAdult() && !gAgent.isGodlike())
			{
				LLComboBox* pMaturityCombo = getChild<LLComboBox>("maturity_desired_combobox");
				// we're going to remove the adult entry from the combo. This obviously depends
				// on the order of items in the XML file, but there doesn't seem to be a reasonable
				// way to depend on the field in XML called 'name'.
				pMaturityCombo->remove(0);
			}
			childSetVisible("maturity_desired_combobox", true);
			childSetVisible("maturity_desired_textbox",	false);
		}
		else
		{
			childSetVisible("maturity_desired_combobox", false);
			std::string selectedItemLabel = getChild<LLComboBox>("maturity_desired_combobox")->getSelectedItemLabel();
			childSetValue("maturity_desired_textbox", selectedItemLabel);
			childSetVisible("maturity_desired_textbox",	true);
		}
	}
	////////////////////// PanelVoice ///////////////////
	if(hasChild("voice_unavailable"))
James Cook's avatar
James Cook committed
	{
		BOOL voice_disabled = gSavedSettings.getBOOL("CmdLineDisableVoice");
		childSetVisible("voice_unavailable", voice_disabled);
		childSetVisible("enable_voice_check", !voice_disabled);
	}
	
	//////////////////////PanelSkins ///////////////////
	
	if (hasChild("skin_selection"))
	{
		LLFloaterPreference::refreshSkin(this);

		// if skin is set to a skin that no longer exists (silver) set back to default
		if (getChild<LLRadioGroup>("skin_selection")->getSelectedIndex() < 0)
James Cook's avatar
James Cook committed
		{
			gSavedSettings.setString("SkinCurrent", "default");
			LLFloaterPreference::refreshSkin(this);
James Cook's avatar
James Cook committed
		}
James Cook's avatar
James Cook committed
	}
	////////////////////////Panel Popups/////////////////
	if(hasChild("disabled_popups") && hasChild("enabled_popups"))
	{
		LLFloaterPreference::buildLists(this);
	}
	//////
	if(hasChild("online_visibility") && hasChild("send_im_to_email"))
	{
		requires("online_visibility");
		requires("send_im_to_email");
		if (!checkRequirements())
		{
			return FALSE;
		}
		childSetText("email_address",getString("log_in_to_change") );
		childSetText("busy_response", getString("log_in_to_change"));
		
	}


	if(hasChild("fullscreen combo"))
	{
		//============================================================================
		// Resolution

		S32 num_resolutions = 0;
		LLWindow::LLWindowResolution* supported_resolutions = gViewerWindow->getWindow()->getSupportedResolutions(num_resolutions);
		
		S32 fullscreen_mode = num_resolutions - 1;
		
		LLComboBox*ctrl_full_screen = getChild<LLComboBox>( "fullscreen combo");
		LLUIString resolution_label = getString("resolution_format");
		
		for (S32 i = 0; i < num_resolutions; i++)
		{
			resolution_label.setArg("[RES_X]", llformat("%d", supported_resolutions[i].mWidth));
			resolution_label.setArg("[RES_Y]", llformat("%d", supported_resolutions[i].mHeight));
			ctrl_full_screen->add( resolution_label, ADD_BOTTOM );
		}
		
		{
			BOOL targetFullscreen;
			S32 targetWidth;
			S32 targetHeight;
			
			gViewerWindow->getTargetWindow(targetFullscreen, targetWidth, targetHeight);
			
			if (targetFullscreen)
			{
				fullscreen_mode = 0; // default to 800x600
				for (S32 i = 0; i < num_resolutions; i++)
				{
					if (targetWidth == supported_resolutions[i].mWidth
						&&  targetHeight == supported_resolutions[i].mHeight)
					{
						fullscreen_mode = i;
					}
				}
				ctrl_full_screen->setCurrentByIndex(fullscreen_mode);
			}
			else
			{
				// set to windowed mode
				//fullscreen_mode = mCtrlFullScreen->getItemCount() - 1;
				ctrl_full_screen->setCurrentByIndex(0);
			}
		}
		
		LLFloaterPreference::initWindowSizeControls(this);
		
		if (gSavedSettings.getBOOL("FullScreenAutoDetectAspectRatio"))
		{
			LLFloaterPreference::sAspectRatio = gViewerWindow->getDisplayAspectRatio();
		}
		else
		{
			LLFloaterPreference::sAspectRatio = gSavedSettings.getF32("FullScreenAspectRatio");
		}

		getChild<LLComboBox>("aspect_ratio")->setTextEntryCallback(boost::bind(&LLPanelPreference::setControlFalse, this, LLSD("FullScreenAutoDetectAspectRatio") ));	
		

		S32 numerator = 0;
		S32 denominator = 0;
		fractionFromDecimal(LLFloaterPreference::sAspectRatio, numerator, denominator);		
		
		LLUIString aspect_ratio_text = getString("aspect_ratio_text");
		if (numerator != 0)
		{
			aspect_ratio_text.setArg("[NUM]", llformat("%d",  numerator));
			aspect_ratio_text.setArg("[DEN]", llformat("%d",  denominator));
		}	
		else
		{
			aspect_ratio_text = llformat("%.3f", LLFloaterPreference::sAspectRatio);
		}
		
		LLComboBox* ctrl_aspect_ratio = getChild<LLComboBox>( "aspect_ratio");
		//mCtrlAspectRatio->setCommitCallback(onSelectAspectRatio, this);
		// add default aspect ratios
		ctrl_aspect_ratio->add(aspect_ratio_text, &LLFloaterPreference::sAspectRatio, ADD_TOP);
		ctrl_aspect_ratio->setCurrentByIndex(0);
		
		refresh();
	}
	

	if(hasChild("user") && hasChild("agent") && hasChild("im") 
	&& hasChild("system") && hasChild("script_error") && hasChild("objects") 
	&& hasChild("owner") && hasChild("background") && hasChild("links"))
	{
		LLColorSwatchCtrl* color_swatch = getChild<LLColorSwatchCtrl>("user");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "UserChatColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("UserChatColor"));

		color_swatch = getChild<LLColorSwatchCtrl>("agent");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "AgentChatColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("AgentChatColor"));

		color_swatch = getChild<LLColorSwatchCtrl>("im");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "IMChatColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("IMChatColor"));

		color_swatch = getChild<LLColorSwatchCtrl>("system");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "SystemChatColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("SystemChatColor"));

		color_swatch = getChild<LLColorSwatchCtrl>("script_error");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "ScriptErrorColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("ScriptErrorColor"));

		color_swatch = getChild<LLColorSwatchCtrl>("objects");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "ObjectChatColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("ObjectChatColor"));

		color_swatch = getChild<LLColorSwatchCtrl>("owner");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "llOwnerSayChatColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("llOwnerSayChatColor"));

		color_swatch = getChild<LLColorSwatchCtrl>("background");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "BackgroundChatColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("BackgroundChatColor"));

		color_swatch = getChild<LLColorSwatchCtrl>("links");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "HTMLLinkColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("HTMLLinkColor"));
	}

	if(hasChild("effect_color_swatch"))
	{
		LLColorSwatchCtrl* color_swatch = getChild<LLColorSwatchCtrl>("effect_color_swatch");
		color_swatch->setCommitCallback(boost::bind(&applyUIColor, "EffectColor", _1, _2));
		color_swatch->setOriginal(LLUIColorTable::instance().getColor("EffectColor"));
	}

void LLPanelPreference::apply()
{
	// Save the value of all controls in the hierarchy
	mSavedValues.clear();
	std::list<LLView*> view_stack;
	view_stack.push_back(this);
	while(!view_stack.empty())
	{
		// Process view on top of the stack
		LLView* curview = view_stack.front();
		view_stack.pop_front();

		LLColorSwatchCtrl* color_swatch = dynamic_cast<LLColorSwatchCtrl *>(curview);
		if (color_swatch)
		{
			mSavedColors[color_swatch->getName()] = color_swatch->get();
		}
		else
			LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
			if (ctrl)
				LLControlVariable* control = ctrl->getControlVariable();
				if (control)
				{
					mSavedValues[control] = control->getValue();
				}
		// Push children onto the end of the work stack
		for (child_list_t::const_iterator iter = curview->getChildList()->begin();
			 iter != curview->getChildList()->end(); ++iter)
		{
			view_stack.push_back(*iter);
		}
	}
	
}
James Cook's avatar
James Cook committed

void LLPanelPreference::cancel()
James Cook's avatar
James Cook committed
{
	for (control_values_map_t::iterator iter =  mSavedValues.begin();
		 iter !=  mSavedValues.end(); ++iter)
James Cook's avatar
James Cook committed
	{
		LLControlVariable* control = iter->first;
		LLSD ctrl_value = iter->second;
		control->set(ctrl_value);
James Cook's avatar
James Cook committed
	}

	for (string_color_map_t::iterator iter = mSavedColors.begin();
		 iter != mSavedColors.end(); ++iter)
	{
		LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>(iter->first);
		if(color_swatch)
		{
			color_swatch->set(iter->second);
			color_swatch->onCommit();
		}
	}
James Cook's avatar
James Cook committed
}
void LLPanelPreference::setControlFalse(const LLSD& user_data)
	std::string control_name = user_data.asString();
	LLControlVariable* control = findControl(control_name);
	
	if (control)
		control->set(LLSD(FALSE));