llpanelgroup.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /**
  2. * @file llpanelgroup.cpp
  3. *
  4. * $LicenseInfo:firstyear=2006&license=viewergpl$
  5. *
  6. * Copyright (c) 2006-2009, Linden Research, Inc.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #include "llviewerprecompiledheaders.h"
  32. #include "llpanelgroup.h"
  33. #include "llbutton.h"
  34. #include "llnotifications.h"
  35. #include "lltabcontainer.h"
  36. #include "lltextbox.h"
  37. #include "lluictrlfactory.h"
  38. #include "llagent.h"
  39. #include "llappviewer.h"
  40. #include "llpanelgroupexperiences.h"
  41. #include "llpanelgroupgeneral.h"
  42. #include "llpanelgrouplandmoney.h"
  43. #include "llpanelgroupnotices.h"
  44. #include "llpanelgrouproles.h"
  45. #include "llviewermessage.h" // For LLOfferInfo
  46. //static
  47. void* LLPanelGroupTab::createTab(void* data)
  48. {
  49. LLUUID* group_id = static_cast<LLUUID*>(data);
  50. return new LLPanelGroupTab("panel group tab", *group_id);
  51. }
  52. LLPanelGroupTab::~LLPanelGroupTab()
  53. {
  54. mObservers.clear();
  55. }
  56. bool LLPanelGroupTab::isVisibleByAgent()
  57. {
  58. // default to being visible
  59. return true;
  60. }
  61. //virtual
  62. bool LLPanelGroupTab::postBuild()
  63. {
  64. // Hook up the help button callback.
  65. LLButton* button = getChild<LLButton>("help_button", true, false);
  66. if (button)
  67. {
  68. button->setClickedCallback(onClickHelp);
  69. button->setCallbackUserData(this);
  70. }
  71. mHelpText = getString("help_text");
  72. return true;
  73. }
  74. void LLPanelGroupTab::addObserver(LLPanelGroupTabObserver *obs)
  75. {
  76. mObservers.insert(obs);
  77. }
  78. void LLPanelGroupTab::removeObserver(LLPanelGroupTabObserver *obs)
  79. {
  80. mObservers.erase(obs);
  81. }
  82. void LLPanelGroupTab::notifyObservers()
  83. {
  84. for (observer_list_t::iterator iter = mObservers.begin();
  85. iter != mObservers.end(); )
  86. {
  87. LLPanelGroupTabObserver* observer = *iter;
  88. observer->tabChanged();
  89. // safe way to increment since changed may delete entries! (@!##%@!@&*!)
  90. iter = mObservers.upper_bound(observer);
  91. }
  92. }
  93. //static
  94. void LLPanelGroupTab::onClickHelp(void* user_data)
  95. {
  96. LLPanelGroupTab* self = static_cast<LLPanelGroupTab*>(user_data);
  97. if (self) self->handleClickHelp();
  98. }
  99. void LLPanelGroupTab::handleClickHelp()
  100. {
  101. // Display the help text.
  102. std::string help_text(getHelpText());
  103. if (!help_text.empty() && gFloaterViewp)
  104. {
  105. LLFloater* parentp = gFloaterViewp->getParentFloater(this);
  106. if (!parentp) return;
  107. LLSD args;
  108. args["MESSAGE"] = help_text;
  109. LLNotification::Params params(parentp->contextualNotification("GenericAlert"));
  110. params.substitutions(args);
  111. gNotifications.add(params);
  112. }
  113. }
  114. LLPanelGroup::LLPanelGroup(const std::string& filename,
  115. const std::string& name,
  116. const LLUUID& group_id,
  117. const std::string& initial_tab_selected)
  118. : LLPanel(name, LLRect(), false),
  119. mFilename(filename),
  120. LLGroupMgrObserver(group_id),
  121. mCurrentTab(NULL),
  122. mRequestedTab(NULL),
  123. mTabContainer(NULL),
  124. mApplyBtn(NULL),
  125. mRefreshBtn(NULL),
  126. mIgnoreTransition(false),
  127. mForceClose(false),
  128. mInitialTab(initial_tab_selected),
  129. mAllowEdit(true),
  130. mShowingNotifyDialog(false)
  131. {
  132. // Set up the factory callbacks.
  133. mFactoryMap["general_tab"] =
  134. LLCallbackMap(LLPanelGroupGeneral::createTab, &mID);
  135. mFactoryMap["roles_tab"] =
  136. LLCallbackMap(LLPanelGroupRoles::createTab, &mID);
  137. mFactoryMap["notices_tab"] =
  138. LLCallbackMap(LLPanelGroupNotices::createTab, &mID);
  139. mFactoryMap["land_money_tab"] =
  140. LLCallbackMap(LLPanelGroupLandMoney::createTab, &mID);
  141. mFactoryMap["experiences_tab"] =
  142. LLCallbackMap(LLPanelGroupExperiences::createTab, &mID);
  143. // Roles sub tabs
  144. mFactoryMap["members_sub_tab"] =
  145. LLCallbackMap(LLPanelGroupMembersSubTab::createTab, &mID);
  146. mFactoryMap["roles_sub_tab"] =
  147. LLCallbackMap(LLPanelGroupRolesSubTab::createTab, &mID);
  148. mFactoryMap["actions_sub_tab"] =
  149. LLCallbackMap(LLPanelGroupActionsSubTab::createTab, &mID);
  150. mFactoryMap["banlist_sub_tab"] =
  151. LLCallbackMap(LLPanelGroupBanListSubTab::createTab, &mID);
  152. gGroupMgr.addObserver(this);
  153. // Pass on construction of this panel to the control factory.
  154. LLUICtrlFactory::getInstance()->buildPanel(this, filename,
  155. &getFactoryMap());
  156. }
  157. LLPanelGroup::~LLPanelGroup()
  158. {
  159. gGroupMgr.removeObserver(this);
  160. S32 tab_count = mTabContainer->getTabCount();
  161. for (S32 i = tab_count - 1; i >= 0; --i)
  162. {
  163. LLPanelGroupTab* panelp =
  164. (LLPanelGroupTab*)mTabContainer->getPanelByIndex(i);
  165. if (panelp)
  166. {
  167. panelp->removeObserver(this);
  168. }
  169. }
  170. }
  171. //virtual
  172. bool LLPanelGroup::postBuild()
  173. {
  174. mTabContainer = getChild<LLTabContainer>("group_tab_container",
  175. true, false);
  176. if (mTabContainer)
  177. {
  178. // Select the initial tab specified via constructor
  179. LLPanelGroupTab* tabp = getChild<LLPanelGroupTab>(mInitialTab.c_str(),
  180. true, false);
  181. if (!tabp)
  182. {
  183. // Our initial tab selection was invalid, just select the first tab
  184. // then or default to selecting the initial selected tab specified
  185. // in the layout file
  186. tabp = (LLPanelGroupTab*)mTabContainer->getCurrentPanel();
  187. // No tab was initially selected through constructor or the XML,
  188. // select the first tab
  189. if (!tabp)
  190. {
  191. mTabContainer->selectFirstTab();
  192. tabp = (LLPanelGroupTab*)mTabContainer->getCurrentPanel();
  193. }
  194. }
  195. else
  196. {
  197. mTabContainer->selectTabPanel(tabp);
  198. }
  199. mCurrentTab = tabp;
  200. // Add click callbacks.
  201. S32 tab_count = mTabContainer->getTabCount();
  202. for (S32 i = tab_count - 1; i >= 0; --i)
  203. {
  204. LLPanel* tab_panel = mTabContainer->getPanelByIndex(i);
  205. LLPanelGroupTab* panelp = (LLPanelGroupTab*)tab_panel;
  206. if (panelp)
  207. {
  208. // Pass on whether or not to allow edit to tabs.
  209. panelp->setAllowEdit(mAllowEdit);
  210. panelp->addObserver(this);
  211. mTabContainer->setTabChangeCallback(panelp, onClickTab);
  212. mTabContainer->setTabUserData(panelp, this);
  213. }
  214. }
  215. updateTabVisibility();
  216. // Act as though this tab was just activated.
  217. mCurrentTab->activate();
  218. }
  219. mDefaultNeedsApplyMesg = getString("default_needs_apply_text");
  220. mWantApplyMesg = getString("want_apply_text");
  221. LLButton* button = getChild<LLButton>("btn_ok", true, false);
  222. if (button)
  223. {
  224. button->setClickedCallback(onBtnOK);
  225. button->setCallbackUserData(this);
  226. button->setVisible(mAllowEdit);
  227. }
  228. button = getChild<LLButton>("btn_cancel", true, false);
  229. if (button)
  230. {
  231. button->setClickedCallback(onBtnCancel);
  232. button->setCallbackUserData(this);
  233. button->setVisible(mAllowEdit);
  234. }
  235. mApplyBtn = getChild<LLButton>("btn_apply", true, false);
  236. if (mApplyBtn)
  237. {
  238. mApplyBtn->setClickedCallback(onBtnApply);
  239. mApplyBtn->setVisible(mAllowEdit);
  240. mApplyBtn->setEnabled(false);
  241. }
  242. mRefreshBtn = getChild<LLButton>("btn_refresh", true, false);
  243. if (mRefreshBtn)
  244. {
  245. mRefreshBtn->setClickedCallback(onBtnRefresh);
  246. mRefreshBtn->setCallbackUserData(this);
  247. mRefreshBtn->setVisible(mAllowEdit);
  248. }
  249. return true;
  250. }
  251. //virtual
  252. void LLPanelGroup::draw()
  253. {
  254. if (mRefreshTimer.hasExpired())
  255. {
  256. mRefreshTimer.stop();
  257. if (mRefreshBtn)
  258. {
  259. mRefreshBtn->setEnabled(true);
  260. }
  261. }
  262. if (mCurrentTab)
  263. {
  264. std::string mesg;
  265. if (mApplyBtn)
  266. {
  267. mApplyBtn->setEnabled(mCurrentTab->needsApply(mesg));
  268. }
  269. }
  270. LLPanel::draw();
  271. }
  272. void LLPanelGroup::updateTabVisibility()
  273. {
  274. S32 tab_count = mTabContainer->getTabCount();
  275. for (S32 i = tab_count - 1; i >= 0; --i)
  276. {
  277. LLPanelGroupTab* panelp =
  278. (LLPanelGroupTab*)mTabContainer->getPanelByIndex(i);
  279. bool visible = panelp->isVisibleByAgent() ||
  280. gAgent.isGodlikeWithoutAdminMenuFakery();
  281. mTabContainer->enableTabButton(i, visible);
  282. if (!visible && mCurrentTab == panelp)
  283. {
  284. // We are disabling the currently selected tab select the previous
  285. // one
  286. mTabContainer->selectPrevTab();
  287. mCurrentTab = (LLPanelGroupTab*)mTabContainer->getCurrentPanel();
  288. }
  289. }
  290. }
  291. void LLPanelGroup::changed(LLGroupChange gc)
  292. {
  293. updateTabVisibility();
  294. // Notify the currently active panel that group manager information has
  295. // changed.
  296. LLPanelGroupTab* panelp =
  297. (LLPanelGroupTab*)mTabContainer->getCurrentPanel();
  298. if (panelp)
  299. {
  300. panelp->update(gc);
  301. }
  302. }
  303. // PanelGroupTab observer trigger
  304. void LLPanelGroup::tabChanged()
  305. {
  306. // Some tab information has changed... Enable/disable the apply button
  307. // based on if they need an apply
  308. if (mApplyBtn && mCurrentTab)
  309. {
  310. std::string mesg;
  311. mApplyBtn->setEnabled(mCurrentTab->needsApply(mesg));
  312. }
  313. }
  314. // static
  315. void LLPanelGroup::onClickTab(void* user_data, bool from_click)
  316. {
  317. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  318. if (self)
  319. {
  320. self->handleClickTab();
  321. }
  322. }
  323. void LLPanelGroup::handleClickTab()
  324. {
  325. // If we are already handling a transition,
  326. // ignore this.
  327. if (mIgnoreTransition)
  328. {
  329. return;
  330. }
  331. mRequestedTab = (LLPanelGroupTab*) mTabContainer->getCurrentPanel();
  332. // Make sure they aren't just clicking the same tab...
  333. if (mRequestedTab == mCurrentTab)
  334. {
  335. return;
  336. }
  337. // Try to switch from the current panel to the panel the user selected.
  338. attemptTransition();
  339. }
  340. void LLPanelGroup::setGroupID(const LLUUID& group_id)
  341. {
  342. LLRect rect(getRect());
  343. gGroupMgr.removeObserver(this);
  344. mID = group_id;
  345. gGroupMgr.addObserver(this);
  346. // *TODO: this is really bad, we should add a method where the panels can
  347. // just update themselves on a group id change. Similar to update() but
  348. // with a group id change.
  349. // Delete children and rebuild panel
  350. deleteAllChildren();
  351. // Rebuild panel
  352. LLUICtrlFactory::getInstance()->buildPanel(this, mFilename,
  353. &getFactoryMap());
  354. }
  355. void LLPanelGroup::selectTab(std::string tab_name)
  356. {
  357. LLPanelGroupTab* tabp = getChild<LLPanelGroupTab>(tab_name.c_str(), true,
  358. false);
  359. if (tabp && mTabContainer)
  360. {
  361. mTabContainer->selectTabPanel(tabp);
  362. onClickTab(this, false);
  363. }
  364. }
  365. bool LLPanelGroup::canClose()
  366. {
  367. if (mShowingNotifyDialog) return false;
  368. if (mCurrentTab && mCurrentTab->hasModal()) return false;
  369. if (mForceClose || !mAllowEdit) return true;
  370. // Try to switch from the current panel to nothing, indicating a close
  371. // action.
  372. mRequestedTab = NULL;
  373. return attemptTransition();
  374. }
  375. bool LLPanelGroup::attemptTransition()
  376. {
  377. // Check if the current tab needs to be applied.
  378. std::string mesg;
  379. if (mCurrentTab && mCurrentTab->needsApply(mesg))
  380. {
  381. // If no message was provided, give a generic one.
  382. if (mesg.empty())
  383. {
  384. mesg = mDefaultNeedsApplyMesg;
  385. }
  386. // Create a notify box, telling the user about the unapplied tab.
  387. LLSD args;
  388. args["NEEDS_APPLY_MESSAGE"] = mesg;
  389. args["WANT_APPLY_MESSAGE"] = mWantApplyMesg;
  390. gNotifications.add("PanelGroupApply", args, LLSD(),
  391. boost::bind(&LLPanelGroup::handleNotifyCallback,
  392. this, _1, _2));
  393. mShowingNotifyDialog = true;
  394. // We need to reselect the current tab, since it isn't finished.
  395. if (mTabContainer && mCurrentTab)
  396. {
  397. // selectTabPanel is going to trigger another click event. We want
  398. // to ignore it so that mRequestedTab is not updated.
  399. mIgnoreTransition = true;
  400. mTabContainer->selectTabPanel(mCurrentTab);
  401. mIgnoreTransition = false;
  402. }
  403. // Returning false will block a close action from finishing until we
  404. // get a response back from the user.
  405. return false;
  406. }
  407. else
  408. {
  409. // The current panel didn't have anything it needed to apply.
  410. if (mRequestedTab)
  411. {
  412. transitionToTab();
  413. }
  414. // Returning true will allow any close action to proceed.
  415. return true;
  416. }
  417. }
  418. void LLPanelGroup::transitionToTab()
  419. {
  420. // Tell the current panel that it is being deactivated.
  421. if (mCurrentTab)
  422. {
  423. mCurrentTab->deactivate();
  424. }
  425. // If the requested panel exists, activate it.
  426. if (mRequestedTab)
  427. {
  428. if (mCurrentTab)
  429. {
  430. // This is now the current tab;
  431. mCurrentTab = mRequestedTab;
  432. mCurrentTab->activate();
  433. }
  434. }
  435. else // NULL requested indicates a close action.
  436. {
  437. close();
  438. }
  439. }
  440. bool LLPanelGroup::handleNotifyCallback(const LLSD& notification,
  441. const LLSD& response)
  442. {
  443. mShowingNotifyDialog = false;
  444. S32 option = LLNotification::getSelectedOption(notification, response);
  445. switch (option)
  446. {
  447. case 0: // "Apply Changes"
  448. {
  449. // Try to apply changes, and switch to the requested tab.
  450. if (!apply())
  451. {
  452. // There was a problem doing the apply. Skip switching tabs.
  453. break;
  454. }
  455. // This panel's info successfully applied. Switch to the next panel
  456. mIgnoreTransition = true;
  457. if (mTabContainer) mTabContainer->selectTabPanel(mRequestedTab);
  458. mIgnoreTransition = false;
  459. transitionToTab();
  460. break;
  461. }
  462. case 1: // "Ignore Changes"
  463. {
  464. // Switch to the requested panel without applying changes (changes
  465. // may already have been applied in the previous block)
  466. mCurrentTab->cancel();
  467. mIgnoreTransition = true;
  468. if (mTabContainer) mTabContainer->selectTabPanel(mRequestedTab);
  469. mIgnoreTransition = false;
  470. transitionToTab();
  471. break;
  472. }
  473. case 2: // "Cancel"
  474. default:
  475. {
  476. // Do nothing. The user is cancelling the action. If we were
  477. // quitting, we didn't really mean it.
  478. gAppViewerp->abortQuit();
  479. break;
  480. }
  481. }
  482. return false;
  483. }
  484. // static
  485. void LLPanelGroup::onBtnOK(void* user_data)
  486. {
  487. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  488. // If we are able to apply changes, then close.
  489. if (self && self->apply())
  490. {
  491. self->close();
  492. }
  493. }
  494. // static
  495. void LLPanelGroup::onBtnCancel(void* user_data)
  496. {
  497. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  498. if (self) self->close();
  499. }
  500. // static
  501. void LLPanelGroup::onBtnApply(void* user_data)
  502. {
  503. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  504. if (self) self->apply();
  505. }
  506. bool LLPanelGroup::apply()
  507. {
  508. // Pass this along to the currently visible tab.
  509. if (!mTabContainer) return false;
  510. LLPanelGroupTab* panelp =
  511. (LLPanelGroupTab*)mTabContainer->getCurrentPanel();
  512. if (!panelp) return false;
  513. std::string mesg;
  514. if (!panelp->needsApply(mesg))
  515. {
  516. // We don't need to apply anything.
  517. // We're done.
  518. return true;
  519. }
  520. // Ignore the needs apply message. Try to do the actual apply.
  521. std::string apply_mesg;
  522. if (panelp->apply(apply_mesg))
  523. {
  524. // Everything worked. We're done.
  525. return true;
  526. }
  527. // There was a problem doing the actual apply.
  528. // Inform the user.
  529. if (!apply_mesg.empty())
  530. {
  531. LLSD args;
  532. args["MESSAGE"] = apply_mesg;
  533. gNotifications.add("GenericAlert", args);
  534. }
  535. return false;
  536. }
  537. // static
  538. void LLPanelGroup::onBtnRefresh(void* user_data)
  539. {
  540. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  541. if (self) self->refreshData();
  542. }
  543. void LLPanelGroup::refreshData()
  544. {
  545. gGroupMgr.clearGroupData(getID());
  546. if (mCurrentTab)
  547. {
  548. mCurrentTab->activate();
  549. }
  550. if (mRefreshBtn)
  551. {
  552. mRefreshBtn->setEnabled(false);
  553. }
  554. // 5 second timeout
  555. mRefreshTimer.start();
  556. mRefreshTimer.setTimerExpirySec(5);
  557. }
  558. void LLPanelGroup::close()
  559. {
  560. // Pass this to the parent, if it is a floater.
  561. LLView* viewp = getParent();
  562. if (!viewp) return;
  563. LLFloater* floaterp = viewp->asFloater();
  564. if (floaterp)
  565. {
  566. // First, set the force close flag, since the floater will be asking us
  567. // whether it can close.
  568. mForceClose = true;
  569. // Tell the parent floater to close.
  570. floaterp->close();
  571. }
  572. }
  573. void LLPanelGroup::showNotice(const std::string& subject,
  574. const std::string& message, bool has_inventory,
  575. const std::string& inventory_name,
  576. LLOfferInfo* inventory_offer)
  577. {
  578. if (!mCurrentTab || mCurrentTab->getName() != "notices_tab")
  579. {
  580. // We need to clean up that inventory offer.
  581. if (inventory_offer)
  582. {
  583. inventory_offer->forceResponse(IOR_DECLINE);
  584. }
  585. return;
  586. }
  587. LLPanelGroupNotices* notices = static_cast<LLPanelGroupNotices*>(mCurrentTab);
  588. if (notices)
  589. {
  590. notices->showNotice(subject, message, has_inventory, inventory_name,
  591. inventory_offer);
  592. }
  593. }