llfloaterpreference.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /**
  2. * @file llfloaterpreference.cpp
  3. * @brief Global preferences with and without persistence.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. /*
  33. * App-wide preferences. Note that these are not per-user,
  34. * because we need to load many preferences before we have
  35. * a login name.
  36. */
  37. #include "llviewerprecompiledheaders.h"
  38. #include "llfloaterpreference.h"
  39. #include "llbutton.h"
  40. #include "lldir.h"
  41. #include "llresizehandle.h" // For RESIZE_HANDLE_WIDTH
  42. #include "llscrollbar.h" // For SCROLLBAR_SIZE
  43. #include "lluictrlfactory.h"
  44. #include "llmessage.h"
  45. #include "llagent.h"
  46. #include "llappviewer.h"
  47. #include "llcommandhandler.h"
  48. #include "llfloaterabout.h"
  49. #include "llgridmanager.h"
  50. #include "hbpanelgrids.h"
  51. #include "llpanellogin.h"
  52. #include "llprefsskins.h"
  53. #include "llprefschat.h"
  54. #include "hbprefscool.h"
  55. #include "llprefsgeneral.h"
  56. #include "llprefsgraphics.h"
  57. #include "llprefsim.h"
  58. #include "llprefsinput.h"
  59. #include "llprefsmedia.h"
  60. #include "llprefsnetwork.h"
  61. #include "llprefsnotifications.h"
  62. #include "llprefsvoice.h"
  63. #include "llviewercontrol.h"
  64. constexpr S32 PREF_BORDER = 4;
  65. constexpr S32 PREF_PAD = 5;
  66. constexpr S32 PREF_BUTTON_WIDTH = 70;
  67. constexpr S32 PREF_CATEGORY_WIDTH = 150;
  68. constexpr S32 PREF_FLOATER_MIN_HEIGHT = 2 * SCROLLBAR_SIZE +
  69. 2 * LLPANEL_BORDER_WIDTH + 96;
  70. class LLPreferencesHandler final : public LLCommandHandler
  71. {
  72. public:
  73. // Requires a trusted browser
  74. LLPreferencesHandler()
  75. : LLCommandHandler("preferences", UNTRUSTED_BLOCK)
  76. {
  77. }
  78. bool handle(const LLSD&, const LLSD&, LLMediaCtrl*) override
  79. {
  80. LLFloaterPreference::showInstance();
  81. return true;
  82. }
  83. };
  84. LLPreferencesHandler gPreferencesHandler;
  85. // Must be done at run time, not compile time. JC
  86. S32 pref_min_width()
  87. {
  88. return 2 * PREF_BORDER + 2 * PREF_BUTTON_WIDTH + 2 * PREF_PAD +
  89. RESIZE_HANDLE_WIDTH + PREF_CATEGORY_WIDTH;
  90. }
  91. S32 pref_min_height()
  92. {
  93. return 2 * PREF_BORDER + 3 * (gBtnHeight + PREF_PAD) + PREF_FLOATER_MIN_HEIGHT;
  94. }
  95. LLPreferenceCore::LLPreferenceCore(LLTabContainer* tab_container,
  96. LLButton* default_btn)
  97. : mTabContainer(tab_container)
  98. {
  99. mPrefsGeneral = new LLPrefsGeneral();
  100. mTabContainer->addTabPanel(mPrefsGeneral->getPanel(),
  101. mPrefsGeneral->getPanel()->getLabel(),
  102. false, onTabChanged, mTabContainer);
  103. mPrefsGeneral->getPanel()->setDefaultBtn(default_btn);
  104. mPrefsInput = new LLPrefsInput();
  105. mTabContainer->addTabPanel(mPrefsInput->getPanel(),
  106. mPrefsInput->getPanel()->getLabel(),
  107. false, onTabChanged, mTabContainer);
  108. mPrefsInput->getPanel()->setDefaultBtn(default_btn);
  109. mPrefsNetwork = new LLPrefsNetwork();
  110. mTabContainer->addTabPanel(mPrefsNetwork, mPrefsNetwork->getLabel(),
  111. false, onTabChanged, mTabContainer);
  112. mPrefsNetwork->setDefaultBtn(default_btn);
  113. mPrefsGraphics = new LLPrefsGraphics();
  114. mTabContainer->addTabPanel(mPrefsGraphics->getPanel(),
  115. mPrefsGraphics->getPanel()->getLabel(),
  116. false, onTabChanged, mTabContainer);
  117. mPrefsGraphics->getPanel()->setDefaultBtn(default_btn);
  118. mPrefsMedia = new LLPrefsMedia();
  119. mTabContainer->addTabPanel(mPrefsMedia->getPanel(),
  120. mPrefsMedia->getPanel()->getLabel(),
  121. false, onTabChanged, mTabContainer);
  122. mPrefsMedia->getPanel()->setDefaultBtn(default_btn);
  123. mPrefsChat = new LLPrefsChat();
  124. mTabContainer->addTabPanel(mPrefsChat->getPanel(),
  125. mPrefsChat->getPanel()->getLabel(),
  126. false, onTabChanged, mTabContainer);
  127. mPrefsChat->getPanel()->setDefaultBtn(default_btn);
  128. mPrefsIM = new LLPrefsIM();
  129. mTabContainer->addTabPanel(mPrefsIM->getPanel(),
  130. mPrefsIM->getPanel()->getLabel(),
  131. false, onTabChanged, mTabContainer);
  132. mPrefsIM->getPanel()->setDefaultBtn(default_btn);
  133. mPrefsVoice = new LLPrefsVoice();
  134. mTabContainer->addTabPanel(mPrefsVoice, mPrefsVoice->getLabel(),
  135. false, onTabChanged, mTabContainer);
  136. mPrefsVoice->setDefaultBtn(default_btn);
  137. mPrefsNotifications = new LLPrefsNotifications();
  138. mTabContainer->addTabPanel(mPrefsNotifications->getPanel(),
  139. mPrefsNotifications->getPanel()->getLabel(),
  140. false, onTabChanged, mTabContainer);
  141. mPrefsNotifications->getPanel()->setDefaultBtn(default_btn);
  142. mPrefsSkins = new LLPrefSkins();
  143. mTabContainer->addTabPanel(mPrefsSkins, mPrefsSkins->getLabel(),
  144. false, onTabChanged, mTabContainer);
  145. mPrefsSkins->setDefaultBtn(default_btn);
  146. mPrefsCool = new HBPrefsCool();
  147. mTabContainer->addTabPanel(mPrefsCool->getPanel(),
  148. mPrefsCool->getPanel()->getLabel(),
  149. false, onTabChanged, mTabContainer);
  150. mPrefsCool->getPanel()->setDefaultBtn(default_btn);
  151. mPrefsGrids = new HBPanelGrids();
  152. mTabContainer->addTabPanel(mPrefsGrids->getPanel(),
  153. mPrefsGrids->getPanel()->getLabel(),
  154. false, onTabChanged, mTabContainer);
  155. mPrefsGrids->getPanel()->setDefaultBtn(default_btn);
  156. if (!mTabContainer->selectTab(gSavedSettings.getS32("LastPrefTab")))
  157. {
  158. mTabContainer->selectFirstTab();
  159. }
  160. }
  161. LLPreferenceCore::~LLPreferenceCore()
  162. {
  163. if (mPrefsGeneral)
  164. {
  165. delete mPrefsGeneral;
  166. mPrefsGeneral = NULL;
  167. }
  168. if (mPrefsInput)
  169. {
  170. delete mPrefsInput;
  171. mPrefsInput = NULL;
  172. }
  173. if (mPrefsNetwork)
  174. {
  175. delete mPrefsNetwork;
  176. mPrefsNetwork = NULL;
  177. }
  178. if (mPrefsGraphics)
  179. {
  180. delete mPrefsGraphics;
  181. mPrefsGraphics = NULL;
  182. }
  183. if (mPrefsMedia)
  184. {
  185. delete mPrefsMedia;
  186. mPrefsMedia = NULL;
  187. }
  188. if (mPrefsChat)
  189. {
  190. delete mPrefsChat;
  191. mPrefsChat = NULL;
  192. }
  193. if (mPrefsIM)
  194. {
  195. delete mPrefsIM;
  196. mPrefsIM = NULL;
  197. }
  198. if (mPrefsNotifications)
  199. {
  200. delete mPrefsNotifications;
  201. mPrefsNotifications = NULL;
  202. }
  203. if (mPrefsSkins)
  204. {
  205. delete mPrefsSkins;
  206. mPrefsSkins = NULL;
  207. }
  208. if (mPrefsCool)
  209. {
  210. delete mPrefsCool;
  211. mPrefsCool = NULL;
  212. }
  213. if (mPrefsGrids)
  214. {
  215. delete mPrefsGrids;
  216. mPrefsGrids = NULL;
  217. }
  218. }
  219. void LLPreferenceCore::apply()
  220. {
  221. mPrefsGeneral->apply();
  222. mPrefsInput->apply();
  223. mPrefsNetwork->apply();
  224. mPrefsGraphics->apply();
  225. mPrefsMedia->apply();
  226. mPrefsChat->apply();
  227. mPrefsVoice->apply();
  228. mPrefsIM->apply();
  229. mPrefsNotifications->apply();
  230. mPrefsSkins->apply();
  231. mPrefsCool->apply();
  232. mPrefsGrids->apply();
  233. }
  234. void LLPreferenceCore::cancel()
  235. {
  236. mPrefsGeneral->cancel();
  237. mPrefsInput->cancel();
  238. mPrefsNetwork->cancel();
  239. mPrefsGraphics->cancel();
  240. mPrefsMedia->cancel();
  241. mPrefsChat->cancel();
  242. mPrefsVoice->cancel();
  243. mPrefsIM->cancel();
  244. mPrefsNotifications->cancel();
  245. mPrefsSkins->cancel();
  246. mPrefsCool->cancel();
  247. mPrefsGrids->cancel();
  248. }
  249. //static
  250. void LLPreferenceCore::onTabChanged(void* user_data, bool from_click)
  251. {
  252. LLTabContainer* self = (LLTabContainer*)user_data;
  253. if (self)
  254. {
  255. gSavedSettings.setS32("LastPrefTab", self->getCurrentPanelIndex());
  256. }
  257. }
  258. void LLPreferenceCore::setPersonalInfo(const std::string& visibility,
  259. bool im_via_email,
  260. const std::string& email,
  261. S32 verified)
  262. {
  263. mPrefsIM->setPersonalInfo(visibility, im_via_email, email, verified);
  264. }
  265. //////////////////////////////////////////////
  266. // LLFloaterPreference
  267. LLFloaterPreference::LLFloaterPreference(const LLSD&)
  268. {
  269. LLUICtrlFactory::getInstance()->buildFloater(this,
  270. "floater_preferences.xml");
  271. }
  272. //virtual
  273. bool LLFloaterPreference::postBuild()
  274. {
  275. mAboutBtn = getChild<LLButton>("About...");
  276. mAboutBtn->setClickedCallback(onClickAbout, this);
  277. mApplyBtn = getChild<LLButton>("Apply");
  278. mApplyBtn->setClickedCallback(onBtnApply, this);
  279. mCancelBtn = getChild<LLButton>("Cancel");
  280. mCancelBtn->setClickedCallback(onBtnCancel, this);
  281. mOKBtn = getChild<LLButton>("OK");
  282. mOKBtn->setClickedCallback(onBtnOK, this);
  283. mPreferenceCore = new LLPreferenceCore(getChild<LLTabContainer>("pref core"),
  284. getChild<LLButton>("OK"));
  285. center();
  286. gAgent.sendAgentUserInfoRequest();
  287. LLPanelLogin::setAlwaysRefresh(true);
  288. return true;
  289. }
  290. //virtual
  291. LLFloaterPreference::~LLFloaterPreference()
  292. {
  293. if (mPreferenceCore)
  294. {
  295. delete mPreferenceCore;
  296. mPreferenceCore = NULL;
  297. }
  298. }
  299. void LLFloaterPreference::apply()
  300. {
  301. if (mPreferenceCore)
  302. {
  303. mPreferenceCore->apply();
  304. }
  305. }
  306. void LLFloaterPreference::cancel()
  307. {
  308. if (mPreferenceCore)
  309. {
  310. mPreferenceCore->cancel();
  311. }
  312. }
  313. //static
  314. void LLFloaterPreference::openInTab(S32 tab)
  315. {
  316. LLFloaterPreference* self = showInstance();
  317. if (!self) return; // Could be out of memory...
  318. if (tab >= 0 && tab < NUMBER_OF_TABS)
  319. {
  320. gSavedSettings.setS32("LastPrefTab", tab);
  321. if (self->mPreferenceCore)
  322. {
  323. self->mPreferenceCore->getTabContainer()->selectTab(tab);
  324. }
  325. }
  326. else
  327. {
  328. llwarns << "Invalid tab number" << llendl;
  329. }
  330. }
  331. //static
  332. void LLFloaterPreference::onClickAbout(void*)
  333. {
  334. LLFloaterAbout::showInstance();
  335. }
  336. //static
  337. void LLFloaterPreference::onBtnOK(void* userdata)
  338. {
  339. LLFloaterPreference* self =(LLFloaterPreference*)userdata;
  340. if (!self) return;
  341. // Commit any outstanding text entry
  342. if (self->hasFocus())
  343. {
  344. LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocusUICtrl();
  345. if (cur_focus && cur_focus->acceptsTextInput())
  346. {
  347. cur_focus->onCommit();
  348. }
  349. }
  350. if (self->canClose())
  351. {
  352. self->apply();
  353. self->close();
  354. gAppViewerp->saveGlobalSettings();
  355. }
  356. else
  357. {
  358. // *TODO ? Show beep, pop up dialog, etc.
  359. llwarns << "Cannot close preferences !" << llendl;
  360. }
  361. LLPanelLogin::refreshLocation();
  362. }
  363. //static
  364. void LLFloaterPreference::onBtnApply(void* userdata)
  365. {
  366. LLFloaterPreference* self =(LLFloaterPreference*)userdata;
  367. if (!self) return;
  368. if (self->hasFocus())
  369. {
  370. LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocusUICtrl();
  371. if (cur_focus && cur_focus->acceptsTextInput())
  372. {
  373. cur_focus->onCommit();
  374. }
  375. }
  376. self->apply();
  377. LLPanelLogin::refreshLocation();
  378. }
  379. void LLFloaterPreference::onClose(bool app_quitting)
  380. {
  381. LLPanelLogin::setAlwaysRefresh(false);
  382. cancel(); // Will be a no-op if OK or apply was performed just prior.
  383. LLFloater::onClose(app_quitting);
  384. }
  385. //static
  386. void LLFloaterPreference::onBtnCancel(void* userdata)
  387. {
  388. LLFloaterPreference* self =(LLFloaterPreference*)userdata;
  389. if (!self) return;
  390. if (self->hasFocus())
  391. {
  392. LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocusUICtrl();
  393. if (cur_focus && cur_focus->acceptsTextInput())
  394. {
  395. cur_focus->onCommit();
  396. }
  397. }
  398. self->close(); // side effect will also cancel any unsaved changes.
  399. }
  400. //static
  401. void LLFloaterPreference::updateUserInfo(const std::string& visibility,
  402. bool im_via_email,
  403. const std::string& email,
  404. S32 verified)
  405. {
  406. LLFloaterPreference* self = findInstance();
  407. if (self && self->mPreferenceCore)
  408. {
  409. self->mPreferenceCore->setPersonalInfo(visibility, im_via_email,
  410. email, verified);
  411. }
  412. }