llprefsgeneral.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /**
  2. * @file llprefsgeneral.cpp
  3. * @brief General preferences panel in preferences floater
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Adapted by Henri Beauchamp from llpanelgeneral.cpp
  8. * Copyright (c) 2001-2009 Linden Research, Inc. (c) 2011 Henri Beauchamp
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "llprefsgeneral.h"
  35. #include "llavatarnamecache.h"
  36. #include "llcheckboxctrl.h"
  37. #include "llcombobox.h"
  38. #include "llradiogroup.h"
  39. #include "lltextbox.h"
  40. #include "lluictrlfactory.h"
  41. #include "llagent.h"
  42. #include "llcolorswatch.h"
  43. #include "llstartup.h"
  44. #include "llviewercontrol.h"
  45. #include "llviewerregion.h"
  46. class LLPrefsGeneralImpl final : public LLPanel
  47. {
  48. public:
  49. LLPrefsGeneralImpl();
  50. ~LLPrefsGeneralImpl() override {}
  51. void refresh() override;
  52. void apply();
  53. void cancel();
  54. private:
  55. void refreshValues();
  56. private:
  57. LLComboBox* mFadeOutNamesCombo;
  58. LLComboBox* mMaturityCombo;
  59. LLComboBox* mLanguageCombo;
  60. LLTextBox* mMaturityText;
  61. LLTextBox* mDisplayNameText1;
  62. LLTextBox* mDisplayNameText2;
  63. LLTextBox* mAlwaysLegacyNamesText;
  64. LLTextBox* mNoDisplayNameText;
  65. LLRadioGroup* mLoginLocationRadio;
  66. LLRadioGroup* mDisplayNameRadio;
  67. LLCheckBoxCtrl* mFriendsLegacyNamesCheck;
  68. LLCheckBoxCtrl* mSpeakersLegacyNamesCheck;
  69. LLCheckBoxCtrl* mOmitResidentCheck;
  70. F32 mChatBubbleOpacity;
  71. F32 mUIScaleFactor;
  72. F32 mHUDScaleFactor;
  73. S32 mRenderName;
  74. U32 mAFKTimeout;
  75. U32 mAwayAction;
  76. U32 mPreferredMaturity;
  77. U32 mDisplayNamesUsage;
  78. LLColor4 mEffectColor;
  79. bool mHasDisplayNames;
  80. bool mCanChooseMaturity;
  81. bool mLoginLastLocation;
  82. bool mRenderHideGroupTitleAll;
  83. bool mRenderHideGroupTitle;
  84. bool mLanguageIsPublic;
  85. bool mRenderNameHideSelf;
  86. bool mSmallAvatarNames;
  87. bool mUIAutoScale;
  88. bool mLegacyNamesForFriends;
  89. bool mLegacyNamesForSpeakers;
  90. bool mOmitResidentAsLastName;
  91. std::string mLanguage;
  92. };
  93. LLPrefsGeneralImpl::LLPrefsGeneralImpl()
  94. : LLPanel(std::string("General Preferences"))
  95. {
  96. LLUICtrlFactory::getInstance()->buildPanel(this,
  97. "panel_preferences_general.xml");
  98. mLoginLocationRadio = getChild<LLRadioGroup>("default_start_location");
  99. mDisplayNameText1 = getChild<LLTextBox>("display_names_text_box1");
  100. mDisplayNameText2 = getChild<LLTextBox>("display_names_text_box2");
  101. mAlwaysLegacyNamesText = getChild<LLTextBox>("always_legacy_names_text");
  102. mNoDisplayNameText = getChild<LLTextBox>("no_display_names_text_box");
  103. mDisplayNameRadio = getChild<LLRadioGroup>("display_names_usage");
  104. mFriendsLegacyNamesCheck = getChild<LLCheckBoxCtrl>("legacy_names_for_friends_check");
  105. mSpeakersLegacyNamesCheck = getChild<LLCheckBoxCtrl>("legacy_names_for_speakers_check");
  106. mOmitResidentCheck = getChild<LLCheckBoxCtrl>("omit_resident_last_name_check");
  107. mFadeOutNamesCombo = getChild<LLComboBox>("fade_out_combobox");
  108. mMaturityCombo = getChild<LLComboBox>("maturity_desired_combobox");
  109. mMaturityText = getChild<LLTextBox>("maturity_desired_textbox");
  110. mLanguageCombo = getChild<LLComboBox>("language_combobox");
  111. bool not_logged_in = !LLStartUp::isLoggedIn();
  112. mHasDisplayNames = not_logged_in || LLAvatarNameCache::hasNameLookupURL();
  113. if (not_logged_in)
  114. {
  115. mCanChooseMaturity = true;
  116. }
  117. else
  118. {
  119. mCanChooseMaturity = gAgent.isMature() || gAgent.isGodlike();
  120. if (mCanChooseMaturity && !gAgent.isAdult() && !gAgent.isGodlike())
  121. {
  122. // If they're not adult or a god, they shouldn't see the adult
  123. // selection, so delete it
  124. mMaturityCombo->remove(0);
  125. }
  126. }
  127. refresh();
  128. }
  129. void LLPrefsGeneralImpl::refreshValues()
  130. {
  131. mLoginLastLocation = gSavedSettings.getBool("LoginLastLocation");
  132. mRenderHideGroupTitleAll = gSavedSettings.getBool("RenderHideGroupTitleAll");
  133. mRenderHideGroupTitle = gSavedSettings.getBool("RenderHideGroupTitle");
  134. mLanguageIsPublic = gSavedSettings.getBool("LanguageIsPublic");
  135. mRenderNameHideSelf = gSavedSettings.getBool("RenderNameHideSelf");
  136. mSmallAvatarNames = gSavedSettings.getBool("SmallAvatarNames");
  137. mUIAutoScale = gSavedSettings.getBool("UIAutoScale");
  138. mLegacyNamesForFriends = gSavedSettings.getBool("LegacyNamesForFriends");
  139. mLegacyNamesForSpeakers = gSavedSettings.getBool("LegacyNamesForSpeakers");
  140. mOmitResidentAsLastName = gSavedSettings.getBool("OmitResidentAsLastName");
  141. mChatBubbleOpacity = gSavedSettings.getF32("ChatBubbleOpacity");
  142. mRenderName = gSavedSettings.getS32("RenderName");
  143. mAFKTimeout = gSavedSettings.getU32("AFKTimeout");
  144. if (mAFKTimeout > 0 && mAFKTimeout < 30)
  145. {
  146. mAFKTimeout = 30;
  147. gSavedSettings.setU32("AFKTimeout", mAFKTimeout);
  148. }
  149. mAwayAction = gSavedSettings.getU32("AwayAction");
  150. if (mAwayAction > 2)
  151. {
  152. mAwayAction = 2;
  153. gSavedSettings.setU32("AwayAction", 2);
  154. }
  155. mUIScaleFactor = gSavedSettings.getF32("UIScaleFactor");
  156. mHUDScaleFactor = gSavedSettings.getF32("HUDScaleFactor");
  157. mPreferredMaturity = gSavedSettings.getU32("PreferredMaturity");
  158. mDisplayNamesUsage = gSavedSettings.getU32("DisplayNamesUsage");
  159. mEffectColor = gSavedSettings.getColor4("EffectColor");
  160. mLanguage = gSavedSettings.getString("Language");
  161. }
  162. void LLPrefsGeneralImpl::refresh()
  163. {
  164. refreshValues();
  165. mLoginLocationRadio->setValue(mLoginLastLocation ? "LastLoc" : "Home");
  166. mFadeOutNamesCombo->setCurrentByIndex(mRenderName);
  167. mMaturityCombo->setValue((S32)gSavedSettings.getU32("PreferredMaturity"));
  168. mMaturityCombo->setVisible(mCanChooseMaturity);
  169. mMaturityText->setVisible(!mCanChooseMaturity);
  170. std::string selected_item_label = mMaturityCombo->getSelectedItemLabel();
  171. mMaturityText->setValue(selected_item_label);
  172. mDisplayNameText1->setVisible(mHasDisplayNames);
  173. mDisplayNameText2->setVisible(mHasDisplayNames);
  174. mAlwaysLegacyNamesText->setVisible(mHasDisplayNames);
  175. mNoDisplayNameText->setVisible(!mHasDisplayNames);
  176. mDisplayNameRadio->setEnabled(mHasDisplayNames);
  177. mFriendsLegacyNamesCheck->setEnabled(mHasDisplayNames);
  178. mSpeakersLegacyNamesCheck->setEnabled(mHasDisplayNames);
  179. mOmitResidentCheck->setEnabled(mHasDisplayNames);
  180. mLanguageCombo->setValue(mLanguage);
  181. }
  182. void LLPrefsGeneralImpl::apply()
  183. {
  184. gSavedSettings.setBool("LoginLastLocation",
  185. mLoginLocationRadio->getValue().asString() == "LastLoc");
  186. gSavedSettings.setS32("RenderName", mFadeOutNamesCombo->getCurrentIndex());
  187. std::string language = mLanguageCombo->getValue();
  188. if (language != mLanguage)
  189. {
  190. gSavedSettings.setString("Language", language);
  191. gNotifications.add("InEffectAfterRestart");
  192. }
  193. if (mCanChooseMaturity)
  194. {
  195. U32 preferred_maturity = mMaturityCombo->getValue().asInteger();
  196. if (preferred_maturity != gSavedSettings.getU32("PreferredMaturity"))
  197. {
  198. gSavedSettings.setU32("PreferredMaturity", preferred_maturity);
  199. }
  200. }
  201. refreshValues();
  202. }
  203. void LLPrefsGeneralImpl::cancel()
  204. {
  205. gSavedSettings.setBool("LoginLastLocation", mLoginLastLocation);
  206. gSavedSettings.setBool("RenderHideGroupTitleAll", mRenderHideGroupTitleAll);
  207. gSavedSettings.setBool("RenderHideGroupTitle", mRenderHideGroupTitle);
  208. gSavedSettings.setBool("LanguageIsPublic", mLanguageIsPublic);
  209. gSavedSettings.setBool("RenderNameHideSelf", mRenderNameHideSelf);
  210. gSavedSettings.setBool("SmallAvatarNames", mSmallAvatarNames);
  211. gSavedSettings.setBool("UIAutoScale", mUIAutoScale);
  212. gSavedSettings.setBool("LegacyNamesForFriends", mLegacyNamesForFriends);
  213. gSavedSettings.setBool("LegacyNamesForSpeakers", mLegacyNamesForSpeakers);
  214. gSavedSettings.setBool("OmitResidentAsLastName", mOmitResidentAsLastName);
  215. gSavedSettings.setF32("ChatBubbleOpacity", mChatBubbleOpacity);
  216. gSavedSettings.setS32("RenderName", mRenderName);
  217. gSavedSettings.setU32("AFKTimeout", mAFKTimeout);
  218. gSavedSettings.setU32("AwayAction", mAwayAction);
  219. gSavedSettings.setF32("UIScaleFactor", mUIScaleFactor);
  220. gSavedSettings.setF32("HUDScaleFactor", mHUDScaleFactor);
  221. if (mPreferredMaturity != gSavedSettings.getU32("PreferredMaturity"))
  222. {
  223. gSavedSettings.setU32("PreferredMaturity", mPreferredMaturity);
  224. }
  225. gSavedSettings.setU32("DisplayNamesUsage", mDisplayNamesUsage);
  226. gSavedSettings.setColor4("EffectColor", mEffectColor);
  227. gSavedSettings.setString("Language", mLanguage);
  228. }
  229. //---------------------------------------------------------------------------
  230. LLPrefsGeneral::LLPrefsGeneral()
  231. : impl(*new LLPrefsGeneralImpl())
  232. {
  233. }
  234. LLPrefsGeneral::~LLPrefsGeneral()
  235. {
  236. delete &impl;
  237. }
  238. void LLPrefsGeneral::apply()
  239. {
  240. impl.apply();
  241. }
  242. void LLPrefsGeneral::cancel()
  243. {
  244. impl.cancel();
  245. }
  246. LLPanel* LLPrefsGeneral::getPanel()
  247. {
  248. return &impl;
  249. }