/indra/newview/llpanelpicks.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 1455 lines · 1120 code · 229 blank · 106 comment · 167 complexity · e0bf79e5530b35058efb8f2667f796dc MD5 · raw file

  1. /**
  2. * @file llpanelpicks.cpp
  3. * @brief LLPanelPicks and related class implementations
  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 "llpanelpicks.h"
  28. #include "llagent.h"
  29. #include "llagentpicksinfo.h"
  30. #include "llavatarconstants.h"
  31. #include "llcommandhandler.h"
  32. #include "lldispatcher.h"
  33. #include "llflatlistview.h"
  34. #include "llfloaterreg.h"
  35. #include "llfloatersidepanelcontainer.h"
  36. #include "llfloaterworldmap.h"
  37. #include "llnotificationsutil.h"
  38. #include "lltexturectrl.h"
  39. #include "lltoggleablemenu.h"
  40. #include "lltrans.h"
  41. #include "llviewergenericmessage.h" // send_generic_message
  42. #include "llmenugl.h"
  43. #include "llviewermenu.h"
  44. #include "llregistry.h"
  45. #include "llaccordionctrl.h"
  46. #include "llaccordionctrltab.h"
  47. #include "llavatarpropertiesprocessor.h"
  48. #include "llfloatersidepanelcontainer.h"
  49. #include "llpanelavatar.h"
  50. #include "llpanelprofile.h"
  51. #include "llpanelpick.h"
  52. #include "llpanelclassified.h"
  53. static const std::string XML_BTN_NEW = "new_btn";
  54. static const std::string XML_BTN_DELETE = "trash_btn";
  55. static const std::string XML_BTN_INFO = "info_btn";
  56. static const std::string XML_BTN_TELEPORT = "teleport_btn";
  57. static const std::string XML_BTN_SHOW_ON_MAP = "show_on_map_btn";
  58. static const std::string PICK_ID("pick_id");
  59. static const std::string PICK_CREATOR_ID("pick_creator_id");
  60. static const std::string PICK_NAME("pick_name");
  61. static const std::string CLASSIFIED_ID("classified_id");
  62. static const std::string CLASSIFIED_NAME("classified_name");
  63. static LLRegisterPanelClassWrapper<LLPanelPicks> t_panel_picks("panel_picks");
  64. class LLPickHandler : public LLCommandHandler,
  65. public LLAvatarPropertiesObserver
  66. {
  67. public:
  68. std::set<LLUUID> mPickIds;
  69. // requires trusted browser to trigger
  70. LLPickHandler() : LLCommandHandler("pick", UNTRUSTED_THROTTLE) { }
  71. bool handle(const LLSD& params, const LLSD& query_map,
  72. LLMediaCtrl* web)
  73. {
  74. if (!LLUI::sSettingGroups["config"]->getBOOL("EnablePicks"))
  75. {
  76. LLNotificationsUtil::add("NoPicks", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
  77. return true;
  78. }
  79. // handle app/classified/create urls first
  80. if (params.size() == 1 && params[0].asString() == "create")
  81. {
  82. createPick();
  83. return true;
  84. }
  85. // then handle the general app/pick/{UUID}/{CMD} urls
  86. if (params.size() < 2)
  87. {
  88. return false;
  89. }
  90. // get the ID for the pick_id
  91. LLUUID pick_id;
  92. if (!pick_id.set(params[0], FALSE))
  93. {
  94. return false;
  95. }
  96. // edit the pick in the side tray.
  97. // need to ask the server for more info first though...
  98. const std::string verb = params[1].asString();
  99. if (verb == "edit")
  100. {
  101. mPickIds.insert(pick_id);
  102. LLAvatarPropertiesProcessor::getInstance()->addObserver(LLUUID(), this);
  103. LLAvatarPropertiesProcessor::getInstance()->sendPickInfoRequest(gAgent.getID(),pick_id);
  104. return true;
  105. }
  106. else
  107. {
  108. llwarns << "unknown verb " << verb << llendl;
  109. return false;
  110. }
  111. }
  112. void createPick()
  113. {
  114. // open the new pick panel on the Picks floater
  115. LLFloater* picks_floater = LLFloaterReg::showInstance("picks");
  116. LLPanelPicks* picks = picks_floater->findChild<LLPanelPicks>("panel_picks");
  117. if (picks)
  118. {
  119. picks->createNewPick();
  120. }
  121. }
  122. void editPick(LLPickData* pick_info)
  123. {
  124. LLSD params;
  125. params["open_tab_name"] = "panel_picks";
  126. params["show_tab_panel"] = "edit_pick";
  127. params["pick_id"] = pick_info->pick_id;
  128. params["avatar_id"] = pick_info->creator_id;
  129. params["snapshot_id"] = pick_info->snapshot_id;
  130. params["pick_name"] = pick_info->name;
  131. params["pick_desc"] = pick_info->desc;
  132. LLFloaterSidePanelContainer::showPanel("picks", params);
  133. }
  134. /*virtual*/ void processProperties(void* data, EAvatarProcessorType type)
  135. {
  136. if (APT_PICK_INFO != type)
  137. {
  138. return;
  139. }
  140. // is this the pick that we asked for?
  141. LLPickData* pick_info = static_cast<LLPickData*>(data);
  142. if (!pick_info || mPickIds.find(pick_info->pick_id) == mPickIds.end())
  143. {
  144. return;
  145. }
  146. // open the edit side tray for this pick
  147. if (pick_info->creator_id == gAgent.getID())
  148. {
  149. editPick(pick_info);
  150. }
  151. else
  152. {
  153. llwarns << "Can't edit a pick you did not create" << llendl;
  154. }
  155. // remove our observer now that we're done
  156. mPickIds.erase(pick_info->pick_id);
  157. LLAvatarPropertiesProcessor::getInstance()->removeObserver(LLUUID(), this);
  158. }
  159. };
  160. LLPickHandler gPickHandler;
  161. class LLClassifiedHandler :
  162. public LLCommandHandler,
  163. public LLAvatarPropertiesObserver
  164. {
  165. public:
  166. // throttle calls from untrusted browsers
  167. LLClassifiedHandler() : LLCommandHandler("classified", UNTRUSTED_THROTTLE) {}
  168. std::set<LLUUID> mClassifiedIds;
  169. std::string mRequestVerb;
  170. bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
  171. {
  172. if (!LLUI::sSettingGroups["config"]->getBOOL("EnableClassifieds"))
  173. {
  174. LLNotificationsUtil::add("NoClassifieds", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
  175. return true;
  176. }
  177. // handle app/classified/create urls first
  178. if (params.size() == 1 && params[0].asString() == "create")
  179. {
  180. createClassified();
  181. return true;
  182. }
  183. // then handle the general app/classified/{UUID}/{CMD} urls
  184. if (params.size() < 2)
  185. {
  186. return false;
  187. }
  188. // get the ID for the classified
  189. LLUUID classified_id;
  190. if (!classified_id.set(params[0], FALSE))
  191. {
  192. return false;
  193. }
  194. // show the classified in the side tray.
  195. // need to ask the server for more info first though...
  196. const std::string verb = params[1].asString();
  197. if (verb == "about")
  198. {
  199. mRequestVerb = verb;
  200. mClassifiedIds.insert(classified_id);
  201. LLAvatarPropertiesProcessor::getInstance()->addObserver(LLUUID(), this);
  202. LLAvatarPropertiesProcessor::getInstance()->sendClassifiedInfoRequest(classified_id);
  203. return true;
  204. }
  205. else if (verb == "edit")
  206. {
  207. mRequestVerb = verb;
  208. mClassifiedIds.insert(classified_id);
  209. LLAvatarPropertiesProcessor::getInstance()->addObserver(LLUUID(), this);
  210. LLAvatarPropertiesProcessor::getInstance()->sendClassifiedInfoRequest(classified_id);
  211. return true;
  212. }
  213. return false;
  214. }
  215. void createClassified()
  216. {
  217. // open the new classified panel on the Picks floater
  218. LLFloater* picks_floater = LLFloaterReg::showInstance("picks");
  219. LLPanelPicks* picks = picks_floater->findChild<LLPanelPicks>("panel_picks");
  220. if (picks)
  221. {
  222. picks->createNewClassified();
  223. }
  224. }
  225. void openClassified(LLAvatarClassifiedInfo* c_info)
  226. {
  227. if (mRequestVerb == "about")
  228. {
  229. // open the classified info panel on the Me > Picks sidetray
  230. LLSD params;
  231. params["id"] = c_info->creator_id;
  232. params["open_tab_name"] = "panel_picks";
  233. params["show_tab_panel"] = "classified_details";
  234. params["classified_id"] = c_info->classified_id;
  235. params["classified_creator_id"] = c_info->creator_id;
  236. params["classified_snapshot_id"] = c_info->snapshot_id;
  237. params["classified_name"] = c_info->name;
  238. params["classified_desc"] = c_info->description;
  239. params["from_search"] = true;
  240. LLFloaterSidePanelContainer::showPanel("picks", params);
  241. }
  242. else if (mRequestVerb == "edit")
  243. {
  244. if (c_info->creator_id == gAgent.getID())
  245. {
  246. llwarns << "edit in progress" << llendl;
  247. // open the new classified panel on the Me > Picks sidetray
  248. LLSD params;
  249. params["id"] = gAgent.getID();
  250. params["open_tab_name"] = "panel_picks";
  251. params["show_tab_panel"] = "edit_classified";
  252. params["classified_id"] = c_info->classified_id;
  253. LLFloaterSidePanelContainer::showPanel("my_profile", params);
  254. }
  255. else
  256. {
  257. llwarns << "Can't edit a classified you did not create" << llendl;
  258. }
  259. }
  260. }
  261. /*virtual*/ void processProperties(void* data, EAvatarProcessorType type)
  262. {
  263. if (APT_CLASSIFIED_INFO != type)
  264. {
  265. return;
  266. }
  267. // is this the classified that we asked for?
  268. LLAvatarClassifiedInfo* c_info = static_cast<LLAvatarClassifiedInfo*>(data);
  269. if (!c_info || mClassifiedIds.find(c_info->classified_id) == mClassifiedIds.end())
  270. {
  271. return;
  272. }
  273. // open the detail side tray for this classified
  274. openClassified(c_info);
  275. // remove our observer now that we're done
  276. mClassifiedIds.erase(c_info->classified_id);
  277. LLAvatarPropertiesProcessor::getInstance()->removeObserver(LLUUID(), this);
  278. }
  279. };
  280. LLClassifiedHandler gClassifiedHandler;
  281. //////////////////////////////////////////////////////////////////////////
  282. //-----------------------------------------------------------------------------
  283. // LLPanelPicks
  284. //-----------------------------------------------------------------------------
  285. LLPanelPicks::LLPanelPicks()
  286. : LLPanelProfileTab(),
  287. mPopupMenu(NULL),
  288. mProfilePanel(NULL),
  289. mPickPanel(NULL),
  290. mPicksList(NULL),
  291. mClassifiedsList(NULL),
  292. mPanelPickInfo(NULL),
  293. mPanelPickEdit(NULL),
  294. mPlusMenu(NULL),
  295. mPicksAccTab(NULL),
  296. mClassifiedsAccTab(NULL),
  297. mPanelClassifiedInfo(NULL),
  298. mNoClassifieds(false),
  299. mNoPicks(false)
  300. {
  301. }
  302. LLPanelPicks::~LLPanelPicks()
  303. {
  304. if(getAvatarId().notNull())
  305. {
  306. LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(),this);
  307. }
  308. }
  309. void* LLPanelPicks::create(void* data /* = NULL */)
  310. {
  311. return new LLPanelPicks();
  312. }
  313. void LLPanelPicks::updateData()
  314. {
  315. // Send Picks request only when we need to, not on every onOpen(during tab switch).
  316. if(isDirty())
  317. {
  318. mNoPicks = false;
  319. mNoClassifieds = false;
  320. mNoItemsLabel->setValue(LLTrans::getString("PicksClassifiedsLoadingText"));
  321. mNoItemsLabel->setVisible(TRUE);
  322. mPicksList->clear();
  323. LLAvatarPropertiesProcessor::getInstance()->sendAvatarPicksRequest(getAvatarId());
  324. mClassifiedsList->clear();
  325. LLAvatarPropertiesProcessor::getInstance()->sendAvatarClassifiedsRequest(getAvatarId());
  326. }
  327. }
  328. void LLPanelPicks::processProperties(void* data, EAvatarProcessorType type)
  329. {
  330. if(APT_PICKS == type)
  331. {
  332. LLAvatarPicks* avatar_picks = static_cast<LLAvatarPicks*>(data);
  333. if(avatar_picks && getAvatarId() == avatar_picks->target_id)
  334. {
  335. std::string full_name;
  336. gCacheName->getFullName(getAvatarId(), full_name);
  337. getChild<LLUICtrl>("pick_title")->setTextArg("[NAME]", full_name);
  338. // Save selection, to be able to edit same item after saving changes. See EXT-3023.
  339. LLUUID selected_id = mPicksList->getSelectedValue()[PICK_ID];
  340. mPicksList->clear();
  341. LLAvatarPicks::picks_list_t::const_iterator it = avatar_picks->picks_list.begin();
  342. for(; avatar_picks->picks_list.end() != it; ++it)
  343. {
  344. LLUUID pick_id = it->first;
  345. std::string pick_name = it->second;
  346. LLPickItem* picture = LLPickItem::create();
  347. picture->childSetAction("info_chevron", boost::bind(&LLPanelPicks::onClickInfo, this));
  348. picture->setPickName(pick_name);
  349. picture->setPickId(pick_id);
  350. picture->setCreatorId(getAvatarId());
  351. LLAvatarPropertiesProcessor::instance().addObserver(getAvatarId(), picture);
  352. picture->update();
  353. LLSD pick_value = LLSD();
  354. pick_value.insert(PICK_ID, pick_id);
  355. pick_value.insert(PICK_NAME, pick_name);
  356. pick_value.insert(PICK_CREATOR_ID, getAvatarId());
  357. mPicksList->addItem(picture, pick_value);
  358. // Restore selection by item id.
  359. if ( pick_id == selected_id )
  360. mPicksList->selectItemByValue(pick_value);
  361. picture->setDoubleClickCallback(boost::bind(&LLPanelPicks::onDoubleClickPickItem, this, _1));
  362. picture->setRightMouseUpCallback(boost::bind(&LLPanelPicks::onRightMouseUpItem, this, _1, _2, _3, _4));
  363. picture->setMouseUpCallback(boost::bind(&LLPanelPicks::updateButtons, this));
  364. }
  365. showAccordion("tab_picks", mPicksList->size());
  366. resetDirty();
  367. updateButtons();
  368. }
  369. mNoPicks = !mPicksList->size();
  370. }
  371. else if(APT_CLASSIFIEDS == type)
  372. {
  373. LLAvatarClassifieds* c_info = static_cast<LLAvatarClassifieds*>(data);
  374. if(c_info && getAvatarId() == c_info->target_id)
  375. {
  376. // do not clear classified list in case we will receive two or more data packets.
  377. // list has been cleared in updateData(). (fix for EXT-6436)
  378. LLAvatarClassifieds::classifieds_list_t::const_iterator it = c_info->classifieds_list.begin();
  379. for(; c_info->classifieds_list.end() != it; ++it)
  380. {
  381. LLAvatarClassifieds::classified_data c_data = *it;
  382. LLClassifiedItem* c_item = new LLClassifiedItem(getAvatarId(), c_data.classified_id);
  383. c_item->childSetAction("info_chevron", boost::bind(&LLPanelPicks::onClickInfo, this));
  384. c_item->setClassifiedName(c_data.name);
  385. LLSD pick_value = LLSD();
  386. pick_value.insert(CLASSIFIED_ID, c_data.classified_id);
  387. pick_value.insert(CLASSIFIED_NAME, c_data.name);
  388. if (!findClassifiedById(c_data.classified_id))
  389. {
  390. mClassifiedsList->addItem(c_item, pick_value);
  391. }
  392. c_item->setDoubleClickCallback(boost::bind(&LLPanelPicks::onDoubleClickClassifiedItem, this, _1));
  393. c_item->setRightMouseUpCallback(boost::bind(&LLPanelPicks::onRightMouseUpItem, this, _1, _2, _3, _4));
  394. c_item->setMouseUpCallback(boost::bind(&LLPanelPicks::updateButtons, this));
  395. }
  396. showAccordion("tab_classifieds", mClassifiedsList->size());
  397. resetDirty();
  398. updateButtons();
  399. }
  400. mNoClassifieds = !mClassifiedsList->size();
  401. }
  402. bool no_data = mNoPicks && mNoClassifieds;
  403. mNoItemsLabel->setVisible(no_data);
  404. if (no_data)
  405. {
  406. if(getAvatarId() == gAgentID)
  407. {
  408. mNoItemsLabel->setValue(LLTrans::getString("NoPicksClassifiedsText"));
  409. }
  410. else
  411. {
  412. mNoItemsLabel->setValue(LLTrans::getString("NoAvatarPicksClassifiedsText"));
  413. }
  414. }
  415. }
  416. LLPickItem* LLPanelPicks::getSelectedPickItem()
  417. {
  418. LLPanel* selected_item = mPicksList->getSelectedItem();
  419. if (!selected_item) return NULL;
  420. return dynamic_cast<LLPickItem*>(selected_item);
  421. }
  422. LLClassifiedItem* LLPanelPicks::getSelectedClassifiedItem()
  423. {
  424. LLPanel* selected_item = mClassifiedsList->getSelectedItem();
  425. if (!selected_item)
  426. {
  427. return NULL;
  428. }
  429. return dynamic_cast<LLClassifiedItem*>(selected_item);
  430. }
  431. BOOL LLPanelPicks::postBuild()
  432. {
  433. mPicksList = getChild<LLFlatListView>("picks_list");
  434. mClassifiedsList = getChild<LLFlatListView>("classifieds_list");
  435. mPicksList->setCommitOnSelectionChange(true);
  436. mClassifiedsList->setCommitOnSelectionChange(true);
  437. mPicksList->setCommitCallback(boost::bind(&LLPanelPicks::onListCommit, this, mPicksList));
  438. mClassifiedsList->setCommitCallback(boost::bind(&LLPanelPicks::onListCommit, this, mClassifiedsList));
  439. mPicksList->setNoItemsCommentText(getString("no_picks"));
  440. mClassifiedsList->setNoItemsCommentText(getString("no_classifieds"));
  441. mNoItemsLabel = getChild<LLUICtrl>("picks_panel_text");
  442. childSetAction(XML_BTN_NEW, boost::bind(&LLPanelPicks::onClickPlusBtn, this));
  443. childSetAction(XML_BTN_DELETE, boost::bind(&LLPanelPicks::onClickDelete, this));
  444. childSetAction(XML_BTN_TELEPORT, boost::bind(&LLPanelPicks::onClickTeleport, this));
  445. childSetAction(XML_BTN_SHOW_ON_MAP, boost::bind(&LLPanelPicks::onClickMap, this));
  446. childSetAction(XML_BTN_INFO, boost::bind(&LLPanelPicks::onClickInfo, this));
  447. mPicksAccTab = getChild<LLAccordionCtrlTab>("tab_picks");
  448. mPicksAccTab->setDropDownStateChangedCallback(boost::bind(&LLPanelPicks::onAccordionStateChanged, this, mPicksAccTab));
  449. mPicksAccTab->setDisplayChildren(true);
  450. mClassifiedsAccTab = getChild<LLAccordionCtrlTab>("tab_classifieds");
  451. mClassifiedsAccTab->setDropDownStateChangedCallback(boost::bind(&LLPanelPicks::onAccordionStateChanged, this, mClassifiedsAccTab));
  452. mClassifiedsAccTab->setDisplayChildren(false);
  453. LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registar;
  454. registar.add("Pick.Info", boost::bind(&LLPanelPicks::onClickInfo, this));
  455. registar.add("Pick.Edit", boost::bind(&LLPanelPicks::onClickMenuEdit, this));
  456. registar.add("Pick.Teleport", boost::bind(&LLPanelPicks::onClickTeleport, this));
  457. registar.add("Pick.Map", boost::bind(&LLPanelPicks::onClickMap, this));
  458. registar.add("Pick.Delete", boost::bind(&LLPanelPicks::onClickDelete, this));
  459. LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registar;
  460. enable_registar.add("Pick.Enable", boost::bind(&LLPanelPicks::onEnableMenuItem, this, _2));
  461. mPopupMenu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>("menu_picks.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
  462. LLUICtrl::CommitCallbackRegistry::ScopedRegistrar plus_registar;
  463. plus_registar.add("Picks.Plus.Action", boost::bind(&LLPanelPicks::onPlusMenuItemClicked, this, _2));
  464. mEnableCallbackRegistrar.add("Picks.Plus.Enable", boost::bind(&LLPanelPicks::isActionEnabled, this, _2));
  465. mPlusMenu = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>("menu_picks_plus.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
  466. return TRUE;
  467. }
  468. void LLPanelPicks::onPlusMenuItemClicked(const LLSD& param)
  469. {
  470. std::string value = param.asString();
  471. if("new_pick" == value)
  472. {
  473. createNewPick();
  474. }
  475. else if("new_classified" == value)
  476. {
  477. createNewClassified();
  478. }
  479. }
  480. bool LLPanelPicks::isActionEnabled(const LLSD& userdata) const
  481. {
  482. std::string command_name = userdata.asString();
  483. if (command_name == "new_pick" && LLAgentPicksInfo::getInstance()->isPickLimitReached())
  484. {
  485. return false;
  486. }
  487. return true;
  488. }
  489. bool LLPanelPicks::isClassifiedPublished(LLClassifiedItem* c_item)
  490. {
  491. if(c_item)
  492. {
  493. LLPanelClassifiedEdit* panel = mEditClassifiedPanels[c_item->getClassifiedId()];
  494. if(panel)
  495. {
  496. return !panel->isNewWithErrors();
  497. }
  498. // we've got this classified from server - it's published
  499. return true;
  500. }
  501. return false;
  502. }
  503. void LLPanelPicks::onAccordionStateChanged(const LLAccordionCtrlTab* acc_tab)
  504. {
  505. if(!mPicksAccTab->getDisplayChildren())
  506. {
  507. mPicksList->resetSelection(true);
  508. }
  509. if(!mClassifiedsAccTab->getDisplayChildren())
  510. {
  511. mClassifiedsList->resetSelection(true);
  512. }
  513. updateButtons();
  514. }
  515. void LLPanelPicks::onOpen(const LLSD& key)
  516. {
  517. const LLUUID id(key.asUUID());
  518. BOOL self = (gAgent.getID() == id);
  519. // only agent can edit her picks
  520. getChildView("edit_panel")->setEnabled(self);
  521. getChildView("edit_panel")->setVisible( self);
  522. // Disable buttons when viewing profile for first time
  523. if(getAvatarId() != id)
  524. {
  525. getChildView(XML_BTN_INFO)->setEnabled(FALSE);
  526. getChildView(XML_BTN_TELEPORT)->setEnabled(FALSE);
  527. getChildView(XML_BTN_SHOW_ON_MAP)->setEnabled(FALSE);
  528. }
  529. // and see a special title - set as invisible by default in xml file
  530. if (self)
  531. {
  532. getChildView("pick_title")->setVisible( !self);
  533. getChildView("pick_title_agent")->setVisible( self);
  534. mPopupMenu->setItemVisible("pick_delete", TRUE);
  535. mPopupMenu->setItemVisible("pick_edit", TRUE);
  536. mPopupMenu->setItemVisible("pick_separator", TRUE);
  537. }
  538. if(getAvatarId() != id)
  539. {
  540. showAccordion("tab_picks", false);
  541. showAccordion("tab_classifieds", false);
  542. mPicksList->goToTop();
  543. // Set dummy value to make panel dirty and make it reload picks
  544. setValue(LLSD());
  545. }
  546. LLPanelProfileTab::onOpen(key);
  547. }
  548. void LLPanelPicks::onClosePanel()
  549. {
  550. if (mPanelClassifiedInfo)
  551. {
  552. onPanelClassifiedClose(mPanelClassifiedInfo);
  553. }
  554. if (mPanelPickInfo)
  555. {
  556. onPanelPickClose(mPanelPickInfo);
  557. }
  558. }
  559. void LLPanelPicks::onListCommit(const LLFlatListView* f_list)
  560. {
  561. // Make sure only one of the lists has selection.
  562. if(f_list == mPicksList)
  563. {
  564. mClassifiedsList->resetSelection(true);
  565. }
  566. else if(f_list == mClassifiedsList)
  567. {
  568. mPicksList->resetSelection(true);
  569. }
  570. else
  571. {
  572. llwarns << "Unknown list" << llendl;
  573. }
  574. updateButtons();
  575. }
  576. //static
  577. void LLPanelPicks::onClickDelete()
  578. {
  579. LLSD value = mPicksList->getSelectedValue();
  580. if (value.isDefined())
  581. {
  582. LLSD args;
  583. args["PICK"] = value[PICK_NAME];
  584. LLNotificationsUtil::add("DeleteAvatarPick", args, LLSD(), boost::bind(&LLPanelPicks::callbackDeletePick, this, _1, _2));
  585. return;
  586. }
  587. value = mClassifiedsList->getSelectedValue();
  588. if(value.isDefined())
  589. {
  590. LLSD args;
  591. args["NAME"] = value[CLASSIFIED_NAME];
  592. LLNotificationsUtil::add("DeleteClassified", args, LLSD(), boost::bind(&LLPanelPicks::callbackDeleteClassified, this, _1, _2));
  593. return;
  594. }
  595. }
  596. bool LLPanelPicks::callbackDeletePick(const LLSD& notification, const LLSD& response)
  597. {
  598. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  599. LLSD pick_value = mPicksList->getSelectedValue();
  600. if (0 == option)
  601. {
  602. LLAvatarPropertiesProcessor::instance().sendPickDelete(pick_value[PICK_ID]);
  603. mPicksList->removeItemByValue(pick_value);
  604. }
  605. updateButtons();
  606. return false;
  607. }
  608. bool LLPanelPicks::callbackDeleteClassified(const LLSD& notification, const LLSD& response)
  609. {
  610. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  611. LLSD value = mClassifiedsList->getSelectedValue();
  612. if (0 == option)
  613. {
  614. LLAvatarPropertiesProcessor::instance().sendClassifiedDelete(value[CLASSIFIED_ID]);
  615. mClassifiedsList->removeItemByValue(value);
  616. }
  617. updateButtons();
  618. return false;
  619. }
  620. bool LLPanelPicks::callbackTeleport( const LLSD& notification, const LLSD& response )
  621. {
  622. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  623. if (0 == option)
  624. {
  625. onClickTeleport();
  626. }
  627. return false;
  628. }
  629. //static
  630. void LLPanelPicks::onClickTeleport()
  631. {
  632. LLPickItem* pick_item = getSelectedPickItem();
  633. LLClassifiedItem* c_item = getSelectedClassifiedItem();
  634. LLVector3d pos;
  635. if(pick_item)
  636. pos = pick_item->getPosGlobal();
  637. else if(c_item)
  638. {
  639. pos = c_item->getPosGlobal();
  640. LLPanelClassifiedInfo::sendClickMessage("teleport", false,
  641. c_item->getClassifiedId(), LLUUID::null, pos, LLStringUtil::null);
  642. }
  643. if (!pos.isExactlyZero())
  644. {
  645. gAgent.teleportViaLocation(pos);
  646. LLFloaterWorldMap::getInstance()->trackLocation(pos);
  647. }
  648. }
  649. //static
  650. void LLPanelPicks::onClickMap()
  651. {
  652. LLPickItem* pick_item = getSelectedPickItem();
  653. LLClassifiedItem* c_item = getSelectedClassifiedItem();
  654. LLVector3d pos;
  655. if (pick_item)
  656. pos = pick_item->getPosGlobal();
  657. else if(c_item)
  658. {
  659. LLPanelClassifiedInfo::sendClickMessage("map", false,
  660. c_item->getClassifiedId(), LLUUID::null, pos, LLStringUtil::null);
  661. pos = c_item->getPosGlobal();
  662. }
  663. LLFloaterWorldMap::getInstance()->trackLocation(pos);
  664. LLFloaterReg::showInstance("world_map", "center");
  665. }
  666. void LLPanelPicks::onRightMouseUpItem(LLUICtrl* item, S32 x, S32 y, MASK mask)
  667. {
  668. updateButtons();
  669. if (mPopupMenu)
  670. {
  671. mPopupMenu->buildDrawLabels();
  672. mPopupMenu->updateParent(LLMenuGL::sMenuContainer);
  673. ((LLContextMenu*)mPopupMenu)->show(x, y);
  674. LLMenuGL::showPopup(item, mPopupMenu, x, y);
  675. }
  676. }
  677. void LLPanelPicks::onDoubleClickPickItem(LLUICtrl* item)
  678. {
  679. LLSD pick_value = mPicksList->getSelectedValue();
  680. if (pick_value.isUndefined()) return;
  681. LLSD args;
  682. args["PICK"] = pick_value[PICK_NAME];
  683. LLNotificationsUtil::add("TeleportToPick", args, LLSD(), boost::bind(&LLPanelPicks::callbackTeleport, this, _1, _2));
  684. }
  685. void LLPanelPicks::onDoubleClickClassifiedItem(LLUICtrl* item)
  686. {
  687. LLSD value = mClassifiedsList->getSelectedValue();
  688. if (value.isUndefined()) return;
  689. LLSD args;
  690. args["CLASSIFIED"] = value[CLASSIFIED_NAME];
  691. LLNotificationsUtil::add("TeleportToClassified", args, LLSD(), boost::bind(&LLPanelPicks::callbackTeleport, this, _1, _2));
  692. }
  693. void LLPanelPicks::updateButtons()
  694. {
  695. bool has_selected = mPicksList->numSelected() > 0 || mClassifiedsList->numSelected() > 0;
  696. if (getAvatarId() == gAgentID)
  697. {
  698. getChildView(XML_BTN_DELETE)->setEnabled(has_selected);
  699. }
  700. getChildView(XML_BTN_INFO)->setEnabled(has_selected);
  701. getChildView(XML_BTN_TELEPORT)->setEnabled(has_selected);
  702. getChildView(XML_BTN_SHOW_ON_MAP)->setEnabled(has_selected);
  703. LLClassifiedItem* c_item = dynamic_cast<LLClassifiedItem*>(mClassifiedsList->getSelectedItem());
  704. if(c_item)
  705. {
  706. getChildView(XML_BTN_INFO)->setEnabled(isClassifiedPublished(c_item));
  707. }
  708. }
  709. void LLPanelPicks::setProfilePanel(LLPanelProfile* profile_panel)
  710. {
  711. mProfilePanel = profile_panel;
  712. }
  713. void LLPanelPicks::buildPickPanel()
  714. {
  715. // if (mPickPanel == NULL)
  716. // {
  717. // mPickPanel = new LLPanelPick();
  718. // mPickPanel->setExitCallback(boost::bind(&LLPanelPicks::onPanelPickClose, this, NULL));
  719. // }
  720. }
  721. void LLPanelPicks::onClickPlusBtn()
  722. {
  723. LLRect rect(getChildView(XML_BTN_NEW)->getRect());
  724. mPlusMenu->updateParent(LLMenuGL::sMenuContainer);
  725. mPlusMenu->setButtonRect(rect, this);
  726. LLMenuGL::showPopup(this, mPlusMenu, rect.mLeft, rect.mTop);
  727. }
  728. void LLPanelPicks::createNewPick()
  729. {
  730. createPickEditPanel();
  731. getProfilePanel()->openPanel(mPanelPickEdit, LLSD());
  732. }
  733. void LLPanelPicks::createNewClassified()
  734. {
  735. LLPanelClassifiedEdit* panel = NULL;
  736. createClassifiedEditPanel(&panel);
  737. getProfilePanel()->openPanel(panel, LLSD());
  738. }
  739. void LLPanelPicks::onClickInfo()
  740. {
  741. if(mPicksList->numSelected() > 0)
  742. {
  743. openPickInfo();
  744. }
  745. else if(mClassifiedsList->numSelected() > 0)
  746. {
  747. openClassifiedInfo();
  748. }
  749. }
  750. void LLPanelPicks::openPickInfo()
  751. {
  752. LLSD selected_value = mPicksList->getSelectedValue();
  753. if (selected_value.isUndefined()) return;
  754. LLPickItem* pick = (LLPickItem*)mPicksList->getSelectedItem();
  755. createPickInfoPanel();
  756. LLSD params;
  757. params["pick_id"] = pick->getPickId();
  758. params["avatar_id"] = pick->getCreatorId();
  759. params["snapshot_id"] = pick->getSnapshotId();
  760. params["pick_name"] = pick->getPickName();
  761. params["pick_desc"] = pick->getPickDesc();
  762. getProfilePanel()->openPanel(mPanelPickInfo, params);
  763. }
  764. void LLPanelPicks::openClassifiedInfo()
  765. {
  766. LLSD selected_value = mClassifiedsList->getSelectedValue();
  767. if (selected_value.isUndefined()) return;
  768. LLClassifiedItem* c_item = getSelectedClassifiedItem();
  769. LLSD params;
  770. params["classified_id"] = c_item->getClassifiedId();
  771. params["classified_creator_id"] = c_item->getAvatarId();
  772. params["classified_snapshot_id"] = c_item->getSnapshotId();
  773. params["classified_name"] = c_item->getClassifiedName();
  774. params["classified_desc"] = c_item->getDescription();
  775. params["from_search"] = false;
  776. openClassifiedInfo(params);
  777. }
  778. void LLPanelPicks::openClassifiedInfo(const LLSD &params)
  779. {
  780. createClassifiedInfoPanel();
  781. getProfilePanel()->openPanel(mPanelClassifiedInfo, params);
  782. }
  783. void LLPanelPicks::openClassifiedEdit(const LLSD& params)
  784. {
  785. LLUUID classified_id = params["classified_id"].asUUID();;
  786. llinfos << "opening classified " << classified_id << " for edit" << llendl;
  787. editClassified(classified_id);
  788. }
  789. void LLPanelPicks::showAccordion(const std::string& name, bool show)
  790. {
  791. LLAccordionCtrlTab* tab = getChild<LLAccordionCtrlTab>(name);
  792. tab->setVisible(show);
  793. LLAccordionCtrl* acc = getChild<LLAccordionCtrl>("accordion");
  794. acc->arrange();
  795. }
  796. void LLPanelPicks::onPanelPickClose(LLPanel* panel)
  797. {
  798. getProfilePanel()->closePanel(panel);
  799. }
  800. void LLPanelPicks::onPanelPickSave(LLPanel* panel)
  801. {
  802. onPanelPickClose(panel);
  803. updateButtons();
  804. }
  805. void LLPanelPicks::onPanelClassifiedSave(LLPanelClassifiedEdit* panel)
  806. {
  807. if(!panel->canClose())
  808. {
  809. return;
  810. }
  811. if(panel->isNew())
  812. {
  813. mEditClassifiedPanels[panel->getClassifiedId()] = panel;
  814. LLClassifiedItem* c_item = new LLClassifiedItem(getAvatarId(), panel->getClassifiedId());
  815. c_item->fillIn(panel);
  816. LLSD c_value;
  817. c_value.insert(CLASSIFIED_ID, c_item->getClassifiedId());
  818. c_value.insert(CLASSIFIED_NAME, c_item->getClassifiedName());
  819. mClassifiedsList->addItem(c_item, c_value, ADD_TOP);
  820. c_item->setDoubleClickCallback(boost::bind(&LLPanelPicks::onDoubleClickClassifiedItem, this, _1));
  821. c_item->setRightMouseUpCallback(boost::bind(&LLPanelPicks::onRightMouseUpItem, this, _1, _2, _3, _4));
  822. c_item->setMouseUpCallback(boost::bind(&LLPanelPicks::updateButtons, this));
  823. c_item->childSetAction("info_chevron", boost::bind(&LLPanelPicks::onClickInfo, this));
  824. // order does matter, showAccordion will invoke arrange for accordions.
  825. mClassifiedsAccTab->changeOpenClose(false);
  826. showAccordion("tab_classifieds", true);
  827. }
  828. else if(panel->isNewWithErrors())
  829. {
  830. LLClassifiedItem* c_item = dynamic_cast<LLClassifiedItem*>(mClassifiedsList->getSelectedItem());
  831. llassert(c_item);
  832. if (c_item)
  833. {
  834. c_item->fillIn(panel);
  835. }
  836. }
  837. else
  838. {
  839. onPanelClassifiedClose(panel);
  840. return;
  841. }
  842. onPanelPickClose(panel);
  843. updateButtons();
  844. }
  845. void LLPanelPicks::onPanelClassifiedClose(LLPanelClassifiedInfo* panel)
  846. {
  847. if(panel->getInfoLoaded() && !panel->isDirty())
  848. {
  849. std::vector<LLSD> values;
  850. mClassifiedsList->getValues(values);
  851. for(size_t n = 0; n < values.size(); ++n)
  852. {
  853. LLUUID c_id = values[n][CLASSIFIED_ID].asUUID();
  854. if(panel->getClassifiedId() == c_id)
  855. {
  856. LLClassifiedItem* c_item = dynamic_cast<LLClassifiedItem*>(
  857. mClassifiedsList->getItemByValue(values[n]));
  858. llassert(c_item);
  859. if (c_item)
  860. {
  861. c_item->setClassifiedName(panel->getClassifiedName());
  862. c_item->setDescription(panel->getDescription());
  863. c_item->setSnapshotId(panel->getSnapshotId());
  864. }
  865. }
  866. }
  867. }
  868. onPanelPickClose(panel);
  869. updateButtons();
  870. }
  871. void LLPanelPicks::createPickInfoPanel()
  872. {
  873. if(!mPanelPickInfo)
  874. {
  875. mPanelPickInfo = LLPanelPickInfo::create();
  876. mPanelPickInfo->setExitCallback(boost::bind(&LLPanelPicks::onPanelPickClose, this, mPanelPickInfo));
  877. mPanelPickInfo->setEditPickCallback(boost::bind(&LLPanelPicks::onPanelPickEdit, this));
  878. mPanelPickInfo->setVisible(FALSE);
  879. }
  880. }
  881. void LLPanelPicks::createClassifiedInfoPanel()
  882. {
  883. mPanelClassifiedInfo = LLPanelClassifiedInfo::create();
  884. mPanelClassifiedInfo->setExitCallback(boost::bind(&LLPanelPicks::onPanelClassifiedClose, this, mPanelClassifiedInfo));
  885. mPanelClassifiedInfo->setEditClassifiedCallback(boost::bind(&LLPanelPicks::onPanelClassifiedEdit, this));
  886. mPanelClassifiedInfo->setVisible(FALSE);
  887. }
  888. void LLPanelPicks::createClassifiedEditPanel(LLPanelClassifiedEdit** panel)
  889. {
  890. if(panel)
  891. {
  892. LLPanelClassifiedEdit* new_panel = LLPanelClassifiedEdit::create();
  893. new_panel->setExitCallback(boost::bind(&LLPanelPicks::onPanelClassifiedClose, this, new_panel));
  894. new_panel->setSaveCallback(boost::bind(&LLPanelPicks::onPanelClassifiedSave, this, new_panel));
  895. new_panel->setCancelCallback(boost::bind(&LLPanelPicks::onPanelClassifiedClose, this, new_panel));
  896. new_panel->setVisible(FALSE);
  897. *panel = new_panel;
  898. }
  899. }
  900. void LLPanelPicks::createPickEditPanel()
  901. {
  902. mPanelPickEdit = LLPanelPickEdit::create();
  903. mPanelPickEdit->setExitCallback(boost::bind(&LLPanelPicks::onPanelPickClose, this, mPanelPickEdit));
  904. mPanelPickEdit->setSaveCallback(boost::bind(&LLPanelPicks::onPanelPickSave, this, mPanelPickEdit));
  905. mPanelPickEdit->setCancelCallback(boost::bind(&LLPanelPicks::onPanelPickClose, this, mPanelPickEdit));
  906. mPanelPickEdit->setVisible(FALSE);
  907. }
  908. // void LLPanelPicks::openPickEditPanel(LLPickItem* pick)
  909. // {
  910. // if(!pick)
  911. // {
  912. // return;
  913. // }
  914. // }
  915. // void LLPanelPicks::openPickInfoPanel(LLPickItem* pick)
  916. // {
  917. // if(!mPanelPickInfo)
  918. // {
  919. // mPanelPickInfo = LLPanelPickInfo::create();
  920. // mPanelPickInfo->setExitCallback(boost::bind(&LLPanelPicks::onPanelPickClose, this, mPanelPickInfo));
  921. // mPanelPickInfo->setEditPickCallback(boost::bind(&LLPanelPicks::onPanelPickEdit, this));
  922. // mPanelPickInfo->setVisible(FALSE);
  923. // }
  924. //
  925. // LLSD params;
  926. // params["pick_id"] = pick->getPickId();
  927. // params["avatar_id"] = pick->getCreatorId();
  928. // params["snapshot_id"] = pick->getSnapshotId();
  929. // params["pick_name"] = pick->getPickName();
  930. // params["pick_desc"] = pick->getPickDesc();
  931. //
  932. // getProfilePanel()->openPanel(mPanelPickInfo, params);
  933. // }
  934. void LLPanelPicks::openPickEdit(const LLSD& params)
  935. {
  936. createPickEditPanel();
  937. getProfilePanel()->openPanel(mPanelPickEdit, params);
  938. }
  939. void LLPanelPicks::onPanelPickEdit()
  940. {
  941. LLSD selected_value = mPicksList->getSelectedValue();
  942. if (selected_value.isUndefined()) return;
  943. LLPickItem* pick = dynamic_cast<LLPickItem*>(mPicksList->getSelectedItem());
  944. createPickEditPanel();
  945. LLSD params;
  946. params["pick_id"] = pick->getPickId();
  947. params["avatar_id"] = pick->getCreatorId();
  948. params["snapshot_id"] = pick->getSnapshotId();
  949. params["pick_name"] = pick->getPickName();
  950. params["pick_desc"] = pick->getPickDesc();
  951. getProfilePanel()->openPanel(mPanelPickEdit, params);
  952. }
  953. void LLPanelPicks::onPanelClassifiedEdit()
  954. {
  955. LLSD selected_value = mClassifiedsList->getSelectedValue();
  956. if (selected_value.isUndefined())
  957. {
  958. return;
  959. }
  960. LLClassifiedItem* c_item = dynamic_cast<LLClassifiedItem*>(mClassifiedsList->getSelectedItem());
  961. llassert(c_item);
  962. if (!c_item)
  963. {
  964. return;
  965. }
  966. editClassified(c_item->getClassifiedId());
  967. }
  968. LLClassifiedItem *LLPanelPicks::findClassifiedById(const LLUUID& classified_id)
  969. {
  970. // HACK - find item by classified id. Should be a better way.
  971. std::vector<LLPanel*> items;
  972. mClassifiedsList->getItems(items);
  973. LLClassifiedItem* c_item = NULL;
  974. for(std::vector<LLPanel*>::iterator it = items.begin(); it != items.end(); ++it)
  975. {
  976. LLClassifiedItem *test_item = dynamic_cast<LLClassifiedItem*>(*it);
  977. if (test_item && test_item->getClassifiedId() == classified_id)
  978. {
  979. c_item = test_item;
  980. break;
  981. }
  982. }
  983. return c_item;
  984. }
  985. void LLPanelPicks::editClassified(const LLUUID& classified_id)
  986. {
  987. LLClassifiedItem* c_item = findClassifiedById(classified_id);
  988. if (!c_item)
  989. {
  990. llwarns << "item not found for classified_id " << classified_id << llendl;
  991. return;
  992. }
  993. LLSD params;
  994. params["classified_id"] = c_item->getClassifiedId();
  995. params["classified_creator_id"] = c_item->getAvatarId();
  996. params["snapshot_id"] = c_item->getSnapshotId();
  997. params["name"] = c_item->getClassifiedName();
  998. params["desc"] = c_item->getDescription();
  999. params["category"] = (S32)c_item->getCategory();
  1000. params["content_type"] = (S32)c_item->getContentType();
  1001. params["auto_renew"] = c_item->getAutoRenew();
  1002. params["price_for_listing"] = c_item->getPriceForListing();
  1003. params["location_text"] = c_item->getLocationText();
  1004. LLPanelClassifiedEdit* panel = mEditClassifiedPanels[c_item->getClassifiedId()];
  1005. if(!panel)
  1006. {
  1007. createClassifiedEditPanel(&panel);
  1008. mEditClassifiedPanels[c_item->getClassifiedId()] = panel;
  1009. }
  1010. getProfilePanel()->openPanel(panel, params);
  1011. panel->setPosGlobal(c_item->getPosGlobal());
  1012. }
  1013. void LLPanelPicks::onClickMenuEdit()
  1014. {
  1015. if(getSelectedPickItem())
  1016. {
  1017. onPanelPickEdit();
  1018. }
  1019. else if(getSelectedClassifiedItem())
  1020. {
  1021. onPanelClassifiedEdit();
  1022. }
  1023. }
  1024. bool LLPanelPicks::onEnableMenuItem(const LLSD& user_data)
  1025. {
  1026. std::string param = user_data.asString();
  1027. LLClassifiedItem* c_item = dynamic_cast<LLClassifiedItem*>(mClassifiedsList->getSelectedItem());
  1028. if(c_item && "info" == param)
  1029. {
  1030. // dont show Info panel if classified was not created
  1031. return isClassifiedPublished(c_item);
  1032. }
  1033. return true;
  1034. }
  1035. inline LLPanelProfile* LLPanelPicks::getProfilePanel()
  1036. {
  1037. llassert_always(NULL != mProfilePanel);
  1038. return mProfilePanel;
  1039. }
  1040. //-----------------------------------------------------------------------------
  1041. // LLPanelPicks
  1042. //-----------------------------------------------------------------------------
  1043. LLPickItem::LLPickItem()
  1044. : LLPanel()
  1045. , mPickID(LLUUID::null)
  1046. , mCreatorID(LLUUID::null)
  1047. , mParcelID(LLUUID::null)
  1048. , mSnapshotID(LLUUID::null)
  1049. , mNeedData(true)
  1050. {
  1051. buildFromFile("panel_pick_list_item.xml");
  1052. }
  1053. LLPickItem::~LLPickItem()
  1054. {
  1055. if (mCreatorID.notNull())
  1056. {
  1057. LLAvatarPropertiesProcessor::instance().removeObserver(mCreatorID, this);
  1058. }
  1059. }
  1060. LLPickItem* LLPickItem::create()
  1061. {
  1062. return new LLPickItem();
  1063. }
  1064. void LLPickItem::init(LLPickData* pick_data)
  1065. {
  1066. setPickDesc(pick_data->desc);
  1067. setSnapshotId(pick_data->snapshot_id);
  1068. mPosGlobal = pick_data->pos_global;
  1069. mSimName = pick_data->sim_name;
  1070. mPickDescription = pick_data->desc;
  1071. mUserName = pick_data->user_name;
  1072. mOriginalName = pick_data->original_name;
  1073. LLTextureCtrl* picture = getChild<LLTextureCtrl>("picture");
  1074. picture->setImageAssetID(pick_data->snapshot_id);
  1075. }
  1076. void LLPickItem::setPickName(const std::string& name)
  1077. {
  1078. mPickName = name;
  1079. getChild<LLUICtrl>("picture_name")->setValue(name);
  1080. }
  1081. const std::string& LLPickItem::getPickName()
  1082. {
  1083. return mPickName;
  1084. }
  1085. const LLUUID& LLPickItem::getCreatorId()
  1086. {
  1087. return mCreatorID;
  1088. }
  1089. const LLUUID& LLPickItem::getSnapshotId()
  1090. {
  1091. return mSnapshotID;
  1092. }
  1093. void LLPickItem::setPickDesc(const std::string& descr)
  1094. {
  1095. getChild<LLUICtrl>("picture_descr")->setValue(descr);
  1096. }
  1097. void LLPickItem::setPickId(const LLUUID& id)
  1098. {
  1099. mPickID = id;
  1100. }
  1101. const LLUUID& LLPickItem::getPickId()
  1102. {
  1103. return mPickID;
  1104. }
  1105. const LLVector3d& LLPickItem::getPosGlobal()
  1106. {
  1107. return mPosGlobal;
  1108. }
  1109. const std::string LLPickItem::getDescription()
  1110. {
  1111. return getChild<LLUICtrl>("picture_descr")->getValue().asString();
  1112. }
  1113. void LLPickItem::update()
  1114. {
  1115. setNeedData(true);
  1116. LLAvatarPropertiesProcessor::instance().sendPickInfoRequest(mCreatorID, mPickID);
  1117. }
  1118. void LLPickItem::processProperties(void *data, EAvatarProcessorType type)
  1119. {
  1120. if (APT_PICK_INFO != type)
  1121. {
  1122. return;
  1123. }
  1124. LLPickData* pick_data = static_cast<LLPickData *>(data);
  1125. if (!pick_data || mPickID != pick_data->pick_id)
  1126. {
  1127. return;
  1128. }
  1129. init(pick_data);
  1130. setNeedData(false);
  1131. LLAvatarPropertiesProcessor::instance().removeObserver(mCreatorID, this);
  1132. }
  1133. void set_child_visible(LLView* parent, const std::string& child_name, bool visible)
  1134. {
  1135. parent->getChildView(child_name)->setVisible(visible);
  1136. }
  1137. BOOL LLPickItem::postBuild()
  1138. {
  1139. setMouseEnterCallback(boost::bind(&set_child_visible, this, "hovered_icon", true));
  1140. setMouseLeaveCallback(boost::bind(&set_child_visible, this, "hovered_icon", false));
  1141. return TRUE;
  1142. }
  1143. void LLPickItem::setValue(const LLSD& value)
  1144. {
  1145. if (!value.isMap()) return;;
  1146. if (!value.has("selected")) return;
  1147. getChildView("selected_icon")->setVisible( value["selected"]);
  1148. }
  1149. //////////////////////////////////////////////////////////////////////////
  1150. //////////////////////////////////////////////////////////////////////////
  1151. //////////////////////////////////////////////////////////////////////////
  1152. LLClassifiedItem::LLClassifiedItem(const LLUUID& avatar_id, const LLUUID& classified_id)
  1153. : LLPanel()
  1154. , mAvatarId(avatar_id)
  1155. , mClassifiedId(classified_id)
  1156. {
  1157. buildFromFile("panel_classifieds_list_item.xml");
  1158. LLAvatarPropertiesProcessor::getInstance()->addObserver(getAvatarId(), this);
  1159. LLAvatarPropertiesProcessor::getInstance()->sendClassifiedInfoRequest(getClassifiedId());
  1160. }
  1161. LLClassifiedItem::~LLClassifiedItem()
  1162. {
  1163. LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(), this);
  1164. }
  1165. void LLClassifiedItem::processProperties(void* data, EAvatarProcessorType type)
  1166. {
  1167. if(APT_CLASSIFIED_INFO != type)
  1168. {
  1169. return;
  1170. }
  1171. LLAvatarClassifiedInfo* c_info = static_cast<LLAvatarClassifiedInfo*>(data);
  1172. if( !c_info || c_info->classified_id != getClassifiedId() )
  1173. {
  1174. return;
  1175. }
  1176. setClassifiedName(c_info->name);
  1177. setDescription(c_info->description);
  1178. setSnapshotId(c_info->snapshot_id);
  1179. setPosGlobal(c_info->pos_global);
  1180. LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(), this);
  1181. }
  1182. BOOL LLClassifiedItem::postBuild()
  1183. {
  1184. setMouseEnterCallback(boost::bind(&set_child_visible, this, "hovered_icon", true));
  1185. setMouseLeaveCallback(boost::bind(&set_child_visible, this, "hovered_icon", false));
  1186. return TRUE;
  1187. }
  1188. void LLClassifiedItem::setValue(const LLSD& value)
  1189. {
  1190. if (!value.isMap()) return;;
  1191. if (!value.has("selected")) return;
  1192. getChildView("selected_icon")->setVisible( value["selected"]);
  1193. }
  1194. void LLClassifiedItem::fillIn(LLPanelClassifiedEdit* panel)
  1195. {
  1196. if(!panel)
  1197. {
  1198. return;
  1199. }
  1200. setClassifiedName(panel->getClassifiedName());
  1201. setDescription(panel->getDescription());
  1202. setSnapshotId(panel->getSnapshotId());
  1203. setCategory(panel->getCategory());
  1204. setContentType(panel->getContentType());
  1205. setAutoRenew(panel->getAutoRenew());
  1206. setPriceForListing(panel->getPriceForListing());
  1207. setPosGlobal(panel->getPosGlobal());
  1208. setLocationText(panel->getClassifiedLocation());
  1209. }
  1210. void LLClassifiedItem::setClassifiedName(const std::string& name)
  1211. {
  1212. getChild<LLUICtrl>("name")->setValue(name);
  1213. }
  1214. void LLClassifiedItem::setDescription(const std::string& desc)
  1215. {
  1216. getChild<LLUICtrl>("description")->setValue(desc);
  1217. }
  1218. void LLClassifiedItem::setSnapshotId(const LLUUID& snapshot_id)
  1219. {
  1220. getChild<LLUICtrl>("picture")->setValue(snapshot_id);
  1221. }
  1222. LLUUID LLClassifiedItem::getSnapshotId()
  1223. {
  1224. return getChild<LLUICtrl>("picture")->getValue();
  1225. }
  1226. //EOF