PageRenderTime 31ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/llpanelprofile.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 433 lines | 339 code | 53 blank | 41 comment | 73 complexity | 56c9b8f06fe92c759795cfbb35033ffd MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelprofile.cpp
  3. * @brief Profile panel implementation
  4. *
  5. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llpanelprofile.h"
  28. #include "llagent.h"
  29. #include "llavataractions.h"
  30. #include "llfloaterreg.h"
  31. #include "llcommandhandler.h"
  32. #include "llnotificationsutil.h"
  33. #include "llpanelpicks.h"
  34. #include "lltabcontainer.h"
  35. #include "llviewercontrol.h"
  36. #include "llviewernetwork.h"
  37. static const std::string PANEL_PICKS = "panel_picks";
  38. std::string getProfileURL(const std::string& agent_name)
  39. {
  40. std::string url;
  41. if (LLGridManager::getInstance()->isInProductionGrid())
  42. {
  43. url = gSavedSettings.getString("WebProfileURL");
  44. }
  45. else
  46. {
  47. url = gSavedSettings.getString("WebProfileNonProductionURL");
  48. }
  49. LLSD subs;
  50. subs["AGENT_NAME"] = agent_name;
  51. url = LLWeb::expandURLSubstitutions(url,subs);
  52. LLStringUtil::toLower(url);
  53. return url;
  54. }
  55. class LLProfileHandler : public LLCommandHandler
  56. {
  57. public:
  58. // requires trusted browser to trigger
  59. LLProfileHandler() : LLCommandHandler("profile", UNTRUSTED_THROTTLE) { }
  60. bool handle(const LLSD& params, const LLSD& query_map,
  61. LLMediaCtrl* web)
  62. {
  63. if (params.size() < 1) return false;
  64. std::string agent_name = params[0];
  65. llinfos << "Profile, agent_name " << agent_name << llendl;
  66. std::string url = getProfileURL(agent_name);
  67. LLWeb::loadURLInternal(url);
  68. return true;
  69. }
  70. };
  71. LLProfileHandler gProfileHandler;
  72. class LLAgentHandler : public LLCommandHandler
  73. {
  74. public:
  75. // requires trusted browser to trigger
  76. LLAgentHandler() : LLCommandHandler("agent", UNTRUSTED_THROTTLE) { }
  77. bool handle(const LLSD& params, const LLSD& query_map,
  78. LLMediaCtrl* web)
  79. {
  80. if (params.size() < 2) return false;
  81. LLUUID avatar_id;
  82. if (!avatar_id.set(params[0], FALSE))
  83. {
  84. return false;
  85. }
  86. const std::string verb = params[1].asString();
  87. if (verb == "about")
  88. {
  89. LLAvatarActions::showProfile(avatar_id);
  90. return true;
  91. }
  92. if (verb == "inspect")
  93. {
  94. LLFloaterReg::showInstance("inspect_avatar", LLSD().with("avatar_id", avatar_id));
  95. return true;
  96. }
  97. if (verb == "im")
  98. {
  99. LLAvatarActions::startIM(avatar_id);
  100. return true;
  101. }
  102. if (verb == "pay")
  103. {
  104. if (!LLUI::sSettingGroups["config"]->getBOOL("EnableAvatarPay"))
  105. {
  106. LLNotificationsUtil::add("NoAvatarPay", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
  107. return true;
  108. }
  109. LLAvatarActions::pay(avatar_id);
  110. return true;
  111. }
  112. if (verb == "offerteleport")
  113. {
  114. LLAvatarActions::offerTeleport(avatar_id);
  115. return true;
  116. }
  117. if (verb == "requestfriend")
  118. {
  119. LLAvatarActions::requestFriendshipDialog(avatar_id);
  120. return true;
  121. }
  122. if (verb == "mute")
  123. {
  124. if (! LLAvatarActions::isBlocked(avatar_id))
  125. {
  126. LLAvatarActions::toggleBlock(avatar_id);
  127. }
  128. return true;
  129. }
  130. if (verb == "unmute")
  131. {
  132. if (LLAvatarActions::isBlocked(avatar_id))
  133. {
  134. LLAvatarActions::toggleBlock(avatar_id);
  135. }
  136. return true;
  137. }
  138. return false;
  139. }
  140. };
  141. LLAgentHandler gAgentHandler;
  142. //-- LLPanelProfile::ChildStack begins ----------------------------------------
  143. LLPanelProfile::ChildStack::ChildStack()
  144. : mParent(NULL)
  145. {
  146. }
  147. LLPanelProfile::ChildStack::~ChildStack()
  148. {
  149. while (mStack.size() != 0)
  150. {
  151. view_list_t& top = mStack.back();
  152. for (view_list_t::const_iterator it = top.begin(); it != top.end(); ++it)
  153. {
  154. LLView* viewp = *it;
  155. if (viewp)
  156. {
  157. viewp->die();
  158. }
  159. }
  160. mStack.pop_back();
  161. }
  162. }
  163. void LLPanelProfile::ChildStack::setParent(LLPanel* parent)
  164. {
  165. llassert_always(parent != NULL);
  166. mParent = parent;
  167. }
  168. /// Save current parent's child views and remove them from the child list.
  169. bool LLPanelProfile::ChildStack::push()
  170. {
  171. view_list_t vlist = *mParent->getChildList();
  172. for (view_list_t::const_iterator it = vlist.begin(); it != vlist.end(); ++it)
  173. {
  174. LLView* viewp = *it;
  175. mParent->removeChild(viewp);
  176. }
  177. mStack.push_back(vlist);
  178. dump();
  179. return true;
  180. }
  181. /// Restore saved children (adding them back to the child list).
  182. bool LLPanelProfile::ChildStack::pop()
  183. {
  184. if (mStack.size() == 0)
  185. {
  186. llwarns << "Empty stack" << llendl;
  187. llassert(mStack.size() == 0);
  188. return false;
  189. }
  190. view_list_t& top = mStack.back();
  191. for (view_list_t::const_iterator it = top.begin(); it != top.end(); ++it)
  192. {
  193. LLView* viewp = *it;
  194. mParent->addChild(viewp);
  195. }
  196. mStack.pop_back();
  197. dump();
  198. return true;
  199. }
  200. /// Temporarily add all saved children back.
  201. void LLPanelProfile::ChildStack::preParentReshape()
  202. {
  203. mSavedStack = mStack;
  204. while(mStack.size() > 0)
  205. {
  206. pop();
  207. }
  208. }
  209. /// Add the temporarily saved children back.
  210. void LLPanelProfile::ChildStack::postParentReshape()
  211. {
  212. mStack = mSavedStack;
  213. mSavedStack = stack_t();
  214. for (stack_t::const_iterator stack_it = mStack.begin(); stack_it != mStack.end(); ++stack_it)
  215. {
  216. const view_list_t& vlist = (*stack_it);
  217. for (view_list_t::const_iterator list_it = vlist.begin(); list_it != vlist.end(); ++list_it)
  218. {
  219. LLView* viewp = *list_it;
  220. lldebugs << "removing " << viewp->getName() << llendl;
  221. mParent->removeChild(viewp);
  222. }
  223. }
  224. }
  225. void LLPanelProfile::ChildStack::dump()
  226. {
  227. unsigned lvl = 0;
  228. lldebugs << "child stack dump:" << llendl;
  229. for (stack_t::const_iterator stack_it = mStack.begin(); stack_it != mStack.end(); ++stack_it, ++lvl)
  230. {
  231. std::ostringstream dbg_line;
  232. dbg_line << "lvl #" << lvl << ":";
  233. const view_list_t& vlist = (*stack_it);
  234. for (view_list_t::const_iterator list_it = vlist.begin(); list_it != vlist.end(); ++list_it)
  235. {
  236. dbg_line << " " << (*list_it)->getName();
  237. }
  238. lldebugs << dbg_line.str() << llendl;
  239. }
  240. }
  241. //-- LLPanelProfile::ChildStack ends ------------------------------------------
  242. LLPanelProfile::LLPanelProfile()
  243. : LLPanel()
  244. , mAvatarId(LLUUID::null)
  245. {
  246. mChildStack.setParent(this);
  247. }
  248. BOOL LLPanelProfile::postBuild()
  249. {
  250. LLPanelPicks* panel_picks = findChild<LLPanelPicks>(PANEL_PICKS);
  251. panel_picks->setProfilePanel(this);
  252. getTabContainer()[PANEL_PICKS] = panel_picks;
  253. return TRUE;
  254. }
  255. // virtual
  256. void LLPanelProfile::reshape(S32 width, S32 height, BOOL called_from_parent)
  257. {
  258. // Temporarily add saved children back and reshape them.
  259. mChildStack.preParentReshape();
  260. LLPanel::reshape(width, height, called_from_parent);
  261. mChildStack.postParentReshape();
  262. }
  263. void LLPanelProfile::onOpen(const LLSD& key)
  264. {
  265. getTabContainer()[PANEL_PICKS]->onOpen(getAvatarId());
  266. // support commands to open further pieces of UI
  267. if (key.has("show_tab_panel"))
  268. {
  269. std::string panel = key["show_tab_panel"].asString();
  270. if (panel == "create_classified")
  271. {
  272. LLPanelPicks* picks = dynamic_cast<LLPanelPicks *>(getTabContainer()[PANEL_PICKS]);
  273. if (picks)
  274. {
  275. picks->createNewClassified();
  276. }
  277. }
  278. else if (panel == "classified_details")
  279. {
  280. LLPanelPicks* picks = dynamic_cast<LLPanelPicks *>(getTabContainer()[PANEL_PICKS]);
  281. if (picks)
  282. {
  283. LLSD params = key;
  284. params.erase("show_tab_panel");
  285. params.erase("open_tab_name");
  286. picks->openClassifiedInfo(params);
  287. }
  288. }
  289. else if (panel == "edit_classified")
  290. {
  291. LLPanelPicks* picks = dynamic_cast<LLPanelPicks *>(getTabContainer()[PANEL_PICKS]);
  292. if (picks)
  293. {
  294. LLSD params = key;
  295. params.erase("show_tab_panel");
  296. params.erase("open_tab_name");
  297. picks->openClassifiedEdit(params);
  298. }
  299. }
  300. else if (panel == "create_pick")
  301. {
  302. LLPanelPicks* picks = dynamic_cast<LLPanelPicks *>(getTabContainer()[PANEL_PICKS]);
  303. if (picks)
  304. {
  305. picks->createNewPick();
  306. }
  307. }
  308. else if (panel == "edit_pick")
  309. {
  310. LLPanelPicks* picks = dynamic_cast<LLPanelPicks *>(getTabContainer()[PANEL_PICKS]);
  311. if (picks)
  312. {
  313. LLSD params = key;
  314. params.erase("show_tab_panel");
  315. params.erase("open_tab_name");
  316. picks->openPickEdit(params);
  317. }
  318. }
  319. }
  320. }
  321. void LLPanelProfile::onTabSelected(const LLSD& param)
  322. {
  323. std::string tab_name = param.asString();
  324. if (NULL != getTabContainer()[tab_name])
  325. {
  326. getTabContainer()[tab_name]->onOpen(getAvatarId());
  327. }
  328. }
  329. void LLPanelProfile::openPanel(LLPanel* panel, const LLSD& params)
  330. {
  331. // Hide currently visible panel (STORM-690).
  332. mChildStack.push();
  333. // Add the panel or bring it to front.
  334. if (panel->getParent() != this)
  335. {
  336. addChild(panel);
  337. }
  338. else
  339. {
  340. sendChildToFront(panel);
  341. }
  342. panel->setVisible(TRUE);
  343. panel->setFocus(TRUE); // prevent losing focus by the floater
  344. panel->onOpen(params);
  345. LLRect new_rect = getRect();
  346. panel->reshape(new_rect.getWidth(), new_rect.getHeight());
  347. new_rect.setLeftTopAndSize(0, new_rect.getHeight(), new_rect.getWidth(), new_rect.getHeight());
  348. panel->setRect(new_rect);
  349. }
  350. void LLPanelProfile::closePanel(LLPanel* panel)
  351. {
  352. panel->setVisible(FALSE);
  353. if (panel->getParent() == this)
  354. {
  355. removeChild(panel);
  356. // Make the underlying panel visible.
  357. mChildStack.pop();
  358. // Prevent losing focus by the floater
  359. const child_list_t* child_list = getChildList();
  360. if (child_list->size() > 0)
  361. {
  362. child_list->front()->setFocus(TRUE);
  363. }
  364. else
  365. {
  366. llwarns << "No underlying panel to focus." << llendl;
  367. }
  368. }
  369. }
  370. S32 LLPanelProfile::notifyParent(const LLSD& info)
  371. {
  372. std::string action = info["action"];
  373. // lets update Picks list after Pick was saved
  374. if("save_new_pick" == action)
  375. {
  376. onOpen(info);
  377. return 1;
  378. }
  379. return LLPanel::notifyParent(info);
  380. }