Skip to content
Snippets Groups Projects
llfloaterpreference.cpp 49.7 KiB
Newer Older
		gViewerWindow->mWindow->setNativeAspectRatio(0.f);
		fractionFromDecimal(gViewerWindow->mWindow->getNativeAspectRatio(), numerator, denominator);
		
		std::string aspect;
		if (numerator != 0)
		{
			aspect = llformat("%d:%d", numerator, denominator);
		}
		else
		{
			aspect = llformat("%.3f", gViewerWindow->mWindow->getNativeAspectRatio());
		}
		
		getChild<LLComboBox>( "aspect_ratio")->setLabel(aspect);
		
		ratio = gViewerWindow->mWindow->getNativeAspectRatio();
		gSavedSettings.setF32("FullScreenAspectRatio", ratio);
	}
}

void LLFloaterPreference::refresh()
{
	LLPanel::refresh();

	// sliders and their text boxes
	//	mPostProcess = gSavedSettings.getS32("RenderGlowResolutionPow");
	// slider text boxes
	updateSliderText(getChild<LLSliderCtrl>("ObjectMeshDetail",		true), getChild<LLTextBox>("ObjectMeshDetailText",		true));
	updateSliderText(getChild<LLSliderCtrl>("FlexibleMeshDetail",	true), getChild<LLTextBox>("FlexibleMeshDetailText",	true));
	updateSliderText(getChild<LLSliderCtrl>("TreeMeshDetail",		true), getChild<LLTextBox>("TreeMeshDetailText",		true));
	updateSliderText(getChild<LLSliderCtrl>("AvatarMeshDetail",		true), getChild<LLTextBox>("AvatarMeshDetailText",		true));
	updateSliderText(getChild<LLSliderCtrl>("TerrainMeshDetail",	true), getChild<LLTextBox>("TerrainMeshDetailText",		true));
	updateSliderText(getChild<LLSliderCtrl>("RenderPostProcess",	true), getChild<LLTextBox>("PostProcessText",			true));
	updateSliderText(getChild<LLSliderCtrl>("SkyMeshDetail",		true), getChild<LLTextBox>("SkyMeshDetailText",			true));
	
	refreshEnabledState();
}

void LLFloaterPreference::onCommitWindowedMode()
{
	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 = LLFloaterReg::showTypedInstance<LLVoiceSetKeyDialog>("voice_set_key", LLSD(), TRUE);
	if (dialog)
	{
		dialog->setParent(this);
	}
void LLFloaterPreference::setKey(KEY key)
{
	childSetValue("modifier_combo", LLKeyboard::stringFromKey(key));
	// update the control right away since we no longer wait for apply
	getChild<LLUICtrl>("modifier_combo")->onCommit();
James Cook's avatar
James Cook committed

void LLFloaterPreference::onClickSetMiddleMouse()
James Cook's avatar
James Cook committed
{
	childSetValue("modifier_combo", "MiddleMouse");
	// update the control right away since we no longer wait for apply
	getChild<LLUICtrl>("modifier_combo")->onCommit();
void LLFloaterPreference::onClickSkipDialogs()
{
	LLNotificationsUtil::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
{
	LLNotificationsUtil::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);
	}
	
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);
	}
	
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::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("plain_text_chat_history");
	childSetValue("plain_text_chat_history", gSavedSettings.getBOOL("PlainTextChatHistory"));
	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", gSavedSettings.getString("BusyModeResponse2"));
	childEnable("log_nearby_chat");
	childEnable("log_instant_messages");
	childEnable("show_timestamps_check_im");
	childEnable("log_path_string");
	childEnable("log_path_button");
	
	std::string display_email(email);
	childSetText("email_address",display_email);
void LLFloaterPreference::onUpdateSliderText(LLUICtrl* ctrl, const LLSD& name)
{
	std::string ctrl_name = name.asString();
	
	if((ctrl_name =="" )|| !hasChild(ctrl_name, true))
		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->getWindowHeightRaw();
	const U32 width = gViewerWindow->getWindowWidthRaw();
	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);
}


void LLFloaterPreference::applyUIColor(LLUICtrl* ctrl, const LLSD& param)
{
	LLUIColorTable::instance().setColor(param.asString(), LLColor4(ctrl->getValue()));
}

void LLFloaterPreference::getUIColor(LLUICtrl* ctrl, const LLSD& param)
{
	LLColorSwatchCtrl* color_swatch = (LLColorSwatchCtrl*) ctrl;
	color_swatch->setOriginal(LLUIColorTable::instance().getColor(param.asString()));
}

//----------------------------------------------------------------------------
static LLRegisterPanelClassWrapper<LLPanelPreference> t_places("panel_preference");
LLPanelPreference::LLPanelPreference()
: LLPanel()
	mCommitCallbackRegistrar.add("Pref.setControlFalse",	boost::bind(&LLPanelPreference::setControlFalse,this, _2));
//virtual
BOOL LLPanelPreference::postBuild()
{

	////////////////////// 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
	}
	if(hasChild("online_visibility") && hasChild("send_im_to_email"))
	{
		childSetText("email_address",getString("log_in_to_change") );
//		childSetText("busy_response", getString("log_in_to_change"));		
	if(hasChild("aspect_ratio"))
	{
		//============================================================================
		// 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();
	}
	
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));